From 9f4d7094dd52892c02ffa8dca00eadfda9bdfae5 Mon Sep 17 00:00:00 2001 From: Michael Uleysky Date: Fri, 4 Aug 2023 12:39:34 +1000 Subject: [PATCH] Sources may specify default variable lists for the tsc module. --- actions/actiontsc.h | 23 +++++++++++++++++++---- include/traits.h | 7 +++++++ sources/MODISBINLOCAL.h | 9 +++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/actions/actiontsc.h b/actions/actiontsc.h index 1a071bd..3fde8ae 100644 --- a/actions/actiontsc.h +++ b/actions/actiontsc.h @@ -24,20 +24,35 @@ template MString ActionTSC::DoAction(const CLArgs& args, D& ds) auto [tindexes, err] = GetTIndexes(ds, args, pars); if(err.Exist()) return err; - if(!args.contains("var")) return "Variables not specified"; - auto vlist = michlib::Split_on_words(args.at("var"), " ,", false); + MString varstring; + if(args.contains("var")) + varstring = args.at("var"); + else + { + if(args.contains("vars")) + varstring = args.at("vars"); + else + { + if constexpr(HasDefVars) + varstring = ds.DefaultVars(); + else + return "Variables not specified"; + } + } + + auto vlist = michlib::Split_on_words(varstring, " ,", false); std::vector vnames{std::make_move_iterator(std::begin(vlist)), std::make_move_iterator(std::end(vlist))}; { std::set used; for(const auto& vname: vnames) { - if(used.contains(vname)) return "Duplicate variable " + vname + " in list " + args.at("var"); + if(used.contains(vname)) return "Duplicate variable " + vname + " in list " + varstring; if(!ds.CheckVar(vname)) return "Variable " + vname + " not exists in this dataset"; used.insert(vname); } } - pars.SetParameter("variables", args.at("var")); + pars.SetParameter("variables", varstring); std::unique_ptr sourcepars; if constexpr(ParametersSupported) diff --git a/include/traits.h b/include/traits.h index f19ae71..0807699 100644 --- a/include/traits.h +++ b/include/traits.h @@ -13,6 +13,13 @@ concept InfoSupported = requires(T t) { } -> std::convertible_to; }; +template +concept HasDefVars = requires(T t) { + { + t.DefaultVars() + } -> std::convertible_to; +}; + template concept ParametersRequiredRegion = requires(T t, michlib_internal::ParameterListEx& pars, const CLArgs& args, const struct Region& r) { { diff --git a/sources/MODISBINLOCAL.h b/sources/MODISBINLOCAL.h index 663647f..e5ed801 100644 --- a/sources/MODISBINLOCAL.h +++ b/sources/MODISBINLOCAL.h @@ -43,6 +43,15 @@ class MODISBINLOCALData bool Read(const MString& vname, std::map& cache, const BaseParameters* ip, size_t tind) const; Data ReadFile(const MString& suf, const struct Parameters* p, size_t tind) const; + MString DefaultVars() const + { + if(dataset.size() == 0) return ""; + if(dataset[0] == "CHL" || dataset[0] == "T_CHL" || dataset[0] == "A_CHL") + return "chl"; + else + return "temp"; + } + std::pair Parameters(michlib_internal::ParameterListEx& pars, const CLArgs& args, const struct Region& reg) const; bool CheckVar(const MString& vname) const