WSL/SLF GitLab Repository

Commit 2fd0bba2 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

The Date class has been revereted in order to compute year, month, day, etc...

The Date class has been revereted in order to compute year, month, day, etc since this is useful when debugging. The external includes that are used for the plugins are now included as system headers in order to avoid generating warnings for some code that we are not responsible for.
parent f3d92593
......@@ -40,13 +40,13 @@ double round(const double& x) {
namespace mio {
const int Date::daysLeapYear[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
const int Date::daysNonLeapYear[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
const double Date::DST_shift = 1.0; //in hours
const float Date::MJD_offset = 2400000.5; ///<offset between julian date and modified julian date
const float Date::Unix_offset = 2440587.5; ///<offset between julian date and Unix Epoch time
const float Date::Excel_offset = 2415018.5; ///<offset between julian date and Excel dates (note that excel invented some days...)
const float Date::Matlab_offset = 1721058.5; ///<offset between julian date and Matlab dates
const int Date::daysLeapYear[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
const int Date::daysNonLeapYear[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
const double Date::epsilon=1./(24.*3600.); ///< minimum difference between two dates. 1 second in units of days
//NOTE: For the comparison operators, we assume that dates are positive so we can bypass a call to abs()
......@@ -56,6 +56,7 @@ const double Date::epsilon=1./(24.*3600.); ///< minimum difference between two d
* @brief Default constructor: timezone is set to GMT without DST, julian date is set to 0 (meaning -4713-01-01T12:00)
*/
Date::Date() : timezone(0.), gmt_julian(0.),
gmt_year(0), gmt_month(0), gmt_day(0), gmt_hour(0), gmt_minute(0),
dst(false), undef(true)
{
}
......@@ -68,6 +69,7 @@ Date::Date() : timezone(0.), gmt_julian(0.),
*/
Date::Date(const double& julian_in, const double& in_timezone, const bool& in_dst)
: timezone(0.), gmt_julian(0.),
gmt_year(0), gmt_month(0), gmt_day(0), gmt_hour(0), gmt_minute(0),
dst(false), undef(true)
{
setDate(julian_in, in_timezone, in_dst);
......@@ -80,6 +82,7 @@ Date::Date(const double& julian_in, const double& in_timezone, const bool& in_ds
*/
Date::Date(const time_t& in_time, const bool& in_dst)
: timezone(in_dst), gmt_julian(0.),
gmt_year(0), gmt_month(0), gmt_day(0), gmt_hour(0), gmt_minute(0),
dst(false), undef(true)
{
setDate(in_time, in_dst);
......@@ -98,6 +101,7 @@ Date::Date(const time_t& in_time, const bool& in_dst)
*/
Date::Date(const int& in_year, const int& in_month, const int& in_day, const int& in_hour, const int& in_minute, const double& in_timezone, const bool& in_dst)
: timezone(in_timezone), gmt_julian(0.),
gmt_year(0), gmt_month(0), gmt_day(0), gmt_hour(0), gmt_minute(0),
dst(false), undef(true)
{
setDate(in_year, in_month, in_day, in_hour, in_minute, in_timezone, in_dst);
......@@ -179,6 +183,8 @@ void Date::setDate(const int& i_year, const int& i_month, const int& i_day, cons
//converting local julian date to GMT julian date
gmt_julian = localToGMT(local_julian);
}
//updating values to GMT, fixing potential 24:00 hour (ie: replaced by next day, 00:00)
calculateValues(gmt_julian, gmt_year, gmt_month, gmt_day, gmt_hour, gmt_minute);
undef = false;
}
......@@ -196,6 +202,7 @@ void Date::setDate(const int& year, const unsigned int& month, const unsigned in
void Date::setDate(const double& julian_in, const double& in_timezone, const bool& in_dst) {
setTimeZone(in_timezone, in_dst);
gmt_julian = localToGMT(julian_in);
calculateValues(gmt_julian, gmt_year, gmt_month, gmt_day, gmt_hour, gmt_minute);
undef = false;
}
......@@ -425,10 +432,14 @@ int Date::getYear(const bool& gmt) const {
if(undef==true)
throw UnknownValueException("Date object is undefined!", AT);
const double local_julian = (gmt)? gmt_julian : GMTToLocal(gmt_julian);
int year_out, month_out, day_out, hour_out, minute_out;
calculateValues(local_julian, year_out, month_out, day_out, hour_out, minute_out);
return year_out;
if(gmt) {
return gmt_year;
} else {
const double local_julian = GMTToLocal(gmt_julian);
int local_year, local_month, local_day, local_hour, local_minute;
calculateValues(local_julian, local_year, local_month, local_day, local_hour, local_minute);
return local_year;
}
}
/**
......@@ -442,9 +453,15 @@ void Date::getDate(int& year_out, int& month_out, int& day_out, const bool& gmt)
if(undef==true)
throw UnknownValueException("Date object is undefined!", AT);
const double local_julian = (gmt)? gmt_julian : GMTToLocal(gmt_julian);
int hour_out, minute_out;
calculateValues(local_julian, year_out, month_out, day_out, hour_out, minute_out);
if(gmt) {
year_out = gmt_year;
month_out = gmt_month;
day_out = gmt_day;
} else {
const double local_julian = GMTToLocal(gmt_julian);
int local_hour, local_minute;
calculateValues(local_julian, year_out, month_out, day_out, local_hour, local_minute);
}
}
/**
......@@ -459,9 +476,16 @@ void Date::getDate(int& year_out, int& month_out, int& day_out, int& hour_out, c
if(undef==true)
throw UnknownValueException("Date object is undefined!", AT);
const double local_julian = (gmt)? gmt_julian : GMTToLocal(gmt_julian);
int minute_out;
calculateValues(local_julian, year_out, month_out, day_out, hour_out, minute_out);
if(gmt) {
year_out = gmt_year;
month_out = gmt_month;
day_out = gmt_day;
hour_out = gmt_hour;
} else {
const double local_julian = GMTToLocal(gmt_julian);
int local_minute;
calculateValues(local_julian, year_out, month_out, day_out, hour_out, local_minute);
}
}
/**
......@@ -477,8 +501,16 @@ void Date::getDate(int& year_out, int& month_out, int& day_out, int& hour_out, i
if(undef==true)
throw UnknownValueException("Date object is undefined!", AT);
const double local_julian = (gmt)? gmt_julian : GMTToLocal(gmt_julian);
calculateValues(local_julian, year_out, month_out, day_out, hour_out, minute_out);
if(gmt) {
year_out = gmt_year;
month_out = gmt_month;
day_out = gmt_day;
hour_out = gmt_hour;
minute_out = gmt_minute;
} else {
const double local_julian = GMTToLocal(gmt_julian);
calculateValues(local_julian, year_out, month_out, day_out, hour_out, minute_out);
}
}
/**
......@@ -491,16 +523,17 @@ int Date::getJulianDayNumber(const bool& gmt) const {
if(undef==true)
throw UnknownValueException("Date object is undefined!", AT);
const double local_julian = (gmt)? gmt_julian : GMTToLocal(gmt_julian);
int year_out, month_out, day_out, hour_out, minute_out;
calculateValues(local_julian, year_out, month_out, day_out, hour_out, minute_out);
const double in_day_offset = 1./24.*((double)hour_out+1./60.*(double)minute_out) - 0.5;
const double first_day_of_year = static_cast<double>(getJulianDayNumber(year_out, 1, 1)) + in_day_offset;
return (int)(local_julian - first_day_of_year + 1);
//HACK: why not using getJulianDayNumber(year, month, day)?
if(gmt) {
const double first_day_of_year = getJulianDayNumber(gmt_year, 1, 1);
return (int)(gmt_julian - first_day_of_year + 1);
} else {
const double local_julian = GMTToLocal(gmt_julian);
int local_year, local_month, local_day, local_hour, local_minute;
calculateValues(local_julian, local_year, local_month, local_day, local_hour, local_minute);
const double in_day_offset = 1./24.*((double)local_hour+1./60.*(double)local_minute) - 0.5;
const double first_day_of_year = static_cast<double>(getJulianDayNumber(local_year, 1, 1)) + in_day_offset;
return (int)(local_julian - first_day_of_year + 1);
}
}
/**
......@@ -556,6 +589,7 @@ Date& Date::operator+=(const Date& indate) {
return *this;
}
gmt_julian += indate.gmt_julian;
calculateValues(gmt_julian, gmt_year, gmt_month, gmt_day, gmt_hour, gmt_minute);
return *this;
}
......@@ -565,12 +599,14 @@ Date& Date::operator-=(const Date& indate) {
return *this;
}
gmt_julian -= indate.gmt_julian;
calculateValues(gmt_julian, gmt_year, gmt_month, gmt_day, gmt_hour, gmt_minute);
return *this;
}
Date& Date::operator+=(const double& indate) {
if(undef==false) {
gmt_julian += indate;
calculateValues(gmt_julian, gmt_year, gmt_month, gmt_day, gmt_hour, gmt_minute);
}
return *this;
}
......@@ -578,6 +614,7 @@ Date& Date::operator+=(const double& indate) {
Date& Date::operator-=(const double& indate) {
if(undef==false) {
gmt_julian -= indate;
calculateValues(gmt_julian, gmt_year, gmt_month, gmt_day, gmt_hour, gmt_minute);
}
return *this;
}
......@@ -585,6 +622,7 @@ Date& Date::operator-=(const double& indate) {
Date& Date::operator*=(const double& value) {
if(undef==false) {
gmt_julian *= value;
calculateValues(gmt_julian, gmt_year, gmt_month, gmt_day, gmt_hour, gmt_minute);
}
return *this;
}
......@@ -592,6 +630,7 @@ Date& Date::operator*=(const double& value) {
Date& Date::operator/=(const double& value) {
if(undef==false) {
gmt_julian /= value;
calculateValues(gmt_julian, gmt_year, gmt_month, gmt_day, gmt_hour, gmt_minute);
}
return *this;
}
......@@ -740,13 +779,23 @@ std::ostream& operator<<(std::ostream &os, const Date &date) {
*/
const string Date::toString(FORMATS type, const bool& gmt) const
{//the date are displayed in LOCAL timezone (more user friendly)
int year_out, month_out, day_out, hour_out, minute_out;
double julian_out;
if(undef==true)
throw UnknownValueException("Date object is undefined!", AT);
const double julian_out = (gmt)? gmt_julian : GMTToLocal(gmt_julian);
int year_out, month_out, day_out, hour_out, minute_out;
calculateValues(julian_out, year_out, month_out, day_out, hour_out, minute_out);
if(gmt) {
julian_out = gmt_julian;
year_out = gmt_year;
month_out = gmt_month;
day_out = gmt_day;
hour_out = gmt_hour;
minute_out = gmt_minute;
} else {
julian_out = GMTToLocal(gmt_julian);
calculateValues(julian_out, year_out, month_out, day_out, hour_out, minute_out);
}
stringstream tmpstr;
if(type==ISO) {
......@@ -802,9 +851,10 @@ void Date::calculateValues(const double& i_julian, int& o_year, int& o_month, in
const double rnd_factor = (60.*24.);
const double tmp_julian = round(i_julian*rnd_factor) / rnd_factor;
long t1;
const long julday = (long) floor(tmp_julian+0.5);
long t1 = julday + 68569L;
t1 = julday + 68569L;
const long t2 = 4L * t1 / 146097L;
t1 = t1 - ( 146097L * t2 + 3L ) / 4L;
const long yr = 4000L * ( t1 + 1L ) / 1461001L;
......@@ -828,8 +878,9 @@ void Date::calculateValues(const double& i_julian, int& o_year, int& o_month, in
bool Date::isLeapYear(const int& i_year) const
{
const long jd1 = getJulianDayNumber( i_year, 2, 28 );
const long jd2 = getJulianDayNumber( i_year, 3, 1 );
long jd1, jd2;
jd1 = getJulianDayNumber( i_year, 2, 28 );
jd2 = getJulianDayNumber( i_year, 3, 1 );
return ( (jd2-jd1) > 1 );
}
......@@ -896,10 +947,21 @@ void Date::Serialize(POPBuffer &buf, bool pack)
buf.Pack(&timezone,1);
buf.Pack(&dst,1);
buf.Pack(&gmt_julian,1);
buf.Pack(&gmt_year,1);
buf.Pack(&gmt_month,1);
buf.Pack(&gmt_day,1);
buf.Pack(&gmt_hour,1);
buf.Pack(&gmt_minute,1);
buf.Pack(&undef,1);
} else {
buf.UnPack(&timezone,1);
buf.UnPack(&dst,1);
buf.UnPack(&gmt_julian,1);
buf.UnPack(&gmt_year,1);
buf.UnPack(&gmt_month,1);
buf.UnPack(&gmt_day,1);
buf.UnPack(&gmt_hour,1);
buf.UnPack(&gmt_minute,1);
buf.UnPack(&undef,1);
}
}
......
......@@ -85,13 +85,13 @@ class Date {
CLOSEST ///< rounding toward closest
} RND;
static const int daysLeapYear[];
static const int daysNonLeapYear[];
static const double DST_shift;
static const float MJD_offset;
static const float Unix_offset;
static const float Excel_offset;
static const float Matlab_offset;
static const int daysLeapYear[];
static const int daysNonLeapYear[];
Date();
Date(const double& julian_in, const double& in_timezone, const bool& in_dst=false);
......@@ -175,6 +175,7 @@ class Date {
static const double epsilon;
double timezone;
double gmt_julian;
int gmt_year, gmt_month, gmt_day, gmt_hour, gmt_minute;
bool dst;
bool undef;
};
......
......@@ -14,14 +14,14 @@ ENDIF(PLUGIN_ARPSIO)
IF(PLUGIN_BORMAIO)
FIND_PACKAGE(LibXML++ REQUIRED)
INCLUDE_DIRECTORIES(${LibXML++_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(SYSTEM ${LibXML++_INCLUDE_DIRS})
SET(plugin_libs ${plugin_libs} ${LibXML++_LIBRARIES})
SET(plugins_sources ${plugins_sources} plugins/BormaIO.cc)
ENDIF(PLUGIN_BORMAIO)
IF(PLUGIN_COSMOXMLIO)
FIND_PACKAGE(LibXML++ REQUIRED)
INCLUDE_DIRECTORIES(${LibXML++_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(SYSTEM ${LibXML++_INCLUDE_DIRS})
SET(plugin_libs ${plugin_libs} ${LibXML++_LIBRARIES})
SET(plugins_sources ${plugins_sources} plugins/CosmoXMLIO.cc)
ENDIF(PLUGIN_COSMOXMLIO)
......@@ -32,7 +32,7 @@ ENDIF(PLUGIN_GRASSIO)
IF(PLUGIN_GRIBIO)
FIND_PACKAGE(GribApi REQUIRED)
INCLUDE_DIRECTORIES(${GribApi_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(SYSTEM ${GribApi_INCLUDE_DIRS})
SET(plugin_libs ${plugin_libs} ${GribApi_LIBRARIES})
SET(plugins_sources ${plugins_sources} plugins/GRIBIO.cc)
ENDIF(PLUGIN_GRIBIO)
......@@ -65,7 +65,7 @@ ENDIF(PLUGIN_GSNIO)
IF(PLUGIN_IMISIO)
FIND_PACKAGE(OCCI REQUIRED)
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${OCCI_INCLUDE_DIR})
INCLUDE_DIRECTORIES(SYSTEM ${OCCI_INCLUDE_DIR})
SET(plugin_libs ${plugin_libs} ${OCCI_LIBRARIES})
SET(plugins_sources ${plugins_sources} plugins/ImisIO.cc)
ENDIF(PLUGIN_IMISIO)
......@@ -76,7 +76,7 @@ ENDIF(PLUGIN_PGMIO)
IF(PLUGIN_PNGIO)
FIND_PACKAGE(PNG REQUIRED)
INCLUDE_DIRECTORIES(${PNG_INCLUDE_DIR})
INCLUDE_DIRECTORIES(SYSTEM ${PNG_INCLUDE_DIR})
SET(plugin_libs ${plugin_libs} ${PNG_LIBRARY})
SET(plugins_sources ${plugins_sources} plugins/PNGIO.cc)
ENDIF(PLUGIN_PNGIO)
......
......@@ -69,12 +69,14 @@ const double CosmoXMLIO::in_tz = 0.; //Plugin specific timezone
const double CosmoXMLIO::out_tz = 0.; //Plugin specific time zone
const std::string CosmoXMLIO::dflt_extension = ".xml";
CosmoXMLIO::CosmoXMLIO(const std::string& configfile) : cfg(configfile)
CosmoXMLIO::CosmoXMLIO(const std::string& configfile)
: cfg(configfile), plugin_nodata(-999.), coordin(), coordinparam(), coordout(), coordoutparam()
{
IOUtils::getProjectionParameters(cfg, coordin, coordinparam, coordout, coordoutparam);
}
CosmoXMLIO::CosmoXMLIO(const Config& cfgreader) : cfg(cfgreader)
CosmoXMLIO::CosmoXMLIO(const Config& cfgreader)
: cfg(cfgreader), plugin_nodata(-999.), coordin(), coordinparam(), coordout(), coordoutparam()
{
IOUtils::getProjectionParameters(cfg, coordin, coordinparam, coordout, coordoutparam);
}
......
......@@ -79,13 +79,17 @@ namespace mio {
* THE SOFTWARE IN THIS PRODUCT WAS IN PART PROVIDED BY GENIVIA INC AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
GSNIO::GSNIO(const std::string& configfile) : cfg(configfile)
GSNIO::GSNIO(const std::string& configfile)
: gsn(), cfg(configfile), vecStationName(), vecMeta(), coordin(), coordinparam(), coordout(), coordoutparam(),
endpoint(), hostname(), port(), userid(), passwd(), proxyport(-1), default_timezone(1.)
{
IOUtils::getProjectionParameters(cfg, coordin, coordinparam, coordout, coordoutparam);
initGSNConnection();
}
GSNIO::GSNIO(const Config& cfgreader) : cfg(cfgreader)
GSNIO::GSNIO(const Config& cfgreader)
: gsn(), cfg(cfgreader), vecStationName(), vecMeta(), coordin(), coordinparam(), coordout(), coordoutparam(),
endpoint(), hostname(), port(), userid(), passwd(), proxyport(-1), default_timezone(1.)
{
IOUtils::getProjectionParameters(cfg, coordin, coordinparam, coordout, coordoutparam);
initGSNConnection();
......@@ -99,13 +103,8 @@ void GSNIO::initGSNConnection(){
cfg.getValue("TIME_ZONE", "Input", tmp_timezone, Config::nothrow);
if (tmp_timezone != ""){
IOUtils::convertString(default_timezone, tmp_timezone);
} else {
default_timezone = 1.0;
}
endpoint = hostname = port = userid = passwd = "";
proxyport = -1;
//soap_init(&gsn);
//soap_init2(&gsn, SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE);
......
......@@ -95,9 +95,9 @@ class GSNIO : public IOInterface {
const Config& cfg;
std::vector<std::string> vecStationName;
std::vector<StationData> vecMeta;
std::string coordin, coordinparam, coordout, coordoutparam; //projection parameters
std::string endpoint, hostname, port, userid, passwd; ///< Variables for proxy configuration
int proxyport; ///< Variable for proxy configuration
std::string coordin, coordinparam, coordout, coordoutparam; //projection parameters
double default_timezone;
};
......
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