Skip to content

Commit

Permalink
Improves performance in unconvirtable scenarios and cleans up logging…
Browse files Browse the repository at this point in the history
… and `-DQUIET` compliance.
  • Loading branch information
Matt Williamson committed Aug 24, 2022
1 parent e310b57 commit 35b86bb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/forcing/CsvPerFeatureForcingProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class CsvPerFeatureForcingProvider : public data_access::GenericDataProvider
}
catch (const std::runtime_error& e){
#ifndef UDUNITS_QUIET
std::cerr<<"Unit conversion error: "<<std::endl<<e.what()<<std::endl<<"Returning unconverted value!"<<std::endl;
std::cerr<<"WARN: Unit conversion unsuccessful - Returning unconverted value! (\""<<e.what()<<"\")"<<std::endl;
#endif
return value;
}
Expand Down
2 changes: 1 addition & 1 deletion include/forcing/NetCDFPerFeatureDataProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ namespace data_access
catch (const std::runtime_error& e)
{
#ifndef UDUNITS_QUIET
std::cerr<<"Unit conversion error: "<<std::endl<<e.what()<<std::endl<<"Returning unconverted value!"<<std::endl;
std::cerr<<"WARN: Unit conversion unsuccessful - Returning unconverted value! (\""<<e.what()<<"\")"<<std::endl;
#endif
return rvalue;
}
Expand Down
12 changes: 10 additions & 2 deletions include/realizations/catchment/Bmi_Module_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ namespace realization {
return values;
}
catch (const std::runtime_error& e){
std::cerr<<"Unit conversion error: "<<std::endl<<e.what()<<std::endl<<"Returning unconverted value!"<<std::endl;
#ifndef UDUNITS_QUIET
std::cerr<<"WARN: Unit conversion unsuccessful - Returning unconverted value! (\""<<e.what()<<"\")"<<std::endl;
#endif
return values;
}
}
Expand Down Expand Up @@ -487,7 +489,9 @@ namespace realization {
return UnitsHelper::get_converted_value(native_units, value, output_units);
}
catch (const std::runtime_error& e){
std::cerr<<"Unit conversion error: "<<std::endl<<e.what()<<std::endl<<"Returning unconverted value!"<<std::endl;
#ifndef UDUNITS_QUIET
std::cerr<<"WARN: Unit conversion unsuccessful - Returning unconverted value! (\""<<e.what()<<"\")"<<std::endl;
#endif
return value;
}
}
Expand Down Expand Up @@ -835,12 +839,16 @@ namespace realization {
case geojson::PropertyType::Natural:
param.second.as_vector(long_vec);
value_ptr = get_values_as_type(type, long_vec.begin(), long_vec.end());
#ifndef NGEN_QUIET
std::cout<<"NAT VALUE: "<<long_vec[0]<<std::endl;
#endif
break;
case geojson::PropertyType::Real:
param.second.as_vector(double_vec);
value_ptr = get_values_as_type(type, double_vec.begin(), double_vec.end());
#ifndef NGEN_QUIET
std::cout<<"REAL VALUE: "<<double_vec[0]<<std::endl;
#endif
break;
/* Not currently supporting string parameter values
case geojson::PropertyType::String:
Expand Down
5 changes: 5 additions & 0 deletions src/core/mediator/UnitsHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ std::shared_ptr<cv_converter> UnitsHelper::get_converter(const std::string& in_u

std::string key = in_units + "|" + out_units; //Better solution? Good enough? Bother with nested maps?
if(converters.count(key) == 1){
if(converters[key] == nullptr){
// same as last throw below
throw std::runtime_error("Unable to convert " + in_units + " to " + out_units);
}
return converters[key];
} else {
ut_unit* from = ut_parse(unit_system, in_units.c_str(), in_encoding);
Expand All @@ -34,6 +38,7 @@ std::shared_ptr<cv_converter> UnitsHelper::get_converter(const std::string& in_u
{
ut_free(from);
ut_free(to);
converters[key] = nullptr;
throw std::runtime_error("Unable to convert " + in_units + " to " + out_units);
}
auto c = std::shared_ptr<cv_converter>(
Expand Down

0 comments on commit 35b86bb

Please sign in to comment.