Commit 8158ea4c authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added support for GRIB time unit 3hours and 6hours

parent 25945609
2010-04-09 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* added support for GRIB time unit 3hours and 6hours [request: Jaison-Thomas Ambadan]
2010-04-01 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* vlistMerge: added support to merge levels
......
......@@ -155,6 +155,9 @@ extern "C" {
#define TUNIT_MONTH 5
#define TUNIT_YEAR 6
#define TUNIT_QUARTER 7
#define TUNIT_3HOURS 8
#define TUNIT_6HOURS 9
#define TUNIT_12HOURS 10
/* TSTEP types */
......
......@@ -189,6 +189,9 @@ int cgribexGetTimeUnit(int *isec1)
case ISEC1_TABLE4_MINUTE: timeunit = TUNIT_MINUTE; break;
case ISEC1_TABLE4_QUARTER: timeunit = TUNIT_QUARTER; break;
case ISEC1_TABLE4_HOUR: timeunit = TUNIT_HOUR; break;
case ISEC1_TABLE4_3HOURS: timeunit = TUNIT_3HOURS; break;
case ISEC1_TABLE4_6HOURS: timeunit = TUNIT_6HOURS; break;
case ISEC1_TABLE4_12HOURS: timeunit = TUNIT_12HOURS; break;
case ISEC1_TABLE4_DAY: timeunit = TUNIT_DAY; break;
default:
if ( lprint )
......@@ -1598,6 +1601,9 @@ int cgribexDefDateTime(int *isec1, int timeunit, int date, int time)
case TUNIT_MINUTE: factor = 60; ISEC1_TimeUnit = ISEC1_TABLE4_MINUTE; break;
case TUNIT_QUARTER: factor = 900; ISEC1_TimeUnit = ISEC1_TABLE4_QUARTER; break;
case TUNIT_HOUR: factor = 3600; ISEC1_TimeUnit = ISEC1_TABLE4_HOUR; break;
case TUNIT_3HOURS: factor = 10800; ISEC1_TimeUnit = ISEC1_TABLE4_3HOURS; break;
case TUNIT_6HOURS: factor = 21600; ISEC1_TimeUnit = ISEC1_TABLE4_6HOURS; break;
case TUNIT_12HOURS: factor = 43200; ISEC1_TimeUnit = ISEC1_TABLE4_12HOURS; break;
case TUNIT_DAY: factor = 86400; ISEC1_TimeUnit = ISEC1_TABLE4_DAY; break;
default: factor = 3600; ISEC1_TimeUnit = ISEC1_TABLE4_HOUR; break;
}
......
......@@ -180,26 +180,26 @@ int gribapiGetTimeUnits(grib_handle *gh)
{
static char func[] = "gribapiGetTimeUnits";
int timeunits = -1;
int stepunits;
long lpar;
size_t len = 8;
char stepunits[8];
static int lprint = TRUE;
GRIB_CHECK(grib_get_long(gh, "stepUnits", &lpar), 0);
stepunits = (int) lpar;
switch ( stepunits )
GRIB_CHECK(grib_get_string(gh, "stepUnits", stepunits, &len), 0);
if ( memcmp(stepunits, "s", len-1) == 0 ) timeunits = TUNIT_SECOND;
else if ( memcmp(stepunits, "m", len-1) == 0 ) timeunits = TUNIT_MINUTE;
else if ( memcmp(stepunits, "h", len-1) == 0 ) timeunits = TUNIT_HOUR;
else if ( memcmp(stepunits, "3h", len-1) == 0 ) timeunits = TUNIT_3HOURS;
else if ( memcmp(stepunits, "6h", len-1) == 0 ) timeunits = TUNIT_6HOURS;
else if ( memcmp(stepunits, "12h", len-1) == 0 ) timeunits = TUNIT_12HOURS;
else if ( memcmp(stepunits, "D", len-1) == 0 ) timeunits = TUNIT_DAY;
else if ( memcmp(stepunits, "M", len-1) == 0 ) timeunits = TUNIT_MONTH;
else if ( memcmp(stepunits, "Y", len-1) == 0 ) timeunits = TUNIT_YEAR;
else if ( lprint )
{
case 0: timeunits = TUNIT_MINUTE; break;
case 1: timeunits = TUNIT_HOUR; break;
case 2: timeunits = TUNIT_DAY; break;
case 3: timeunits = TUNIT_MONTH; break;
case 4: timeunits = TUNIT_YEAR; break;
default:
if ( lprint )
{
Message(func, "Step units %d unsupported", stepunits);
lprint = FALSE;
}
Message(func, "Step units >%s< unsupported!", stepunits);
lprint = FALSE;
}
return (timeunits);
......@@ -1800,20 +1800,26 @@ static
int gribapiDefDateTime(grib_handle *gh, int timeunit, int date, int time)
{
int factor = 1;
int stepunits = 0;
char stepunits[8];
size_t len;
GRIB_CHECK(grib_set_long(gh, "dataDate", date), 0);
GRIB_CHECK(grib_set_long(gh, "dataTime", time/100), 0);
switch (timeunit)
{
case TUNIT_MINUTE: factor = 60; stepunits = 0; break;
case TUNIT_HOUR: factor = 3600; stepunits = 1; break;
case TUNIT_DAY: factor = 86400; stepunits = 2; break;
default: factor = 3600; stepunits = 1; break;
case TUNIT_SECOND: factor = 1; strcpy(stepunits, "s"); break;
case TUNIT_MINUTE: factor = 60; strcpy(stepunits, "m"); break;
case TUNIT_HOUR: factor = 3600; strcpy(stepunits, "h"); break;
case TUNIT_3HOURS: factor = 10800; strcpy(stepunits, "3h"); break;
case TUNIT_6HOURS: factor = 21600; strcpy(stepunits, "6h"); break;
case TUNIT_12HOURS: factor = 43200; strcpy(stepunits, "12h"); break;
case TUNIT_DAY: factor = 86400; strcpy(stepunits, "D"); break;
default: factor = 3600; strcpy(stepunits, "h"); break;
}
GRIB_CHECK(grib_set_long(gh, "stepUnits", stepunits), 0);
len = strlen(stepunits)+1;
GRIB_CHECK(grib_set_string(gh, "stepUnits", stepunits, &len), 0);
return (factor);
}
......
......@@ -25,6 +25,9 @@ char *Timeunits[] = {
"months",
"years",
"quarter",
"3hours",
"6hours",
"12hours",
};
......@@ -54,6 +57,12 @@ void taxis_defaults(void)
DefaultTimeUnit = TUNIT_MINUTE;
else if ( strcmp(timeunit, "hour") == 0 )
DefaultTimeUnit = TUNIT_HOUR;
else if ( strcmp(timeunit, "3hours") == 0 )
DefaultTimeUnit = TUNIT_3HOURS;
else if ( strcmp(timeunit, "6hours") == 0 )
DefaultTimeUnit = TUNIT_6HOURS;
else if ( strcmp(timeunit, "12hours") == 0 )
DefaultTimeUnit = TUNIT_12HOURS;
else if ( strcmp(timeunit, "day") == 0 )
DefaultTimeUnit = TUNIT_DAY;
else if ( strcmp(timeunit, "month") == 0 )
......@@ -978,15 +987,15 @@ void cdiEncodeTimevalue(int days, int secs, int timeunit, double *timevalue)
{
*timevalue = days*86400. + secs;
}
else if ( timeunit == TUNIT_MINUTE )
else if ( timeunit == TUNIT_MINUTE ||
timeunit == TUNIT_QUARTER )
{
*timevalue = days*1440. + secs/60.;
}
else if ( timeunit == TUNIT_QUARTER )
{
*timevalue = days*1440. + secs/60.;
}
else if ( timeunit == TUNIT_HOUR )
else if ( timeunit == TUNIT_HOUR ||
timeunit == TUNIT_3HOURS ||
timeunit == TUNIT_6HOURS ||
timeunit == TUNIT_12HOURS )
{
*timevalue = days*24. + secs/3600.;
}
......
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