WSL/SLF GitLab Repository

SMETIO.h 5.43 KB
Newer Older
1
/***********************************************************************************/
2
/*  Copyright 2010 WSL Institute for Snow and Avalanche Research    SLF-DAVOS      */
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/***********************************************************************************/
/* 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 __SMETIO_H__
#define __SMETIO_H__
20
21

#include <meteoio/IOInterface.h>
22
#include <meteoio/Config.h>
23
24
25
26
27
28

#include <string>

namespace mio {

/**
29
 * @class SMETIO
30
31
32
33
34
 * @brief This (empty) class is to be used as a template for developing new plugins
 *
 * @author Mathias Bavay
 * @date   2010-06-14
 */
35
class SMETIO : public IOInterface {
36
	public:
37
		SMETIO(void (*delObj)(void*), const Config& i_cfg);
38

39
40
		SMETIO(const std::string& configfile);
		SMETIO(const SMETIO&);
41
		SMETIO(const Config& cfgreader);
42
		~SMETIO() throw();
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

		virtual void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="");

		virtual void readDEM(DEMObject& dem_out);
		virtual void readLanduse(Grid2DObject& landuse_out);

		virtual void readStationData(const Date& date, std::vector<StationData>& vecStation);
		virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
		                           std::vector< std::vector<MeteoData> >& vecMeteo,
		                           std::vector< std::vector<StationData> >& vecStation,
		                           const unsigned int& stationindex=IOUtils::npos);

		virtual void writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMeteo, 
		                            const std::vector< std::vector<StationData> >& vecStation,
		                            const std::string& name="");

		virtual void readAssimilationData(const Date&, Grid2DObject& da_out);
		virtual void readSpecialPoints(std::vector<Coords>& pts);
		virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& filename);

	private:
64
		static const std::string smet_version;
65
		static const unsigned int buffer_reserve; //for optimizing vectors (ie: avoid unecessary resizing)
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
		static std::map<std::string, MeteoData::Parameters> mapParameterByName; ///<Associate name and meteo parameter
		static const bool __init;    ///<helper variable to enable the init of static collection data
		static bool initStaticData();///<initialize the static map meteoparamname 
		static double& getParameter(const std::string& columnName, MeteoData& md);
		static void checkColumnNames(const std::vector<std::string>& vecColumns, const bool& locationInHeader);

		void cleanup() throw();
		void parseInputOutputSection();
		bool checkConsistency(const std::vector<StationData>& vecStation, StationData& sd);
		void checkForUsedParameters(const std::vector<MeteoData>& vecMeteo, double& timezone, 
                                      std::vector<bool>& vecParamInUse);
		void writeHeaderSection(const bool& writeLocationInHeader, const StationData& sd, 
                                  const double& timezone, const std::vector<bool>& vecParamInUse);
		void writeDataAscii(const bool& writeLocationInHeader, const std::vector<MeteoData>& vecMeteo,
                              const std::vector<StationData>& vecStation, const std::vector<bool>& vecParamInUse);
		void writeDataBinary(const bool& writeLocationInHeader, const std::vector<MeteoData>& vecMeteo,
                               const std::vector<StationData>& vecStation, const std::vector<bool>& vecParamInUse);

		void readHeader(const char& eoln, const std::string& filename, bool& locationInHeader,
                          double& timezone, StationData& sd, std::vector<std::string>& vecDataSequence);
		void readDataAscii(const char& eoln, const std::string& filename, const double& timezone,
					    const StationData& sd, const std::vector<std::string>& vecDataSequence,
					    const Date& dateStart, const Date& dateEnd,
					    std::vector<MeteoData>& vecMeteo, std::vector<StationData>& vecStation);
		void readDataBinary(const char& eoln, const std::string& filename, const double& timezone,
					     const StationData& sd, const std::vector<std::string>& vecDataSequence,
					     const Date& dateStart, const Date& dateEnd,
					     std::vector<MeteoData>& vecMeteo, std::vector<StationData>& vecStation);

		void checkSignature(const std::vector<std::string>& vecSignature, const std::string& filename, bool& isAscii);
96
		void setFormatting(const MeteoData::Parameters& paramindex);
97

98
		unsigned int nr_stations; //number of stations to read from
99
100
101
		std::vector<std::string> vecFiles;  //read from the Config [Input] section
		std::string outpath;                //read from the Config [Output] section
		bool outputIsAscii, outputIsGzipped;//read from the Config [Output] section
102

103
		Config cfg;
104
105
		std::ifstream fin; //Input file streams
		std::ofstream fout; //Output file streams
106
		std::string coordin, coordinparam, coordout, coordoutparam; //default projection parameters
107
108
109
110
};

} //namespace
#endif