MeteoIODoc  2.10.0
CsvIO.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-or-later
2 /***********************************************************************************/
3 /* Copyright 2018 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 CSVIO_H
20 #define CSVIO_H
21 
22 #include <meteoio/IOInterface.h>
23 #include <meteoio/FileUtils.h>
26 
27 #include <string>
28 #include <vector>
29 
30 namespace mio {
39 class CsvIO : public IOInterface {
40  public:
41  CsvIO(const std::string& configfile);
42  CsvIO(const CsvIO&);
43  CsvIO(const Config& cfgreader);
44 
45  virtual void readStationData(const Date& date, std::vector<StationData>& vecStation);
46 
47  virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
48  std::vector< std::vector<MeteoData> >& vecMeteo);
49 
50  private:
51  void parseInputOutputSection();
52  void cleanup() noexcept;
53  std::string setDateParsing(const std::string& datetime_spec);
54  std::vector<std::string> readHeaders(std::ifstream& fin, CsvParameters& params) const;
55  static MeteoData createTemplate(const CsvParameters& params);
56  static Date getDate(CsvParameters& params, const std::vector<std::string>& vecFields, const bool& silent_errors, const std::string& filename, const size_t& linenr);
57  std::vector<MeteoData> readCSVFile(CsvParameters& params, const Date& dateStart, const Date& dateEnd);
58 
59  const Config cfg;
60  std::map<std::string, FileUtils::FileIndexer> indexer_map;
61  std::vector<CsvParameters> csvparam;
62  std::vector<StationData> vecStations;
63  std::string coordin, coordinparam; //projection parameters
64  static const size_t streampos_every_n_lines; //save current stream pos every n lines of data
65  bool silent_errors;
66  bool errors_to_nodata; //unparseable values are treated as nodata, but the dataset is kept
67 };
68 
69 } //namespace
70 #endif
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition: Config.h:79
Reads meteo data from a comma separated file.
Definition: CsvIO.h:39
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: CsvIO.cc:746
virtual void readStationData(const Date &date, std::vector< StationData > &vecStation)
Fill vecStation with StationData objects for a certain date of interest.
Definition: CsvIO.cc:558
CsvIO(const CsvIO &)
CsvIO(const std::string &configfile)
Definition: CsvIO.cc:350
Definition: CsvParams.h:89
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
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
A class to represent meteo stations with attributes like longitude, latitude, etc.
Definition: StationData.h:41
Definition: Config.cc:30