WSL/SLF GitLab Repository

NetCDFIO.h 5.35 KB
Newer Older
1
/***********************************************************************************/
2
/*  Copyright 2014 WSL Institute for Snow and Avalanche Research    SLF-DAVOS      */
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/***********************************************************************************/
/* 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 __NetCDFIO_H__
#define __NetCDFIO_H__

#include <meteoio/IOInterface.h>
#include <meteoio/Config.h>

#include <string>

namespace mio {

/**
 * @class NetCDFIO
30
 * @brief This plug-in allows reading and writing of NetCDF files formatted according to CNRM standard.
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 *
 * @ingroup plugins
 * @author Thomas Egger
 * @date   2014-03-13
 */
class NetCDFIO : public IOInterface {
	public:
		NetCDFIO(const std::string& configfile);
		NetCDFIO(const NetCDFIO&);
		NetCDFIO(const Config& cfgreader);
		~NetCDFIO() throw();

		virtual void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="");
		virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
		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,
		                           const size_t& stationindex=IOUtils::npos);

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

		virtual void readAssimilationData(const Date&, Grid2DObject& da_out);
		virtual void readPOI(std::vector<Coords>& pts);
		virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& filename);
		virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);

	private:
62
63
64
65
66
67
68
69
70
71
72
73
		typedef struct ATTRIBUTES {
			ATTRIBUTES() : var(), standard_name(), long_name(), units(), height(IOUtils::nodata) {};
			ATTRIBUTES(const std::string& str1, const std::string& str2, const std::string& str3, const std::string& str4, const double& hgt)
			                     : var(str1), standard_name(str2), long_name(str3), units(str4), height(hgt) {};
  
			std::string var;
			std::string standard_name;
			std::string long_name;
			std::string units;
			double height;
		} attributes;

74
75
		void initAttributesMap(const std::string& schema, std::map<MeteoGrids::Parameters, attributes> &attr);
		void setTimeTransform(const std::string& schema, double &time_offset, double &time_multiplier);
76
		void parseInputOutputSection();
77
		void check_consistency(const int& ncid, const Grid2DObject& grid, double*& lat_array, double*& lon_array,
78
		                       int& did_lat, int& did_lon, int& vid_lat, int& vid_lon);
79
		//void read2DGrid_meta(const std::string& filename, const std::string& varname, int &ncid, int &varid, std::vector<size_t> &dimlen, size_t &time_index, size_t &lat_index, size_t &lon_index, double &missing_value,double &lat, double &lon);
80
		bool read2DGrid_internal(Grid2DObject& grid_out, const std::string& filename, const MeteoGrids::Parameters& parameter, const Date& date=Date());
81
		bool read2DGrid_internal(Grid2DObject& grid_out, const std::string& full_name, const std::string& varname, const Date& date=Date(), const bool& isPrecip=false);
82
		void write2DGrid_internal(const Grid2DObject& grid_in, const std::string& filename, const std::string& varname, const Date& date=Date());
83
		void add_attributes_for_variable(const int& ncid, const int& varid, const MeteoGrids::Parameters& parameter);
84
		//void add_attributes_for_variable(const int& ncid, const int& varid, const std::string& varname);
85
		void getTimeTransform(const int& ncid, const int& varid, double &time_offset, double &time_multiplier) const;
86
87
		void create_latlon_dimensions(const int& ncid, const Grid2DObject& grid, int& did_lat, int& did_lon, int& vid_lat, int& vid_lon);
		void create_time_dimension(const int& ncid, int& did_time, int& vid_time);
88
		void readWind(const std::string& filename, const Date& date);
89

Thomas Egger's avatar
Thomas Egger committed
90
		// Private variables
91
		static const double plugin_nodata; //plugin specific nodata value, e.g. -999
92
		static const double epsilon; //for numerical comparisons of double values
93
		static const std::string cf_time, cf_latitude, cf_longitude, cf_altitude;
94

Thomas Egger's avatar
Thomas Egger committed
95
		const Config cfg;
96
		std::map <MeteoGrids::Parameters, attributes> in_attributes, out_attributes;
97
		std::string coordin, coordinparam, coordout, coordoutparam; //projection parameters
98
99
		double in_dflt_TZ, out_dflt_TZ; //default time zones
		double in_time_offset, in_time_multiplier; //each schema defines its own time specification...
100
		bool dem_altimeter, in_strict, out_strict;
101
		std::vector<StationData> vecMetaData;
102
103
104
105
};

} //namespace
#endif