WSL/SLF GitLab Repository

SNIO.h 3.61 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/***********************************************************************************/
/*  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 __SNIO_H__
#define __SNIO_H__

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

#include <string>
#include <sstream>
#include <iostream>

namespace mio {

/**
 * @class SNIO
 * @brief This class enables the access to meteo data stored in SNOWPACK format
 *
 * @author Mathias Bavay
 * @date   2009-12-04
 */
class SNIO : public IOInterface {
	public:
43
		SNIO(void (*delObj)(void*), const Config& i_cfg);
44
45
46

		SNIO(const std::string& configfile);
		SNIO(const SNIO&);
47
		SNIO(const Config& cfgreader);
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
		~SNIO() throw();

		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:
		void writeStationHeader(const std::vector<MeteoData>& Meteo, const std::string station_name);
		void writeStationMeteo(const std::vector<MeteoData>& Meteo, const std::string& file_name);
		void convertUnits(MeteoData& meteo);
		void convertUnitsBack(MeteoData& meteo);
74
		double cloudiness_to_ilwr (const double& RH, const double& TA, const double& cloudiness );
75
76
77
78
		void parseMeteoLine(const std::vector<std::string>& vecLine, const std::string& filepos, MeteoData& md);
		void readMetaData(unsigned int& nrOfStations);
		void parseMetaDataLine(const std::vector<std::string>& vecLine, StationData& sd);
		void cleanup() throw();
79
80

		double in_tz, out_tz;
81
		Config cfg;
82
83
84
85
86
87
88
89
90
91
		std::ifstream fin; //Input file streams
		std::ofstream fout;//Output file streams
		static const int sn_julian_offset;
		static const double plugin_nodata; //plugin specific nodata value, e.g. -999
		std::string coordin, coordinparam, coordout, coordoutparam; //projection parameters		
		std::vector<StationData> vecAllStations;
};

} //namespace
#endif