WSL/SLF GitLab Repository

SMETIO.h 4.41 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
#include <meteoio/plugins/libsmet.h>
24
25
26
27
28
29

#include <string>

namespace mio {

/**
30
 * @class SMETIO
31
 * @brief Reads meteo data in the SMET ASCII or binary format.
32
 *
33
 * @ingroup plugins
34
35
36
 * @author Mathias Bavay
 * @date   2010-06-14
 */
37
class SMETIO : public IOInterface {
38
	public:
39
40
		SMETIO(const std::string& configfile);
		SMETIO(const SMETIO&);
41
		SMETIO(const Config& cfgreader);
42
		~SMETIO() throw();
43
44

		virtual void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="");
45
		virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
46
47
48
49
50
51
52

		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,
53
		                           const size_t& stationindex=IOUtils::npos);
54

55
		virtual void writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMeteo,
56
57
58
59
60
		                            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);
61
		virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
62
63

	private:
64
		void read_meta_data(const smet::SMETReader& myreader, StationData& meta);
65
66
		void identify_fields(const std::vector<std::string>& fields, std::vector<size_t>& indexes,
		                     bool& julian_present, MeteoData& md);
67
68
		void copy_data(const std::string& filename, const smet::SMETReader& myreader, const std::vector<std::string>& timestamps,
		               const std::vector<double>& mydata, std::vector<MeteoData>& vecMeteo);
69

70
		void parseInputOutputSection();
71
		bool checkConsistency(const std::vector<MeteoData>& vecMeteo, StationData& sd);
72
73
74
		size_t getNrOfParameters(const std::string& stationname, const std::vector<MeteoData>& vecMeteo);
		void checkForUsedParameters(const std::vector<MeteoData>& vecMeteo, const size_t& nr_parameters, double& tz,
		                            std::vector<bool>& vecParamInUse, std::vector<std::string>& vecColumnName);
75
		void getFormatting(const size_t& param, int& prec, int& width);
76
		double olwr_to_tss(const double& olwr);
77
		void generateHeaderInfo(const StationData& sd, const bool& i_outputIsAscii, const bool& isConsistent,
78
79
80
81
		                        const double& timezone, const size_t& nr_of_parameters,
		                        const std::vector<bool>& vecParamInUse,
		                        const std::vector<std::string>& vecColumnName,
		                        smet::SMETWriter& mywriter);
82

83
		static const std::string dflt_extension;
84
		const Config cfg;
85
86
		std::string coordin, coordinparam, coordout, coordoutparam; //default projection parameters
		std::vector<smet::SMETReader> vec_smet_reader;
87
88
		std::vector<std::string> vecFiles;  //read from the Config [Input] section
		std::string outpath;                //read from the Config [Output] section
89
		double in_dflt_TZ, out_dflt_TZ;     //default time zones
90
		double plugin_nodata;
91
92
		size_t nr_stations; //number of stations to read from
		bool outputIsAscii, outputIsGzipped;//read from the Config [Output] section
93
94
95
96
};

} //namespace
#endif