From 7c18a9446aa573e44b53cbc1065d8fa5e7a1d6b9 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Wed, 25 Sep 2024 14:06:36 -0600 Subject: [PATCH] add timestamp to rpointer files --- src/cpl/nuopc/rof_comp_nuopc.F90 | 7 ++- src/riverroute/mosart_driver.F90 | 16 +++--- src/riverroute/mosart_restfile.F90 | 49 +++++++++++------- src/riverroute/mosart_timemanager.F90 | 72 +++++++++------------------ 4 files changed, 70 insertions(+), 74 deletions(-) diff --git a/src/cpl/nuopc/rof_comp_nuopc.F90 b/src/cpl/nuopc/rof_comp_nuopc.F90 index 29b75d4..985c95d 100644 --- a/src/cpl/nuopc/rof_comp_nuopc.F90 +++ b/src/cpl/nuopc/rof_comp_nuopc.F90 @@ -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 @@ -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 !-------------------------------- diff --git a/src/riverroute/mosart_driver.F90 b/src/riverroute/mosart_driver.F90 index 652bf98..2a386ce 100644 --- a/src/riverroute/mosart_driver.F90 +++ b/src/riverroute/mosart_driver.F90 @@ -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 @@ -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 @@ -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 @@ -247,11 +249,11 @@ subroutine mosart_init1(rc) !------------------------------------------------------- ! Initialize time manager !------------------------------------------------------- - if (nsrest == nsrStartup) then - call timemgr_init(dtime_in=coupling_period) - else - call mosart_rest_timemanager(file=fnamer) - end if +! if (nsrest == nsrStartup) then + +! else +! call mosart_rest_timemanager(file=fnamer) +! end if !------------------------------------------------------- ! Write out tracers to stdout diff --git a/src/riverroute/mosart_restfile.F90 b/src/riverroute/mosart_restfile.F90 index 3e5c39d..ed17d8c 100644 --- a/src/riverroute/mosart_restfile.F90 +++ b/src/riverroute/mosart_restfile.F90 @@ -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 @@ -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 @@ -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 !------------------------------------- @@ -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 !----------------------------------------------------------------------- @@ -275,10 +286,14 @@ 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 @@ -286,7 +301,7 @@ subroutine restFile_write_pfile( fnamer ) 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 diff --git a/src/riverroute/mosart_timemanager.F90 b/src/riverroute/mosart_timemanager.F90 index df53ba5..9aecebe 100644 --- a/src/riverroute/mosart_timemanager.F90 +++ b/src/riverroute/mosart_timemanager.F90 @@ -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 @@ -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 ) @@ -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()