WSL/SLF GitLab Repository

IOManager.h 6.66 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
100
		unsigned int getMeteoData(const Date& i_date, METEO_TIMESERIE& vecMeteo);

#ifdef _POPC_ //HACK popc
101
102
		void interpolate(/*const*/ Date& date, /*const*/ DEMObject& dem, /*const*/ MeteoData::Parameters meteoparam,
		                 Grid2DObject& result);
103
#else
104
		void interpolate(const Date& date, const DEMObject& dem, const MeteoData::Parameters& meteoparam, 
105
		                 Grid2DObject& result);
106
107
108
#endif

#ifdef _POPC_ //HACK popc
109
110
		void interpolate(/*const*/ Date& date, /*const*/ DEMObject& dem, /*const*/ MeteoData::Parameters meteoparam,
		                 Grid2DObject& result, std::string& info_string);
111
#else
112
		void interpolate(const Date& date, const DEMObject& dem, const MeteoData::Parameters& meteoparam, 
113
		                 Grid2DObject& result, std::string& info_string);
114
#endif
115

116
117
118
119
120
121
122
123
124
125
126
127
		/**
		 * @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
		 */
128
129
		void setProcessingLevel(const unsigned int& i_level);

130
131
		double getAvgSamplingRate();

132
133
134
135
136
#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
137

138
		std::string toString() const;
139
140
		friend std::ostream& operator<<(std::ostream& os, const IOManager& io);

141
	private:
142
		void add_to_cache(const Date& i_date, const METEO_TIMESERIE& vecMeteo);
143
144
		void fill_filtered_cache();
		bool read_filtered_cache(const Date& start_date, const Date& end_date,
145
		                         std::vector< METEO_TIMESERIE >& vec_meteo);
146

147
		const Config& cfg;
148
149
150
		IOHandler rawio;
		BufferedIOHandler bufferedio;
		MeteoProcessor meteoprocessor;
151
		ProcessingProperties proc_properties;
152

153
154
		std::map<Date, METEO_TIMESERIE > resampled_cache;  ///< stores already resampled data points
		std::vector< METEO_TIMESERIE > filtered_cache; ///< stores already filtered data intervals
155
		Date fcache_start, fcache_end;
156
157
158
159
		unsigned int processing_level;
};
} //end namespace
#endif