WSL/SLF GitLab Repository

Commit 5f07ce00 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

The POPC compilation issue has been fixed (work around a POPC bug). These work...

The POPC compilation issue has been fixed (work around a POPC bug). These work arounds have been tagged as "HACK for POPC" in DEMObject, Date, Grid2/3DObject, IOHandler.ph, LegacyIO.ph and marshall_meteoio.cc.

The SNIO plugin that was forgotten at the last commit is now here and has been improved so that it correctly formats its output (it does not read yet).
parent f1511094
......@@ -31,6 +31,8 @@
*/
namespace mio {
class DEMObjectDummy {}; //HACK for POPC
class DEMObject : public Grid2DObject {
public:
Array2D<double> slope;
......
......@@ -59,6 +59,8 @@
*/
namespace mio {
class DateDummy {}; //HACK for POPC
#ifdef _POPC_
class Date : POPBase {
public:
......
......@@ -32,6 +32,8 @@
*/
namespace mio {
class Grid2DObjetctDummy {}; //HACK for POPC
#ifdef _POPC_
class Grid2DObject : POPBase {
public:
......
......@@ -32,6 +32,8 @@
*/
namespace mio {
class Grid3DObjetctDummy {}; //HACK for POPC
#ifdef _POPC_
class Grid3DObject : POPBase {
public:
......
......@@ -26,7 +26,7 @@
#include "IOPlugin.h"
#include "marshal_meteoio.h"
namespace mio {
using namespace mio; //HACK for POPC: it should be in the namespace!
typedef std::map<std::string, IOPlugin::IOPlugin>::iterator PLUGIN_ITERATOR;
......@@ -76,6 +76,5 @@ parclass IOHandler {
PLUGIN_ITERATOR mapit;
A3DIO fileio;
};
} //end namespace
#endif
......@@ -51,7 +51,7 @@
#define MAX_STRING_LENGTH 256
#define MAX_LINE_LENGTH 6000
namespace mio {
using namespace mio; //HACK for POPC: it should be in the namespace!
typedef struct {
double x;
......@@ -120,6 +120,5 @@ parclass LegacyIO
int dimx, dimy, dimz;
};
} //end namespace
#endif
......@@ -21,7 +21,8 @@
using namespace mio;
void marshal_uint(POPBuffer &buf, unsigned int &data, int maxsize, int flag, POPMemspool *temp)
//HACK for POPC: each method has been prefixed by "mio::" because it seems that POPC does not "see" the using namespace above...
void mio::marshal_uint(POPBuffer &buf, unsigned int &data, int maxsize, int flag, POPMemspool *temp)
{
(void)maxsize;
(void)*temp;
......@@ -35,7 +36,7 @@ void marshal_uint(POPBuffer &buf, unsigned int &data, int maxsize, int flag, POP
}
}
void marshal_slope_type(POPBuffer &buf, DEMObject::slope_type &data, int maxsize, int flag, POPMemspool *temp)
void mio::marshal_slope_type(POPBuffer &buf, DEMObject::slope_type &data, int maxsize, int flag, POPMemspool *temp)
{
(void)maxsize;
(void)*temp;
......@@ -49,7 +50,7 @@ void marshal_slope_type(POPBuffer &buf, DEMObject::slope_type &data, int maxsize
}
}
void marshal_geo_distances(POPBuffer &buf, Coords::geo_distances &data, int maxsize, int flag, POPMemspool *temp)
void mio::marshal_geo_distances(POPBuffer &buf, Coords::geo_distances &data, int maxsize, int flag, POPMemspool *temp)
{
(void)maxsize;
(void)*temp;
......@@ -63,7 +64,7 @@ void marshal_geo_distances(POPBuffer &buf, Coords::geo_distances &data, int maxs
}
}
void marshal_vec_coords(POPBuffer &buf,std::vector<Coords> &data, int maxsize, int flag, POPMemspool *temp)
void mio::marshal_vec_coords(POPBuffer &buf,std::vector<Coords> &data, int maxsize, int flag, POPMemspool *temp)
{
(void)maxsize;
(void)*temp;
......@@ -85,7 +86,7 @@ void marshal_vec_coords(POPBuffer &buf,std::vector<Coords> &data, int maxsize, i
}
}
void marshal_METEO_DATASET(POPBuffer &buf, METEO_DATASET &data, int maxsize, int flag, POPMemspool *temp)
void mio::marshal_METEO_DATASET(POPBuffer &buf, METEO_DATASET &data, int maxsize, int flag, POPMemspool *temp)
{
(void)maxsize;
(void)*temp;
......@@ -107,7 +108,7 @@ void marshal_METEO_DATASET(POPBuffer &buf, METEO_DATASET &data, int maxsize, int
}
}
void marshal_vector_METEO_DATASET(POPBuffer &buf, std::vector<METEO_DATASET> &data, int maxsize, int flag, POPMemspool *temp)
void mio::marshal_vector_METEO_DATASET(POPBuffer &buf, std::vector<METEO_DATASET> &data, int maxsize, int flag, POPMemspool *temp)
{
if(flag&FLAG_MARSHAL) {
int n=data.size();
......@@ -127,7 +128,7 @@ void marshal_vector_METEO_DATASET(POPBuffer &buf, std::vector<METEO_DATASET> &da
}
}
void marshal_map_str_str(POPBuffer &buf, std::map<std::string, std::string> &data_map, int maxsize, int flag, POPMemspool *temp)
void mio::marshal_map_str_str(POPBuffer &buf, std::map<std::string, std::string> &data_map, int maxsize, int flag, POPMemspool *temp)
{
(void)maxsize;
(void)*temp;
......@@ -153,7 +154,7 @@ void marshal_map_str_str(POPBuffer &buf, std::map<std::string, std::string> &dat
}
}
void marshal_vecstr(POPBuffer &buf, std::vector<std::string> &data, int maxsize, int flag, POPMemspool *temp)
void mio::marshal_vecstr(POPBuffer &buf, std::vector<std::string> &data, int maxsize, int flag, POPMemspool *temp)
{
(void)maxsize;
(void)*temp;
......@@ -175,7 +176,7 @@ void marshal_vecstr(POPBuffer &buf, std::vector<std::string> &data, int maxsize,
}
}
void marshal_map_str_vecstr(POPBuffer &buf, std::map<std::string, STR_VECTOR> &data_map, int maxsize, int flag, POPMemspool *temp)
void mio::marshal_map_str_vecstr(POPBuffer &buf, std::map<std::string, STR_VECTOR> &data_map, int maxsize, int flag, POPMemspool *temp)
{
if(flag&FLAG_MARSHAL) {
int n=data_map.size();
......@@ -199,7 +200,7 @@ void marshal_map_str_vecstr(POPBuffer &buf, std::map<std::string, STR_VECTOR> &d
}
}
void marshal_Coords(POPBuffer &buf, Coords &data, int maxsize, int flag, POPMemspool *temp) {
void mio::marshal_Coords(POPBuffer &buf, Coords &data, int maxsize, int flag, POPMemspool *temp) {
(void)maxsize;
(void)*temp;
if(flag&FLAG_MARSHAL) {
......@@ -209,7 +210,7 @@ void marshal_Coords(POPBuffer &buf, Coords &data, int maxsize, int flag, POPMems
}
}
void marshal_STATION_DATASET(POPBuffer &buf, STATION_DATASET &data, int maxsize, int flag, POPMemspool *temp)
void mio::marshal_STATION_DATASET(POPBuffer &buf, STATION_DATASET &data, int maxsize, int flag, POPMemspool *temp)
{
(void)maxsize;
(void)*temp;
......@@ -231,7 +232,7 @@ void marshal_STATION_DATASET(POPBuffer &buf, STATION_DATASET &data, int maxsize,
}
}
void marshal_vector_STATION_DATASET(POPBuffer &buf, std::vector<STATION_DATASET> &data, int maxsize, int flag, POPMemspool *temp)
void mio::marshal_vector_STATION_DATASET(POPBuffer &buf, std::vector<STATION_DATASET> &data, int maxsize, int flag, POPMemspool *temp)
{
if(flag&FLAG_MARSHAL) {
int n=data.size();
......@@ -251,7 +252,7 @@ void marshal_vector_STATION_DATASET(POPBuffer &buf, std::vector<STATION_DATASET>
}
}
void marshal_vector_Grid2DObject(POPBuffer &buf, std::vector<Grid2DObject> &data, int maxsize, int flag, POPMemspool *temp)
void mio::marshal_vector_Grid2DObject(POPBuffer &buf, std::vector<Grid2DObject> &data, int maxsize, int flag, POPMemspool *temp)
{
(void)maxsize;
(void)*temp;
......@@ -276,7 +277,7 @@ void marshal_vector_Grid2DObject(POPBuffer &buf, std::vector<Grid2DObject> &data
}
}
void marshal_TYPE_DOUBLE2D(POPBuffer &buf, TYPE_DOUBLE2D &data,int maxsize, int flag, POPMemspool *temp)
void mio::marshal_TYPE_DOUBLE2D(POPBuffer &buf, TYPE_DOUBLE2D &data,int maxsize, int flag, POPMemspool *temp)
{
(void)maxsize;
(void)*temp;
......@@ -300,7 +301,7 @@ void marshal_TYPE_DOUBLE2D(POPBuffer &buf, TYPE_DOUBLE2D &data,int maxsize, int
}
}
void marshal_TYPE_DOUBLE3D(POPBuffer &buf, TYPE_DOUBLE3D &data,int maxsize, int flag, POPMemspool *temp)
void mio::marshal_TYPE_DOUBLE3D(POPBuffer &buf, TYPE_DOUBLE3D &data,int maxsize, int flag, POPMemspool *temp)
{
(void)maxsize;
(void)*temp;
......@@ -330,7 +331,7 @@ void marshal_TYPE_DOUBLE3D(POPBuffer &buf, TYPE_DOUBLE3D &data,int maxsize, int
}
}
void marshal_TYPE_INT2D(POPBuffer &buf, TYPE_INT2D &data,int maxsize, int flag, POPMemspool *temp)
void mio::marshal_TYPE_INT2D(POPBuffer &buf, TYPE_INT2D &data,int maxsize, int flag, POPMemspool *temp)
{
(void)maxsize;
(void)*temp;
......@@ -356,7 +357,7 @@ void marshal_TYPE_INT2D(POPBuffer &buf, TYPE_INT2D &data,int maxsize, int flag,
}
}
void marshal_CDoubleArray(POPBuffer &buf, CDoubleArray &data,int maxsize, int flag, POPMemspool *temp)
void mio::marshal_CDoubleArray(POPBuffer &buf, CDoubleArray &data,int maxsize, int flag, POPMemspool *temp)
{
(void)maxsize;
(void)*temp;
......@@ -377,7 +378,7 @@ void marshal_CDoubleArray(POPBuffer &buf, CDoubleArray &data,int maxsize, int fl
}
void marshal_CNodeArray(POPBuffer &buf,CNodeArray &data,int maxsize, int flag, POPMemspool *temp)
void mio::marshal_CNodeArray(POPBuffer &buf,CNodeArray &data,int maxsize, int flag, POPMemspool *temp)
{
(void)maxsize;
(void)*temp;
......@@ -399,7 +400,7 @@ void marshal_CNodeArray(POPBuffer &buf,CNodeArray &data,int maxsize, int flag, P
}
}
void marshal_update_CNodeArray(POPBuffer &buf,CNodeArray &data,int maxsize, int flag, POPMemspool *temp)
void mio::marshal_update_CNodeArray(POPBuffer &buf,CNodeArray &data,int maxsize, int flag, POPMemspool *temp)
{
(void)maxsize;
(void)*temp;
......@@ -449,7 +450,7 @@ void marshal_update_CNodeArray(POPBuffer &buf,CNodeArray &data,int maxsize, int
}
}
void marshal_input_CNodeArray(POPBuffer &buf,CNodeArray &data,int maxsize, int flag, POPMemspool *temp)
void mio::marshal_input_CNodeArray(POPBuffer &buf,CNodeArray &data,int maxsize, int flag, POPMemspool *temp)
{
(void)maxsize;
(void)*temp;
......
/***********************************************************************************/
/* 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/>.
*/
#include "SNIO.h"
/**
* @page snowpack SNIO
* @section snowpack_format Format
* This is for reading grid data in the SNOWPACK meteo format (HACK: read implementation still missing)
*
* @section snowpack_units Units
* The distances are assumed to be in meters.
*
* @section snowpack_keywords Keywords
* This plugin uses the following keywords:
* - COORDIN: input coordinate system (see Coordinate)
* - COORDPARAM: extra input coordinates parameters (see Coordinate)
* - METEOPATH: path to the output directory
*
*/
//HACK: to do!!
using namespace std;
using namespace mio;
const int SNIO::sn_julian_offset = 2415021;
const double SNIO::plugin_nodata = 0.0; //plugin specific nodata value
SNIO::SNIO(void (*delObj)(void*), const std::string& filename) : IOInterface(delObj), cfg(filename)
{
IOUtils::getProjectionParameters(cfg, coordin, coordinparam, coordout, coordoutparam);
}
SNIO::SNIO(const std::string& configfile) : IOInterface(NULL), cfg(configfile)
{
IOUtils::getProjectionParameters(cfg, coordin, coordinparam, coordout, coordoutparam);
}
SNIO::SNIO(const ConfigReader& cfgreader) : IOInterface(NULL), cfg(cfgreader)
{
IOUtils::getProjectionParameters(cfg, coordin, coordinparam, coordout, coordoutparam);
}
SNIO::~SNIO() throw()
{
cleanup();
}
void SNIO::cleanup() throw()
{
if (fin.is_open()) {//close fin if open
fin.close();
}
if (fout.is_open()) {//close fout if open
fout.close();
}
}
void SNIO::read2DGrid(Grid2DObject& /*grid_out*/, const std::string& /*filename*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void SNIO::readDEM(DEMObject& /*dem_out*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void SNIO::readLanduse(Grid2DObject& /*landuse_out*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void SNIO::readAssimilationData(const Date& /*date_in*/, Grid2DObject& /*da_out*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void SNIO::readStationData(const Date& /*date*/, std::vector<StationData>& /*vecStation*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void SNIO::readMeteoData(const Date& /*dateStart*/, const Date& /*dateEnd*/,
std::vector< std::vector<MeteoData> >& /*vecMeteo*/,
std::vector< std::vector<StationData> >& /*vecStation*/,
const unsigned int& /*stationindex*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void SNIO::writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMeteo,
const std::vector< std::vector<StationData> >& vecStation,
const std::string&)
{
string path="";
cfg.getValue("METEOPATH", "Output", path);
for(unsigned int ii=0; ii<vecMeteo.size(); ii++) {
if(vecStation[ii].size()>0) {
const std::string station_name = vecStation[ii][0].stationName;
const std::string output_name = path + "/" + station_name + ".inp";
if( !IOUtils::fileExists(output_name) ) {
fout.open(output_name.c_str());
writeStationHeader(vecMeteo[ii], station_name);
} else {
fout.open(output_name.c_str());
}
writeStationMeteo(vecMeteo[ii], output_name);
fout.close();
}
}
}
void SNIO::writeStationHeader(const std::vector<MeteoData>& Meteo, const std::string station_name)
{
//writing the (very basic) metadata
fout << "MTO <" << station_name << "> " << Meteo.size() << "\n";
}
void SNIO::writeStationMeteo(const std::vector<MeteoData>& Meteo, const std::string& file_name)
{ //write out the data for 1 station
unsigned int failure_count = 0;
unsigned int Dirichlet_failure_count = 0;
for(unsigned int ii=0; ii<Meteo.size(); ii++) {
int YYYY, MM, DD, HH, MI;
Meteo[ii].date.getDate(YYYY, MM, DD, HH, MI);
const double sn_julian = Meteo[ii].date.getJulianDate() - sn_julian_offset + 0.5;
const double ta = Meteo[ii].ta;
const double rh = Meteo[ii].rh;
const double hnw = Meteo[ii].hnw;
const double vw = Meteo[ii].vw;
const double dw = Meteo[ii].dw;
const double iswr = Meteo[ii].iswr;
const double rswr = Meteo[ii].rswr;
const double ilwr = Meteo[ii].ilwr;
const double tss = Meteo[ii].tss;
const double tsg = Meteo[ii].tsg;
const double hs = Meteo[ii].hs;
fout.fill('0');
fout << "M " << setw(2) << DD << "." << setw(2) << MM << "." << setw(4) << YYYY << " " << setw(2) << HH << ":" << setw(2) << MI << " ";
fout.flags ( ios::fixed );
fout << setprecision(6) << setw(12) << sn_julian << " ";
//default formatting parameters for the measurements
fout.flags ( ios::fixed );
fout.fill(' ');
fout.width(6);
//TA, RH, VW, DW
if(ta==IOUtils::nodata) {
failure_count++;
fout << setw(6) << setprecision(2) << ta << " ";
} else
fout << setw(6) << setprecision(2) << K_TO_C(Meteo[ii].ta) << " ";
if(rh==IOUtils::nodata) {
failure_count++;
fout << setw(5) << setprecision(1) << rh << " ";
} else
fout << setw(5) << setprecision(1) << rh * 100. << " ";
if(vw==IOUtils::nodata)
failure_count++;
fout << setw(4) << setprecision(1) << vw << " ";
if(dw==IOUtils::nodata)
failure_count++;
fout << setw(3) << setprecision(0) << dw << " ";
//ISWR, RSWR
if(iswr==IOUtils::nodata && rswr==IOUtils::nodata) {
failure_count++;
fout << setw(3) << setprecision(0) << iswr << " " << setprecision(0) << rswr << " ";
} else {
if(iswr==IOUtils::nodata)
fout << setw(3) << setprecision(1) << "0.0" << " ";
else
fout << setw(3) << setprecision(0) << iswr << " ";
if(rswr==IOUtils::nodata)
fout << setw(3) << setprecision(1) << "0.0" << " ";
else
fout << setw(3) << setprecision(0) << rswr << " ";
}
//LWR
if(ilwr==IOUtils::nodata)
failure_count++;
fout << setw(3) << setprecision(0) << Meteo[ii].ilwr << " ";
//TSS, TSG (only required for Dirichlet)
if(tsg==IOUtils::nodata) {
Dirichlet_failure_count++;
fout << setw(6) << setprecision(1) << "0.0" << " ";
} else {
fout << setw(6) << setprecision(2) << K_TO_C(tsg) << " ";
}
if(tss==IOUtils::nodata) {
Dirichlet_failure_count++;
fout << setw(6) << setprecision(1) << "0.0" << " ";
} else {
fout << setw(6) << setprecision(2) << K_TO_C(tss) << " ";
}
//HNW, HS
if(hnw==IOUtils::nodata && hs==IOUtils::nodata) {
failure_count++;
fout << setw(5) << setprecision(2) << hnw << " " << setprecision(3) << hs << " ";
} else {
if(hnw==IOUtils::nodata)
fout << setw(5) << setprecision(1) << "0.0" << " ";
else
fout << setw(5) << setprecision(2) << hnw << " ";
if(hs==IOUtils::nodata)
fout << setw(5) << setprecision(1) << "0.0" << " ";
else
fout << setw(5) << setprecision(3) << hs / 100. << " ";
}
//we don't write any snow depth temperatures.
//we can not write wind velocity at the wind station, but since it is optional...
fout << endl;
}
fout << "END" << endl;
if(failure_count>0 || Dirichlet_failure_count>0) {
std::cout << "[W] " << failure_count << " (and potentially " << Dirichlet_failure_count <<
" more) errors found when writing " << file_name << std::endl;
}
}
void SNIO::readSpecialPoints(std::vector<Coords>&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void SNIO::write2DGrid(const Grid2DObject& /*grid_in*/, const std::string& /*name*/)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
#ifndef _METEOIO_JNI
extern "C"
{
void deleteObject(void* obj) {
delete reinterpret_cast<PluginObject*>(obj);
}
void* loadObject(const string& classname, const string& filename) {
if(classname == "SNIO") {
//cerr << "Creating dynamic handle for " << classname << endl;
return new SNIO(deleteObject, filename);
}
//cerr << "Could not load " << classname << endl;
return NULL;
}
}
#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 __SNIO_H__
#define __SNIO_H__
#include "IOInterface.h"
#include "ConfigReader.h"
#include "IOUtils.h"
#include "Coords.h"
#include "IOExceptions.h"
#include "DynamicLibrary.h"
#include <string>
#include <sstream>
#include <iostream>
namespace mio {
/**
* @class SNIO
* @brief This class enables the access to 2D grids stored in ARPS format
*
* @author Mathias Bavay
* @date 2009-12-04
*/
class SNIO : public IOInterface {
public:
SNIO(void (*delObj)(void*), const std::string& filename);
SNIO(const std::string& configfile);
SNIO(const SNIO&);
SNIO(const ConfigReader&);
~SNIO() 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:
void writeStationHeader(const std::vector<MeteoData>& Meteo, const std::string station_name);
void writeStationMeteo(const std::vector<MeteoData>& Meteo, const std::string& file_name);
void cleanup() throw();
ConfigReader cfg;
std::ifstream fin; //Input file streams
std::ofstream fout;//Output file streams
static const int sn_julian_offset;
static const double plugin_nodata; //plugin specific nodata value, e.g. -999
std::string coordin, coordinparam, coordout, coordoutparam; //projection parameters
};
} //namespace
#endif