Commit 264ee989 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

timeval2vtime: set vtime=rtime if timevalue=0 [Bug: #6496]

parent 22c6b769
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
* Version 1.7.1 released * Version 1.7.1 released
* using CGRIBEX library version 1.7.4 * using CGRIBEX library version 1.7.4
2016-02-05 Uwe Schulzweida
* timeval2vtime: set vtime=rtime if timevalue=0 [Bug: #6496]
2015-12-23 Uwe Schulzweida 2015-12-23 Uwe Schulzweida
* ZAXIS_HEIGHT: added support for units cm, dm and km * ZAXIS_HEIGHT: added support for units cm, dm and km
......
...@@ -1008,28 +1008,26 @@ void cdiEncodeTimevalue(int days, int secs, int timeunit, double *timevalue) ...@@ -1008,28 +1008,26 @@ void cdiEncodeTimevalue(int days, int secs, int timeunit, double *timevalue)
} }
} }
void timeval2vtime(double timevalue, taxis_t *taxis, int *vdate, int *vtime) void timeval2vtime(double timevalue, taxis_t *taxis, int *vdate, int *vtime)
{ {
int year, month, day, hour, minute, second; int rdate = taxis->rdate;
int rdate, rtime; int rtime = taxis->rtime;
int timeunit;
int calendar;
int julday, secofday, days, secs;
*vdate = 0;
*vtime = 0;
timeunit = (*taxis).unit;
calendar = (*taxis).calendar;
rdate = (*taxis).rdate;
rtime = (*taxis).rtime;
if ( rdate == 0 && rtime == 0 && DBL_IS_EQUAL(timevalue, 0.) ) return; if ( DBL_IS_EQUAL(timevalue, 0.) )
{
*vdate = rdate;
*vtime = rtime;
return;
}
int year, month, day, hour, minute, second;
cdiDecodeDate(rdate, &year, &month, &day); cdiDecodeDate(rdate, &year, &month, &day);
cdiDecodeTime(rtime, &hour, &minute, &second); cdiDecodeTime(rtime, &hour, &minute, &second);
int timeunit = taxis->unit;
int calendar = taxis->calendar;
if ( timeunit == TUNIT_MONTH && calendar == CALENDAR_360DAYS ) if ( timeunit == TUNIT_MONTH && calendar == CALENDAR_360DAYS )
{ {
timeunit = TUNIT_DAY; timeunit = TUNIT_DAY;
...@@ -1038,24 +1036,22 @@ void timeval2vtime(double timevalue, taxis_t *taxis, int *vdate, int *vtime) ...@@ -1038,24 +1036,22 @@ void timeval2vtime(double timevalue, taxis_t *taxis, int *vdate, int *vtime)
if ( timeunit == TUNIT_MONTH || timeunit == TUNIT_YEAR ) if ( timeunit == TUNIT_MONTH || timeunit == TUNIT_YEAR )
{ {
int nmon, dpm;
double fmon;
if ( timeunit == TUNIT_YEAR ) timevalue *= 12; if ( timeunit == TUNIT_YEAR ) timevalue *= 12;
nmon = (int) timevalue; int nmon = (int) timevalue;
fmon = timevalue - nmon; double fmon = timevalue - nmon;
month += nmon; month += nmon;
while ( month > 12 ) { month -= 12; year++; } while ( month > 12 ) { month -= 12; year++; }
while ( month < 1 ) { month += 12; year--; } while ( month < 1 ) { month += 12; year--; }
dpm = days_per_month(calendar, year, month); int dpm = days_per_month(calendar, year, month);
timeunit = TUNIT_DAY; timeunit = TUNIT_DAY;
timevalue = fmon*dpm; timevalue = fmon*dpm;
} }
int julday, secofday, days, secs;
encode_caldaysec(calendar, year, month, day, hour, minute, second, &julday, &secofday); encode_caldaysec(calendar, year, month, day, hour, minute, second, &julday, &secofday);
cdiDecodeTimevalue(timeunit, timevalue, &days, &secs); cdiDecodeTimevalue(timeunit, timevalue, &days, &secs);
......
Markdown is supported
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