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

Trendarith: added parameter equal=false.

parent 319756e8
......@@ -109,7 +109,7 @@ Trend(void *process)
CheckTimeInc checkTimeInc;
JulianDate juldate0;
double deltat1 = 0;
double deltat1 = 0.0;
int64_t vdate = 0;
int vtime = 0;
int tsID = 0;
......
......@@ -26,25 +26,56 @@
#include "functs.h"
#include "process_int.h"
#include "cdo_vlist.h"
#include "datetime.h"
#include "pmlist.h"
#include "param_conversion.h"
static void
addtrend(int tsID, const Field &field1, const Field &field2, const Field &field3, Field &field4)
addtrend(double zj, const Field &field1, const Field &field2, const Field &field3, Field &field4)
{
const auto gridsize = field1.size;
const auto missval = field1.missval;
const auto missval1 = missval;
const auto missval2 = missval;
for (size_t i = 0; i < gridsize; i++) field4.vec_d[i] = ADDMN(field1.vec_d[i], ADDMN(field2.vec_d[i], MULMN(field3.vec_d[i], tsID)));
for (size_t i = 0; i < gridsize; i++) field4.vec_d[i] = ADDMN(field1.vec_d[i], ADDMN(field2.vec_d[i], MULMN(field3.vec_d[i], zj)));
}
static void
subtrend(int tsID, const Field &field1, const Field &field2, const Field &field3, Field &field4)
subtrend(double zj, const Field &field1, const Field &field2, const Field &field3, Field &field4)
{
const auto gridsize = field1.size;
const auto missval = field1.missval;
const auto missval1 = missval;
const auto missval2 = missval;
for (size_t i = 0; i < gridsize; i++) field4.vec_d[i] = SUBMN(field1.vec_d[i], ADDMN(field2.vec_d[i], MULMN(field3.vec_d[i], tsID)));
for (size_t i = 0; i < gridsize; i++) field4.vec_d[i] = SUBMN(field1.vec_d[i], ADDMN(field2.vec_d[i], MULMN(field3.vec_d[i], zj)));
}
static void
trendarithGetParameter(bool &tstepIsEqual)
{
const auto pargc = cdoOperatorArgc();
if (pargc)
{
auto pargv = cdoGetOperArgv();
KVList kvlist;
kvlist.name = "TREND";
if (kvlist.parseArguments(pargc, pargv) != 0) cdoAbort("Parse error!");
if (Options::cdoVerbose) kvlist.print();
for (const auto &kv : kvlist)
{
const auto &key = kv.key;
if (kv.nvalues > 1) cdoAbort("Too many values for parameter key >%s<!", key.c_str());
if (kv.nvalues < 1) cdoAbort("Missing value for parameter key >%s<!", key.c_str());
const auto &value = kv.values[0];
// clang-format off
if (key == "equal") tstepIsEqual = parameter2bool(value);
else cdoAbort("Invalid parameter key >%s<!", key.c_str());
// clang-format on
}
}
}
void *
......@@ -58,7 +89,8 @@ Trendarith(void *process)
const auto operatorID = cdoOperatorID();
const auto operfunc = cdoOperatorF1(operatorID);
operatorCheckArgc(0);
auto tstepIsEqual = true;
trendarithGetParameter(tstepIsEqual);
const auto streamID1 = cdoOpenRead(0);
const auto streamID2 = cdoOpenRead(1);
......@@ -110,9 +142,20 @@ Trendarith(void *process)
cdoReadRecord(streamID3, vars3[varID][levelID].vec_d.data(), &vars3[varID][levelID].nmiss);
}
const auto calendar = taxisInqCalendar(taxisID1);
CheckTimeInc checkTimeInc;
JulianDate juldate0;
double deltat1 = 0.0;
tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
{
const auto vdate = taxisInqVdate(taxisID1);
const auto vtime = taxisInqVtime(taxisID1);
if (tstepIsEqual) checkTimeIncrement(tsID, calendar, vdate, vtime, checkTimeInc);
const auto zj = tstepIsEqual ? (double) tsID : deltaTimeStep0(tsID, calendar, vdate, vtime, juldate0, deltat1);
taxisCopyTimestep(taxisID4, taxisID1);
cdoDefTimestep(streamID4, tsID);
......@@ -128,9 +171,9 @@ Trendarith(void *process)
field4.missval = varList[varID].missval;
if (operfunc == func_add)
addtrend(tsID, field1, vars2[varID][levelID], vars3[varID][levelID], field4);
addtrend(zj, field1, vars2[varID][levelID], vars3[varID][levelID], field4);
else
subtrend(tsID, field1, vars2[varID][levelID], vars3[varID][levelID], field4);
subtrend(zj, field1, vars2[varID][levelID], vars3[varID][levelID], field4);
cdoDefRecord(streamID4, varID, levelID);
cdoWriteRecord(streamID4, field4.vec_d.data(), fieldNumMiss(field4));
......
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