SNOWPACK 20241221.26c8720
SmetIO.h
Go to the documentation of this file.
1/*
2 * SNOWPACK stand-alone
3 *
4 * Copyright WSL Institute for Snow and Avalanche Research SLF, DAVOS, SWITZERLAND
5*/
6/* This file is part of Snowpack.
7 Snowpack is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 Snowpack is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Snowpack. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifndef SMET_IO_H
22#define SMET_IO_H
23
24#include <meteoio/MeteoIO.h>
25#include <snowpack/Constants.h>
27#include <snowpack/Hazard.h>
28
29#include <string>
30
32
33 public:
34 SmetIO(const SnowpackConfig& i_cfg, const RunInfo& run_info);
35 SmetIO(const SmetIO&);
36
37 ~SmetIO();
38
39 SmetIO& operator=(const SmetIO&);
40
41 virtual bool snowCoverExists(const std::string& i_snowfile, const std::string& stationID) const;
42
43 virtual void readSnowCover(const std::string& i_snowfile, const std::string& stationID,
44 SN_SNOWSOIL_DATA& SSdata, ZwischenData& Zdata, const bool& read_salinity);
45
46 virtual void writeSnowCover(const mio::Date& date, const SnowStation& Xdata,
47 const ZwischenData& Zdata, const bool& forbackup=false);
48
49 virtual void writeTimeSeries(const SnowStation& Xdata, const SurfaceFluxes& Sdata, const CurrentMeteo& Mdata,
50 const ProcessDat& Hdata, const double wind_trans24);
51
52 virtual void writeProfile(const mio::Date& date, const SnowStation& Xdata);
53
54 virtual bool writeHazardData(const std::string& stationID, const std::vector<ProcessDat>& Hdata,
55 const std::vector<ProcessInd>& Hdata_ind, const size_t& num);
56
57 mio::Date read_hazsmet(const std::string& hazfilename, ZwischenData& Zdata);
58 static void writeHazFile(const std::string& hazfilename, const mio::Date& date,
59 const SnowStation& Xdata, const ZwischenData& Zdata);
60
61 private:
62 std::string getFilenamePrefix(const std::string& fnam, const std::string& path, const bool addexp=true) const;
63 void writeSnoFile(const std::string& snofilename, const mio::Date& date, const SnowStation& Xdata, const ZwischenData& Zdata, const bool& write_pref_flow, const bool& write_ice_reservoir) const;
64 mio::Date read_snosmet(const std::string& snofilename, const std::string& stationID, SN_SNOWSOIL_DATA& SSdata, const bool& read_salinity) const;
65 mio::Date read_snosmet_header(const smet::SMETReader& sno_reader, const std::string& stationID,
66 SN_SNOWSOIL_DATA& SSdata) const;
67 double compPerpPosition(const double& z_vert, const double& hs_ref, const double& ground, const double& cos_sl) const;
68 std::string getFieldsHeader(const SnowStation& Xdata) const;
69 void writeTimeSeriesHeader(const SnowStation& Xdata, const double& tz, smet::SMETWriter& smet_writer) const;
70 void writeTimeSeriesData(const SnowStation& Xdata, const SurfaceFluxes& Sdata, const CurrentMeteo& Mdata, const ProcessDat& Hdata, const double &wind_trans24, smet::SMETWriter& smet_writer) const;
71
72 static void setBasicHeader(const SnowStation& Xdata, const std::string& fields, smet::SMETWriter& smet_writer);
73 static void setSnoSmetHeader(const SnowStation& Xdata, const mio::Date& date, smet::SMETWriter& smet_writer);
74 static void setFormatting(const size_t& nr_solutes,
75 std::vector<int>& vec_width, std::vector<int>& vec_precision, const bool& write_pref_flow, const bool& write_ice_reservoir, const bool& write_sea_ice);
76
77 static bool keyExists(const smet::SMETReader& reader, const std::string& key);
78 static double get_doubleval(const smet::SMETReader& reader, const std::string& keyname);
79 static double get_doubleval_no_error(const smet::SMETReader& reader, const std::string& key);
80 static int get_intval(const smet::SMETReader& reader, const std::string& keyname);
81
82 private:
83 std::vector<double> fixedPositions;
84 std::string outpath, o_snowpath, experiment, inpath, i_snowpath;
85 std::string metamorphism_model, variant, sw_mode;
86 const RunInfo info;
87 std::map<std::string, smet::SMETWriter*> tsWriters;
88 mio::ACDD acdd;
89 double in_dflt_TZ;
90 double calculation_step_length, ts_days_between;
91 double min_depth_subsurf;
92 bool avgsum_time_series, useCanopyModel, useSoilLayers, research_mode, perp_to_slope, precip_rates, haz_write;
93 bool useReferenceLayer; //Whether or not the output should be referenced to the marked reference layer (i.e., the layer with int(mk/1000)==9).
94 bool out_heat, out_lw, out_sw, out_meteo, out_haz, out_mass, out_t, out_load, out_stab, out_canopy, out_soileb, out_inflate;
95 bool useRichardsEq;
96 bool enable_pref_flow;
97 bool enable_ice_reservoir;
98 bool read_dsm;
99};
100
101#endif
CurrentMeteo is the class of interpolated meteo data for the current calculation time step It contai...
Definition: DataClasses.h:83
class to collect the information about the current simulation (version, date)
Definition: DataClasses.h:849
SN_SNOWSOIL_DATA includes all important station parameters as well as LayerData.
Definition: DataClasses.h:230
Definition: SmetIO.h:31
SmetIO(const SmetIO &)
virtual void readSnowCover(const std::string &i_snowfile, const std::string &stationID, SN_SNOWSOIL_DATA &SSdata, ZwischenData &Zdata, const bool &read_salinity)
This routine reads the status of the snow cover at program start.
Definition: SmetIO.cc:298
SmetIO(const SnowpackConfig &i_cfg, const RunInfo &run_info)
Definition: SmetIO.cc:147
SmetIO & operator=(const SmetIO &)
Assignement operator, required because of pointer member.
Definition: SmetIO.cc:227
virtual void writeSnowCover(const mio::Date &date, const SnowStation &Xdata, const ZwischenData &Zdata, const bool &forbackup=false)
This routine writes the status of the snow cover at program termination and at specified backup times...
Definition: SmetIO.cc:631
virtual bool snowCoverExists(const std::string &i_snowfile, const std::string &stationID) const
This routine checks if the specified snow cover data exists.
Definition: SmetIO.cc:278
mio::Date read_hazsmet(const std::string &hazfilename, ZwischenData &Zdata)
Definition: SmetIO.cc:322
static void writeHazFile(const std::string &hazfilename, const mio::Date &date, const SnowStation &Xdata, const ZwischenData &Zdata)
Definition: SmetIO.cc:653
virtual bool writeHazardData(const std::string &stationID, const std::vector< ProcessDat > &Hdata, const std::vector< ProcessInd > &Hdata_ind, const size_t &num)
Definition: SmetIO.cc:1453
virtual void writeProfile(const mio::Date &date, const SnowStation &Xdata)
Definition: SmetIO.cc:1448
virtual void writeTimeSeries(const SnowStation &Xdata, const SurfaceFluxes &Sdata, const CurrentMeteo &Mdata, const ProcessDat &Hdata, const double wind_trans24)
Definition: SmetIO.cc:1424
~SmetIO()
Definition: SmetIO.cc:217
Definition: DataClasses.h:604
Definition: SnowpackConfig.h:28
Definition: SnowpackIOInterface.h:27
Definition: DataClasses.h:733
ZwischenData contains "memory" information mainly for operational use It is used to prepare some para...
Definition: DataClasses.h:65
Structure of double values for output to SDB.
Definition: Hazard.h:37