MeteoIODoc 2.11.0
GRIBIO.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2012 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
4/***********************************************************************************/
5/* This file is part of MeteoIO.
6 MeteoIO is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MeteoIO is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef GRIBIO_H
20#define GRIBIO_H
21
22#include <meteoio/IOInterface.h>
23
24#include <string>
25#include <grib_api.h>
26
27namespace mio {
28
37class GRIBIO : public IOInterface {
38 public:
39 GRIBIO(const std::string& configfile);
40 GRIBIO(const GRIBIO&);
41 GRIBIO(const Config& cfgreader);
42 ~GRIBIO() noexcept;
43
44 GRIBIO& operator=(const GRIBIO&);
45
46 virtual bool list2DGrids(const Date& /*start*/, const Date& /*end*/, std::map<Date, std::set<size_t> >& /*list*/) {return false;}
47 virtual void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="");
48 virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
49 virtual void readDEM(DEMObject& dem_out);
50
51 virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
52 std::vector< std::vector<MeteoData> >& vecMeteo);
53
54 private:
55 void setOptions();
56 void getDate(grib_handle* h, Date &base, double &d1, double &d2);
57 Coords getGeolocalization(grib_handle* h, double &cellsize_x, double &cellsize_y);
58 void read2Dlevel(grib_handle* h, Grid2DObject& grid_out);
59 bool read2DGrid_indexed(const double& in_marsParam, const long& i_levelType, const long& i_level, const Date i_date, Grid2DObject& grid_out);
60 void read2DGrid(const std::string& filename, Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
61 void readWind(const std::string& filename, const Date& date);
62 void indexFile(const std::string& filename);
63 void readStations(std::vector<Coords> &vecPoints);
64 void listFields(const std::string& filename);
65 void listKeys(grib_handle** h, const std::string& filename);
66 void scanMeteoPath();
67 void cleanup() noexcept;
68
69 bool removeDuplicatePoints(std::vector<Coords>& vecPoints, double *lats, double *lons);
70 bool readMeteoMeta(std::vector<Coords>& vecPoints, std::vector<StationData> &stations, double *lats, double *lons);
71 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);
72 void fillMeteo(double *values, const MeteoData::Parameters& param, const size_t& npoints, std::vector<MeteoData> &Meteo);
73 void readMeteoStep(std::vector<StationData> &stations, double *lats, double *lons, const Date i_date, std::vector<MeteoData> &Meteo);
74
75 const Config cfg;
76 std::string grid2dpath_in;
77 std::string meteopath_in;
78 std::vector<Coords> vecPts; //points to use for virtual stations if METEO=GRIB
79 std::vector< std::pair<Date,std::string> > cache_meteo_files; //cache of meteo files in METEOPATH
80 std::string meteo_ext; //file extension
81 std::string grid2d_ext; //file extension
82 std::string grid2d_prefix; //filename prefix, like "laf"
83 std::string idx_filename; //matching file name for the index
84 std::string coordin, coordinparam; //projection parameters
85 Grid2DObject VW, DW; //for caching wind fields, since they require quite some calculations
86 Date wind_date;
87 Coords llcorner;
88
89 FILE *fp; //since passing fp always fail...
90 grib_index *idx; //because it needs to be kept between calls
91 double latitudeOfNorthernPole, longitudeOfNorthernPole; //for rotated coordinates
92 double bearing_offset; //to correct vectors coming from rotated lat/lon, we will add an offset to the bearing
93 double cellsize, factor_x, factor_y;
94
95 static const std::string default_ext;
96 static const double plugin_nodata; //plugin specific nodata value, e.g. -999
97 static const double tz_in; //GRIB time zone
98 bool indexed; //flag to know if the file has already been indexed
99 bool meteo_initialized; //set to true after we scanned METEOPATH, filed the cache, read the virtual stations from io.ini
100 bool llcorner_initialized; //set to true after we properly computed llcorner
101 bool update_dem, debug;
102
103};
104
105} //namespace
106#endif
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition: Config.h:79
A class to handle geographic coordinate systems. This class offers an easy way to transparently conve...
Definition: Coords.h:83
A class to represent DEMs and automatically compute some properties. This class stores elevation grid...
Definition: DEMObject.h:40
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
This plugin reads GRIB 1 or 2 data files.
Definition: GRIBIO.h:37
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:754
GRIBIO(const GRIBIO &)
virtual bool list2DGrids(const Date &, const Date &, std::map< Date, std::set< size_t > > &)
Return the list of grids within a given time period that could be read by the plugin,...
Definition: GRIBIO.h:46
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:481
~GRIBIO() noexcept
Definition: GRIBIO.cc:180
virtual void readDEM(DEMObject &dem_out)
Parse the DEM (Digital Elevation Model) into the Grid2DObject.
Definition: GRIBIO.cc:703
GRIBIO(const std::string &configfile)
Definition: GRIBIO.cc:125
A class to represent 2D Grids. Typical application as DEM or Landuse Model.
Definition: Grid2DObject.h:42
A class representing the IO Layer of the software Alpine3D. For each type of IO (File,...
Definition: IOInterface.h:98
A class to represent a singular measurement received from one station at a certain time (represented ...
Definition: MeteoData.h:107
Parameters
this enum provides names for possible meteogrids (from an ARPS file, etc)
Definition: MeteoData.h:46
A class to represent meteo stations with attributes like longitude, latitude, etc.
Definition: StationData.h:41
Definition: Config.cc:31