Browse Source

Check if variable with this name already exist

master
Michael Uleysky 3 weeks ago
parent
commit
260ec1f8da
  1. 8
      include/Adapter.h
  2. 6
      src/CF.cpp

8
include/Adapter.h

@ -98,15 +98,19 @@ class Adapter
void SetTitle(const MString& t) { title = t; }
void Add2DVariable(const MString& name, std::unique_ptr<VInfoBase>&& vinfo, std::shared_ptr<Projection> proj, decltype(VarInfo().Read2D) func = Def2DReader)
bool Add2DVariable(const MString& name, std::unique_ptr<VInfoBase>&& vinfo, std::shared_ptr<Projection> proj, decltype(VarInfo().Read2D) func = Def2DReader)
{
if(vars.contains(name)) return false;
vars[name] = {.info = std::move(vinfo), .proj = proj, .Read2D = func, .Read3D = {}};
return true;
}
void Add3DVariable(const MString& name, std::unique_ptr<VInfoBase>&& vinfo, std::shared_ptr<Projection> proj, std::shared_ptr<Vertical> vert,
bool Add3DVariable(const MString& name, std::unique_ptr<VInfoBase>&& vinfo, std::shared_ptr<Projection> proj, std::shared_ptr<Vertical> vert,
decltype(VarInfo().Read3D) func = Def3DReader)
{
if(vars.contains(name)) return false;
vars[name] = {.info = std::move(vinfo), .proj = proj, .vert = vert, .Read2D = {}, .Read3D = func};
return true;
}
void CleanVariables(const std::set<MString>& keep)

6
src/CF.cpp

@ -443,9 +443,9 @@ Error CF::FillAdapterFromCF(const CLArgs& args, michlib_internal::ParameterListE
vinfo->targetunit = vinfo->unit;
if(vinfo->stname.SubStr(vinfo->stname.Len() - 7, 8) == "velocity") vinfo->targetunit = "cm/s";
MString name = StName2Name(vinfo->stname).Exist() ? StName2Name(vinfo->stname) : v;
if(dnames.size() == 3) { ad.Add2DVariable(name, Adapter::VInfo(vinfo), proj); }
else { ad.Add3DVariable(name, Adapter::VInfo(vinfo), proj, vert); }
MString name = StName2Name(vinfo->stname).Exist() ? StName2Name(vinfo->stname) : v;
const bool addsuc = dnames.size() == 3 ? ad.Add2DVariable(name, Adapter::VInfo(vinfo), proj) : ad.Add3DVariable(name, Adapter::VInfo(vinfo), proj, vert);
if(!addsuc) return {pref, "Variable with name " + name + " already exist"};
}
return Error();

Loading…
Cancel
Save