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

New operator addtrend: Add trend

parent 4d01d96c
2020-03-26 Uwe Schulzweida
* New operator addtrend: Add trend
2020-03-25 Uwe Schulzweida
* Distgrid: Added memory support for 32-bit float data.
......
......@@ -27,6 +27,16 @@
#include "process_int.h"
#include "cdo_vlist.h"
static void
addtrend(int tsID, 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)));
}
static void
subtrend(int tsID, const Field &field1, const Field &field2, const Field &field3, Field &field4)
{
......@@ -40,10 +50,14 @@ subtrend(int tsID, const Field &field1, const Field &field2, const Field &field3
void *
Trendarith(void *process)
{
int varID, levelID;
cdoInitialize(process);
cdoOperatorAdd("addtrend", func_add, 0, nullptr);
cdoOperatorAdd("subtrend", func_sub, 0, nullptr);
const auto operatorID = cdoOperatorID();
const auto operfunc = cdoOperatorF1(operatorID);
operatorCheckArgc(0);
const auto streamID1 = cdoOpenRead(0);
......@@ -82,6 +96,7 @@ Trendarith(void *process)
auto nrecs = cdoStreamInqTimestep(streamID2, tsID);
for (int recID = 0; recID < nrecs; recID++)
{
int varID, levelID;
cdoInqRecord(streamID2, &varID, &levelID);
cdoReadRecord(streamID2, vars2[varID][levelID].vec_d.data(), &vars2[varID][levelID].nmiss);
}
......@@ -90,6 +105,7 @@ Trendarith(void *process)
nrecs = cdoStreamInqTimestep(streamID3, tsID);
for (int recID = 0; recID < nrecs; recID++)
{
int varID, levelID;
cdoInqRecord(streamID3, &varID, &levelID);
cdoReadRecord(streamID3, vars3[varID][levelID].vec_d.data(), &vars3[varID][levelID].nmiss);
}
......@@ -102,6 +118,7 @@ Trendarith(void *process)
for (int recID = 0; recID < nrecs; recID++)
{
int varID, levelID;
cdoInqRecord(streamID1, &varID, &levelID);
cdoReadRecord(streamID1, field1.vec_d.data(), &field1.nmiss);
......@@ -110,7 +127,10 @@ Trendarith(void *process)
field4.size = varList[varID].gridsize;
field4.missval = varList[varID].missval;
subtrend(tsID, field1, vars2[varID][levelID], vars3[varID][levelID], field4);
if (operfunc == func_add)
addtrend(tsID, field1, vars2[varID][levelID], vars3[varID][levelID], field4);
else
subtrend(tsID, 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