1
1
module nuopc_shr_methods
2
-
3
2
use ESMF , only : operator (<), operator (/= ), operator (+ )
4
3
use ESMF , only : operator (- ), operator (* ) , operator (>= )
5
4
use ESMF , only : operator (<= ), operator (>), operator (==), MOD
@@ -501,7 +500,7 @@ end subroutine field_getfldptr
501
500
502
501
subroutine alarmInit ( clock , alarm , option , &
503
502
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
505
504
! Setup an alarm in a clock
506
505
! Notes: The ringtime sent to AlarmCreate MUST be the next alarm
507
506
! time. If you send an arbitrary but proper ringtime from the
@@ -595,27 +594,23 @@ subroutine alarmInit( clock, alarm, option, &
595
594
return
596
595
end if
597
596
end if
597
+ call ESMF_TimeIntervalSet(AlarmInterval, yy= 9999 , rc= rc)
598
+ if (chkerr(rc,__LINE__,u_FILE_u)) return
598
599
599
600
! Determine inputs for call to create alarm
600
601
selectcase (trim (option))
601
602
602
603
case (optNONE)
603
- call ESMF_TimeIntervalSet(AlarmInterval, yy= 9999 , rc= rc)
604
- if (chkerr(rc,__LINE__,u_FILE_u)) return
605
604
call ESMF_TimeSet( NextAlarm, yy= 9999 , mm= 12 , dd= 1 , s= 0 , calendar= cal, rc= rc )
606
605
if (chkerr(rc,__LINE__,u_FILE_u)) return
607
606
update_nextalarm = .false.
608
607
609
608
case (optNever)
610
- call ESMF_TimeIntervalSet(AlarmInterval, yy= 9999 , rc= rc)
611
- if (chkerr(rc,__LINE__,u_FILE_u)) return
612
609
call ESMF_TimeSet( NextAlarm, yy= 9999 , mm= 12 , dd= 1 , s= 0 , calendar= cal, rc= rc )
613
610
if (chkerr(rc,__LINE__,u_FILE_u)) return
614
611
update_nextalarm = .false.
615
612
616
613
case (optDate)
617
- call ESMF_TimeIntervalSet(AlarmInterval, yy= 9999 , rc= rc)
618
- if (chkerr(rc,__LINE__,u_FILE_u)) return
619
614
call timeInit(NextAlarm, lymd, cal, ltod, rc)
620
615
if (chkerr(rc,__LINE__,u_FILE_u)) return
621
616
update_nextalarm = .false.
@@ -682,6 +677,13 @@ subroutine alarmInit( clock, alarm, option, &
682
677
call ESMF_TimeSet( NextAlarm, yy= cyy, mm= 1 , dd= 1 , s= 0 , calendar= cal, rc= rc )
683
678
if (ChkErr(rc,__LINE__,u_FILE_u)) return
684
679
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
+
685
687
case default
686
688
call ESMF_LogWrite(subname// ' unknown option ' // trim (option), ESMF_LOGMSG_ERROR)
687
689
rc = ESMF_FAILURE
@@ -762,114 +764,45 @@ end subroutine timeInit
762
764
763
765
! ===============================================================================
764
766
765
- integer function get_minimum_timestep (gcomp , rc )
767
+ integer function get_minimum_timestep (gcomp , rc )
766
768
! Get the minimum timestep interval in seconds based on the nuopc.config variables *_cpl_dt,
767
769
! if none of these variables are defined this routine will throw an error
768
770
type (ESMF_GridComp), intent (in ) :: gcomp
769
771
integer , intent (out ) :: rc
770
772
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
782
780
!- --------------------------------------------------------------------------
783
781
! Determine driver clock timestep
784
782
!- --------------------------------------------------------------------------
783
+ compname = (/ " atm" , " lnd" , " ice" , " ocn" , " rof" , " glc" , " wav" , " esp" / )
785
784
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
819
785
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)
852
790
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
856
791
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
859
799
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
866
800
if (get_minimum_timestep == huge (1 )) then
867
801
call ESMF_LogWrite(' minimum_timestep_error: this option is not supported ' , ESMF_LOGMSG_ERROR)
868
802
rc = ESMF_FAILURE
869
803
return
870
804
endif
871
805
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
873
806
call ESMF_LogWrite(' minimum_timestep_error ERROR ' , ESMF_LOGMSG_ERROR)
874
807
rc = ESMF_FAILURE
875
808
return
@@ -890,7 +823,6 @@ subroutine shr_get_rpointer_name(gcomp, compname, ymd, time, rpfile, mode, rc)
890
823
character (len= 16 ) timestr
891
824
logical :: isPresent
892
825
character (len= ESMF_MAXSTR) :: inst_suffix
893
-
894
826
character (len=* ), parameter :: subname= ' shr_get_rpointer_name'
895
827
896
828
rc = ESMF_SUCCESS
@@ -904,8 +836,8 @@ subroutine shr_get_rpointer_name(gcomp, compname, ymd, time, rpfile, mode, rc)
904
836
mon = (ymd - yr* 10000 )/ 100
905
837
day = (ymd - yr* 10000 - mon* 100 )
906
838
write (timestr,' (i4.4,a,i2.2,a,i2.2,a,i5.5)' ) yr,' -' ,mon,' -' ,day,' -' ,time
907
-
908
839
write (rpfile,* ) " rpointer." // compname// trim (inst_suffix)// ' .' // trim (timestr)
840
+ rpfile = adjustl (rpfile)
909
841
if (mode.eq. ' read' ) then
910
842
inquire (file= trim (rpfile), exist= isPresent)
911
843
if (.not. isPresent) then
0 commit comments