MeteoIODoc 20250905.f67af007
 
Loading...
Searching...
No Matches
iCSVIO.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2024 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 iCSV_H
20#define iCSV_H
21
22#include <meteoio/FileUtils.h>
23#include <meteoio/IOInterface.h>
24#include <meteoio/IOUtils.h>
27
28#include <vector>
29
30namespace mio {
31
32using namespace iCSV;
45class iCSVIO : public IOInterface {
46 public:
47 iCSVIO(const std::string &configfile);
48 iCSVIO(const iCSVIO &);
49 iCSVIO(const Config &cfgreader);
50
51 virtual void readStationData(const Date &date, std::vector<StationData> &vecStation) override;
52 virtual void readMeteoData(const Date &dateStart, const Date &dateEnd, std::vector<std::vector<MeteoData>> &vecMeteo) override;
53
54 virtual void writeMeteoData(const std::vector<std::vector<MeteoData>> &vecMeteo, const std::string &name = "") override;
55
56 private:
57 // constructor helpers
58 void parseInputSection();
59 void parseOutputSection();
60
61 // read helpers
62 static void identify_fields(const std::vector<std::string> &fields, std::vector<size_t> &indexes, MeteoData &md, const std::string &geometry_field);
63 static double getSnowpackSlope(const std::string &id);
64 void read_meta_data(const iCSVFile &current_file, StationData &meta) const;
65 void setMetaDataPosition(const iCSVFile &current_file, StationData &meta, const double &nodata_value) const;
66 void setMetaDataSlope(const iCSVFile &current_file, StationData &meta, const double &nodata_value) const;
67
68 void readDataSequential(iCSVFile &current_file) const;
69 std::vector<MeteoData> createMeteoDataVector(iCSVFile &current_file, std::vector<Date> &date_vec, std::vector<geoLocation> &location_vec) const;
70 static void setMeteoDataLocation(MeteoData &tmp_md, geoLocation &loc, iCSVFile &current_file, double nodata);
71 static void setMeteoDataFields(MeteoData &tmp_md, iCSVFile &current_file, const Date &date, std::vector<size_t> &indexes, double nodata);
72
73 // write helpers
74 void prepareOutfile(iCSVFile &outfile, const std::vector<MeteoData> &vecMeteo, bool file_exists) const;
75 void handleNewFile(iCSVFile &outfile, const std::vector<MeteoData> &vecMeteo, bool file_exists) const;
76 static void handleFileAppend(iCSVFile &outfile, const std::vector<MeteoData> &vecMeteo);
77
78 static std::string getGeometry(const geoLocation &loc);
79 static bool checkLocationConsistency(const std::vector<MeteoData> &vecMeteo);
80 bool createFilename(iCSVFile &outfile, const std::vector<MeteoData> &vecvecMeteo, size_t station_num) const;
81 void createMetaDataSection(iCSVFile &current_file, const std::vector<MeteoData> &vecMeteo) const;
82 static void createFieldsSection(iCSVFile &current_file, const std::vector<MeteoData> &vecMeteo);
83 void writeToFile(const iCSVFile &outfile);
84
85
86 // constants
87 const std::string iCSV_version = "1.0";
88 const std::string iCSV_firstline = "# iCSV " + iCSV_version + " UTF-8";
89
90 std::vector<iCSVFile> stations_files;
91 const Config cfg;
92 ACDD acdd;
93 std::string coordin, coordinparam, coordout, coordoutparam; // projection parameters
94 std::string file_extension_out, outpath, versioning_str;
95 double TZ_out;
96 VersioningType outputVersioning; //this is usefull when generating multiple versions of the same dataset, for example with forecast data
97 char out_delimiter;
98 bool snowpack_slopes, read_sequential, allow_overwrite, allow_append;
99};
100
101} // namespace
102#endif
This class contains and handles NetCDF Attribute Conventions Dataset Discovery attributes (see ACDD).
Definition libacdd.h:121
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 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
VersioningType
Definition IOInterface.h:337
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 to read and write iCSV files.
Definition iCSVIO.h:45
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 iCSVIO.cc:262
virtual void readStationData(const Date &date, std::vector< StationData > &vecStation) override
Fill vecStation with StationData objects for a certain date of interest.
Definition iCSVIO.cc:247
virtual void writeMeteoData(const std::vector< std::vector< MeteoData > > &vecMeteo, const std::string &name="") override
Write vecMeteo time series to a certain destination.
Definition iCSVIO.cc:517
iCSVIO(const iCSVIO &)
This class is responsible for handling and storing iCSV files.
Definition iCSVHelper.h:297
Definition Config.cc:34
Represents a geographic location extracted from iCSV files. (POINT(X Y)...)
Definition iCSVHelper.h:39