MeteoIODoc  MeteoIODoc-2.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImisIO.h
Go to the documentation of this file.
1 /***********************************************************************************/
2 /* Copyright 2009, 2010 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
3 /***********************************************************************************/
4 /* This file is part of MeteoIO.
5  MeteoIO is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  MeteoIO is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef IMISIO_H
19 #define IMISIO_H
20 
21 #include <meteoio/IOInterface.h>
22 
23 #include <string>
24 #include <map>
25 #include <vector>
26 #include <occi.h>
27 
28 namespace mio {
29 
30 class AnetzData{
31  public:
33  : nrOfAnetzStations(3), nrOfCoefficients(3), coeffs(3, IOUtils::nodata), anetzstations(3, "") {}
34 
35  AnetzData(const size_t& nr_anetz,
36  const std::string& i_anetz1, const std::string& i_anetz2, const std::string& i_anetz3,
37  const size_t& nr_coeffs,
38  const double& coeff1, const double& coeff2, const double& coeff3)
39  : nrOfAnetzStations(nr_anetz), nrOfCoefficients(nr_coeffs), coeffs(3), anetzstations(3)
40  {
41  anetzstations[0] = i_anetz1;
42  anetzstations[1] = i_anetz2;
43  anetzstations[2] = i_anetz3;
44  coeffs[0] = coeff1;
45  coeffs[1] = coeff2;
46  coeffs[2] = coeff3;
47  }
48 
50  std::vector<double> coeffs;
51  std::vector<std::string> anetzstations;
52 };
53 
63 class ImisIO : public IOInterface {
64  public:
65  ImisIO(const std::string& configfile);
66  ImisIO(const ImisIO&);
67  ImisIO(const Config&);
68 
69  virtual void readStationData(const Date& date, std::vector<StationData>& vecStation);
70  virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
71  std::vector< std::vector<MeteoData> >& vecMeteo);
72 
73  private:
74  void openDBConnection(oracle::occi::Environment*& env, oracle::occi::Connection*& conn);
75  void closeDBConnection(oracle::occi::Environment*& env, oracle::occi::Connection*& conn);
76  void getDBParameters();
77 
78  size_t getStationIDs(const std::string& stat_code,
79  const std::string& sqlQuery, std::vector<std::string>& vecStationMetaData,
80  oracle::occi::Statement*& stmt);
81  size_t getStationMetaData(const std::string& stat_abk, const std::string& stao_nr,
82  const std::string& sqlQuery, std::vector<std::string>& vecMetaData,
83  oracle::occi::Statement*& stmt);
84  size_t getSensorDepths(const std::string& stat_abk, const std::string& stao_nr,
85  const std::string& sqlQuery, std::vector<std::string>& vecHTS1,
86  oracle::occi::Statement*& stmt);
87  bool getStationData(const std::string& stat_abk, const std::string& stao_nr,
88  const Date& dateS, const Date& dateE,
89  const std::vector<std::string>& i_vecHTS1,
90  std::vector< std::vector<std::string> >& vecMeteoData,
91  oracle::occi::Environment*& env, oracle::occi::Statement*& stmt);
92 
93  void parseDataSet(const std::vector<std::string>& meteo_in, MeteoData& md, bool& _fullStation);
94  void readData(const Date& dateStart, const Date& dateEnd, std::vector< std::vector<MeteoData> >& vecMeteo,
95  const size_t& stationindex, const std::vector<StationData>& vecStationID,
96  oracle::occi::Environment*& env, oracle::occi::Statement*& stmt);
97  void readSWE(const Date& dateStart, const Date& dateEnd, std::vector< std::vector<MeteoData> >& vecMeteo,
98  const size_t& stationindex, const std::vector<StationData>& vecStationIDs,
99  oracle::occi::Environment*& env, oracle::occi::Statement*& stmt);
100  void readStationIDs(std::vector<std::string>& vecStationID);
101  void parseStationID(const std::string& stationID, std::string& stnAbbrev, std::string& stnNumber);
102 
103  void readStationMetaData(oracle::occi::Connection*& conn);
104  void convertSnowTemperature(MeteoData& meteo, const std::string& parameter);
105  void convertSensorDepth(MeteoData& meteo, const std::string& parameter);
106  void convertUnits(MeteoData& meteo);
107 
108  //helper functions for the Anetz coefficient mangling:
109  void findAnetzStations(std::map<std::string, size_t>& mapAnetzNames, std::vector<StationData>& vecAnetzStation);
110  void assimilateAnetzData(const AnetzData& ad,
111  const std::map<std::string, size_t>& mapAnetzNames, const std::vector< std::vector< std::pair<Date, double> > > &vecPsum,
112  const size_t& stationindex, std::vector< std::vector<MeteoData> >& vecMeteo);
113  void computeAnetzPSUM(std::vector<MeteoData> &vecMeteo, std::vector< std::pair<Date, double> > &vecPsum);
114 
115  static const double in_tz; //timezone
116  const Config cfg;
117  std::string coordin, coordinparam, coordout, coordoutparam; //projection parameters
118  std::vector<StationData> vecStationMetaData;
119  std::map<std::string, std::string> mapDriftStation;
120  static const double plugin_nodata; //plugin specific nodata value, e.g. -999
121  static const std::string sqlQueryStationIDs;
122  static const std::string sqlQueryStationMetaData;
123  static const std::string sqlQuerySensorDepths;
124  static const std::string sqlQueryMeteoDataDrift; // combined snow_drift query from two stations (ams.v_ams_raw)
125  static const std::string sqlQueryMeteoData; // single station query (ams.v_ams_raw)
126  static const std::string sqlQuerySWEData; //SWE as computed by SNOWPACK
127  std::string oracleUserName_in;
128  std::string oraclePassword_in;
129  std::string oracleDBName_in;
130  bool useAnetz, use_imis_psum, use_psum_snowpack;
131 
132  static std::map<std::string, AnetzData> mapAnetz;
133  static const bool __init;
134  static bool initStaticData();
135 };
136 
137 } //end namespace mio
138 
139 #endif
140 
ImisIO(const std::string &configfile)
Definition: ImisIO.cc:215
size_t nrOfCoefficients
Definition: ImisIO.h:49
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:372
Definition: ImisIO.h:30
AnetzData()
Definition: ImisIO.h:32
A class representing the IO Layer of the software Alpine3D. For each type of IO (File, DB, Webservice, etc) a derived class is to be created that holds the specific implementation of the appropriate virtual methods. The IOHandler class is a wrapper class that is able to deal with all above implementations of the IOInterface abstract base class.
Definition: IOInterface.h:43
std::vector< double > coeffs
Definition: ImisIO.h:50
virtual void readStationData(const Date &date, std::vector< StationData > &vecStation)
Fill vecStation with StationData objects for a certain date of interest.
Definition: ImisIO.cc:251
size_t nrOfAnetzStations
Definition: ImisIO.h:49
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:35
The class with-in the data from the database are treated. The MeteoData and the StationData will be s...
Definition: ImisIO.h:63
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition: Config.h:58
const double nodata
This is the internal nodata value.
Definition: IOUtils.h:60
std::vector< std::string > anetzstations
Definition: ImisIO.h:51
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:79
A class to represent a singular measurement received from one station at a certain time (represented ...
Definition: MeteoData.h:101