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 @@
* Version 1.7.1 released
* 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
* ZAXIS_HEIGHT: added support for units cm, dm and km
......
......@@ -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)
{
int year, month, day, hour, minute, second;
int rdate, 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;
int rdate = taxis->rdate;
int 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);
cdiDecodeTime(rtime, &hour, &minute, &second);
int timeunit = taxis->unit;
int calendar = taxis->calendar;
if ( timeunit == TUNIT_MONTH && calendar == CALENDAR_360DAYS )
{
timeunit = TUNIT_DAY;
......@@ -1038,24 +1036,22 @@ void timeval2vtime(double timevalue, taxis_t *taxis, int *vdate, int *vtime)
if ( timeunit == TUNIT_MONTH || timeunit == TUNIT_YEAR )
{
int nmon, dpm;
double fmon;
if ( timeunit == TUNIT_YEAR ) timevalue *= 12;
nmon = (int) timevalue;
fmon = timevalue - nmon;
int nmon = (int) timevalue;
double fmon = timevalue - nmon;
month += nmon;
while ( month > 12 ) { 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;
timevalue = fmon*dpm;
}
int julday, secofday, days, secs;
encode_caldaysec(calendar, year, month, day, hour, minute, second, &julday, &secofday);
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