Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove custom time unit conversion in favor of UDUNITS #627

Closed
mattw-nws opened this issue Sep 5, 2023 · 0 comments · Fixed by #633
Closed

Remove custom time unit conversion in favor of UDUNITS #627

mattw-nws opened this issue Sep 5, 2023 · 0 comments · Fixed by #633
Assignees

Comments

@mattw-nws
Copy link
Contributor

mattw-nws commented Sep 5, 2023

The following exists:

void acquire_time_conversion_factor(double &time_convert_factor) {
std::string time_units = GetTimeUnits();
if (time_units == "s" || time_units == "sec" || time_units == "second" || time_units == "seconds")
time_convert_factor = 1.0;
else if (time_units == "m" || time_units == "min" || time_units == "minute" ||
time_units == "minutes")
time_convert_factor = 60.0;
else if (time_units == "h" || time_units == "hr" || time_units == "hour" || time_units == "hours")
time_convert_factor = 3600.0;
else if (time_units == "d" || time_units == "day" || time_units == "days")
time_convert_factor = 86400.0;
else
throw std::runtime_error(
"Invalid model time step units ('" + time_units + "') in " + model_name + ".");
}

The BMI docs for get_time_units state:

It’s recommended to use time unit conventions from Unidata’s UDUNITS package; e.g., "s", "min", "h", "d".

Replace the time unit conversion code above with the use of UnitsHelper/UDUNITS for consistency.

Bonus/Future: Consider an optimization for the case when the native units of the model are seconds? UnitsHelper does this somewhat, but it might be worthwhile to highly optimize this function that is called every timestep.

Current behavior

time units are converted with bespoke internal code which may not be consistent with UDUNITS conversion

Expected behavior

unit conversions are consistent across the application and with UDUNITS as suggested by the BMI docs.

Steps to replicate behavior (include URLs)

Screenshots

@mattw-nws mattw-nws linked a pull request Sep 8, 2023 that will close this issue
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants