32#define SMET_STRINGIFY(x) #x
33#define SMET_TOSTRING(x) SMET_STRINGIFY(x)
34#define SMET_AT __FILE__ ":" SMET_TOSTRING(__LINE__)
48 SMETException(
const std::string& message=
"SMETException occured",
const std::string& position=
"");
49 const char*
what()
const noexcept;
63 static void copy_file(
const std::string& src,
const std::string& dest);
64 static bool fileExists(
const std::string& filename);
65 static std::string
strToLower(std::string str);
70 static char getEoln(std::istream& fin);
71 static void trim(std::string& str);
72 static void toUpper(std::string& str);
73 static bool readKeyValuePair(
const std::string& in_line,
const std::string& delimiter,
74 std::map<std::string,std::string>& out_map);
75 static size_t readLineToVec(
const std::string& line_in, std::vector<std::string>& vecString);
76 static size_t readLineToVec(
const std::string& line_in, std::vector<std::string>& vecString,
const char& delim);
77 static bool is_decimal(
const std::string& value);
86 static const bool __init;
87 static bool initStaticData();
115 SMETWriter(
const std::string& in_filename,
const std::string& in_fields,
const double& in_nodata);
140 void write(
const std::vector<std::string>& vec_timestamp,
const std::vector<double>& data,
const mio::ACDD& acdd);
148 void write(
const std::vector<double>& data,
const mio::ACDD& acdd);
164 void set_width(
const std::vector<int>& vec_width);
185 void setAppendMode(std::vector<std::string> vecFields);
186 void print_if_exists(
const std::string& header_field,
const std::string& prefix,
mio::ofilestream& fout)
const;
189 void write_data_line_ascii(
const std::string& timestamp,
const std::vector<double>& data,
mio::ofilestream& fout);
190 void write_data_line_binary(
const std::vector<double>& data,
mio::ofilestream& fout);
191 bool check_fields(
const std::string& key,
const std::string& value);
192 void check_formatting();
193 bool valid_header_pair(
const std::string& key,
const std::string& value);
196 std::vector<std::string> other_header_keys;
197 std::vector<int> ascii_precision, ascii_width;
198 std::map< std::string, std::string > header;
199 std::set<std::string> mandatory_header_keys;
201 std::string filename;
202 std::string nodata_string;
205 size_t nr_of_fields, julian_field, timestamp_field;
206 char location_wgs84, location_epsg;
208 bool location_in_header, location_in_data_wgs84, location_in_data_epsg;
209 bool timestamp_present, julian_present;
210 bool file_is_binary, append_mode, append_possible, comment_headers;
239 void read(
const std::string& timestamp_start,
const std::string& timestamp_end,
240 std::vector<std::string>& vec_timestamp, std::vector<double>& vec_data);
249 void read(
const double& julian_start,
const double& julian_end, std::vector<double>& vec_data);
256 void read(std::vector<std::string>& vec_timestamp, std::vector<double>& vec_data);
262 void read(std::vector<double>& vec_data);
342 void truncate_file(
const std::string& date_stop)
const;
344 void copy_file_data(
const std::string& date_stop, std::ifstream& fin,
mio::ofilestream& fout)
const;
345 std::string getLastTimestamp()
const;
346 void read_data_ascii(std::ifstream& fin, std::vector<std::string>& vec_timestamp, std::vector<double>& vec_data);
347 void read_data_binary(std::ifstream& fin, std::vector<double>& vec_data);
348 void cleanup(std::ifstream& fin)
noexcept;
349 void checkSignature(
const std::vector<std::string>& vecSignature,
bool& o_isAscii);
350 void read_header(std::ifstream& fin);
351 void process_header();
353 std::streampos data_start_fpointer;
355 std::vector<double> vec_offset;
356 std::vector<double> vec_multiplier;
357 std::vector<std::string> vec_fieldnames;
358 std::map< std::string, std::string > header;
361 std::string filename;
362 std::string timestamp_start, timestamp_end;
364 double julian_start, julian_end;
365 static const size_t streampos_every_n_lines;
367 size_t timestamp_field, julian_field;
368 char location_wgs84, location_epsg, location_data_wgs84, location_data_epsg;
371 bool timestamp_present, julian_present;
374 bool timestamp_interval, julian_interval;
This class contains and handles NetCDF Attribute Conventions Dataset Discovery attributes (see ACDD).
Definition: libacdd.h:113
Definition: FileUtils.h:150
A class that extends std::ofstream, adding some output functionality. Limiting the write access of th...
Definition: FStream.h:37
A static class to provide basic operations and variables for the libsmet library.
Definition: libsmet.h:60
static std::string strToLower(std::string str)
Definition: libsmet.cc:154
static void toUpper(std::string &str)
Definition: libsmet.cc:249
static size_t readLineToVec(const std::string &line_in, std::vector< std::string > &vecString)
Definition: libsmet.cc:296
static char convert_to_char(const std::string &in_string)
Definition: libsmet.cc:180
static void copy_file(const std::string &src, const std::string &dest)
Definition: libsmet.cc:133
static int convert_to_int(const std::string &in_string)
Definition: libsmet.cc:171
static void stripComments(std::string &str)
Definition: libsmet.cc:229
static bool is_decimal(const std::string &value)
Definition: libsmet.cc:287
static bool readKeyValuePair(const std::string &in_line, const std::string &delimiter, std::map< std::string, std::string > &out_map)
Definition: libsmet.cc:204
static std::set< std::string > all_optional_header_keys
Definition: libsmet.h:80
static std::set< std::string > all_decimal_header_values
Definition: libsmet.h:81
static char getEoln(std::istream &fin)
Definition: libsmet.cc:254
static const char * smet_version
Definition: libsmet.h:83
static void trim(std::string &str)
Definition: libsmet.cc:189
static std::set< std::string > all_mandatory_header_keys
Definition: libsmet.h:82
static double convert_to_double(const std::string &in_string)
Definition: libsmet.cc:159
static bool fileExists(const std::string &filename)
Definition: libsmet.cc:102
static bool validFileAndPath(const std::string &filename)
Definition: libsmet.cc:117
A basic exception class adjusted for the needs of the SMET library.
Definition: libsmet.h:46
const char * what() const noexcept
Definition: libsmet.cc:50
std::string msg
Definition: libsmet.h:52
SMETException(const std::string &message="SMETException occured", const std::string &position="")
Definition: libsmet.cc:47
The SMETReader class enables to read a SMET formatted file. Data and header info can be extracted thr...
Definition: libsmet.h:221
void get_units_conversion(std::vector< double > &offset, std::vector< double > &multiplier) const
Get the unit conversion (offset and multiplier) that are used for this SMET object If the fields unit...
Definition: libsmet.cc:948
std::string get_filename() const
Retrieve the filename that this reader operates upon.
Definition: libsmet.cc:1605
bool location_in_data(const LocationType &type) const
Check whether location information is written in the data section.
Definition: libsmet.cc:965
size_t get_nr_of_fields() const
Get number of fields (=columns) in SMET file (timestamp excluded)
Definition: libsmet.cc:943
bool contains_timestamp() const
Check whether timestamp is a part of the fields.
Definition: libsmet.cc:1600
std::string get_field_name(const size_t &nr_of_field)
Get a name for a certain column in the SMET file.
Definition: libsmet.cc:931
int get_header_intvalue(const std::string &key) const
Get an int value for a header key in a SMET file.
Definition: libsmet.cc:1582
std::string get_header_value(const std::string &key) const
Get a string value for a header key in a SMET file.
Definition: libsmet.cc:1591
void convert_to_MKSA(const bool &in_mksa)
Set whether the values returned should be converted according to unit_offset and multiplier or whethe...
Definition: libsmet.cc:926
void read(const std::string ×tamp_start, const std::string ×tamp_end, std::vector< std::string > &vec_timestamp, std::vector< double > &vec_data)
Read the data in a SMET file for a given interval of time if no timestamp is present in the file,...
Definition: libsmet.cc:1233
bool location_in_header(const LocationType &type) const
Check whether location information is written in the header.
Definition: libsmet.cc:954
double get_header_doublevalue(const std::string &key) const
Get a double value for a header key in a SMET file.
Definition: libsmet.cc:1573
SMETReader(const std::string &in_fname)
A constructor that will immediately parse the header of the SMET file.
Definition: libsmet.cc:887
The SMETWriter class that enables to write a SMET formatted file. The user constructs a SMETWriter cl...
Definition: libsmet.h:99
void set_precision(const std::vector< int > &vec_precision)
Set precision for each field (except timestamp), otherwise a default precision of 3 is used for each ...
Definition: libsmet.cc:877
SMETWriter(const std::string &in_filename, const SMETType &in_type=ASCII)
The constructor allows to set the filename, the type and whether the file should be gzipped.
Definition: libsmet.cc:334
void set_width(const std::vector< int > &vec_width)
Set width for each field (except timestamp), otherwise a default width of 8 is used for each column.
Definition: libsmet.cc:862
void set_separator(const char &i_separator)
For some special cases (import into DB), the white space separator should be replaced by another one ...
Definition: libsmet.cc:867
const std::string toString() const
Definition: libsmet.cc:416
void set_header_value(const std::string &key, const std::string &value)
Set a key, value pair in the SMET header (both strings)
Definition: libsmet.cc:453
void set_commented_headers(const bool &flag)
For some special cases (import into DB), the headers should be commented out (please note that this b...
Definition: libsmet.h:180
void write(const std::vector< std::string > &vec_timestamp, const std::vector< double > &data, const mio::ACDD &acdd)
Write a SMET file, providing ASCII ISO formatted timestamps and data.
Definition: libsmet.cc:591
Definition: libsmet.cc:40
SMETType
Definition: libsmet.h:38
@ BINARY
Definition: libsmet.h:38
@ ASCII
Definition: libsmet.h:38
LocationType
Definition: libsmet.h:39
@ EPSG
Definition: libsmet.h:39
@ WGS84
Definition: libsmet.h:39