MeteoIODoc  MeteoIODoc-2.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mio::IOUtils Namespace Reference

Enumerations

enum  ProcessingLevel {
  raw = 1, filtered = 1 << 1, resampled = 1 << 2, generated = 1 << 3,
  num_of_levels = 1 << 4
}
 
enum  ThrowOptions { dothrow, nothrow }
 

Functions

double bearing_to_angle (const double &bearing)
 Converts a compass bearing to a trigonometric angle. More...
 
double angle_to_bearing (const double &angle)
 Converts a trigonometric angle to a compass bearing. More...
 
double bearing (std::string bearing_str)
 Converts a string bearing to a compass bearing. More...
 
std::string bearing (double bearing)
 Converts a compass bearing to a string bearing. More...
 
void stripComments (std::string &str)
 
void trim (std::string &s)
 Removes trailing and leading whitespaces, tabs and newlines from a string. More...
 
void toUpper (std::string &str)
 
void toLower (std::string &str)
 
std::string strToUpper (std::string str)
 
std::string strToLower (std::string str)
 
bool isNumeric (std::string str, const unsigned int &nBase)
 
bool readKeyValuePair (const std::string &in_line, const std::string &delimiter, std::string &key, std::string &value, const bool &setToUpperCase=false)
 read a string line, parse it and save it into a map object, that is passed by reference More...
 
std::string getLogName ()
 Retrieve the user name This checks various environment variables (USERNAME, USER, LOGNAME). More...
 
std::string getHostName ()
 Retrieve the name of the computer running the binary. More...
 
size_t readLineToVec (const std::string &line_in, std::vector< double > &vec_data)
 
size_t readLineToVec (const std::string &line_in, std::vector< std::string > &vecString)
 
size_t readLineToVec (const std::string &line_in, std::vector< std::string > &vecString, const char &delim)
 
template<>
bool convertString< std::string > (std::string &t, const std::string &str, std::ios_base &(*f)(std::ios_base &))
 
template<>
bool convertString< bool > (bool &t, const std::string &str, std::ios_base &(*f)(std::ios_base &))
 
template<>
bool convertString< double > (double &t, const std::string &str, std::ios_base &(*f)(std::ios_base &))
 
template<>
bool convertString< unsigned int > (unsigned int &t, const std::string &str, std::ios_base &(*f)(std::ios_base &))
 
bool convertString (Date &t, const std::string &str, const double &time_zone, std::ios_base &(*f)(std::ios_base &))
 
template<>
bool convertString< Coords > (Coords &t, const std::string &str, std::ios_base &(*f)(std::ios_base &))
 
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] section and sets the respective strings to the values of those keywords. More...
 
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. More...
 
size_t seek (const Date &soughtdate, const std::vector< MeteoData > &vecM, const bool &exactmatch=true)
 Search for an element at a given date in a vector of MeteoData. The position of the matching date is returned or IOUtils::npos if not found. If exactmatch=false, the position of the first element after soughtdate is returned (or IOUtils::npos if this is not possible / relevant). More...
 
void getArraySliceParams (const size_t &dimx, const size_t &nbworkers, const size_t &wk, size_t &startx, size_t &nx)
 Returns the parameters for splitting an array in several, balanced sub-arrays. This is mostly usefull for parallel calculations, where an array will be split and sent to different workers. More...
 
double unitsPrefix (const char &prefix)
 Convert a textual representation of a unit prefix (like 'm' or 'G') to multiplying factor. More...
 
double unitsConversion (const double &val, std::string unitIn, std::string unitOut)
 Performs simple unit conversion (supports temperature, prefixes and exponents) NOTE "composite" units such as 'K/m' or 'N/m2' are currently NOT supported. More...
 
double C_TO_K (const double &T)
 
double K_TO_C (const double &T)
 
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 each other) More...
 
template<class T >
bool convertString (T &t, const std::string &str, std::ios_base &(*f)(std::ios_base &)=std::dec)
 Convert a string to the requested type (template function). More...
 
template<class T >
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). More...
 
template<class T >
void getValueForKey (const std::map< std::string, std::string > &properties, const std::string &key, std::vector< T > &vecT, const ThrowOptions &options=IOUtils::dothrow)
 Returns, with the requested type, the value associated to a key (template function). More...
 
template<class T >
standardizeNodata (const T &value, const double &plugin_nodata)
 Standardize a given value to use MeteoIO's internal nodata value (if applicable) More...
 

Variables

const char ALPHANUM [] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
 
const char NUM [] = "0123456789"
 
const double nodata = -999.0
 This is the internal nodata value. More...
 
const unsigned int unodata = static_cast<unsigned int>(-1)
 
const int inodata = -999
 
const short int snodata = -999
 
const size_t npos = static_cast<size_t>(-1)
 npos is the out-of-range value More...
 
const double grid_epsilon = 5.
 What is an acceptable small distance on a grid, in meters. More...
 
const double lon_epsilon = grid_epsilon / Cst::earth_R0 * Cst::to_deg
 in degrees. Small angle for longitudes, so sin(x)=x More...
 
const double lat_epsilon = lon_epsilon
 in degrees. Small angle for latitudes. More...
 

Enumeration Type Documentation

Enumerator
raw 
filtered 
resampled 
generated 
num_of_levels 
Enumerator
dothrow 
nothrow 

Function Documentation

double mio::IOUtils::angle_to_bearing ( const double &  angle)

Converts a trigonometric angle to a compass bearing.

Parameters
angletrigonometric angle (0° on the right, counterclockwise, in [0, 2PI[)
Returns
bearing (0° on top, clockwise, in [0°, 360°[)
double mio::IOUtils::bearing ( std::string  bearing_str)

Converts a string bearing to a compass bearing.

Parameters
bearing_stras N, NE, SSW, etc
Returns
bearing (0° on top, clockwise, in [0°, 360°[)
std::string mio::IOUtils::bearing ( double  bearing)

Converts a compass bearing to a string bearing.

Parameters
bearing(0° on top, clockwise, in [0°, 360°[)
Returns
bearing_str as N, NE, SSW, etc
double mio::IOUtils::bearing_to_angle ( const double &  bearing)

Converts a compass bearing to a trigonometric angle.

Parameters
bearingcompass bearing (0° on top, clockwise, in [0°, 360°[)
Returns
trigonometric angle (0° on the right, counterclockwise, in [0, 2PI[)
double mio::IOUtils::C_TO_K ( const double &  T)
inline
bool mio::IOUtils::checkEpsilonEquality ( const double &  val1,
const double &  val2,
const double &  epsilon 
)
inline

Check whether two values are equal regarding a certain epsilon environment (within certain radius of each other)

Parameters
val1
val2
epsilonis a radius around val1
Returns
true if val2 is within the radius around val1, false otherwise.
template<class T >
bool mio::IOUtils::convertString ( T &  t,
const std::string &  str,
std::ios_base &(*)(std::ios_base &)  f = std::dec 
)

Convert a string to the requested type (template function).

Template Parameters
T[in] The type wanted for the return value (template type parameter).
Parameters
t[out] The value converted to the requested type.
str[in] The input string to convert; trailling whitespaces are ignored, comment after non-string values are allowed, but multiple values are not allowed.
f[in] The radix for reading numbers, such as std::dec or std::oct; default is std::dec.
Returns
true if everything went fine, false otherwise
bool mio::IOUtils::convertString ( Date &  t,
const std::string &  str,
const double &  time_zone,
std::ios_base &(*)(std::ios_base &)  f 
)
template<>
bool mio::IOUtils::convertString< bool > ( bool &  t,
const std::string &  str,
std::ios_base &(*)(std::ios_base &)  f 
)
template<>
bool mio::IOUtils::convertString< Coords > ( Coords &  t,
const std::string &  str,
std::ios_base &(*)(std::ios_base &)  f 
)
template<>
bool mio::IOUtils::convertString< double > ( double &  t,
const std::string &  str,
std::ios_base &(*)(std::ios_base &)  f 
)
template<>
bool mio::IOUtils::convertString< std::string > ( std::string &  t,
const std::string &  str,
std::ios_base &(*)(std::ios_base &)  f 
)
template<>
bool mio::IOUtils::convertString< unsigned int > ( unsigned int &  t,
const std::string &  str,
std::ios_base &(*)(std::ios_base &)  f 
)
void mio::IOUtils::getArraySliceParams ( const size_t &  dimx,
const size_t &  nbworkers,
const size_t &  wk,
size_t &  startx,
size_t &  nx 
)

Returns the parameters for splitting an array in several, balanced sub-arrays. This is mostly usefull for parallel calculations, where an array will be split and sent to different workers.

Parameters
[in]dimxnumber of cells in the desired dimension
[in]nbworkerstotal number of slices
[in]wkcurrent slice index (starting at 1)
[out]startxcalculated start index for the current slice
[out]nxcalculated number of cells (in the desired dimension) of the current slice
std::string mio::IOUtils::getHostName ( )

Retrieve the name of the computer running the binary.

Returns
host name
std::string mio::IOUtils::getLogName ( )

Retrieve the user name This checks various environment variables (USERNAME, USER, LOGNAME).

Returns
user name
void mio::IOUtils::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] section and sets the respective strings to the values of those keywords.

Parameters
[in]cfgA Config object
[out]coordinThe coordinate system to be used for input data
[out]coordinparamThe coordinate system parameters to be used for output data
[out]coordoutThe coordinate system to be used for output data
[out]coordoutparamThe coordinate system parameters to be used for output data
void mio::IOUtils::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.

Parameters
[in]cfgA Config object
[out]tz_invalue to be used for the input timezone
[out]tz_outvalue to be used for the output timezone
template<class T >
void mio::IOUtils::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).

Template Parameters
T[in] The type wanted for the return value (template type parameter).
Parameters
[in]propertiesA map containing all the parameters.
[in]keyThe key of the parameter to retrieve.
[out]tThe value associated to the key, converted to the requested type
[in]optionsExtra options, by default IOUtils::dothrow
template<class T >
void mio::IOUtils::getValueForKey ( const std::map< std::string, std::string > &  properties,
const std::string &  key,
std::vector< T > &  vecT,
const ThrowOptions &  options = IOUtils::dothrow 
)

Returns, with the requested type, the value associated to a key (template function).

Template Parameters
T[in] The type wanted for the return value (template type parameter).
Parameters
[in]propertiesA map containing all the parameters.
[in]keyThe key of the parameter to retrieve.
[out]vecTThe vector of values associated to the key, each value is converted to the requested type
[in]optionsExtra options, by default IOUtils::dothrow
bool mio::IOUtils::isNumeric ( std::string  str,
const unsigned int &  nBase 
)
double mio::IOUtils::K_TO_C ( const double &  T)
inline
bool mio::IOUtils::readKeyValuePair ( const std::string &  in_line,
const std::string &  delimiter,
std::string &  key,
std::string &  value,
const bool &  setToUpperCase = false 
)

read a string line, parse it and save it into a map object, that is passed by reference

Parameters
in_line(const string&) string to parse
delimiter(const string&) delimiter to use for the parsing
setToUpperCaseIf set to true the key will be put into upper case (for case insensitivity)
keyretrieved key
valueretrieved value
Returns
(bool) true when line is empty
size_t mio::IOUtils::readLineToVec ( const std::string &  line_in,
std::vector< double > &  vec_data 
)
size_t mio::IOUtils::readLineToVec ( const std::string &  line_in,
std::vector< std::string > &  vecString 
)
size_t mio::IOUtils::readLineToVec ( const std::string &  line_in,
std::vector< std::string > &  vecString,
const char &  delim 
)
size_t mio::IOUtils::seek ( const Date &  soughtdate,
const std::vector< MeteoData > &  vecM,
const bool &  exactmatch = true 
)

Search for an element at a given date in a vector of MeteoData. The position of the matching date is returned or IOUtils::npos if not found. If exactmatch=false, the position of the first element after soughtdate is returned (or IOUtils::npos if this is not possible / relevant).

Parameters
[in]soughtdatedate that should be found
[in]vecMvector that should contain the data
[in]exactmatchif the exact requested date is not found, return npos
template<class T >
T mio::IOUtils::standardizeNodata ( const T &  value,
const double &  plugin_nodata 
)

Standardize a given value to use MeteoIO's internal nodata value (if applicable)

Template Parameters
T[in]The type wanted for the return value (template type parameter).
Parameters
[in]valuethe value to check/convert
[in]plugin_nodataplugin-specific nodata value
Returns
checked/converted value
void mio::IOUtils::stripComments ( std::string &  str)
std::string mio::IOUtils::strToLower ( std::string  str)
std::string mio::IOUtils::strToUpper ( std::string  str)
void mio::IOUtils::toLower ( std::string &  str)
void mio::IOUtils::toUpper ( std::string &  str)
void mio::IOUtils::trim ( std::string &  s)

Removes trailing and leading whitespaces, tabs and newlines from a string.

Parameters
sThe reference of the string to trim (in/out parameter)
double mio::IOUtils::unitsConversion ( const double &  val,
std::string  unitIn,
std::string  unitOut 
)

Performs simple unit conversion (supports temperature, prefixes and exponents) NOTE "composite" units such as 'K/m' or 'N/m2' are currently NOT supported.

Parameters
valvalue to convert
unitInunits of the input
unitOutunits to convert to return value, expressed in unitOut
double mio::IOUtils::unitsPrefix ( const char &  prefix)

Convert a textual representation of a unit prefix (like 'm' or 'G') to multiplying factor.

Parameters
prefixunit prefix return multiplying factor

Variable Documentation

const char mio::IOUtils::ALPHANUM[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
const double mio::IOUtils::grid_epsilon = 5.

What is an acceptable small distance on a grid, in meters.

const int mio::IOUtils::inodata = -999
const double mio::IOUtils::lat_epsilon = lon_epsilon

in degrees. Small angle for latitudes.

const double mio::IOUtils::lon_epsilon = grid_epsilon / Cst::earth_R0 * Cst::to_deg

in degrees. Small angle for longitudes, so sin(x)=x

const double mio::IOUtils::nodata = -999.0

This is the internal nodata value.

const size_t mio::IOUtils::npos = static_cast<size_t>(-1)

npos is the out-of-range value

const char mio::IOUtils::NUM[] = "0123456789"
const short int mio::IOUtils::snodata = -999
const unsigned int mio::IOUtils::unodata = static_cast<unsigned int>(-1)