WSL/SLF GitLab Repository

Commit 4f010eb5 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

A warning has been fixed for Clang on FreeBSD by setting a compilation flag...

A warning has been fixed for Clang on FreeBSD by setting a compilation flag only for one specific file. A clear sky, potential short wave generator has been implemented as this is very useful when working with SW radiation. A bug in the AllSkySW generator has been fixed as it was not using TAU_CLD if available in one of the two possible calls. Its documentation was also not proper and has been improved.
parent b6648754
......@@ -56,6 +56,8 @@ SET(meteoio_sources
${dataGenerators_sources}
)
set_source_files_properties(IOUtils.cc PROPERTIES COMPILE_FLAGS -Wno-date-time)
IF(GUI_EXCEPTIONS)
IF(MSVC)
ADD_DEFINITIONS(/DMSG_BOX)
......
......@@ -93,7 +93,7 @@ bool AllSkySWGenerator::generate(const size_t& param, std::vector<MeteoData>& ve
for (size_t ii=0; ii<vecMeteo.size(); ii++) {
double &value = vecMeteo[ii](param);
if (value == IOUtils::nodata) {
const double ISWR=vecMeteo[ii](MeteoData::ISWR), RSWR=vecMeteo[ii](MeteoData::RSWR), HS=vecMeteo[ii](MeteoData::HS);
const double ISWR=vecMeteo[ii](MeteoData::ISWR), RSWR=vecMeteo[ii](MeteoData::RSWR), HS=vecMeteo[ii](MeteoData::HS), TAU_CLD=vecMeteo[ii](MeteoData::HS);
double TA=vecMeteo[ii](MeteoData::TA), RH=vecMeteo[ii](MeteoData::RH), ILWR=vecMeteo[ii](MeteoData::ILWR);
double albedo = .5;
......@@ -114,7 +114,7 @@ bool AllSkySWGenerator::generate(const size_t& param, std::vector<MeteoData>& ve
}
sun.setDate(vecMeteo[ii].date.getJulian(true), 0.);
const double solarIndex = (ILWR!=IOUtils::nodata)? getSolarIndex(TA, RH, ILWR) : 1.;
const double solarIndex = (TAU_CLD!=IOUtils::nodata)? TAU_CLD : (ILWR!=IOUtils::nodata)? getSolarIndex(TA, RH, ILWR) : 1.;
const double P=vecMeteo[ii](MeteoData::P);
if (P==IOUtils::nodata)
......
......@@ -28,9 +28,9 @@ namespace mio {
* @brief ISWR all sky parametrization
*
* Using air temperature (TA) and relative humidity (RH) and optionnally cloud transmissivity (TAU_CLD),
* This computes the potential incoming solar radiation, based on the position of the sun in the sky
* (as a function of the location and the date). Please note that although this is the radiation as perceived
* at ground level (on the horizontal). If a cloud transmissivity (TAU_CLD) has been provided, or if an
* this computes the potential incoming solar radiation, based on the position of the sun in the sky
* (as a function of the location and the date) on the horizontal at ground level.
* If a cloud transmissivity (TAU_CLD) has been provided, or if an
* incoming long wave measurement is available, it corrects the generated iswr for cloudiness
* (basically doing like UnsworthGenerator in reverse), otherwise this assumes clear sky!
* If no TA or RH is available, average values will be used (in order to get an average value
......
......@@ -5,6 +5,7 @@ SET(dataGenerators_sources
dataGenerators/AllSkyLWGenerator.cc
dataGenerators/AllSkySWGenerator.cc
dataGenerators/ClearSkyLWGenerator.cc
dataGenerators/ClearSkySWGenerator.cc
dataGenerators/ConstGenerator.cc
dataGenerators/ESOLIPGenerator.cc
dataGenerators/IswrAlbedoGenerator.cc
......
/***********************************************************************************/
/* Copyright 2013 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
/***********************************************************************************/
/* This file is part of MeteoIO.
MeteoIO is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MeteoIO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
*/
#include <meteoio/dataGenerators/ClearSkySWGenerator.h>
#include <meteoio/meteoLaws/Atmosphere.h>
namespace mio {
void ClearSkySWGenerator::parse_args(const std::vector<std::string>& vecArgs)
{
//Get the optional arguments for the algorithm: constant value to use
if (!vecArgs.empty()) { //incorrect arguments, throw an exception
throw InvalidArgumentException("Wrong number of arguments supplied for the "+algo+" generator", AT);
}
}
bool ClearSkySWGenerator::generate(const size_t& param, MeteoData& md)
{
double &value = md(param);
if (value == IOUtils::nodata) {
const double ISWR=md(MeteoData::ISWR), RSWR=md(MeteoData::RSWR), HS=md(MeteoData::HS);
double TA=md(MeteoData::TA), RH=md(MeteoData::RH);
const double lat = md.meta.position.getLat();
const double lon = md.meta.position.getLon();
const double alt = md.meta.position.getAltitude();
if (lat==IOUtils::nodata || lon==IOUtils::nodata || alt==IOUtils::nodata) return false;
double albedo = .5;
if (RSWR==IOUtils::nodata || ISWR==IOUtils::nodata) {
if (HS!=IOUtils::nodata) //no big deal if we can not adapt the albedo
albedo = (HS>=snow_thresh)? snow_albedo : soil_albedo;
} else if (ISWR>0. && RSWR>0.) { //this could happen if the user calls this generator for a copy parameter, etc
albedo = RSWR / ISWR;
if (albedo>=1.) albedo=0.99;
if (albedo<=0.) albedo=0.01;
}
if (TA==IOUtils::nodata || RH==IOUtils::nodata) {
//set TA & RH so the reduced precipitable water will get an average value
TA=274.98;
RH=0.666;
}
sun.setLatLon(lat, lon, alt);
sun.setDate(md.date.getJulian(true), 0.);
const double P=md(MeteoData::P);
if (P==IOUtils::nodata)
sun.calculateRadiation(TA, RH, albedo);
else
sun.calculateRadiation(TA, RH, P, albedo);
double toa, direct, diffuse;
sun.getHorizontalRadiation(toa, direct, diffuse);
if (param!=MeteoData::RSWR)
value = (direct+diffuse); //ISWR
else
value = (direct+diffuse)*albedo; //RSWR
}
return true; //all missing values could be filled
}
bool ClearSkySWGenerator::generate(const size_t& param, std::vector<MeteoData>& vecMeteo)
{
if (vecMeteo.empty()) return true;
const double lat = vecMeteo.front().meta.position.getLat();
const double lon = vecMeteo.front().meta.position.getLon();
const double alt = vecMeteo.front().meta.position.getAltitude();
if (lat==IOUtils::nodata || lon==IOUtils::nodata || alt==IOUtils::nodata) return false;
sun.setLatLon(lat, lon, alt);
bool all_filled = true;
for (size_t ii=0; ii<vecMeteo.size(); ii++) {
double &value = vecMeteo[ii](param);
if (value == IOUtils::nodata) {
const double ISWR=vecMeteo[ii](MeteoData::ISWR), RSWR=vecMeteo[ii](MeteoData::RSWR), HS=vecMeteo[ii](MeteoData::HS);
double TA=vecMeteo[ii](MeteoData::TA), RH=vecMeteo[ii](MeteoData::RH);
double albedo = .5;
if (RSWR==IOUtils::nodata || ISWR==IOUtils::nodata) {
if (HS!=IOUtils::nodata) //no big deal if we can not adapt the albedo
albedo = (HS>=snow_thresh)? snow_albedo : soil_albedo;
} else if (ISWR>0. && RSWR>0.) { //this could happen if the user calls this generator for a copy parameter, etc
albedo = RSWR / ISWR;
if (albedo>=1.) albedo=0.99;
if (albedo<=0.) albedo=0.01;
}
if (TA==IOUtils::nodata || RH==IOUtils::nodata) {
//set TA & RH so the reduced precipitable water will get an average value
TA=274.98;
RH=0.666;
}
sun.setDate(vecMeteo[ii].date.getJulian(true), 0.);
const double P=vecMeteo[ii](MeteoData::P);
if (P==IOUtils::nodata)
sun.calculateRadiation(TA, RH, albedo);
else
sun.calculateRadiation(TA, RH, P, albedo);
double toa, direct, diffuse;
sun.getHorizontalRadiation(toa, direct, diffuse);
if (param!=MeteoData::RSWR)
value = (direct+diffuse); //ISWR
else
value = (direct+diffuse)*albedo; //RSWR
}
}
return all_filled;
}
} //namespace
/***********************************************************************************/
/* Copyright 2013 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
/***********************************************************************************/
/* This file is part of MeteoIO.
MeteoIO is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MeteoIO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CLEARSKYSWGENERATOR_H
#define CLEARSKYSWGENERATOR_H
#include <meteoio/dataGenerators/GeneratorAlgorithms.h>
#include <meteoio/meteoLaws/Sun.h>
namespace mio {
/**
* @class ClearSkySWGenerator
* @brief ISWR clear sky parametrization
*
* Using air temperature (TA) and relative humidity (RH),
* this computes the potential incoming solar radiation, based on the position of the sun in the sky
* (as a function of the location and the date) on the horizontal at ground level.
*
* If no TA or RH is available, average values will be used (in order to get an average value
* for the precipitable water vapor).
* @note This relies on SunObject to perform the heavy duty computation.
* @code
* ISWR::generators = clearSky_SW
* @endcode
*/
class ClearSkySWGenerator : public GeneratorAlgorithm {
public:
ClearSkySWGenerator(const std::vector<std::string>& vecArgs, const std::string& i_algo)
: GeneratorAlgorithm(vecArgs, i_algo), sun() { parse_args(vecArgs); }
bool generate(const size_t& param, MeteoData& md);
bool generate(const size_t& param, std::vector<MeteoData>& vecMeteo);
private:
void parse_args(const std::vector<std::string>& vecArgs);
SunObject sun;
};
} //end namespace mio
#endif
......@@ -20,6 +20,7 @@
#include <meteoio/dataGenerators/AllSkyLWGenerator.h>
#include <meteoio/dataGenerators/AllSkySWGenerator.h>
#include <meteoio/dataGenerators/ClearSkyLWGenerator.h>
#include <meteoio/dataGenerators/ClearSkySWGenerator.h>
#include <meteoio/dataGenerators/ConstGenerator.h>
#include <meteoio/dataGenerators/ESOLIPGenerator.h>
#include <meteoio/dataGenerators/IswrAlbedoGenerator.h>
......@@ -80,6 +81,7 @@ namespace mio {
* - SIN: sinusoidal variation (see SinGenerator)
* - CLEARSKY_LW: use a clear sky model to generate ILWR from TA, RH (see ClearSkyLWGenerator)
* - ALLSKY_LW: use an all sky model to generate ILWR from TA, RH and cloudiness (see AllSkyLWGenerator)
* - CLEARSKY_SW: use a clear sky model to generate ISWR from TA, RH (see ClearSkySWGenerator)
* - ALLSKY_SW: generate the incoming short wave radiation from the potential radiation, corrected for cloudiness if possible (see AllSkySWGenerator)
* - TAU_CLD: generate the atmospheric transmissivity based on cloud cover fraction (see TauCLDGenerator)
* - ESOLIP: generate precipitation from snow height changes (see ESOLIPGenerator)
......@@ -138,6 +140,8 @@ GeneratorAlgorithm* GeneratorAlgorithmFactory::getAlgorithm(const Config& /*cfg*
return new AllSkyLWGenerator(vecArgs, i_algoname);
} else if (algoname == "ALLSKY_SW"){
return new AllSkySWGenerator(vecArgs, i_algoname);
} else if (algoname == "CLEARSKY_SW"){
return new ClearSkySWGenerator(vecArgs, i_algoname);
} else if (algoname == "ESOLIP"){
return new ESOLIPGenerator(vecArgs, i_algoname);
} else if (algoname == "PPHASE"){
......
......@@ -136,7 +136,7 @@ MACRO (SET_COMPILER_OPTIONS)
SET(EXTRA "${EXTRA} -DDEBUG_ARITHM")
ENDIF(DEBUG_ARITHM)
SET(WARNINGS_OFF "-Wno-long-long -Wno-date-time -Wno-float-equal -Wno-documentation -Wno-documentation-unknown-command -Wno-old-style-cast -Wno-padded -Wno-missing-noreturn -Wno-weak-vtables -Wno-switch-enum -Wno-covered-switch-default -Wno-global-constructors -Wno-exit-time-destructors -Wno-unknown-pragmas")
SET(WARNINGS_OFF "-Wno-long-long -Wno-float-equal -Wno-documentation -Wno-documentation-unknown-command -Wno-old-style-cast -Wno-padded -Wno-missing-noreturn -Wno-weak-vtables -Wno-switch-enum -Wno-covered-switch-default -Wno-global-constructors -Wno-exit-time-destructors -Wno-unknown-pragmas")
SET(WARNINGS "-Wall -Wswitch -Weverything ${WARNINGS_OFF}") #obviously, we should try to fix the warnings! Keeping in mind that some of these W are half buggy...
SET(DEEP_WARNINGS "-Wunused-value -Wshadow -Wpointer-arith -Wconversion -Winline -Wdisabled-optimization -Wctor-dtor-privacy") #-Rpass=.* for static analysis
SET(EXTRA_WARNINGS "-Wextra -pedantic -Weffc++ ${DEEP_WARNINGS}")
......
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