diff --git a/src/layereddataz.cpp b/src/layereddataz.cpp index 15f8ac1..135bf08 100644 --- a/src/layereddataz.cpp +++ b/src/layereddataz.cpp @@ -202,7 +202,6 @@ std::pair LayeredDataZ::Parameters(michlib_inter break; } } - if(depthinv) ppar->layer = depths.size() - ppar->layer - 1; } pars.SetParameter("depth", Depth(ppar->layer)); @@ -269,11 +268,13 @@ template LayeredDataZ::Data LayeredDataZ::ReadVarRaw(const NC& f auto trans = [scale, offset, unitmul](auto raw) -> DataType { return (raw * scale + offset) * unitmul; }; + auto rlayer = depthinv ? depths.size() - p->layer - 1 : p->layer; + if(p->xb < p->xe) { auto ret = nodepth ? f.Read(name, data, trans, {dname.lonname, p->xb, p->xe - p->xb + 1}, {dname.latname, p->yb, p->ye - p->yb + 1}, {dname.timename, i, 1}) : f.Read(name, data, trans, {dname.lonname, p->xb, p->xe - p->xb + 1}, {dname.latname, p->yb, p->ye - p->yb + 1}, {dname.timename, i, 1}, - {dname.depthname, p->layer, 1}); + {dname.depthname, rlayer, 1}); if(!ret) return Data(); } else @@ -281,7 +282,7 @@ template LayeredDataZ::Data LayeredDataZ::ReadVarRaw(const NC& f { auto ret = nodepth ? f.Read(name, data, trans, {dname.lonname, p->xb, dname.nx - p->xb + 1}, {dname.latname, p->yb, p->ye - p->yb + 1}, {dname.timename, i, 1}) : f.Read(name, data, trans, {dname.lonname, p->xb, dname.nx - p->xb + 1}, {dname.latname, p->yb, p->ye - p->yb + 1}, {dname.timename, i, 1}, - {dname.depthname, p->layer, 1}); + {dname.depthname, rlayer, 1}); if(!ret) return Data(); } { @@ -290,7 +291,7 @@ template LayeredDataZ::Data LayeredDataZ::ReadVarRaw(const NC& f auto ret = nodepth ? f.Read(name, shifteddata, trans, {dname.lonname, 0, p->xe + 1}, {dname.latname, p->yb, p->ye - p->yb + 1}, {dname.timename, i, 1}) - : f.Read(name, shifteddata, trans, {dname.lonname, 0, p->xe + 1}, {dname.latname, p->yb, p->ye - p->yb + 1}, {dname.timename, i, 1}, {dname.depthname, p->layer, 1}); + : f.Read(name, shifteddata, trans, {dname.lonname, 0, p->xe + 1}, {dname.latname, p->yb, p->ye - p->yb + 1}, {dname.timename, i, 1}, {dname.depthname, rlayer, 1}); if(!ret) return Data(); } }