Add robustness to `icb_rst`
Context
When something is going wrong in icb_rst
, it is difficult to understand if it is an issue about NetCDF or something else.
Here an example from icb_rst
:
! Variables
nret = NF90_DEF_VAR(ncid, 'kount' , NF90_INT , (/ ik_dim /), nkountid)
nret = NF90_DEF_VAR(ncid, 'calving' , NF90_DOUBLE, (/ ix_dim, iy_dim /), ncalvid)
nret = NF90_DEF_VAR(ncid, 'calving_hflx', NF90_DOUBLE, (/ ix_dim, iy_dim /), ncalvhid)
nret = NF90_DEF_VAR(ncid, 'stored_ice' , NF90_DOUBLE, (/ ix_dim, iy_dim, nc_dim /), nsiceid)
nret = NF90_DEF_VAR(ncid, 'stored_heat' , NF90_DOUBLE, (/ ix_dim, iy_dim /), nsheatid)
In this example (there are many others), nret
is overwritten and not tested. There is a iom_nf90 function that allow us to check easily it with possibility to add also more information that the netcdf error string: iom_nf90_check
. I suggest to add a CALL iom_nf90_check(..., clinfo)
to every NF90 call as it is done in iom_nf90.
Here an example from iom_nf90_open
:
! define dimensions
CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'x', kdompar(1,1), idmy ), clinfo)
CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'y', kdompar(2,1), idmy ), clinfo)
CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'nav_lev', jpk, idmy ), clinfo)
CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'time_counter', NF90_UNLIMITED, idmy ), clinfo)