Skip to content

Commit

Permalink
ESMF_ConfigGetAttribute from model_configure
Browse files Browse the repository at this point in the history
  • Loading branch information
NickSzapiro-NOAA committed Sep 13, 2024
1 parent f60b324 commit da79cde
Showing 1 changed file with 39 additions and 31 deletions.
70 changes: 39 additions & 31 deletions mediator/med_phases_restart_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ subroutine med_phases_restart_alarm_init(gcomp, rc)
use ESMF , only : ESMF_LogWrite, ESMF_LOGMSG_INFO, ESMF_LOGMSG_ERROR
use ESMF , only : ESMF_SUCCESS, ESMF_FAILURE
use ESMF , only : operator(==), operator(+)
use ESMF , only : ESMF_KIND_R8, ESMF_ConfigCreate, ESMF_ConfigDestroy, ESMF_ConfigLoadFile, &
ESMF_ConfigGetLen, ESMF_ConfigGetAttribute, ESMF_Config, &
ESMF_LogFoundError, ESMF_LOGERR_PASSTHRU
use NUOPC , only : NUOPC_CompAttributeGet
use NUOPC_Model , only : NUOPC_ModelGet
use med_time_mod , only : med_time_AlarmInit
Expand All @@ -70,7 +73,8 @@ subroutine med_phases_restart_alarm_init(gcomp, rc)
logical :: isSet
integer :: n, nfh, fh_s
character(len=256) :: timestr
real(R8), allocatable :: restart_fh(:)
real(kind=ESMF_KIND_R8), allocatable :: restart_fh(:)
type(ESMF_Config) :: CF_mc
character(len=*), parameter :: subname='(med_phases_restart_alarm_init)'
!---------------------------------------

Expand Down Expand Up @@ -112,37 +116,41 @@ subroutine med_phases_restart_alarm_init(gcomp, rc)
if (trim(cvalue) .eq. '.true.') write_restart_at_endofrun = .true.
end if

! Set up times to write non-interval restarts
call NUOPC_CompAttributeGet(gcomp, name='restart_fh', isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
call NUOPC_CompAttributeGet(gcomp, name='restart_fh', value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! convert string to a list of integer restart_fh values
nfh = 1 + count(transfer(trim(cvalue), 'a', len(cvalue)) == ",")
allocate(restart_fh(1:nfh))
allocate(restartFhTimes(1:nfh)) !not deallocated
read(cvalue,*)restart_fh(1:nfh)

! create a list of times at each restart_fh
do n = 1,nfh
fh_s = NINT(3600*restart_fh(n))
call ESMF_TimeIntervalSet(fhInterval, s=fh_s, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
restartFhTimes(n) = mCurrTime + fhInterval
call ESMF_TimePrint(restartFhTimes(n), options="string", preString="restart_fh at ", unit=timestr, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (maintask) then
if (mod(fh_s,timestep_length) /= 0) then
write(logunit,'(A)')trim(subname)//trim(timestr)//' will not be written'
else
write(logunit,'(A)')trim(subname)//trim(timestr)//' will be written'
! Set up times to write non-interval restarts
inquire(FILE='model_configure', EXIST=isPresent)
if (isPresent) then !model_configure exists. this is ufs run
CF_mc = ESMF_ConfigCreate(rc=rc)
call ESMF_ConfigLoadFile(config=CF_mc,filename='model_configure' ,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

nfh = ESMF_ConfigGetLen(config=CF_mc, label ='restart_fh:',rc=rc)
if (nfh .gt. 0) then
allocate(restart_fh(1:nfh))
allocate(restartFhTimes(1:nfh)) !not deallocated

call ESMF_ConfigGetAttribute(CF_mc,valueList=restart_fh,label='restart_fh:', rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
! create a list of times at each restart_fh
do n = 1,nfh
fh_s = NINT(3600*restart_fh(n))
call ESMF_TimeIntervalSet(fhInterval, s=fh_s, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
restartFhTimes(n) = mCurrTime + fhInterval
call ESMF_TimePrint(restartFhTimes(n), options="string", preString="restart_fh at ", unit=timestr, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (maintask) then
if (mod(fh_s, timestep_length) /= 0) then
write(logunit,'(A)')trim(subname)//trim(timestr)//' will not be written'
else
write(logunit,'(A)')trim(subname)//trim(timestr)//' will be written'
end if
end if
end if
end do
deallocate(restart_fh)
end if
end do
deallocate(restart_fh)
end if !nfh>0
call ESMF_ConfigDestroy(CF_mc, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
end if !model_configure

! Write mediator diagnostic output
if (maintask) then
Expand Down

0 comments on commit da79cde

Please sign in to comment.