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

Deltat: Add memory support for 32-bit float data.

parent 187cd709
2021-11-08 Uwe Schulzweida
* Deltat: Add memory support for 32-bit float data.
* Change: Add memory support for 32-bit float data.
* Timcount: Add memory support for 32-bit float data.
* Seascount: Add memory support for 32-bit float data.
......
......@@ -16,6 +16,57 @@
#include "process_int.h"
#include "datetime.h"
template <typename T>
static void
varray_deltat(const size_t len, const Varray<T> &v0, const Varray<T> &v1, Varray<T> &v2, double factor, double mv)
{
assert(len > 0);
assert(v0.size() > 0);
assert(v1.size() > 0);
assert(v2.size() > 0);
assert(len <= v0.size());
assert(len <= v1.size());
assert(len <= v2.size());
for (size_t i = 0; i < len; ++i)
{
if (DBL_IS_EQUAL(v0[i], mv) || DBL_IS_EQUAL(v1[i], mv))
v2[i] = mv;
else
v2[i] = (v1[i] - v0[i]) * factor;
}
}
template <typename T>
static void
varray_deltat(const size_t len, const Varray<T> &v0, const Varray<T> &v1, Varray<T> &v2, double factor)
{
assert(len > 0);
for (size_t i = 0; i < len; ++i) v2[i] = (v1[i] - v0[i]) * factor;
}
void
field_deltat(const Field &field0, const Field &field1, Field &field2, double factor)
{
if (field1.nmiss || field0.nmiss)
{
if (field1.memType == MemType::Float)
varray_deltat(field1.size, field0.vec_f, field1.vec_f, field2.vec_f, factor, field1.missval);
else
varray_deltat(field1.size, field0.vec_d, field1.vec_d, field2.vec_d, factor, field1.missval);
field2.nmiss = field_num_mv(field2);
}
else
{
if (field1.memType == MemType::Float)
varray_deltat(field1.size, field0.vec_f, field1.vec_f, field2.vec_f, factor);
else
varray_deltat(field1.size, field0.vec_d, field1.vec_d, field2.vec_d, factor);
}
}
void *
Deltat(void *process)
{
......@@ -45,11 +96,13 @@ Deltat(void *process)
const auto streamID2 = cdo_open_write(1);
cdo_def_vlist(streamID2, vlistID2);
FieldVector2D vars;
fields_from_vlist(vlistID1, vars, FIELD_VEC);
VarList varList1;
varListInit(varList1, vlistID1);
const auto gridsizemax = vlistGridsizeMax(vlistID1);
Varray<double> array1(gridsizemax), array2(gridsizemax);
Field field1, field2;
FieldVector2D vars;
fields_from_vlist(vlistID1, vars, FIELD_VEC | FIELD_NAT);
int tsID = 0;
auto nrecs = cdo_stream_inq_timestep(streamID1, tsID);
......@@ -60,9 +113,7 @@ Deltat(void *process)
{
int varID, levelID;
cdo_inq_record(streamID1, &varID, &levelID);
size_t nmiss;
cdo_read_record(streamID1, vars[varID][levelID].vec_d.data(), &nmiss);
vars[varID][levelID].nmiss = nmiss;
cdo_read_record(streamID1, vars[varID][levelID]);
}
tsID++;
......@@ -73,7 +124,7 @@ Deltat(void *process)
if (nrecs == 0) break;
const auto juldate1 = juldate_encode(calendar, taxisInqVdate(taxisID1), taxisInqVtime(taxisID1));
const double idt_in_sec = ldivdt ? 1. / juldate_to_seconds(juldate_sub(juldate1, juldate0)) : 1;
const auto idtInSec = ldivdt ? 1.0 / juldate_to_seconds(juldate_sub(juldate1, juldate0)) : 1.0;
juldate0 = juldate1;
cdo_taxis_copy_timestep(taxisID2, taxisID1);
......@@ -83,33 +134,18 @@ Deltat(void *process)
{
int varID, levelID;
cdo_inq_record(streamID1, &varID, &levelID);
size_t nmiss;
cdo_read_record(streamID1, array1.data(), &nmiss);
const auto missval = vars[varID][levelID].missval;
const auto fieldsize = vars[varID][levelID].size;
auto &array0 = vars[varID][levelID].vec_d;
if (nmiss || vars[varID][levelID].nmiss)
{
for (size_t i = 0; i < fieldsize; ++i)
{
if (DBL_IS_EQUAL(array0[i], missval) || DBL_IS_EQUAL(array1[i], missval))
array2[i] = missval;
else
array2[i] = (array1[i] - array0[i]) * idt_in_sec;
}
nmiss = varray_num_mv(fieldsize, array2, missval);
}
else
{
for (size_t i = 0; i < fieldsize; ++i) array2[i] = (array1[i] - array0[i]) * idt_in_sec;
}
varray_copy(fieldsize, array1, array0);
field1.init(varList1[varID]);
cdo_read_record(streamID1, field1);
auto &field0 = vars[varID][levelID];
field2.init(varList1[varID]);
field_deltat(field0, field1, field2, idtInSec);
field_copy(field1, field0);
cdo_def_record(streamID2, varID, levelID);
cdo_write_record(streamID2, array2.data(), nmiss);
cdo_write_record(streamID2, field2);
}
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