WSL/SLF GitLab Repository

Commit 15f0a153 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

A wrong commit on doc/examples/io.ini has been reverted. A new undercatch...

A wrong commit on doc/examples/io.ini has been reverted. A new undercatch filter has been implemented, following (Hamon, 1973). I would not recommend using it for the moment, though. 

The issue 222 was actually more complex than it seemed: the behavior of an uncaught exception is actually not specified by the standard, so there is nothing that could be doneon MeteoIO's side: instead, each application is invited to properly wrap its calls in try/catch blocks, or wrap its whole main in try/catch. The code examples and examples have been modified to show several such possibilities.
parent 81ab7153
......@@ -33,6 +33,9 @@ IF(MSVC)
SET(DEBUG "/Z7 /Od /D__DEBUG /MDd")
LIST(APPEND CFLAGS " /D_CRT_SECURE_NO_WARNINGS /EHsc") #Za: strict ansi EHsc: handle c++ exceptions
SET(_VERSION "/D_VERSION=\\\"${_versionString}\\\"")
IF(BUILD_SHARED_LIBS)
ADD_DEFINITIONS(/DMIO_DLL)
ENDIF(BUILD_SHARED_LIBS)
ELSE(MSVC)
#we consider that all other compilers support "-" options and silently ignore what they don't know
SET(WARNINGS "-Wall")
......@@ -57,6 +60,9 @@ ELSE(MSVC)
SET(ARCH_SAFE "")
SET(DEBUG "-g3 -O0 -D__DEBUG")
SET(_VERSION "-D_VERSION=\\\"${_versionString}\\\"")
IF(BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DMIO_DLL)
ENDIF(BUILD_SHARED_LIBS)
ENDIF(MSVC)
IF(UNIX)
......
......@@ -7,7 +7,8 @@ using namespace mio; //The MeteoIO namespace is called mio
//for example ./data_converter 2008-12-01T00:00:00 2008-12-31T23:00
//It will retrieve the data for this time interval and write it out as specified
//in the io.ini configuration
int main(int argc, char** argv) {
void real_main(int argc, char** argv) {
if(argc!=3) {
std::cout << "Invalid number of arguments! Please provide a date range!\n";
exit(0);
......@@ -47,5 +48,14 @@ int main(int argc, char** argv) {
io.writeMeteoData(vecMeteo);
std::cout << "Done!! in " << timer.getElapsed() << " s" << std::endl;
}
int main(int argc, char** argv) {
try {
real_main(argc, argv);
} catch(const std::exception &e) {
std::cerr << e.what();
exit(1);
}
return 0;
}
......@@ -50,14 +50,13 @@ DEMFILE = ./input/surface-grids/Switzerland_1000m.asc
#SMET meteorological file format
METEO = SMET
METEOPATH = ./input/meteo
STATION1 = *WFJ.smet
; STATION1 = FLU2.smet
; STATION2 = FIR2.smet
; STATION3 = FRA2.smet
; STATION4 = GLA2.smet
; STATION5 = ILI2.smet
; STATION6 = OTT2.smet
;STATION7 = TUJ3.smet
STATION1 = FLU2.smet
STATION2 = FIR2.smet
STATION3 = FRA2.smet
STATION4 = GLA2.smet
STATION5 = ILI2.smet
STATION6 = OTT2.smet
STATION7 = TUJ3.smet
#IMIS network database input -> IMIS plugin
; METEO = IMIS
......
......@@ -84,7 +84,6 @@ IOException::IOException(const std::string& message, const std::string& position
IOException::~IOException() throw(){
}
const char* IOException::what() const throw()
{
return msg.c_str();
......
......@@ -27,6 +27,8 @@
#include <execinfo.h> //needed for the backtracing of the stack
#endif
#include <meteoio/exports.h>
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define AT __FILE__ ":" TOSTRING(__LINE__)
......@@ -42,7 +44,7 @@ namespace mio {
#ifdef _POPC_
#include <paroc_exception.h>
class IOException : public POPException {
class MIO_API IOException : public POPException {
#else
class IOException : public std::exception {
#endif
......@@ -61,7 +63,7 @@ class IOException : public POPException {
*
* @author Thomas Egger
*/
class FileNotFoundException : public IOException {
class MIO_API FileNotFoundException : public IOException {
public:
FileNotFoundException(const std::string& filename="",
const std::string& position="") : IOException("FileNotFoundException: " + filename, position){}
......@@ -73,7 +75,7 @@ class FileNotFoundException : public IOException {
*
* @author Thomas Egger
*/
class FileAccessException : public IOException {
class MIO_API FileAccessException : public IOException {
public:
FileAccessException(const std::string& filename="",
const std::string& position="") : IOException("FileAccessException: " + filename, position){}
......@@ -85,7 +87,7 @@ class FileAccessException : public IOException {
*
* @author Thomas Egger
*/
class InvalidFileNameException : public IOException {
class MIO_API InvalidFileNameException : public IOException {
public:
InvalidFileNameException(const std::string& filename="",
const std::string& position="") : IOException("InvalidFileNameException: " + filename, position){}
......@@ -97,7 +99,7 @@ class InvalidFileNameException : public IOException {
*
* @author Thomas Egger
*/
class InvalidFormatException : public IOException {
class MIO_API InvalidFormatException : public IOException {
public:
InvalidFormatException(const std::string& message="",
const std::string& position="") : IOException("InvalidFormatException: " + message, position){}
......@@ -109,7 +111,7 @@ class InvalidFormatException : public IOException {
*
* @author Thomas Egger
*/
class IndexOutOfBoundsException : public IOException {
class MIO_API IndexOutOfBoundsException : public IOException {
public:
IndexOutOfBoundsException(const std::string& message="",
const std::string& position="") : IOException("IndexOutOfBoundsException: " + message, position){}
......@@ -121,7 +123,7 @@ class IndexOutOfBoundsException : public IOException {
*
* @author Thomas Egger
*/
class ConversionFailedException : public IOException {
class MIO_API ConversionFailedException : public IOException {
public:
ConversionFailedException(const std::string& message="",
const std::string& position="") : IOException("ConversionFailedException: " + message, position){}
......@@ -133,7 +135,7 @@ class ConversionFailedException : public IOException {
*
* @author Florian Hof
*/
class InvalidArgumentException : public IOException {
class MIO_API InvalidArgumentException : public IOException {
public:
InvalidArgumentException(const std::string& message="",
const std::string& position="") : IOException("InvalidArgumentException: " + message, position){}
......@@ -145,7 +147,7 @@ class InvalidArgumentException : public IOException {
*
* @author Florian Hof
*/
class UnknownValueException : public IOException {
class MIO_API UnknownValueException : public IOException {
public:
UnknownValueException(const std::string& message="",
const std::string& position="") : IOException("UnknownValueException: " + message, position){}
......@@ -157,7 +159,7 @@ class UnknownValueException : public IOException {
*
* @author Florian Hof
*/
class NoAvailableDataException : public IOException
class MIO_API NoAvailableDataException : public IOException
{
public:
NoAvailableDataException(const std::string& message="",
......
......@@ -383,7 +383,7 @@ namespace mio {
* const double dist_x=700, dist_y=1200;
* mio::DEMObject dem;
* mio::IOManager *io = NULL;
* mio::Config *cfg = NULL;
* mio::Config *cfg = NULL;
* int i,j;
*
* try {
......@@ -392,16 +392,21 @@ namespace mio {
* } catch (const IOException& e){
* std::cout << "Problem with IOHandler creation, cause: " << e.what() << std::endl;
* }
* io->readDEM(dem);
* mio::Coords point(*cfg);
* point.setLatLon(46.1592, 8.12993);
* dem.WGS84_to_grid(point, i,j);
*
* const int ncols = (int)ceil(dist_x/dem.cellsize);
* const int nrows = (int)ceil(dist_y/dem.cellsize);
* try {
* io->readDEM(dem);
* mio::Coords point(*cfg);
* point.setLatLon(46.1592, 8.12993);
* dem.WGS84_to_grid(point, i,j);
*
* const int ncols = (int)ceil(dist_x/dem.cellsize);
* const int nrows = (int)ceil(dist_y/dem.cellsize);
*
* mio::DEMObject sub_dem(dem, i, j, ncols, nrows);
* io->write2DGrid(sub_dem,"sub_dem.dem");
* mio::DEMObject sub_dem(dem, i, j, ncols, nrows);
* io->write2DGrid(sub_dem,"sub_dem.dem");
* } catch (const IOException& e){
* std::cout << "Problem processing DEM: " << e.what() << std::endl;
* }
*
* return 0;
* }
......@@ -411,7 +416,7 @@ namespace mio {
* \code
* #include "MeteoIO.h"
*
* int main(void) {
* void real_main(void) {
* mio::Date d1;
*
* //initializing the io handlers according to the config file
......@@ -430,6 +435,14 @@ namespace mio {
* mio::Grid2DObject ta_grid;
* io.interpolate(d1, dem, MeteoData::TA, ta_grid);
* io.write2DGrid(param,"ta.asc");
* }
*
* int main(void) {
* try {
* real_main();
* } catch (const IOException& e){
* std::cout << e.what() << std::endl;
* }
*
* return 0;
* }
......
......@@ -14,6 +14,7 @@ SET(meteofilters_sources
meteofilters/FilterUnheatedHNW.cc
meteofilters/ProcUnventilatedT.cc
meteofilters/ProcUndercatch_WMO.cc
meteofilters/ProcUndercatch_Hamon.cc
meteofilters/ProcAdd.cc
meteofilters/ProcMult.cc
meteofilters/ProcExpSmoothing.cc
......
/***********************************************************************************/
/* Copyright 2012 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/meteofilters/ProcUndercatch_Hamon.h>
#include <meteoio/meteolaws/Atmosphere.h>
#include <cmath>
using namespace std;
namespace mio {
ProcUndercatch_Hamon::ProcUndercatch_Hamon(const std::vector<std::string>& vec_args) : ProcessingBlock("UNDERCATCH_HAMON") {
parse_args(vec_args);
properties.stage = ProcessingProperties::first; //for the rest: default values
}
void ProcUndercatch_Hamon::process(const unsigned int& param, const std::vector<MeteoData>& ivec,
std::vector<MeteoData>& ovec)
{
if(param!=MeteoData::HNW)
throw InvalidArgumentException("Trying to use UNDERCATCH_HAMON filter on " + MeteoData::getParameterName(param) + " but it can only be applied to precipitation!!" + getName(), AT);
ovec.clear();
ovec.reserve(ivec.size());
for (size_t ii=0; ii<ivec.size(); ii++){
ovec.push_back(ivec[ii]);
double& tmp = ovec[ii](param);
double VW = ovec[ii](MeteoData::VW);
if(VW!=IOUtils::nodata) VW = Atmosphere::windLogProfile(VW, 10., 2.); //impact seems minimal
double t = ovec[ii](MeteoData::TA);
if(t==IOUtils::nodata) continue; //we MUST have air temperature in order to filter
t=K_TO_C(t); //t in celsius
double k=0.;
if (tmp == IOUtils::nodata || tmp==0.) {
continue; //preserve nodata values and no precip or purely liquid precip
} else if(type==unsh) {
if(t>1.67) k=0.0146;
else if(t>0.) k=0.0294;
else if(t>-5.) k=0.0527;
else k=0.0889;
} else if(type==sh) {
if(t>1.67) k=0.0060;
else if(t>0.) k=0.0121;
else if(t>-5.) k=0.0217;
else k=0.0366;
} else if(type==hellmannsh) {
if(t>1.2) k=0.;
else if(t>0.) k=0.0294;
else if(t>-5.) k=0.0527;
else k=0.0889;
}
tmp *= (exp(k*VW));
}
}
void ProcUndercatch_Hamon::parse_args(std::vector<std::string> filter_args)
{
if (filter_args.size() < 1)
throw InvalidArgumentException("Wrong number of arguments for filter " + getName(), AT);
for(size_t ii=0; ii<filter_args.size(); ii++) {
IOUtils::toLower(filter_args[ii]);
}
if(filter_args[0]=="sh") {
type=sh;
} else if(filter_args[0]=="unsh") {
type=unsh;
} else if(filter_args[0]=="hellmannsh") {
type=hellmannsh;
} else {
throw InvalidArgumentException("Rain gauge type \""+ filter_args[0] +"\" unknown for filter "+getName(), AT);
}
}
} //end namespace
/***********************************************************************************/
/* Copyright 2012 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 __PROCUNDERCATCH_HAMON_H__
#define __PROCUNDERCATCH_HAMON_H__
#include <meteoio/meteofilters/FilterBlock.h>
#include <vector>
#include <string>
namespace mio {
/**
* @class ProcUndercatch_Hamon
* @ingroup processing
* @author Mathias Bavay
* @date 2012-02-06
* @brief Correct precipitation for undercatch in winter conditions.
* @details
* This implements the method for precipitation correction as described in
* <i>"Computing actual precipitation"</i>, W. R. Hamon, in <i>Distribution of precipitation in mountaineous areas, Geilo symposium 1</i>, pp 159-174, World Meteorological Organization, Geneva, 1972. This correction depends on the usage of a shield around the gauge,
* therefore the type of rain gauge must be specified as an argument:
* - sh - original rain gauge as used in the reference, shielded
* - unsh - original rain gauge as used in the reference, unshielded
* - Hellmansh - shielded and fitted on Weissflujoch (Switzerland) data
*
* @code
* HNW::filter1 = undercatch_hamon
* HNW::arg1 = sh
* @endcode
*/
class ProcUndercatch_Hamon : public ProcessingBlock {
public:
ProcUndercatch_Hamon(const std::vector<std::string>& vec_args);
virtual void process(const unsigned int& param, const std::vector<MeteoData>& ivec,
std::vector<MeteoData>& ovec);
private:
typedef enum SENSOR_TYPE {
sh,
unsh,
hellmannsh
} sensor_type;
void parse_args(std::vector<std::string> filter_args);
sensor_type type;
//std::vector<double> vec_vw, vec_ta;
};
} //end namespace
#endif
......@@ -28,6 +28,7 @@
#include <meteoio/meteofilters/FilterTukey.h>
#include <meteoio/meteofilters/FilterMAD.h>
#include <meteoio/meteofilters/ProcUndercatch_WMO.h>
#include <meteoio/meteofilters/ProcUndercatch_Hamon.h>
#include <meteoio/meteofilters/ProcUnventilatedT.h>
#include <meteoio/meteofilters/ProcAdd.h>
#include <meteoio/meteofilters/ProcMult.h>
......@@ -89,6 +90,7 @@ namespace mio {
* - ADD: adds a given offset to the data, see ProcAdd
* - MULT: multiply the data by a given factor, see ProcMult
* - UNDERCATCH_WMO: WMO rain gauge correction for undercatch, using various correction models, see ProcUndercatch_WMO
* - UNDERCATCH_HAMON: Hamon1973 rain gauge correction for undercatch, see ProcUndercatch_Hamon
* - UNVENTILATED_T: unventilated temperature sensor correction, see ProcUnventilatedT
*
*/
......@@ -110,6 +112,7 @@ bool BlockFactory::initStaticData()
availableBlocks.insert("MAD");
availableBlocks.insert("UNHEATED_RAINGAUGE");
availableBlocks.insert("UNDERCATCH_WMO");
availableBlocks.insert("UNDERCATCH_HAMON");
availableBlocks.insert("UNVENTILATED_T");
availableBlocks.insert("ADD");
availableBlocks.insert("MULT");
......@@ -148,6 +151,8 @@ ProcessingBlock* BlockFactory::getBlock(const std::string& blockname, const std:
return new FilterUnheatedHNW(vec_args);
} else if (blockname == "UNDERCATCH_WMO"){
return new ProcUndercatch_WMO(vec_args);
} else if (blockname == "UNDERCATCH_HAMON"){
return new ProcUndercatch_Hamon(vec_args);
} else if (blockname == "UNVENTILATED_T"){
return new ProcUnventilatedT(vec_args);
} else if (blockname == "MULT"){
......
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