From f94a7290dff79e31ab74a53904a4634f745850b7 Mon Sep 17 00:00:00 2001 From: Kitware Robot Date: Wed, 8 Jan 2025 18:25:46 -0800 Subject: [PATCH] Fix error of writing fillValue attribute after writing data --- io/teca_cf_layout_manager.cxx | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/io/teca_cf_layout_manager.cxx b/io/teca_cf_layout_manager.cxx index 68a36b5d..6d3e44f2 100644 --- a/io/teca_cf_layout_manager.cxx +++ b/io/teca_cf_layout_manager.cxx @@ -449,9 +449,28 @@ int teca_cf_layout_manager::define(const teca_metadata &md_in, #endif ) + // First implementation: Save the var to var_def so that attributes + // get written with other variables + // -> This caused an error when trying to write the attribute + // "_FillValue" after writing the data. // save the var id - this->var_def[coord_array_names[i]] = var_def_t(parent_id, var_id, - var_type_code); + // this->var_def[coord_array_names[i]] = var_def_t(parent_id, var_id, + // var_type_code); + + // Second implementation: + // write variable attributes + // this needs to be done before writing arrays to avoid a NetCDF error + // of specifying fill value when data already exists. + teca_metadata array_atts; + if (array_attributes.get(coord_array_names[i], array_atts) == 0) + { + if (teca_netcdf_util::write_variable_attributes( + parent_id, var_id, array_atts)) + { + TECA_ERROR("Failed to write attributes for \"" + << coord_array_names[i] << "\"") + } + } // NOTE: Moved writing arrays to directly after defining them. There // used to be a separate for-loop later that wrote them. However,