Commit 177a04a5 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Renamed varlist.h to datarangelist.h.

parent 5aaaf54b
......@@ -65,6 +65,7 @@ libcdo_la_SOURCES = after_dvtrans.cc \
convert_units.cc \
convert_units.h \
counter.h \
datarangelist.h \
datetime.cc \
datetime.h \
dmemory.h \
......@@ -226,7 +227,6 @@ libcdo_la_SOURCES = after_dvtrans.cc \
util_wildcards.cc \
util_wildcards.h \
util_date.h \
varlist.h \
vector3d.h \
verifygrid.h \
vertical_interp.cc \
......
......@@ -144,8 +144,7 @@ Pack(void *process)
for (varID = 0; varID < nvars; varID++)
{
double fmin = 1.e300;
double fmax = -1.e300;
double fmin = 1.e300, fmax = -1.e300;
size_t nmisspv = 0;
const auto timetype = varList[varID].timetype;
......@@ -156,27 +155,20 @@ Pack(void *process)
{
for (int tsID = 0; tsID < nts; tsID++)
{
std::pair<double, double> minmax;
if (tsID > 0 && timetype == TIME_CONSTANT) continue;
const auto &array = vars[tsID][varID][levelID].vec_d;
const auto nmiss = vars[tsID][varID][levelID].nmiss;
if (nmiss)
{
nmisspv += nmiss;
minmax = varrayMinMaxMV(gridsize, array, missval1);
}
else
{
minmax = varrayMinMax(gridsize, array);
}
if (minmax.first < fmin) fmin = minmax.first;
if (minmax.second > fmax) fmax = minmax.second;
if (nmiss) nmisspv += nmiss;
auto minmax = nmiss ? varrayMinMaxMV(gridsize, array, missval1) : varrayMinMax(gridsize, array);
fmin = std::min(fmin, minmax.first);
fmax = std::max(fmax, minmax.second);
}
}
vlistDefVarDatatype(vlistID2, varID, datatype);
const double missval2 = vlistInqVarMissval(vlistID2, varID);
const auto missval2 = vlistInqVarMissval(vlistID2, varID);
if (nmisspv)
{
......
......@@ -45,7 +45,7 @@ fpe_errstr(int fpeRaised)
return errstr;
}
std::pair<double, double>
MinMaxVal
varrayMinMaxMV(const size_t len, const double *array, const double missval, size_t &nvals)
{
double vmin = DBL_MAX;
......@@ -62,17 +62,17 @@ varrayMinMaxMV(const size_t len, const double *array, const double missval, size
}
}
return std::pair<double, double>(vmin, vmax);
return MinMaxVal(vmin, vmax);
}
std::pair<double, double>
MinMaxVal
varrayMinMaxMV(const size_t len, const double *array, const double missval)
{
size_t nvals;
return varrayMinMaxMV(len, array, missval, nvals);
}
std::pair<double, double>
MinMaxVal
varrayMinMaxMV(const size_t len, const Varray<double> &array, const double missval)
{
size_t nvals;
......@@ -265,7 +265,7 @@ varrayNumMV(const size_t len, const Varray<T> &array, const double missval)
template size_t varrayNumMV(const size_t len, const Varray<float> &array, const double missval);
template size_t varrayNumMV(const size_t len, const Varray<double> &array, const double missval);
std::pair<double, double>
MinMaxVal
varrayMinMax(const size_t len, const double *restrict array)
{
double vmin = DBL_MAX;
......@@ -280,17 +280,17 @@ varrayMinMax(const size_t len, const double *restrict array)
if (array[i] > vmax) vmax = array[i];
}
return std::pair<double, double>(vmin, vmax);
return MinMaxVal(vmin, vmax);
}
std::pair<double, double>
MinMaxVal
varrayMinMax(const size_t len, const Varray<double> &v)
{
return varrayMinMax(len, v.data());
}
template <typename T>
std::pair<double, double>
MinMaxVal
varrayMinMax(const Varray<T> &v)
{
double vmin = DBL_MAX;
......@@ -306,12 +306,12 @@ varrayMinMax(const Varray<T> &v)
if (v[i] > vmax) vmax = v[i];
}
return std::pair<double, double>(vmin, vmax);
return MinMaxVal(vmin, vmax);
}
// Explicit instantiation
template std::pair<double, double> varrayMinMax(const Varray<float> &v);
template std::pair<double, double> varrayMinMax(const Varray<double> &v);
template MinMaxVal varrayMinMax(const Varray<float> &v);
template MinMaxVal varrayMinMax(const Varray<double> &v);
double
varrayMin(const size_t len, const Varray<double> &v)
......
......@@ -21,6 +21,9 @@
#include <cstddef>
#include "compare.h"
using MinMaxVal = std::pair<double, double>;
template <typename T>
using Varray = std::vector<T>;
......@@ -167,15 +170,15 @@ size_t arrayNumMV(size_t len, const double *array, double missval);
template <typename T>
size_t varrayNumMV(size_t len, const Varray<T> &array, double missval);
std::pair<double, double> varrayMinMax(size_t len, const Varray<double> &v);
std::pair<double, double> varrayMinMax(size_t len, const double *array);
MinMaxVal varrayMinMax(size_t len, const Varray<double> &v);
MinMaxVal varrayMinMax(size_t len, const double *array);
template <typename T>
std::pair<double, double> varrayMinMax(const Varray<T> &v);
MinMaxVal varrayMinMax(const Varray<T> &v);
std::pair<double, double> varrayMinMaxMV(size_t len, const Varray<double> &array, double missval);
std::pair<double, double> varrayMinMaxMV(size_t len, const double *array, double missval);
std::pair<double, double> varrayMinMaxMV(size_t len, const double *array, double missval, size_t &nvals);
MinMaxVal varrayMinMaxMV(size_t len, const Varray<double> &array, double missval);
MinMaxVal varrayMinMaxMV(size_t len, const double *array, double missval);
MinMaxVal varrayMinMaxMV(size_t len, const double *array, double missval, size_t &nvals);
double varrayMin(size_t len, const Varray<double> &v);
double varrayMax(size_t len, const Varray<double> &v);
......
......@@ -68,27 +68,27 @@ CdoStream::defVarList(int p_vlistID)
if (m_vlistID != -1) cdoAbort("Internal problem, vlist already defined!");
if (m_varlist.size() != 0) cdoAbort("Internal problem, varlist already allocated!");
if (m_datarangelist.size() != 0) cdoAbort("Internal problem, datarangelist already allocated!");
const auto nvars = vlistNvars(p_vlistID);
assert(nvars > 0);
m_varlist.resize(nvars);
m_datarangelist.resize(nvars);
for (int varID = 0; varID < nvars; ++varID)
{
m_varlist[varID].gridsize = gridInqSize(vlistInqVarGrid(p_vlistID, varID));
m_varlist[varID].datatype = vlistInqVarDatatype(p_vlistID, varID);
m_varlist[varID].missval = vlistInqVarMissval(p_vlistID, varID);
m_varlist[varID].addoffset = vlistInqVarAddoffset(p_vlistID, varID);
m_varlist[varID].scalefactor = vlistInqVarScalefactor(p_vlistID, varID);
m_datarangelist[varID].gridsize = gridInqSize(vlistInqVarGrid(p_vlistID, varID));
m_datarangelist[varID].datatype = vlistInqVarDatatype(p_vlistID, varID);
m_datarangelist[varID].missval = vlistInqVarMissval(p_vlistID, varID);
m_datarangelist[varID].addoffset = vlistInqVarAddoffset(p_vlistID, varID);
m_datarangelist[varID].scalefactor = vlistInqVarScalefactor(p_vlistID, varID);
m_varlist[varID].check_datarange = false;
m_datarangelist[varID].check_datarange = false;
const bool laddoffset = IS_NOT_EQUAL(m_varlist[varID].addoffset, 0);
const bool lscalefactor = IS_NOT_EQUAL(m_varlist[varID].scalefactor, 1);
const bool laddoffset = IS_NOT_EQUAL(m_datarangelist[varID].addoffset, 0);
const bool lscalefactor = IS_NOT_EQUAL(m_datarangelist[varID].scalefactor, 1);
auto datatype = m_varlist[varID].datatype;
auto datatype = m_datarangelist[varID].datatype;
if (filetype == CDI_FILETYPE_NC || filetype == CDI_FILETYPE_NC2 || filetype == CDI_FILETYPE_NC4
|| filetype == CDI_FILETYPE_NC4C || filetype == CDI_FILETYPE_NC5)
......@@ -97,25 +97,25 @@ CdoStream::defVarList(int p_vlistID)
&& (filetype == CDI_FILETYPE_NC || filetype == CDI_FILETYPE_NC2 || filetype == CDI_FILETYPE_NC5))
{
datatype = CDI_DATATYPE_INT16;
m_varlist[varID].datatype = datatype;
m_datarangelist[varID].datatype = datatype;
}
if (datatype == CDI_DATATYPE_UINT16
&& (filetype == CDI_FILETYPE_NC || filetype == CDI_FILETYPE_NC2 || filetype == CDI_FILETYPE_NC5))
{
datatype = CDI_DATATYPE_INT32;
m_varlist[varID].datatype = datatype;
m_datarangelist[varID].datatype = datatype;
}
if (laddoffset || lscalefactor)
{
if (datatype == CDI_DATATYPE_INT8 || datatype == CDI_DATATYPE_UINT8 || datatype == CDI_DATATYPE_INT16
|| datatype == CDI_DATATYPE_UINT16)
m_varlist[varID].check_datarange = true;
m_datarangelist[varID].check_datarange = true;
}
else if (Options::CheckDatarange)
{
m_varlist[varID].check_datarange = true;
m_datarangelist[varID].check_datarange = true;
}
}
}
......
......@@ -22,11 +22,11 @@
#include "config.h" /* _FILE_OFFSET_BITS influence off_t */
#endif
#include "varlist.h"
#include <sys/types.h> /* off_t */
#include <vector>
#include <memory>
#include "datarangelist.h"
#include "field.h"
class FileStream;
......@@ -82,7 +82,7 @@ public:
bool isopen;
std::string m_name;
std::vector<varlist_t> m_varlist;
std::vector<Datarange> m_datarangelist;
int m_vlistID;
int m_tsID;
......
......@@ -14,15 +14,15 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef VARLIST_H
#define VARLIST_H
#ifndef DATARANGELIST_H
#define DATARANGELIST_H
#include <cdi.h>
#include <cstddef>
#include "cdo_output.h"
#include "array.h"
struct varlist_t
struct Datarange
{
bool check_datarange;
size_t gridsize;
......@@ -35,22 +35,13 @@ struct varlist_t
checkDatarange(double *array, size_t nmiss)
{
size_t ivals = 0;
std::pair<double, double> minmax;
if (nmiss)
{
minmax = varrayMinMaxMV(gridsize, array, missval, ivals);
}
else
{
minmax = varrayMinMax(gridsize, array);
ivals = gridsize;
}
auto minmax = nmiss ? varrayMinMaxMV(gridsize, array, missval, ivals) : varrayMinMax(gridsize, array);
if (nmiss == 0) ivals = gridsize;
if (ivals > 0)
{
double smin = (minmax.first - addoffset) / scalefactor;
double smax = (minmax.second - addoffset) / scalefactor;
auto smin = (minmax.first - addoffset) / scalefactor;
auto smax = (minmax.second - addoffset) / scalefactor;
if (datatype == CDI_DATATYPE_INT8 || datatype == CDI_DATATYPE_UINT8 || datatype == CDI_DATATYPE_INT16
|| datatype == CDI_DATATYPE_UINT16)
......
......@@ -198,7 +198,7 @@ fieldNumMV(Field &field)
return field.nmiss;
}
std::pair<double, double>
MinMaxVal
fieldMinMax(Field &field)
{
if (field.memType == MemType::Float)
......
......@@ -93,7 +93,7 @@ void fieldCopy(const Field3D &field_src, int levelID, Field &field_tgt);
void fieldAdd(Field &field1, const Field3D &field2, int levelID);
size_t fieldNumMiss(const Field &field);
size_t fieldNumMV(Field &field);
std::pair<double, double> fieldMinMax(Field &field);
MinMaxVal fieldMinMax(Field &field);
// fieldmem.cc
void fieldsFromVlist(int vlistID, FieldVector2D &field2D);
......
......@@ -233,8 +233,8 @@ FileStream::writeRecord(double *p_data, size_t p_nmiss)
auto varID = m_varID;
if (FileStream::timersEnabled()) timer_start(timer_write);
if (varID < (int) m_varlist.size())
if (m_varlist[varID].check_datarange) m_varlist[varID].checkDatarange(p_data, p_nmiss);
if (varID < (int) m_datarangelist.size())
if (m_datarangelist[varID].check_datarange) m_datarangelist[varID].checkDatarange(p_data, p_nmiss);
streamWriteRecordDoubleLocked(m_fileID, p_data, p_nmiss);
......@@ -324,9 +324,9 @@ FileStream::close()
streamCloseLocked(m_fileID);
isopen = false;
if (m_varlist.size())
if (m_datarangelist.size())
{
m_varlist.clear();
m_varlist.shrink_to_fit();
m_datarangelist.clear();
m_datarangelist.shrink_to_fit();
}
}
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