Skip to content

Commit

Permalink
Merge pull request #2679 from samsrabin/fix-failedinitdata-error2
Browse files Browse the repository at this point in the history
Always check finidat_interp_dest.status
  • Loading branch information
samsrabin authored Aug 13, 2024
2 parents 51067b0 + 5e7e5b5 commit 8252dc8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/main/clm_initializeMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ subroutine initialize2(ni,nj)
use SatellitePhenologyMod , only : SatellitePhenologyInit, readAnnualVegetation, interpMonthlyVeg, SatellitePhenology
use SnowSnicarMod , only : SnowAge_init, SnowOptics_init
use lnd2atmMod , only : lnd2atm_minimal
use controlMod , only : NLFilename
use controlMod , only : NLFilename, check_missing_initdata_status
use clm_instMod , only : clm_fates
use BalanceCheckMod , only : BalanceCheckInit
use CNSharedParamsMod , only : CNParamsSetSoilDepth
Expand Down Expand Up @@ -520,17 +520,7 @@ subroutine initialize2(ni,nj)
else
if (trim(finidat) == trim(finidat_interp_dest)) then
! Check to see if status file for finidat exists
klen = len_trim(finidat_interp_dest) - 3 ! remove the .nc
locfn = finidat_interp_dest(1:klen)//'.status'
inquire(file=trim(locfn), exist=lexists)
if (.not. lexists) then
if (masterproc) then
write(iulog,'(a)')' failed to find file '//trim(locfn)
write(iulog,'(a)')' this indicates a problem in creating '//trim(finidat_interp_dest)
write(iulog,'(a)')' remove '//trim(finidat_interp_dest)//' and try again'
end if
call endrun()
end if
call check_missing_initdata_status(finidat_interp_dest)
end if
if (masterproc) then
write(iulog,'(a)')'Reading initial conditions from file '//trim(finidat)
Expand Down
37 changes: 37 additions & 0 deletions src/main/controlMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module controlMod
public :: control_setNL ! Set namelist filename
public :: control_init ! initial run control information
public :: control_print ! print run control information
public :: check_missing_initdata_status ! check for missing finidat_interp_dest .status file
!
!
! !PRIVATE MEMBER FUNCTIONS:
Expand Down Expand Up @@ -1221,6 +1222,38 @@ subroutine control_print ()
end subroutine control_print


!-----------------------------------------------------------------------
subroutine check_missing_initdata_status(finidat_interp_dest)
!
! !DESCRIPTION:
! Checks that the finidat_interp_dest .status file was written (i.e., that write of
! finidat_interp_dest succeeded)
!
! !ARGUMENTS:
character(len=*), intent(in) :: finidat_interp_dest
!
! !LOCAL VARIABLES:
logical :: lexists
integer :: klen
character(len=SHR_KIND_CL) :: status_file
character(len=*), parameter :: subname = 'check_missing_initdata_status'
!-----------------------------------------------------------------------

klen = len_trim(finidat_interp_dest) - 3 ! remove the .nc
status_file = finidat_interp_dest(1:klen)//'.status'
inquire(file=trim(status_file), exist=lexists)
if (.not. lexists) then
if (masterproc) then
write(iulog,'(a)')' failed to find file '//trim(status_file)
write(iulog,'(a)')' this indicates a problem in creating '//trim(finidat_interp_dest)
write(iulog,'(a)')' remove '//trim(finidat_interp_dest)//' and try again'
end if
call endrun(subname//': finidat_interp_dest file exists but is probably bad')
end if

end subroutine check_missing_initdata_status


!-----------------------------------------------------------------------
subroutine apply_use_init_interp(finidat_interp_dest, finidat, finidat_interp_source)
!
Expand Down Expand Up @@ -1271,6 +1304,10 @@ subroutine apply_use_init_interp(finidat_interp_dest, finidat, finidat_interp_so

inquire(file=trim(finidat_interp_dest), exist=lexists)
if (lexists) then

! Check that the status file also exists (i.e., that finidat_interp_dest was written successfully)
call check_missing_initdata_status(finidat_interp_dest)

! open the input file and check for the name of the input source file
status = nf90_open(trim(finidat_interp_dest), 0, ncid)
if (status /= nf90_noerr) call handle_err(status)
Expand Down

0 comments on commit 8252dc8

Please sign in to comment.