MeteoIODoc 20240507.aefd3c94
mio::iCSV::iCSVFile Class Reference

Detailed Description

This class is responsible for handling and storing iCSV files.

General information about the file is stored as public members, the station_location is an additional member. The MetaData is stored in the METADATA member, and the fields are stored in the FIELDS member.

It is possible to store all the data as well with read_sequential= false

Format checking is done on initialization.

Getters are provided to access the data, Metadata is directly accessed.

#include <iCSVHelper.h>

Public Member Functions

 iCSVFile ()
 
 iCSVFile (const iCSVFile &)
 
 iCSVFile (const std::string &infile, const bool &read_sequential)
 Reads a iCSV file, and checks the format. More...
 
void readFile (const std::string &infile, const bool &sequentially)
 
bool checkFormatValidity ()
 Checks the validity of the format for the iCSVFile. More...
 
bool checkMeteoIOCompatibility () const
 
void parseGeometry ()
 Parses the geometry information of the iCSV file. More...
 
double getNoData () const
 
double getTimeZone () const
 
const std::vector< std::vector< double > > & getRowData () const
 
const std::vector< Date > & getAllDatesInFile () const
 
const std::vector< geoLocation > & getAllLocationsInData () const
 
geoLocation getLocationAt (size_t index) const
 
std::vector< DategetDatesInFile (const Date &start_date, const Date &end_date) const
 
std::vector< geoLocationgetLocationsInData (const Date &start_date, const Date &end_date) const
 
bool processLine (const std::string &line, std::string &section, const bool &sequentially)
 
void processContent (const std::string &content, const std::string &section)
 
void processData (const std::string &content)
 
bool isValidLocation (const geoLocation &location)
 
bool isColumnName (const std::string &geometry)
 
void findTime ()
 
void findLocation ()
 
std::vector< std::string > columnsToAppend (const std::vector< MeteoData > &vecMeteo) const
 
double readData (const Date &r_date, const std::string &fieldname)
 
void aggregateData (const std::vector< MeteoData > &vecMeteo)
 
void populateMetaData (const std::string &key, const std::string &value)
 
void populateFields (const std::string &key, const std::string &value)
 

Public Attributes

size_t skip_lines_to_data
 
std::string filename
 
std::string firstline
 
geoLocation station_location
 
MetaDataSection METADATA
 
fieldsSection FIELDS
 
bool location_in_header = true
 
bool timezone_in_data = false
 
bool timestamp_present = false
 
bool julian_present = false
 
size_t time_id = IOUtils::npos
 
size_t location_id = IOUtils::npos
 

Constructor & Destructor Documentation

◆ iCSVFile() [1/3]

mio::iCSV::iCSVFile::iCSVFile ( )

◆ iCSVFile() [2/3]

mio::iCSV::iCSVFile::iCSVFile ( const iCSVFile other)

◆ iCSVFile() [3/3]

mio::iCSV::iCSVFile::iCSVFile ( const std::string &  infile,
const bool &  read_sequential 
)

Reads a iCSV file, and checks the format.

iCSVFile constructor

The data is only read if read_sequential is set to false. Otherwise, only the HEADER is processed

Parameters
[in]infileThe path to the input file.
[in]read_sequentialIf true, only HEADER will be processed.

Member Function Documentation

◆ aggregateData()

void mio::iCSV::iCSVFile::aggregateData ( const std::vector< MeteoData > &  vecMeteo)

Aggregates data from the given vector of MeteoData objects.

Parameters
[in]vecMeteoThe vector of MeteoData objects to aggregate.
Exceptions
IOExceptionif the vector is empty.

◆ checkFormatValidity()

bool mio::iCSV::iCSVFile::checkFormatValidity ( )

Checks the validity of the format for the iCSVFile.

Returns
true if the format is valid, false otherwise.

◆ checkMeteoIOCompatibility()

bool mio::iCSV::iCSVFile::checkMeteoIOCompatibility ( ) const

Checks the compatibility of the iCSV file with MeteoIO.

Returns
true if the iCSV file is compatible with MeteoIO, false otherwise.

◆ columnsToAppend()

std::vector< std::string > mio::iCSV::iCSVFile::columnsToAppend ( const std::vector< MeteoData > &  vecMeteo) const

Finds parameters, that are used in MeteoIO but not given in a iCSV file.

Parameters
[in]vecMeteoThe vector of MeteoData objects to compare with.
Returns
A vector of strings containing the parameters to append.
Exceptions
IOExceptionif the vector is empty.

◆ findLocation()

void mio::iCSV::iCSVFile::findLocation ( )

◆ findTime()

void mio::iCSV::iCSVFile::findTime ( )

◆ getAllDatesInFile()

const std::vector< Date > & mio::iCSV::iCSVFile::getAllDatesInFile ( ) const
inline

◆ getAllLocationsInData()

const std::vector< geoLocation > & mio::iCSV::iCSVFile::getAllLocationsInData ( ) const
inline

◆ getDatesInFile()

std::vector< Date > mio::iCSV::iCSVFile::getDatesInFile ( const Date start_date,
const Date end_date 
) const
inline

◆ getLocationAt()

geoLocation mio::iCSV::iCSVFile::getLocationAt ( size_t  index) const
inline

◆ getLocationsInData()

std::vector< geoLocation > mio::iCSV::iCSVFile::getLocationsInData ( const Date start_date,
const Date end_date 
) const
inline

◆ getNoData()

double mio::iCSV::iCSVFile::getNoData ( ) const
inline

◆ getRowData()

const std::vector< std::vector< double > > & mio::iCSV::iCSVFile::getRowData ( ) const
inline

◆ getTimeZone()

double mio::iCSV::iCSVFile::getTimeZone ( ) const
inline

◆ isColumnName()

bool mio::iCSV::iCSVFile::isColumnName ( const std::string &  geometry)

◆ isValidLocation()

bool mio::iCSV::iCSVFile::isValidLocation ( const geoLocation location)

◆ parseGeometry()

void mio::iCSV::iCSVFile::parseGeometry ( )

Parses the geometry information of the iCSV file.

This function extracts the coordinates from the metadata and checks if they are valid. If the coordinates are empty or not a known WKTS station location, an exception is thrown. If the z-coordinate is set to the default nodata value, it is updated to the actual nodata value. Finally, the station location is updated with the parsed coordinates.

Exceptions
IOExceptionif the geometry is neither a column name nor a known WKTS station location, or if the location is invalid.

◆ populateFields()

void mio::iCSV::iCSVFile::populateFields ( const std::string &  key,
const std::string &  value 
)

◆ populateMetaData()

void mio::iCSV::iCSVFile::populateMetaData ( const std::string &  key,
const std::string &  value 
)

◆ processContent()

void mio::iCSV::iCSVFile::processContent ( const std::string &  content,
const std::string &  section 
)

◆ processData()

void mio::iCSV::iCSVFile::processData ( const std::string &  content)

◆ processLine()

bool mio::iCSV::iCSVFile::processLine ( const std::string &  line,
std::string &  section,
const bool &  sequentially 
)

◆ readData()

double mio::iCSV::iCSVFile::readData ( const Date r_date,
const std::string &  fieldname 
)

Reads the data for a given date and fieldname from the iCSV file.

Parameters
[in]r_dateThe date for which to read the data.
[in]fieldnameThe name of the field for which to read the data.
Returns
The data value for the given date and fieldname.
Exceptions
IOExceptionIf there is no data available or if the date is out of range.

◆ readFile()

void mio::iCSV::iCSVFile::readFile ( const std::string &  infile,
const bool &  sequentially 
)

Reads the contents of a iCSV file.

Parameters
[in]infileThe path of the input file to be read.
[in]sequentiallyFlag indicating whether to read the data
Exceptions
IOExceptionIf there is an error opening or reading the file.
InvalidFormatExceptionIf the iCSV file format is invalid.

Member Data Documentation

◆ FIELDS

fieldsSection mio::iCSV::iCSVFile::FIELDS

◆ filename

std::string mio::iCSV::iCSVFile::filename

◆ firstline

std::string mio::iCSV::iCSVFile::firstline

◆ julian_present

bool mio::iCSV::iCSVFile::julian_present = false

◆ location_id

size_t mio::iCSV::iCSVFile::location_id = IOUtils::npos

◆ location_in_header

bool mio::iCSV::iCSVFile::location_in_header = true

◆ METADATA

MetaDataSection mio::iCSV::iCSVFile::METADATA

◆ skip_lines_to_data

size_t mio::iCSV::iCSVFile::skip_lines_to_data

◆ station_location

geoLocation mio::iCSV::iCSVFile::station_location

◆ time_id

size_t mio::iCSV::iCSVFile::time_id = IOUtils::npos

◆ timestamp_present

bool mio::iCSV::iCSVFile::timestamp_present = false

◆ timezone_in_data

bool mio::iCSV::iCSVFile::timezone_in_data = false

The documentation for this class was generated from the following files: