Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add timestamp to rpointer files #105

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions src/cpl/nuopc/rof_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
! local variables
type(ESMF_Mesh) :: Emesh
type(ESMF_VM) :: vm
type(ESMF_Time) :: currTime ! Current time
integer , allocatable :: gindex(:) ! global index space on my processor
integer :: lbnum ! input to memory diagnostic
character(CL) :: cvalue ! temporary
Expand Down Expand Up @@ -482,8 +483,10 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
! - Adjust area estimation from DRT algorithm for those outlet grids
! - useful for grid-based representation only
! - need to compute areas where they are not defined in input file

call mosart_init1(rc)
call ESMF_ClockGet(clock, currTime=currtime, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call mosart_init1(currtime, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

!--------------------------------
Expand Down Expand Up @@ -811,51 +814,51 @@ subroutine ModelSetRunClock(gcomp, rc)
call ESMF_LogWrite(subname//'setting alarms for' // trim(name), ESMF_LOGMSG_INFO)

!----------------
! Restart alarm
! Stop alarm
!----------------
call NUOPC_CompAttributeGet(gcomp, name="restart_option", value=restart_option, rc=rc)
call NUOPC_CompAttributeGet(gcomp, name="stop_option", value=stop_option, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call NUOPC_CompAttributeGet(gcomp, name="restart_n", value=cvalue, rc=rc)
call NUOPC_CompAttributeGet(gcomp, name="stop_n", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) restart_n
read(cvalue,*) stop_n

call NUOPC_CompAttributeGet(gcomp, name="restart_ymd", value=cvalue, rc=rc)
call NUOPC_CompAttributeGet(gcomp, name="stop_ymd", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) restart_ymd
read(cvalue,*) stop_ymd

call alarmInit(mclock, restart_alarm, restart_option, &
opt_n = restart_n, &
opt_ymd = restart_ymd, &
call alarmInit(mclock, stop_alarm, stop_option, &
opt_n = stop_n, &
opt_ymd = stop_ymd, &
RefTime = mcurrTime, &
alarmname = 'alarm_restart', rc=rc)
alarmname = 'alarm_stop', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call ESMF_AlarmSet(restart_alarm, clock=mclock, rc=rc)
call ESMF_AlarmSet(stop_alarm, clock=mclock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

!----------------
! Stop alarm
! Restart alarm
!----------------
call NUOPC_CompAttributeGet(gcomp, name="stop_option", value=stop_option, rc=rc)
call NUOPC_CompAttributeGet(gcomp, name="restart_option", value=restart_option, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call NUOPC_CompAttributeGet(gcomp, name="stop_n", value=cvalue, rc=rc)
call NUOPC_CompAttributeGet(gcomp, name="restart_n", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) stop_n
read(cvalue,*) restart_n

call NUOPC_CompAttributeGet(gcomp, name="stop_ymd", value=cvalue, rc=rc)
call NUOPC_CompAttributeGet(gcomp, name="restart_ymd", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) stop_ymd
read(cvalue,*) restart_ymd

call alarmInit(mclock, stop_alarm, stop_option, &
opt_n = stop_n, &
opt_ymd = stop_ymd, &
call alarmInit(mclock, restart_alarm, restart_option, &
opt_n = restart_n, &
opt_ymd = restart_ymd, &
RefTime = mcurrTime, &
alarmname = 'alarm_stop', rc=rc)
alarmname = 'alarm_restart', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call ESMF_AlarmSet(stop_alarm, clock=mclock, rc=rc)
call ESMF_AlarmSet(restart_alarm, clock=mclock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

end if
Expand Down
15 changes: 4 additions & 11 deletions src/riverroute/mosart_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module mosart_driver
use perf_mod , only : t_startf, t_stopf
use nuopc_shr_methods , only : chkerr
use ESMF , only : ESMF_SUCCESS, ESMF_FieldGet, ESMF_FieldSMMStore, ESMF_FieldSMM, &
ESMF_TERMORDER_SRCSEQ, ESMF_Mesh
ESMF_TERMORDER_SRCSEQ, ESMF_Mesh, ESMF_Time
use mosart_io , only : ncd_pio_openfile, ncd_inqdid, ncd_inqdlen, ncd_pio_closefile, ncd_decomp_init, &
pio_subsystem
use pio , only : file_desc_t
Expand Down Expand Up @@ -217,12 +217,13 @@ end subroutine mosart_read_namelist

!-----------------------------------------------------------------------

subroutine mosart_init1(rc)
subroutine mosart_init1(currTime, rc)

!-------------------------------------------------
! Initialize mosart grid, mask, decomp
!
! Arguments
type(ESMF_Time), intent(in) :: currTime
integer, intent(out) :: rc
!
! Local variables
Expand All @@ -235,6 +236,7 @@ subroutine mosart_init1(rc)
!-------------------------------------------------

rc = ESMF_SUCCESS
call timemgr_init(dtime_in=coupling_period, curr_date_in=currTime)

!-------------------------------------------------------
! Obtain restart file if appropriate
Expand All @@ -244,15 +246,6 @@ subroutine mosart_init1(rc)
call mosart_rest_getfile( file=fnamer )
endif

!-------------------------------------------------------
! Initialize time manager
!-------------------------------------------------------
if (nsrest == nsrStartup) then
call timemgr_init(dtime_in=coupling_period)
else
call mosart_rest_timemanager(file=fnamer)
end if

!-------------------------------------------------------
! Write out tracers to stdout
!-------------------------------------------------------
Expand Down
49 changes: 32 additions & 17 deletions src/riverroute/mosart_restfile.F90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module mosart_restfile
use mosart_data, only : ctl, Trunoff
use mosart_histfile, only : mosart_hist_restart
use mosart_fileutils, only : getfil
use mosart_timemanager, only : timemgr_restart, get_nstep, get_curr_date
use mosart_timemanager, only : timemgr_restart, get_nstep, get_curr_date, get_prev_date
use mosart_io, only : ncd_pio_createfile, ncd_enddef, ncd_pio_openfile, ncd_pio_closefile, &
ncd_defdim, ncd_putatt, ncd_defvar, ncd_io, ncd_global, ncd_double, &
ncd_getdatetime
Expand Down Expand Up @@ -223,8 +223,9 @@ end subroutine mosart_rest_Getfile
!-----------------------------------------------------------------------

subroutine restFile_read_pfile( pnamer )

!-------------------------------------
use mpi, only : MPI_CHARACTER
use mosart_vars, only : mpicom_rof
!-------------------------------------
! Setup restart file and perform necessary consistency checks

! Arguments
Expand All @@ -234,6 +235,8 @@ subroutine restFile_read_pfile( pnamer )
integer :: nio ! restart unit
integer :: ier ! error return from fortran open
integer :: i ! index
integer :: yr, mon, day, tod
character(len=17) :: timestamp
character(len=CL) :: locfn ! Restart pointer file name
!-------------------------------------

Expand All @@ -244,21 +247,29 @@ subroutine restFile_read_pfile( pnamer )
! New history files are always created for branch runs.

if (mainproc) then
write(iulog,*) 'Reading restart pointer file....'
call get_curr_date(yr, mon, day, tod)
write(timestamp,'(".",i4.4,"-",i2.2,"-",i2.2,"-",i5.5)'),yr,mon,day,tod
locfn = './'// trim(rpntfil)//trim(inst_suffix)//timestamp

write(iulog,*) 'Reading restart pointer file: '//trim(locfn)
open (newunit=nio, file=trim(locfn), status='old', form='formatted', iostat=ier)
if (ier /= 0) then
locfn = './'// trim(rpntfil)//trim(inst_suffix)
open (newunit=nio, file=trim(locfn), status='old', form='formatted', iostat=ier)
if (ier /= 0) then
write(iulog,'(a,i8)')'(restFile_read_pfile): failed to open file '//trim(locfn)//' ierr=',ier
call shr_sys_abort()
end if
endif
read (nio,'(a256)') pnamer
close(nio)
endif
locfn = './'// trim(rpntfil)//trim(inst_suffix)
open (newunit=nio, file=trim(locfn), status='unknown', form='formatted', iostat=ier)
if (ier /= 0) then
write(iulog,'(a,i8)')'(restFile_read_pfile): failed to open file '//trim(locfn)//' ierr=',ier
call shr_sys_abort()
end if
read (nio,'(a256)') pnamer
close(nio)
if (mainproc) then
write(iulog,'(a)') 'Reading restart data.....'
call mpi_bcast (pnamer, CL, MPI_CHARACTER, 0, mpicom_rof, ier)
if(mainproc) then
write(iulog,'(a)') 'Reading restart data: ',trim(pnamer)
write(iulog,'(72a1)') ("-",i=1,60)
end if

end subroutine restFile_read_pfile

!-----------------------------------------------------------------------
Expand All @@ -275,18 +286,22 @@ subroutine restFile_write_pfile( fnamer )
integer :: nio ! restart pointer file unit number
integer :: ier ! error return from fortran open
character(len=CL) :: filename ! local file name
integer :: yr, mon, day, tod
character(len=17) :: timestamp
!-------------------------------------

if (mainproc) then
filename= './'// trim(rpntfil)//trim(inst_suffix)
call get_curr_date(yr, mon, day, tod)
write(timestamp,'(".",i4.4,"-",i2.2,"-",i2.2,"-",i5.5)') yr, mon, day, tod
filename= './'// trim(rpntfil)//trim(inst_suffix)//timestamp
open (newunit=nio, file=trim(filename), status='unknown', form='formatted', iostat=ier)
if (ier /= 0) then
write(iulog,'(a,i8)')'(restFile_write_pfile): failed to open file '//trim(filename)//' ierr=',ier
call shr_sys_abort()
end if
write(nio,'(a)') fnamer
close(nio)
write(iulog,*)'Successfully wrote local restart pointer file'
write(iulog,*)'Successfully wrote local restart pointer file: '//trim(filename)
end if

end subroutine restFile_write_pfile
Expand Down
72 changes: 24 additions & 48 deletions src/riverroute/mosart_timemanager.F90
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ end subroutine timemgr_setup

!=========================================================================================

subroutine timemgr_init( dtime_in )
subroutine timemgr_init( dtime_in, curr_date_in )

! Initialize the ESMF time manager from the sync clock

! Arguments
integer, intent(in) :: dtime_in ! Time-step (sec)
type(ESMF_Time), intent(in), optional :: curr_date_in

! Local variables
integer :: rc ! return code
Expand Down Expand Up @@ -144,8 +145,11 @@ subroutine timemgr_init( dtime_in )
start_date = TimeSetymd( start_ymd, start_tod, "start_date" )

! Initialize current date
curr_date = start_date

if(present(curr_date_in)) then
curr_date = curr_date_in
else
curr_date = start_date
endif
! Initalize stop date.
stop_date = TimeSetymd( 99991231, stop_tod, "stop_date" )
call ESMF_TimeIntervalSet( step_size, s=dtime, rc=rc )
Expand Down Expand Up @@ -474,58 +478,30 @@ subroutine timemgr_restart(ncid, flag)
end if
end if


if (flag == 'read') then

! Initialize calendar from restart info
call init_calendar()

! Initialize the timestep from restart info
dtime = rst_step_sec

! Initialize start date from restart info
start_date = TimeSetymd( rst_start_ymd, rst_start_tod, "start_date" )

! Initialize current date from restart info
curr_date = TimeSetymd( rst_curr_ymd, rst_curr_tod, "curr_date" )

! Initialize stop date from sync clock or namelist input
stop_date = TimeSetymd( 99991231, stop_tod, "stop_date" )
! Compare the timestep to restart file
if(dtime .ne. rst_step_sec) then
call shr_sys_abort( sub//'ERROR: dtime does not match restart file rst_step_sec')
endif
if(start_ymd .ne. rst_start_ymd) then
call shr_sys_abort( sub//'ERROR: start_ymd does not match restart file rst_start_ymd')
endif
if(start_tod .ne. rst_start_tod) then
call shr_sys_abort( sub//'ERROR: start_tod does not match restart file rst_start_tod')
endif

if(ref_ymd .ne. rst_ref_ymd) then
call shr_sys_abort( sub//'ERROR: ref_ymd does not match restart file rst_ref_ymd')
endif
if(ref_tod .ne. rst_ref_tod) then
call shr_sys_abort( sub//'ERROR: ref_tod does not match restart file rst_ref_tod')
endif

call ESMF_TimeIntervalSet( step_size, s=dtime, rc=rc )
call chkrc(rc, sub//': error return from ESMF_TimeIntervalSet: setting step_size')
call ESMF_TimeIntervalSet( day_step_size, d=1, rc=rc )
call chkrc(rc, sub//': error return from ESMF_TimeIntervalSet: setting day_step_size')
if ( stop_ymd /= uninit_int ) then
current = TimeSetymd( stop_ymd, stop_tod, "stop_date" )
if ( current < stop_date ) stop_date = current
else
call shr_sys_abort (sub//': Must specify stop_ymd')
end if

! Error check
if ( stop_date <= start_date ) then
write(iulog,*)sub, ': stop date must be specified later than start date: '
call ESMF_TimeGet( start_date, yy=yr, mm=mon, dd=day, s=tod )
write(iulog,*) ' Start date (yr, mon, day, tod): ', yr, mon, day, tod
call ESMF_TimeGet( stop_date, yy=yr, mm=mon, dd=day, s=tod )
write(iulog,*) ' Stop date (yr, mon, day, tod): ', yr, mon, day, tod
call shr_sys_abort
end if
if ( curr_date >= stop_date ) then
write(iulog,*)sub, ': stop date must be specified later than current date: '
call ESMF_TimeGet( curr_date, yy=yr, mm=mon, dd=day, s=tod )
write(iulog,*) ' Current date (yr, mon, day, tod): ', yr, mon, day, tod
call ESMF_TimeGet( stop_date, yy=yr, mm=mon, dd=day, s=tod )
write(iulog,*) ' Stop date (yr, mon, day, tod): ', yr, mon, day, tod
call shr_sys_abort
end if

! Initialize ref date from restart info
ref_date = TimeSetymd( rst_ref_ymd, rst_ref_tod, "ref_date" )

! Initialize clock
call init_clock( start_date, ref_date, curr_date, stop_date )

! Print configuration summary to log file (stdout).
if (mainproc) call timemgr_print()
Expand Down