WSL/SLF GitLab Repository

Commit 841d9337 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Finally adressing issue 72 with second resolution in dates. The ISO strings...

Finally adressing issue 72 with second resolution in dates. The ISO strings now contain the seconds when written out and by reading them, the seconds can be provided (but this is not mandatory). In ARC, grids are now named with the seconds (except when enabling the Alpine3D naming scheme). The adresses a bug that was found when requesting" raw" processing level from a plugin that constructs its timestamps from a decomposed time: time-1s and time+1s were the same and therefore this could trigger problems in the plugin.
parent 0d0e62ea
......@@ -439,7 +439,7 @@ bool convertString(Date& t, const std::string& str, const double& time_zone, std
stripComments(timezone_iso);
const double tz = (timezone_iso.empty())? time_zone : Date::parseTimeZone(timezone_iso);
if(tz==nodata) return false;
t.setDate(year, month, day, hour, minute, tz);
t.setDate(year, month, day, hour, minute, second, tz);
return true;
} else if (sscanf(c_str, "%d-%u-%uT%u:%u:%lg%31s", &year, &month, &day, &hour, &minute, &second, rest) >= 6) { //ISO
......@@ -447,7 +447,7 @@ bool convertString(Date& t, const std::string& str, const double& time_zone, std
stripComments(timezone_iso);
const double tz = (timezone_iso.empty())? time_zone : Date::parseTimeZone(timezone_iso);
if(tz==nodata) return false;
t.setDate(year, month, day, hour, minute, tz);
t.setDate(year, month, day, hour, minute, second, tz);
return true;
} else if (sscanf(c_str, "%d-%u-%u %u:%u%31s", &year, &month, &day, &hour, &minute, rest) >= 5) {
......@@ -455,7 +455,7 @@ bool convertString(Date& t, const std::string& str, const double& time_zone, std
stripComments(timezone_iso);
const double tz = (timezone_iso.empty())? time_zone : Date::parseTimeZone(timezone_iso);
if(tz==nodata) return false;
t.setDate(year, month, day, hour, minute, tz);
t.setDate(year, month, day, hour, minute, (unsigned)0, tz);
return true;
} else if (sscanf(c_str, "%d-%u-%uT%u:%u%31s", &year, &month, &day, &hour, &minute, rest) >= 5) {
......@@ -463,7 +463,7 @@ bool convertString(Date& t, const std::string& str, const double& time_zone, std
stripComments(timezone_iso);
const double tz = (timezone_iso.empty())? time_zone : Date::parseTimeZone(timezone_iso);
if(tz==nodata) return false;
t.setDate(year, month, day, hour, minute, tz);
t.setDate(year, month, day, hour, minute, (unsigned)0, tz);
return true;
} else if (sscanf(c_str, "%d-%u-%u%31s", &year, &month, &day, rest) >= 3) {
......@@ -471,7 +471,7 @@ bool convertString(Date& t, const std::string& str, const double& time_zone, std
stripComments(timezone_iso);
const double tz = (timezone_iso.empty())? time_zone : Date::parseTimeZone(timezone_iso);
if(tz==nodata) return false;
t.setDate(year, month, day, (unsigned)0, (unsigned)0, tz);
t.setDate(year, month, day, (unsigned)0, (unsigned)0, (unsigned)0, tz);
return true;
} else if (sscanf(c_str, "%u:%u%31s", &hour, &minute, rest) >= 2) {
......@@ -528,7 +528,7 @@ bool convertString(Date& t, const std::string& str, const double& time_zone, std
if(!timezone_iso.empty()) tz = Date::parseTimeZone(timezone_iso);
}
t.setDate( year, month, day, hour, minute, tz );
t.setDate( year, month, day, hour, minute, second, tz );
}
return true;
......
This diff is collapsed.
......@@ -39,8 +39,7 @@ namespace mio {
* class has to be recompiled with the proper define.
*
* Internally, the date is stored as true julian date in GMT.
* The maximal precision is 1 minute (that can be easily brought to 1 seconds if
* it would appear necessary/useful, with the limitation that leap seconds are currently not handled).
* The maximal precision is 1 second (however with the limitation that leap seconds are currently not handled).
*
* Please see Date::FORMATS for supported display formats and http://en.wikipedia.org/wiki/Julian_day for
* the various date representation definitions. The following data representation are currently supported:
......@@ -91,7 +90,11 @@ class Date {
void setDate(const Date& in_date);
void setDate(const double& julian_in, const double& in_timezone, const bool& in_dst=false);
void setDate(const int& year, const int& month, const int& day, const int& hour, const int& minute, const double& in_timezone, const bool& in_dst=false);
void setDate(const int& year, const int& month, const int& day, const int& hour, const int& minute, const int& second, const double& in_timezone, const bool& in_dst=false);
void setDate(const int& year, const int& month, const int& day, const int& hour, const int& minute, const double& second, const double& in_timezone, const bool& in_dst=false);
void setDate(const int& year, const unsigned int& month, const unsigned int& day, const unsigned int& hour, const unsigned int& minute, const double& in_timezone, const bool& in_dst=false);
void setDate(const int& year, const unsigned int& month, const unsigned int& day, const unsigned int& hour, const unsigned int& minute, const unsigned int& second, const double& in_timezone, const bool& in_dst=false);
void setDate(const int& year, const unsigned int& month, const unsigned int& day, const unsigned int& hour, const unsigned int& minute, const double& second, const double& in_timezone, const bool& in_dst=false);
void setDate(const time_t& in_time, const bool& in_dst=false);
void setModifiedJulianDate(const double& julian_in, const double& in_timezone, const bool& in_dst=false);
void setUnixDate(const time_t& in_time, const bool& in_dst=false);
......@@ -159,16 +162,16 @@ class Date {
protected:
double localToGMT(const double& in_julian) const;
double GMTToLocal(const double& in_gmt_julian) const;
double calculateJulianDate(const int& in_year, const int& in_month, const int& in_day, const int& in_hour, const int& in_minute) const;
void calculateValues(const double& i_julian, int& out_year, int& out_month, int& out_day, int& out_hour, int& out_minute) const;
double calculateJulianDate(const int& in_year, const int& in_month, const int& in_day, const int& in_hour, const int& in_minute, const double& i_second) const;
void calculateValues(const double& i_julian, int& out_year, int& out_month, int& out_day, int& out_hour, int& out_minute, int& o_second) const;
long getJulianDayNumber(const int&, const int&, const int&) const;
bool isLeapYear(const int&) const;
void plausibilityCheck(const int& in_year, const int& in_month, const int& in_day, const int& in_hour, const int& in_minute) const;
void plausibilityCheck(const int& in_year, const int& in_month, const int& in_day, const int& in_hour, const int& in_minute, const double& in_second) const;
static const double epsilon;
double timezone;
double gmt_julian;
int gmt_year, gmt_month, gmt_day, gmt_hour, gmt_minute;
int gmt_year, gmt_month, gmt_day, gmt_hour, gmt_minute, gmt_second;
bool dst;
bool undef;
};
......
......@@ -275,7 +275,9 @@ void ARCIO::read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& par
ext = MeteoGrids::getParameterName(parameter);
IOUtils::toLower(ext);
}
read2DGrid_internal(grid_out, grid2dpath_in + "/" + date.toString(Date::NUM)+"."+ext );
string dateStr( date.toString(Date::NUM) );
dateStr.erase( dateStr.size()-2, string::npos); //remove the seconds
read2DGrid_internal(grid_out, grid2dpath_in + "/" + dateStr + "." + ext );
} else {
std::string date_str = date.toString(Date::ISO);
std::replace( date_str.begin(), date_str.end(), ':', '.');
......@@ -299,17 +301,12 @@ void ARCIO::readLanduse(Grid2DObject& landuse_out)
void ARCIO::readAssimilationData(const Date& date_in, Grid2DObject& da_out)
{
int yyyy, MM, dd, hh, mm;
date_in.getDate(yyyy, MM, dd, hh, mm);
string filepath;
cfg.getValue("DAPATH", "Input", filepath);
ostringstream ss;
ss.fill('0');
ss << filepath << "/" << setw(4) << yyyy << setw(2) << MM << setw(2) << dd << setw(2) << hh << setw(2) << mm << ".sca";
read2DGrid_internal(da_out, ss.str());
string dateStr( date_in.toString(Date::NUM) );
dateStr.erase( dateStr.size()-2, string::npos); //remove the seconds
read2DGrid_internal(da_out, filepath+"/"+dateStr+".sca");
}
void ARCIO::readStationData(const Date&, std::vector<StationData>&)
......@@ -399,7 +396,9 @@ void ARCIO::write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameter
ext = MeteoGrids::getParameterName(parameter);
IOUtils::toLower(ext);
}
write2DGrid(grid_in, date.toString(Date::NUM)+"."+ext );
string dateStr( date.toString(Date::NUM) );
dateStr.erase( dateStr.size()-2, string::npos); //remove the seconds
write2DGrid(grid_in, dateStr+"."+ext );
} else {
if(parameter==MeteoGrids::DEM || parameter==MeteoGrids::AZI || parameter==MeteoGrids::SLOPE) {
write2DGrid(grid_in, MeteoGrids::getParameterName(parameter) + grid2d_ext_out);
......
This diff is collapsed.
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