Commit a5c1ad78 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

taxis.c: add support for non integer timevalues (TUNIT_MONTH/CALENDAR_360DAYS)

parent 960d5fb1
......@@ -6,6 +6,7 @@
* update: echam5 code table
* fileOpen: add O_BINARY if available [report: Klaus Wyser]
* file.c: _WIN32 support
* taxis.c: add support for non integer timevalues (TUNIT_MONTH/CALENDAR_360DAYS)
* stream_cdf: add ICON grid support
* stream_srv: add support for GRID_CELL (bug fix)
* cdfInqContents: support of lon/lat units radian
......
......@@ -13,7 +13,7 @@
void basetimeInit(BaseTime *basetime)
{
static char func[] = "cdiInitTime";
static char func[] = "basetimeInit";
if ( basetime == NULL )
Error(func, "Internal problem! Basetime not allocated.");
......
......@@ -921,6 +921,12 @@ void timeval2vtime(double timevalue, TAXIS *taxis, int *vdate, int *vtime)
decode_date(rdate, &year, &month, &day);
decode_time(rtime, &hour, &minute);
if ( timeunit == TUNIT_MONTH && calendar == CALENDAR_360DAYS )
{
timeunit = TUNIT_DAY;
timevalue *= 30;
}
if ( timeunit == TUNIT_MONTH || timeunit == TUNIT_YEAR )
{
if ( timeunit == TUNIT_YEAR ) timevalue *= 12;
......@@ -959,6 +965,7 @@ double vtime2timeval(int vdate, int vtime, TAXIS *taxis)
int rdate, rtime;
double value;
int timeunit;
int timeunit0;
int calendar;
int julday1, secofday1, julday2, secofday2, days, secs;
......@@ -981,6 +988,13 @@ double vtime2timeval(int vdate, int vtime, TAXIS *taxis)
decode_date(vdate, &year, &month, &day);
decode_time(vtime, &hour, &minute);
timeunit0 = timeunit;
if ( timeunit == TUNIT_MONTH && calendar == CALENDAR_360DAYS )
{
timeunit = TUNIT_DAY;
}
if ( timeunit == TUNIT_MONTH || timeunit == TUNIT_YEAR )
{
value = (year-ryear)*12 - rmonth + month;
......@@ -995,6 +1009,11 @@ double vtime2timeval(int vdate, int vtime, TAXIS *taxis)
encode_timevalue(days, secs, timeunit, &value);
}
if ( timeunit0 == TUNIT_MONTH && calendar == CALENDAR_360DAYS )
{
value /= 30;
}
return (value);
}
......
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