From 996ba39640b5b79a1e243fd554bad0ebd1b23a1b Mon Sep 17 00:00:00 2001 From: apcraig Date: Wed, 28 Aug 2024 10:02:33 -0600 Subject: [PATCH] Update flush implementation, fix unit number bug and check that files are open at the end of the run before flushing. --- configuration/driver/icedrv_MAIN.F90 | 22 +++++++++++++++------ configuration/driver/icedrv_diagnostics.F90 | 3 +-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/configuration/driver/icedrv_MAIN.F90 b/configuration/driver/icedrv_MAIN.F90 index 7d486912..c8564d4e 100644 --- a/configuration/driver/icedrv_MAIN.F90 +++ b/configuration/driver/icedrv_MAIN.F90 @@ -35,6 +35,7 @@ program icedrv implicit none integer n + logical openflag character(len=*), parameter :: subname='(icedrv)' !----------------------------------------------------------------- @@ -55,15 +56,24 @@ program icedrv write(ice_stdout, *) "ICEPACK COMPLETED SUCCESSFULLY " - call icedrv_system_flush(ice_stdout) - close (ice_stdout) + inquire(unit=ice_stdout,opened=openflag) + if (openflag) then + call icedrv_system_flush(ice_stdout) + close (ice_stdout) + endif - call icedrv_system_flush(nu_diag) - close (nu_diag) + inquire(unit=nu_diag,opened=openflag) + if (openflag) then + call icedrv_system_flush(nu_diag) + close (nu_diag) + endif do n = 1, nx - call icedrv_system_flush(nu_diag_out+n+1) - close (nu_diag_out+n-1) + inquire(unit=nu_diag_out+n-1,opened=openflag) + if (openflag) then + call icedrv_system_flush(nu_diag_out+n-1) + close (nu_diag_out+n-1) + endif enddo end program icedrv diff --git a/configuration/driver/icedrv_diagnostics.F90 b/configuration/driver/icedrv_diagnostics.F90 index 5a0cf6ad..4ca0cb82 100644 --- a/configuration/driver/icedrv_diagnostics.F90 +++ b/configuration/driver/icedrv_diagnostics.F90 @@ -267,13 +267,12 @@ subroutine runtime_diags (dt) write(nu_diag_out+n-1,901) 'isotopic conc chg = ',pdiso(n,k),k enddo endif + call icedrv_system_flush(nu_diag_out+n-1) end do 899 format (43x,a24) 900 format (a25,2x,f24.17) 901 format (a25,2x,f24.17,i6) - call icedrv_system_flush(nu_diag_out+n-1) - end subroutine runtime_diags !=======================================================================