|
|
@ -178,10 +178,10 @@ std::pair<const BaseParameters*, MString> LayeredData::Parameters(michlib_intern |
|
|
|
return {ppar.release(), ""}; |
|
|
|
return {ppar.release(), ""}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LayeredData::Data LayeredData::Read(const MString& vname, const BaseParameters* ip, size_t i) const |
|
|
|
bool LayeredData::Read(const MString& vname, std::map<MString, LayeredData::Data>& cache, const BaseParameters* ip, size_t i) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(!isOk()) return Data(); |
|
|
|
if(cache.contains(vname)) return true; |
|
|
|
bool nodepth = false; |
|
|
|
if(!isOk()) return false; |
|
|
|
|
|
|
|
|
|
|
|
auto p = dynamic_cast<const struct Parameters*>(ip); |
|
|
|
auto p = dynamic_cast<const struct Parameters*>(ip); |
|
|
|
auto [name, id, tid] = VarNameLoc(vname, times[i]); |
|
|
|
auto [name, id, tid] = VarNameLoc(vname, times[i]); |
|
|
@ -190,86 +190,101 @@ LayeredData::Data LayeredData::Read(const MString& vname, const BaseParameters* |
|
|
|
// ptemp from temp and sal
|
|
|
|
// ptemp from temp and sal
|
|
|
|
if(vname == "ptemp") |
|
|
|
if(vname == "ptemp") |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto temp = Read("temp", ip, i); |
|
|
|
if(!(Read("temp", cache, ip, i) && Read("sal", cache, ip, i))) return false; |
|
|
|
auto sal = Read("sal", ip, i); |
|
|
|
cache[vname] = cache.at("temp").CopyGrid(); |
|
|
|
if(!(temp && sal)) return Data(); |
|
|
|
auto& ptemp = cache.at(vname); |
|
|
|
temp.SetUnit("degrees_C"); |
|
|
|
const auto& temp = cache.at("temp"); |
|
|
|
for(size_t ind = 0; ind < temp.N(); ind++) |
|
|
|
const auto& sal = cache.at("sal"); |
|
|
|
|
|
|
|
ptemp.SetUnit("degrees_C"); |
|
|
|
|
|
|
|
for(size_t ind = 0; ind < ptemp.N(); ind++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(temp.IsFill(ind) || sal.IsFill(ind)) |
|
|
|
if(temp.IsFill(ind) || sal.IsFill(ind)) |
|
|
|
temp.V(ind) = temp.Fillval(); |
|
|
|
ptemp.V(ind) = ptemp.Fillval(); |
|
|
|
else |
|
|
|
else |
|
|
|
temp.V(ind) = Temp2PTemp(temp.V(ind), sal.V(ind), Depth(p->layer), temp.Lon(ind), temp.Lat(ind)); |
|
|
|
ptemp.V(ind) = Temp2PTemp(temp.V(ind), sal.V(ind), Depth(p->layer), ptemp.Lon(ind), ptemp.Lat(ind)); |
|
|
|
} |
|
|
|
} |
|
|
|
return temp; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
// temp from ptemp and sal
|
|
|
|
// temp from ptemp and sal
|
|
|
|
if(vname == "temp") |
|
|
|
if(vname == "temp") |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto temp = Read("ptemp", ip, i); |
|
|
|
if(!(Read("ptemp", cache, ip, i) && Read("sal", cache, ip, i))) return false; |
|
|
|
auto sal = Read("sal", ip, i); |
|
|
|
cache[vname] = cache.at("ptemp").CopyGrid(); |
|
|
|
if(!(temp && sal)) return Data(); |
|
|
|
auto& temp = cache.at(vname); |
|
|
|
|
|
|
|
const auto& ptemp = cache.at("ptemp"); |
|
|
|
|
|
|
|
const auto& sal = cache.at("sal"); |
|
|
|
temp.SetUnit("degrees_C"); |
|
|
|
temp.SetUnit("degrees_C"); |
|
|
|
for(size_t ind = 0; ind < temp.N(); ind++) |
|
|
|
for(size_t ind = 0; ind < temp.N(); ind++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(temp.IsFill(ind) || sal.IsFill(ind)) |
|
|
|
if(ptemp.IsFill(ind) || sal.IsFill(ind)) |
|
|
|
temp.V(ind) = temp.Fillval(); |
|
|
|
temp.V(ind) = temp.Fillval(); |
|
|
|
else |
|
|
|
else |
|
|
|
temp.V(ind) = PTemp2Temp(temp.V(ind), sal.V(ind), Depth(p->layer), temp.Lon(ind), temp.Lat(ind)); |
|
|
|
temp.V(ind) = PTemp2Temp(ptemp.V(ind), sal.V(ind), Depth(p->layer), temp.Lon(ind), temp.Lat(ind)); |
|
|
|
} |
|
|
|
} |
|
|
|
return temp; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
// pdens from temp and sal
|
|
|
|
// pdens from temp and sal
|
|
|
|
if(vname == "pdens") |
|
|
|
if(vname == "pdens") |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool tempispot = HaveVar("ptemp"); |
|
|
|
bool tempispot = HaveVar("ptemp"); |
|
|
|
auto temp = Read(tempispot ? "ptemp" : "temp", ip, i); |
|
|
|
if(!(Read(tempispot ? "ptemp" : "temp", cache, ip, i) && Read("sal", cache, ip, i))) return false; |
|
|
|
auto sal = Read("sal", ip, i); |
|
|
|
cache[vname] = cache.at("sal").CopyGrid(); |
|
|
|
if(!(temp && sal)) return Data(); |
|
|
|
auto& pdens = cache.at(vname); |
|
|
|
temp.SetUnit("kg m-3"); |
|
|
|
const auto& temp = cache.at(tempispot ? "ptemp" : "temp"); |
|
|
|
for(size_t ind = 0; ind < temp.N(); ind++) |
|
|
|
const auto& sal = cache.at("sal"); |
|
|
|
|
|
|
|
pdens.SetUnit("kg m-3"); |
|
|
|
|
|
|
|
for(size_t ind = 0; ind < pdens.N(); ind++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(temp.IsFill(ind) || sal.IsFill(ind)) |
|
|
|
if(temp.IsFill(ind) || sal.IsFill(ind)) |
|
|
|
temp.V(ind) = temp.Fillval(); |
|
|
|
pdens.V(ind) = pdens.Fillval(); |
|
|
|
else |
|
|
|
else |
|
|
|
temp.V(ind) = tempispot ? PTemp2PDens(temp.V(ind), sal.V(ind), Depth(p->layer), temp.Lon(ind), temp.Lat(ind)) |
|
|
|
pdens.V(ind) = tempispot ? PTemp2PDens(temp.V(ind), sal.V(ind), Depth(p->layer), pdens.Lon(ind), pdens.Lat(ind)) |
|
|
|
: Temp2PDens(temp.V(ind), sal.V(ind), Depth(p->layer), temp.Lon(ind), temp.Lat(ind)); |
|
|
|
: Temp2PDens(temp.V(ind), sal.V(ind), Depth(p->layer), pdens.Lon(ind), pdens.Lat(ind)); |
|
|
|
} |
|
|
|
} |
|
|
|
return temp; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
// U and U2 from u and v
|
|
|
|
// U and U2 from u and v
|
|
|
|
if(vname == "U" || vname == "U2") |
|
|
|
if(vname == "U" || vname == "U2") |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool square = vname == "U2"; |
|
|
|
bool square = vname == "U2"; |
|
|
|
auto u = Read("u", ip, i); |
|
|
|
if(!(Read("u", cache, ip, i) && Read("v", cache, ip, i))) return false; |
|
|
|
auto v = Read("v", ip, i); |
|
|
|
cache[vname] = cache.at("u").CopyGrid(); |
|
|
|
if(!(u && v)) return Data(); |
|
|
|
auto& U = cache.at(vname); |
|
|
|
if(square && u.Unit().Exist()) u.SetUnit("(" + u.Unit() + ")2"); |
|
|
|
const auto& u = cache.at("u"); |
|
|
|
for(size_t ind = 0; ind < u.N(); ind++) |
|
|
|
const auto& v = cache.at("v"); |
|
|
|
|
|
|
|
if(u.Unit().Exist()) U.SetUnit(square ? ("(" + u.Unit() + ")2") : u.Unit()); |
|
|
|
|
|
|
|
for(size_t ind = 0; ind < U.N(); ind++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(u.IsFill(ind) || v.IsFill(ind)) |
|
|
|
if(u.IsFill(ind) || v.IsFill(ind)) |
|
|
|
u.V(ind) = u.Fillval(); |
|
|
|
U.V(ind) = U.Fillval(); |
|
|
|
else |
|
|
|
else |
|
|
|
u.V(ind) = square ? (u(ind) * u(ind) + v(ind) * v(ind)) : michlib::Hypot(u(ind), v(ind)); |
|
|
|
U.V(ind) = square ? (u(ind) * u(ind) + v(ind) * v(ind)) : michlib::Hypot(u(ind), v(ind)); |
|
|
|
} |
|
|
|
} |
|
|
|
return u; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return Data(); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Direct read
|
|
|
|
// Direct read
|
|
|
|
|
|
|
|
bool nodepth = false; |
|
|
|
|
|
|
|
Data data; |
|
|
|
auto head = nc[id]->Header(); |
|
|
|
auto head = nc[id]->Header(); |
|
|
|
for(const auto& v: head.Variables()) |
|
|
|
for(const auto& v: head.Variables()) |
|
|
|
if(v.Name() == name) |
|
|
|
if(v.Name() == name) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(v.Dimensions().size() == 3) nodepth = true; |
|
|
|
if(v.Dimensions().size() == 3) nodepth = true; |
|
|
|
if(v.Type().Id() == NC_SHORT) return ReadVarRaw<int2>(nc[id], name, tid, nodepth, p); |
|
|
|
if(v.Type().Id() == NC_SHORT) data = ReadVarRaw<int2>(nc[id], name, tid, nodepth, p); |
|
|
|
if(v.Type().Id() == NC_INT) return ReadVarRaw<int>(nc[id], name, tid, nodepth, p); |
|
|
|
if(v.Type().Id() == NC_INT) data = ReadVarRaw<int>(nc[id], name, tid, nodepth, p); |
|
|
|
if(v.Type().Id() == NC_FLOAT) return ReadVarRaw<float>(nc[id], name, tid, nodepth, p); |
|
|
|
if(v.Type().Id() == NC_FLOAT) data = ReadVarRaw<float>(nc[id], name, tid, nodepth, p); |
|
|
|
if(v.Type().Id() == NC_DOUBLE) return ReadVarRaw<double>(nc[id], name, tid, nodepth, p); |
|
|
|
if(v.Type().Id() == NC_DOUBLE) data = ReadVarRaw<double>(nc[id], name, tid, nodepth, p); |
|
|
|
|
|
|
|
if(data) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
cache[vname] = std::move(data); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return Data(); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template<class DataType> LayeredData::Data LayeredData::ReadVarRaw(const NC& f, const MString& name, size_t i, bool nodepth, const struct LayeredData::Parameters* p) const |
|
|
|
template<class DataType> LayeredData::Data LayeredData::ReadVarRaw(const NC& f, const MString& name, size_t i, bool nodepth, const struct LayeredData::Parameters* p) const |
|
|
|