WSL/SLF GitLab Repository

A3DIO.h 4.98 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
23
/***********************************************************************************/
/*  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 __A3DIO_H__
#define __A3DIO_H__

#include <meteoio/IOInterface.h>

#include <meteoio/Coords.h>
24
#include <meteoio/Config.h>
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <meteoio/IOExceptions.h>
#include <meteoio/IOUtils.h>

#include <string>
#include <vector>
#include <map>

namespace mio {

class A3DIO : public IOInterface {
	public:
		//virtual A3DIO* clone() const;

		//A3DIO(void (*delObj)(void*), const std::string& filename);

		A3DIO(const std::string& configfile);
		A3DIO(const A3DIO&);
42
		A3DIO(const Config&);
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
		~A3DIO() throw();

		virtual void read2DGrid(Grid2DObject& dem_out, const std::string& name="");

		virtual void readDEM(DEMObject& dem_out);
		virtual void readLanduse(Grid2DObject& landuse_out);
		virtual void readAssimilationData(const Date&, Grid2DObject& da_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);

		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 readSpecialPoints(std::vector<Coords>& pts);

		virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& name);

	private:
		static const double plugin_nodata; //plugin specific nodata value, e.g. -9999
71
72
		static const unsigned int buffer_reserve; //for optimizing vectors (ie: avoid unecessary resizing)
		void read1DStation(std::string& file_1d, StationData& sd);
73
74
		void read1DMeteo(const Date& dateStart, const Date& dateEnd, 
		                 std::vector< std::vector<MeteoData> >&, std::vector< std::vector<StationData> >&); ///< No buffering
75
		void read2DStations(const Date& timestamp, std::vector<StationData>& vecStation);
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
		void read2DMeteo(std::vector< std::vector<MeteoData> >&, std::vector< std::vector<StationData> >&); ///< No buffering

		void constructMeteo2DFilenames(const Date& _startDate, const Date& _endDate, std::vector<std::string>& _filenames);
		bool readMeteoDataLine(std::string& line, MeteoData& tmpdata, std::string filename);
		void convertUnits(MeteoData& meteo);
		void cleanup() throw();
		void read2DMeteoData(const std::string&, const std::string&, std::map<std::string,unsigned int>& hashStations, 
		                     std::vector< std::vector<MeteoData> >&, unsigned int& bufferindex);
		void read2DMeteoHeader(const std::string& filename, std::map<std::string, unsigned int>& hashStations, 
		                       std::vector<StationData>&);
		unsigned int getNrOfStations(std::vector<std::string>& filenames, 
		                             std::map<std::string, unsigned int>& hashStations);

		int create1DFile(const std::vector< std::vector<MeteoData> >& data, const std::vector< std::vector<StationData> >& stations);
		int writeHeader(std::ofstream &file, const std::vector< std::vector<StationData> >& stations, const std::string parameter_name);
		void open2DFile(const std::vector< std::vector<StationData> >& stations,
		                const std::string& fileprefix, const std::string& label, const double& year,
		                std::ofstream& file);
		int write2DmeteoFile(const std::vector< std::vector<MeteoData> >& data, const std::vector< std::vector<StationData> >& stations,
		                      const unsigned int& parindex, const std::string& filename,
		                      const std::string& label);
		void write2DMeteo(const std::vector< std::vector<MeteoData> >& data, const std::vector< std::vector<StationData> >& stations);

99
		Config cfg;
100
101
102
103
104
105
		std::ifstream fin; //Input file streams
		std::string coordin, coordinparam, coordout, coordoutparam; //projection parameters
};
} //end namespace

#endif