MeteoIODoc  MeteoIODoc-2.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GRIBIO.h
Go to the documentation of this file.
1 /***********************************************************************************/
2 /* Copyright 2012 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 GRIBIO_H
19 #define GRIBIO_H
20 
21 #include <meteoio/IOInterface.h>
22 
23 #include <string>
24 #include <grib_api.h>
25 
26 namespace mio {
27 
36 class GRIBIO : public IOInterface {
37  public:
38  GRIBIO(const std::string& configfile);
39  GRIBIO(const GRIBIO&);
40  GRIBIO(const Config& cfgreader);
41  ~GRIBIO() throw();
42 
43  GRIBIO& operator=(const GRIBIO&);
44 
45  virtual void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="");
46  virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
47  virtual void readDEM(DEMObject& dem_out);
48 
49  virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
50  std::vector< std::vector<MeteoData> >& vecMeteo);
51 
52  private:
53  void setOptions();
54  void listFields(const std::string& filename);
55  void getDate(grib_handle* h, Date &base, double &d1, double &d2);
56  Coords getGeolocalization(grib_handle* h, double &cellsize_x, double &cellsize_y);
57  void read2Dlevel(grib_handle* h, Grid2DObject& grid_out);
58  bool read2DGrid_indexed(const double& in_marsParam, const long& i_levelType, const long& i_level, const Date i_date, Grid2DObject& grid_out);
59  void read2DGrid(const std::string& filename, Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
60  void readWind(const std::string& filename, const Date& date);
61  void indexFile(const std::string& filename);
62  void readStations(std::vector<Coords> &vecPoints);
63  void listKeys(grib_handle** h, const std::string& filename);
64  void scanMeteoPath();
65  void cleanup() throw();
66 
67  bool removeDuplicatePoints(std::vector<Coords>& vecPoints, double *lats, double *lons);
68  bool readMeteoMeta(std::vector<Coords>& vecPoints, std::vector<StationData> &stations, double *lats, double *lons);
69  bool readMeteoValues(const double& marsParam, const long& levelType, const long& i_level, const Date& i_date, const size_t& npoints, double *lats, double *lons, double *values);
70  void fillMeteo(double *values, const MeteoData::Parameters& param, const size_t& npoints, std::vector<MeteoData> &Meteo);
71  void readMeteoStep(std::vector<StationData> &stations, double *lats, double *lons, const Date i_date, std::vector<MeteoData> &Meteo);
72 
73  const Config cfg;
74  std::string grid2dpath_in;
75  std::string meteopath_in;
76  std::vector<Coords> vecPts; //points to use for virtual stations if METEO=GRIB
77  std::vector< std::pair<Date,std::string> > cache_meteo_files; //cache of meteo files in METEOPATH
78  std::string meteo_ext; //file extension
79  std::string grid2d_ext; //file extension
80  std::string grid2d_prefix; //filename prefix, like "laf"
81  std::string idx_filename; //matching file name for the index
82  std::string coordin, coordinparam; //projection parameters
83  Grid2DObject VW, DW; //for caching wind fields, since they require quite some calculations
84  Date wind_date;
85  Coords llcorner;
86 
87  FILE *fp; //since passing fp always fail...
88  grib_index *idx; //because it needs to be kept between calls
89  double latitudeOfNorthernPole, longitudeOfNorthernPole; //for rotated coordinates
90  double bearing_offset; //to correct vectors coming from rotated lat/lon, we will add an offset to the bearing
91  double cellsize, factor_x, factor_y;
92 
93  static const std::string default_ext;
94  static const double plugin_nodata; //plugin specific nodata value, e.g. -999
95  static const double tz_in; //GRIB time zone
96  bool indexed; //flag to know if the file has already been indexed
97  bool meteo_initialized; //set to true after we scanned METEOPATH, filed the cache, read the virtual stations from io.ini
98  bool llcorner_initialized; //set to true after we properly computed llcorner
99  bool update_dem;
100 
101 };
102 
103 } //namespace
104 #endif
GRIBIO & operator=(const GRIBIO &)
Assignement operator, required because of pointer member.
Definition: GRIBIO.cc:123
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
A class to handle geographic coordinate systems. This class offers an easy way to transparently conve...
Definition: Coords.h:81
virtual void readMeteoData(const Date &dateStart, const Date &dateEnd, std::vector< std::vector< MeteoData > > &vecMeteo)
Fill vecMeteo with a time series of objects corresponding to the interval indicated by dateStart and ...
Definition: GRIBIO.cc:731
~GRIBIO()
Definition: GRIBIO.cc:155
Parameters
Definition: MeteoData.h:119
This plugin reads GRIB 1 or 2 data files.
Definition: GRIBIO.h:36
virtual void readDEM(DEMObject &dem_out)
Parse the DEM (Digital Elevation Model) into the Grid2DObject.
Definition: GRIBIO.cc:680
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
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:79
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: GRIBIO.cc:445
GRIBIO(const std::string &configfile)
Definition: GRIBIO.cc:101
Parameters
Definition: MeteoData.h:44