SNOWPACK  SNOWPACK-3.6.0
Utils.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 */
27 #ifndef UTILS_H
28 #define UTILS_H
29 
30 #include <snowpack/DataClasses.h>
31 
32 #include <cstdarg> // needed for va_list
33 #include <string>
34 #include <cstring>
35 #include <vector>
36 
37 #ifdef _MSC_VER
38 //Microsoft still does NOT support C99...
39 //This replacement is not fully compatible, so
40 //switch to a real, standard compliant compiler
41  #define snprintf _snprintf
42 #endif
43 
48 namespace snowpack {
49 std::string getLibVersion();
50 }
51 
52 #ifdef GNU //in this case, GCC can check the format arguments for types, number, ...
53 void prn_msg(const char *theFile, const int theLine, const char *msg_type, const mio::Date& date_in, const char *format, ...)
54 __attribute__ ((format (printf, 5, 6)));
55 #else
56 void prn_msg(const char *theFile, const int theLine, const char *msg_type, const mio::Date& date_in, const char *format, ...);
57 #endif
58 
59 bool booleanTime(const double& JulianDate, double days_between,
60  const double& start, const double& calculation_step_length);
61 
62 void deleteOldOutputFiles(const std::string& outdir, const std::string& experiment,
63  const std::string& stationID, const unsigned int& nSlopes,
64  const std::vector<std::string>& vecExtensions);
65 
66 void averageFluxTimeSeries(const size_t& n_steps, const bool& useCanopyModel,
67  SurfaceFluxes& Sdata, SnowStation& Xdata);
68 
69 void typeToCode(int *F1, int *F2, int *F3, int type);
70 
71 double unitConversion(const double val, char* unitIn, char* unitOut);
72 
73 bool massBalanceCheck(const SnowStation& Xdata, const SurfaceFluxes& Sdata, double& tot_mass_in);
74 
75 size_t findUpperNode(const double& z, const std::vector<NodeData>& Ndata, const size_t& nN);
76 
77 double forcedErosion(const double hs, SnowStation& Xdata);
78 
79 void deflateInflate(const CurrentMeteo& Mdata, SnowStation& Xdata, double& dhs_corr, double& mass_corr);
80 
81 double logisticFunction(const double input, const double threshold, const double width);
82 
83 void cumulate(double& accu, const double value);
84 
85 void checkOldOutputFiles(const mio::Date& i_date, const std::string& stationID);
86 
87 double getPerpSensorPosition(const bool& useSoilLayers, const double& z_vert, const double& hs_ref, const double& Ground, const double& SlopeAngle);
88 
94 
96 #define M_TO_CM( l ) ( (l) * 100. ) // meter to centimeters
98 #define M_TO_MM( l ) ( (l) * 1000. ) // meter to millimeters
99 #define CM_TO_M( l ) ( (l) / 100. ) // centimeter to meter
100 #define MM_TO_M( l ) ( (l) / 1000. ) // millimeter to meter
101 #define MM_TO_CM( l ) ( (l) / 10. ) // millimeter to centimeter
102 #define D_TO_H( t ) ( (t) * 24. ) // day to hours
104 #define D_TO_M( t ) ( (t) * 1440. ) // day to minutes
105 #define D_TO_S( t ) ( (t) * 86400. ) // day to seconds
106 #define H_TO_D( t ) ( (t) / 24.0 ) // hour to day
107 #define H_TO_M( t ) ( (t) * 60. ) // hour to minutes
108 #define H_TO_S( t ) ( (t) * 3600. ) // hour to seconds
109 #define M_TO_D( t ) ( (t) / 1440. ) // minute to day
110 #define M_TO_H( t ) ( (t) / 60. ) // minute to hour
111 #define M_TO_S( t ) ( (t) * 60. ) // minute to seconds
112 #define S_TO_D( t ) ( (t) / 86400. ) // second to day
113 #define S_TO_H( t ) ( (t) / 3600. ) // second to hour
114 #define S_TO_M( t ) ( (t) / 60. ) // second to minute
115 
116 
117 
118 #endif //End of Utils.h
void cumulate(double &accu, const double value)
Cumulate if and only if value is defined.
Definition: Utils.cc:585
bool booleanTime(const double &JulianDate, double days_between, const double &start, const double &calculation_step_length)
Determines whether a certain time has been reached (e.g. to dump output) The function returns TRUE wh...
Definition: Utils.cc:126
double forcedErosion(const double hs, SnowStation &Xdata)
Forced erosion of a missed event.
Definition: Utils.cc:436
double logisticFunction(const double input, const double threshold, const double width)
Logistic function.
Definition: Utils.cc:572
void averageFluxTimeSeries(const size_t &n_steps, const bool &useCanopyModel, SurfaceFluxes &Sdata, SnowStation &Xdata)
Averages energy fluxes.
Definition: Utils.cc:265
Definition: DataClasses.h:589
void typeToCode(int *F1, int *F2, int *F3, int type)
Decompose type in its constituents At present decomposition into Swiss numerical code TODO Adapt to ...
Definition: Utils.cc:286
size_t findUpperNode(const double &z, const std::vector< NodeData > &Ndata, const size_t &nN)
Returns number of lowest node above a given position z perpendicular to slope (m) ...
Definition: Utils.cc:221
double unitConversion(const double val, char *unitIn, char *unitOut)
Performs simple unit conversion (supports temperature, prefixes and exponents)
Definition: Utils.cc:303
CurrentMeteo is the class of interpolated meteo data for the current calculation time step It contai...
Definition: DataClasses.h:81
std::string getLibVersion()
Definition: Utils.cc:34
void deflateInflate(const CurrentMeteo &Mdata, SnowStation &Xdata, double &dhs_corr, double &mass_corr)
Deflates or inflates the snowpack for warning service purposes.
Definition: Utils.cc:470
bool massBalanceCheck(const SnowStation &Xdata, const SurfaceFluxes &Sdata, double &tot_mass_in)
Performs mass balance check either before or after a calculation time step.
Definition: Utils.cc:386
void deleteOldOutputFiles(const std::string &outdir, const std::string &experiment, const std::string &stationID, const unsigned int &nSlopes, const std::vector< std::string > &vecExtensions)
Delete old output files (*.sno, *.ini) from outdir.
Definition: Utils.cc:156
double getPerpSensorPosition(const bool &useSoilLayers, const double &z_vert, const double &hs_ref, const double &Ground, const double &SlopeAngle)
Returns sensor position perpendicular to slope (m). Negative vertical height indicates depth from eit...
Definition: Utils.cc:246
void checkOldOutputFiles(const mio::Date &i_date, const std::string &stationID)
Station data including all information on snowpack layers (elements and nodes) and on canopy This is...
Definition: DataClasses.h:468
Return the library version.
Definition: Utils.cc:33
void prn_msg(const char *theFile, const int theLine, const char *msg_type, const mio::Date &date_in, const char *format,...)
Print a message to screen (see p.351-352[,469] in C: The Complete Reference) If date_in is Date()...
Definition: Utils.cc:60