MeteoIODoc 20260620.13b5b0a5
Environmental timeseries pre-processing
Loading...
Searching...
No Matches
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/FStream.h>
24#include <meteoio/FileUtils.h>
27
28#include <string>
29#include <vector>
30
31namespace mio {
40class CsvIO : public IOInterface {
41 public:
42 CsvIO(const std::string& configfile);
43 CsvIO(const CsvIO&);
44 CsvIO(const Config& cfgreader);
45
46 virtual void readStationData(const Date& date, std::vector<StationData>& vecStation) override;
47
48 virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
49 std::vector< std::vector<MeteoData> >& vecMeteo) override;
50
51 private:
52 void parseInputOutputSection();
53 void cleanup() noexcept;
54 std::string setDateParsing(const std::string& datetime_spec);
55 std::vector<std::string> readHeaders(ifilestream& fin, CsvParameters& params) const;
56 static MeteoData createTemplate(const CsvParameters& params);
57 static Date getDate(CsvParameters& params, const std::vector<std::string>& vecFields, const bool& silent_errors, const std::string& filename, const size_t& linenr);
58 std::vector<MeteoData> readCSVFile(CsvParameters& params, const Date& dateStart, const Date& dateEnd);
59
60 const Config cfg;
61 std::map<std::string, FileUtils::FileIndexer> indexer_map;
62 std::vector<CsvParameters> csvparam;
63 std::vector<StationData> vecStations;
64 std::string coordin, coordinparam; //projection parameters
65 static const size_t streampos_every_n_lines; //save current stream pos every n lines of data
66 bool silent_errors;
67 bool errors_to_nodata; //unparseable values are treated as nodata, but the dataset is kept
68};
69
70} //namespace
71#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:40
virtual void readStationData(const Date &date, std::vector< StationData > &vecStation) override
Fill vecStation with StationData objects for a certain date of interest.
Definition CsvIO.cc:648
CsvIO(const CsvIO &)
virtual void readMeteoData(const Date &dateStart, const Date &dateEnd, std::vector< std::vector< MeteoData > > &vecMeteo) override
Fill vecMeteo with a time series of objects corresponding to the interval indicated by dateStart and ...
Definition CsvIO.cc:842
Definition CsvParams.h:91
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:121
A class to represent a singular measurement received from one station at a certain time (represented ...
Definition MeteoData.h:108
A class to represent meteo stations with attributes like longitude, latitude, etc.
Definition StationData.h:40
A class that extends std::ifstream, adding sandbox validation.
Definition FStream.h:69
Definition Config.cc:34