WSL/SLF GitLab Repository

Commit 8750dd19 authored by Thomas Egger's avatar Thomas Egger
Browse files

Added new plugin for WSMDF format. gzipped version of format currently not...

Added new plugin for WSMDF format. gzipped version of format currently not supported. binary version works, but since the julian date does not fit into a 4 byte (32bit) float, it is unusable. ASCII format works, although unit_multiplier and unit_offset are currently not supported. For location information the easting, northing version is not yet supported.

Added function IOUtils::stripComments(string&) it, deletes everything after # or ; from the string&
parent 3d62447c
......@@ -87,6 +87,7 @@ set(PGMIO ON CACHE BOOL "Compilation PGMIO ON or OFF")
set(BORMAIO OFF CACHE BOOL "Compilation BORMAIO ON or OFF")
set(GEOTOPIO OFF CACHE BOOL "Compilation GEOTOPIO ON or OFF")
set(SNIO ON CACHE BOOL "Compilation SNIO ON or OFF")
set(WSMDFIO ON CACHE BOOL "Compilation WSMDFIO ON or OFF")
set(GRASSIO ON CACHE BOOL "Compilation GRASSIO ON or OFF")
set(GSNIO OFF CACHE BOOL "Compilation GSNIO ON or OFF")
set(IMISIO OFF CACHE BOOL "Compilation IMISIO ON or OFF")
......
......@@ -108,10 +108,7 @@ void ConfigReader::parseFile(const std::string& filename)
void ConfigReader::parseLine(const unsigned int& linenr, std::string& line, std::string& section)
{
//First thing cut away any possible comments (may start with "#" or ";")
size_t found = line.find_first_of("#;");
if (found != string::npos){
line.erase(found); //rest of line disregarded
}
IOUtils::stripComments(line);
IOUtils::trim(line); //delete leading and trailing whitespace characters
if (line.length() == 0) //ignore empty lines
......
......@@ -49,9 +49,9 @@ namespace mio {
namespace IOUtils {
void toUpper(std::string& str);
template <class T> void getValueForKey(const std::map<std::string,std::string>& properties,
const std::string& key, T& t);
const std::string& key, T& t, const unsigned int& options=1);
template <class T> void getValueForKey(const std::map<std::string,std::string>& properties,
const std::string& key, std::vector<T>& vecT);
const std::string& key, std::vector<T>& vecT, const unsigned int& options=1);
}
#ifdef _POPC_
......
......@@ -89,7 +89,7 @@ class Date {
Date(const time_t&, const double& _timezone=undefined, const bool& _dst=false);
Date(const Date& _date_in);
void setTimeZone(const double& _timezone, const bool& _dst);
void setTimeZone(const double& _timezone, const bool& _dst=false);
void setDate(const double& julian_in, const double& _timezone=undefined, const bool& _dst=false);
void setDate(const int& year, const int& month, const int& day, const int& hour, const int& minute, const double& _timezone=undefined, const bool& _dst=false);
void setDate(const time_t& _time, const double& _timezone=undefined, const bool& _dst=false);
......
......@@ -636,6 +636,10 @@ void FilterAlgorithms::MedianAbsoluteDeviationFilter(const std::vector<MeteoData
(void)vecS; (void)vecWindowS;
for (unsigned int ii=0; ii<vecWindowM.size(); ii++){
double& value = vecWindowM[ii].param(paramindex);
if (value == IOUtils::nodata) //No need to run filter for nodata points
continue;
unsigned int pos = IOUtils::seek(vecWindowM[ii].date, vecM, false);
std::vector<double> vecWindow;
......@@ -656,7 +660,6 @@ void FilterAlgorithms::MedianAbsoluteDeviationFilter(const std::vector<MeteoData
double sigma = mad * K;
double& value = vecWindowM[ii].param(paramindex);
if( (value>(median + 3.*sigma)) || (value<(median - 3.*sigma)) ) {
value = IOUtils::nodata;
}
......
......@@ -46,6 +46,7 @@ namespace mio {
* - \subpage grass "GRASS" for reading Grass DEM files (no extra requirements)
* - \subpage arps "ARPSIO" for reading ARPS formatted DEM (no extra requirements)
* - \subpage pgmio "PGMIO" for reading PGM grid files (no extra requirements)
* - \subpage wsmdfio "WSMDFIO" for reading WSMDF grid files (no extra requirements)
*
*/
......@@ -63,16 +64,17 @@ void IOHandler::registerPlugins()
#else
const std::string popc_extra = "";
#endif
mapPlugins["A3D"] = IOPlugin("", "A3DIO", &fileio, NULL);
mapPlugins["BORMA"] = IOPlugin("libbormaio"+popc_extra+libsuffix, "BormaIO", NULL, NULL);
mapPlugins["IMIS"] = IOPlugin("libimisio"+popc_extra+libsuffix, "ImisIO", NULL, NULL);
mapPlugins["GEOTOP"] = IOPlugin("libgeotopio"+popc_extra+libsuffix, "GeotopIO", NULL, NULL);
mapPlugins["SNOWPACK"] = IOPlugin("libsnio"+popc_extra+libsuffix, "SNIO", NULL, NULL);
mapPlugins["GSN"] = IOPlugin("libgsnio"+popc_extra+libsuffix, "GSNIO", NULL, NULL);
mapPlugins["ARC"] = IOPlugin("libarcio"+popc_extra+libsuffix, "ARCIO", NULL, NULL);
mapPlugins["GRASS"] = IOPlugin("libgrassio"+popc_extra+libsuffix, "GrassIO", NULL, NULL);
mapPlugins["ARPS"] = IOPlugin("libarpsio"+popc_extra+libsuffix, "ARPSIO", NULL, NULL);
mapPlugins["PGM"] = IOPlugin("libpgmio"+popc_extra+libsuffix, "PGMIO", NULL, NULL);
mapPlugins["A3D"] = IOPlugin("", "A3DIO", &fileio, NULL);
mapPlugins["BORMA"] = IOPlugin("libbormaio"+popc_extra+libsuffix, "BormaIO", NULL, NULL);
mapPlugins["IMIS"] = IOPlugin("libimisio"+popc_extra+libsuffix, "ImisIO", NULL, NULL);
mapPlugins["GEOTOP"] = IOPlugin("libgeotopio"+popc_extra+libsuffix, "GeotopIO", NULL, NULL);
mapPlugins["SNOWPACK"] = IOPlugin("libsnio"+popc_extra+libsuffix, "SNIO", NULL, NULL);
mapPlugins["GSN"] = IOPlugin("libgsnio"+popc_extra+libsuffix, "GSNIO", NULL, NULL);
mapPlugins["ARC"] = IOPlugin("libarcio"+popc_extra+libsuffix, "ARCIO", NULL, NULL);
mapPlugins["GRASS"] = IOPlugin("libgrassio"+popc_extra+libsuffix, "GrassIO", NULL, NULL);
mapPlugins["ARPS"] = IOPlugin("libarpsio"+popc_extra+libsuffix, "ARPSIO", NULL, NULL);
mapPlugins["PGM"] = IOPlugin("libpgmio"+popc_extra+libsuffix, "PGMIO", NULL, NULL);
mapPlugins["WSMDF"] = IOPlugin("libwsmdfio"+popc_extra+libsuffix, "WSMDFIO", NULL, NULL);
}
#ifdef _POPC_
......
......@@ -53,6 +53,14 @@ double IOUtils::angle_to_bearing(const double& angle) {
return (fmod( 90.-angle*to_deg+360. , 360. ));
}
void IOUtils::stripComments(std::string& str)
{
size_t found = str.find_first_of("#;");
if (found != std::string::npos){
str.erase(found); //rest of line disregarded
}
}
void IOUtils::trim(std::string& str)
{
const std::string whitespaces (" \t\f\v\n\r");
......
......@@ -59,6 +59,8 @@ class Coords;
class ConfigReader;
namespace IOUtils {
const unsigned int nothrow = 0;
const unsigned int dothrow = 1;
const double nodata = -999.0; ///<This is the internal nodata value
//const double not_set = std::numeric_limits<double>::max()-2.;
const unsigned int unodata = (unsigned int)-1;
......@@ -115,6 +117,8 @@ namespace IOUtils {
*/
void trim(std::string &s);
void stripComments(std::string& str);
char getEoln(std::istream& fin);
void skipLines(std::istream& fin, const unsigned int& nbLines, const char& eoln='\n');
......@@ -189,14 +193,17 @@ namespace IOUtils {
* @param[out] t The value associated to the key, converted to the requested type
*/
template <class T> void getValueForKey(const std::map<std::string,std::string>& properties,
const std::string& key, T& t) {
const std::string& key, T& t, const unsigned int& options=IOUtils::dothrow){
if (key == "") {
throw InvalidArgumentException("Empty key", AT);
}
const std::string value = (const_cast<std::map<std::string,std::string>&>(properties))[key];
if (value == "") {
throw UnknownValueException("No value for key " + key, AT);
if (value == ""){
if (options == IOUtils::nothrow)
return;
else
throw UnknownValueException("No value for key " + key, AT);
}
if(!convertString<T>(t, value, std::dec)) {
......@@ -212,14 +219,17 @@ namespace IOUtils {
* @param[out] vecT The vector of values associated to the key, each value is converted to the requested type
*/
template <class T> void getValueForKey(const std::map<std::string,std::string>& properties,
const std::string& key, std::vector<T>& vecT) {
const std::string& key, std::vector<T>& vecT, const unsigned int& options=IOUtils::dothrow){
if (key == "") {
throw InvalidArgumentException("Empty key", AT);
}
const std::string value = (const_cast<std::map<std::string,std::string>&>(properties))[key];
if (value == "") {
throw UnknownValueException("No value for key " + key, AT);
if (value == ""){
if (options == IOUtils::nothrow)
return;
else
throw UnknownValueException("No value for key " + key, AT);
}
//split value string
......
......@@ -10,11 +10,11 @@ IF(DEST STREQUAL "par")
SET(ARCIONAME arcio_par)
SET(ARPSIONAME arpsio_par)
SET(PGMIONAME pgmio_par)
SET(WSMDFIONAME wsmdfio_par)
SET(GRASSIONAME grassio_par)
SET(GEOTOPIONAME geotopio_par)
SET(SNIONAME snio_par)
SET(GSNIONAME gsnio_par)
SET(GSNIONAME gsnio_par)
SET(IMISIONAME imisio_par)
SET(BORMAIONAME bormaio_par)
......@@ -27,6 +27,7 @@ ELSE(DEST)
SET(ARCIONAME arcio)
SET(ARPSIONAME arpsio)
SET(PGMIONAME pgmio)
SET(WSMDFIONAME wsmdfio)
SET(GEOTOPIONAME geotopio)
SET(SNIONAME snio)
SET(GSNIONAME gsnio)
......@@ -37,6 +38,16 @@ ENDIF(DEST STREQUAL "par")
LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/lib)
IF(WSMDFIO)
ADD_LIBRARY(${WSMDFIONAME} WSMDFIO.cc)
TARGET_LINK_LIBRARIES(${WSMDFIONAME} ${SHAREDNAME})
SET_TARGET_PROPERTIES(${WSMDFIONAME} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
SOVERSION ${VERSION_MAJOR})
SET(MYPLUGINS ${MYPLUGINS} ${WSMDFIONAME})
ENDIF(WSMDFIO)
IF(ARCIO)
ADD_LIBRARY(${ARCIONAME} ARCIO.cc)
TARGET_LINK_LIBRARIES(${ARCIONAME} ${SHAREDNAME})
......
This diff is collapsed.
/***********************************************************************************/
/* Copyright 2009 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 __WSMDFIO_H__
#define __WSMDFIO_H__
#include <meteoio/IOInterface.h>
#include <meteoio/ConfigReader.h>
#include <string>
namespace mio {
/**
* @class WSMDFIO
* @brief This (empty) class is to be used as a template for developing new plugins
*
* @author Mathias Bavay
* @date 2010-06-14
*/
class WSMDFIO : public IOInterface {
public:
WSMDFIO(void (*delObj)(void*), const std::string& filename);
WSMDFIO(const std::string& configfile);
WSMDFIO(const WSMDFIO&);
WSMDFIO(const ConfigReader& cfgreader);
~WSMDFIO() throw();
virtual void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="");
virtual void readDEM(DEMObject& dem_out);
virtual void readLanduse(Grid2DObject& landuse_out);
virtual void readStationData(const Date& date, std::vector<StationData>& vecStation);
virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
std::vector< std::vector<MeteoData> >& vecMeteo,
std::vector< std::vector<StationData> >& vecStation,
const unsigned int& stationindex=IOUtils::npos);
virtual void writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMeteo,
const std::vector< std::vector<StationData> >& vecStation,
const std::string& name="");
virtual void readAssimilationData(const Date&, Grid2DObject& da_out);
virtual void readSpecialPoints(std::vector<Coords>& pts);
virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& filename);
private:
static const std::string wsmdf_version;
static std::map<std::string, MeteoData::Parameters> mapParameterByName; ///<Associate name and meteo parameter
static const bool __init; ///<helper variable to enable the init of static collection data
static bool initStaticData();///<initialize the static map meteoparamname
static double& getParameter(const std::string& columnName, MeteoData& md);
static void checkColumnNames(const std::vector<std::string>& vecColumns, const bool& locationInHeader);
void cleanup() throw();
void parseInputOutputSection();
bool checkConsistency(const std::vector<StationData>& vecStation, StationData& sd);
void checkForUsedParameters(const std::vector<MeteoData>& vecMeteo, double& timezone,
std::vector<bool>& vecParamInUse);
void writeHeaderSection(const bool& writeLocationInHeader, const StationData& sd,
const double& timezone, const std::vector<bool>& vecParamInUse);
void writeDataAscii(const bool& writeLocationInHeader, const std::vector<MeteoData>& vecMeteo,
const std::vector<StationData>& vecStation, const std::vector<bool>& vecParamInUse);
void writeDataBinary(const bool& writeLocationInHeader, const std::vector<MeteoData>& vecMeteo,
const std::vector<StationData>& vecStation, const std::vector<bool>& vecParamInUse);
void readHeader(const char& eoln, const std::string& filename, bool& locationInHeader,
double& timezone, StationData& sd, std::vector<std::string>& vecDataSequence);
void readDataAscii(const char& eoln, const std::string& filename, const double& timezone,
const StationData& sd, const std::vector<std::string>& vecDataSequence,
const Date& dateStart, const Date& dateEnd,
std::vector<MeteoData>& vecMeteo, std::vector<StationData>& vecStation);
void readDataBinary(const char& eoln, const std::string& filename, const double& timezone,
const StationData& sd, const std::vector<std::string>& vecDataSequence,
const Date& dateStart, const Date& dateEnd,
std::vector<MeteoData>& vecMeteo, std::vector<StationData>& vecStation);
void checkSignature(const std::vector<std::string>& vecSignature, const std::string& filename, bool& isAscii);
std::vector<std::string> vecFiles; //read from the ConfigReader [Input] section
std::string outpath; //read from the ConfigReader [Output] section
bool outputIsAscii, outputIsGzipped;//read from the ConfigReader [Output] section
ConfigReader cfg;
std::ifstream fin; //Input file streams
std::ofstream fout; //Output file streams
std::string coordin, coordinparam, coordout, coordoutparam; //projection parameters
};
} //namespace
#endif
......@@ -37,7 +37,7 @@ class TEMPLATE : public IOInterface {
TEMPLATE(void (*delObj)(void*), const std::string& filename);
TEMPLATE(const std::string& configfile);
TEMPLATE(const ARPSIO&);
TEMPLATE(const TEMPLATE&);
TEMPLATE(const ConfigReader& cfgreader);
~TEMPLATE() throw();
......@@ -60,8 +60,6 @@ class TEMPLATE : public IOInterface {
virtual void readSpecialPoints(std::vector<Coords>& pts);
virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& filename);
void read3DGrid(Grid3DObject& grid_out, const std::string& _name);
private:
void cleanup() throw();
......
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