Commit 615f0678 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added taxisDefForecastPeriod()

parent 1f78a106
......@@ -954,6 +954,9 @@ int taxisInqTunit(int taxisID);
void taxisDefForecastTunit(int taxisID, int tunit);
int taxisInqForecastTunit(int taxisID);
void taxisDefForecastPeriod(int taxisID, double fc_period);
double taxisInqForecastPeriod(int taxisID);
void taxisDefNumavg(int taxisID, int numavg);
int taxisInqType(int taxisID);
......
......@@ -7730,18 +7730,25 @@ int cdfInqTimestep(stream_t * streamptr, int tsID)
if ( nctimeboundsid != UNDEFID )
{
size_t start[2], count[2];
start[0] = tsID; count[0] = 1; start[1] = 0; count[1] = 1;
start[0] = index; count[0] = 1; start[1] = 0; count[1] = 1;
cdf_get_vara_double(fileID, nctimeboundsid, start, count, &timevalue);
if ( timevalue >= NC_FILL_DOUBLE || timevalue < -NC_FILL_DOUBLE ) timevalue = 0;
cdiDecodeTimeval(timevalue, taxis, &taxis->vdate_lb, &taxis->vtime_lb);
start[0] = tsID; count[0] = 1; start[1] = 1; count[1] = 1;
start[0] = index; count[0] = 1; start[1] = 1; count[1] = 1;
cdf_get_vara_double(fileID, nctimeboundsid, start, count, &timevalue);
if ( timevalue >= NC_FILL_DOUBLE || timevalue < -NC_FILL_DOUBLE ) timevalue = 0;
cdiDecodeTimeval(timevalue, taxis, &taxis->vdate_ub, &taxis->vtime_ub);
}
int leadtimeid = streamptr->basetime.leadtimeid;
if ( leadtimeid != UNDEFID )
{
cdf_get_var1_double(fileID, leadtimeid, &index, &timevalue);
cdiSetForecastPeriod(timevalue, taxis);
}
}
}
......
......@@ -117,16 +117,17 @@ void taxisDefaultValue(taxis_t* taxisptr)
taxisptr->ftime = 0;
taxisptr->calendar = cdiDefaultCalendar;
taxisptr->unit = DefaultTimeUnit;
taxisptr->fc_unit = DefaultTimeUnit;
taxisptr->numavg = 0;
taxisptr->climatology = FALSE;
taxisptr->has_bounds = FALSE;
taxisptr->vdate_lb = 0;
taxisptr->vtime_lb = 0;
taxisptr->vdate_ub = 0;
taxisptr->vtime_ub = 0;
taxisptr->fc_unit = DefaultTimeUnit;
taxisptr->fc_period = 0;
taxisptr->name = NULL;
taxisptr->longname = NULL;
taxisptr->climatology = FALSE;
}
static taxis_t *
......@@ -529,6 +530,22 @@ void taxisDefForecastTunit(int taxisID, int unit)
}
void taxisDefForecastPeriod(int taxisID, double fc_period)
{
if ( reshGetStatus ( taxisID, &taxisOps ) == RESH_CLOSED )
{
Warning("%s", "Operation not executed.");
return;
}
taxis_t *taxisptr = ( taxis_t * ) reshGetVal ( taxisID, &taxisOps );
taxis_check_ptr(__func__, taxisptr);
taxisptr->fc_period = fc_period;
}
void taxisDefNumavg(int taxisID, int numavg)
{
if ( reshGetStatus ( taxisID, &taxisOps ) == RESH_CLOSED )
......@@ -894,6 +911,16 @@ int taxisInqForecastTunit(int taxisID)
}
double taxisInqForecastPeriod(int taxisID)
{
taxis_t *taxisptr = ( taxis_t * ) reshGetVal ( taxisID, &taxisOps );
taxis_check_ptr(__func__, taxisptr);
return (taxisptr->fc_period);
}
int taxisInqNumavg(int taxisID)
{
taxis_t *taxisptr = ( taxis_t * ) reshGetVal ( taxisID, &taxisOps );
......@@ -1241,6 +1268,66 @@ void splitTimevalue(double timevalue, int timeunit, int *date, int *time)
}
void cdiSetForecastPeriod(double timevalue, taxis_t *taxis)
{
int year, month, day, hour, minute, second;
int vdate, vtime;
int timeunit;
int calendar;
int julday, secofday, days, secs;
(*taxis).fc_period = timevalue;
timeunit = (*taxis).fc_unit;
calendar = (*taxis).calendar;
vdate = (*taxis).vdate;
vtime = (*taxis).vtime;
if ( vdate == 0 && vtime == 0 && DBL_IS_EQUAL(timevalue, 0.) ) return;
cdiDecodeDate(vdate, &year, &month, &day);
cdiDecodeTime(vtime, &hour, &minute, &second);
if ( timeunit == TUNIT_MONTH && calendar == CALENDAR_360DAYS )
{
timeunit = TUNIT_DAY;
timevalue *= 30;
}
if ( timeunit == TUNIT_MONTH || timeunit == TUNIT_YEAR )
{
int nmon, dpm;
double fmon;
if ( timeunit == TUNIT_YEAR ) timevalue *= 12;
nmon = (int) timevalue;
fmon = timevalue - nmon;
month -= nmon;
while ( month > 12 ) { month -= 12; year++; }
while ( month < 1 ) { month += 12; year--; }
dpm = days_per_month(calendar, year, month);
timeunit = TUNIT_DAY;
timevalue = fmon*dpm;
}
encode_caldaysec(calendar, year, month, day, hour, minute, second, &julday, &secofday);
cdiDecodeTimevalue(timeunit, timevalue, &days, &secs);
julday_add(-days, -secs, &julday, &secofday);
decode_caldaysec(calendar, julday, secofday, &year, &month, &day, &hour, &minute, &second);
(*taxis).fdate = cdiEncodeDate(year, month, day);
(*taxis).ftime = cdiEncodeTime(hour, minute, second);
}
void cdiDecodeTimeval(double timevalue, taxis_t *taxis, int *date, int *time)
{
if ( taxis->type == TAXIS_ABSOLUTE )
......@@ -1310,14 +1397,15 @@ void ptaxisCopy(taxis_t *dest, taxis_t *source)
dest->ftime = source->ftime;
dest->calendar = source->calendar;
dest->unit = source->unit;
dest->fc_unit = source->fc_unit;
dest->numavg = source->numavg;
dest->climatology = source->climatology;
dest->has_bounds = source->has_bounds;
dest->vdate_lb = source->vdate_lb;
dest->vtime_lb = source->vtime_lb;
dest->vdate_ub = source->vdate_ub;
dest->vtime_ub = source->vtime_ub;
dest->climatology = source->climatology;
dest->fc_unit = source->fc_unit;
dest->fc_period = source->fc_period;
reshUnlock ();
}
......@@ -1348,7 +1436,6 @@ taxisPrintKernel(taxis_t * taxisptr, FILE * fp)
fprintf ( fp, "ftime = %d\n", taxisptr->ftime );
fprintf ( fp, "calendar = %d\n", taxisptr->calendar );
fprintf ( fp, "unit = %d\n", taxisptr->unit );
fprintf ( fp, "fc_unit = %d\n", taxisptr->fc_unit );
fprintf ( fp, "numavg = %d\n", taxisptr->numavg );
fprintf ( fp, "climatology = %d\n", taxisptr->climatology );
fprintf ( fp, "has_bounds = %d\n", taxisptr->has_bounds );
......@@ -1356,6 +1443,8 @@ taxisPrintKernel(taxis_t * taxisptr, FILE * fp)
fprintf ( fp, "vtime_lb = %d\n", vtime_lb );
fprintf ( fp, "vdate_ub = %d\n", vdate_ub );
fprintf ( fp, "vtime_ub = %d\n", vtime_ub );
fprintf ( fp, "fc_unit = %d\n", taxisptr->fc_unit );
fprintf ( fp, "fc_period = %g\n", taxisptr->fc_period );
fprintf ( fp, "\n");
}
......
......@@ -19,7 +19,6 @@ typedef struct {
int ftime; // forecast reference time
int calendar;
int unit; // time unit
int fc_unit; // forecast time unit
int numavg;
int climatology;
int has_bounds;
......@@ -27,6 +26,8 @@ typedef struct {
int vtime_lb; // lower bounds of vtime
int vdate_ub; // upper bounds of vdate
int vtime_ub; // upper bounds of vtime
int fc_unit; // forecast time unit
double fc_period; // forecast time period
char* name;
char* longname;
}
......@@ -35,6 +36,7 @@ taxis_t;
void ptaxisInit(taxis_t* taxis);
void ptaxisCopy(taxis_t* dest, taxis_t* source);
taxis_t* taxisPtr(int taxisID);
void cdiSetForecastPeriod(double timevalue, taxis_t *taxis);
void cdiDecodeTimeval(double timevalue, taxis_t* taxis, int* date, int* time);
double cdiEncodeTimeval(int date, int time, taxis_t* taxis);
void timeval2vtime(double timevalue, taxis_t* taxis, int* vdate, int* vtime);
......
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