From a6d44a13048488e0b7ca44fdcdcbaf298dca7db0 Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Wed, 17 May 2023 08:06:24 -0400 Subject: [PATCH] io_netcdf: do check exit status of nf90_close in final_restart In ice_restart::final_restart, we call nf90_close outside any condition on 'my_task'. This is very fishy, as the restart file is only opened by the first MPI rank in init_restart_write. The reason it works is (most likely) because we do not check the exit status of nf90_close, which (most likely) fails on all ranks other than the first. What's more, we always output "Restart read/written" to the log file, even if the call to nf90_close failed. This means the log file will always say the restart was written, even if it might not have been because of an error, which can be very confusing (see [1] and following). Move the call to nf90_close inside the existing condition on 'my_task', and also check the exit status, converting any error code to its textual representation using 'nf90_strerror'. [1] https://gitlab.science.gc.ca/Ocean_Data_Assimilation/RIOPS/issues/101#note_790575 --- .../cicedynB/infrastructure/io/io_netcdf/ice_restart.F90 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cicecore/cicedynB/infrastructure/io/io_netcdf/ice_restart.F90 b/cicecore/cicedynB/infrastructure/io/io_netcdf/ice_restart.F90 index f6002ff40..72877244b 100644 --- a/cicecore/cicedynB/infrastructure/io/io_netcdf/ice_restart.F90 +++ b/cicecore/cicedynB/infrastructure/io/io_netcdf/ice_restart.F90 @@ -822,10 +822,14 @@ subroutine final_restart() character(len=*), parameter :: subname = '(final_restart)' #ifdef USE_NETCDF - status = nf90_close(ncid) - if (my_task == master_task) & + if (my_task == master_task) then + status = nf90_close(ncid) + if (status /= nf90_noerr) call abort_ice(subname// & + 'ERROR: closing restart ncfile: ' // trim(nf90_strerror(status))) + write(nu_diag,*) 'Restart read/written ',istep1,idate + endif #else call abort_ice(subname//'ERROR: USE_NETCDF cpp not defined', &