WSL/SLF GitLab Repository

Commit 6a034988 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Trying to optimize MeteoData and to reduce its memory consumption

parent 33d58293
......@@ -93,29 +93,12 @@ size_t MeteoGrids::getParameterIndex(const std::string& parname)
************************************************************/
const double MeteoData::epsilon = 1e-5;
const size_t MeteoData::nrOfParameters = MeteoData::lastparam - MeteoData::firstparam + 1;
map<size_t, string> MeteoData::static_meteoparamname;
std::vector<std::string> MeteoData::s_default_paramname;
const bool MeteoData::__init = MeteoData::initStaticData();
bool MeteoData::initStaticData()
{
//Associate unsigned int value and a string representation of a meteo parameter
static_meteoparamname[P] = "P";
static_meteoparamname[TA] = "TA";
static_meteoparamname[RH] = "RH";
static_meteoparamname[TSG] = "TSG";
static_meteoparamname[TSS] = "TSS";
static_meteoparamname[HS] = "HS";
static_meteoparamname[VW] = "VW";
static_meteoparamname[DW] = "DW";
static_meteoparamname[VW_MAX] = "VW_MAX";
static_meteoparamname[RSWR] = "RSWR";
static_meteoparamname[ISWR] = "ISWR";
static_meteoparamname[ILWR] = "ILWR";
static_meteoparamname[TAU_CLD]= "TAU_CLD";
static_meteoparamname[PSUM] = "PSUM";
static_meteoparamname[PSUM_PH] = "PSUM_PH";
//Since the parameters enum starts at 0, this is enough to associate an index with its name
s_default_paramname.push_back("P");
s_default_paramname.push_back("TA");
s_default_paramname.push_back("RH");
......@@ -140,7 +123,7 @@ const std::string& MeteoData::getParameterName(const size_t& parindex)
if (parindex >= MeteoData::nrOfParameters)
throw IndexOutOfBoundsException("Trying to access meteo parameter that does not exist", AT);
return MeteoData::static_meteoparamname[parindex];
return MeteoData::s_default_paramname[parindex];
}
/************************************************************
......@@ -415,11 +398,10 @@ void MeteoData::merge(std::vector<MeteoData>& vec)
vec.swap( vecResult );
}
MeteoData MeteoData::merge(const MeteoData& meteo1, const MeteoData& meteo2)
MeteoData MeteoData::merge(MeteoData meteo1, const MeteoData& meteo2)
{
MeteoData tmp(meteo1);
tmp.merge(meteo2);
return tmp;
meteo1.merge(meteo2);
return meteo1;
}
void MeteoData::merge(const MeteoData& meteo2)
......
......@@ -232,7 +232,7 @@ class MeteoData {
* @param meteo1 reference MeteoData, highest priority
* @param meteo2 extra MeteoData to merge, lowest priority
*/
static MeteoData merge(const MeteoData& meteo1, const MeteoData& meteo2);
static MeteoData merge(MeteoData meteo1, const MeteoData& meteo2);
/**
* @brief Simple merge strategy.
......@@ -259,8 +259,7 @@ class MeteoData {
private:
//static methods
static std::map<size_t, std::string> static_meteoparamname; ///<Associate a name with meteo parameters in Parameters
static std::vector<std::string> s_default_paramname;
static std::vector<std::string> s_default_paramname; ///<Associate a name with meteo parameters in Parameters
static const double epsilon; ///<for comparing fields
static const bool __init; ///<helper variable to enable the init of static collection data
static bool initStaticData();///<initialize the static map meteoparamname
......
......@@ -38,16 +38,16 @@ void StationData::setStationData(const Coords& i_position, const std::string& i_
void StationData::setSlope(const double& in_slope_angle, const double& in_azimuth)
{
if(in_slope_angle!=IOUtils::nodata) {
if (in_slope_angle!=IOUtils::nodata) {
slope = fmod(in_slope_angle, 360.);
//normalizing the slope between 0 and 90
if(slope>90. && slope <=180.) slope = 180. - slope;
if(slope>180. && slope <=270.) slope = slope - 180.;
if(slope>270. && slope <=360.) slope = 360. - slope;
if (slope>90. && slope <=180.) slope = 180. - slope;
if (slope>180. && slope <=270.) slope = slope - 180.;
if (slope>270. && slope <=360.) slope = 360. - slope;
} else
slope = IOUtils::nodata;
if(in_azimuth!=IOUtils::nodata)
if (in_azimuth!=IOUtils::nodata)
azi = fmod(in_azimuth, 360.);
else
azi = IOUtils::nodata;
......@@ -65,17 +65,16 @@ bool StationData::operator!=(const StationData& in) const {
return !(*this==in);
}
StationData StationData::merge(const StationData& sd1, const StationData& sd2) {
StationData tmp(sd1);
tmp.merge(sd2);
return tmp;
StationData StationData::merge(StationData sd1, const StationData& sd2) {
sd1.merge(sd2);
return sd1;
}
void StationData::merge(const StationData& sd2) {
if(stationID.empty()) stationID=sd2.stationID;
if(stationName.empty()) stationName=sd2.stationName;
if(slope==IOUtils::nodata) slope=sd2.slope;
if(azi==IOUtils::nodata) azi=sd2.azi;
if (stationID.empty()) stationID=sd2.stationID;
if (stationName.empty()) stationName=sd2.stationName;
if (slope==IOUtils::nodata) slope=sd2.slope;
if (azi==IOUtils::nodata) azi=sd2.azi;
position.merge(sd2.position);
}
......
......@@ -107,7 +107,7 @@ class StationData {
* @param sd2 second StationData to merge, lowest priority
* @return new StationData object
*/
static StationData merge(const StationData& sd1, const StationData& sd2);
static StationData merge(StationData sd1, const StationData& sd2);
/**
* @brief Simple merge strategy.
......
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