E3SM-Project / E3SM

Energy Exascale Earth System Model source code. NOTE: use "maint" branches for your work. Head of master is not validated.
https://docs.e3sm.org/E3SM
Other
332 stars 334 forks source link

The units attribute is written twice for a single variable in ELM restart files #6384

Open dqwu opened 2 weeks ago

dqwu commented 2 weeks ago

This issue was confirmed by @whannah1 before:

There's an interface of routines for restartvar, which takes a units argument. Each of these interface routines calls ncd_defvar, which ALSO takes a units argument and calls ncd_putatt But then farther down in the various restartvar routines they also check if "units" was provided and add a second ncd_putatt call

components/elm/src/utils/restUtilMod.F90.in

  subroutine restartvar_{DIMS}d_{TYPE}(&
       ncid, flag, varname, xtype, &
       long_name, units, interpinic_flag, data, readvar, &
    ...
    character(len=*)  , intent(in), optional :: units            ! long name for variable
    ...
    if (flag == 'define') then
       ...
       call ncd_defvar(ncid=ncid, varname=trim(varname), xtype=lxtype, &
            long_name=trim(long_name), units=units)
       ...
       if (present(units)) then
          call ncd_putatt(ncid, varid, 'units', trim(units))
       end if
  ...
  end subroutine restartvar_{DIMS}d_{TYPE}

components/elm/src/main/ncdio_pio.F90.in

  subroutine ncd_defvar_bynf(ncid, varname, xtype, ndims, dimid, varid, &
       long_name, standard_name, units, cell_method, missing_value, fill_value, &
    ...
    character(len=*)   , intent(in), optional :: units          ! attribute
    ...
    if (present(units)) then
       call ncd_putatt(ncid, varid, 'units', trim(units))
    end if
  ...
dqwu commented 2 weeks ago

@jayeshkrishna For ne4 F case run with ADIOS type, this issue has triggered the following warnings:

[0] PIO: WARNING: Writing variable (timemgr_rst_nstep_rad_prev, varid=0) attribute (units) to file (./F2010_ne4_oQU240_ADIOS.elm.r.0001-01-02-00000.nc, ncid=153) using ADIOS iotype is ignored. Overwriting an existing attribute is not supported yet
[0] PIO: WARNING: Writing variable (timemgr_rst_type, varid=1) attribute (units) to file (./F2010_ne4_oQU240_ADIOS.elm.r.0001-01-02-00000.nc, ncid=153) using ADIOS iotype is ignored. Overwriting an existing attribute is not supported yet
...
[0] PIO: WARNING: Writing variable (TCS_MONTH_END, varid=464) attribute (units) to file (./F2010_ne4_oQU240_ADIOS.elm.r.0001-01-02-00000.nc, ncid=153) using ADIOS iotype is ignored. Overwriting an existing attribute is not supported yet