WSL/SLF GitLab Repository

Commit bb694fb0 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

In order to add 3D grid reading/writing methods to the plugins, the whole...

In order to add 3D grid reading/writing methods to the plugins, the whole architecture of IOInterface has been changed: this is not a purely virtual class anymore, it now always implements the "nothing implemented here" exception. This makes the plugins more compact (there is no need to implement empty methods for what the plugin can not support) and much clearer. The documentation and template have been changed acoordingly.
parent 5bff3ee5
......@@ -46,6 +46,7 @@ SET(meteoio_sources
DataGenerator.cc
GeneratorAlgorithms.cc
plugins/libsmet.cc
IOInterface.cc
${plugins_sources}
${meteoLaws_sources}
${meteoStats_sources}
......
......@@ -23,10 +23,12 @@
#include <meteoio/dataClasses/Date.h>
#include <meteoio/dataClasses/DEMObject.h>
#include <meteoio/dataClasses/Grid2DObject.h>
#include <meteoio/dataClasses/Grid3DObject.h>
#include <meteoio/dataClasses/MeteoData.h>
#include <meteoio/dataClasses/StationData.h>
#include <vector>
#include <string>
namespace mio {
......@@ -79,8 +81,8 @@ namespace mio {
/**
* @class IOInterface
* @brief An abstract class representing the IO Layer of the software Alpine3D. For each type of IO (File, DB, Webservice, etc)
* a derived class is to be created that holds the specific implementation of the purely virtual member funtions.
* @brief A class representing the IO Layer of the software Alpine3D. For each type of IO (File, DB, Webservice, etc)
* a derived class is to be created that holds the specific implementation of the appropriate virtual methods.
* The IOHandler class is a wrapper class that is able to deal with all above implementations of the IOInterface abstract base class.
*
* @ingroup plugins
......@@ -97,7 +99,7 @@ class IOInterface {
* @param grid_out A Grid2DObject instance
* @param parameter A std::string representing some information for the function on what grid to retrieve
*/
virtual void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="") = 0;
virtual void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="");
/**
* @brief Read the given meteo parameter into a Grid2DObject.
......@@ -106,7 +108,24 @@ class IOInterface {
* @param parameter The meteo parameter grid type to return (ie: air temperature, wind component, etc)
* @param date date of the data to read
*/
virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date) = 0;
virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
/**
* @brief A generic function for parsing 3D grids into a Grid3DObject. The string parameter shall be used for addressing the
* specific 3D grid to be parsed into the Grid3DObject, relative to GRID3DPATH for most plugins.
* @param grid_out A Grid3DObject instance
* @param parameter A std::string representing some information for the function on what grid to retrieve
*/
virtual void read3DGrid(Grid3DObject& grid_out, const std::string& parameter="");
/**
* @brief Read the given meteo parameter into a Grid3DObject.
* Each plugin has its own logic for finding the requested meteo parameter grid relative to GRID3DPATH for most plugins
* @param grid_out A Grid3DObject instance
* @param parameter The meteo parameter grid type to return (ie: air temperature, wind component, etc)
* @param date date of the data to read
*/
virtual void read3DGrid(Grid3DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
/**
* @brief Parse the DEM (Digital Elevation Model) into the Grid2DObject
......@@ -119,7 +138,7 @@ class IOInterface {
* @endcode
* @param dem_out A Grid2DObject that holds the DEM
*/
virtual void readDEM(DEMObject& dem_out) = 0;
virtual void readDEM(DEMObject& dem_out);
/**
* @brief Parse the landuse model into the Grid2DObject
......@@ -132,7 +151,7 @@ class IOInterface {
* @endcode
* @param landuse_out A Grid2DObject that holds the landuse model
*/
virtual void readLanduse(Grid2DObject& landuse_out) = 0;
virtual void readLanduse(Grid2DObject& landuse_out);
/**
* @brief Fill vecStation with StationData objects for a certain date of interest
......@@ -147,7 +166,7 @@ class IOInterface {
* @param date A Date object representing the date for which the meta data is to be fetched
* @param vecStation A vector of StationData objects to be filled with meta data
*/
virtual void readStationData(const Date& date, std::vector<StationData>& vecStation) = 0;
virtual void readStationData(const Date& date, std::vector<StationData>& vecStation);
/**
* @brief Fill vecMeteo with a time series of objects
......@@ -174,7 +193,7 @@ class IOInterface {
*/
virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
std::vector< std::vector<MeteoData> >& vecMeteo,
const size_t& stationindex=IOUtils::npos) = 0;
const size_t& stationindex=IOUtils::npos);
/**
* @brief Write vecMeteo time series to a certain destination
......@@ -200,7 +219,7 @@ class IOInterface {
* of a file name, a db table, etc)
*/
virtual void writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMeteo,
const std::string& name="") = 0;
const std::string& name="");
/**
* @brief Parse the assimilation data into a Grid2DObject for a certain date represented by the Date object
......@@ -215,32 +234,51 @@ class IOInterface {
* @param date_in A Date object representing the date of the assimilation data
* @param da_out A Grid2DObject that holds the assimilation data for every grid point
*/
virtual void readAssimilationData(const Date& date_in, Grid2DObject& da_out) = 0;
virtual void readAssimilationData(const Date& date_in, Grid2DObject& da_out);
/**
* @brief Read a list of points by their grid coordinates
* This allows for example to get a list of points where to produce more detailed outputs.
* @param pts (std::vector<Coords>) A vector of points coordinates
*/
virtual void readPOI(std::vector<Coords>& pts) = 0;
virtual void readPOI(std::vector<Coords>& pts);
/**
* @brief Write a Grid2DObject
* The filename is specified relative to GRID2DPATH for most plugins
* @param grid_in (Grid2DObject) The grid to write
* @param grid_out (Grid2DObject) The grid to write
* @param options (string) Identifier usefull for the output plugin (it could become part of a file name, a db table, etc)
*/
virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& options="") = 0;
virtual void write2DGrid(const Grid2DObject& grid_out, const std::string& options="");
/**
* @brief Write a Grid2DObject comtaining a known meteorological parameter
* A filename is build relative to GRID2DPATH for most plugins.
* @param grid_in (Grid2DObject) The grid to write
* @param grid_out (Grid2DObject) The grid to write
* @param parameter The meteo parameter grid type of the provided grid object (ie: air temperature, wind component, etc)
* @param date date of the data to write
*/
virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date) = 0;
virtual void write2DGrid(const Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
/**
* @brief Write a Grid3DObject
* The filename is specified relative to GRID3DPATH for most plugins
* @param grid_out (Grid3DObject) The grid to write
* @param options (string) Identifier usefull for the output plugin (it could become part of a file name, a db table, etc)
*/
virtual void write3DGrid(const Grid3DObject& grid_out, const std::string& options);
/**
* @brief Write a Grid3DObject comtaining a known meteorological parameter
* A filename is build relative to GRID3DPATH for most plugins.
* @param grid_out (Grid3DObject) The grid to write
* @param parameter The meteo parameter grid type of the provided grid object (ie: air temperature, wind component, etc)
* @param date date of the data to write
*/
virtual void write3DGrid(const Grid3DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
};
} //end namespace
#endif
......@@ -80,48 +80,6 @@ A3DIO::A3DIO(const Config& in_cfg)
meteo1d += "/meteo1d.txt";
}
void A3DIO::read2DGrid(Grid2DObject&, const std::string&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void A3DIO::read2DGrid(Grid2DObject&, const MeteoGrids::Parameters&, const Date&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void A3DIO::readDEM(DEMObject& /*dem_out*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void A3DIO::readLanduse(Grid2DObject& /*landuse_out*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void A3DIO::readAssimilationData(const Date& /*date_in*/, Grid2DObject& /*da_out*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void A3DIO::write2DGrid(const Grid2DObject&, const std::string&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void A3DIO::write2DGrid(const Grid2DObject&, const MeteoGrids::Parameters&, const Date&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void A3DIO::writeMeteoData(const std::vector< std::vector<MeteoData> >& vec_data, const std::string&)
{
if (!vec_data.empty()) {
......
......@@ -39,13 +39,7 @@ class A3DIO : public IOInterface {
public:
A3DIO(const std::string& configfile);
A3DIO(const Config&);
virtual void read2DGrid(Grid2DObject& dem_out, const std::string& name="");
virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
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,
......@@ -55,12 +49,8 @@ class A3DIO : public IOInterface {
virtual void writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMeteo,
const std::string& name="");
virtual void readAssimilationData(const Date&, Grid2DObject& da_out);
virtual void readPOI(std::vector<Coords>& pts);
virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& name);
virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
private:
void read1DStation(StationData& sd);
void read1DMeteo(const Date& dateStart, const Date& dateEnd, std::vector< std::vector<MeteoData> >&);
......
......@@ -205,36 +205,6 @@ void ALPUG::readMetaData()
throw NoDataException(msg+" do(es) not have metadata in \'"+metafile+"\'", AT);
}
void ALPUG::read2DGrid(Grid2DObject& /*grid_out*/, const std::string& /*name_in*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ALPUG::read2DGrid(Grid2DObject& /*grid_out*/, const MeteoGrids::Parameters& /*parameter*/, const Date& /*date*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ALPUG::readDEM(DEMObject& /*dem_out*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ALPUG::readLanduse(Grid2DObject& /*landuse_out*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ALPUG::readAssimilationData(const Date& /*date_in*/, Grid2DObject& /*da_out*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ALPUG::readStationData(const Date&, std::vector<StationData>& vecStation)
{
vecStation = vecMeta;
......@@ -392,29 +362,4 @@ void ALPUG::readMeteoData(const Date& dateStart, const Date& dateEnd,
}
}
void ALPUG::writeMeteoData(const std::vector< std::vector<MeteoData> >& /*vecMeteo*/,
const std::string&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ALPUG::readPOI(std::vector<Coords>&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ALPUG::write2DGrid(const Grid2DObject& /*grid_in*/, const std::string& /*name*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ALPUG::write2DGrid(const Grid2DObject& /*grid_in*/, const MeteoGrids::Parameters& /*parameter*/, const Date& /*date*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
} //namespace
......@@ -41,24 +41,11 @@ class ALPUG : public IOInterface {
ALPUG(const Config& cfgreader);
~ALPUG() throw() {}
virtual void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="");
virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
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,
const size_t& stationindex=IOUtils::npos);
virtual void writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMeteo,
const std::string& name="");
virtual void readAssimilationData(const Date&, Grid2DObject& da_out);
virtual void readPOI(std::vector<Coords>& pts);
virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& filename);
virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
private:
void parseInputOutputSection();
void readMetaData();
......
......@@ -288,31 +288,6 @@ void ARCIO::readAssimilationData(const Date& date_in, Grid2DObject& da_out)
read2DGrid_internal(da_out, filepath+"/"+dateStr+".sca");
}
void ARCIO::readStationData(const Date&, std::vector<StationData>&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ARCIO::readMeteoData(const Date&, const Date&, std::vector< std::vector<MeteoData> >&,
const size_t&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ARCIO::writeMeteoData(const std::vector< std::vector<MeteoData> >&, const std::string&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ARCIO::readPOI(std::vector<Coords>&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ARCIO::write2DGrid(const Grid2DObject& grid_in, const std::string& name)
{
const std::string full_name = grid2dpath_out+"/"+name;
......
......@@ -48,15 +48,8 @@ class ARCIO : public IOInterface {
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,
const size_t& stationindex=IOUtils::npos);
virtual void writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMeteo,
const std::string& name="");
virtual void readAssimilationData(const Date&, Grid2DObject& da_out);
virtual void readPOI(std::vector<Coords>& pts);
virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& filename);
virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
......
......@@ -318,57 +318,6 @@ void ARPSIO::readDEM(DEMObject& dem_out)
fclose(fin);
}
void ARPSIO::readLanduse(Grid2DObject& /*landuse_out*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ARPSIO::readAssimilationData(const Date& /*date_in*/, Grid2DObject& /*da_out*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ARPSIO::readStationData(const Date&, std::vector<StationData>& /*vecStation*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ARPSIO::readMeteoData(const Date& /*dateStart*/, const Date& /*dateEnd*/,
std::vector< std::vector<MeteoData> >& /*vecMeteo*/,
const size_t&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ARPSIO::writeMeteoData(const std::vector< std::vector<MeteoData> >& /*vecMeteo*/,
const std::string&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ARPSIO::readPOI(std::vector<Coords>&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ARPSIO::write2DGrid(const Grid2DObject& /*grid_in*/, const std::string& /*name*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ARPSIO::write2DGrid(const Grid2DObject&, const MeteoGrids::Parameters&, const Date&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ARPSIO::initializeGRIDARPS(FILE* &fin, const std::string& filename)
{
double v1, v2;
......
......@@ -55,22 +55,9 @@ class ARPSIO : public IOInterface {
virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
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,
const size_t& stationindex=IOUtils::npos);
virtual void writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMeteo,
const std::string& name="");
virtual void readAssimilationData(const Date&, Grid2DObject& da_out);
virtual void readPOI(std::vector<Coords>& pts);
virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& filename);
virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
void read3DGrid(Grid3DObject& grid_out, const std::string& parameter="");
virtual void read3DGrid(Grid3DObject& grid_out, const std::string& parameter="");
//virtual void read3DGrid(Grid3DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
private:
void setOptions();
......
......@@ -66,43 +66,6 @@ BormaIO::BormaIO(const Config& cfgreader)
cfg.getValue("TIME_ZONE","Input",in_tz,IOUtils::nothrow);
}
void BormaIO::read2DGrid(Grid2DObject&, const std::string&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void BormaIO::read2DGrid(Grid2DObject&, const MeteoGrids::Parameters&, const Date&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void BormaIO::readDEM(DEMObject&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void BormaIO::readLanduse(Grid2DObject&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void BormaIO::writeMeteoData(const std::vector< std::vector<MeteoData> >&,
const std::string&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void BormaIO::readStationData(const Date&, std::vector<StationData>&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void BormaIO::readMeteoData(const Date& dateStart, const Date& dateEnd,
std::vector< std::vector<MeteoData> >& vecMeteo,
const size_t& stationindex)
......@@ -400,30 +363,6 @@ bool BormaIO::validFilename(const std::string& tmp) const
return true;
}
void BormaIO::readAssimilationData(const Date&, Grid2DObject&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void BormaIO::readPOI(std::vector<Coords>&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void BormaIO::write2DGrid(const Grid2DObject&, const std::string&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void BormaIO::write2DGrid(const Grid2DObject&, const MeteoGrids::Parameters&, const Date&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void BormaIO::convertUnits(MeteoData& meteo)
{
meteo.standardizeNodata(plugin_nodata);
......
......@@ -46,29 +46,12 @@ class BormaIO : public IOInterface {
BormaIO(void (*delObj)(void*), const Config& i_cfg);
BormaIO(const std::string& configfile);
BormaIO(const BormaIO&);
BormaIO(const Config&);
virtual void read2DGrid(Grid2DObject& dem_out, const std::string& parameter="");
virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
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,
const size_t& stationindex=IOUtils::npos);
virtual void writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMeteo,
const std::string& name="");
virtual void readAssimilationData(const Date&, Grid2DObject& da_out);
virtual void readPOI(std::vector<Coords>& pts);
virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& name);
virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
private:
void convertUnits(MeteoData& meteo);
void checkForMeteoFiles(const std::string& xmlpath, const std::string& stationname, const Date& date_in,
......
......@@ -156,8 +156,6 @@ CNRMIO::CNRMIO(const Config& cfgreader) : cfg(cfgreader), coordin(), coordinpara
parseInputOutputSection();
}
CNRMIO::~CNRMIO() throw() {}
void CNRMIO::parseInputOutputSection()
{
//default timezones
......@@ -265,18 +263,6 @@ void CNRMIO::readDEM(DEMObject& dem_out)
read2DGrid_internal(dem_out, filename, varname);
}
void CNRMIO::readLanduse(Grid2DObject& /*landuse_out*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void CNRMIO::readAssimilationData(const Date& /*date_in*/, Grid2DObject& /*da_out*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void CNRMIO::readStationData(const Date&, std::vector<StationData>& vecStation)