SNOWPACK 3.7.0
Utils.h File Reference

This header file contains the definition of the structures required to handle I/O. More...

#include <snowpack/DataClasses.h>
#include <cstdarg>
#include <string>
#include <cstring>
#include <vector>

Go to the source code of this file.

Namespaces

namespace  snowpack
 Return the library version.
 

Macros

Conversion macros
#define M_TO_CM(l)   ( (l) * 100. )
 For lengths. More...
 
#define M_TO_MM(l)   ( (l) * 1000. )
 
#define CM_TO_M(l)   ( (l) / 100. )
 
#define MM_TO_M(l)   ( (l) / 1000. )
 
#define MM_TO_CM(l)   ( (l) / 10. )
 
#define D_TO_H(t)   ( (t) * 24. )
 For time. More...
 
#define D_TO_M(t)   ( (t) * 1440. )
 
#define D_TO_S(t)   ( (t) * 86400. )
 
#define H_TO_D(t)   ( (t) / 24.0 )
 
#define H_TO_M(t)   ( (t) * 60. )
 
#define H_TO_S(t)   ( (t) * 3600. )
 
#define M_TO_D(t)   ( (t) / 1440. )
 
#define M_TO_H(t)   ( (t) / 60. )
 
#define M_TO_S(t)   ( (t) * 60. )
 
#define S_TO_D(t)   ( (t) / 86400. )
 
#define S_TO_H(t)   ( (t) / 3600. )
 
#define S_TO_M(t)   ( (t) / 60. )
 

Functions

std::string snowpack::getLibVersion ()
 
void prn_msg (const char *fileAndPath, 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(), no running date will be written,
otherwise write date_in to (<t>)
The output format depends on message type: More...
 
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 whenever JulianDate >= start && JulianDate == start + n*days_between, n=0,1,2,... More...
 
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. More...
 
void averageFluxTimeSeries (const size_t &n_steps, const bool &useCanopyModel, SurfaceFluxes &Sdata, SnowStation &Xdata)
 Averages energy fluxes. More...
 
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 new international code. More...
 
double unitConversion (const double val, char *unitIn, char *unitOut)
 Performs simple unit conversion (supports temperature, prefixes and exponents) More...
 
bool massBalanceCheck (const SnowStation &Xdata, const SurfaceFluxes &Sdata, double &tot_mass_in)
 Performs mass balance check either before or after a calculation time step. More...
 
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)
. More...
 
double forcedErosion (const double hs, SnowStation &Xdata)
 Forced erosion of a missed event. More...
 
void deflateInflate (const CurrentMeteo &Mdata, SnowStation &Xdata, double &dhs_corr, double &mass_corr, const bool &prn_check)
 Deflates or inflates the snowpack for warning service purposes. More...
 
double logisticFunction (const double input, const double threshold, const double width)
 Logistic function. More...
 
void cumulate (double &accu, const double value)
 Cumulate if and only if value is defined. More...
 
void checkOldOutputFiles (const mio::Date &i_date, const std::string &stationID)
 
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 either snow or ground surface (depending on useSoilLayers). For example, a sensor at -0.1 when useSoilLayers=false means a snow temperature at 10cm below the surface; a sensor at -0.2 when useSoilLayers=true means a soil temperature 20cm deep in the ground. NOTE: Depth from snow surface cannot be used with SNP_SOIL set. More...
 

Detailed Description

This header file contains the definition of the structures required to handle I/O.

Version
10.02
Date
-

Macro Definition Documentation

◆ CM_TO_M

#define CM_TO_M (   l)    ( (l) / 100. )

◆ D_TO_H

#define D_TO_H (   t)    ( (t) * 24. )

For time.

◆ D_TO_M

#define D_TO_M (   t)    ( (t) * 1440. )

◆ D_TO_S

#define D_TO_S (   t)    ( (t) * 86400. )

◆ H_TO_D

#define H_TO_D (   t)    ( (t) / 24.0 )

◆ H_TO_M

#define H_TO_M (   t)    ( (t) * 60. )

◆ H_TO_S

#define H_TO_S (   t)    ( (t) * 3600. )

◆ M_TO_CM

#define M_TO_CM (   l)    ( (l) * 100. )

For lengths.

◆ M_TO_D

#define M_TO_D (   t)    ( (t) / 1440. )

◆ M_TO_H

#define M_TO_H (   t)    ( (t) / 60. )

◆ M_TO_MM

#define M_TO_MM (   l)    ( (l) * 1000. )

◆ M_TO_S

#define M_TO_S (   t)    ( (t) * 60. )

◆ MM_TO_CM

#define MM_TO_CM (   l)    ( (l) / 10. )

◆ MM_TO_M

#define MM_TO_M (   l)    ( (l) / 1000. )

◆ S_TO_D

#define S_TO_D (   t)    ( (t) / 86400. )

◆ S_TO_H

#define S_TO_H (   t)    ( (t) / 3600. )

◆ S_TO_M

#define S_TO_M (   t)    ( (t) / 60. )

Function Documentation

◆ averageFluxTimeSeries()

void averageFluxTimeSeries ( const size_t &  n_steps,
const bool &  useCanopyModel,
SurfaceFluxes Sdata,
SnowStation Xdata 
)

Averages energy fluxes.

Version
11.03
Parameters
n_stepsNumber of calculation time steps since last output
useCanopyModel
Sdata
Xdata

◆ booleanTime()

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 whenever JulianDate >= start && JulianDate == start + n*days_between, n=0,1,2,...

  • Start must be a Julian Date with origin 1900-01-01T00:00
  • In case regular dumps are requested throughout the day, it is best to set start to 0.0. This is the preferred setting in operational mode with *_START = 0.0
  • This version is the result of various efforts (Michael Lehning, Julia Kowalski, Henning Loewe, Charles Fierz, Mathias Bavay)
    Parameters
    JulianDateJulian Date
    days_betweennumber of days between two outputs
    startstart date as Julian Date
    calculation_step_length(min) //HACK: it should be in SI!!
    Returns
    int

◆ checkOldOutputFiles()

void checkOldOutputFiles ( const mio::Date &  i_date,
const std::string &  stationID 
)

◆ cumulate()

void cumulate ( double &  accu,
const double  value 
)

Cumulate if and only if value is defined.

Version
11.01
Parameters
accucumulator
valueto be added to accu

◆ deflateInflate()

void deflateInflate ( const CurrentMeteo Mdata,
SnowStation Xdata,
double &  dhs_corr,
double &  mass_corr,
const bool &  prn_check 
)

Deflates or inflates the snowpack for warning service purposes.

  • Forced erosion: dhs_corr < 0. & mass_corr > 0.
  • Deflate : dhs_corr < 0. & mass_corr < 0.
  • Inlate : dhs_corr > 0. & mass_corr > 0.
    Note
    Michi is very unhappy that the warning service wants to deflate or inflate the snow if there is a consistent under- oder overestimation of settling, respectively. But since the will of the warning service is law at the SLF, we have no choice and need to implement this additional terrible non mass-conserving and cheating feature. But it will make the operational users happy, I hope.
    Implemented on 2 Feb 2008 (and 7 Mar 2008: back to erosion) by Mathias Bavay and Michi, who should be home with Leo being sick ...
    Parameters
    Mdata
    Xdata
    dhs_corrCorrection on calculated snow depth (m)
    mass_corrMass correction (kg m-2)
    prn_checkIf set to true, output an information message when correcting for a missed erosion event or wrong settling

◆ deleteOldOutputFiles()

void deleteOldOutputFiles ( const std::string &  outdir,
const std::string &  experiment,
const std::string &  stationID,
const unsigned int &  nSlopes,
const std::vector< std::string > &  vecExtension 
)

Delete old output files (*.sno, *.ini) from outdir.

Parameters
outdirOutput dir
experimentName of ongoing experiment
stationID
nSlopesNumber of slopes treated
vecExtensionfile extensions that have to be removed

◆ findUpperNode()

size_t findUpperNode ( const double &  z,
const vector< NodeData > &  Ndata,
const size_t &  nN 
)

Returns number of lowest node above a given position z perpendicular to slope (m)
.

Author
Charles Fierz
Version
10.02
Parameters
zPosition perpendicular to slope (m)
Ndata
nNNumber of nodes
Returns
Upper node number

◆ forcedErosion()

double forcedErosion ( const double  hs,
SnowStation Xdata 
)

Forced erosion of a missed event.

Author
Michael Lehning
Mathis Bavay
Date
2008-03-07
Parameters
hsSnow depth to assimilate
Xdata
Returns
Eroded mass (kg m-2)

◆ getPerpSensorPosition()

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 either snow or ground surface (depending on useSoilLayers). For example, a sensor at -0.1 when useSoilLayers=false means a snow temperature at 10cm below the surface; a sensor at -0.2 when useSoilLayers=true means a soil temperature 20cm deep in the ground. NOTE: Depth from snow surface cannot be used with SNP_SOIL set.

Author
Charles Fierz
Version
10.02
Parameters
useSoilLayersAre soil layers defined?
z_vertVertical position of the sensor (m)
hs_refHeight of snow to refer to (m)
GroundGround level (m)
SlopeAngle(rad)

◆ logisticFunction()

double logisticFunction ( const double  input,
const double  threshold,
const double  width 
)

Logistic function.

Version
10.11
Parameters
inputvalue
thresholdThreshold of logistic function
widthWidth of logistic function

◆ massBalanceCheck()

bool massBalanceCheck ( const SnowStation Xdata,
const SurfaceFluxes Sdata,
double &  tot_mass_in 
)

Performs mass balance check either before or after a calculation time step.

  • NOTE: AVGSUM_TIME_SERIES should not be set
    Author
    Charles Fierz
    Version
    10.03
    Parameters
    Xdata
    Sdata
    tot_mass_inTotal mass after last time step (kg m-2)
    Returns
    bool if mass error occured, putting balance terms on screen

◆ prn_msg()

void prn_msg ( const char *  fileAndPath,
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(), no running date will be written,
otherwise write date_in to (<t>)
The output format depends on message type:

  • "err" : [E] [<t>] [<file>:<line>] <on date_in> <msg> \n
  • "wrn" : [W] [<t>] [<file>:<line>] <on date_in> <msg> \n
  • "msg+" : [I] [<t>] [<file>:<line>] <on date_in> <msg> \n
  • "msg" : [i] [<t>] —> <msg> <n>
  • "msg-" : [i] [] <msg> <n>
    Author
    Charles Fierz
    Mathias Bavay
    Version
    11.02
    Parameters
    *fileAndPath
    theLine
    *msg_typeSee above
    date_inUse Date() if date_in is not available.
    *formatFormat for message
    ...Variable number of parameters to format

◆ typeToCode()

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 new international code.

Author
Charles Fierz
Version
9.12
Parameters
F1Majority grain shape
F2Minority grain shape
F32 indicates a melt-freeze crust
typeaggregated shape information

◆ unitConversion()

double unitConversion ( const double  val,
char *  unitIn,
char *  unitOut 
)

Performs simple unit conversion (supports temperature, prefixes and exponents)

Author
Adrien Gaudard
Version
11.03
Parameters
valValue (expressed in unitIn)
unitIn(units of input)
unitOut(units of output) return Value (expressed in unitOut)