Browse Source

We distinguish between conventional and geostrophic velocities, since some data sets contain both.

lintest
Michael Uleysky 8 months ago
parent
commit
91579910ff
  1. 38
      actions/actiongenintfile.h
  2. 46
      actions/actionuv.h
  3. 95
      include/actiondep.h
  4. 8
      src/ncfuncs.cpp

38
actions/actiongenintfile.h

@ -23,7 +23,19 @@ template<class D> MString ActionGenIntFile::DoAction(const CLArgs& args, D& ds)
if(!args.contains("out")) return "Output file name not specified";
bool mode = args.contains("geostrophic");
VelSource mode = VelSource::AUTOSEL;
if(args.contains("geostrophic"))
{
auto modestr = args.at("geostrophic");
if(modestr == "" || modestr == "ssh")
mode = VelSource::GEOSTROPHICSSH;
else if(modestr == "surf" || modestr == "surface")
mode = VelSource::GEOSTROPHIC;
else if(modestr == "nongeo")
mode = VelSource::STANDART;
else
return "Parameter \"geostrophic\" have incorrect value " + modestr;
}
auto [tindexes, err] = GetTIndexes(ds, args, pars);
if(err.Exist()) return err;
@ -72,7 +84,29 @@ template<class D> MString ActionGenIntFile::DoAction(const CLArgs& args, D& ds)
fw.SetParameter("dt", (ds.Time(tindexes[1]) - ds.Time(tindexes[0])).D());
fw.SetParameter("FillValue", data.Fillval());
fw.UsePrefix("Info");
fw.SetParameter("Mode", mode ? "from ssh" : "normal");
switch(mode)
{
case(VelSource::AUTOSEL):
{
fw.SetParameter("Mode", "autoselect between standart and geostrophic");
break;
}
case(VelSource::STANDART):
{
fw.SetParameter("Mode", "standart");
break;
}
case(VelSource::GEOSTROPHIC):
{
fw.SetParameter("Mode", "geostrophic");
break;
}
case(VelSource::GEOSTROPHICSSH):
{
fw.SetParameter("Mode", "geostrophic from ssh");
break;
}
}
fw.SetParameter("lonb", lonb);
fw.SetParameter("latb", latb);
fw.SetParameter("lone", lone);

46
actions/actionuv.h

@ -119,7 +119,19 @@ template<class D> MString ActionUV::DoAction(const CLArgs& args, D& ds)
pars.SetParameter("source", args.at("source"));
pars.SetParameter("history", args.at("_cmdline"));
bool mode = args.contains("geostrophic");
VelSource mode = VelSource::AUTOSEL;
if(args.contains("geostrophic"))
{
auto modestr = args.at("geostrophic");
if(modestr == "" || modestr == "ssh")
mode = VelSource::GEOSTROPHICSSH;
else if(modestr == "surf" || modestr == "surface")
mode = VelSource::GEOSTROPHIC;
else if(modestr == "nongeo")
mode = VelSource::STANDART;
else
return "Parameter \"geostrophic\" have incorrect value " + modestr;
}
auto [tindexes, err] = GetTIndexes(ds, args, pars);
if(err.Exist()) return err;
@ -229,24 +241,12 @@ template<class D> MString ActionUV::DoAction(const CLArgs& args, D& ds)
if(!err.Exist() && !headwrited) err = fw.AddVariable("eke", "", "Squared velocity dispersion aka eddy kinetic energy, <u^2+v^2>-<u>^2-<v>^2", "(" + velunit + ")2", "");
if(!err.Exist() && !headwrited) err = fw.WriteGrid(data);
if(!err.Exist())
err = fw.WriteVariable(
data, "u", [&data = std::as_const(data)](size_t i, size_t j) { return data.U(i, j); }, it);
if(!err.Exist())
err = fw.WriteVariable(
data, "v", [&data = std::as_const(data)](size_t i, size_t j) { return data.V(i, j); }, it);
if(!err.Exist())
err = fw.WriteVariable(
data, "div", [&data = std::as_const(data)](size_t i, size_t j) { return data.Div(i, j); }, it);
if(!err.Exist())
err = fw.WriteVariable(
data, "rot", [&data = std::as_const(data)](size_t i, size_t j) { return data.Rot(i, j); }, it);
if(!err.Exist())
err = fw.WriteVariable(
data, "ow", [&data = std::as_const(data)](size_t i, size_t j) { return data.OW(i, j); }, it);
if(!err.Exist())
err = fw.WriteVariable(
data, "ke", [&data = std::as_const(data)](size_t i, size_t j) { return data.U2(i, j); }, it);
if(!err.Exist()) err = fw.WriteVariable(data, "u", [&data = std::as_const(data)](size_t i, size_t j) { return data.U(i, j); }, it);
if(!err.Exist()) err = fw.WriteVariable(data, "v", [&data = std::as_const(data)](size_t i, size_t j) { return data.V(i, j); }, it);
if(!err.Exist()) err = fw.WriteVariable(data, "div", [&data = std::as_const(data)](size_t i, size_t j) { return data.Div(i, j); }, it);
if(!err.Exist()) err = fw.WriteVariable(data, "rot", [&data = std::as_const(data)](size_t i, size_t j) { return data.Rot(i, j); }, it);
if(!err.Exist()) err = fw.WriteVariable(data, "ow", [&data = std::as_const(data)](size_t i, size_t j) { return data.OW(i, j); }, it);
if(!err.Exist()) err = fw.WriteVariable(data, "ke", [&data = std::as_const(data)](size_t i, size_t j) { return data.U2(i, j); }, it);
if(!err.Exist())
err = fw.WriteVariable(
data, "eke", [&data = std::as_const(data)](size_t i, size_t j) { return data.U2(i, j) - (data.U(i, j) * data.U(i, j) + data.V(i, j) * data.V(i, j)); }, it);
@ -292,12 +292,8 @@ template<class D> MString ActionUV::DoAction(const CLArgs& args, D& ds)
if(!err.Exist() && !headwrited) err = fwfilt.AddVariable("v", "", "Northward velocity", velunit, "");
if(!err.Exist() && !headwrited) err = fwfilt.WriteGrid(sdata);
if(!err.Exist())
err = fwfilt.WriteVariable(
sdata, "u", [&data = std::as_const(sdata)](size_t i, size_t j) { return data.U(i, j); }, it);
if(!err.Exist())
err = fwfilt.WriteVariable(
sdata, "v", [&data = std::as_const(sdata)](size_t i, size_t j) { return data.V(i, j); }, it);
if(!err.Exist()) err = fwfilt.WriteVariable(sdata, "u", [&data = std::as_const(sdata)](size_t i, size_t j) { return data.U(i, j); }, it);
if(!err.Exist()) err = fwfilt.WriteVariable(sdata, "v", [&data = std::as_const(sdata)](size_t i, size_t j) { return data.V(i, j); }, it);
if(err.Exist()) return err;
}
else

95
include/actiondep.h

@ -23,6 +23,14 @@ using michlib::MDateTime;
};
#endif
enum class VelSource
{
AUTOSEL,
STANDART,
GEOSTROPHIC,
GEOSTROPHICSSH
};
struct TimeData
{
static constexpr auto stepunits = std::to_array<uint>({3600 * 24, 3600, 60, 1});
@ -187,15 +195,49 @@ template<class D> std::vector<ReadType<D>> Read(const D& data, const std::vector
return out;
}
template<class D> UVData<ReadType<D>> ReadUV(const D& data, const BaseParameters* p, size_t ind, bool usegeo)
template<class D> UVData<ReadType<D>> ReadUV(const D& data, const BaseParameters* p, size_t ind, VelSource usegeo)
{
using RT = ReadType<D>;
using UV = UVData<RT>;
michlib::message("Time: " + data.Time(ind).ToTString());
std::map<MString, RT> cache;
bool res = false;
const MString uname = usegeo ? "ugeo" : "u";
const MString vname = usegeo ? "vgeo" : "v";
bool res = false;
MString uname, vname;
switch(usegeo)
{
case(VelSource::AUTOSEL):
{
if(data.CheckVar("u") == VarPresence::INTERNAL && data.CheckVar("v") == VarPresence::INTERNAL)
{
uname = "u";
vname = "v";
}
else
{
uname = "ugs";
vname = "vgs";
}
break;
}
case(VelSource::STANDART):
{
uname = "u";
vname = "v";
break;
}
case(VelSource::GEOSTROPHIC):
{
uname = "ugs";
vname = "vgs";
break;
}
case(VelSource::GEOSTROPHICSSH):
{
uname = "ugeo";
vname = "vgeo";
break;
}
}
if constexpr(ReadPSupported<D>)
res = data.Read(uname, cache, p, ind) && data.Read(vname, cache, p, ind);
else if constexpr(ReadSupported<D>)
@ -205,12 +247,47 @@ template<class D> UVData<ReadType<D>> ReadUV(const D& data, const BaseParameters
return UV(cache.at(uname), cache.at(vname));
}
template<class D> UVData<ReadType<D>> ReadUV(const D& data, const BaseParameters* p, const TIndex& tindex, bool usegeo)
template<class D> UVData<ReadType<D>> ReadUV(const D& data, const BaseParameters* p, const TIndex& tindex, VelSource usegeo)
{
using RT = ReadType<D>;
using UV = UVData<RT>;
const MString uname = usegeo ? "ugeo" : "u";
const MString vname = usegeo ? "vgeo" : "v";
using RT = ReadType<D>;
using UV = UVData<RT>;
MString uname, vname;
switch(usegeo)
{
case(VelSource::AUTOSEL):
{
if(data.CheckVar("u") == VarPresence::INTERNAL && data.CheckVar("v") == VarPresence::INTERNAL)
{
uname = "u";
vname = "v";
}
else
{
uname = "ugs";
vname = "vgs";
}
break;
}
case(VelSource::STANDART):
{
uname = "u";
vname = "v";
break;
}
case(VelSource::GEOSTROPHIC):
{
uname = "ugs";
vname = "vgs";
break;
}
case(VelSource::GEOSTROPHICSSH):
{
uname = "ugeo";
vname = "vgeo";
break;
}
}
if(tindex.size() == 1)
return ReadUV(data, p, tindex[0], usegeo);

8
src/ncfuncs.cpp

@ -208,9 +208,9 @@ MString NCFuncs::StName2Name(const MString& stname)
if(stname == "sea_surface_elevation") return "ssh";
if(stname == "eastward_sea_water_velocity") return "u";
if(stname == "northward_sea_water_velocity") return "v";
if(stname == "surface_geostrophic_eastward_sea_water_velocity") return "u";
if(stname == "surface_geostrophic_northward_sea_water_velocity") return "v";
if(stname == "upward_sea_water_velocity") return "w";
if(stname == "surface_geostrophic_eastward_sea_water_velocity") return "ugs";
if(stname == "surface_geostrophic_northward_sea_water_velocity") return "vgs";
if(stname == "mass_concentration_of_chlorophyll_a_in_sea_water") return "chl";
if(stname == "mole_concentration_of_nitrate_in_sea_water") return "NO3";
if(stname == "net_primary_production_of_biomass_expressed_as_carbon_per_unit_volume_in_sea_water") return "prprod";
@ -230,6 +230,8 @@ MString NCFuncs::Name2StName(const MString& name)
if(name == "u") return "eastward_sea_water_velocity";
if(name == "v") return "northward_sea_water_velocity";
if(name == "w") return "upward_sea_water_velocity";
if(name == "ugs") return "surface_geostrophic_eastward_sea_water_velocity";
if(name == "vgs") return "surface_geostrophic_northward_sea_water_velocity";
if(name == "chl") return "mass_concentration_of_chlorophyll_a_in_sea_water";
if(name == "NO3") return "mole_concentration_of_nitrate_in_sea_water";
if(name == "prprod") return "net_primary_production_of_biomass_expressed_as_carbon_per_unit_volume_in_sea_water";
@ -251,6 +253,8 @@ MString NCFuncs::Name2LongName(const MString& name)
if(name == "w") return "Z-velocity";
if(name == "ugeo") return "Geostrophic eastward velocity from ssh";
if(name == "vgeo") return "Geostrophic northward velocity from ssh";
if(name == "ugs") return "Geostrophic eastward velocity";
if(name == "vgs") return "Geostrophic northward velocity";
if(name == "chl") return "Concentration of chlorophyll";
if(name == "NO3") return "Concentration of nitrates";
if(name == "prprod") return "Primary production";

Loading…
Cancel
Save