MeteoIODoc 2.11.0
SMETIO.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2010 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
4/***********************************************************************************/
5/* This file is part of MeteoIO.
6 MeteoIO is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MeteoIO is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef SMETIO_H
20#define SMETIO_H
21
22#include <meteoio/IOInterface.h>
25
26#include <string>
27#include <vector>
28
29#ifdef _MSC_VER
30 #pragma warning(disable:4512) //we don't need any = operator!
31#endif
32
33namespace mio {
42class SMETIO : public IOInterface {
43 public:
44 SMETIO(const std::string& configfile);
45 SMETIO(const SMETIO&);
46 SMETIO(const Config& cfgreader);
47
48 virtual void readStationData(const Date& date, std::vector<StationData>& vecStation);
49 virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
50 std::vector< std::vector<MeteoData> >& vecMeteo);
51
52 virtual void writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMeteo,
53 const std::string& name="");
54
55 virtual void readPOI(std::vector<Coords>& pts);
56
57 private:
59 typedef struct PLOT_ATTR {
60 PLOT_ATTR() : units(), description(), color(), min(IOUtils::nodata), max(IOUtils::nodata) {} //please do NOT use this constructor!
61 PLOT_ATTR(const std::string& i_units, const std::string& i_description, const std::string& i_color) : units(i_units), description(i_description), color(i_color), min(IOUtils::nodata), max(IOUtils::nodata) {}
62 PLOT_ATTR(const std::string& i_units, const std::string& i_description, const std::string& i_color, const double& i_min, const double& i_max) : units(i_units), description(i_description), color(i_color), min(i_min), max(i_max) {}
63 PLOT_ATTR(const size_t& parindex, const std::string& i_color, const double& i_min, const double& i_max) : units(MeteoGrids::getParameterUnits(parindex)), description(MeteoGrids::getParameterDescription(parindex, false)), color(i_color), min(i_min), max(i_max) {}
64
65 std::string units;
66 std::string description;
67 std::string color;
68 double min;
69 double max;
70 } plot_attr;
71
72 typedef enum VERSIONING_TYPE {
73 NO_VERSIONING,
74 NOW,
75 DATA_START,
76 DATA_END,
77 DATA_YEARS
78 } VersioningType;
79
80 static std::map<std::string, plot_attr> initPlotParams();
81 static double getSnowpackSlope(const std::string& id);
82 void read_meta_data(const smet::SMETReader& myreader, StationData& meta);
83 void identify_fields(const std::vector<std::string>& fields, std::vector<size_t>& indexes,
84 bool& julian_present, MeteoData& md);
85 void populateMeteo(const smet::SMETReader& myreader, const std::vector<std::string>& timestamps,
86 const std::vector<double>& mydata, std::vector<MeteoData>& vecMeteo);
87
88 void parseInputOutputSection();
89 bool checkConsistency(const std::vector<MeteoData>& vecMeteo, StationData& sd);
90 size_t getNrOfParameters(const std::string& stationname, const std::vector<MeteoData>& vecMeteo);
91 bool getPlotProperties(std::string param, std::ostringstream &plot_units, std::ostringstream &plot_description, std::ostringstream &plot_color, std::ostringstream &plot_min, std::ostringstream &plot_max) const;
92 void getFormatting(const std::string& parname, int& prec, int& width) const;
93 std::string buildVersionString(const std::vector< std::vector<MeteoData> >& vecMeteo, const double& smet_timezone) const;
94 double olwr_to_tss(const double& olwr);
95 void generateHeaderInfo(const StationData& sd, const bool& i_outputIsAscii, const bool& isConsistent,
96 const double& smet_timezone, const std::set<std::string>& paramInUse, smet::SMETWriter& mywriter);
97
98 static const char* dflt_extension;
99 static const double snVirtualSlopeAngle;
100 const Config cfg;
101 ACDD acdd;
102 std::map<std::string, plot_attr> plot_ppt;
103 std::string coordin, coordinparam, coordout, coordoutparam; //default projection parameters
104 std::vector<smet::SMETReader> vec_smet_reader;
105 std::vector<std::string> vecFiles; //read from the Config [Input] section
106 std::string outpath; //read from the Config [Output] section
107 double out_dflt_TZ; //default time zone
108 double plugin_nodata;
109 int default_prec, default_width; //output default precision and width
110 char output_separator; //output field separator
111 VersioningType outputVersioning; //this is usefull when generating multiple versions of the same dataset, for example with forecast data
112 bool outputCommentedHeaders; //prefix all headers with a '#' for easy import into dbs but breaks SMET conformance
113 bool outputIsAscii, outputPlotHeaders, randomColors, allowAppend, allowOverwrite, snowpack_slopes;//read from the Config [Output] section
114 // the default values of allowOverwrite and allowAppend should be kept as they are, to allow backward compatibility
115};
116
117} //namespace
118#endif
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition: Config.h:79
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
A class representing the IO Layer of the software Alpine3D. For each type of IO (File,...
Definition: IOInterface.h:98
Reads meteo data in the SMET ASCII or binary format.
Definition: SMETIO.h:42
SMETIO(const SMETIO &)
SMETIO(const std::string &configfile)
Definition: SMETIO.cc:117
virtual void readMeteoData(const Date &dateStart, const Date &dateEnd, std::vector< std::vector< MeteoData > > &vecMeteo)
Fill vecMeteo with a time series of objects corresponding to the interval indicated by dateStart and ...
Definition: SMETIO.cc:507
virtual void writeMeteoData(const std::vector< std::vector< MeteoData > > &vecMeteo, const std::string &name="")
Write vecMeteo time series to a certain destination.
Definition: SMETIO.cc:574
virtual void readStationData(const Date &date, std::vector< StationData > &vecStation)
Fill vecStation with StationData objects for a certain date of interest.
Definition: SMETIO.cc:264
virtual void readPOI(std::vector< Coords > &pts)
Read a list of points by their grid coordinates This allows for example to get a list of points where...
Definition: SMETIO.cc:905
The SMETReader class enables to read a SMET formatted file. Data and header info can be extracted thr...
Definition: libsmet.h:221
The SMETWriter class that enables to write a SMET formatted file. The user constructs a SMETWriter cl...
Definition: libsmet.h:99
const double nodata
This is the internal nodata value.
Definition: IOUtils.h:75
Definition: Config.cc:31
std::string getParameterDescription(const size_t &param)
Definition: libncpp.cc:649
std::string getParameterUnits(const size_t &param)
Definition: libncpp.cc:655