29 #define SMET_STRINGIFY(x) #x
30 #define SMET_TOSTRING(x) SMET_STRINGIFY(x)
31 #define SMET_AT __FILE__ ":" SMET_TOSTRING(__LINE__)
45 SMETException(
const std::string& message=
"SMETException occured",
const std::string& position=
"");
47 const char*
what()
const throw();
61 static void copy_file(
const std::string& src,
const std::string& dest);
62 static bool fileExists(
const std::string& filename);
66 static char getEoln(std::istream& fin);
67 static void trim(std::string& str);
68 static void toUpper(std::string& str);
69 static bool readKeyValuePair(
const std::string& in_line,
const std::string& delimiter,
70 std::map<std::string,std::string>& out_map);
71 static size_t readLineToVec(
const std::string& line_in, std::vector<std::string>& vec_string);
72 static bool is_decimal(
const std::string& value);
81 static const bool __init;
82 static bool initStaticData();
110 SMETWriter(
const std::string& in_filename,
const std::string& in_fields,
const double& in_nodata);
134 void write(
const std::vector<std::string>& vec_timestamp,
const std::vector<double>& data);
141 void write(
const std::vector<double>& data);
157 void set_width(
const std::vector<int>& vec_width);
162 void print_if_exists(
const std::string& header_field, std::ofstream& fout)
const;
163 void write_header(std::ofstream& fout);
164 void write_data_line_ascii(
const std::string& timestamp,
const std::vector<double>& data, std::ofstream& fout);
165 void write_data_line_binary(
const std::vector<double>& data, std::ofstream& fout);
166 bool check_fields(
const std::string& key,
const std::string& value);
167 void check_formatting();
168 bool valid_header_pair(
const std::string& key,
const std::string& value);
171 std::vector<std::string> other_header_keys;
172 std::vector<int> ascii_precision, ascii_width;
173 std::map< std::string, std::string > header;
174 std::set<std::string> mandatory_header_keys;
176 std::string filename;
177 std::string nodata_string;
180 size_t nr_of_fields, julian_field, timestamp_field;
181 char location_wgs84, location_epsg;
182 bool location_in_header, location_in_data_wgs84, location_in_data_epsg;
183 bool timestamp_present, julian_present;
184 bool file_is_binary, append_mode, append_possible;
214 void read(
const std::string& timestamp_start,
const std::string& timestamp_end,
215 std::vector<std::string>& vec_timestamp, std::vector<double>& vec_data);
224 void read(
const double& julian_start,
const double& julian_end, std::vector<double>& vec_data);
231 void read(std::vector<std::string>& vec_timestamp, std::vector<double>& vec_data);
237 void read(std::vector<double>& vec_data);
317 void truncate_file(
const std::string& date_stop)
const;
318 void copy_file_header(std::ifstream& fin, std::ofstream& fout)
const;
319 void copy_file_data(
const std::string& date_stop, std::ifstream& fin, std::ofstream& fout)
const;
320 std::string getLastTimestamp()
const;
321 void read_data_ascii(std::ifstream& fin, std::vector<std::string>& vec_timestamp, std::vector<double>& vec_data);
322 void read_data_binary(std::ifstream& fin, std::vector<double>& vec_data);
323 void cleanup(std::ifstream& fin)
throw();
324 void checkSignature(
const std::vector<std::string>& vecSignature,
bool& o_isAscii);
325 void read_header(std::ifstream& fin);
326 void process_header();
328 std::streampos data_start_fpointer;
330 std::vector<double> vec_offset;
331 std::vector<double> vec_multiplier;
332 std::vector<std::string> vec_fieldnames;
333 std::map< std::string, std::string > header;
336 std::string filename;
337 std::string timestamp_start, timestamp_end;
339 double julian_start, julian_end;
340 static const size_t streampos_every_n_lines;
342 size_t timestamp_field, julian_field;
343 char location_wgs84, location_epsg, location_data_wgs84, location_data_epsg;
345 bool timestamp_present, julian_present;
348 bool timestamp_interval, julian_interval;
static double convert_to_double(const std::string &in_string)
Definition: libsmet.cc:153
bool location_in_header(const LocationType &type) const
Check whether location information is written in the header.
Definition: libsmet.cc:878
const std::string toString() const
Definition: libsmet.cc:372
bool location_in_data(const LocationType &type) const
Check whether location information is written in the data section.
Definition: libsmet.cc:889
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:872
~SMETException()
Definition: libsmet.cc:48
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:850
bool contains_timestamp() const
Check whether timestamp is a part of the fields.
Definition: libsmet.cc:1516
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:800
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:297
std::string msg
Definition: libsmet.h:50
A basic exception class adjusted for the needs of the SMET library.
Definition: libsmet.h:43
SMETReader(const std::string &in_fname)
A constructor that will immediately parse the header of the SMET file.
Definition: libsmet.cc:810
static std::set< std::string > all_decimal_header_values
Definition: libsmet.h:76
The SMETWriter class that enables to write a SMET formatted file. The user constructs a SMETWriter cl...
Definition: libsmet.h:94
static const char * smet_version
Definition: libsmet.h:78
static size_t readLineToVec(const std::string &line_in, std::vector< std::string > &vec_string)
Definition: libsmet.cc:276
The SMETReader class enables to read a SMET formatted file. Data and header info can be extracted thr...
Definition: libsmet.h:195
Definition: FileUtils.h:129
double get_header_doublevalue(const std::string &key) const
Get a double value for a header key in a SMET file.
Definition: libsmet.cc:1489
LocationType
Definition: libsmet.h:36
void write(const std::vector< std::string > &vec_timestamp, const std::vector< double > &data)
Write a SMET file, providing ASCII ISO formatted timestamps and data.
Definition: libsmet.cc:546
static void copy_file(const std::string &src, const std::string &dest)
Definition: libsmet.cc:132
static std::set< std::string > all_optional_header_keys
Definition: libsmet.h:75
~SMETReader()
Definition: libsmet.h:204
std::string get_filename() const
Retrieve the filename that this reader operates upon.
Definition: libsmet.cc:1521
size_t get_nr_of_fields() const
Get number of fields (=columns) in SMET file (timestamp excluded)
Definition: libsmet.cc:867
static void trim(std::string &str)
Definition: libsmet.cc:174
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:1507
static bool fileExists(const std::string &filename)
Definition: libsmet.cc:101
SMETType
Definition: libsmet.h:35
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:795
A static class to provide basic operations and variables for the libsmet library. ...
Definition: libsmet.h:58
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:409
static void toUpper(std::string &str)
Definition: libsmet.cc:229
static bool validFileAndPath(const std::string &filename)
Definition: libsmet.cc:116
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:855
const char * what() const
Definition: libsmet.cc:50
static std::set< std::string > all_mandatory_header_keys
Definition: libsmet.h:77
static int convert_to_int(const std::string &in_string)
Definition: libsmet.cc:165
SMETException(const std::string &message="SMETException occured", const std::string &position="")
Definition: libsmet.cc:45
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:1153
static char getEoln(std::istream &fin)
Definition: libsmet.cc:234
static bool is_decimal(const std::string &value)
Definition: libsmet.cc:267
int get_header_intvalue(const std::string &key) const
Get an int value for a header key in a SMET file.
Definition: libsmet.cc:1498
static bool readKeyValuePair(const std::string &in_line, const std::string &delimiter, std::map< std::string, std::string > &out_map)
Definition: libsmet.cc:189
static void stripComments(std::string &str)
Definition: libsmet.cc:221