Skip to content

Commit

Permalink
steps to unify the ncar and emc nuopc caps
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertens committed Jul 28, 2018
1 parent 04b9bba commit 8fd077b
Show file tree
Hide file tree
Showing 3 changed files with 271 additions and 85 deletions.
100 changes: 50 additions & 50 deletions config_src/nuopc_driver/mom_cap.F90
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ module mom_cap_mod
use shr_file_mod, only: shr_file_getUnit, shr_file_freeUnit
use shr_file_mod, only: shr_file_getLogUnit, shr_file_getLogLevel
use shr_file_mod, only: shr_file_setLogUnit, shr_file_setLogLevel
use shr_nuopc_time_mod, only: shr_nuopc_time_alarmInit
#endif

use ESMF ! TODO: only: ...
Expand Down Expand Up @@ -1064,10 +1065,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)

#endif

write(6,*)'DEBUG: fldstoocn_num= ',fldstoocn_num
write(6,*)'DEBUG: fldsfrocn_num= ',fldsfrocn_num
do n = 1,fldsToOcn_num
write(6,*)'DEBUG: n, stdname',n,trim(fldsToOcn(n)%stdname)
call NUOPC_Advertise(importState, standardName=fldsToOcn(n)%stdname, name=fldsToOcn(n)%shortname, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
Expand Down Expand Up @@ -2004,7 +2002,7 @@ subroutine ModelAdvance(gcomp, rc)
return ! bail out

! If restart alarm is ringing - write restart file
call ESMF_ClockGetAlarm(clock, alarmname='seq_timemgr_alarm_restart', alarm=alarm, rc=rc)
call ESMF_ClockGetAlarm(clock, alarmname='alarm_restart', alarm=alarm, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
Expand Down Expand Up @@ -2196,9 +2194,12 @@ subroutine ModelSetRunClock(gcomp, rc)
type(ESMF_Time) :: mstoptime
type(ESMF_TimeInterval) :: mtimestep, dtimestep
character(len=128) :: mtimestring, dtimestring
type(ESMF_Alarm),pointer :: alarmList(:)
type(ESMF_Alarm) :: dalarm
integer :: alarmcount, n
character(len=256) :: cvalue
character(len=256) :: restart_option ! Restart option units
integer :: restart_n ! Number until restart interval
integer :: restart_ymd ! Restart date (YYYYMMDD)
type(ESMF_ALARM) :: restart_alarm
logical :: first_time = .true.
character(len=*),parameter :: subname='mom_cap:(ModelSetRunClock) '
!--------------------------------

Expand Down Expand Up @@ -2242,11 +2243,8 @@ subroutine ModelSetRunClock(gcomp, rc)

call ESMF_LogWrite(subname//" ERROR in time consistency; "//trim(dtimestring)//" ne "//trim(mtimestring), &
ESMF_LOGMSG_ERROR, rc=dbrc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
rc=ESMF_Failure
rc = ESMF_FAILURE
return
endif

!--------------------------------
Expand All @@ -2261,47 +2259,49 @@ subroutine ModelSetRunClock(gcomp, rc)
file=__FILE__)) &
return ! bail out

!--------------------------------
! copy alarms from driver to model clock if model clock has no alarms (do this only once!)
!--------------------------------

call ESMF_ClockGetAlarmList(mclock, alarmlistflag=ESMF_ALARMLIST_ALL, alarmCount=alarmCount, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out

if (alarmCount == 0) then
call ESMF_ClockGetAlarmList(dclock, alarmlistflag=ESMF_ALARMLIST_ALL, alarmCount=alarmCount, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
if (first_time) then
!--------------------------------
! set restart alarm
!--------------------------------
call NUOPC_CompAttributeGet(gcomp, name="restart_option", value=restart_option, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out

allocate(alarmList(alarmCount))
call ESMF_ClockGetAlarmList(dclock, alarmlistflag=ESMF_ALARMLIST_ALL, alarmList=alarmList, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call NUOPC_CompAttributeGet(gcomp, name="restart_n", value=cvalue, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
read(cvalue,*) restart_n

do n = 1, alarmCount
! call ESMF_AlarmPrint(alarmList(n), rc=rc)
! if (shr_nuopc_methods_ChkErr(rc,__LINE__,u_FILE_u)) return
dalarm = ESMF_AlarmCreate(alarmList(n), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_AlarmSet(dalarm, clock=mclock, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
enddo
call NUOPC_CompAttributeGet(gcomp, name="restart_ymd", value=cvalue, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
read(cvalue,*) restart_ymd

call shr_nuopc_time_alarmInit(mclock, &
alarm = restart_alarm, &
option = trim(restart_option), &
opt_n = restart_n, &
opt_ymd = restart_ymd, &
RefTime = mcurrTime, &
alarmname = 'alarm_restart', rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out

deallocate(alarmList)
endif
call ESMF_AlarmSet(restart_alarm, clock=mclock, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
first_time = .false.
end if

!--------------------------------
! Advance model clock to trigger alarms then reset model clock back to currtime
Expand Down
Loading

0 comments on commit 8fd077b

Please sign in to comment.