From 91579910ff3a49ac58a6348d42d79d7d5a2ca6ba Mon Sep 17 00:00:00 2001 From: Michael Uleysky Date: Fri, 19 Apr 2024 13:23:26 +1000 Subject: [PATCH] We distinguish between conventional and geostrophic velocities, since some data sets contain both. --- actions/actiongenintfile.h | 38 ++++++++++++++- actions/actionuv.h | 46 +++++++++--------- include/actiondep.h | 95 ++++++++++++++++++++++++++++++++++---- src/ncfuncs.cpp | 8 +++- 4 files changed, 149 insertions(+), 38 deletions(-) diff --git a/actions/actiongenintfile.h b/actions/actiongenintfile.h index 48a3f49..d53a4f7 100644 --- a/actions/actiongenintfile.h +++ b/actions/actiongenintfile.h @@ -23,7 +23,19 @@ template 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 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); diff --git a/actions/actionuv.h b/actions/actionuv.h index fc4a3f6..ebe4d41 100644 --- a/actions/actionuv.h +++ b/actions/actionuv.h @@ -119,7 +119,19 @@ template 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 MString ActionUV::DoAction(const CLArgs& args, D& ds) if(!err.Exist() && !headwrited) err = fw.AddVariable("eke", "", "Squared velocity dispersion aka eddy kinetic energy, -^2-^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 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 diff --git a/include/actiondep.h b/include/actiondep.h index d7c1df6..5db0be9 100644 --- a/include/actiondep.h +++ b/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({3600 * 24, 3600, 60, 1}); @@ -187,15 +195,49 @@ template std::vector> Read(const D& data, const std::vector return out; } -template UVData> ReadUV(const D& data, const BaseParameters* p, size_t ind, bool usegeo) +template UVData> ReadUV(const D& data, const BaseParameters* p, size_t ind, VelSource usegeo) { using RT = ReadType; using UV = UVData; michlib::message("Time: " + data.Time(ind).ToTString()); std::map 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) res = data.Read(uname, cache, p, ind) && data.Read(vname, cache, p, ind); else if constexpr(ReadSupported) @@ -205,12 +247,47 @@ template UVData> ReadUV(const D& data, const BaseParameters return UV(cache.at(uname), cache.at(vname)); } -template UVData> ReadUV(const D& data, const BaseParameters* p, const TIndex& tindex, bool usegeo) +template UVData> ReadUV(const D& data, const BaseParameters* p, const TIndex& tindex, VelSource usegeo) { - using RT = ReadType; - using UV = UVData; - const MString uname = usegeo ? "ugeo" : "u"; - const MString vname = usegeo ? "vgeo" : "v"; + using RT = ReadType; + using UV = UVData; + + 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); diff --git a/src/ncfuncs.cpp b/src/ncfuncs.cpp index efa5f87..a19e329 100644 --- a/src/ncfuncs.cpp +++ b/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";