Browse Source

Always read variables as real values

lintest
Michael Uleysky 7 months ago
parent
commit
a36d6ce955
  1. 2
      include/layereddataz.h
  2. 10
      src/layereddataz.cpp

2
include/layereddataz.h

@ -180,7 +180,7 @@ class LayeredDataZ: public NCFuncs
} }
private: private:
template<class DataType> Data ReadVarRaw(const NC& f, const MString& name, size_t i, bool nodepth, const struct Parameters* p) const; Data ReadVarRaw(const NC& f, const MString& name, size_t i, bool nodepth, const struct Parameters* p) const;
bool HaveVar(const MString& vname) const bool HaveVar(const MString& vname) const
{ {

10
src/layereddataz.cpp

@ -233,10 +233,7 @@ bool LayeredDataZ::Read(const MString& vname, std::map<MString, LayeredDataZ::Da
if(v.Name() == name) if(v.Name() == name)
{ {
if(v.NDim() == 3) nodepth = true; if(v.NDim() == 3) nodepth = true;
if(v.Type() == NcZarrTypes::VarType::INT2) data = ReadVarRaw<int2>(nc[id], name, tid, nodepth, p); data = ReadVarRaw(nc[id], name, tid, nodepth, p);
if(v.Type() == NcZarrTypes::VarType::INT4) data = ReadVarRaw<int>(nc[id], name, tid, nodepth, p);
if(v.Type() == NcZarrTypes::VarType::FLOAT) data = ReadVarRaw<float>(nc[id], name, tid, nodepth, p);
if(v.Type() == NcZarrTypes::VarType::DOUBLE) data = ReadVarRaw<double>(nc[id], name, tid, nodepth, p);
if(data) if(data)
{ {
cache[vname] = std::move(data); cache[vname] = std::move(data);
@ -247,10 +244,9 @@ bool LayeredDataZ::Read(const MString& vname, std::map<MString, LayeredDataZ::Da
return false; return false;
} }
template<class DataType> LayeredDataZ::Data LayeredDataZ::ReadVarRaw(const NC& f, const MString& name, size_t i, bool nodepth, const struct LayeredDataZ::Parameters* p) const LayeredDataZ::Data LayeredDataZ::ReadVarRaw(const NC& f, const MString& name, size_t i, bool nodepth, const struct LayeredDataZ::Parameters* p) const
{ {
real unitmul = 1.0; real unitmul = 1.0;
//DataType fill;
real offset = 0.0, scale = 1.0; real offset = 0.0, scale = 1.0;
if(f.HasAtt(name, "add_offset")) offset = f.AttReal(name, "add_offset"); if(f.HasAtt(name, "add_offset")) offset = f.AttReal(name, "add_offset");
@ -266,7 +262,7 @@ template<class DataType> LayeredDataZ::Data LayeredDataZ::ReadVarRaw(const NC& f
Data data((p->xb < p->xe) ? (p->xe - p->xb + 1) : (dname.nx + p->xe - p->xb + 1), p->ye - p->yb + 1, Lon(p->xb), Lat(p->yb), lonstep, latstep, std::move(unit)); Data data((p->xb < p->xe) ? (p->xe - p->xb + 1) : (dname.nx + p->xe - p->xb + 1), p->ye - p->yb + 1, Lon(p->xb), Lat(p->yb), lonstep, latstep, std::move(unit));
auto trans = [scale, offset, unitmul](auto raw) -> DataType { return (raw * scale + offset) * unitmul; }; auto trans = [scale, offset, unitmul](auto raw) -> real { return (raw * scale + offset) * unitmul; };
auto rlayer = depthinv ? depths.size() - p->layer - 1 : p->layer; auto rlayer = depthinv ? depths.size() - p->layer - 1 : p->layer;

Loading…
Cancel
Save