Skip to content

Commit

Permalink
add sampled_on_subcycle flag and remove time_bounds field from instan…
Browse files Browse the repository at this point in the history
…taneous files
  • Loading branch information
Courtney Peverley committed Oct 11, 2024
1 parent 7b04a6e commit 225f7e3
Show file tree
Hide file tree
Showing 11 changed files with 618 additions and 592 deletions.
53 changes: 38 additions & 15 deletions src/control/cam_history.F90
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ subroutine intht (model_doi_url_in)
!
do t=1,ptapes
do fld=1,nflds(t)
if ((.not. tape(t)%hlist(fld)%field%sampled_on_subcycle) .and. nhtfrq(t) == 1) then
! Override accumulate flag to "I" if nhtfrq equals 1 and subcycle
! averaging is not enabled
tape(t)%hlist(fld)%avgflag = 'I'
end if

if (tape(t)%hlist(fld)%avgflag .ne. 'I') then
hfile_accum(t) = .true.
end if
Expand Down Expand Up @@ -4022,7 +4028,9 @@ subroutine h_inquire (t)
ierr=pio_inq_varid (tape(t)%Files(f),'nscur ', tape(t)%nscurid)
ierr=pio_inq_varid (tape(t)%Files(f),'nsteph ', tape(t)%nstephid)
end if
ierr=pio_inq_varid (tape(t)%Files(f),'time_bounds', tape(t)%tbndid)
if (f == accumulated_file_index) then
ierr=pio_inq_varid (tape(t)%Files(f),'time_bounds', tape(t)%tbndid)
end if
ierr=pio_inq_varid (tape(t)%Files(f),'date_written', tape(t)%date_writtenid)
ierr=pio_inq_varid (tape(t)%Files(f),'time_written', tape(t)%time_writtenid)
#if ( defined BFB_CAM_SCAM_IOP )
Expand Down Expand Up @@ -4321,6 +4329,7 @@ subroutine h_define (t, restart)
cam_snapshot_before_num_out = cam_snapshot_before_num, &
cam_snapshot_after_num_out = cam_snapshot_after_num)


if(restart) then
tape => restarthistory_tape
if(masterproc) write(iulog,*)'Opening netcdf history restart file ', trim(hrestpath(t))
Expand Down Expand Up @@ -4500,13 +4509,14 @@ subroutine h_define (t, restart)

if(.not. is_satfile(t)) then

ierr=pio_put_att (tape(t)%Files(f), tape(t)%timeid, 'bounds', 'time_bounds')

ierr=pio_def_var (tape(t)%Files(f),'time_bounds',pio_double,(/bnddim,timdim/),tape(t)%tbndid)
ierr=pio_put_att (tape(t)%Files(f), tape(t)%tbndid, 'long_name', 'time interval endpoints')
str = 'days since ' // date2yyyymmdd(nbdate) // ' ' // sec2hms(nbsec)
ierr=pio_put_att (tape(t)%Files(f), tape(t)%tbndid, 'units', trim(str))
ierr=pio_put_att (tape(t)%Files(f), tape(t)%tbndid, 'calendar', trim(calendar))
if (f == accumulated_file_index) then
ierr=pio_put_att (tape(t)%Files(f), tape(t)%timeid, 'bounds', 'time_bounds')
ierr=pio_def_var (tape(t)%Files(f),'time_bounds',pio_double,(/bnddim,timdim/),tape(t)%tbndid)
ierr=pio_put_att (tape(t)%Files(f), tape(t)%tbndid, 'long_name', 'time interval endpoints')
str = 'days since ' // date2yyyymmdd(nbdate) // ' ' // sec2hms(nbsec)
ierr=pio_put_att (tape(t)%Files(f), tape(t)%tbndid, 'units', trim(str))
ierr=pio_put_att (tape(t)%Files(f), tape(t)%tbndid, 'calendar', trim(calendar))
end if
!
! Character
!
Expand Down Expand Up @@ -5843,14 +5853,16 @@ subroutine wshist (rgnht_in)
cycle
end if
! We have two files - one for accumulated and one for instantaneous fields
if (f == accumulated_file_index .and. .not. restart .and. .not. is_initfile(t)) then
! accumulated tape - time is midpoint of time_bounds
ierr=pio_put_var (tape(t)%Files(f), tape(t)%timeid, (/start/),(/count1/),(/(tdata(1) + tdata(2)) / 2._r8/))
if (f == accumulated_file_index) then
ierr=pio_put_var (tape(t)%Files(f), tape(t)%tbndid, startc, countc, tdata)
if (.not. restart .and. .not. is_initfile(t)) then
! accumulated tape - time is midpoint of time_bounds
ierr=pio_put_var (tape(t)%Files(f), tape(t)%timeid, (/start/),(/count1/),(/(tdata(1) + tdata(2)) / 2._r8/))
end if
else
! not an accumulated history tape - time is current time
ierr=pio_put_var (tape(t)%Files(f), tape(t)%timeid, (/start/),(/count1/),(/time/))
end if
ierr=pio_put_var (tape(t)%Files(f), tape(t)%tbndid, startc, countc, tdata)
end do
if(.not.restart) beg_time(t) = time ! update beginning time of next interval
startc(1) = 1
Expand Down Expand Up @@ -5938,7 +5950,7 @@ end subroutine wshist

subroutine addfld_1d(fname, vdim_name, avgflag, units, long_name, &
gridname, flag_xyfill, sampling_seq, standard_name, fill_value, &
optype, op_f1name, op_f2name)
optype, op_f1name, op_f2name, sampled_on_subcycle)

!
!-----------------------------------------------------------------------
Expand Down Expand Up @@ -5970,6 +5982,7 @@ subroutine addfld_1d(fname, vdim_name, avgflag, units, long_name, &
character(len=*), intent(in), optional :: optype ! currently 'dif' or 'sum' is supported
character(len=*), intent(in), optional :: op_f1name ! first field to be operated on
character(len=*), intent(in), optional :: op_f2name ! second field which is subtracted from or added to first field
logical, intent(in), optional :: sampled_on_subcycle ! If .true., subcycle averaging is enabled
!
! Local workspace
!
Expand All @@ -5988,13 +6001,13 @@ subroutine addfld_1d(fname, vdim_name, avgflag, units, long_name, &
end if
call addfld(fname, dimnames, avgflag, units, long_name, gridname, &
flag_xyfill, sampling_seq, standard_name, fill_value, optype, op_f1name, &
op_f2name)
op_f2name, sampled_on_subcycle)

end subroutine addfld_1d

subroutine addfld_nd(fname, dimnames, avgflag, units, long_name, &
gridname, flag_xyfill, sampling_seq, standard_name, fill_value, optype, &
op_f1name, op_f2name)
op_f1name, op_f2name, sampled_on_subcycle)

!
!-----------------------------------------------------------------------
Expand Down Expand Up @@ -6030,6 +6043,7 @@ subroutine addfld_nd(fname, dimnames, avgflag, units, long_name, &
character(len=*), intent(in), optional :: optype ! currently 'dif' or 'sum' supported
character(len=*), intent(in), optional :: op_f1name ! first field to be operated on
character(len=*), intent(in), optional :: op_f2name ! second field which is subtracted from or added to first field
logical, intent(in), optional :: sampled_on_subcycle ! If .true., subcycle averaging is enabled

!
! Local workspace
Expand Down Expand Up @@ -6154,6 +6168,15 @@ subroutine addfld_nd(fname, dimnames, avgflag, units, long_name, &
listentry%field%fillvalue = fillvalue
endif

!
! Whether to allow subcycle averages; default is false
!
if (present(sampled_on_subcycle)) then
listentry%field%sampled_on_subcycle = sampled_on_subcycle
else
listentry%field%sampled_on_subcycle = .false.
end if

!
! Process shape
!
Expand Down
3 changes: 3 additions & 0 deletions src/control/cam_history_support.F90
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ module cam_history_support
integer :: meridional_complement ! meridional field id or -1
integer :: zonal_complement ! zonal field id or -1

! Logical to determine if subcycle averages are allowed
logical :: sampled_on_subcycle = .false.

character(len=field_op_len) :: field_op = '' ! 'sum' or 'dif'
integer :: op_field1_id ! first field id or -1
integer :: op_field2_id ! second field id or -1
Expand Down
6 changes: 3 additions & 3 deletions src/physics/cam/cam_diagnostics.F90
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ subroutine diag_init_dry(pbuf2d)
call register_vector_field('UTEND_TOT','VTEND_TOT')

! Debugging negative water output fields
call addfld ('INEGCLPTEND ', (/ 'lev' /), 'A', 'kg/kg/s', 'Cloud ice tendency due to clipping neg values after microp')
call addfld ('LNEGCLPTEND ', (/ 'lev' /), 'A', 'kg/kg/s', 'Cloud liq tendency due to clipping neg values after microp')
call addfld ('VNEGCLPTEND ', (/ 'lev' /), 'A', 'kg/kg/s', 'Vapor tendency due to clipping neg values after microp')
call addfld ('INEGCLPTEND ', (/ 'lev' /), 'A', 'kg/kg/s', 'Cloud ice tendency due to clipping neg values after microp', sampled_on_subcycle=.true.)
call addfld ('LNEGCLPTEND ', (/ 'lev' /), 'A', 'kg/kg/s', 'Cloud liq tendency due to clipping neg values after microp', sampled_on_subcycle=.true.)
call addfld ('VNEGCLPTEND ', (/ 'lev' /), 'A', 'kg/kg/s', 'Vapor tendency due to clipping neg values after microp', sampled_on_subcycle=.true.)

call addfld ('Z3', (/ 'lev' /), 'A', 'm', 'Geopotential Height (above sea level)')
call addfld ('Z1000', horiz_only, 'A', 'm', 'Geopotential Z at 1000 mbar pressure surface')
Expand Down
12 changes: 6 additions & 6 deletions src/physics/cam/check_energy.F90
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ subroutine check_energy_init()
history_waccm_out = history_waccm )

! register history variables
call addfld('TEINP', horiz_only, 'A', 'J/m2', 'Total energy of physics input')
call addfld('TEOUT', horiz_only, 'A', 'J/m2', 'Total energy of physics output')
call addfld('TEFIX', horiz_only, 'A', 'J/m2', 'Total energy after fixer')
call addfld('EFIX', horiz_only, 'A', 'W/m2', 'Effective sensible heat flux due to energy fixer')
call addfld('DTCORE', (/ 'lev' /), 'A', 'K/s' , 'T tendency due to dynamical core')
call addfld('DQCORE', (/ 'lev' /), 'A', 'kg/kg/s' , 'Water vapor tendency due to dynamical core')
call addfld('TEINP', horiz_only, 'A', 'J/m2', 'Total energy of physics input', sampled_on_subcycle=.true.)
call addfld('TEOUT', horiz_only, 'A', 'J/m2', 'Total energy of physics output', sampled_on_subcycle=.true.)
call addfld('TEFIX', horiz_only, 'A', 'J/m2', 'Total energy after fixer', sampled_on_subcycle=.true.)
call addfld('EFIX', horiz_only, 'A', 'W/m2', 'Effective sensible heat flux due to energy fixer', sampled_on_subcycle=.true.)
call addfld('DTCORE', (/ 'lev' /), 'A', 'K/s' , 'T tendency due to dynamical core', sampled_on_subcycle=.true.)
call addfld('DQCORE', (/ 'lev' /), 'A', 'kg/kg/s' , 'Water vapor tendency due to dynamical core', sampled_on_subcycle=.true.)

if ( history_budget ) then
call add_default ('DTCORE', history_budget_histfile_num, ' ')
Expand Down
Loading

0 comments on commit 225f7e3

Please sign in to comment.