Commit 3ce0ee4d authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Field cleanup.

parent 2dfd8430
......@@ -27,7 +27,6 @@
#include "cdo_options.h"
#include "cdo_int.h"
#include "param_conversion.h"
#include "util_string.h"
/*
......@@ -99,9 +98,9 @@ calc_adisit(size_t gridsize, size_t nlevel, const std::vector<double> &pressure,
for (size_t levelID = 0; levelID < nlevel; ++levelID)
{
const std::vector<double> &thovec = tho[levelID].vec;
const std::vector<double> &saovec = sao[levelID].vec;
std::vector<double> &tisvec = tis[levelID].vec;
const auto &thovec = tho[levelID].vec;
const auto &saovec = sao[levelID].vec;
auto &tisvec = tis[levelID].vec;
const double tho_missval = tho[levelID].missval;
const double sao_missval = sao[levelID].missval;
const double tis_missval = tis[levelID].missval;
......@@ -120,8 +119,8 @@ calc_adisit(size_t gridsize, size_t nlevel, const std::vector<double> &pressure,
}
static void
calc_adipot(size_t gridsize, size_t nlevel, const std::vector<double> &pressure, const std::vector<Field> &t,
const std::vector<Field> &s, std::vector<Field> &tpot)
calc_adipot(size_t gridsize, size_t nlevel, const std::vector<double> &pressure, const FieldVector &t,
const FieldVector &s, FieldVector &tpot)
{
// pressure units: hPa
// t units: Celsius
......@@ -129,9 +128,9 @@ calc_adipot(size_t gridsize, size_t nlevel, const std::vector<double> &pressure,
for (size_t levelID = 0; levelID < nlevel; ++levelID)
{
const std::vector<double> &tvec = t[levelID].vec;
const std::vector<double> &svec = s[levelID].vec;
std::vector<double> &tpotvec = tpot[levelID].vec;
const auto &tvec = t[levelID].vec;
const auto &svec = s[levelID].vec;
auto &tpotvec = tpot[levelID].vec;
const double t_missval = t[levelID].missval;
const double s_missval = s[levelID].missval;
const double tpot_missval = tpot[levelID].missval;
......
......@@ -469,7 +469,7 @@ CMOR_lite(void *process)
size_t gridsize = gridInqSize(vlistInqVarGrid(vlistID2, varID2));
if (vlistInqVarNumber(vlistID2, varID2) != CDI_REAL) gridsize *= 2;
if (nmiss > 0 && var.changemissval)
if (nmiss && var.changemissval)
{
for (size_t i = 0; i < gridsize; ++i)
{
......
......@@ -68,7 +68,7 @@ Change_e5slm(void *process)
streamInqRecord(streamIDslm, &varID, &levelID);
streamReadRecord(streamIDslm, cland.data(), &nmiss);
if (nmiss > 0) cdoAbort("SLM with missing values are unsupported!");
if (nmiss) cdoAbort("SLM with missing values are unsupported!");
double minval, maxval;
arrayMinMaxMask(gridsize, cland.data(), nullptr, &minval, &maxval);
......
......@@ -47,11 +47,11 @@ selEndOfPeriod(Field &periods, const Field &history, const Field &current, int i
{
size_t i;
double pmissval = periods.missval;
std::vector<double> &parray = periods.vec;
auto &parray = periods.vec;
double hmissval = history.missval;
const std::vector<double> &harray = history.vec;
const auto &harray = history.vec;
double cmissval = current.missval;
const std::vector<double> &carray = current.vec;
const auto &carray = current.vec;
size_t len = gridInqSize(periods.grid);
if (len != gridInqSize(current.grid) || (gridInqSize(current.grid) != gridInqSize(history.grid)))
......@@ -59,7 +59,7 @@ selEndOfPeriod(Field &periods, const Field &history, const Field &current, int i
if (!isLastTimestep)
{
if (current.nmiss > 0 || history.nmiss > 0)
if (current.nmiss || history.nmiss)
{
#ifdef _OPENMP
#pragma omp parallel for default(shared)
......@@ -94,7 +94,7 @@ selEndOfPeriod(Field &periods, const Field &history, const Field &current, int i
}
else
{
if (current.nmiss > 0)
if (current.nmiss)
{
#ifdef _OPENMP
#pragma omp parallel for default(shared)
......@@ -198,6 +198,7 @@ Consecstat(void *process)
cdoInqRecord(istreamID, &varID, &levelID);
cdoReadRecord(istreamID, field.vec.data(), &field.nmiss);
field.grid = varList[varID].gridID;
field.size = varList[varID].gridsize;
field.missval = varList[varID].missval;
vfarsumtr(vars[varID][levelID], field, refval);
......@@ -217,7 +218,7 @@ Consecstat(void *process)
}
#ifdef _OPENMP
#pragma omp parallel for default(shared) schedule(static)
for (size_t i = 0; i < gridInqSize(vars[varID][levelID].grid); i++)
for (size_t i = 0; i < vars[varID][levelID].size; i++)
hist[varID][levelID].vec[i] = vars[varID][levelID].vec[i];
#else
hist[varID][levelID].vec = vars[varID][levelID].vec;
......
......@@ -91,11 +91,11 @@ Deltat(void *process)
cdoReadRecord(streamID1, array1.data(), &nmiss);
const double missval = vars[varID][levelID].missval;
const size_t gridsize = vars[varID][levelID].gridsize;
std::vector<double> &array0 = vars[varID][levelID].vec;
const size_t fieldsize = vars[varID][levelID].size;
auto &array0 = vars[varID][levelID].vec;
if (nmiss || vars[varID][levelID].nmiss)
{
for (size_t i = 0; i < gridsize; ++i)
for (size_t i = 0; i < fieldsize; ++i)
{
if (DBL_IS_EQUAL(array0[i], missval) || DBL_IS_EQUAL(array1[i], missval))
array2[i] = missval;
......@@ -103,14 +103,14 @@ Deltat(void *process)
array2[i] = (array1[i] - array0[i]) * idt_in_sec;
}
nmiss = arrayNumMV(gridsize, array2.data(), missval);
nmiss = arrayNumMV(fieldsize, array2.data(), missval);
}
else
{
for (size_t i = 0; i < gridsize; ++i) array2[i] = (array1[i] - array0[i]) * idt_in_sec;
for (size_t i = 0; i < fieldsize; ++i) array2[i] = (array1[i] - array0[i]) * idt_in_sec;
}
arrayCopy(gridsize, array1.data(), array0.data());
arrayCopy(fieldsize, array1.data(), array0.data());
cdoDefRecord(streamID2, varID, levelID);
cdoWriteRecord(streamID2, array2.data(), nmiss);
......
......@@ -367,7 +367,7 @@ Distgrid(void *process)
int i = 0;
window_cell(&array1[0], &array2[0], gridinfo[i].gridsize[index], gridinfo[i].gridindex[index].data());
cdoDefRecord(streamIDs[index], varID, levelID);
if (nmiss > 0) nmiss = arrayNumMV(gridinfo[i].gridsize[index], &array2[0], missval);
if (nmiss) nmiss = arrayNumMV(gridinfo[i].gridsize[index], &array2[0], missval);
cdoWriteRecord(streamIDs[index], &array2[0], nmiss);
}
}
......
......@@ -22,9 +22,7 @@
#include <time.h>
#include <cdi.h>
#include "cdo_int.h"
#include "commandline.h"
#ifdef HAVE_LIBNETCDF
......
......@@ -193,12 +193,8 @@ Ensstat(void *process)
std::vector<ens_file_t> ef(nfiles);
std::vector<Field> fields(Threading::ompNumThreads);
for (int i = 0; i < Threading::ompNumThreads; i++)
{
fields[i].gridsize = nfiles;
fields[i].resize(nfiles);
}
FieldVector fields(Threading::ompNumThreads);
for (int i = 0; i < Threading::ompNumThreads; i++) fields[i].resize(nfiles);
for (int fileID = 0; fileID < nfiles; fileID++)
{
......
......@@ -134,7 +134,6 @@ Ensstat3(void *process)
FieldVector field(Threading::ompNumThreads);
for (i = 0; i < Threading::ompNumThreads; i++)
{
field[i].gridsize = nfiles;
field[i].resize(nfiles);
field[i].weightv.resize(nfiles);
for (int fileID = 0; fileID < nfiles; fileID++) field[i].weightv[fileID] = 1;
......@@ -143,9 +142,7 @@ Ensstat3(void *process)
for (int fileID = 0; fileID < nfiles; fileID++)
{
streamID = cdoStreamOpenRead(cdoStreamName(fileID));
vlistID = cdoStreamInqVlist(streamID);
ef[fileID].streamID = streamID;
ef[fileID].vlistID = vlistID;
}
......
......@@ -23,7 +23,6 @@
#include <cdi.h>
#include "cdo_int.h"
#include <mpim_grid.h>
void *
......@@ -112,7 +111,7 @@ Fldrms(void *process)
{
lastgrid = field1.grid;
field1.weightv[0] = 1;
if (field1.gridsize > 1)
if (field1.size > 1)
{
const int wstatus = gridWeights(field1.grid, field1.weightv.data());
if (wstatus != 0 && tsID == 0 && levelID == 0)
......
......@@ -35,7 +35,6 @@
#include "cdo_int.h"
#include "param_conversion.h"
#include <mpim_grid.h>
#include "percentiles.h"
#include "pmlist.h"
......@@ -209,13 +208,13 @@ Fldstat(void *process)
cdoReadRecord(streamID1, field.vec.data(), &field.nmiss);
field.grid = vlistInqVarGrid(vlistID1, varID);
field.gridsize = gridInqSize(field.grid);
field.size = gridInqSize(field.grid);
if (needWeights && field.grid != lastgrid)
{
lastgrid = field.grid;
field.weightv[0] = 1;
if (useweights && field.gridsize > 1)
if (useweights && field.size > 1)
{
const bool wstatus = gridWeights(field.grid, field.weightv.data()) != 0;
if (wstatus && tsID == 0 && levelID == 0)
......
......@@ -34,7 +34,6 @@
#include "cdo_int.h"
#include "param_conversion.h"
#include <mpim_grid.h>
#include "cdo_options.h"
#include "progress.h"
......@@ -447,10 +446,9 @@ gridboxstat(const Field &field1, Field &field2, const size_t xinc, const size_t
const bool useWeight = (!field1.weightv.empty());
const size_t gridsize = xinc * yinc;
std::vector<Field> field(Threading::ompNumThreads);
FieldVector field(Threading::ompNumThreads);
for (int i = 0; i < Threading::ompNumThreads; i++)
{
field[i].gridsize = gridsize;
field[i].resize(gridsize);
if (useWeight) field[i].weightv.resize(gridsize);
field[i].missval = field1.missval;
......@@ -494,7 +492,7 @@ gridboxstat(const Field &field1, Field &field2, const size_t xinc, const size_t
}
}
field[ompthID].gridsize = isize;
field[ompthID].size = isize;
field2.vec[ig] = vfldfun(field[ompthID], statfunc);
}
......@@ -577,11 +575,11 @@ Gridboxstat(void *process)
cdoReadRecord(streamID1, field1.vec.data(), &field1.nmiss);
field1.grid = vlistInqVarGrid(vlistID1, varID);
field1.gridsize = gridInqSize(field1.grid);
field1.size = gridInqSize(field1.grid);
field1.missval = vlistInqVarMissval(vlistID1, varID);
field2.grid = gridID2;
field2.gridsize = gridsize2;
field2.size = gridsize2;
field2.missval = field1.missval;
if (needWeights && field1.grid != lastgrid)
......
......@@ -131,7 +131,7 @@ Harmonic(void *process)
cdoInqRecord(streamID1, &varID, &levelID);
cdoReadRecord(streamID1, array, &nmiss);
if (nmiss > 0) cdoAbort("Missing values are not allowed!");
if (nmiss) cdoAbort("Missing values are not allowed!");
gridsize = gridInqSize(vlistInqVarGrid(vlistID1, varID));
offset = gridsize * levelID;
......
......@@ -64,7 +64,7 @@ farexpr(Field &field1, const Field &field2, const Field &field3, double (*expres
if (len != gridInqSize(grid2) || len != gridInqSize(grid3)) cdoAbort("Fields have different gridsize (%s)", __func__);
if (nmiss1 > 0 || nmiss2 > 0 || nmiss3 > 0)
if (nmiss1 || nmiss2 || nmiss3)
{
for (size_t i = 0; i < len; i++)
if (DBL_IS_EQUAL(field1.vec[i], missval1) || DBL_IS_EQUAL(field2.vec[i], missval2) || DBL_IS_EQUAL(field3.vec[i], missval3))
......
......@@ -1099,7 +1099,7 @@ read_dataset(hid_t loc_id, const char *name, void *opdata)
if (Options::cdoVerbose)
cdoPrint("Dataset %s: dtype = %d minval = %g maxval = %g missval = %g", varname, dtype, minval, maxval, missval);
if (nmiss > 0)
if (nmiss)
{
if (!(missval < minval || missval > maxval))
{
......
......@@ -415,7 +415,7 @@ Info(void *process)
{
fpeRaised = 0;
if (infostatr.nmiss > 0)
if (infostatr.nmiss)
{
size_t nvals;
if (Options::CDO_Memtype == MEMTYPE_FLOAT)
......@@ -532,7 +532,7 @@ Info(void *process)
fprintf(stdout, "\n");
}
if (imiss != nmiss && nmiss > 0) cdoPrint("Found %zu of %zu missing values!", imiss, nmiss);
if (imiss != nmiss && nmiss) cdoPrint("Found %zu of %zu missing values!", imiss, nmiss);
if (fpeRaised > 0) cdoWarning("floating-point exception reported: %s!", fpe_errstr(fpeRaised));
......
......@@ -165,7 +165,7 @@ Intntime(void *process)
const double *single1 = &vardata[curFirst][varID][offset];
const double *single2 = &vardata[curSecond][varID][offset];
const bool withMissval = nmiss[curFirst][varID][levelID] > 0 || nmiss[curSecond][varID][levelID] > 0;
const bool withMissval = nmiss[curFirst][varID][levelID] || nmiss[curSecond][varID][levelID];
const size_t nmiss3 = inttime(fac1, fac2, gridsize, single1, single2, array,
withMissval, varList1[varID].missval, varList2[varID].missval);
......
......@@ -290,7 +290,7 @@ Inttime(void *process)
const double *single1 = &vardata[curFirst][varID][offset];
const double *single2 = &vardata[curSecond][varID][offset];
const bool withMissval = nmiss[curFirst][varID][levelID] > 0 || nmiss[curSecond][varID][levelID] > 0;
const bool withMissval = nmiss[curFirst][varID][levelID] || nmiss[curSecond][varID][levelID];
const size_t nmiss3 = inttime(fac1, fac2, gridsize, single1, single2, array,
withMissval, varList1[varID].missval, varList2[varID].missval);
......
......@@ -124,7 +124,7 @@ Intyear(void *process)
nmiss3 = 0;
if (nmiss1 > 0 || nmiss2 > 0)
if (nmiss1 || nmiss2)
{
const double missval1 = vlistInqVarMissval(vlistID1, varID);
const double missval2 = vlistInqVarMissval(vlistID2, varID);
......
......@@ -28,7 +28,7 @@ isosurface(double isoval, long nlev1, const std::vector<double> &lev1, const Fie
const size_t gridsize = gridInqSize(field3D[0].grid);
const size_t nmiss = field3D[0].nmiss;
const double missval = field3D[0].missval;
std::vector<double> &data2D = field2D.vec;
auto &data2D = field2D.vec;
for (size_t i = 0; i < gridsize; ++i)
{
......@@ -39,7 +39,7 @@ isosurface(double isoval, long nlev1, const std::vector<double> &lev1, const Fie
const double val1 = field3D[k].vec[i];
const double val2 = field3D[k+1].vec[i];
if (nmiss > 0)
if (nmiss)
{
const bool lmiss1 = DBL_IS_EQUAL(val1, missval);
const bool lmiss2 = DBL_IS_EQUAL(val2, missval);
......
......@@ -301,7 +301,7 @@ NCL_wind(void *process)
if (nmissu != nmissv)
{
cdoAbort("u and v have different number of missing values!");
if (nmissu > 0 && !DBL_IS_EQUAL(missvalu, missvalv))
if (nmissu && !DBL_IS_EQUAL(missvalu, missvalv))
{
for (levelID = 0; levelID < nlev; ++levelID)
{
......
......@@ -157,7 +157,7 @@ Pack(void *process)
if (tsID > 0 && timetype == TIME_CONSTANT) continue;
const double *array = vars[tsID][varID][levelID].vec.data();
const size_t nmiss = vars[tsID][varID][levelID].nmiss;
if (nmiss > 0)
if (nmiss)
{
nmisspv += nmiss;
arrayMinMaxMV(gridsize, array, missval1, &zmin, &zmax);
......@@ -175,7 +175,7 @@ Pack(void *process)
vlistDefVarDatatype(vlistID2, varID, datatype);
const double missval2 = vlistInqVarMissval(vlistID2, varID);
if (nmisspv > 0)
if (nmisspv)
{
double tmin, tmax;
if (!get_type_values(datatype, tmin, tmax))
......@@ -188,9 +188,9 @@ Pack(void *process)
for (int tsID = 0; tsID < nts; tsID++)
{
if (tsID > 0 && timetype == TIME_CONSTANT) continue;
std::vector<double> &array = vars[tsID][varID][levelID].vec;
auto &array = vars[tsID][varID][levelID].vec;
const size_t nmiss = vars[tsID][varID][levelID].nmiss;
if (nmiss > 0)
if (nmiss)
for (size_t i = 0; i < gridsize; ++i)
if (DBL_IS_EQUAL(array[i], missval1)) array[i] = missval2;
}
......
......@@ -119,7 +119,7 @@ Pinfo(void *process)
}
else
{
if (nmiss > 0)
if (nmiss)
{
ivals = arrayMinMaxMeanMV(gridsize, array1.data(), missval, &arrmin, &arrmax, &arrmean);
imiss = gridsize - ivals;
......@@ -139,7 +139,7 @@ Pinfo(void *process)
fprintf(stdout, " nan\n");
}
if (imiss != nmiss && nmiss > 0) fprintf(stdout, "Found %zu of %zu missing values!\n", imiss, nmiss);
if (imiss != nmiss && nmiss) fprintf(stdout, "Found %zu of %zu missing values!\n", imiss, nmiss);
}
arrayCopy(gridsize, array1.data(), array2.data());
......
......@@ -242,7 +242,7 @@ Pressure(void *process)
if (varID == pvarID)
{
cdoReadRecord(streamID1, array.data(), &nmiss);
if (nmiss > 0) cdoAbort("Missing valus unsupported!");
if (nmiss) cdoAbort("Missing valus unsupported!");
}
}
......
......@@ -182,7 +182,7 @@ remapPrintInfo(int operfunc, bool remap_genweights, RemapGrid &src_grid, RemapGr
strcat(line, tmpstr);
strcat(line, " grid");
if (nmiss > 0)
if (nmiss)
{
snprintf(tmpstr, sizeof(tmpstr), ", with source mask (%zu)", gridInqSize(src_grid.gridID) - nmiss);
strcat(line, tmpstr);
......@@ -211,7 +211,7 @@ remapPrintWarning(const char *remap_file, int operfunc, RemapGrid &src_grid, siz
strcat(line, tmpstr);
strcat(line, " grid");
if (nmiss > 0)
if (nmiss)
{
snprintf(tmpstr, sizeof(tmpstr), " with mask (%zu)", gridInqSize(src_grid.gridID) - nmiss);
strcat(line, tmpstr);
......
......@@ -26,7 +26,6 @@
#include "cdo_int.h"
#include "param_conversion.h"
#include "cdo_math.h"
#include <mpim_grid.h>
#include "util_string.h"
......@@ -132,9 +131,9 @@ calc_rhopot(size_t gridsize, size_t nlevel, const std::vector<double> &pressure,
for (size_t levelID = 0; levelID < nlevel; ++levelID)
{
const std::vector<double> &tovec = to[levelID].vec;
const std::vector<double> &saovec = sao[levelID].vec;
std::vector<double> &rhovec = rho[levelID].vec;
const auto &tovec = to[levelID].vec;
const auto &saovec = sao[levelID].vec;
auto &rhovec = rho[levelID].vec;
const double to_missval = to[levelID].missval;
const double sao_missval = sao[levelID].missval;
const double rho_missval = rho[levelID].missval;
......
......@@ -146,13 +146,13 @@ Runstat(void *process)
Field &rvars1 = vars1[tsID][varID][levelID];
const size_t gridsize = rvars1.gridsize;
const size_t fieldsize = rvars1.size;
cdoReadRecord(streamID1, rvars1.vec.data(), &rvars1.nmiss);
if (lrange)
{
vars2[tsID][varID][levelID].nmiss = rvars1.nmiss;
for (size_t i = 0; i < gridsize; i++) vars2[tsID][varID][levelID].vec[i] = rvars1.vec[i];
for (size_t i = 0; i < fieldsize; i++) vars2[tsID][varID][levelID].vec[i] = rvars1.vec[i];
}
if (runstat_nomiss && rvars1.nmiss) cdoAbort("Missing values supported was swichted off by env. RUNSTAT_NOMISS!");
......@@ -161,16 +161,16 @@ Runstat(void *process)
{
const double missval = rvars1.missval;
for (size_t i = 0; i < gridsize; i++) imask[i] = !DBL_IS_EQUAL(rvars1.vec[i], missval);
for (size_t i = 0; i < gridsize; i++) samp1[tsID][varID][levelID].vec[i] = (double) imask[i];
for (size_t i = 0; i < fieldsize; i++) imask[i] = !DBL_IS_EQUAL(rvars1.vec[i], missval);
for (size_t i = 0; i < fieldsize; i++) samp1[tsID][varID][levelID].vec[i] = (double) imask[i];
#ifdef _OPENMP
#pragma omp parallel for default(none) shared(tsID, imask, samp1, varID, levelID)
#endif
for (int inp = 0; inp < tsID; inp++)
{
std::vector<double> &samp = samp1[inp][varID][levelID].vec;
for (size_t i = 0; i < gridsize; i++)
auto &samp = samp1[inp][varID][levelID].vec;
for (size_t i = 0; i < fieldsize; i++)
if (imask[i]) samp[i]++;
}
}
......@@ -296,32 +296,32 @@ Runstat(void *process)
Field &rvars1 = vars1[ndates - 1][varID][levelID];
const size_t gridsize = rvars1.gridsize;
const size_t fieldsize = rvars1.size;
cdoReadRecord(streamID1, rvars1.vec.data(), &nmiss);
rvars1.nmiss = nmiss;
if (lrange)
{
vars2[ndates - 1][varID][levelID].nmiss = rvars1.nmiss;
for (size_t i = 0; i < gridsize; i++) vars2[ndates - 1][varID][levelID].vec[i] = rvars1.vec[i];
for (size_t i = 0; i < fieldsize; i++) vars2[ndates - 1][varID][levelID].vec[i] = rvars1.vec[i];
}
if (runstat_nomiss && nmiss > 0) cdoAbort("Missing values supported swichted off!");
if (runstat_nomiss && nmiss) cdoAbort("Missing values supported swichted off!");
if (!runstat_nomiss)
{
const double missval = rvars1.missval;
for (size_t i = 0; i < gridsize; i++) imask[i] = !DBL_IS_EQUAL(rvars1.vec[i], missval);
for (size_t i = 0; i < gridsize; i++) samp1[ndates - 1][varID][levelID].vec[i] = (double) imask[i];
for (size_t i = 0; i < fieldsize; i++) imask[i] = !DBL_IS_EQUAL(rvars1.vec[i], missval);
for (size_t i = 0; i < fieldsize; i++) samp1[ndates - 1][varID][levelID].vec[i] = (double) imask[i];
#ifdef _OPENMP
#pragma omp parallel for default(none) shared(imask, samp1, varID, levelID)
#endif
for (int inp = 0; inp < ndates - 1; inp++)
{
std::vector<double> &samp = samp1[inp][varID][levelID].vec;
for (size_t i = 0; i < gridsize; i++)
auto &samp = samp1[inp][varID][levelID].vec;
for (size_t i = 0; i < fieldsize; i++)
if (imask[i]) samp[i]++;
}
}
......
......@@ -24,7 +24,6 @@
#include <cdi.h>
#include "cdo_int.h"
#include "cdo_season.h"
void *
......@@ -106,14 +105,13 @@ Seascount(void *process)
recList[recID].levelID = levelID;
recList[recID].lconst = vlistInqVarTimetype(vlistID1, varID) == TIME_CONSTANT;
}