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

Changed type of vars to FieldVector.

parent fd6bdca7
......@@ -43,17 +43,17 @@ enum
#define SWITCHWARN "Hit default case!This should never happen (%s).\n"
static void
selEndOfPeriod(Field *periods, Field history, Field current, int isLastTimestep)
selEndOfPeriod(Field &periods, const Field &history, Field current, int isLastTimestep)
{
size_t i;
double pmissval = periods->missval;
double *parray = periods->ptr;
double pmissval = periods.missval;
double *parray = periods.ptr;
double hmissval = history.missval;
double *harray = history.ptr;
double cmissval = current.missval;
double *carray = current.ptr;
size_t len = gridInqSize(periods->grid);
size_t len = gridInqSize(periods.grid);
if (len != gridInqSize(current.grid) || (gridInqSize(current.grid) != gridInqSize(history.grid)))
cdoAbort("Fields have different gridsize (%s)", __func__);
......@@ -118,7 +118,7 @@ selEndOfPeriod(Field *periods, Field history, Field current, int isLastTimestep)
}
}
periods->nmiss = arrayNumMV(len, parray, pmissval);
periods.nmiss = arrayNumMV(len, parray, pmissval);
}
void *
......@@ -153,12 +153,12 @@ Consecstat(void *process)
field.ptr = (double *) Malloc(vlistGridsizeMax(ovlistID) * sizeof(double));
int nvars = vlistNvars(ivlistID);
Field **vars = field_calloc(ivlistID, FIELD_PTR);
Field **hist = NULL, **periods = NULL;
FieldVector2D vars, hist, periods;
fieldsFromVlist(ivlistID, vars, FIELD_PTR, 0);
if (operatorID == CONSECTS)
{
hist = field_malloc(ivlistID, FIELD_PTR);
periods = field_malloc(ivlistID, FIELD_PTR);
fieldsFromVlist(ivlistID, hist, FIELD_PTR);
fieldsFromVlist(ivlistID, periods, FIELD_PTR);
}
for (varID = 0; varID < nvars; varID++)
......@@ -212,7 +212,7 @@ Consecstat(void *process)
case CONSECTS:
if (itsID != 0)
{
selEndOfPeriod(&periods[varID][levelID], hist[varID][levelID], vars[varID][levelID], FALSE);
selEndOfPeriod(periods[varID][levelID], hist[varID][levelID], vars[varID][levelID], FALSE);
pstreamDefRecord(ostreamID, varID, levelID);
pstreamWriteRecord(ostreamID, periods[varID][levelID].ptr, periods[varID][levelID].nmiss);
}
......@@ -227,6 +227,7 @@ Consecstat(void *process)
default: printf(SWITCHWARN, __func__); break;
}
}
histvdate = vdate;
histvtime = vtime;
itsID++;
......@@ -243,16 +244,16 @@ Consecstat(void *process)
nlevels = zaxisInqSize(vlistInqVarZaxis(ovlistID, varID));
for (levelID = 0; levelID < nlevels; levelID++)
{
selEndOfPeriod(&periods[varID][levelID], hist[varID][levelID], vars[varID][levelID], TRUE);
selEndOfPeriod(periods[varID][levelID], hist[varID][levelID], vars[varID][levelID], TRUE);
pstreamDefRecord(ostreamID, varID, levelID);
pstreamWriteRecord(ostreamID, periods[varID][levelID].ptr, periods[varID][levelID].nmiss);
}
}
}
if (vars) field_free(vars, ivlistID);
if (hist) field_free(hist, ivlistID);
if (periods) field_free(periods, ivlistID);
fieldsFree(ivlistID, vars);
if (hist.size()) fieldsFree(ivlistID, hist);
if (periods.size()) fieldsFree(ivlistID, periods);
pstreamClose(istreamID);
pstreamClose(ostreamID);
......
......@@ -46,7 +46,8 @@ Deltat(void *process)
int streamID2 = cdoStreamOpenWrite(cdoStreamName(1), cdoFiletype());
pstreamDefVlist(streamID2, vlistID2);
Field **vars = field_malloc(vlistID1, FIELD_PTR);
FieldVector2D vars;
fieldsFromVlist(vlistID1, vars, FIELD_PTR);
size_t gridsizemax = vlistGridsizeMax(vlistID1);
std::vector<double> array1(gridsizemax);
......@@ -103,7 +104,7 @@ Deltat(void *process)
tsID2++;
}
field_free(vars, vlistID1);
fieldsFree(vlistID1, vars);
pstreamClose(streamID2);
pstreamClose(streamID1);
......
......@@ -86,7 +86,7 @@ Detrend(void *process)
pstreamDefVlist(streamID2, vlistID2);
int nvars = vlistNvars(vlistID1);
std::vector<Field **> vars;
FieldVector3D vars;
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
......@@ -99,7 +99,7 @@ Detrend(void *process)
dtlist.taxisInqTimestep(taxisID1, tsID);
vars[tsID] = field_malloc(vlistID1, FIELD_NONE);
fieldsFromVlist(vlistID1, vars[tsID], FIELD_NONE);
for (int recID = 0; recID < nrecs; recID++)
{
......@@ -164,7 +164,7 @@ Detrend(void *process)
}
}
field_free(vars[tsID], vlistID1);
fieldsFree(vlistID1, vars[tsID]);
}
pstreamClose(streamID2);
......
......@@ -68,7 +68,7 @@ Duplicate(void *process)
int streamID2 = cdoStreamOpenWrite(cdoStreamName(1), cdoFiletype());
pstreamDefVlist(streamID2, vlistID2);
std::vector<Field **> vars;
FieldVector3D vars;
std::vector<int64_t> vdate;
std::vector<int> vtime;
......@@ -86,7 +86,7 @@ Duplicate(void *process)
vdate[tsID] = taxisInqVdate(taxisID1);
vtime[tsID] = taxisInqVtime(taxisID1);
vars[tsID] = field_malloc(vlistID1, FIELD_NONE);
fieldsFromVlist(vlistID1, vars[tsID], FIELD_NONE);
for (int recID = 0; recID < nrecs; recID++)
{
......@@ -127,7 +127,7 @@ Duplicate(void *process)
}
}
for (tsID = 0; tsID < nts; tsID++) field_free(vars[tsID], vlistID1);
for (tsID = 0; tsID < nts; tsID++) fieldsFree(vlistID1, vars[tsID]);
pstreamClose(streamID2);
pstreamClose(streamID1);
......
......@@ -173,7 +173,7 @@ Filter(void *process)
int calendar = taxisInqCalendar(taxisID1);
int nvars = vlistNvars(vlistID1);
std::vector<Field **> vars;
FieldVector3D vars;
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
......@@ -186,7 +186,7 @@ Filter(void *process)
dtlist.taxisInqTimestep(taxisID1, tsID);
vars[tsID] = field_malloc(vlistID1, FIELD_NONE);
fieldsFromVlist(vlistID1, vars[tsID], FIELD_NONE);
for (int recID = 0; recID < nrecs; recID++)
{
......@@ -388,7 +388,7 @@ Filter(void *process)
}
}
field_free(vars[tsID], vlistID1);
fieldsFree(vlistID1, vars[tsID]);
}
pstreamClose(streamID2);
......
......@@ -57,7 +57,7 @@ Fourier(void *process)
pstreamDefVlist(streamID2, vlistID2);
int nvars = vlistNvars(vlistID1);
std::vector<Field **> vars;
FieldVector3D vars;
std::vector<int64_t> vdate;
std::vector<int> vtime;
......@@ -75,7 +75,7 @@ Fourier(void *process)
vdate[tsID] = taxisInqVdate(taxisID1);
vtime[tsID] = taxisInqVtime(taxisID1);
vars[tsID] = field_malloc(vlistID1, FIELD_NONE);
fieldsFromVlist(vlistID1, vars[tsID], FIELD_NONE);
for (int recID = 0; recID < nrecs; recID++)
{
......@@ -175,7 +175,7 @@ Fourier(void *process)
}
}
field_free(vars[tsID], vlistID1);
fieldsFree(vlistID1, vars[tsID]);
}
pstreamClose(streamID2);
......
......@@ -119,7 +119,7 @@ Pack(void *process)
std::vector<bool> varIsConst(nvars);
for (int varID = 0; varID < nvars; ++varID) varIsConst[varID] = vlistInqVarTimetype(vlistID1, varID) == TIME_CONSTANT;
std::vector<Field **> vars;
FieldVector3D vars;
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
......@@ -132,7 +132,7 @@ Pack(void *process)
dtlist.taxisInqTimestep(taxisID1, tsID);
vars[tsID] = field_malloc(vlistID1, FIELD_NONE);
fieldsFromVlist(vlistID1, vars[tsID], FIELD_NONE);
for (int recID = 0; recID < nrecs; recID++)
{
......@@ -264,7 +264,7 @@ Pack(void *process)
}
}
field_free(vars[tsID], vlistID1);
fieldsFree(vlistID1, vars[tsID]);
}
pstreamClose(streamID2);
......
......@@ -122,7 +122,7 @@ Runstat(void *process)
}
size_t gridsizemax = vlistGridsizeMax(vlistID1);
bool *imask = (bool *) Malloc(gridsizemax * sizeof(bool));
std::vector<bool> imask(gridsizemax);
int tsID = 0;
for (tsID = 0; tsID < ndates; tsID++)
......@@ -381,8 +381,6 @@ Runstat(void *process)
if (!runstat_nomiss) Free(samp1);
if (lvarstd || lrange) Free(vars2);
if (imask) Free(imask);
pstreamClose(streamID2);
pstreamClose(streamID1);
......
......@@ -73,6 +73,7 @@ Seasstat(void *process)
bool lvarstd = operfunc == func_std || operfunc == func_var || operfunc == func_std1 || operfunc == func_var1;
int divisor = operfunc == func_std1 || operfunc == func_var1;
// clang-format on
bool lvars2 = lvarstd || lrange;
int season_start = get_season_start();
get_season_name(seas_name);
......@@ -104,10 +105,10 @@ Seasstat(void *process)
field_init(&field);
field.ptr = (double *) Malloc(gridsizemax * sizeof(double));
Field **samp1 = field_malloc(vlistID1, FIELD_NONE);
Field **vars1 = field_malloc(vlistID1, FIELD_PTR);
Field **vars2 = NULL;
if (lvarstd || lrange) vars2 = field_malloc(vlistID1, FIELD_PTR);
FieldVector2D samp1, vars1, vars2;
fieldsFromVlist(vlistID1, samp1, FIELD_NONE);
fieldsFromVlist(vlistID1, vars1, FIELD_PTR);
if (lvars2) fieldsFromVlist(vlistID1, vars2, FIELD_PTR);
int tsID = 0;
int otsID = 0;
......@@ -157,7 +158,7 @@ Seasstat(void *process)
Field *psamp1 = &samp1[varID][levelID];
Field *pvars1 = &vars1[varID][levelID];
Field *pvars2 = vars2 ? &vars2[varID][levelID] : NULL;
Field *pvars2 = lvars2 ? &vars2[varID][levelID] : NULL;
size_t gridsize = pvars1->size;
......@@ -243,7 +244,7 @@ Seasstat(void *process)
int levelID = recinfo[recID].levelID;
Field *psamp1 = &samp1[varID][levelID];
Field *pvars1 = &vars1[varID][levelID];
Field *pvars2 = vars2 ? &vars2[varID][levelID] : NULL;
Field *pvars2 = lvars2 ? &vars2[varID][levelID] : NULL;
if (lmean)
{
......@@ -313,9 +314,9 @@ Seasstat(void *process)
otsID++;
}
field_free(vars1, vlistID1);
field_free(samp1, vlistID1);
if (lvarstd) field_free(vars2, vlistID1);
fieldsFree(vlistID1, samp1);
fieldsFree(vlistID1, vars1);
if (lvars2) fieldsFree(vlistID1, vars2);
if (field.ptr) Free(field.ptr);
......
......@@ -200,7 +200,6 @@ Seltime(void *process)
std::vector<int> vtime_list;
ListArray<int> listArrayInt;
ListArray<double> listArrayFlt;
Field ***vars = NULL;
cdoInitialize(process);
......@@ -326,6 +325,8 @@ Seltime(void *process)
for (varID = 0; varID < nvars; varID++)
if (vlistInqVarTimetype(vlistID1, varID) == TIME_CONSTANT) nconst++;
FieldVector3D vars;
bool lnts1 = (operatorID == SELSMON) && (nts1 > 0);
if (lnts1 || nconst)
......@@ -340,11 +341,11 @@ Seltime(void *process)
nts1 = 1;
}
vars = (Field ***) Malloc(nts1 * sizeof(Field **));
vars.resize(nts1);
for (int tsID = 0; tsID < nts1; tsID++)
{
vars[tsID] = field_malloc(vlistID1, FIELD_NONE);
fieldsFromVlist(vlistID1, vars[tsID], FIELD_NONE);
for (varID = 0; varID < nvars; varID++)
{
......@@ -655,8 +656,7 @@ Seltime(void *process)
if (lnts1 || nconst)
{
for (tsID = 0; tsID < nts1; tsID++) field_free(vars[tsID], vlistID2);
if (vars) Free(vars);
for (tsID = 0; tsID < nts1; tsID++) fieldsFree(vlistID2, vars[tsID]);
}
vlistDestroy(vlistID2);
......
......@@ -61,8 +61,9 @@ Subtrend(void *process)
field1.ptr = (double *) Malloc(gridsize * sizeof(double));
field4.ptr = (double *) Malloc(gridsize * sizeof(double));
Field **vars2 = field_malloc(vlistID1, FIELD_PTR);
Field **vars3 = field_malloc(vlistID1, FIELD_PTR);
FieldVector2D vars2, vars3;
fieldsFromVlist(vlistID1, vars2, FIELD_PTR);
fieldsFromVlist(vlistID1, vars3, FIELD_PTR);
int tsID = 0;
int nrecs = cdoStreamInqTimestep(streamID2, tsID);
......@@ -110,8 +111,8 @@ Subtrend(void *process)
tsID++;
}
field_free(vars2, vlistID1);
field_free(vars3, vlistID1);
fieldsFree(vlistID1, vars2);
fieldsFree(vlistID1, vars3);
if (field1.ptr) Free(field1.ptr);
if (field4.ptr) Free(field4.ptr);
......
......@@ -47,7 +47,7 @@ Ydaypctl(void *process)
int64_t vdates1[NDAY], vdates2[NDAY];
int vtimes1[NDAY];
long nsets[NDAY];
Field **vars1[NDAY];
FieldVector2D vars1[NDAY];
HISTOGRAM_SET *hsets[NDAY];
cdoInitialize(process);
......@@ -59,7 +59,6 @@ Ydaypctl(void *process)
for (dayoy = 0; dayoy < NDAY; dayoy++)
{
vars1[dayoy] = NULL;
hsets[dayoy] = NULL;
nsets[dayoy] = 0;
}
......@@ -126,9 +125,9 @@ Ydaypctl(void *process)
vdates2[dayoy] = vdate;
if (vars1[dayoy] == NULL)
if (!vars1[dayoy].size())
{
vars1[dayoy] = field_malloc(vlistID1, FIELD_PTR);
fieldsFromVlist(vlistID1, vars1[dayoy], FIELD_PTR);
hsets[dayoy] = hsetCreate(nvars);
for (varID = 0; varID < nvars; varID++)
......@@ -180,7 +179,7 @@ Ydaypctl(void *process)
vdates1[dayoy] = vdate;
vtimes1[dayoy] = vtime;
if (vars1[dayoy] == NULL)
if (!vars1[dayoy].size())
cdoAbort("No data for day %d in %s and %s", dayoy, cdoGetStreamName(1).c_str(), cdoGetStreamName(2).c_str());
for (int recID = 0; recID < nrecs; recID++)
......@@ -240,9 +239,9 @@ Ydaypctl(void *process)
for (dayoy = 0; dayoy < NDAY; dayoy++)
{
if (vars1[dayoy] != NULL)
if (vars1[dayoy].size())
{
field_free(vars1[dayoy], vlistID1);
fieldsFree(vlistID1, vars1[dayoy]);
hsetDestroy(hsets[dayoy]);
}
}
......
......@@ -79,7 +79,7 @@ Ydaystat(void *process)
size_t nmiss;
int64_t vdates[MAX_DOY];
int vtimes[MAX_DOY];
FieldVector3D vars1(MAX_DOY), vars2(MAX_DOY), samp1(MAX_DOY);
FieldVector2D vars1[MAX_DOY], vars2[MAX_DOY], samp1[MAX_DOY];
cdoInitialize(process);
......
......@@ -85,8 +85,9 @@ Yearmonstat(void *process)
field_init(&field);
field.ptr = (double *) Malloc(gridsize * sizeof(double));
Field **vars1 = field_malloc(vlistID1, FIELD_PTR);
Field **samp1 = field_malloc(vlistID1, FIELD_NONE);
FieldVector2D samp1, vars1;
fieldsFromVlist(vlistID1, samp1, FIELD_NONE);
fieldsFromVlist(vlistID1, vars1, FIELD_PTR);
int tsID = 0;
int otsID = 0;
......@@ -222,9 +223,6 @@ Yearmonstat(void *process)
otsID++;
}
field_free(vars1, vlistID1);
field_free(samp1, vlistID1);
if (field.ptr) Free(field.ptr);
pstreamClose(streamID2);
......
......@@ -52,7 +52,7 @@ Ymonpctl(void *process)
int64_t vdates1[NMONTH], vdates2[NMONTH];
int vtimes1[NMONTH];
long nsets[NMONTH];
Field **vars1[NMONTH];
FieldVector2D vars1[NMONTH];
HISTOGRAM_SET *hsets[NMONTH];
cdoInitialize(process);
......@@ -64,7 +64,6 @@ Ymonpctl(void *process)
for (month = 0; month < NMONTH; month++)
{
vars1[month] = NULL;
hsets[month] = NULL;
nsets[month] = 0;
}
......@@ -125,9 +124,9 @@ Ymonpctl(void *process)
vdates2[month] = vdate;
if (vars1[month] == NULL)
if (!vars1[month].size())
{
vars1[month] = field_malloc(vlistID1, FIELD_PTR);
fieldsFromVlist(vlistID1, vars1[month], FIELD_PTR);
hsets[month] = hsetCreate(nvars);
for (varID = 0; varID < nvars; varID++)
......@@ -173,7 +172,7 @@ Ymonpctl(void *process)
vdates1[month] = vdate;
vtimes1[month] = vtime;
if (vars1[month] == NULL)
if (!vars1[month].size())
cdoAbort("No data for month %d in %s and %s", month, cdoGetStreamName(1).c_str(), cdoGetStreamName(2).c_str());
for (int recID = 0; recID < nrecs; recID++)
......@@ -233,9 +232,9 @@ Ymonpctl(void *process)
for (month = 0; month < NMONTH; month++)
{
if (vars1[month] != NULL)
if (vars1[month].size())
{
field_free(vars1[month], vlistID1);
fieldsFree(vlistID1, vars1[month]);
hsetDestroy(hsets[month]);
}
}
......
......@@ -60,7 +60,7 @@ Ymonstat(void *process)
int vtimes[NMONTH];
int mon[NMONTH];
int nmon = 0;
FieldVector3D vars1(NMONTH), vars2(NMONTH), samp1(NMONTH);
FieldVector2D vars1[NMONTH], vars2[NMONTH], samp1[NMONTH];
Field field;
cdoInitialize(process);
......
......@@ -54,7 +54,7 @@ Yseaspctl(void *process)
int nlevels;
long nsets[NSEAS];
date_time_t datetime1[NSEAS], datetime2[NSEAS];
Field **vars1[NSEAS];
FieldVector2D vars1[NSEAS];
HISTOGRAM_SET *hsets[NSEAS];
cdoInitialize(process);
......@@ -66,7 +66,6 @@ Yseaspctl(void *process)
for (seas = 0; seas < NSEAS; seas++)
{
vars1[seas] = NULL;
hsets[seas] = NULL;
nsets[seas] = 0;
datetime1[seas].vdate = 0;
......@@ -132,9 +131,10 @@ Yseaspctl(void *process)
set_date(vdate, vtime, &datetime2[seas]);
if (vars1[seas] == NULL)
if (!vars1[seas].size())
{
vars1[seas] = field_malloc(vlistID1, FIELD_PTR);
fieldsFromVlist(vlistID1, vars1[seas], FIELD_PTR);
hsets[seas] = hsetCreate(nvars);
for (varID = 0; varID < nvars; varID++)
......@@ -183,7 +183,7 @@ Yseaspctl(void *process)
set_date(vdate, vtime, &datetime1[seas]);
if (vars1[seas] == NULL)
if (!vars1[seas].size())
cdoAbort("No data for season %d in %s and %s", seas, cdoGetStreamName(1).c_str(), cdoGetStreamName(2).c_str());
for (int recID = 0; recID < nrecs; recID++)
......@@ -243,9 +243,9 @@ Yseaspctl(void *process)
for (seas = 0; seas < NSEAS; seas++)
{
if (vars1[seas] != NULL)
if (vars1[seas].size())
{
field_free(vars1[seas], vlistID1);
fieldsFree(vlistID1, vars1[seas]);
hsetDestroy(hsets[seas]);
}
}
......
......@@ -72,6 +72,7 @@ Field **field_malloc(const int vlistID, const int ptype);
Field **field_calloc(const int vlistID, const int ptype);
void field_free(Field **field, const int vlistID);
void fieldsFromVlist(const int vlistID, FieldVector2D &field2D, int ptype);
void fieldsFromVlist(const int vlistID, FieldVector2D &field2D, int ptype, double fillValue);
void fieldsFree(const int vlistID, FieldVector2D &field2D);
......
......@@ -140,9 +140,8 @@ field_free(Field **field, int vlistID)
}
void
fieldsFromVlist(int vlistID, std::vector<std::vector<Field>> &field2D, int ptype)
fieldsFromVlistKernel(const int vlistID, FieldVector2D &field2D, int ptype, bool lfill, double fillValue)
{
bool init = false;
int nvars = vlistNvars(vlistID);
field2D.resize(nvars);
......@@ -180,12 +179,12 @@ fieldsFromVlist(int vlistID, std::vector<std::vector<Field>> &field2D, int ptype
if (ptype & FIELD_FLT)
{
field2D[varID][levelID].ptrf = (float *) Malloc(nwpv * gridsize * sizeof(float));
if (init) arrayFill(nwpv * gridsize, field2D[varID][levelID].ptrf, 0.0f);
if (lfill) arrayFill(nwpv * gridsize, field2D[varID][levelID].ptrf, (float)fillValue);
}
else
{
field2D[varID][levelID].ptr = (double *) Malloc(nwpv * gridsize * sizeof(double));
if (init) arrayFill(nwpv * gridsize, field2D[varID][levelID].ptr, 0.0);
if (lfill) arrayFill(nwpv * gridsize, field2D[varID][levelID].ptr, fillValue);
}
}
......@@ -194,26 +193,38 @@ fieldsFromVlist(int vlistID, std::vector<std::vector<Field>> &field2D, int ptype
if (ptype & FIELD_FLT)
{
field2D[varID][levelID].ptr2f = (float *) Malloc(nwpv * gridsize * sizeof(float));
if (init) arrayFill(nwpv * gridsize, (float *) field2D[varID][levelID].ptr2f, 0.0f);
if (lfill) arrayFill(nwpv * gridsize, (float *) field2D[varID][levelID].ptr2f, (float)fillValue);
}
else
{
field2D[varID][levelID].ptr2 = (double *) Malloc(nwpv * gridsize * sizeof(double));