WSL/SLF GitLab Repository

Commit 752c0068 authored by Thomas Egger's avatar Thomas Egger
Browse files

Directory structure change: src folder now called meteoio

Overall all include statements within in the library have been replaced by angle brackets, the default install path for the include file is $CMAKE_INSTALL_DIR/include/meteoio, the meteoio libraries (static and shared) will be installed in $CMAKE_INSTALL_DIR/lib per default.

The plugins will be installed in the subdirectory $CMAKE_INSTALL_DIR/lib/meteoio/plugins
parent 630ca661
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 __A3DIO_H__
#define __A3DIO_H__
#include <meteoio/IOInterface.h>
#include <meteoio/Coords.h>
#include <meteoio/ConfigReader.h>
#include <meteoio/IOExceptions.h>
#include <meteoio/IOUtils.h>
#include <string>
#include <vector>
#include <map>
namespace mio {
class A3DIO : public IOInterface {
public:
//virtual A3DIO* clone() const;
//A3DIO(void (*delObj)(void*), const std::string& filename);
A3DIO(const std::string& configfile);
A3DIO(const A3DIO&);
A3DIO(const ConfigReader&);
~A3DIO() throw();
virtual void read2DGrid(Grid2DObject& dem_out, const std::string& name="");
virtual void readDEM(DEMObject& dem_out);
virtual void readLanduse(Grid2DObject& landuse_out);
virtual void readAssimilationData(const Date&, Grid2DObject& da_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);
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 readSpecialPoints(std::vector<Coords>& pts);
virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& name);
private:
static const double plugin_nodata; //plugin specific nodata value, e.g. -9999
void read1DMeteo(const Date& dateStart, const Date& dateEnd,
std::vector< std::vector<MeteoData> >&, std::vector< std::vector<StationData> >&); ///< No buffering
void read2DMeteo(std::vector< std::vector<MeteoData> >&, std::vector< std::vector<StationData> >&); ///< No buffering
void constructMeteo2DFilenames(const Date& _startDate, const Date& _endDate, std::vector<std::string>& _filenames);
bool readMeteoDataLine(std::string& line, MeteoData& tmpdata, std::string filename);
void convertUnits(MeteoData& meteo);
void cleanup() throw();
void read2DMeteoData(const std::string&, const std::string&, std::map<std::string,unsigned int>& hashStations,
std::vector< std::vector<MeteoData> >&, unsigned int& bufferindex);
void read2DMeteoHeader(const std::string& filename, std::map<std::string, unsigned int>& hashStations,
std::vector<StationData>&);
unsigned int getNrOfStations(std::vector<std::string>& filenames,
std::map<std::string, unsigned int>& hashStations);
int create1DFile(const std::vector< std::vector<MeteoData> >& data, const std::vector< std::vector<StationData> >& stations);
int writeHeader(std::ofstream &file, const std::vector< std::vector<StationData> >& stations, const std::string parameter_name);
void open2DFile(const std::vector< std::vector<StationData> >& stations,
const std::string& fileprefix, const std::string& label, const double& year,
std::ofstream& file);
int write2DmeteoFile(const std::vector< std::vector<MeteoData> >& data, const std::vector< std::vector<StationData> >& stations,
const unsigned int& parindex, const std::string& filename,
const std::string& label);
void write2DMeteo(const std::vector< std::vector<MeteoData> >& data, const std::vector< std::vector<StationData> >& stations);
ConfigReader cfg;
std::ifstream fin; //Input file streams
std::string coordin, coordinparam, coordout, coordoutparam; //projection parameters
};
} //end namespace
#endif
/***********************************************************************************/
/* 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 ARRAY_H
#define ARRAY_H
#include <meteoio/IOUtils.h>
#include <meteoio/IOExceptions.h>
#include <vector>
#include <limits>
#include <iostream>
#define NOSAFECHECKS
namespace mio {
/**
* @class Array
* @brief The template class Array is a 1D array (vector) able to hold any type of object as datatype
*
* @author Thomas Egger
* @date 2009-05-02
*/
template<class T> class Array {
public:
Array(const unsigned int& asize=0);
unsigned int size();
void resize(const unsigned int& asize);
void clear();
void insertAt(const int& index, T e);
void removeAt(const unsigned int& index);
/**
* @brief returns the minimum value contained in the grid
* @param flag_nodata specify how to process nodata values (see NODATA_HANLDING)
* @return minimum value
*/
T getMin(const IOUtils::nodata_handling flag_nodata=IOUtils::PARSE_NODATA) const;
/**
* @brief returns the maximum value contained in the grid
* @param flag_nodata specify how to process nodata values (see NODATA_HANLDING)
* @return maximum value
*/
T getMax(const IOUtils::nodata_handling flag_nodata=IOUtils::PARSE_NODATA) const;
/**
* @brief returns the mean value contained in the grid
* @param flag_nodata specify how to process nodata values (see NODATA_HANLDING)
* @return mean value
*/
T getMean(const IOUtils::nodata_handling flag_nodata=IOUtils::PARSE_NODATA) const;
template<class P> friend std::ostream& operator<<(std::ostream& os, const Array<P>& array);
T& operator [](const unsigned int& index);
const T operator [](const unsigned int& index) const;
T& operator ()(const unsigned int& index);
const T operator ()(const unsigned int& index) const;
Array<T>& operator =(const Array<T>&);
Array<T>& operator+=(const T& rhs);
const Array<T> operator+(const T& rhs);
Array<T>& operator+=(const Array<T>& rhs);
const Array<T> operator+(const Array<T>& rhs);
Array<T>& operator-=(const T& rhs);
const Array<T> operator-(const T& rhs);
Array<T>& operator-=(const Array<T>& rhs);
const Array<T> operator-(const Array<T>& rhs);
Array<T>& operator*=(const T& rhs);
const Array<T> operator*(const T& rhs);
Array<T>& operator*=(const Array<T>& rhs);
const Array<T> operator*(const Array<T>& rhs);
Array<T>& operator/=(const T& rhs);
const Array<T> operator/(const T& rhs);
Array<T>& operator/=(const Array<T>& rhs);
const Array<T> operator/(const Array<T>& rhs);
protected:
std::vector<T> vecData; ///<the actual data structure, that holds the objects of type T
unsigned int nx; ///<this is introduced to omit the costly vecData.size()
};
template<class T> Array<T>::Array(const unsigned int& asize) {
resize(asize);
nx = asize;
}
template<class T> unsigned int Array<T>::size() {
return nx;
}
template<class T> void Array<T>::resize(const unsigned int& asize) {
if (asize != vecData.size()) {
vecData.resize(asize);
nx = asize;
}
}
template<class T> T& Array<T>::operator()(const unsigned int& index) {
#ifndef NOSAFECHECKS
if (index >= nx) {
throw IndexOutOfBoundsException("", AT);
}
#endif
return vecData[index];
}
template<class T> const T Array<T>::operator()(const unsigned int& index) const {
#ifndef NOSAFECHECKS
if (index >= nx) {
throw IndexOutOfBoundsException("", AT);
}
#endif
return vecData[index];
}
template<class T> T& Array<T>::operator [](const unsigned int& index) {
#ifndef NOSAFECHECKS
if (index >= nx) {
throw IndexOutOfBoundsException("", AT);
}
#endif
return vecData[index];
}
template<class T> const T Array<T>::operator [](const unsigned int& index) const {
#ifndef NOSAFECHECKS
if (index >= nx) {
throw IndexOutOfBoundsException("", AT);
}
#endif
return vecData[index];
}
template<class T> void Array<T>::clear() {
vecData.clear();
nx = 0;
}
template<class T> std::ostream& operator<<(std::ostream& os, const Array<T>& array) {
os << "<array1d>\n";
for(unsigned int ii=0; ii<array.nx; ii++) {
os << array(ii) << " ";
}
os << "\n</array1d>\n";
return os;
}
template<class T> void Array<T>::insertAt(const int& index, T e) {
if (index < 0) {
vecData.push_back(e);
nx++;
} else if ((index >= 0) && (index < (int)vecData.size())) {
vecData.insert(vecData.begin() + index, e);
nx++;
} else {
throw IndexOutOfBoundsException("", AT);
}
}
template<class T> void Array<T>::removeAt(const unsigned int& index) {
if (index < vecData.size()) {
vecData.erase(vecData.begin()+index);
nx--;
}
}
template<class T> T Array<T>::getMin(const IOUtils::nodata_handling flag_nodata) const {
T min = std::numeric_limits<T>::max();
if(flag_nodata==IOUtils::RAW_NODATA) {
for (unsigned int ii=0; ii<nx; ii++) {
const T val = vecData[ii];
if(val<min) min=val;
}
return min;
} else if(flag_nodata==IOUtils::PARSE_NODATA) {
for (unsigned int ii=0; ii<nx; ii++) {
const T val = vecData[ii];
if(val!=IOUtils::nodata && val<min) min=val;
}
if(min!=std::numeric_limits<T>::max()) return min;
else return (T)IOUtils::nodata;
} else {
throw InvalidArgumentException("Unknown nodata_handling flag",AT);
}
}
template<class T> T Array<T>::getMax(const IOUtils::nodata_handling flag_nodata) const {
T max = -std::numeric_limits<T>::max();
if(flag_nodata==IOUtils::RAW_NODATA) {
for (unsigned int ii=0; ii<nx; ii++) {
const T val = vecData[ii];
if(val>max) max=val;
}
return max;
} else if(flag_nodata==IOUtils::PARSE_NODATA) {
for (unsigned int ii=0; ii<nx; ii++) {
const T val = vecData[ii];
if(val!=IOUtils::nodata && val>max) max=val;
}
if(max!=-std::numeric_limits<T>::max()) return max;
else return (T)IOUtils::nodata;
} else {
throw InvalidArgumentException("Unknown nodata_handling flag",AT);
}
}
template<class T> T Array<T>::getMean(const IOUtils::nodata_handling flag_nodata) const {
T mean = 0;
if(flag_nodata==IOUtils::RAW_NODATA) {
for (unsigned int ii=0; ii<nx; ii++) {
const T val = vecData[ii];
mean += val;
}
const unsigned int count = nx;
if(count>0) return mean/(T)(count);
else return (T)0;
} else if(flag_nodata==IOUtils::PARSE_NODATA) {
unsigned int count = 0;
for (unsigned int ii=0; ii<nx; ii++) {
const T val = vecData[ii];
if(val!=IOUtils::nodata) {
mean += val;
count++;
}
}
if(count>0) return mean/(T)(count);
else return (T)IOUtils::nodata;
} else {
throw InvalidArgumentException("Unknown nodata_handling flag",AT);
}
}
//arithmetic operators
template<class T> Array<T>& Array<T>::operator=(const Array<T>& source) {
if(this != &source) {
vecData = source.vecData;
nx = source.nx;
}
return *this;
}
template<class T> Array<T>& Array<T>::operator+=(const Array<T>& rhs)
{
//They have to have equal size
if (rhs.nx != nx)
throw IOException("Trying to add two Array objects with different dimensions", AT);
//Add to every single member of the Array<T>
for (unsigned int ii=0; ii<nx; ii++) {
operator()(ii) += rhs(ii);
}
return *this;
}
template<class T> const Array<T> Array<T>::operator+(const Array<T>& rhs)
{
Array<T> result = *this; //make a copy
result += rhs; //already implemented
return result;
}
template<class T> Array<T>& Array<T>::operator+=(const T& rhs)
{
//Add to every single member of the Array<T>
for (unsigned int ii=0; ii<nx; ii++) {
operator()(ii) += rhs;
}
return *this;
}
template<class T> const Array<T> Array<T>::operator+(const T& rhs)
{
Array<T> result = *this;
result += rhs; //already implemented
return result;
}
template<class T> Array<T>& Array<T>::operator-=(const Array<T>& rhs)
{
//They have to have equal size
if (rhs.nx != nx)
throw IOException("Trying to substract two Array objects with different dimensions", AT);
//Substract to every single member of the Array<T>
for (unsigned int ii=0; ii<nx; ii++) {
operator()(ii) -= rhs(ii);
}
return *this;
}
template<class T> const Array<T> Array<T>::operator-(const Array<T>& rhs)
{
Array<T> result = *this; //make a copy
result -= rhs; //already implemented
return result;
}
template<class T> Array<T>& Array<T>::operator-=(const T& rhs)
{
//Substract to every single member of the Array<T>
for (unsigned int ii=0; ii<nx; ii++) {
operator()(ii) -= rhs;
}
return *this;
}
template<class T> const Array<T> Array<T>::operator-(const T& rhs)
{
Array<T> result = *this;
result -= rhs; //already implemented
return result;
}
template<class T> Array<T>& Array<T>::operator*=(const Array<T>& rhs)
{
//They have to have equal size
if (rhs.nx != nx)
throw IOException("Trying to multiply two Array objects with different dimensions", AT);
//Add to every single member of the Array<T>
for (unsigned int ii=0; ii<nx; ii++) {
operator()(ii) *= rhs(ii);
}
return *this;
}
template<class T> const Array<T> Array<T>::operator*(const Array<T>& rhs)
{
Array<T> result = *this; //make a copy
result *= rhs; //already implemented
return result;
}
template<class T> Array<T>& Array<T>::operator*=(const T& rhs)
{
//Add to every single member of the Array<T>
for (unsigned int ii=0; ii<nx; ii++) {
operator()(ii) *= rhs;
}
return *this;
}
template<class T> const Array<T> Array<T>::operator*(const T& rhs)
{
Array<T> result = *this;
result *= rhs; //already implemented
return result;
}
template<class T> Array<T>& Array<T>::operator/=(const Array<T>& rhs)
{
//They have to have equal size
if (rhs.nx != nx)
throw IOException("Trying to divide two Array objects with different dimensions", AT);
//Divide every single member of the Array<T>
for (unsigned int ii=0; ii<nx; ii++) {
operator()(ii) /= rhs(ii);
}
return *this;
}
template<class T> const Array<T> Array<T>::operator/(const Array<T>& rhs)
{
Array<T> result = *this; //make a copy
result /= rhs; //already implemented
return result;
}
template<class T> Array<T>& Array<T>::operator/=(const T& rhs)
{
//Divide every single member of the Array<T>
for (unsigned int ii=0; ii<nx; ii++) {
operator()(ii) /= rhs;
}
return *this;
}
template<class T> const Array<T> Array<T>::operator/(const T& rhs)
{
Array<T> result = *this;
result /= rhs; //already implemented
return result;
}
} //end namespace mio
#endif
/***********************************************************************************/
/* 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 ARRAY2D_H
#define ARRAY2D_H
#include <meteoio/IOExceptions.h>
#include <meteoio/IOUtils.h>
#include <vector>
#include <limits>
#include <iostream>
#define NOSAFECHECKS
namespace mio {
template <class T> class Array2D;
/**
* @class Array2DProxy
* @brief The template class Array2DProxy is a helper class for the template class Array2D
* with the purpose of adding the [][] operator to Array2D
*
* @author Thomas Egger
*/
template <class T> class Array2DProxy {
public:
friend class Array2D<T>;
T& operator[](const unsigned int& j) {
return array2D(anx, j);
}
private:
Array2DProxy(Array2D<T>& _array2D, const unsigned int& _anx) : array2D(_array2D), anx(_anx){}
Array2D<T>& array2D;
const unsigned int anx;
};
/**
* @class Array2D
* @brief The template class Array2D is a 2D Array (Matrix) able to hold any type of object as datatype
*
* @author Thomas Egger
*/
template<class T> class Array2D {
public:
Array2D();
Array2D(const unsigned int& anx, const unsigned int& any);
Array2D(const unsigned int& anx, const unsigned int& any, const T& init);
/**
* A constructor that can be used to create an Array2D object that is contained in the
* one passed as _array2D argument. The resulting Array2D object is a by value copy of
* a subplane of the plane spanned by the _array2D
*/
Array2D(const Array2D<T>& _array2D, const unsigned int& _nx, const unsigned int& _ny,
const unsigned int& _ncols,