MeteoIODoc 20240501.aefd3c94
IOInterface.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2009 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 IOINTERFACE_H
20#define IOINTERFACE_H
21
22#include <meteoio/Config.h> //so the plugins can get access to Config for their constructor
28
29#include <vector>
30#include <string>
31
32namespace mio {
33
43 public:
44 LinesRange() : start(), end() {}
45 LinesRange(const size_t& l1, const size_t& l2) : start(l1), end(l2) {}
46
52 bool in(const size_t& ll) const {
53 return (ll >= start && ll <= end);
54 }
55
61 bool operator<(const size_t& ll) const {
62 return end < ll;
63 }
64
70 bool operator>(const size_t& ll) const {
71 return start > ll;
72 }
73
74 bool operator<(const LinesRange& ll) const { //needed for "sort"
75 if (start==ll.start) return end < ll.end;
76 return start < ll.start;
77 }
78
79 bool operator==(const LinesRange& ll) const { //needed to check for uniqueness
80 return (start==ll.start) && (end==ll.end);
81 }
82
83 const std::string toString() const {std::ostringstream os; os << "[" << start << " - " << end << "]"; return os.str();}
84
85 size_t start, end;
86};
87
99 public:
100 virtual ~IOInterface() {}
101
112 virtual bool list2DGrids(const Date& start, const Date& end, std::map<Date, std::set<size_t> >& list);
113
120 virtual void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="");
121
129 virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
130
139 virtual void readPointsIn2DGrid(std::vector<double>& data, const MeteoGrids::Parameters& parameter, const Date& date, const std::vector< std::pair<size_t, size_t> >& Pts);
140
147 virtual void read3DGrid(Grid3DObject& grid_out, const std::string& parameter="");
148
156 virtual void read3DGrid(Grid3DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
157
169 virtual void readDEM(DEMObject& dem_out);
170
182 virtual void readLanduse(Grid2DObject& landuse_out);
183
195 virtual void readGlacier(Grid2DObject& glacier_out);
196
210 virtual void readStationData(const Date& date, std::vector<StationData>& vecStation);
211
234 virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
235 std::vector< std::vector<MeteoData> >& vecMeteo);
236
260 virtual void writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMeteo,
261 const std::string& name="");
262
276 virtual void readAssimilationData(const Date& date_in, Grid2DObject& da_out);
277
283 virtual void readPOI(std::vector<Coords>& pts);
284
291 virtual void write2DGrid(const Grid2DObject& grid_out, const std::string& options="");
292
300 virtual void write2DGrid(const Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
301
308 virtual void write3DGrid(const Grid3DObject& grid_out, const std::string& options="");
309
317 virtual void write3DGrid(const Grid3DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
318
319 static void set2DGridLatLon(Grid2DObject &grid, const double& i_ur_lat, const double& i_ur_lon);
320 static double computeGridXYCellsize(const std::vector<double>& vecX, const std::vector<double>& vecY);
321
333 static std::vector< LinesRange > initLinesRestrictions(const std::string& args, const std::string& where, const bool& negate);
334
335 protected:
340 static void mergeLinesRanges(std::vector< LinesRange >& lines_specs);
341};
342
343} //end namespace
344
345#endif
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
A class to represent 2D Grids. Typical application as DEM or Landuse Model.
Definition: Grid2DObject.h:42
A class to represent 3D Grids. Typical application: wind field.
Definition: Grid3DObject.h:39
A class representing the IO Layer of the software Alpine3D. For each type of IO (File,...
Definition: IOInterface.h:98
virtual void write3DGrid(const Grid3DObject &grid_out, const std::string &options="")
Write a Grid3DObject The filename is specified relative to GRID3DPATH for most plugins.
Definition: IOInterface.cc:156
virtual ~IOInterface()
Definition: IOInterface.h:100
virtual void readStationData(const Date &date, std::vector< StationData > &vecStation)
Fill vecStation with StationData objects for a certain date of interest.
Definition: IOInterface.cc:119
static std::vector< LinesRange > initLinesRestrictions(const std::string &args, const std::string &where, const bool &negate)
built the set of line ranges to read or skip.
Definition: IOInterface.cc:197
virtual void readDEM(DEMObject &dem_out)
Parse the DEM (Digital Elevation Model) into the Grid2DObject.
Definition: IOInterface.cc:104
virtual void read3DGrid(Grid3DObject &grid_out, const std::string &parameter="")
A generic function for parsing 3D grids into a Grid3DObject. The string parameter shall be used for a...
Definition: IOInterface.cc:94
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: IOInterface.cc:71
static void mergeLinesRanges(std::vector< LinesRange > &lines_specs)
Merge potentially overlaping line ranges.
Definition: IOInterface.cc:178
static void set2DGridLatLon(Grid2DObject &grid, const double &i_ur_lat, const double &i_ur_lon)
Definition: IOInterface.cc:166
virtual void readGlacier(Grid2DObject &glacier_out)
Parse the input glacier grid into the Grid2DObject.
Definition: IOInterface.cc:114
virtual void writeMeteoData(const std::vector< std::vector< MeteoData > > &vecMeteo, const std::string &name="")
Write vecMeteo time series to a certain destination.
Definition: IOInterface.cc:130
virtual void write2DGrid(const Grid2DObject &grid_out, const std::string &options="")
Write a Grid2DObject The filename is specified relative to GRID2DPATH for most plugins.
Definition: IOInterface.cc:146
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: IOInterface.cc:76
static double computeGridXYCellsize(const std::vector< double > &vecX, const std::vector< double > &vecY)
Definition: IOInterface.cc:173
virtual void readPOI(std::vector< Coords > &pts)
Read a list of points by their grid coordinates This allows for example to get a list of points where...
Definition: IOInterface.cc:141
virtual void readPointsIn2DGrid(std::vector< double > &data, const MeteoGrids::Parameters &parameter, const Date &date, const std::vector< std::pair< size_t, size_t > > &Pts)
Read the given meteo parameter into a vector for a list of points. Each plugin has its own logic for ...
Definition: IOInterface.cc:86
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: IOInterface.cc:124
virtual void readLanduse(Grid2DObject &landuse_out)
Parse the landuse model into the Grid2DObject.
Definition: IOInterface.cc:109
virtual void readAssimilationData(const Date &date_in, Grid2DObject &da_out)
Parse the assimilation data into a Grid2DObject for a certain date represented by the Date object.
Definition: IOInterface.cc:136
A class to represent and handle ranges of lines. They can be sorted, checked for uniqueness and a lin...
Definition: IOInterface.h:42
bool operator<(const LinesRange &ll) const
Definition: IOInterface.h:74
size_t end
Definition: IOInterface.h:85
size_t start
Definition: IOInterface.h:85
bool operator<(const size_t &ll) const
Is the provided line number before the end of the range?
Definition: IOInterface.h:61
const std::string toString() const
Definition: IOInterface.h:83
bool operator==(const LinesRange &ll) const
Definition: IOInterface.h:79
LinesRange()
Definition: IOInterface.h:44
bool in(const size_t &ll) const
Is the provided line number within the current range?
Definition: IOInterface.h:52
LinesRange(const size_t &l1, const size_t &l2)
Definition: IOInterface.h:45
bool operator>(const size_t &ll) const
Is the provided line number after the start of the range?
Definition: IOInterface.h:70
Parameters
this enum provides names for possible meteogrids (from an ARPS file, etc)
Definition: MeteoData.h:46
Definition: Config.cc:31