Commit 1e9e4f11 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Exprf: added function setDateAndTime().

parent 9bb3b6a4
......@@ -104,7 +104,7 @@ exprsFromFile(const std::vector<std::string> &exprArgv)
if (exprArgc != 1) operatorCheckArgc(1);
auto exprf = exprArgv[0].c_str();
/* Open expr script file for reading */
// Open expr script file for reading
auto fp = fopen(exprf, "r");
if (!fp) cdoAbort("Open failed on %s", exprf);
......@@ -136,7 +136,7 @@ str_replace(char *target, const char *needle, const char *replacement)
const auto needle_len = strlen(needle);
const auto repl_len = strlen(replacement);
while (1)
while (true)
{
char *p = strstr(tmp, needle);
......@@ -395,6 +395,36 @@ genZonalID(int vlistID)
return zonalID;
}
static
void setDateAndTime(paramType &varts, int calendar, int tsID, int64_t vdate0, int vtime0, int64_t vdate, int vtime)
{
double jdelta = 0.0;
if (tsID)
{
const auto juldate0 = julianDateEncode(calendar, vdate0, vtime0);
const auto juldate = julianDateEncode(calendar, vdate, vtime);
jdelta = julianDateToSeconds(julianDateSub(juldate, juldate0));
}
varts.data[CTIMESTEP] = tsID + 1;
varts.data[CDATE] = vdate;
varts.data[CTIME] = vtime;
varts.data[CDELTAT] = jdelta;
int year, mon, day;
int hour, minute, second;
cdiDecodeDate(vdate, &year, &mon, &day);
cdiDecodeTime(vtime, &hour, &minute, &second);
varts.data[CDAY] = day;
varts.data[CMONTH] = mon;
varts.data[CYEAR] = year;
varts.data[CSECOND] = second;
varts.data[CMINUTE] = minute;
varts.data[CHOUR] = hour;
}
void *
Expr(void *process)
{
......@@ -650,42 +680,20 @@ Expr(void *process)
int vtime0 = 0;
const auto calendar = taxisInqCalendar(taxisID1);
int nrecs;
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
while (true)
{
const auto nrecs = cdoStreamInqTimestep(streamID1, tsID);
if (nrecs == 0) break;
const auto vdate = taxisInqVdate(taxisID1);
const auto vtime = taxisInqVtime(taxisID1);
double jdelta = 0;
if (tsID)
{
const auto juldate0 = julianDateEncode(calendar, vdate0, vtime0);
const auto juldate = julianDateEncode(calendar, vdate, vtime);
jdelta = julianDateToSeconds(julianDateSub(juldate, juldate0));
}
setDateAndTime(params[vartsID], calendar, tsID, vdate0, vtime0, vdate, vtime);
vdate0 = vdate;
vtime0 = vtime;
params[vartsID].data[CTIMESTEP] = tsID + 1;
params[vartsID].data[CDATE] = vdate;
params[vartsID].data[CTIME] = vtime;
params[vartsID].data[CDELTAT] = jdelta;
int year, mon, day;
int hour, minute, second;
cdiDecodeDate(vdate, &year, &mon, &day);
cdiDecodeTime(vtime, &hour, &minute, &second);
params[vartsID].data[CDAY] = day;
params[vartsID].data[CMONTH] = mon;
params[vartsID].data[CYEAR] = year;
params[vartsID].data[CSECOND] = second;
params[vartsID].data[CMINUTE] = minute;
params[vartsID].data[CHOUR] = hour;
taxisCopyTimestep(taxisID2, taxisID1);
cdoDefTimestep(streamID2, tsID);
......
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