MeteoIODoc 2.11.0
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
32 using namespace iCSV;
45 class 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);
52 virtual void readMeteoData(const Date &dateStart, const Date &dateEnd, std::vector<std::vector<MeteoData>> &vecMeteo);
53
54 virtual void writeMeteoData(const std::vector<std::vector<MeteoData>> &vecMeteo, const std::string &name = "");
55
56 private:
57 // input section
58 const Config cfg;
59 std::string coordin, coordinparam, coordout, coordoutparam; // projection parameters
60 bool snowpack_slopes;
61 bool read_sequential;
62
63 // file information
64 std::vector<iCSVFile> stations_files;
65
66 // output section
67 ACDD acdd_metadata;
68 double TZ_out;
69 std::string outpath;
70 bool allow_overwrite;
71 bool allow_append;
72 char out_delimiter;
73 std::string file_extension_out;
74
75
76 // constants
77 const std::string iCSV_version = "1.0";
78 const std::string iCSV_firstline = "# iCSV " + iCSV_version + " UTF-8";
79 static const double snVirtualSlopeAngle;
80
81 // constructor helpers
82 void parseInputSection();
83 void parseOutputSection();
84
85 // read helpers
86 void identify_fields(const std::vector<std::string> &fields, std::vector<size_t> &indexes, MeteoData &md,
87 const std::string &geometry_field);
88 double getSnowpackSlope(const std::string &id);
89 void read_meta_data(const iCSVFile &current_file, StationData &meta);
90 void setMetaDataPosition(const iCSVFile &current_file, StationData &meta, const double &nodata_value);
91 void setMetaDataSlope(const iCSVFile &current_file, StationData &meta, const double &nodata_value);
92
93 void readDataSequential(iCSVFile &current_file);
94 std::vector<MeteoData> createMeteoDataVector(iCSVFile &current_file, std::vector<Date> &date_vec,
95 std::vector<geoLocation> &location_vec);
96 void setMeteoDataLocation(MeteoData &tmp_md, geoLocation &loc, iCSVFile &current_file, double nodata);
97 void setMeteoDataFields(MeteoData &tmp_md, iCSVFile &current_file, Date &date, std::vector<size_t> &indexes, double nodata);
98
99 // write helpers
100 void prepareOutfile(iCSVFile &outfile, const std::vector<MeteoData> &vecMeteo, bool file_exists);
101 void handleNewFile(iCSVFile &outfile, const std::vector<MeteoData> &vecMeteo, bool file_exists);
102 void handleFileAppend(iCSVFile &outfile, const std::vector<MeteoData> &vecMeteo);
103
104 std::string getGeometry(const geoLocation &loc);
105 bool checkLocationConsistency(const std::vector<MeteoData> &vecMeteo);
106 bool createFilename(iCSVFile &outfile, const StationData &station, size_t station_num);
107 void createMetaDataSection(iCSVFile &current_file, const std::vector<MeteoData> &vecMeteo);
108 void createFieldsSection(iCSVFile &current_file, const std::vector<MeteoData> &vecMeteo);
109 void writeToFile(const iCSVFile &outfile);
110 };
111
112} // namespace
113#endif
This class contains and handles NetCDF Attribute Conventions Dataset Discovery attributes (see ACDD).
Definition: libacdd.h:113
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
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
A class to read and write iCSV files.
Definition: iCSVIO.h:45
virtual void readStationData(const Date &date, std::vector< StationData > &vecStation)
Fill vecStation with StationData objects for a certain date of interest.
Definition: iCSVIO.cc:242
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: iCSVIO.cc:256
virtual void writeMeteoData(const std::vector< std::vector< MeteoData > > &vecMeteo, const std::string &name="")
Write vecMeteo time series to a certain destination.
Definition: iCSVIO.cc:506
iCSVIO(const std::string &configfile)
Definition: iCSVIO.cc:168
iCSVIO(const iCSVIO &)
This class is responsible for handling and storing iCSV files.
Definition: iCSVHelper.h:297
const double nodata
This is the internal nodata value.
Definition: IOUtils.h:75
Definition: Config.cc:31
Represents a geographic location extracted from iCSV files. (POINT(X Y)...)
Definition: iCSVHelper.h:39