Skip to content

Commit

Permalink
Fix error of writing fillValue attribute after writing data
Browse files Browse the repository at this point in the history
  • Loading branch information
kwrobot committed Jan 9, 2025
1 parent 07dc1b6 commit f94a729
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions io/teca_cf_layout_manager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f94a729

Please sign in to comment.