Commit 4c550408 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

expr: added function cdeltat().

parent adf05b84
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
* Using CDI library version 1.9.3 * Using CDI library version 1.9.3
* Version 1.9.3 release * Version 1.9.3 release
2018-01-18 Uwe Schulzweida
* expr: added function ctimestep(), cdate(), ctime(), cdeltat()
2018-01-15 Uwe Schulzweida 2018-01-15 Uwe Schulzweida
* uvDestag: target grid undefined in output (bug fix) * uvDestag: target grid undefined in output (bug fix)
......
...@@ -569,15 +569,32 @@ void *Expr(void *argument) ...@@ -569,15 +569,32 @@ void *Expr(void *argument)
int streamID2 = pstreamOpenWrite(cdoStreamName(1), cdoFiletype()); int streamID2 = pstreamOpenWrite(cdoStreamName(1), cdoFiletype());
pstreamDefVlist(streamID2, vlistID2); pstreamDefVlist(streamID2, vlistID2);
int vdate0 = 0, vtime0 = 0;
int calendar = taxisInqCalendar(taxisID1);
int nrecs; int nrecs;
int tsID = 0; int tsID = 0;
while ( (nrecs = pstreamInqTimestep(streamID1, tsID)) ) while ( (nrecs = pstreamInqTimestep(streamID1, tsID)) )
{ {
int vdate = taxisInqVdate(taxisID1); int vdate = taxisInqVdate(taxisID1);
int vtime = taxisInqVtime(taxisID1); int vtime = taxisInqVtime(taxisID1);
double jdelta = 0;
if ( tsID )
{
juldate_t juldate0 = juldate_encode(calendar, vdate0, vtime0);
juldate_t juldate = juldate_encode(calendar, vdate, vtime);
jdelta = juldate_to_seconds(juldate_sub(juldate, juldate0));
}
vdate0 = vdate;
vtime0 = vtime;
params[vartsID].data[0] = tsID+1; params[vartsID].data[0] = tsID+1;
params[vartsID].data[1] = vdate; params[vartsID].data[1] = vdate;
params[vartsID].data[2] = vtime; params[vartsID].data[2] = vtime;
params[vartsID].data[3] = jdelta;
taxisCopyTimestep(taxisID2, taxisID1); taxisCopyTimestep(taxisID2, taxisID1);
......
...@@ -39,17 +39,12 @@ int iunits[] = {1, 60, 3600, 86400, 1, 12}; ...@@ -39,17 +39,12 @@ int iunits[] = {1, 60, 3600, 86400, 1, 12};
void getTimeInc(double jdelta, int vdate0, int vdate1, int *incperiod, int *incunit) void getTimeInc(double jdelta, int vdate0, int vdate1, int *incperiod, int *incunit)
{ {
int lperiod;
int sign = 1;
*incperiod = 0; *incperiod = 0;
*incunit = 0; *incunit = 0;
if ( jdelta < 0 ) int lperiod = (jdelta < 0) ? (int)(jdelta-0.5) : (int)(jdelta+0.5);
lperiod = (int)(jdelta-0.5);
else
lperiod = (int)(jdelta+0.5);
int sign = 1;
if ( lperiod < 0 ) if ( lperiod < 0 )
{ {
int tmp = vdate1; int tmp = vdate1;
...@@ -219,10 +214,8 @@ void *Tinfo(void *argument) ...@@ -219,10 +214,8 @@ void *Tinfo(void *argument)
int vdate0 = 0, vtime0 = 0; int vdate0 = 0, vtime0 = 0;
int vdate = 0, vtime = 0; int vdate = 0, vtime = 0;
int tsID = 0, ntimeout; int tsID = 0, ntimeout;
int calendar;
int year0, month0, day0; int year0, month0, day0;
int year, month, day; int year, month, day;
int unit;
bool lforecast = false; bool lforecast = false;
int incperiod0 = 0, incunit0 = 0; int incperiod0 = 0, incunit0 = 0;
int incperiod = 0, incunit = 0; int incperiod = 0, incunit = 0;
...@@ -268,10 +261,10 @@ void *Tinfo(void *argument) ...@@ -268,10 +261,10 @@ void *Tinfo(void *argument)
fprintf(stdout, " RefTime = %s %s", vdatestr, vtimestr); fprintf(stdout, " RefTime = %s %s", vdatestr, vtimestr);
unit = taxisInqTunit(taxisID); int unit = taxisInqTunit(taxisID);
if ( unit != CDI_UNDEFID ) fprintf(stdout, " Units = %s", tunit2str(unit)); if ( unit != CDI_UNDEFID ) fprintf(stdout, " Units = %s", tunit2str(unit));
calendar = taxisInqCalendar(taxisID); int calendar = taxisInqCalendar(taxisID);
if ( calendar != CDI_UNDEFID ) fprintf(stdout, " Calendar = %s", calendar2str(calendar)); if ( calendar != CDI_UNDEFID ) fprintf(stdout, " Calendar = %s", calendar2str(calendar));
if ( taxisHasBounds(taxisID) ) if ( taxisHasBounds(taxisID) )
......
...@@ -72,6 +72,7 @@ static double pt_missval(paramType *p) { return p->missval; } ...@@ -72,6 +72,7 @@ static double pt_missval(paramType *p) { return p->missval; }
static double ts_ctimestep(double *data) { return lround(data[0]); } static double ts_ctimestep(double *data) { return lround(data[0]); }
static double ts_cdate(double *data) { return lround(data[1]); } static double ts_cdate(double *data) { return lround(data[1]); }
static double ts_ctime(double *data) { return lround(data[2]); } static double ts_ctime(double *data) { return lround(data[2]); }
static double ts_cdeltat(double *data) { return data[3]; }
typedef struct { typedef struct {
int type; int type;
...@@ -150,6 +151,7 @@ static func_t fun_sym_tbl[] = ...@@ -150,6 +151,7 @@ static func_t fun_sym_tbl[] =
{FT_0, 0, "ctimestep", (double (*)()) ts_ctimestep}, {FT_0, 0, "ctimestep", (double (*)()) ts_ctimestep},
{FT_0, 0, "cdate", (double (*)()) ts_cdate}, {FT_0, 0, "cdate", (double (*)()) ts_cdate},
{FT_0, 0, "ctime", (double (*)()) ts_ctime}, {FT_0, 0, "ctime", (double (*)()) ts_ctime},
{FT_0, 0, "cdeltat", (double (*)()) ts_cdeltat},
{FT_1C, 0, "sellevel", NULL}, {FT_1C, 0, "sellevel", NULL},
{FT_1C, 0, "sellevidx", NULL}, {FT_1C, 0, "sellevidx", NULL},
......
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