From e5006af45f781219cd1dd4f86b13ac8b9c36e71d Mon Sep 17 00:00:00 2001 From: Nick Szapiro Date: Fri, 13 Sep 2024 03:54:41 +0000 Subject: [PATCH] ESMF_ConfigGetAttribute from model_configure --- config_src/drivers/nuopc_cap/mom_cap.F90 | 72 +++++++++++++----------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/config_src/drivers/nuopc_cap/mom_cap.F90 b/config_src/drivers/nuopc_cap/mom_cap.F90 index e3b1de4882..a131fb020b 100644 --- a/config_src/drivers/nuopc_cap/mom_cap.F90 +++ b/config_src/drivers/nuopc_cap/mom_cap.F90 @@ -1928,7 +1928,9 @@ end subroutine ModelAdvance subroutine ModelSetRunClock(gcomp, rc) - use ESMF, only : ESMF_TimeIntervalSet + use ESMF, only : ESMF_TimeIntervalSet, ESMF_Config + use ESMF, only : ESMF_ConfigCreate, ESMF_ConfigDestroy, ESMF_ConfigLoadFile, & + ESMF_ConfigGetLen, ESMF_ConfigGetAttribute, ESMF_LogFoundError type(ESMF_GridComp) :: gcomp integer, intent(out) :: rc @@ -1953,7 +1955,8 @@ subroutine ModelSetRunClock(gcomp, rc) logical :: first_time = .true. integer :: localPet integer :: n, nfh, fh_s - real(ESMF_KIND_R8), allocatable :: restart_fh(:) + real(kind=ESMF_KIND_R8), allocatable :: restart_fh(:) + type(ESMF_Config) :: CF_mc character(len=*),parameter :: subname='(MOM_cap:ModelSetRunClock) ' !-------------------------------- @@ -2099,39 +2102,42 @@ subroutine ModelSetRunClock(gcomp, rc) call ESMF_LogWrite("Stop Alarm will ring at : "//trim(timestr), ESMF_LOGMSG_INFO) ! 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 ESMF_TimeIntervalGet(dtimestep, s=dt_cpl, rc=rc) - if (ChkErr(rc,__LINE__,u_FILE_u)) return - 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)) - read(cvalue,*)restart_fh(1:nfh) - - ! create a list of times at each restart_fh - do n = 1,nfh - fh_s = NINT(restart_fh(n)*3600) - 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) + 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 + call ESMF_TimeIntervalGet(dtimestep, s=dt_cpl, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - if (localPet == 0) then - if (mod(fh_s,dt_cpl) /= 0) then - write(stdout,'(A)')trim(subname)//trim(timestr)//' will not be written' - else - write(stdout,'(A)')trim(subname)//trim(timestr)//' will be written' + 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 (localPet==0) then + if (mod(fh_s,dt_cpl) /= 0) then + write(stdout,'(A)')trim(subname)//trim(timestr)//' will not be written' + else + write(stdout,'(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 first_time = .false. endif