WSL/SLF GitLab Repository

IOManager.h 6.06 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
25
26
27
28
29
30

namespace mio {

class IOManager {

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

		IOManager(const Config& i_cfg);

39
40
41
42
43
44
45
46
47
		//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

48
49
		unsigned int getStationData(const Date& date, std::vector<StationData>& 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
		/**
		* @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
		*/
74
		unsigned int getMeteoData(const Date& dateStart, const Date& dateEnd,
75
		                          std::vector< std::vector<MeteoData> >& vecMeteo);
76

77
		/**
78
79
80
81
82
		 * @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)
83
84
		 *
		 * NOTE:
85
		 * - vecMeteo will be empty if there is no data found for any station
86
87
88
89
90
91
92
93
94
		 *
		 * 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
95
		 * @return            Number of stations for which data has been found in the interval
96
		 */
97
98
		unsigned int getMeteoData(const Date& i_date, std::vector<MeteoData>& vecMeteo);
		
99
		void interpolate(const Date& date, const DEMObject& dem, const MeteoData::Parameters& meteoparam, 
100
		                 Grid2DObject& result, std::string& info_string);
101
		
102
		void interpolate(const Date& date, const DEMObject& dem, const MeteoData::Parameters& meteoparam, 
103
		                 Grid2DObject& result);
104
		
105
106
107
108
109
110
111
112
113
114
115
116
		/**
		 * @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
		 */
117
118
		void setProcessingLevel(const unsigned int& i_level);

119
120
		double getAvgSamplingRate();

121
122
		void writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMeteo, const std::string& name="");

123
124
		friend std::ostream& operator<<(std::ostream& os, const IOManager& io);

125
	private:
126
		void add_to_cache(const Date& i_date, const std::vector<MeteoData>& vecMeteo);
127
128
129
		void fill_filtered_cache();
		bool read_filtered_cache(const Date& start_date, const Date& end_date,
							std::vector<METEO_DATASET>& vec_meteo);
130

131
132
133
134
		Config cfg;
		IOHandler rawio;
		BufferedIOHandler bufferedio;
		MeteoProcessor meteoprocessor;
135
		ProcessingProperties proc_properties;
136

137
138
139
		std::map<Date, std::vector<MeteoData> > meteo_cache;  ///< stores already fetched data points
		std::vector< std::vector<MeteoData> > filtered_cache; ///< stores already filtered data intervals
		Date fcache_start, fcache_end;
140
141
142
143
		unsigned int processing_level;
};
} //end namespace
#endif