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

Distgrid: Added memory support for 32-bit float data.

parent edd08e38
2020-03-25 Uwe Schulzweida
* Distgrid: Added memory support for 32-bit float data.
2020-03-24 Uwe Schulzweida
* Vertintml: Added memory support for 32-bit float data.
......
......@@ -211,9 +211,12 @@ genGrids(int gridID1, int *gridIDs, size_t nxvals, size_t nyvals, size_t nxblock
}
static void
window_cell(double *array1, double *array2, size_t gridsize2, size_t *cellidx)
window_cell(const Field &field1, Field &field2, size_t gridsize2, size_t *cellidx)
{
for (size_t i = 0; i < gridsize2; ++i) array2[i] = array1[cellidx[i]];
if (field1.memType == MemType::Float)
for (size_t i = 0; i < gridsize2; ++i) field2.vec_f[i] = field1.vec_f[cellidx[i]];
else
for (size_t i = 0; i < gridsize2; ++i) field2.vec_d[i] = field1.vec_d[cellidx[i]];
}
struct GridInfo
......@@ -234,7 +237,6 @@ Distgrid(void *process)
char filename[8192];
int index;
int gridtype = -1;
size_t nmiss;
cdoInitialize(process);
......@@ -296,7 +298,11 @@ Distgrid(void *process)
const auto nsplit = nxblocks * nyblocks;
if (nsplit > MAX_BLOCKS) cdoAbort("Too many blocks (max = %d)!", MAX_BLOCKS);
Varray<double> array1(gridsize);
Field field1, field2;
VarList varList1;
varListInit(varList1, vlistID1);
std::vector<int> vlistIDs(nsplit);
std::vector<CdoStreamID> streamIDs(nsplit);
......@@ -327,12 +333,6 @@ Distgrid(void *process)
for (size_t index = 0; index < nsplit; index++) vlistChangeGridIndex(vlistIDs[index], i, gridinfo[i].gridIDs[index]);
}
size_t gridsize2max = 0;
for (size_t index = 0; index < nsplit; index++)
if (gridinfo[0].gridsize[index] > gridsize2max) gridsize2max = gridinfo[0].gridsize[index];
Varray<double> array2(gridsize2max);
strcpy(filename, cdoGetObase());
const int nchars = strlen(filename);
......@@ -353,21 +353,26 @@ Distgrid(void *process)
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
{
for (size_t index = 0; index < nsplit; index++) cdoDefTimestep(streamIDs[index], tsID);
for (auto &streamID : streamIDs) cdoDefTimestep(streamID, tsID);
for (int recID = 0; recID < nrecs; recID++)
{
cdoInqRecord(streamID1, &varID, &levelID);
cdoReadRecord(streamID1, &array1[0], &nmiss);
const auto missval = vlistInqVarMissval(vlistID1, varID);
field1.init(varList1[varID]);
cdoReadRecord(streamID1, field1);
for (size_t index = 0; index < nsplit; index++)
{
window_cell(&array1[0], &array2[0], gridinfo[0].gridsize[index], gridinfo[0].gridindex[index].data());
auto var = varList1[varID];
var.gridID = gridinfo[0].gridIDs[index];
var.gridsize = gridinfo[0].gridsize[index];
field2.init(var);
window_cell(field1, field2, gridinfo[0].gridsize[index], gridinfo[0].gridindex[index].data());
if (field1.nmiss) fieldNumMV(field2);
cdoDefRecord(streamIDs[index], varID, levelID);
if (nmiss) nmiss = varrayNumMV(gridinfo[0].gridsize[index], array2, missval);
cdoWriteRecord(streamIDs[index], array2.data(), nmiss);
cdoWriteRecord(streamIDs[index], field2);
}
}
......@@ -376,11 +381,8 @@ Distgrid(void *process)
cdoStreamClose(streamID1);
for (size_t index = 0; index < nsplit; index++)
{
cdoStreamClose(streamIDs[index]);
vlistDestroy(vlistIDs[index]);
}
for (auto &streamID : streamIDs) cdoStreamClose(streamID);
for (auto &vlistID : vlistIDs) vlistDestroy(vlistID);
for (int i = 0; i < ngrids; i++)
for (size_t index = 0; index < nsplit; index++) gridDestroy(gridinfo[i].gridIDs[index]);
......
......@@ -77,7 +77,7 @@ varrayFree(std::vector<T> &v)
}
/*
template <class T, size_t ROW, size_t COL<
template <class T, size_t ROW, size_t COL>
using Matrix = std::array<std::array<T, COL>, ROW>;
*/
......
......@@ -27,8 +27,6 @@
#include "functs.h"
#include "cdo_output.h"
Field::Field() : fpeRaised(0), nwpv(1), memType(MemType::Native), grid(-1), gridsize(0), size(0), nsamp(0), nmiss(0), missval(0) { m_count = 0; }
Field3D::Field3D() : nlevels(0) {}
void
Field::init(const CdoVar &var)
......
......@@ -52,7 +52,7 @@ public:
Varray<double> vec_d;
Varray<double> weightv;
Field();
Field() : fpeRaised(0), nwpv(1), memType(MemType::Native), grid(-1), gridsize(0), size(0), nsamp(0), nmiss(0), missval(0) { m_count = 0; }
void init(const CdoVar &var);
void resize(size_t count);
void resize(size_t count, double value);
......@@ -70,7 +70,7 @@ class Field3D : public Field
public:
size_t nlevels;
Field3D();
Field3D() : nlevels(0) {}
void init(const CdoVar &var);
};
......
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