Skip to content

Commit

Permalink
feat(ForcingsEngineDataProvider): add ensure_variable member for alia…
Browse files Browse the repository at this point in the history
…sing variable names to forcings engine names
  • Loading branch information
program-- committed Jul 24, 2024
1 parent 359fc6a commit 110b9bb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions include/forcing/ForcingsEngineDataProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,27 @@ struct ForcingsEngineDataProvider
var_output_names_ = bmi_->GetOutputVarNames();
}

std::string ensure_variable(std::string name, const std::string& suffix = "_ELEMENT") const
{
// TODO: use get_available_var_names() once const
auto vars = boost::span<const std::string>{var_output_names_};

if (std::find(vars.begin(), vars.end(), name) != vars.end()) {
return name;
}

auto suffixed_name = std::move(name) + suffix;
if (std::find(vars.begin(), vars.end(), suffixed_name) != vars.end()) {
return suffixed_name;
}

throw std::runtime_error{
"ForcingsEngineDataProvider: neither variable `"
+ suffixed_name.substr(0, suffixed_name.size() - suffix.size())
+ "` nor `" + suffixed_name + "` exist."
};
}

//! Forcings Engine instance
std::shared_ptr<models::bmi::Bmi_Py_Adapter> bmi_ = nullptr;

Expand Down

0 comments on commit 110b9bb

Please sign in to comment.