WSL/SLF GitLab Repository

IOManager.h 7.65 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/***********************************************************************************/
/*  Copyright 2009 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/>.
*/
#ifndef __IOMANAGER_H__
#define __IOMANAGER_H__

#include <meteoio/BufferedIOHandler.h>
#include <meteoio/Meteo2DInterpolator.h>
23
#include <meteoio/MeteoProcessor.h>
24
#include <meteoio/MeteoData.h>
25
26
27
28
29
30
31

namespace mio {

class IOManager {

	public:
		enum ProcessingLevel {
32
33
34
35
			raw           = 1,
			filtered      = 1 << 1,
			resampled     = 1 << 2,
			num_of_levels = 1 << 3
36
37
38
39
		};

		IOManager(const Config& i_cfg);

40
41
42
43
44
45
46
47
48
		//Legacy support to support functionality of the IOInterface superclass:
		void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="");
		void readDEM(DEMObject& dem_out);
		void readAssimilationData(const Date& date_in, Grid2DObject& da_out);
		void readLanduse(Grid2DObject& landuse_out);
		void readSpecialPoints(std::vector<Coords>& pts);
		void write2DGrid(const Grid2DObject& grid_in, const std::string& options="");
		//end legacy support

49
		unsigned int getStationData(const Date& date, STATION_TIMESERIE& vecStation);
50

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
		/**
		* @brief Fill vecMeteo with a time series of objects
		* corresponding to the interval indicated by dateStart and dateEnd.
		* Depending on the ProcessingLevel for the instance of the IOManager
		* the data returned will be either raw (read directly from the IOHandler)
		* or processed (read from an BufferedIOHandler and filtered through the 
		* MeteoProcessor
		*
		* vecMeteo will be empty if no datasets were retrieved in the interval defined
		* by dateStart and dateEnd
		*    
		* Example Usage:
		* @code
		* vector< vector<MeteoData> > vecMeteo;      //empty vector
		* Date d1(2008,06,21,11,00);       //21.6.2008 11:00
		* Date d2(2008,07,21,11,00);       //21.7.2008 11:00
		* IOManager iom(Config("io.ini"));
		* unsigned int nstations = iom.getMeteoData(d1, d2, vecMeteo);
		* @endcode
		* @param dateStart   A Date object representing the beginning of an interval (inclusive)
		* @param dateEnd     A Date object representing the end of an interval (inclusive)
		* @param vecMeteo    A vector of vector<MeteoData> objects to be filled with data
		* @return            Number of stations for which data has been found in the interval
		*/
75
		unsigned int getMeteoData(const Date& dateStart, const Date& dateEnd,
76
		                          std::vector< METEO_TIMESERIE >& vecMeteo);
77

78
		/**
79
80
81
82
83
		 * @brief Fill vector<MeteoData> object with multiple instances of MeteoData
		 * corresponding to the instant indicated by a Date object. Each MeteoData
		 * instance within the vector represents the data for one station at the given 
		 * instant. Depending on the ProcessingLevel configured data will be either 
		 * raw (read directly from the IOHandler)
84
85
		 *
		 * NOTE:
86
		 * - vecMeteo will be empty if there is no data found for any station
87
88
89
90
91
92
93
94
95
		 *
		 * Example Usage:
		 * @code
		 * vector<MeteoData> vecMeteo;      //empty vector
		 * IOManager iomanager(Config("io.ini"));
		 * iomanager.getMeteoData(Date(2008,06,21,11,00), vecMeteo); //21.6.2008 11:00
		 * @endcode
		 * @param i_date      A Date object representing the date/time for the sought MeteoData objects
		 * @param vecMeteo    A vector of MeteoData objects to be filled with data
96
		 * @return            Number of stations for which data has been found in the interval
97
		 */
98
99
		unsigned int getMeteoData(const Date& i_date, METEO_TIMESERIE& vecMeteo);

100
101
102
103
104
105
106
107
108
109
110
111
		/**
		 * @brief Push a vector of time series of MeteoData objects into the IOManager. This overwrites
		 *        any internal buffers that are used and subsequent calls to getMeteoData or interpolate
		 *        will be performed upon this data. This method is a way to bypass the internal reading
		 *        of MeteoData from a certain source and is useful in case the user is only interested 
		 *        in data processing and interpolation performed by the IOManager object. 
		 * @param level Level of processing that has already been performed on the data (raw XOR filtered)
		 * @param date_start Representing the beginning of the data
		 * @param date_end Representing the end of the data
		 * @param vecMeteo The actual data being pushed into the IOManager object
		 */
		void push_meteo_data(const ProcessingLevel& level, const Date& date_start, const Date& date_end, 
112
		                     const std::vector< METEO_TIMESERIE >& vecMeteo);
113

114
#ifdef _POPC_ //HACK popc
115
116
		void interpolate(/*const*/ Date& date, /*const*/ DEMObject& dem, /*const*/ MeteoData::Parameters meteoparam,
		                 Grid2DObject& result);
117
#else
118
		void interpolate(const Date& date, const DEMObject& dem, const MeteoData::Parameters& meteoparam, 
119
		                 Grid2DObject& result);
120
121
122
#endif

#ifdef _POPC_ //HACK popc
123
124
		void interpolate(/*const*/ Date& date, /*const*/ DEMObject& dem, /*const*/ MeteoData::Parameters meteoparam,
		                 Grid2DObject& result, std::string& info_string);
125
#else
126
		void interpolate(const Date& date, const DEMObject& dem, const MeteoData::Parameters& meteoparam, 
127
		                 Grid2DObject& result, std::string& info_string);
128
#endif
129

130
131
132
133
134
135
136
137
138
139
140
141
		/**
		 * @brief Set the desired ProcessingLevel of the IOManager instance
		 *        The processing level affects the way meteo data is read and processed
		 *        Three values are possible:
		 *        - IOManager::raw data shall be read directly from the buffer
		 *        - IOManager::filtered data shall be filtered before returned to the user
		 *        - IOManager::resampled data shall be resampled before returned to the user
		 *          this only affects the function getMeteoData(const Date&, METEO_DATASET&);
		 *
		 *        The three values can be combined: e.g. IOManager::filtered | IOManager:resampled
		 * @param i_level The ProcessingLevel values that shall be used to process data
		 */
142
143
		void setProcessingLevel(const unsigned int& i_level);

144
145
		double getAvgSamplingRate();

146
147
148
149
150
#ifdef _POPC_ //HACK popc
		void writeMeteoData(/*const*/ std::vector< METEO_TIMESERIE >& vecMeteo, /*const*/ std::string& name/*=""*/);
#else
		void writeMeteoData(const std::vector< METEO_TIMESERIE >& vecMeteo, const std::string& name="");
#endif
151

152
		std::string toString() const;
153
154
		friend std::ostream& operator<<(std::ostream& os, const IOManager& io);

155
	private:
156
		void add_to_cache(const Date& i_date, const METEO_TIMESERIE& vecMeteo);
157
158
		void fill_filtered_cache();
		bool read_filtered_cache(const Date& start_date, const Date& end_date,
159
		                         std::vector< METEO_TIMESERIE >& vec_meteo);
160

161
		const Config& cfg;
162
163
164
		IOHandler rawio;
		BufferedIOHandler bufferedio;
		MeteoProcessor meteoprocessor;
165
		ProcessingProperties proc_properties;
166

167
168
		std::map<Date, METEO_TIMESERIE > resampled_cache;  ///< stores already resampled data points
		std::vector< METEO_TIMESERIE > filtered_cache; ///< stores already filtered data intervals
169
		Date fcache_start, fcache_end; ///< store the beginning and the end date of the filtered_cache
170
171
172
173
		unsigned int processing_level;
};
} //end namespace
#endif