SNOWPACK 20241222.26c8720
CaaMLIO.h
Go to the documentation of this file.
1/***********************************************************************************/
2/* Copyright 2014 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
3/***********************************************************************************/
4/* This file is part of Snowpack.
5MeteoIO is free software: you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation, either version 3 of the License, or
8(at your option) any later version.
9
10MeteoIO is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License
16along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef CAAMLIO_H
19#define CAAMLIO_H
20
21#include <meteoio/MeteoIO.h>
22#include <snowpack/Constants.h>
23#include <snowpack/Hazard.h>
26
27#include <string>
28
29#pragma GCC diagnostic push
30#pragma GCC diagnostic ignored "-Weffc++"
31#include <snowpack/plugins/pugixml/pugixml.hpp>
32#pragma GCC diagnostic pop
33
34
44
45 public:
46 CaaMLIO(const SnowpackConfig& i_cfg, const RunInfo& run_info);
48
49 virtual bool snowCoverExists(const std::string& i_snowfile, const std::string& stationID) const;
50
51 virtual void readSnowCover(const std::string& i_snowfile, const std::string& stationID,
52 SN_SNOWSOIL_DATA& SSdata, ZwischenData& Zdata, const bool& read_salinity);
53
54 virtual void writeSnowCover(const mio::Date& date, const SnowStation& Xdata,
55 const ZwischenData& Zdata, const bool& forbackup=false);
56
57 virtual void writeTimeSeries(const SnowStation& Xdata, const SurfaceFluxes& Sdata, const CurrentMeteo& Mdata,
58 const ProcessDat& Hdata, const double wind_trans24);
59
60 virtual void writeProfile(const mio::Date& date, const SnowStation& Xdata);
61
62 virtual bool writeHazardData(const std::string& stationID, const std::vector<ProcessDat>& Hdata,
63 const std::vector<ProcessInd>& Hdata_ind, const size_t& num);
64
65 private:
66 void cleanup() throw();
67 void init(const SnowpackConfig& cfg);
68
69 void setBasicHeader(const SnowStation& Xdata, const std::string& fields, smet::SMETWriter& smet_writer) const;
70 void setSnoSmetHeader(const SnowStation& Xdata, const SN_SNOWSOIL_DATA& SSdata, const mio::Date& date, smet::SMETWriter& smet_writer) const;
71 void setFormatting(const size_t& nr_solutes, std::vector<int>& vec_width, std::vector<int>& vec_precision) const;
72 std::string getFilenamePrefix(const std::string& fnam, const std::string& path, const bool addexp=true) const;
73
74 //functions for reading caaml-files:
75 bool read_snocaaml(const std::string& snofilename, const std::string& stationID, SN_SNOWSOIL_DATA& SSdata);
76 void openIn_CAAML(const std::string& in_snowfile);
77 mio::Date xmlGetDate();
78 mio::StationData xmlGetStationData(const std::string& stationID);
79 void setCustomSnowSoil(SN_SNOWSOIL_DATA& Xdata);
80 void xmlReadLayerData(SN_SNOWSOIL_DATA& SSdata);
81 void adjustToSlopeAngle(SN_SNOWSOIL_DATA& SSdata); // #cmb
82 LayerData xmlGetLayer(pugi::xml_node nodeLayer, std::string& grainFormCode);
83 bool getLayersDir();
84 void getAndSetProfile(const std::string path, const std::string name,const bool directionTopDown,
85 const bool isRangeMeasurement,std::vector<LayerData>& Layers);
86 bool xmlGetProfile(const std::string path, const std::string name, std::vector<double>& zVec, std::vector<double>& valVec);
87 void estimateValidFormationTimesIfNotSetYet(std::vector<LayerData> &Layers, const mio::Date);
88 void checkAllDataForConsistencyAndSetMissingValues( SN_SNOWSOIL_DATA& SSdata );
89 bool checkWhatWasReadIn(SN_SNOWSOIL_DATA& SSdata);
90
91 //functions for writing caaml-file:
92 void writeSnowFile(const std::string& snofilename, const mio::Date& date, const SnowStation& Xdata);
93 void writeCustomSnowSoil(pugi::xml_node& node, const SnowStation& Xdata);
94 void writeLayers(pugi::xml_node& node, const SnowStation& Xdata);
95 void writeCustomLayerData(pugi::xml_node& node, const ElementData& Edata, const NodeData& Ndata);
96 void writeProfiles(pugi::xml_node& node, const SnowStation& Xdata);
97 void writeStationData(pugi::xml_node& root, const SnowStation& Xdata);
98
99 double lwc_codeToVal(const char* code);
100 std::string lwc_valToCode(const double val);
101 double hardness_codeToVal(char* code);
102 std::string hardness_valToCode(const double code);
103 void grainShape_codeToVal(const std::string& code, double &sp, double &dd, unsigned short int &mk);
104 std::string grainShape_valToAbbrev(const unsigned int var);
105 std::string grainShape_valToAbbrev_old(const double* var);
106
107 //xml functions:
108 double xmlReadValueFromPath(const std::string& xpath, const std::string& property, const double& dflt);
109 int xmlReadValueFromPath(const std::string& xpath, const std::string& property, const int& dflt);
110 void xmlWriteElement(pugi::xml_node& node, const char* name, const char* content, const char* att_name, const char* att_val);
111 bool xmlDoesPathExist(const std::string& path);
112 bool xmlReadValueFromNode(const pugi::xml_node node, const std::string propertyName, double& variableToSet,
113 const std::string unitOut = "",const std::string unitMeasured = "", const double factor=1.0);
114 std::string xmlReadAttributeFromPath (const std::string& path, const std::string& attributeName);
115
116 const RunInfo info;
117 std::string i_snowpath, o_snowpath, experiment;
118 double i_max_element_thickness;
119 bool caaml_writeout_as_readin, haz_write;
120 /*static const*/ double in_tz; //plugin specific time zones
121
122 pugi::xml_document inDoc;
123 pugi::xml_encoding inEncoding;
124
125 //charEncoding in_encoding;
126 static const char *xml_ns_caaml, *xml_ns_abrev_caaml;
127 static const char *xml_ns_gml, *xml_ns_abrev_gml;
128 static const char *xml_ns_xsi, *xml_ns_abrev_xsi;
129 static const char *xml_ns_slf, *xml_ns_abrev_slf;
130 static const char *xml_ns_snp, *xml_ns_abrev_snp;
131 static const std::string TimeData_xpath, StationMetaData_xpath, SnowData_xpath;
132
133 char layerDepthTopStr[10], layerThicknessStr[10], layerValStr[10], valueStr[10];
134 double hoarDensitySurf;
135 std::vector<std::string> grainForms;
136};
137
138#endif //End of CAAMLIO.h
Reading snow profile data in CAAML format. Reads in CAAML snow profile data, the CAA-IACS internation...
Definition: CaaMLIO.h:43
virtual bool snowCoverExists(const std::string &i_snowfile, const std::string &stationID) const
This routine checks if the specified snow cover data exists.
Definition: CaaMLIO.cc:494
virtual void writeProfile(const mio::Date &date, const SnowStation &Xdata)
Definition: CaaMLIO.cc:1387
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: CaaMLIO.cc:513
virtual void writeTimeSeries(const SnowStation &Xdata, const SurfaceFluxes &Sdata, const CurrentMeteo &Mdata, const ProcessDat &Hdata, const double wind_trans24)
Definition: CaaMLIO.cc:1381
virtual bool writeHazardData(const std::string &stationID, const std::vector< ProcessDat > &Hdata, const std::vector< ProcessInd > &Hdata_ind, const size_t &num)
Definition: CaaMLIO.cc:1392
CaaMLIO(const CaaMLIO &)
CaaMLIO(const SnowpackConfig &i_cfg, const RunInfo &run_info)
Definition: CaaMLIO.cc:420
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: CaaMLIO.cc:1049
CurrentMeteo is the class of interpolated meteo data for the current calculation time step It contai...
Definition: DataClasses.h:83
ELEMENT DATA used as a pointer in the SnowStation structure NOTE on M below: this is the mass of an e...
Definition: DataClasses.h:285
Parameters of the different layers of the snowpack.
Definition: DataClasses.h:186
NODAL DATA used as a pointer in the SnowStation structure.
Definition: DataClasses.h:393
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: 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