Skip to content

Commit ae61417

Browse files
committed
update nuopc_shr_methods to match share code
1 parent 8197f05 commit ae61417

File tree

1 file changed

+31
-99
lines changed

1 file changed

+31
-99
lines changed

share/nuopc_shr_methods.F90

Lines changed: 31 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
module nuopc_shr_methods
2-
32
use ESMF , only : operator(<), operator(/=), operator(+)
43
use ESMF , only : operator(-), operator(*) , operator(>=)
54
use ESMF , only : operator(<=), operator(>), operator(==), MOD
@@ -501,7 +500,7 @@ end subroutine field_getfldptr
501500

502501
subroutine alarmInit( clock, alarm, option, &
503502
opt_n, opt_ymd, opt_tod, RefTime, alarmname, advance_clock, rc)
504-
use ESMF, only : ESMF_AlarmPrint
503+
use ESMF, only : ESMF_AlarmPrint, ESMF_ClockGetAlarm
505504
! Setup an alarm in a clock
506505
! Notes: The ringtime sent to AlarmCreate MUST be the next alarm
507506
! time. If you send an arbitrary but proper ringtime from the
@@ -595,27 +594,23 @@ subroutine alarmInit( clock, alarm, option, &
595594
return
596595
end if
597596
end if
597+
call ESMF_TimeIntervalSet(AlarmInterval, yy=9999, rc=rc)
598+
if (chkerr(rc,__LINE__,u_FILE_u)) return
598599

599600
! Determine inputs for call to create alarm
600601
selectcase (trim(option))
601602

602603
case (optNONE)
603-
call ESMF_TimeIntervalSet(AlarmInterval, yy=9999, rc=rc)
604-
if (chkerr(rc,__LINE__,u_FILE_u)) return
605604
call ESMF_TimeSet( NextAlarm, yy=9999, mm=12, dd=1, s=0, calendar=cal, rc=rc )
606605
if (chkerr(rc,__LINE__,u_FILE_u)) return
607606
update_nextalarm = .false.
608607

609608
case (optNever)
610-
call ESMF_TimeIntervalSet(AlarmInterval, yy=9999, rc=rc)
611-
if (chkerr(rc,__LINE__,u_FILE_u)) return
612609
call ESMF_TimeSet( NextAlarm, yy=9999, mm=12, dd=1, s=0, calendar=cal, rc=rc )
613610
if (chkerr(rc,__LINE__,u_FILE_u)) return
614611
update_nextalarm = .false.
615612

616613
case (optDate)
617-
call ESMF_TimeIntervalSet(AlarmInterval, yy=9999, rc=rc)
618-
if (chkerr(rc,__LINE__,u_FILE_u)) return
619614
call timeInit(NextAlarm, lymd, cal, ltod, rc)
620615
if (chkerr(rc,__LINE__,u_FILE_u)) return
621616
update_nextalarm = .false.
@@ -682,6 +677,13 @@ subroutine alarmInit( clock, alarm, option, &
682677
call ESMF_TimeSet( NextAlarm, yy=cyy, mm=1, dd=1, s=0, calendar=cal, rc=rc )
683678
if (ChkErr(rc,__LINE__,u_FILE_u)) return
684679
update_nextalarm = .true.
680+
681+
case (optEnd)
682+
call ESMF_ClockGetAlarm(clock, alarmname="alarm_stop", alarm=alarm, rc=rc)
683+
if (ChkErr(rc,__LINE__,u_FILE_u)) return
684+
call ESMF_AlarmGet(alarm, ringTime=NextAlarm, rc=rc)
685+
if (ChkErr(rc,__LINE__,u_FILE_u)) return
686+
685687
case default
686688
call ESMF_LogWrite(subname//'unknown option '//trim(option), ESMF_LOGMSG_ERROR)
687689
rc = ESMF_FAILURE
@@ -762,114 +764,45 @@ end subroutine timeInit
762764

763765
!===============================================================================
764766

765-
integer function get_minimum_timestep(gcomp, rc)
767+
integer function get_minimum_timestep(gcomp, rc)
766768
! Get the minimum timestep interval in seconds based on the nuopc.config variables *_cpl_dt,
767769
! if none of these variables are defined this routine will throw an error
768770
type(ESMF_GridComp), intent(in) :: gcomp
769771
integer, intent(out) :: rc
770772

771-
character(len=CS) :: cvalue
772-
integer :: atm_cpl_dt ! Atmosphere coupling interval
773-
integer :: lnd_cpl_dt ! Land coupling interval
774-
integer :: ice_cpl_dt ! Sea-Ice coupling interval
775-
integer :: ocn_cpl_dt ! Ocean coupling interval
776-
integer :: glc_cpl_dt ! Glc coupling interval
777-
integer :: rof_cpl_dt ! Runoff coupling interval
778-
integer :: wav_cpl_dt ! Wav coupling interval
779-
logical :: is_present, is_set ! determine if these variables are used
780-
integer :: esp_cpl_dt ! Esp coupling interval
781-
773+
character(len=CS) :: cvalue
774+
integer :: comp_dt ! coupling interval of component
775+
integer, parameter :: ncomps = 8
776+
character(len=3),dimension(ncomps) :: compname
777+
character(len=10) :: comp
778+
logical :: is_present, is_set ! determine if these variables are used
779+
integer :: i
782780
!---------------------------------------------------------------------------
783781
! Determine driver clock timestep
784782
!---------------------------------------------------------------------------
783+
compname = (/"atm", "lnd", "ice", "ocn", "rof", "glc", "wav", "esp"/)
785784
get_minimum_timestep = huge(1)
786-
787-
call NUOPC_CompAttributeGet(gcomp, name="atm_cpl_dt", isPresent=is_present, isSet=is_set, rc=rc)
788-
if (ChkErr(rc,__LINE__,u_FILE_u)) return
789-
790-
if (is_present .and. is_set) then
791-
call NUOPC_CompAttributeGet(gcomp, name="atm_cpl_dt", value=cvalue, rc=rc)
792-
if (ChkErr(rc,__LINE__,u_FILE_u)) return
793-
read(cvalue,*) atm_cpl_dt
794-
get_minimum_timestep = min(atm_cpl_dt, get_minimum_timestep)
795-
endif
796-
797-
call NUOPC_CompAttributeGet(gcomp, name="lnd_cpl_dt", isPresent=is_present, isSet=is_set, rc=rc)
798-
if (ChkErr(rc,__LINE__,u_FILE_u)) return
799-
800-
if (is_present .and. is_set) then
801-
call NUOPC_CompAttributeGet(gcomp, name="lnd_cpl_dt", value=cvalue, rc=rc)
802-
if (ChkErr(rc,__LINE__,u_FILE_u)) return
803-
read(cvalue,*) lnd_cpl_dt
804-
get_minimum_timestep = min(lnd_cpl_dt, get_minimum_timestep)
805-
endif
806-
807-
call NUOPC_CompAttributeGet(gcomp, name="ice_cpl_dt", isPresent=is_present, isSet=is_set, rc=rc)
808-
if (ChkErr(rc,__LINE__,u_FILE_u)) return
809-
810-
if (is_present .and. is_set) then
811-
call NUOPC_CompAttributeGet(gcomp, name="ice_cpl_dt", value=cvalue, rc=rc)
812-
if (ChkErr(rc,__LINE__,u_FILE_u)) return
813-
read(cvalue,*) ice_cpl_dt
814-
get_minimum_timestep = min(ice_cpl_dt, get_minimum_timestep)
815-
endif
816-
817-
call NUOPC_CompAttributeGet(gcomp, name="ocn_cpl_dt", isPresent=is_present, isSet=is_set, rc=rc)
818-
if (ChkErr(rc,__LINE__,u_FILE_u)) return
819785

820-
if (is_present .and. is_set) then
821-
call NUOPC_CompAttributeGet(gcomp, name="ocn_cpl_dt", value=cvalue, rc=rc)
822-
if (ChkErr(rc,__LINE__,u_FILE_u)) return
823-
read(cvalue,*) ocn_cpl_dt
824-
get_minimum_timestep = min(ocn_cpl_dt, get_minimum_timestep)
825-
endif
826-
827-
call NUOPC_CompAttributeGet(gcomp, name="glc_cpl_dt", isPresent=is_present, isSet=is_set, rc=rc)
828-
if (ChkErr(rc,__LINE__,u_FILE_u)) return
829-
830-
if (is_present .and. is_set) then
831-
call NUOPC_CompAttributeGet(gcomp, name="glc_cpl_dt", value=cvalue, rc=rc)
832-
if (ChkErr(rc,__LINE__,u_FILE_u)) return
833-
read(cvalue,*) glc_cpl_dt
834-
get_minimum_timestep = min(glc_cpl_dt, get_minimum_timestep)
835-
endif
836-
837-
call NUOPC_CompAttributeGet(gcomp, name="rof_cpl_dt", isPresent=is_present, isSet=is_set, rc=rc)
838-
if (ChkErr(rc,__LINE__,u_FILE_u)) return
839-
840-
if (is_present .and. is_set) then
841-
call NUOPC_CompAttributeGet(gcomp, name="rof_cpl_dt", value=cvalue, rc=rc)
842-
if (ChkErr(rc,__LINE__,u_FILE_u)) return
843-
read(cvalue,*) rof_cpl_dt
844-
get_minimum_timestep = min(rof_cpl_dt, get_minimum_timestep)
845-
endif
846-
847-
call NUOPC_CompAttributeGet(gcomp, name="wav_cpl_dt", isPresent=is_present, isSet=is_set, rc=rc)
848-
if (ChkErr(rc,__LINE__,u_FILE_u)) return
849-
850-
if (is_present .and. is_set) then
851-
call NUOPC_CompAttributeGet(gcomp, name="wav_cpl_dt", value=cvalue, rc=rc)
786+
do i=1,ncomps
787+
comp = compname(i)//"_cpl_dt"
788+
789+
call NUOPC_CompAttributeGet(gcomp, name=comp, isPresent=is_present, isSet=is_set, rc=rc)
852790
if (ChkErr(rc,__LINE__,u_FILE_u)) return
853-
read(cvalue,*) wav_cpl_dt
854-
get_minimum_timestep = min(wav_cpl_dt, get_minimum_timestep)
855-
endif
856791

857-
call NUOPC_CompAttributeGet(gcomp, name="esp_cpl_dt", isPresent=is_present, isSet=is_set, rc=rc)
858-
if (ChkErr(rc,__LINE__,u_FILE_u)) return
792+
if (is_present .and. is_set) then
793+
call NUOPC_CompAttributeGet(gcomp, name=comp, value=cvalue, rc=rc)
794+
if (ChkErr(rc,__LINE__,u_FILE_u)) return
795+
read(cvalue,*) comp_dt
796+
get_minimum_timestep = min(comp_dt, get_minimum_timestep)
797+
endif
798+
enddo
859799

860-
if (is_present .and. is_set) then
861-
call NUOPC_CompAttributeGet(gcomp, name="esp_cpl_dt", value=cvalue, rc=rc)
862-
if (ChkErr(rc,__LINE__,u_FILE_u)) return
863-
read(cvalue,*) esp_cpl_dt
864-
get_minimum_timestep = min(esp_cpl_dt, get_minimum_timestep)
865-
endif
866800
if(get_minimum_timestep == huge(1)) then
867801
call ESMF_LogWrite('minimum_timestep_error: this option is not supported ', ESMF_LOGMSG_ERROR)
868802
rc = ESMF_FAILURE
869803
return
870804
endif
871805
if(get_minimum_timestep <= 0) then
872-
print *,__FILE__,__LINE__,atm_cpl_dt, lnd_cpl_dt, ocn_cpl_dt, ice_cpl_dt, glc_cpl_dt, rof_cpl_dt, wav_cpl_dt
873806
call ESMF_LogWrite('minimum_timestep_error ERROR ', ESMF_LOGMSG_ERROR)
874807
rc = ESMF_FAILURE
875808
return
@@ -890,7 +823,6 @@ subroutine shr_get_rpointer_name(gcomp, compname, ymd, time, rpfile, mode, rc)
890823
character(len=16) timestr
891824
logical :: isPresent
892825
character(len=ESMF_MAXSTR) :: inst_suffix
893-
894826
character(len=*), parameter :: subname='shr_get_rpointer_name'
895827

896828
rc = ESMF_SUCCESS
@@ -904,8 +836,8 @@ subroutine shr_get_rpointer_name(gcomp, compname, ymd, time, rpfile, mode, rc)
904836
mon = (ymd - yr*10000)/100
905837
day = (ymd - yr*10000 - mon*100)
906838
write(timestr,'(i4.4,a,i2.2,a,i2.2,a,i5.5)') yr,'-',mon,'-',day,'-',time
907-
908839
write(rpfile,*) "rpointer."//compname//trim(inst_suffix)//'.'//trim(timestr)
840+
rpfile = adjustl(rpfile)
909841
if (mode.eq.'read') then
910842
inquire(file=trim(rpfile), exist=isPresent)
911843
if(.not. isPresent) then

0 commit comments

Comments
 (0)