39double round(
const double& x);
76 const unsigned int unodata =
static_cast<unsigned int>(-1);
79 const char cnodata = std::numeric_limits<char>::max();
80 const size_t npos =
static_cast<size_t>(-1);
121 inline bool checkEpsilonEquality(
const double& val1,
const double& val2,
const double& epsilon) {
return (std::abs(val1-val2) < epsilon);}
132 size_t seek(
const Date& soughtdate,
const std::vector<MeteoData>& vecM,
const bool& exactmatch=
true);
151 double bearing(std::string bearing_str);
182 void trim(std::string &s);
189 std::string
trim(
const std::string &s);
193 void stripComments(std::string& str,
const char& comment_mk);
204 void replace_all(std::string &input,
const std::string& search,
const std::string& format);
237 void removeChars(std::string& line,
const std::set<char>& specialChars);
247 void cleanFieldName(std::string& field,
const bool& clean_whitespaces =
true,
const char& rep =
'-');
256 size_t count(
const std::string &input,
const std::string& search);
266 size_t FNV_hash(
const std::string& text);
277 bool readKeyValuePair(
const std::string& in_line,
const std::string& delimiter,
278 std::string &key, std::string &value,
const bool& setToUpperCase=
false);
280 void toUpper(std::string& str);
282 void toLower(std::string& str);
284 bool isNumeric(std::string input,
const unsigned int& nBase=10);
285 size_t readLineToVec(
const std::string& line_in, std::vector<double>& vec_data);
286 size_t readLineToSet(
const std::string& line_in, std::set<std::string>& setString);
287 size_t readLineToVec(
const std::string& line_in, std::vector<std::string>& vecString);
288 size_t readLineToVec(
const std::string& line_in, std::vector<std::string>& vecString,
const char& delim);
289 size_t readLineToVec(
const std::string& line_in, std::vector<double>& vecRet,
const char& delim);
291 std::vector<std::string>
split(
const std::string& str,
char delim);
292 std::vector<std::string>
split(
const std::string& str, std::string delim);
294 template <
class T> std::string
toString(
const T& t) {
295 std::ostringstream os;
309 template <
class T>
bool convertString(T& t, std::string str, std::ios_base& (*f)(std::ios_base&) = std::dec) {
312 t =
static_cast<T
>(
nodata);
315 std::istringstream iss(str);
316 iss.setf(std::ios::fixed);
317 iss.precision(std::numeric_limits<double>::digits10);
326 if (!tmp.empty() && tmp[0] !=
'#' && tmp[0] !=
';') {
334 template<>
bool convertString<double>(
double& t, std::string str, std::ios_base& (*f)(std::ios_base&));
335 template<>
bool convertString<std::string>(std::string& t, std::string str, std::ios_base& (*f)(std::ios_base&));
336 template<>
bool convertString<bool>(
bool& t, std::string str, std::ios_base& (*f)(std::ios_base&));
337 template<>
bool convertString<char>(
char& t, std::string str, std::ios_base& (*f)(std::ios_base&));
341 bool convertString(
Date& t, std::string str,
const double& time_zone, std::ios_base& (*f)(std::ios_base&) = std::dec);
351 template <
class T>
void getValueForKey(
const std::map<std::string,std::string>& properties,
356 const std::map<std::string, std::string>::const_iterator it( properties.find(key) );
357 if (it == properties.end()){
363 const std::string& value = it->second;
366 std::cerr <<
"[E] When reading \"" << key <<
"\" = \"" << t <<
"\"\n";
379 template <
class T>
void getValueForKey(
const std::map<std::string,std::string>& properties,
385 const std::map<std::string, std::string>::const_iterator it( properties.find(key) );
386 if (it == properties.end()) {
393 const std::string& value = it->second;
396 std::vector<std::string> vecUnconvertedValues;
397 const size_t counter =
readLineToVec(value, vecUnconvertedValues);
398 vecT.resize( counter );
399 for (
size_t ii=0; ii<counter; ii++){
401 if (!convertString<T>(myvar, vecUnconvertedValues.at(ii), std::dec) && options!=
IOUtils::nothrow){
402 std::cerr <<
"[E] When reading \"" << key <<
"\" = \"" << myvar <<
"\"\n";
417 if (value==plugin_nodata)
return static_cast<T
> (
nodata);
428 template <
class T>
static void parseArg(
const std::pair< std::string, std::string>& arg,
const std::string& algo, T& val) {
443 std::string& coordout, std::string& coordoutparam);
477 double unitsConversion(
const double& val, std::string unitIn, std::string unitOut);
#define AT
Definition: IOExceptions.h:28
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition: Config.h:79
thrown when an unsuccessful attempt to convert data types/classes is made (e.g. attempt to convert a ...
Definition: IOExceptions.h:118
A class to handle geographic coordinate systems. This class offers an easy way to transparently conve...
Definition: Coords.h:83
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
thrown when encountered an unexpected function's argument (e.g. bad index, bad or missing parameter n...
Definition: IOExceptions.h:130
thrown when encountered an unexpected value (e.g. unknown name or key)
Definition: IOExceptions.h:142
static const double to_rad
Definition: Meteoconst.h:81
static const double t_water_freezing_pt
Definition: Meteoconst.h:50
static const double earth_R0
Definition: Meteoconst.h:62
static const double to_deg
Definition: Meteoconst.h:82
bool convertString< char >(char &t, std::string str, std::ios_base &(*f)(std::ios_base &))
Definition: IOUtils.cc:596
double bearing_to_angle(const double &bearing)
Converts a compass bearing to a trigonometric angle.
Definition: IOUtils.cc:68
size_t readLineToVec(const std::string &line_in, std::vector< double > &vec_data)
Definition: IOUtils.cc:395
const double lat_epsilon
in degrees. Small angle for latitudes.
Definition: IOUtils.h:84
bool readKeyValuePair(const std::string &in_line, const std::string &delimiter, std::string &key, std::string &value, const bool &setToUpperCase)
read a string line, parse it and save it into a map object, that is passed by reference
Definition: IOUtils.cc:326
bool convertString(Date &t, std::string str, const double &time_zone, std::ios_base &(*f)(std::ios_base &))
Convert a string to a date (template specialization of convertString)
Definition: IOUtils.cc:654
static void parseArg(const std::pair< std::string, std::string > &arg, const std::string &algo, T &val)
Parse a given named argument.
Definition: IOUtils.h:428
std::string getLogName()
Retrieve the user name This checks various environment variables (USERNAME, USER, LOGNAME).
Definition: IOUtils.cc:348
T standardizeNodata(const T &value, const double &plugin_nodata)
Standardize a given value to use MeteoIO's internal nodata value (if applicable)
Definition: IOUtils.h:416
double bearing(std::string bearing_str)
Converts a string bearing to a compass bearing.
Definition: IOUtils.cc:76
void stripComments(std::string &str)
Definition: IOUtils.cc:129
double VWDW_TO_V(const double &VW, const double &DW)
From wind speed and direction to v component (south-to-north)
Definition: IOUtils.h:112
void removeQuotes(std::string &line)
Removes single and double quotation marks.
Definition: IOUtils.cc:236
void removeChars(std::string &line, const std::set< char > &specialChars)
Removes any character present in the provided set from the given line.
Definition: IOUtils.cc:242
void toLower(std::string &str)
Definition: IOUtils.cc:290
double C_TO_K(const double &T)
Definition: IOUtils.h:86
const size_t npos
npos is the out-of-range value
Definition: IOUtils.h:80
void removeDuplicateWhitespaces(std::string &line)
Removes consecutive occurrences of spaces and tabs.
Definition: IOUtils.cc:218
bool convertString< unsigned int >(unsigned int &t, std::string str, std::ios_base &(*f)(std::ios_base &))
Definition: IOUtils.cc:620
const int inodata
Definition: IOUtils.h:77
double unitsConversion(const double &val, std::string unitIn, std::string unitOut)
Performs simple unit conversion (supports temperature, prefixes and exponents) NOTE "composite" units...
Definition: IOUtils.cc:910
void cleanEscapedCharacters(std::string &str, const std::vector< char > &escaped_chars)
Definition: IOUtils.cc:157
double unitsPrefix(const char &prefix)
Convert a textual representation of a unit prefix (like 'm' or 'G') to multiplying factor.
Definition: IOUtils.cc:885
size_t FNV_hash(const std::string &text)
Fowler/Noll/Vo hash function (FNV-1a)
Definition: IOUtils.cc:273
bool convertString< double >(double &t, std::string str, std::ios_base &(*f)(std::ios_base &))
Definition: IOUtils.cc:545
bool isNumeric(std::string str, const unsigned int &nBase)
Definition: IOUtils.cc:306
std::string strToUpper(std::string str)
Definition: IOUtils.cc:294
size_t readLineToSet(const std::string &line_in, std::set< std::string > &setString)
Definition: IOUtils.cc:417
std::string getDomainName()
Retrieve the domain name of the computer running the binary.
Definition: IOUtils.cc:383
OperationMode
Keywords for mode of operation. Please keep all the GRID_xxx last!
Definition: IOUtils.h:63
@ GRID_EXTRACT_PTS
as GRID_EXTRACT, but queries plugin only for virtual stations points, instead of full grids
Definition: IOUtils.h:68
@ GRID_SMART
extract all relevant grid points from a provided grid
Definition: IOUtils.h:69
@ GRID_ALL
extract all grid points from a provided grid
Definition: IOUtils.h:70
@ GRID_RESAMPLE
generate a grid at a different resolution
Definition: IOUtils.h:71
@ VSTATIONS
extract virtual stations as specified in the ini file
Definition: IOUtils.h:65
@ GRID_1DINTERPOLATE
temporally interpolate existing grids (must be enumerated before GRID_EXTRACT)
Definition: IOUtils.h:66
@ GRID_EXTRACT
extract data from grids at locations provided in the ini file
Definition: IOUtils.h:67
@ STD
default: extract timeseries from timeseries or grids from grids or spatially interpolate timeseries
Definition: IOUtils.h:64
const double nodata
This is the internal nodata value.
Definition: IOUtils.h:75
double UV_TO_DW(const double &U, const double &V)
From wind speed components (u,v) to wind direction, following standard meteorological definitions: U ...
Definition: IOUtils.h:96
void getValueForKey(const std::map< std::string, std::string > &properties, const std::string &key, T &t, const ThrowOptions &options=IOUtils::dothrow)
Returns, with the requested type, the value associated to a key (template function).
Definition: IOUtils.h:351
bool convertString< Coords >(Coords &t, std::string str, std::ios_base &(*f)(std::ios_base &))
Definition: IOUtils.cc:789
std::string toString(const T &t)
Definition: IOUtils.h:294
const char cnodata
Definition: IOUtils.h:79
const unsigned int unodata
Definition: IOUtils.h:76
void replace_all(std::string &input, const std::string &search, const std::string &format)
Replace a substring within a given string by another one.
Definition: IOUtils.cc:198
void getProjectionParameters(const Config &cfg, std::string &coordin, std::string &coordinparam, std::string &coordout, std::string &coordoutparam)
A function that parses a Config object for COORSYS, COORDPARAM keywords in [Input] and [Output] secti...
Definition: IOUtils.cc:806
void trim(std::string &str)
Removes trailing and leading whitespaces, tabs and newlines from a string.
Definition: IOUtils.cc:176
double VWDW_TO_U(const double &VW, const double &DW)
From wind speed and direction to u component (west-to-east)
Definition: IOUtils.h:104
void toUpper(std::string &str)
Definition: IOUtils.cc:286
const short int snodata
Definition: IOUtils.h:78
size_t seek(const Date &soughtdate, const std::vector< MeteoData > &vecM, const bool &exactmatch)
Search for an element at a given date in a vector of MeteoData. The position of the matching date is ...
Definition: IOUtils.cc:827
std::string getHostName()
Retrieve the name of the computer running the binary.
Definition: IOUtils.cc:362
const double lon_epsilon
in degrees. Small angle for longitudes, so sin(x)=x
Definition: IOUtils.h:83
void replaceWhitespaces(std::string &line, const char &rep)
Replaces spaces and tabs with a single character or removes them.
Definition: IOUtils.cc:226
ProcessingLevel
Definition: IOUtils.h:54
@ resampled
Definition: IOUtils.h:57
@ num_of_levels
Definition: IOUtils.h:59
@ raw
Definition: IOUtils.h:55
@ filtered
Definition: IOUtils.h:56
@ generated
Definition: IOUtils.h:58
void getTimeZoneParameters(const Config &cfg, double &tz_in, double &tz_out)
A function that parses a Config object for the time_zone keyword and returns the timezone.
Definition: IOUtils.cc:821
void replaceInvalidChars(std::string &line, const char &rep)
Replaces invalid characters with a single character or removes them.
Definition: IOUtils.cc:231
double K_TO_C(const double &T)
Definition: IOUtils.h:87
bool convertString< bool >(bool &t, std::string str, std::ios_base &(*f)(std::ios_base &))
Definition: IOUtils.cc:516
std::vector< std::string > split(const std::string &s, char delimiter)
Definition: IOUtils.cc:478
void cleanFieldName(std::string &field, const bool &clean_whitespaces, const char &rep)
Cleans up a string to be usable as, for example, a parameter name.
Definition: IOUtils.cc:248
double angle_to_bearing(const double &angle)
Converts a trigonometric angle to a compass bearing.
Definition: IOUtils.cc:72
size_t count(const std::string &input, const std::string &search)
count how many times a substring appears in a string
Definition: IOUtils.cc:258
const double grid_epsilon
What is an acceptable small distance on a grid, in meters.
Definition: IOUtils.h:82
bool checkEpsilonEquality(const double &val1, const double &val2, const double &epsilon)
Check whether two values are equal regarding a certain epsilon environment (within certain radius of ...
Definition: IOUtils.h:121
std::string strToLower(std::string str)
Definition: IOUtils.cc:301
ThrowOptions
Definition: IOUtils.h:74
@ nothrow
Definition: IOUtils.h:74
@ dothrow
Definition: IOUtils.h:74
long int round(const double &x)
Optimized version of c++ round() This version works with positive and negative numbers but does not c...
Definition: MathOptim.h:45
std::string getLibVersion(const bool &short_version)
Return the library version.
Definition: IOUtils.cc:59