WSL/SLF GitLab Repository

Commit 0611228b authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Some uncommitted fixes to the documentation are now committed. Hopefully all...

Some uncommitted fixes to the documentation are now committed. Hopefully all the namespace issues (ie: broken links) are now fixed!
parent 9220cd6b
......@@ -17,17 +17,21 @@
*/
#include "A3DIO.h"
using namespace std;
using namespace mio;
namespace mio {
/**
* @page a3d A3D
* @section a3d_format Format
* This plugin reads legacy Alpine3D meteorological input files. It reads the meteo1d.txt file that contains, as measured at one unique location, the following fields:
* This plugin reads legacy Alpine3D meteorological input files. It reads the meteo1d.txt file that contains, as measured at one unique location, the following fields:
* - air temperature in field ta
* - incoming short wave radiation in field iswr
* - wind velocity in field vw
* - relative humidity in field rh
* - incoming long wave radiation in field ea
* - precipitations in field nswc
*
*
* and optionally a list of stations with their measurements (meteo2d files) for the following parameters (with YYYY being the 4-digits year):
* - precipitations (file named precYYYY.txt)
* - relative humidity (file named rhumYYYY.txt)
......@@ -46,15 +50,13 @@
* @section a3d_keywords Keywords
* This plugin uses the following keywords:
* - METEOPATH: string containing the path to the meteorological files (ie: where to find meteo1d.txt and meteo2d files)
* - COORDSYS: input coordinate system (see Coordinate) specified in the [Input] section
* - COORDPARAM: extra input coordinates parameters (see Coordinate) specified in the [Input] section
* - COORDSYS: output coordinate system (see Coordinate) specified in the [Output] section
* - COORDPARAM: extra output coordinates parameters (see Coordinate) specified in the [Output] section
* - COORDSYS: input coordinate system (see Coords) specified in the [Input] section
* - COORDPARAM: extra input coordinates parameters (see Coords) specified in the [Input] section
* - COORDSYS: output coordinate system (see Coords) specified in the [Output] section
* - COORDPARAM: extra output coordinates parameters (see Coords) specified in the [Output] section
* - SPECIALPTSFILE: a path+file name to the a file containing grid coordinates of special points of interest (for special outputs)
*/
using namespace std;
using namespace mio;
}
const double A3DIO::plugin_nodata = -9999.0; //plugin specific nodata value
......@@ -123,7 +125,7 @@ void A3DIO::readAssimilationData(const Date& date_in, Grid2DObject& da_out)
throw IOException("Nothing implemented here", AT);
}
void A3DIO::writeMeteoData(const std::vector< std::vector<MeteoData> >&,
void A3DIO::writeMeteoData(const std::vector< std::vector<MeteoData> >&,
const std::vector< std::vector<StationData> >&,
const std::string&)
{
......@@ -143,8 +145,8 @@ void A3DIO::readMeteoData(const Date& dateStart, const Date& dateEnd, std::vecto
readMeteoData(dateStart, dateEnd, vecMeteo, vecStation);
}
void A3DIO::readMeteoData(const Date& dateStart, const Date& dateEnd,
std::vector< std::vector<MeteoData> >& vecMeteo,
void A3DIO::readMeteoData(const Date& dateStart, const Date& dateEnd,
std::vector< std::vector<MeteoData> >& vecMeteo,
std::vector< std::vector<StationData> >& vecStation,
const unsigned int& stationindex)
{
......@@ -164,7 +166,7 @@ void A3DIO::readMeteoData(const Date& dateStart, const Date& dateEnd,
try {
read2DMeteo(vecMeteo, vecStation);
} catch(std::exception& e){
std::cerr << "[E] No meteo2d data found or error while reading it, using only Meteo1D data: "
std::cerr << "[E] No meteo2d data found or error while reading it, using only Meteo1D data: "
<< std::endl << "\t" << e.what() << std::endl;
}
}
......@@ -185,11 +187,11 @@ void A3DIO::convertUnits(MeteoData& meteo)
}
}
void A3DIO::read1DMeteo(const Date& dateStart, const Date& dateEnd,
std::vector< std::vector<MeteoData> >& vecMeteo,
void A3DIO::read1DMeteo(const Date& dateStart, const Date& dateEnd,
std::vector< std::vector<MeteoData> >& vecMeteo,
std::vector< std::vector<StationData> >& vecStation)
{
double latitude=IOUtils::nodata, longitude=IOUtils::nodata,
double latitude=IOUtils::nodata, longitude=IOUtils::nodata,
xcoord=IOUtils::nodata, ycoord=IOUtils::nodata, altitude=IOUtils::nodata;
std::string tmp="", line="";
Date tmp_date;
......@@ -213,7 +215,7 @@ void A3DIO::read1DMeteo(const Date& dateStart, const Date& dateEnd,
}
char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
//Go through file, save key value pairs
try {
//Read in station meta data
......@@ -246,7 +248,7 @@ void A3DIO::read1DMeteo(const Date& dateStart, const Date& dateEnd,
//Read one line, construct Date object and see whether date is greater or equal than the date_in object
IOUtils::skipLines(fin, 1, eoln); //skip rest of line
//Loop going through the data sequentially until dateStart is found
do {
getline(fin, line, eoln); //read complete line
......@@ -297,7 +299,7 @@ bool A3DIO::readMeteoDataLine(std::string& line, MeteoData& tmpdata, std::string
return true;
//throw InvalidFormatException("Premature End of Line or no data for date " + date_in + " found in File " + filename, AT);
}
for (int ii=0; ii<4; ii++) {
if (!IOUtils::convertString(tmp_ymdh[ii], tmpvec.at(ii), std::dec))
throw InvalidFormatException(filename + ": " + line, AT);
......@@ -306,13 +308,13 @@ bool A3DIO::readMeteoDataLine(std::string& line, MeteoData& tmpdata, std::string
tmp_date.setDate(tmp_ymdh[0],tmp_ymdh[1],tmp_ymdh[2],tmp_ymdh[3], 0);
//Read rest of line with values ta, iswr, vw, rh, ea, hnw
for (int ii=0; ii<6; ii++) { //go through the columns
if (!IOUtils::convertString(tmp_values[ii], tmpvec.at(ii+4), std::dec)) {
throw InvalidFormatException(filename + ": " + line, AT);
}
}
tmpdata.setDate(tmp_date);
tmpdata.setData(MeteoData::TA, tmp_values[0]);
tmpdata.setData(MeteoData::ISWR, tmp_values[1]);
......@@ -320,24 +322,24 @@ bool A3DIO::readMeteoDataLine(std::string& line, MeteoData& tmpdata, std::string
tmpdata.setData(MeteoData::RH, tmp_values[3]);
tmpdata.setData(MeteoData::ILWR, tmp_values[4]);
tmpdata.setData(MeteoData::HNW, tmp_values[5]);
return false;
}
/*
Preamble: Files are in METEOFILE directory. 4 types of files:
Preamble: Files are in METEOFILE directory. 4 types of files:
prec????.txt == hnw
rh????.txt == rh
ta????.txt == ta
wspd????.txt == vw
Remarks: The headers of the files may defer - for each unique
Remarks: The headers of the files may defer - for each unique
StationData one MeteoData and one StationData object will be created
*/
void A3DIO::read2DMeteo(std::vector< std::vector<MeteoData> >& vecMeteo, std::vector< std::vector<StationData> >& vecStation)
{
unsigned int stations=0, bufferindex=0;
std::map<std::string, unsigned int> hashStations = std::map<std::string, unsigned int>();
std::vector<std::string> filenames = std::vector<std::string>();
......@@ -345,9 +347,9 @@ bool A3DIO::readMeteoDataLine(std::string& line, MeteoData& tmpdata, std::string
//Requirement: meteo1D data must exist:
if ((vecMeteo.size() == 0) || (vecMeteo[0].size() == 0))
return;
//1D and 2D data must correspond, that means that if there is 1D data
//for a certain date (e.g. 1.1.2006) then 2D data must exist (prec2006.txt etc),
//for a certain date (e.g. 1.1.2006) then 2D data must exist (prec2006.txt etc),
//otherwise throw FileNotFoundException
Date startDate(vecMeteo[0][0].date);
Date endDate(vecMeteo[0][vecMeteo[0].size()-1].date);
......@@ -359,8 +361,8 @@ bool A3DIO::readMeteoDataLine(std::string& line, MeteoData& tmpdata, std::string
std::cerr << "[I] Number of 2D meteo stations: " << stations << std::endl;
if (stations < 1) {
throw InvalidFormatException("No StationData found in 2D Meteo Files", AT);
}
throw InvalidFormatException("No StationData found in 2D Meteo Files", AT);
}
std::vector<StationData> tmpvecS = std::vector<StationData>(stations); //stores unique stations
......@@ -389,7 +391,7 @@ bool A3DIO::readMeteoDataLine(std::string& line, MeteoData& tmpdata, std::string
read2DMeteoData(filenames[2], "ta", hashStations, vecMeteo, bufferindex);
bufferindex = currentindex;
read2DMeteoData(filenames[3], "vw", hashStations, vecMeteo, bufferindex);
if(filenames.size() == 5) { //for keeping dw optional
bufferindex = currentindex;
read2DMeteoData(filenames.at(4), "dw", hashStations, vecMeteo, bufferindex);
......@@ -405,14 +407,14 @@ bool A3DIO::readMeteoDataLine(std::string& line, MeteoData& tmpdata, std::string
//clear all 2D meteo data if error occurs
if (vecMeteo.size() > 1)
vecMeteo.erase(vecMeteo.begin()+1, vecMeteo.end());
if (vecStation.size() > 1)
vecStation.erase(vecStation.begin()+1, vecStation.end());
cleanup();
throw;
}
//clean data and convert the units
for (unsigned int ii=1; ii<vecMeteo.size(); ii++) { //loop over all stations except 1D Meteo
for (unsigned int jj=0; jj<vecMeteo[ii].size(); jj++){ //Meteo1D data already cleaned
......@@ -428,7 +430,7 @@ void A3DIO::constructMeteo2DFilenames(const Date& startDate, const Date& endDate
std::string tmp;
filenames.clear();
startDate.getDate(startyear, dummy, dummy, dummy, dummy);
endDate.getDate(endyear, dummy, dummy, dummy, dummy);
cfg.getValue("METEOPATH", "Input", tmp);
......@@ -447,7 +449,7 @@ void A3DIO::constructMeteo2DFilenames(const Date& startDate, const Date& endDate
filenames.push_back(rhFilename);
filenames.push_back(taFilename);
filenames.push_back(wspdFilename);
if (IOUtils::fileExists(wdirFilename)) //keeping wdir optional
filenames.push_back(wdirFilename);
}
......@@ -464,7 +466,7 @@ unsigned int A3DIO::getNrOfStations(std::vector<std::string>& filenames, std::ma
{
std::vector<std::string> tmpvec;
std::string line_in="";
for (unsigned int ii=0; ii<filenames.size(); ii++) {
//cout << *it << endl;
std::string filename = filenames[ii];
......@@ -472,10 +474,10 @@ unsigned int A3DIO::getNrOfStations(std::vector<std::string>& filenames, std::ma
fin.clear();
fin.open (filename.c_str(), std::ifstream::in);
if (fin.fail()) throw FileAccessException(filename, AT);
char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
IOUtils::skipLines(fin, 4, eoln);
IOUtils::skipLines(fin, 4, eoln);
getline(fin, line_in, eoln); //5th line holds the names of the stations
unsigned int cols = IOUtils::readLineToVec(line_in, tmpvec);
if ( cols > 4) { // if there are any stations
......@@ -489,16 +491,16 @@ unsigned int A3DIO::getNrOfStations(std::vector<std::string>& filenames, std::ma
}
}
cleanup();
}
}
return (hashStations.size());
}
void A3DIO::read2DMeteoData(const std::string& filename, const std::string& parameter,
std::map<std::string,unsigned int>& hashStations,
void A3DIO::read2DMeteoData(const std::string& filename, const std::string& parameter,
std::map<std::string,unsigned int>& hashStations,
std::vector< std::vector<MeteoData> >& vecM, unsigned int& bufferindex)
{
std::string line_in = "";
unsigned int columns;
std::vector<std::string> tmpvec, vec_names;
......@@ -512,7 +514,7 @@ void A3DIO::read2DMeteoData(const std::string& filename, const std::string& para
}
char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
IOUtils::skipLines(fin, 4, eoln); //skip first 4 lines
getline(fin, line_in, eoln); //line containing UNIQUE station names
columns = IOUtils::readLineToVec(line_in, vec_names);
......@@ -523,7 +525,7 @@ void A3DIO::read2DMeteoData(const std::string& filename, const std::string& para
MeteoData& lastMeteoData = vecM[0][vecM[0].size()-1]; //last time stamp in buffer of 1D meteo
do {
getline(fin, line_in, eoln);
getline(fin, line_in, eoln);
std::string tmpline = line_in;
IOUtils::trim(tmpline);
......@@ -532,11 +534,11 @@ void A3DIO::read2DMeteoData(const std::string& filename, const std::string& para
}
if (IOUtils::readLineToVec(line_in, tmpvec)!=columns) { //Every station has to have its own column
throw InvalidFormatException("Premature End of Line or no data for date "
+ vecM[0][bufferindex].date.toString(Date::FULL) + " found in File "
throw InvalidFormatException("Premature End of Line or no data for date "
+ vecM[0][bufferindex].date.toString(Date::FULL) + " found in File "
+ filename, AT);
}
for (int ii=0; ii<4; ii++) {
if (!IOUtils::convertString(tmp_ymdh[ii], tmpvec[ii], std::dec)) {
throw InvalidFormatException("Check date columns in " + filename, AT);
......@@ -548,7 +550,7 @@ void A3DIO::read2DMeteoData(const std::string& filename, const std::string& para
if (tmp_date == currentMeteoData.date) {
//Read in data
for (unsigned int ii=4; ii<columns; ii++) {
unsigned int stationnr = hashStations[vec_names.at(ii)];
unsigned int stationnr = hashStations[vec_names.at(ii)];
MeteoData& tmpmd = vecM[stationnr][bufferindex];
tmpmd.date = tmp_date;
......@@ -556,31 +558,31 @@ void A3DIO::read2DMeteoData(const std::string& filename, const std::string& para
if (!IOUtils::convertString(tmpmd.hnw, tmpvec[ii], std::dec)) {
throw ConversionFailedException("For hnw value in " + filename + " for date " + tmpmd.date.toString(Date::FULL), AT);
}
} else if (parameter == "rh") {
if (!IOUtils::convertString(tmpmd.rh, tmpvec[ii], std::dec)) {
throw ConversionFailedException("For rh value in " + filename + " for date " + tmpmd.date.toString(Date::FULL), AT);
}
} else if (parameter == "ta") {
if (!IOUtils::convertString(tmpmd.ta, tmpvec[ii], std::dec))
if (!IOUtils::convertString(tmpmd.ta, tmpvec[ii], std::dec))
throw ConversionFailedException("For ta value in " + filename + " for date " + tmpmd.date.toString(Date::FULL), AT);
} else if (parameter == "vw") {
if (!IOUtils::convertString(tmpmd.vw, tmpvec[ii], std::dec)) {
if (!IOUtils::convertString(tmpmd.vw, tmpvec[ii], std::dec)) {
throw ConversionFailedException("For vw value in " + filename + " for date " + tmpmd.date.toString(Date::FULL), AT);
}
} else if (parameter == "dw") {
if (!IOUtils::convertString(tmpmd.dw, tmpvec[ii], std::dec)) {
if (!IOUtils::convertString(tmpmd.dw, tmpvec[ii], std::dec)) {
throw ConversionFailedException("For dw value in " + filename + " for date " + tmpmd.date.toString(Date::FULL), AT);
}
}
}
bufferindex++;
}
} while((tmp_date<lastMeteoData.date) && (!fin.eof()));
cleanup();
}
......@@ -596,7 +598,7 @@ void A3DIO::read2DMeteoHeader(const std::string& filename, std::map<std::string,
if (fin.fail()) {
throw FileAccessException(filename, AT);
}
char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
IOUtils::skipLines(fin, 1, eoln);
......@@ -645,7 +647,7 @@ void A3DIO::read2DMeteoHeader(const std::string& filename, std::map<std::string,
|| (!IOUtils::convertString(easting, vec_xcoord.at(ii), std::dec))
|| (!IOUtils::convertString(northing, vec_ycoord.at(ii), std::dec))
|| (!IOUtils::convertString(stationName, vec_names.at(ii), std::dec))) {
throw ConversionFailedException("Conversion of station description failed in " + filename, AT);
throw ConversionFailedException("Conversion of station description failed in " + filename, AT);
}
coordinate.setXY(easting, northing, altitude);
vecS[stationnr-1].stationName = stationName;
......@@ -673,7 +675,7 @@ void A3DIO::readSpecialPoints(std::vector<Coords>& pts)
char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
while (!fin.eof()) {
getline(fin, line_in, eoln);
getline(fin, line_in, eoln);
if (IOUtils::readLineToVec(line_in, tmpvec)==2) { //Try to convert
int x, y;
......@@ -702,7 +704,7 @@ void A3DIO::readSpecialPoints(std::vector<Coords>& pts)
void A3DIO::write2DGrid(const Grid2DObject&, const std::string&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
throw IOException("Nothing implemented here", AT);
}
......
......@@ -31,14 +31,14 @@ namespace mio {
/**
* @class ConfigReader
* @brief A class that reads a key/value file. These files (typically named *.ini) have the following structure:
* @brief A class that reads a key/value file. These files (typically named *.ini) follow the INI file format standard (see http://en.wikipedia.org/wiki/INI_file) and have the following structure:
* - they consist of 0 or more explicitly indicated sections, which start with a sectionname enclosed in square brackets
* e.g. [General] or [Filter]
* - within each section there are 0 or more key value pairs defined: KEY = VALUE
* - within each section there are 0 or more key value pairs defined: KEY = VALUE
* - in this implementation each key is unique within its section
* - lines that start with a semicolon ';' or a hash sign '#' are ignored (regarded as comments)
* - empty lines are ignored
* - if there is no section name given in a file, the default section called "GENERAL" is assumed
* - if there is no section name given in a file, the default section called "GENERAL" is assumed
* - a VALUE for a KEY can consist of multiple whitespace separated values (e.g. MYNUMBERS = 17.77 -18.55 8888 99.99)
*
* @author Thomas Egger
......@@ -49,7 +49,7 @@ 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);
template <class T> void getValueForKey(const std::map<std::string,std::string>& properties,
template <class T> void getValueForKey(const std::map<std::string,std::string>& properties,
const std::string& key, std::vector<T>& vecT);
}
......@@ -115,12 +115,12 @@ class ConfigReader {
* @param[out] vecT a variable of class vector<T> into which the values for the corresponding key are saved
* @param[in] options indicating whether an exception should be raised, when key is not present
*/
template <class T> void getValue(const std::string& key,
std::vector<T>& vecT,
template <class T> void getValue(const std::string& key,
std::vector<T>& vecT,
const unsigned int& options=0) const {
getValue(key, "GENERAL", vecT, options);
}
/**
* @brief Template function to retrieve a vector of values of class T for a certain key
* @code
......@@ -129,12 +129,12 @@ class ConfigReader {
* @endcode
* @param[in] key std::string representing a KEY in the key/value file
* @param[in] section std::string representing a section name; the key has to be part of this section
* @param[out] vecT a variable of class vector<T> into which the values for the corresponding key are saved
* @param[out] vecT a variable of class vector<T> into which the values for the corresponding key are saved
* @param[in] options indicating whether an exception should be raised, when key is not present
*/
template <class T> void getValue(const std::string& key,
const std::string& section,
std::vector<T>& vecT,
template <class T> void getValue(const std::string& key,
const std::string& section,
std::vector<T>& vecT,
const unsigned int& options=0) const {
try {
vecT.clear();
......@@ -166,8 +166,8 @@ class ConfigReader {
* @param[out] t a variable of class T into which the value for the corresponding key is saved (e.g. double, int, std::string)
* @param[in] options indicating whether an exception should be raised, when key is not present
*/
template <class T> void getValue(const std::string& key, const std::string& section,
T& t,
template <class T> void getValue(const std::string& key, const std::string& section,
T& t,
const unsigned int& options=0) const {
try {
std::string _section = section;
......@@ -180,7 +180,7 @@ class ConfigReader {
}
}
}
/**
* @brief Function that searches for a given string within the keys of section (default: GENERAL)
......@@ -194,7 +194,7 @@ class ConfigReader {
* unsigned int nrOfMatches = getKeys(myVec, "TA::", "Filters");
* @endcode
*/
unsigned int findKeys(std::vector<std::string>& vecResult,
unsigned int findKeys(std::vector<std::string>& vecResult,
const std::string keystart, const std::string section="GENERAL") const;
static const unsigned int nothrow;
......
......@@ -24,6 +24,7 @@
using namespace std;
using namespace mio;
namespace mio {
/**
* @page coords Available coordinate systems
* Geographic coordinates will be transparently and automatically converted to lat/lon and any other coordinate system that
......@@ -58,6 +59,7 @@ using namespace mio;
* @endcode
*
*/
}
const struct mio::Coords::ELLIPSOID mio::Coords::ellipsoids[] = {
{ 6378137., 6356752.3142 }, ///< E_WGS84
......@@ -356,12 +358,12 @@ void Coords::setGridIndex(const int _grid_i, const int _grid_j, const int _grid_
}
/**
* \anchor Coordinate_types
* @brief Set projection to use
* This projection will be used for converting between lat/lon and East/North
* @param[in] _coordinatesystem string identifying the coordinate system to use
* @param[in] _parameters string giving some additional parameters for the projection (optional)
*
* \anchor Coordinate_types
* The coordinate system can be any of the following:
* - CH1903 for coordinates in the Swiss Grid [ref: http://geomatics.ladetto.ch/ch1903_wgs84_de.pdf]
* - UTM for UTM coordinates (the zone must be specified in the parameters, for example 31T) [ref: http://www.oc.nps.edu/oc2902w/maps/utmups.pdf]
......
......@@ -17,32 +17,33 @@
*/
#include "FilterAlgorithms.h"
using namespace std;
using namespace mio;
namespace mio {
/**
* @page filters Filters overview
* The filtering infrastructure is described in FilterAlgorithms (for its API). The goal of this page is to give an overview of the available filters and their usage.
*
*
* @section filters_modes Modes of operation
* It should be noted that filters often have two modes of operations: soft or hard. In soft mode, all value that is rejected is replaced by the filter parameter's value. This means that for a soft min filter set at 0.0, all values less than 0.0 will be replaced by 0.0. In hard mode, all rejected values are replaced by nodata.
*
* @section filters_available Available filters
* The filters that are currently available are the following:
* - rate: rate of change filter, see mio::FilterAlgorithms::RateFilter
* - min_max: range check filter, see mio::FilterAlgorithms::MinMaxFilter
* - min: minimum check filter, see mio::FilterAlgorithms::MinValueFilter
* - max: maximum check filter, see mio::FilterAlgorithms::MaxValueFilter
* - mad: median absolute deviation, see mio::FilterAlgorithms::MedianAbsoluteDeviationFilter
*
* - rate: rate of change filter, see FilterAlgorithms::RateFilter
* - min_max: range check filter, see FilterAlgorithms::MinMaxFilter
* - min: minimum check filter, see FilterAlgorithms::MinValueFilter
* - max: maximum check filter, see FilterAlgorithms::MaxValueFilter
* - mad: median absolute deviation, see FilterAlgorithms::MedianAbsoluteDeviationFilter
*
* A few data transformations are also supported besides filtering:
* - accumulate: data accumulates over a given period, see mio::FilterAlgorithms::AccumulateProcess
* - resample: linear data resampling, mio::FilterAlgorithms::LinResamplingProcess
* - median_avg: running median average over a given window, see mio::FilterAlgorithms::MedianAvgProcess
* - mean_avg: running mean average over a given window, see mio::FilterAlgorithms::MeanAvgProcess
* - wind_avg: vector average over a given window, see mio::FilterAlgorithms::WindAvgProcess
* - accumulate: data accumulates over a given period, see FilterAlgorithms::AccumulateProcess
* - resample: linear data resampling, FilterAlgorithms::LinResamplingProcess
* - median_avg: running median average over a given window, see FilterAlgorithms::MedianAvgProcess
* - mean_avg: running mean average over a given window, see FilterAlgorithms::MeanAvgProcess
* - wind_avg: vector average over a given window, see FilterAlgorithms::WindAvgProcess
*/
using namespace std;
using namespace mio;
}
#define PI 3.141592653589
std::map<std::string, FilterProperties> FilterAlgorithms::filterMap;
......@@ -81,7 +82,7 @@ void FilterAlgorithms::parseFilterArguments(const std::string& filtername, const
{
isSoft = false;
unsigned int argindex = 0;
vecArgs_out.clear();
vecArgs_out.clear();
double tmp;
//Test for softness
......@@ -102,7 +103,7 @@ void FilterAlgorithms::parseFilterArguments(const std::string& filtername, const
}
}
void FilterAlgorithms::parseWindowFilterArguments(const std::string& filtername,
void FilterAlgorithms::parseWindowFilterArguments(const std::string& filtername,
const std::vector<std::string>& vecArgs_in,
const unsigned int& minArgs, const unsigned int& maxArgs,
bool& isSoft, std::string& windowposition, std::vector<double>& vecArgs_out)
......@@ -113,7 +114,7 @@ void FilterAlgorithms::parseWindowFilterArguments(const std::string& filtername,
for (unsigned int ii=0; ii<vecArgs_in.size(); ii++){
//Check for "left", "right" or "center" keywords
if ((vecArgs_in[ii] == "center") || (vecArgs_in[ii] == "left") || (vecArgs_in[ii] == "right")){
if (alreadyDefined)
if (alreadyDefined)
throw InvalidArgumentException("Invalid or redefined arguments for filter " + filtername, AT);
windowposition = vecArgs_in[ii];
alreadyDefined = true;
......@@ -125,7 +126,7 @@ void FilterAlgorithms::parseWindowFilterArguments(const std::string& filtername,
parseFilterArguments(filtername, vecArgs_new, minArgs, maxArgs, isSoft, vecArgs_out);
}
bool FilterAlgorithms::getWindowData(const std::string& filtername, const std::vector<MeteoData>& vecM,
bool FilterAlgorithms::getWindowData(const std::string& filtername, const std::vector<MeteoData>& vecM,
const unsigned int& pos,
const Date& date, const std::vector<std::string>& _vecArgs,
const unsigned int& paramindex, std::vector<double>& vecWindow,
......@@ -134,7 +135,7 @@ bool FilterAlgorithms::getWindowData(const std::string& filtername, const std::v
vecWindow.clear();
bool isSoft = false;
std::string windowposition = "center"; //the default is a centered window
std::vector<double> vecArgs;
std::vector<double> vecArgs;
parseWindowFilterArguments(filtername, _vecArgs, 2, 2, isSoft, windowposition, vecArgs);
if (vecArgs[0] < 1) //the window size has to be at least 1
......@@ -145,7 +146,7 @@ bool FilterAlgorithms::getWindowData(const std::string& filtername, const std::v
//Deal with first parameter: minimal number of data points
unsigned int windowSize = (unsigned int)vecArgs[0];
unsigned int increment = 0;
if (windowposition=="right"){
if (windowposition=="right"){
increment = (unsigned int)windowSize - 1; //window reaches to the right
if ((date != vecM[pos].date) && (increment>0)) increment--;
} else if (windowposition=="left") {
......@@ -194,7 +195,7 @@ bool FilterAlgorithms::getWindowData(const std::string& filtername, const std::v
} else {
if (startposition<(vecM.size()-1)) startposition++;
else return false; //time window not big enough
}
}
} else if ((windowposition == "center") && (isSoft)){ //expand to left and right (whereever possible)
if ((endposition+startposition)%2 == 0) { //try to alternate when broadening window
if (endposition > 0) endposition--;
......@@ -204,16 +205,16 @@ bool FilterAlgorithms::getWindowData(const std::string& filtername, const std::v
if (startposition<(vecM.size()-1)) startposition++;
else if (endposition > 0) endposition--;
else return false; //time window not big enough
}
}
}
}
//Date gap(vecM[startposition].date - vecM[endposition].date);
//cout << "The final gap is " << gap << " windowposition: " << windowposition << endl;
//Push all relevant data elements into the vector vecWindow
//cout << "Start: " << startposition << " End: " << endposition << endl;
for (unsigned int ii=startposition+1; (ii--) > endposition; ){
for (unsigned int ii=startposition+1; (ii--) > endposition; ){
const double& tmp = vecM[ii].param(paramindex);
if (tmp != IOUtils::nodata) {