Browse Source

Sources may specify default variable lists for the tsc module.

interpolate
Michael Uleysky 1 year ago
parent
commit
9f4d7094dd
  1. 23
      actions/actiontsc.h
  2. 7
      include/traits.h
  3. 9
      sources/MODISBINLOCAL.h

23
actions/actiontsc.h

@ -24,20 +24,35 @@ template<class D> 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<D>)
varstring = ds.DefaultVars();
else
return "Variables not specified";
}
}
auto vlist = michlib::Split_on_words(varstring, " ,", false);
std::vector<MString> vnames{std::make_move_iterator(std::begin(vlist)), std::make_move_iterator(std::end(vlist))};
{
std::set<MString> 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<const BaseParameters> sourcepars;
if constexpr(ParametersSupported<D>)

7
include/traits.h

@ -13,6 +13,13 @@ concept InfoSupported = requires(T t) {
} -> std::convertible_to<MString>;
};
template<class T>
concept HasDefVars = requires(T t) {
{
t.DefaultVars()
} -> std::convertible_to<MString>;
};
template<class T>
concept ParametersRequiredRegion = requires(T t, michlib_internal::ParameterListEx& pars, const CLArgs& args, const struct Region& r) {
{

9
sources/MODISBINLOCAL.h

@ -43,6 +43,15 @@ class MODISBINLOCALData
bool Read(const MString& vname, std::map<MString, Data>& 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<const BaseParameters*, MString> Parameters(michlib_internal::ParameterListEx& pars, const CLArgs& args, const struct Region& reg) const;
bool CheckVar(const MString& vname) const

Loading…
Cancel
Save