MeteoIODoc  MeteoIODoc-2.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NetCDFIO.h
Go to the documentation of this file.
1 /***********************************************************************************/
2 /* Copyright 2014 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
3 /***********************************************************************************/
4 /* This file is part of MeteoIO.
5  MeteoIO is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  MeteoIO is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef NetCDFIO_H
19 #define NetCDFIO_H
20 
21 #include <meteoio/IOInterface.h>
22 
23 #include <string>
24 
25 namespace mio {
26 
35 class NetCDFIO : public IOInterface {
36  public:
37  NetCDFIO(const std::string& configfile);
38  NetCDFIO(const NetCDFIO&);
39  NetCDFIO(const Config& cfgreader);
40 
41  virtual void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="");
42  virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
43  virtual void readDEM(DEMObject& dem_out);
44 
45  virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& filename);
46  virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
47 
48  private:
49  typedef struct ATTRIBUTES {
50  ATTRIBUTES() : var(), standard_name(), long_name(), units(), height(IOUtils::nodata) {};
51  ATTRIBUTES(const std::string& str1, const std::string& str2, const std::string& str3, const std::string& str4, const double& hgt)
52  : var(str1), standard_name(str2), long_name(str3), units(str4), height(hgt) {};
53  std::string toString() {std::ostringstream os; os << "[" << var << " / " << standard_name << " / " << long_name << " , in " << units << " @ " << height << "]"; return os.str();};
54 
55  std::string var;
56  std::string standard_name;
57  std::string long_name;
58  std::string units;
59  double height;
60  } attributes;
61 
62  void initAttributesMap(const std::string& schema, std::map<MeteoGrids::Parameters, attributes> &attr);
63  void scanMeteoPath(const std::string& meteopath_in, std::vector< std::pair<std::pair<mio::Date, mio::Date>, std::string> > &meteo_files);
64  void setTimeTransform(const std::string& schema, double &time_offset, double &time_multiplier);
65  void parseInputOutputSection();
66  void check_consistency(const int& ncid, const Grid2DObject& grid, double*& lat_array, double*& lon_array,
67  int& did_lat, int& did_lon, int& vid_lat, int& vid_lon);
68 
69  void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date, const std::string& filename);
70  bool read2DGrid_internal(Grid2DObject& grid_out, const std::string& filename, const MeteoGrids::Parameters& parameter, const Date& date=Date());
71  bool read2DGrid_internal(Grid2DObject& grid_out, const std::string& full_name, const std::string& varname, const Date& date=Date(), const bool& isPrecip=false);
72  void write2DGrid_internal(Grid2DObject grid_in, const std::string& filename, const attributes& attr, const Date& date=Date(), const bool& isPrecip=false);
73  void add_attributes_for_variable(const int& ncid, const int& varid, const attributes& attr, const double& nodata_out);
74  void getTimeTransform(const int& ncid, double &time_offset, double &time_multiplier) const;
75  void create_latlon_dimensions(const int& ncid, const Grid2DObject& grid, int& did_lat, int& did_lon, int& vid_lat, int& vid_lon);
76  void create_time_dimension(const int& ncid, int& did_time, int& vid_time);
77  void readWind(const std::string& filename, const Date& date);
78 
79  // Private variables
80  static const double plugin_nodata; //plugin specific nodata value, e.g. -999
81  static const std::string cf_time, cf_latitude, cf_longitude;
82 
83  const Config cfg;
84  std::vector< std::pair<std::pair<Date,Date>, std::string> > cache_meteo_files; //cache of meteo files in METEOPATH
85  std::map <MeteoGrids::Parameters, attributes> in_attributes, out_attributes;
86  std::string coordin, coordinparam, coordout, coordoutparam; //projection parameters
87  double in_dflt_TZ, out_dflt_TZ; //default time zones
88  double in_time_offset, in_time_multiplier; //each schema defines its own time specification...
89  bool dem_altimeter, in_strict, out_strict;
90  std::vector<StationData> vecMetaData;
91 };
92 
93 } //namespace
94 #endif
A class representing the IO Layer of the software Alpine3D. For each type of IO (File, DB, Webservice, etc) a derived class is to be created that holds the specific implementation of the appropriate virtual methods. The IOHandler class is a wrapper class that is able to deal with all above implementations of the IOInterface abstract base class.
Definition: IOInterface.h:43
virtual void readDEM(DEMObject &dem_out)
Parse the DEM (Digital Elevation Model) into the Grid2DObject.
Definition: NetCDFIO.cc:421
virtual void write2DGrid(const Grid2DObject &grid_in, const std::string &filename)
Write a Grid2DObject The filename is specified relative to GRID2DPATH for most plugins.
Definition: NetCDFIO.cc:455
NetCDFIO(const std::string &configfile)
Definition: NetCDFIO.cc:175
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition: Config.h:58
A class to represent DEMs and automatically compute some properties. This class stores elevation grid...
Definition: DEMObject.h:39
A class to represent 2D Grids. Typical application as DEM or Landuse Model.
Definition: Grid2DObject.h:37
const double nodata
This is the internal nodata value.
Definition: IOUtils.h:60
virtual void read2DGrid(Grid2DObject &grid_out, const std::string &parameter="")
A generic function for parsing 2D grids into a Grid2DObject. The string parameter shall be used for a...
Definition: NetCDFIO.cc:277
This plug-in allows reading and writing of NetCDF files formatted according to CNRM standard...
Definition: NetCDFIO.h:35
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:79
Parameters
Definition: MeteoData.h:44