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

Timestamp in rpointer name #1147

Draft
wants to merge 3 commits into
base: cam_development
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions src/control/cam_comp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ subroutine cam_init( &
use cam_snapshot_common, only: cam_snapshot_deactivate
use air_composition, only: air_composition_init
use phys_grid_ctem, only: phys_grid_ctem_reg

use filenames, only: interpret_filename_spec
! Arguments
character(len=cl), intent(in) :: caseid ! case ID
character(len=cl), intent(in) :: ctitle ! case title
Expand Down Expand Up @@ -122,7 +122,6 @@ subroutine cam_init( &
integer, intent(in) :: stop_tod ! Stop time of day (sec)
integer, intent(in) :: ref_ymd ! Reference date (YYYYMMDD)
integer, intent(in) :: ref_tod ! Reference time of day (sec)

type(cam_out_t), pointer :: cam_out(:) ! Output from CAM to surface
type(cam_in_t) , pointer :: cam_in(:) ! Merged input state to CAM

Expand Down Expand Up @@ -152,6 +151,7 @@ subroutine cam_init( &

! Read CAM namelists.
filein = "atm_in" // trim(inst_suffix)

call read_namelist(filein, single_column, scmlat, scmlon)

! Open initial or restart file, and topo file if specified.
Expand Down
27 changes: 17 additions & 10 deletions src/control/cam_initfiles.F90
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ module cam_initfiles

real(r8), public, protected :: scale_dry_air_mass = 0.0_r8 ! Toggle and target avg air mass for MPAS dycore

! The restart pointer file contains name of most recently written primary restart file.
! The contents of this file are updated by cam_write_restart as new restart files are written.
character(len=cl), public, protected :: rest_pfile

! Filename for initial restart file.
character(len=cl) :: restart_file = ' '

Expand All @@ -68,16 +64,20 @@ subroutine cam_initfiles_readnl(nlfile)
use spmd_utils, only: mpicom, mstrid=>masterprocid, mpir8=>mpi_real8, &
mpichar=>mpi_character, mpi_logical
use cam_instance, only: inst_suffix

use filenames, only: interpret_filename_spec

character(len=*), intent(in) :: nlfile ! filepath for file containing namelist input

! Local variables
integer :: unitn, ierr

character(len=cl) :: locfn
logical :: filefound
integer :: xtype
integer(pio_offset_kind) :: slen
logical :: found

! The restart pointer file contains name of most recently written primary restart file.
character(len=cl) :: rest_pfile

character(len=*), parameter :: sub = 'cam_initfiles_readnl'

Expand Down Expand Up @@ -112,18 +112,25 @@ subroutine cam_initfiles_readnl(nlfile)
call mpi_bcast(scale_dry_air_mass, 1, mpir8, mstrid, mpicom, ierr)
if (ierr /= 0) call endrun(sub//": ERROR: mpi_bcast: scale_dry_air_mass")

! Set pointer file name based on instance suffix
rest_pfile = './rpointer.atm' // trim(inst_suffix)

! Set name of primary restart file
if (restart_run) then
! Read name of restart file from pointer file
if (masterproc) then
rest_pfile = interpret_filename_spec("rpointer.cam"//trim(inst_suffix)//".%y-%m-%d-%s", prev=.true.)
inquire(file=trim(rest_pfile),exist=found)
if(.not. found) then
write(iulog, "Warning : rpointer file "//trim(rest_pfile)//" not found.")
rest_pfile = "rpointer.cam"//trim(inst_suffix)
inquire(file=trim(rest_pfile),exist=found)
if(.not. found) then
call endrun(sub // ': ERROR: rpointer file: '//trim(rest_pfile) // ' not found')
endif
endif
unitn = getunit()
call opnfil(rest_pfile, unitn, 'f', status="old")
read (unitn, '(a)', iostat=ierr) restart_file
if (ierr /= 0) then
call endrun(sub // ': ERROR: reading rpointer file')
call endrun(sub // ': ERROR: reading rpointer file: '//trim(rest_pfile))
end if
close(unitn)
call freeunit(unitn)
Expand Down
35 changes: 16 additions & 19 deletions src/control/cam_restart.F90
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,8 @@ subroutine cam_write_restart(cam_in, cam_out, dyn_out, pbuf2d, &
! (%c = caseid, $y = year, $m = month, $d = day, $s = seconds in day, %t = number)
rfilename_spec = '%c.cam' // trim(inst_suffix) //'.r.%y-%m-%d-%s.nc'

if (present(yr_spec).and.present(mon_spec).and.present(day_spec).and.present(sec_spec)) then
fname = interpret_filename_spec( rfilename_spec, &
yr_spec=yr_spec, mon_spec=mon_spec, day_spec=day_spec, sec_spec= sec_spec )
else
fname = interpret_filename_spec( rfilename_spec )
end if
fname = interpret_filename_spec( rfilename_spec, &
yr_spec=yr_spec, mon_spec=mon_spec, day_spec=day_spec, sec_spec= sec_spec )

call cam_pio_createfile(fh, trim(fname), 0)
ierr = cam_pio_set_fill(fh)
Expand All @@ -132,38 +128,39 @@ subroutine cam_write_restart(cam_in, cam_out, dyn_out, pbuf2d, &
call ionosphere_write_restart(fh)
call write_restart_physics(fh, cam_in, cam_out, pbuf2d)

if (present(yr_spec).and.present(mon_spec).and.&
present(day_spec).and.present(sec_spec)) then
call write_restart_history(fh, yr_spec=yr_spec, mon_spec=mon_spec, &
day_spec=day_spec, sec_spec= sec_spec )
else
call write_restart_history(fh)
end if
call write_restart_history(fh, yr_spec=yr_spec, mon_spec=mon_spec, &
day_spec=day_spec, sec_spec= sec_spec )

! Close the primary restart file
call pio_closefile(fh)

! Update the restart pointer file
call write_rest_pfile(fname)
call write_rest_pfile(fname, yr_spec=yr_spec, mon_spec=mon_spec, &
day_spec=day_spec, sec_spec= sec_spec )

end subroutine cam_write_restart

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

subroutine write_rest_pfile(restart_file)
subroutine write_rest_pfile(restart_file, yr_spec, mon_spec, day_spec, sec_spec)

! Write the restart pointer file

use cam_initfiles, only: rest_pfile

use cam_instance, only: inst_suffix
use filenames, only: interpret_filename_spec
character(len=*), intent(in) :: restart_file
integer, optional, intent(in) :: yr_spec ! Simulation year
integer, optional, intent(in) :: mon_spec ! Simulation month
integer, optional, intent(in) :: day_spec ! Simulation day
integer, optional, intent(in) :: sec_spec ! Seconds into current simulation day

integer :: nsds, ierr
character(len=CL) :: rest_pfile
character(len=*), parameter :: sub='write_rest_pfile'
!---------------------------------------------------------------------------

if (masterproc) then

rest_pfile = interpret_filename_spec('rpointer.cam'//trim(inst_suffix)//'.'//'%y-%m-%d-%s',&
yr_spec=yr_spec, mon_spec=mon_spec, day_spec=day_spec, sec_spec= sec_spec )
nsds = getunit()
call opnfil(rest_pfile, nsds, 'f')
rewind nsds
Expand Down
1 change: 0 additions & 1 deletion src/control/runtime_opts.F90
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ subroutine read_namelist(nlfilename, single_column, scmlat, scmlon)
logical, intent(in) :: single_column
real(r8), intent(in) :: scmlat
real(r8), intent(in) :: scmlon

!---------------------------Local variables-----------------------------
character(len=*), parameter :: subname = "read_namelist"

Expand Down
3 changes: 3 additions & 0 deletions src/cpl/nuopc/atm_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1976,6 +1976,9 @@ subroutine cam_write_clockrest( clock, yr_spec, mon_spec, day_spec, sec_spec, rc
yr_spec=yr_spec, mon_spec=mon_spec, day_spec=day_spec, sec_spec= sec_spec )

if (masterproc) then
restart_pfile = interpret_filename_spec('rpointer.cpl.%y-%m-%d-%s',&
yr_spec=yr_spec, mon_spec=mon_spec, day_spec=day_spec, sec_spec= sec_spec )

write(iulog,*) " In this configuration, there is no mediator"
write(iulog,*) " Normally, the mediator restart file provides the restart time info"
write(iulog,*) " In this case, CAM will create the rpointer.cpl and cpl restart file"
Expand Down
Loading