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