WSL/SLF GitLab Repository

ImisIO.h 6.53 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/***********************************************************************************/
/*  Copyright 2009, 2010 WSL Institute for Snow and Avalanche Research   SLF-DAVOS */
/***********************************************************************************/
/* This file is part of MeteoIO.
    MeteoIO is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    MeteoIO is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with MeteoIO.  If not, see <http://www.gnu.org/licenses/>.
*/
18
19
#ifndef IMISIO_H
#define IMISIO_H
20

21
#include <meteoio/IOInterface.h>
22
23

#include <string>
24
#include <map>
25
26
27
28
29
#include <vector>
#include <occi.h>

namespace mio {

30
31
class AnetzData{
	public:
32
		AnetzData()
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
42
43
44
45
46
			anetzstations[0] = i_anetz1;
			anetzstations[1] = i_anetz2;
			anetzstations[2] = i_anetz3;
			coeffs[0] = coeff1;
			coeffs[1] = coeff2;
			coeffs[2] = coeff3;
47
48
		}

49
		size_t nrOfAnetzStations, nrOfCoefficients;
50
51
52
		std::vector<double> coeffs;
		std::vector<std::string> anetzstations;
};
53

54
55
56
57
/**
 * @class ImisIO
 * @brief The class with-in the data from the database are treated. The MeteoData and the StationData will be set in.
 * This class also herited to IOInterface class which is abstract.
58
59
 *
 * @ingroup plugins
60
61
 * @author Thomas Egger, first version by Moustapha Mbengue
 * @date 2010-11-02
62
63
64
65
66
 */
class ImisIO : public IOInterface {
	public:
		ImisIO(const std::string& configfile);
		ImisIO(const ImisIO&);
67
		ImisIO(const Config&);
68
69
70

		virtual void readStationData(const Date& date, std::vector<StationData>& vecStation);
		virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
71
		                           std::vector< std::vector<MeteoData> >& vecMeteo);
72
73

	private:
74
75
		void openDBConnection(oracle::occi::Environment*& env, oracle::occi::Connection*& conn);
		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);
Fierz's avatar
Fierz committed
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,
Fierz's avatar
Fierz committed
90
		                    std::vector< std::vector<std::string> >& vecMeteoData,
91
		                    oracle::occi::Environment*& env, oracle::occi::Statement*& stmt);
Fierz's avatar
Fierz committed
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
98
		void readSWE(const Date& dateStart, const Date& dateEnd, std::vector< std::vector<MeteoData> >& vecMeteo,
		             const size_t& stationindex, const std::vector<StationData>& vecStationIDs,
99
		             oracle::occi::Environment*& env, oracle::occi::Statement*& stmt);
Fierz's avatar
Fierz committed
100
101
		void readStationIDs(std::vector<std::string>& vecStationID);
		void parseStationID(const std::string& stationID, std::string& stnAbbrev, std::string& stnNumber);
102

103
		void readStationMetaData(oracle::occi::Connection*& conn);
Fierz's avatar
Fierz committed
104
105
		void convertSnowTemperature(MeteoData& meteo, const std::string& parameter);
		void convertSensorDepth(MeteoData& meteo, const std::string& parameter);
106
		void convertUnits(MeteoData& meteo);
107
108

		//helper functions for the Anetz coefficient mangling:
109
110
111
112
113
		void findAnetzStations(std::map<std::string, size_t>& mapAnetzNames, std::vector<StationData>& vecAnetzStation);
		void assimilateAnetzData(const AnetzData& ad,
                                 const std::map<std::string, size_t>& mapAnetzNames, const std::vector< std::vector< std::pair<Date, double> > > &vecPsum,
                                 const size_t& stationindex, std::vector< std::vector<MeteoData> >& vecMeteo);
		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
Fierz's avatar
Fierz committed
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
Fierz's avatar
Fierz committed
121
122
123
124
125
		static const std::string sqlQueryStationIDs;
		static const std::string sqlQueryStationMetaData;
		static const std::string sqlQuerySensorDepths;
		static const std::string sqlQueryMeteoDataDrift; // combined snow_drift query from two stations (ams.v_ams_raw)
		static const std::string sqlQueryMeteoData; // single station query (ams.v_ams_raw)
126
		static const std::string sqlQuerySWEData; //SWE as computed by SNOWPACK
127
128
129
		std::string oracleUserName_in;
		std::string oraclePassword_in;
		std::string oracleDBName_in;
130
		bool useAnetz, use_imis_psum, use_psum_snowpack;
131
132
133

		static std::map<std::string, AnetzData> mapAnetz;
		static const bool __init;    ///<helper variable to enable the init of static collection data
134
		static bool initStaticData();///<initialize the static map meteoparamname
135
136
137
138
139
140
};

} //end namespace mio

#endif