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

grib: added support for start date for accum, avg, range and diff.

parent afd1d61f
......@@ -3,6 +3,10 @@
* using CGRIBEX library version 1.9.4
* Version 1.9.8 released
2019-09-09 Uwe Schulzweida
* grib: added support for start date for accum, avg, range and diff
2019-09-08 Uwe Schulzweida
* time axis: added support for datatype integer
......
......@@ -10768,7 +10768,7 @@ void encodePDS(GRIBPACK *lpds, long pdsLen, int *isec1)
else if ( ISEC1_TimeRange == 5 || ISEC1_TimeRange == 4 ||
ISEC1_TimeRange == 3 || ISEC1_TimeRange == 2 )
{
Put1Byte(0);
Put1Byte(ISEC1_TimePeriod1);
Put1Byte(ISEC1_TimePeriod2);
}
else
......
......@@ -720,7 +720,9 @@ int cgribexScanTimestep1(stream_t *streamptr)
off_t recpos = 0;
void *gribbuffer = NULL;
size_t buffersize = 0;
int leveltype = 0, level1 = 0, level2 = 0, vdate = 0, vtime = 0;
int leveltype = 0, level1 = 0, level2 = 0;
int vdate = 0, vtime = 0;
int sdate = 0, stime = 0;
DateTime datetime, datetime0 = { LONG_MIN, LONG_MIN };
unsigned recID;
int nrecs_scanned = 0;
......@@ -781,7 +783,7 @@ int cgribexScanTimestep1(stream_t *streamptr)
cgribexGetLevel(isec1, &leveltype, &level1, &level2);
gribDateTime(isec1, &vdate, &vtime);
gribDateTimeX(isec1, &vdate, &vtime, &sdate, &stime);
if ( nrecs == 0 )
{
......@@ -859,6 +861,8 @@ int cgribexScanTimestep1(stream_t *streamptr)
taxis->rtime = rtime;
taxis->vdate = (int64_t)datetime0.date;
taxis->vtime = (int)datetime0.time;
taxis->sdate = sdate;
taxis->stime = stime;
const int vlistID = streamptr->vlistID;
vlistDefTaxis(vlistID, taxisID);
......@@ -1407,8 +1411,8 @@ void cgribexDefParam(int *isec1, int param)
}
static
int cgribexDefTimerange(int tsteptype, int factor, int calendar,
int rdate, int rtime, int vdate, int vtime, int *pip1, int *pip2)
int cgribexDefTimerange(int tsteptype, int factor, int calendar, int rdate, int rtime,
int vdate, int vtime, int sdate, int stime, int *pip1, int *pip2)
{
int year, month, day, hour, minute, second;
int64_t julday1, julday2, days;
......@@ -1431,15 +1435,27 @@ int cgribexDefTimerange(int tsteptype, int factor, int calendar,
const int ip = (int) ((days*86400.0 + secs)/factor);
if ( (ip > 255) && (tsteptype == TSTEP_INSTANT) ) tsteptype = TSTEP_INSTANT3;
int ipx = 0;
if (sdate != 0 && (tsteptype == TSTEP_RANGE || tsteptype == TSTEP_AVG || tsteptype == TSTEP_ACCUM || tsteptype == TSTEP_DIFF))
{
cdiDecodeDate(sdate, &year, &month, &day);
cdiDecodeTime(stime, &hour, &minute, &second);
encode_juldaysec(calendar, year, month, day, hour, minute, second, &julday2, &secofday2);
(void) julday_sub(julday1, secofday1, julday2, secofday2, &days, &secs);
ipx = (int) ((days*86400.0 + secs)/factor);
}
// clang-format off
switch ( tsteptype )
{
case TSTEP_INSTANT: timerange = 0; ip1 = ip; ip2 = 0; break;
case TSTEP_INSTANT2: timerange = 1; ip1 = 0; ip2 = 0; break;
case TSTEP_RANGE: timerange = 2; ip1 = 0; ip2 = ip; break;
case TSTEP_AVG: timerange = 3; ip1 = 0; ip2 = ip; break;
case TSTEP_ACCUM: timerange = 4; ip1 = 0; ip2 = ip; break;
case TSTEP_DIFF: timerange = 5; ip1 = 0; ip2 = ip; break;
case TSTEP_INSTANT: timerange = 0; ip1 = ip; ip2 = 0; break;
case TSTEP_INSTANT2: timerange = 1; ip1 = 0; ip2 = 0; break;
case TSTEP_RANGE: timerange = 2; ip1 = 0; ip2 = ip; break;
case TSTEP_AVG: timerange = 3; ip1 = 0; ip2 = ip; break;
case TSTEP_ACCUM: timerange = 4; ip1 = ipx; ip2 = ip; break;
case TSTEP_DIFF: timerange = 5; ip1 = 0; ip2 = ip; break;
case TSTEP_INSTANT3:
default: timerange = 10; ip1 = ip/256; ip2 = ip%256; break;
}
......@@ -1529,15 +1545,18 @@ void cgribexDefTime(int *isec1, int vdate, int vtime, int tsteptype, int numavg,
rtime = vtime;
}
int sdate = taxisInqSdate(taxisID);
int stime = taxisInqStime(taxisID);
int factor = cgribexDefDateTime(isec1, timeunit, rdate, rtime);
int ip1 = 0, ip2 = 0;
timerange = cgribexDefTimerange(tsteptype, factor, calendar, rdate, rtime, vdate, vtime, &ip1, &ip2);
timerange = cgribexDefTimerange(tsteptype, factor, calendar, rdate, rtime, vdate, vtime, sdate, stime, &ip1, &ip2);
if ( ip2 > 0xFF && timeunit < TUNIT_YEAR )
{
timeunit++;
factor = cgribexDefDateTime(isec1, timeunit, rdate, rtime);
timerange = cgribexDefTimerange(tsteptype, factor, calendar, rdate, rtime, vdate, vtime, &ip1, &ip2);
timerange = cgribexDefTimerange(tsteptype, factor, calendar, rdate, rtime, vdate, vtime, sdate, stime, &ip1, &ip2);
}
if ( timerange == -1 || timerange == 3 )
......
......@@ -111,6 +111,8 @@ void taxisDefaultValue(taxis_t* taxisptr)
taxisptr->used = false;
taxisptr->datatype = CDI_DATATYPE_FLT64;
taxisptr->type = DefaultTimeType;
taxisptr->sdate = 0;
taxisptr->stime = 0;
taxisptr->vdate = 0;
taxisptr->vtime = 0;
taxisptr->rdate = CDI_UNDEFID;
......@@ -579,6 +581,9 @@ void taxisCopyTimestep(int taxisID2, int taxisID1)
taxisptr2->rdate = taxisptr1->rdate;
taxisptr2->rtime = taxisptr1->rtime;
*/
taxisptr2->sdate = taxisptr1->sdate;
taxisptr2->stime = taxisptr1->stime;
taxisptr2->vdate = taxisptr1->vdate;
taxisptr2->vtime = taxisptr1->vtime;
......@@ -623,6 +628,13 @@ int64_t taxisInqVdate(int taxisID)
}
int64_t taxisInqSdate(int taxisID)
{
taxis_t *taxisptr = (taxis_t *)reshGetVal(taxisID, &taxisOps);
return taxisptr->sdate;
}
void taxisInqVdateBounds(int taxisID, int64_t *vdate_lb, int64_t *vdate_ub)
{
taxis_t *taxisptr = (taxis_t *)reshGetVal(taxisID, &taxisOps);
......@@ -670,6 +682,13 @@ int taxisInqVtime(int taxisID)
}
int taxisInqStime(int taxisID)
{
taxis_t *taxisptr = (taxis_t *)reshGetVal(taxisID, &taxisOps);
return taxisptr->stime;
}
void taxisInqVtimeBounds(int taxisID, int *vtime_lb, int *vtime_ub)
{
taxis_t *taxisptr = (taxis_t *)reshGetVal(taxisID, &taxisOps);
......@@ -1360,6 +1379,8 @@ void ptaxisCopy(taxis_t *dest, taxis_t *source)
dest->used = source->used;
dest->datatype = source->datatype;
dest->type = source->type;
dest->sdate = source->sdate;
dest->stime = source->stime;
dest->vdate = source->vdate;
dest->vtime = source->vtime;
dest->rdate = source->rdate;
......
......@@ -15,6 +15,8 @@ typedef struct {
short has_bounds;
int datatype; // datatype
int type; // time type
int64_t sdate; // start date
int stime; // start time
int64_t vdate; // verification date
int vtime; // verification time
int64_t rdate; // reference date
......@@ -37,6 +39,12 @@ typedef struct {
}
taxis_t;
// taxisInqSdate: Get the start date
int64_t taxisInqSdate(int taxisID);
// taxisInqStime: Get the start time
int taxisInqStime(int taxisID);
void ptaxisInit(taxis_t* taxis);
void ptaxisCopy(taxis_t* dest, taxis_t* source);
taxis_t* taxisPtr(int taxisID);
......
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