MeteoIODoc 2.11.0
ImisIO.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2009, 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 IMISIO_H
20#define IMISIO_H
21
22#include <meteoio/IOInterface.h>
23
24#include <string>
25#include <map>
26#include <vector>
27#include <occi.h>
28
29namespace mio {
30
32 public:
34 : anetzstations(3, ""), coeffs(3, IOUtils::nodata), nrOfAnetzStations(3), nrOfCoefficients(3) {}
35
36 AnetzData(const size_t& nr_anetz,
37 const std::string& i_anetz1, const std::string& i_anetz2, const std::string& i_anetz3,
38 const size_t& nr_coeffs,
39 const double& coeff1, const double& coeff2, const double& coeff3)
40 : anetzstations(3), coeffs(3), nrOfAnetzStations(nr_anetz), nrOfCoefficients(nr_coeffs)
41 {
42 anetzstations[0] = i_anetz1;
43 anetzstations[1] = i_anetz2;
44 anetzstations[2] = i_anetz3;
45 coeffs[0] = coeff1;
46 coeffs[1] = coeff2;
47 coeffs[2] = coeff3;
48 }
49
50 std::vector<std::string> anetzstations;
51 std::vector<double> coeffs;
53};
54
64class ImisIO : public IOInterface {
65 public:
66 ImisIO(const std::string& configfile);
67 ImisIO(const ImisIO&);
68 ImisIO(const Config&);
69
70 virtual void readStationData(const Date& date, std::vector<StationData>& vecStation);
71 virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
72 std::vector< std::vector<MeteoData> >& vecMeteo);
73
74 private:
75 void openDBConnection(oracle::occi::Environment*& env, oracle::occi::Connection*& conn) const;
76 void closeDBConnection(oracle::occi::Environment*& env, oracle::occi::Connection*& conn) const;
77 void getDBParameters();
78
79 std::vector<std::string> getStationIDs(const std::string& stat_code,
80 const std::string& sqlQuery, oracle::occi::Statement*& stmt) const;
81 std::vector<std::string> getStationMetaData(const std::string& stat_abk, const std::string& stao_nr,
82 const std::string& sqlQuery, oracle::occi::Statement*& stmt) const;
83 std::vector<std::string> getSensorDepths(const std::string& stat_abk, const std::string& stao_nr,
84 const std::string& sqlQuery, oracle::occi::Statement*& stmt) const;
85 bool getStationData(const std::string& stat_abk, const std::string& stao_nr,
86 const Date& dateS, const Date& dateE,
87 const std::vector<std::string>& i_vecHTS1,
88 std::vector< std::vector<std::string> >& vecMeteoData,
89 oracle::occi::Environment*& env, oracle::occi::Statement*& stmt);
90
91 static void parseDataSet(const std::vector<std::string>& meteo_in, MeteoData& md, const bool& fullStation);
92 void readData(const Date& dateStart, const Date& dateEnd, std::vector< std::vector<MeteoData> >& vecMeteo,
93 const size_t& stationindex, const std::vector<StationData>& vecStationID,
94 oracle::occi::Environment*& env, oracle::occi::Statement*& stmt);
95 void readSWE(const Date& dateStart, const Date& dateEnd, std::vector< std::vector<MeteoData> >& vecMeteo,
96 const size_t& stationindex, const std::vector<StationData>& vecStationIDs,
97 oracle::occi::Environment*& env, oracle::occi::Statement*& stmt);
98 std::vector<std::string> readStationIDs();
99 static void parseStationID(const std::string& stationID, std::string& stnAbbrev, std::string& stnNumber);
100
101 void readStationMetaData(oracle::occi::Connection*& conn);
102 void convertSnowTemperature(MeteoData& meteo, const std::string& parameter);
103 void convertSensorDepth(MeteoData& meteo, const std::string& parameter);
104 void convertUnits(MeteoData& meteo, const bool& reduce_pressure);
105
106 //helper functions for the Anetz coefficient mangling:
107 void findAnetzStations(std::map<std::string, size_t>& mapAnetzNames, std::vector<StationData>& vecAnetzStation) const;
108 void assimilateAnetzData(const AnetzData& ad,
109 const std::map<std::string, size_t>& mapAnetzNames, const std::vector< std::vector< std::pair<Date, double> > > &vecPsum,
110 const size_t& stationindex, std::vector< std::vector<MeteoData> >& vecMeteo);
111 static std::vector< std::pair<Date, double> > computeAnetzPSUM(std::vector<MeteoData> &vecMeteo);
112
113 static const double in_tz; //timezone
114 const Config cfg;
115 std::string coordout, coordoutparam; //projection parameters
116 std::vector<StationData> vecStationMetaData;
117 std::map<std::string, std::string> mapDriftStation;
118 static const double plugin_nodata; //plugin specific nodata value, e.g. -999
119 static const std::string sqlQueryStationIDs;
120 static const std::string sqlQueryStationMetaData;
121 static const std::string sqlQuerySensorDepths;
122 static const std::string sqlQueryMeteoDataDrift; // combined snow_drift query from two stations (ams.v_ams_raw)
123 static const std::string sqlQueryMeteoData; // single station query (ams.v_ams_raw)
124 static const std::string sqlQuerySWEData; //SWE as computed by SNOWPACK
125 static const std::string coordin, coordinparam; //these are fixed for IMIS
126 std::string oracleUserName_in;
127 std::string oraclePassword_in;
128 std::string oracleDBName_in;
129 bool useAnetz, use_imis_psum, use_psum_snowpack;
130
131 static std::map<std::string, AnetzData> mapAnetz;
132 static std::map< std::string, std::pair<double, double> > mapSlopes;
133 static const bool __init;
134 static bool initStaticData();
135};
136
137} //end namespace mio
138
139#endif
140
Definition: ImisIO.h:31
size_t nrOfAnetzStations
Definition: ImisIO.h:52
std::vector< double > coeffs
Definition: ImisIO.h:51
std::vector< std::string > anetzstations
Definition: ImisIO.h:50
AnetzData(const size_t &nr_anetz, const std::string &i_anetz1, const std::string &i_anetz2, const std::string &i_anetz3, const size_t &nr_coeffs, const double &coeff1, const double &coeff2, const double &coeff3)
Definition: ImisIO.h:36
size_t nrOfCoefficients
Definition: ImisIO.h:52
AnetzData()
Definition: ImisIO.h:33
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
The class with-in the data from the database are treated. The MeteoData and the StationData will be s...
Definition: ImisIO.h:64
ImisIO(const std::string &configfile)
Definition: ImisIO.cc:249
ImisIO(const ImisIO &)
virtual void readStationData(const Date &date, std::vector< StationData > &vecStation)
Fill vecStation with StationData objects for a certain date of interest.
Definition: ImisIO.cc:285
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: ImisIO.cc:411
A class to represent a singular measurement received from one station at a certain time (represented ...
Definition: MeteoData.h:107
const double nodata
This is the internal nodata value.
Definition: IOUtils.h:75
Definition: Config.cc:31