MeteoIODoc 2.11.0
smet::SMETWriter Class Reference

Detailed Description

The SMETWriter class that enables to write a SMET formatted file. The user constructs a SMETWriter class and fills in the header values Finally the user may call write(...) and pass the data to be written.

Author
Thomas Egger
Date
2011-07-14

#include <libsmet.h>

Public Member Functions

 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. More...
 
 SMETWriter (const std::string &in_filename, const std::string &in_fields, const double &in_nodata)
 The constructor allows to append data to an existing file. More...
 
void set_header_value (const std::string &key, const std::string &value)
 Set a key, value pair in the SMET header (both strings) More...
 
void set_header_value (const std::string &key, const double &value)
 Set a double value for a string key in a SMET header. More...
 
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. More...
 
void write (const std::vector< double > &data, const mio::ACDD &acdd)
 Write a SMET file, providing a vector of doubles. More...
 
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 column. More...
 
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. More...
 
void set_separator (const char &i_separator)
 For some special cases (import into DB), the white space separator should be replaced by another one (typically, comma). In this case, each field will be delimited by a single separator but the headers will remain space-delimited. More...
 
void set_commented_headers (const bool &flag)
 For some special cases (import into DB), the headers should be commented out (please note that this breaks SMET conformance) More...
 
const std::string toString () const
 

Constructor & Destructor Documentation

◆ SMETWriter() [1/2]

smet::SMETWriter::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.

Parameters
[in]in_filenameThe filename of the SMET file to be written
[in]in_typeThe type of the SMET file, i.e. smet::ASCII or smet::BINARY (default: ASCII)

◆ SMETWriter() [2/2]

smet::SMETWriter::SMETWriter ( const std::string &  in_filename,
const std::string &  in_fields,
const double &  in_nodata 
)

The constructor allows to append data to an existing file.

Parameters
[in]in_filenameThe filename of the SMET file to be written
[in]in_fieldsThe fields that should be written in order to check that we write the same data at the same place.
[in]in_nodataValue representing nodata

Member Function Documentation

◆ set_commented_headers()

void smet::SMETWriter::set_commented_headers ( const bool &  flag)
inline

For some special cases (import into DB), the headers should be commented out (please note that this breaks SMET conformance)

Parameters
[in]flagshould headers be commented out?

◆ set_header_value() [1/2]

void smet::SMETWriter::set_header_value ( const std::string &  key,
const double &  value 
)

Set a double value for a string key in a SMET header.

Parameters
[in]keyA string key to set in the header (overwritten if already present)
[in]valueA double value to be converted into a string and stored in the header

◆ set_header_value() [2/2]

void smet::SMETWriter::set_header_value ( const std::string &  key,
const std::string &  value 
)

Set a key, value pair in the SMET header (both strings)

Parameters
[in]keyA string key to set in the header (overwritten if already present)
[in]valueA string value associated with the key

◆ set_precision()

void smet::SMETWriter::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 column.

Parameters
[in]vec_precisionSet the precision for every column to be written (timestamp is not counted if present)

◆ set_separator()

void smet::SMETWriter::set_separator ( const char &  i_separator)

For some special cases (import into DB), the white space separator should be replaced by another one (typically, comma). In this case, each field will be delimited by a single separator but the headers will remain space-delimited.

Parameters
[in]i_separatorfield separator to use instead of spaces

◆ set_width()

void smet::SMETWriter::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.

Parameters
[in]vec_widthSet the width for every column to be written (timestamp is not counted if present)

◆ toString()

const std::string smet::SMETWriter::toString ( ) const

◆ write() [1/2]

void smet::SMETWriter::write ( const std::vector< double > &  data,
const mio::ACDD acdd 
)

Write a SMET file, providing a vector of doubles.

Parameters
[in]dataAll the data to be written sequentially into the columns, the data is aligned sequentially, not per line;
[in]acddACDD object that contains acdd metadata

◆ write() [2/2]

void smet::SMETWriter::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.

Parameters
[in]vec_timestampA vector with one ASCII date/time combined string for each line
[in]dataAll the data to be written sequentially into the columns, the data is aligned sequentially, not per line; Total size of the vector: Total size of the vector: vec_timestamp.size() * nr_of_fields (timestamp is not counted as field)
[in]acddACDD object that contains acdd metadata

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