Skip to content

Commit

Permalink
Merge Pull Request #2596 from E3SM-Project/scream/bartgol/io/fp-preci…
Browse files Browse the repository at this point in the history
…sion-nano-fix

Automatically Merged using E3SM Pull Request AutoTester
PR Title: EAMxx: fix setting of FillValue based on fp precision
PR Author: bartgol
PR LABELS: I/O, AT: AUTOMERGE, bugfix
  • Loading branch information
E3SM-Autotester authored Nov 14, 2023
2 parents 225cbb8 + 6fea441 commit 8e28e91
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
12 changes: 9 additions & 3 deletions components/eamxx/src/share/io/scorpio_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,9 +896,14 @@ register_variables(const std::string& filename,
const std::string& fp_precision,
const scorpio::FileMode mode)
{

using namespace scorpio;
using namespace ShortFieldTagsNames;
using strvec_t = std::vector<std::string>;

EKAT_REQUIRE_MSG (ekat::contains(strvec_t{"float","single","double","real"},fp_precision),
"Error! Invalid/unsupported value for fp_precision.\n"
" - input value: " + fp_precision + "\n"
" - supported values: float, single, double, real\n");

// Helper lambdas
auto set_decomp_tag = [&](const FieldLayout& layout) {
Expand Down Expand Up @@ -963,8 +968,9 @@ register_variables(const std::string& filename,
if (mode != FileMode::Append ) {
// Add FillValue as an attribute of each variable
// FillValue is a protected metadata, do not add it if it already existed
if (fp_precision == "real") {
Real fill_value = m_fill_value;
if (fp_precision=="double" or
(fp_precision=="real" and std::is_same<Real,double>::value)) {
double fill_value = m_fill_value;
set_variable_metadata(filename, name, "_FillValue",fill_value);
} else {
float fill_value = m_fill_value;
Expand Down
12 changes: 8 additions & 4 deletions components/eamxx/src/share/io/scream_output_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,11 @@ void OutputManager::
set_params (const ekat::ParameterList& params,
const std::map<std::string,std::shared_ptr<fm_type>>& field_mgrs)
{
using vos_t = std::vector<std::string>;

m_params = params;
if (m_is_model_restart_output) {
using vos_t = std::vector<std::string>;

if (m_is_model_restart_output) {
// We build some restart parameters internally
auto avg_type = m_params.get<std::string>("Averaging Type","INSTANT");
m_avg_type = str2avg(avg_type);
Expand Down Expand Up @@ -614,8 +615,11 @@ set_params (const ekat::ParameterList& params,
// Allow user to ask for higher precision for normal model output,
// but default to single to save on storage
const auto& prec = m_params.get<std::string>("Floating Point Precision", "single");
EKAT_REQUIRE_MSG (prec=="single" || prec=="double" || prec=="real",
"Error! Invalid floating point precision '" + prec + "'.\n");
vos_t valid_prec = {"single", "float", "double", "real"};
EKAT_REQUIRE_MSG (ekat::contains(valid_prec,prec),
"Error! Invalid/unsupported value for 'Floating Point Precision'.\n"
" - input value: " + prec + "\n"
" - supported values: float, single, double, real\n");
}
}
/*===============================================================================================*/
Expand Down
5 changes: 5 additions & 0 deletions components/eamxx/src/share/io/tests/io_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ void write (const std::string& avg_type, const std::string& freq_units,

// Create Output manager
OutputManager om;

// Attempt to use invalid fp precision string
om_pl.set("Floating Point Precision",std::string("triple"));
REQUIRE_THROWS (om.setup(comm,om_pl,fm,gm,t0,t0,false));
om_pl.set("Floating Point Precision",std::string("single"));
om.setup(comm,om_pl,fm,gm,t0,t0,false);

// Time loop: ensure we always hit 3 output steps
Expand Down

0 comments on commit 8e28e91

Please sign in to comment.