MeteoIODoc  2.10.0
OshdIO.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-or-later
2 /***********************************************************************************/
3 /* Copyright 2016 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 OSHDIO_H
20 #define OSHDIO_H
21 
22 #include <meteoio/IOInterface.h>
23 
24 #include <string>
25 
26 namespace mio {
27 
36 class OshdIO : public IOInterface {
37  public:
38  OshdIO(const std::string& configfile);
39  OshdIO(const OshdIO&);
40  OshdIO(const Config& cfgreader);
41 
42  virtual void readStationData(const Date& date, std::vector<StationData>& vecStation);
43 
44  virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
45  std::vector< std::vector<MeteoData> >& vecMeteo);
46 
47  virtual bool list2DGrids(const Date& start, const Date& end, std::map<Date, std::set<size_t> >& list);
48  virtual void read2DGrid(Grid2DObject& grid_out, const std::string& filename="");
49  virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
50  virtual void readDEM(DEMObject& dem_out);
51 
52  private:
53  struct file_index {
54  file_index(const Date& i_date, const std::string& i_path, const std::string& i_filename, const std::string& i_run_date)
55  : date(i_date), run_date(i_run_date), path(i_path), filename(i_filename) {}
56  bool operator<(const file_index& a) const {
57  return date < a.date;
58  }
59  bool operator>(const file_index& a) const {
60  return date > a.date;
61  }
62  std::string toString() const {
63  return "<"+date.toString(Date::ISO)+" - "+run_date+" "+path+" "+filename+">";
64  }
65  Date date;
66  std::string run_date;
67  std::string path;
68  std::string filename;
69  };
70 
71  struct station_index {
72  station_index(const std::string& i_id)
73  : id(i_id), oshd_acro(), idx(IOUtils::npos) {}
74  station_index(const std::string& i_id, const std::string& acro, const size_t& i_idx)
75  : id(i_id), oshd_acro(acro), idx(i_idx) {}
76  std::string id, oshd_acro;
77  size_t idx;
78  };
79 
80  void parseInputOutputSection();
81  void readFromFile(const std::string& file_and_path, const Date& in_timestep, std::vector< std::vector<MeteoData> >& vecMeteo) const;
82  void buildVecIdx(std::vector<std::string> vecAcro);
83  void fillStationMeta();
84 
85  static size_t getFileIdx(const std::vector< struct file_index >& cache, const Date& start_date);
86  static std::vector< struct file_index > scanMeteoPath(const std::string& meteopath_in, const bool& is_recursive);
87  static double convertUnits(const double& val, const std::string& units, const size_t& param, const std::string& filename);
88 
89  const Config cfg;
90  std::vector< struct file_index > cache_meteo_files; //cache of meteo files in METEOPATH
91  std::vector< struct file_index > cache_grid_files; //cache of meteo files in METEOPATH
92  std::vector<StationData> vecMeta;
93  std::vector< struct station_index > statIDs;
94  std::string coordin, coordinparam; //projection parameters
95  std::string grid2dpath_in, in_meteopath, in_metafile;
96  size_t nrMetadata;
97  bool debug;
98 
99  static const char* meteo_ext; //for the file naming scheme
100  static std::map< std::string, MeteoGrids::Parameters > params_map;
101  static std::map< MeteoGrids::Parameters, std::string > grids_map;
102  static const double in_dflt_TZ; //default time zone, should be visible to matio for debugging
103  static const bool __init;
104  static bool initStaticData();
105 };
106 
107 } //namespace
108 #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 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
@ ISO
ISO 8601 extended format combined date: YYYY-MM-DDTHH:mm:SS.sss (fields might be dropped,...
Definition: Date.h:91
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
Parameters
this enum provides names for possible meteogrids (from an ARPS file, etc)
Definition: MeteoData.h:46
This plugin reads Matlab binary files, relying on the MatIO library.
Definition: OshdIO.h:36
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: OshdIO.cc:293
virtual bool list2DGrids(const Date &start, const Date &end, std::map< Date, std::set< size_t > > &list)
Return the list of grids within a given time period that could be read by the plugin,...
Definition: OshdIO.cc:251
OshdIO(const OshdIO &)
virtual void read2DGrid(Grid2DObject &grid_out, const std::string &filename="")
A generic function for parsing 2D grids into a Grid2DObject. The string parameter shall be used for a...
Definition: OshdIO.cc:529
virtual void readStationData(const Date &date, std::vector< StationData > &vecStation)
Fill vecStation with StationData objects for a certain date of interest.
Definition: OshdIO.cc:286
OshdIO(const std::string &configfile)
Definition: OshdIO.cc:128
virtual void readDEM(DEMObject &dem_out)
Parse the DEM (Digital Elevation Model) into the Grid2DObject.
Definition: OshdIO.cc:576
const size_t npos
npos is the out-of-range value
Definition: IOUtils.h:80
std::string toString(const T &t)
Definition: IOUtils.h:289
Definition: Config.cc:30