WSL/SLF GitLab Repository

Commit 174a0b12 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Last small changes, and MeteoIO compiles with Visual C++!! (but not the plugins)

A few functions have been added to the Atmosphere class that are usefull (specifically for Alpine3D snowdrift)
parent e5b18035
......@@ -36,6 +36,7 @@ IF(UNIX)
ELSE(UNIX)
IF(WIN32)
set(PLATFORM "-DWIN32 -U__STRICT_ANSI__ -D_USE_MATH_DEFINES")
# see IF(MSVC) "/MD /MDd"
set(EXTRA_WARNINGS "-ansi")
ENDIF(WIN32)
ENDIF(UNIX)
......
......@@ -148,7 +148,7 @@ bool IOUtils::readKeyValuePair(const std::string& in_line, const std::string& de
bool IOUtils::validFileName(const std::string& filename)
{
size_t startpos = filename.find_first_not_of(" \t\n"); // Find the first character position after excluding leading blank spaces
const size_t startpos = filename.find_first_not_of(" \t\n"); // Find the first character position after excluding leading blank spaces
if((startpos!=0) || (filename==".") || (filename=="..")) {
return false;
}
......@@ -159,7 +159,7 @@ bool IOUtils::validFileName(const std::string& filename)
#ifdef _WIN32
bool IOUtils::fileExists(const std::string& filename)
{
return ( GetFileAttributes( filename ) != INVALID_FILE_ATTRIBUTES );
return ( GetFileAttributes( filename.c_str() ) != INVALID_FILE_ATTRIBUTES );
}
void IOUtils::readDirectory(const std::string& path, std::list<std::string>& dirlist, const std::string& pattern)
......@@ -167,13 +167,14 @@ void IOUtils::readDirectory(const std::string& path, std::list<std::string>& dir
WIN32_FIND_DATA ffd;
HANDLE hFind = INVALID_HANDLE_VALUE;
size_t path_length = path.length();
const size_t path_length = path.length();
if (path_length > (MAX_PATH - 3)) {
std::cout << "Path " << path << "is too long (" << path_length << " characters)" << std::endl;
throw FileAccessException("Error opening directory " + path, AT);
}
hFind = FindFirstFile(path+"\\"+pattern, &ffd);
const std::string filepath = path+"\\"+pattern;
hFind = FindFirstFile(filepath.c_str(), &ffd);
if (INVALID_HANDLE_VALUE == hFind) {
throw FileAccessException("Error opening directory " + path, AT);
}
......@@ -217,12 +218,12 @@ void IOUtils::readDirectory(const std::string& path, std::list<std::string>& dir
}
while ((dirp = readdir(dp)) != NULL) {
std::string tmp = std::string(dirp->d_name);
const std::string tmp = std::string(dirp->d_name);
if( tmp.compare(".")!=0 && tmp.compare("..")!=0 ) { //skip "." and ".."
if (pattern=="") {
dirlist.push_back(tmp);
} else {
size_t pos = tmp.find(pattern);
const size_t pos = tmp.find(pattern);
if (pos!=std::string::npos) {
dirlist.push_back(tmp);
}
......
......@@ -61,6 +61,26 @@ double Atmosphere::stdAirPressure(const double& altitude) {
return(p);
}
/**
* @brief Standard dry air pressure
* @param altitude altitude above sea level (m)
* @param temperature air temperature (K)
* @return standard pressure (Pa)
*/
double Atmosphere::stdDryAirDensity(const double& altitude, const double& temperature) {
return stdAirPressure(altitude)/(Cst::gaz_constant_dry_air*temperature);
}
/**
* @brief Calculates the water vapor density, for a given temperature and vapor pressure
* @param temperature air temperature (K)
* @param VaporPressure water vapor pressure (Pa)
* @return water vapor density (kg/m^3)
*/
double Atmosphere::waterVaporDensity(const double& Temperature, const double& VaporPressure) {
return (Cst::water_molecular_mass*VaporPressure)/(Cst::gaz_constant*Temperature);
}
/**
* @brief Standard atmosphere wet bulb temperature.
* This gives the lowest temperature that could be reached by water evaporation. It is therefore linked to
......@@ -280,4 +300,34 @@ double Atmosphere::DewPointtoRh(double TD, double TA, const bool& force_water)
}
}
/**
* @brief Calculate the relative Humidity (RH) from specific humidity.
* @param altitude altitude over sea level (m)
* @param TA air temperature (K)
* @param qi specific humidity
* @return relative humidity between 0 and 1
*/
double Atmosphere::specToRelHumidity(const double& altitude, const double& TA, const double& qi)
{//HACK: should we check that RH in [0;1]?
const double SatVaporDensity = waterVaporDensity(TA, waterSaturationPressure(TA));
const double RH = (qi/(1.-qi))*stdDryAirDensity(altitude, TA)/SatVaporDensity;
return RH;
}
/**
* @brief Calculate the specific Humidity from relative humidity (RH).
* @param altitude altitude over sea level (m)
* @param TA air temperature (K)
* @param RH relative humidity (between 0 and 1)
* @return specific humidity
*/
double Atmosphere::relToSpecHumidity(const double& altitude, const double& TA, const double& RH)
{
const double dryAir_density = stdDryAirDensity(altitude, TA);
const double wetAir_density = RH * waterVaporDensity(TA,waterSaturationPressure(TA));
const double qi = 1./( dryAir_density/wetAir_density+1. );
return qi;
}
} //namespace
......@@ -32,7 +32,9 @@ class Atmosphere {
public:
static double stdAirPressure(const double& altitude);
static double stdDryAirDensity(const double& altitude, const double& temperature);
static double waterSaturationPressure(const double& T);
static double waterVaporDensity(const double& Temperature, const double& VaporPressure);
static double wetBulbTemperature(const double& T, const double& RH, const double& altitude);
static double Omstedt_emissivity(const double& e0, const double& cloudiness);
......@@ -42,6 +44,8 @@ class Atmosphere {
static double RhtoDewPoint(double RH, double TA, const bool& force_water);
static double DewPointtoRh(double TD, double TA, const bool& force_water);
static double specToRelHumidity(const double& altitude, const double& TA, const double& qi);
static double relToSpecHumidity(const double& altitude, const double& TA, const double& RH);
static double blkBody_Emissivity(const double& lwr, const double& T);
static double blkBody_Radiation(const double& ea, const double& T);
......
......@@ -25,7 +25,7 @@ namespace Cst {
const double gravity = 9.80665; // (m s-2)
const double std_press = 101325.; // (Pa)
const double gaz_constant_dry_air = 287.; // (J kg-1 K-1)
const double gaz_constant_dry_air = 287.058; // (J kg-1 K-1)
const double gaz_constant_water_vapor = 461.9; // (J kg-1 K-1)
const double gaz_constant = 8.31451; // (J mol-1 K-1)
......@@ -35,6 +35,7 @@ namespace Cst {
const double l_water_sublimation = 2.838e6; // (J Kg-1)
const double l_water_vaporization = 2.504e6; // (J Kg-1)
const double l_water_fusion = 3.34e5; // (J Kg-1)
const double water_molecular_mass = 18.0153e-3; // (Kg)
const double specific_heat_ice = 2100.0; // (J K-1), at 0C
const double specific_heat_water = 4190.0; // (J K-1) at 0C
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment