Skip to content

Commit

Permalink
If avgflag /= 'I', time_bounds is present and time = mid of time_bounds
Browse files Browse the repository at this point in the history
...and other mods that I'm preserving from closed PR ESCOMP#2019, such as
- changes to long_names and
- treating avgflag as a tape (not field) trait for 'I' and 'L' tapes
  • Loading branch information
slevis-lmwg committed Mar 28, 2024
1 parent 1bab27e commit 258792e
Showing 1 changed file with 51 additions and 14 deletions.
65 changes: 51 additions & 14 deletions src/main/histFileMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,7 @@ subroutine htape_addfld (t, f, avgflag)
integer :: beg1d,end1d ! beginning and ending indices for this field (assume already set)
integer :: num1d_out ! history output 1d size
type(bounds_type) :: bounds
character(len=avgflag_strlen) :: avgflag_temp ! local copy of hist_avgflag_pertape(t)
character(len=*),parameter :: subname = 'htape_addfld'
!-----------------------------------------------------------------------

Expand Down Expand Up @@ -1300,6 +1301,19 @@ subroutine htape_addfld (t, f, avgflag)
tape(t)%hlist(n)%avgflag = avgflag
end if

! Override this tape's avgflag if nhtfrq == 1
if (tape(t)%nhtfrq == 1) then ! output is instantaneous
hist_avgflag_pertape(t) = 'I'
end if
! Override this field's avgflag if the namelist or the previous line
! has set this tape to
! - instantaneous (I) or
! - local time (L)
avgflag_temp = hist_avgflag_pertape(t)
if (avgflag_temp == 'I' .or. avgflag_temp(1:1) == 'L') then
tape(t)%hlist(n)%avgflag = avgflag_temp
end if

end subroutine htape_addfld

!-----------------------------------------------------------------------
Expand Down Expand Up @@ -3093,6 +3107,7 @@ subroutine htape_timeconst(t, mode)
integer :: mcdate ! current date
integer :: yr,mon,day,nbsec ! year,month,day,seconds components of a date
integer :: hours,minutes,secs ! hours,minutes,seconds of hh:mm:ss
character(len= 12) :: step_or_bounds ! string used in long_name of several time variables
character(len= 10) :: basedate ! base date (yyyymmdd)
character(len= 8) :: basesec ! base seconds
character(len= 8) :: cdate ! system date
Expand Down Expand Up @@ -3352,20 +3367,30 @@ subroutine htape_timeconst(t, mode)

dim1id(1) = time_dimid
str = 'days since ' // basedate // " " // basesec
call ncd_defvar(nfid(t), 'time', tape(t)%ncprec, 1, dim1id, varid, &
long_name='time',units=str)
if (tape(t)%hlist(1)%avgflag /= 'I') then ! NOT instantaneous fields tape
step_or_bounds = 'time_bounds'
long_name = 'time at exact middle of ' // step_or_bounds
call ncd_defvar(nfid(t), 'time', tape(t)%ncprec, 1, dim1id, varid, &
long_name=long_name, units=str)
call ncd_putatt(nfid(t), varid, 'bounds', 'time_bounds')
else ! instantaneous fields tape
step_or_bounds = 'time step'
long_name = 'time at end of ' // step_or_bounds
call ncd_defvar(nfid(t), 'time', tape(t)%ncprec, 1, dim1id, varid, &
long_name=long_name, units=str)
end if
cal = get_calendar()
if ( trim(cal) == NO_LEAP_C )then
caldesc = "noleap"
else if ( trim(cal) == GREGORIAN_C )then
caldesc = "gregorian"
end if
call ncd_putatt(nfid(t), varid, 'calendar', caldesc)
call ncd_putatt(nfid(t), varid, 'bounds', 'time_bounds')

dim1id(1) = time_dimid
long_name = 'current date (YYYYMMDD) at end of ' // step_or_bounds
call ncd_defvar(nfid(t) , 'mcdate', ncd_int, 1, dim1id , varid, &
long_name = 'current date (YYYYMMDD)')
long_name = long_name)
!
! add global attribute time_period_freq
!
Expand All @@ -3392,18 +3417,23 @@ subroutine htape_timeconst(t, mode)
call ncd_putatt(nfid(t), ncd_global, 'time_period_freq', &
trim(time_period_freq))

long_name = 'current seconds of current date at end of ' // step_or_bounds
call ncd_defvar(nfid(t) , 'mcsec' , ncd_int, 1, dim1id , varid, &
long_name = 'current seconds of current date', units='s')
long_name = long_name, units='s')
long_name = 'current day (from base day) at end of ' // step_or_bounds
call ncd_defvar(nfid(t) , 'mdcur' , ncd_int, 1, dim1id , varid, &
long_name = 'current day (from base day)')
long_name = long_name)
long_name = 'current seconds of current day at end of ' // step_or_bounds
call ncd_defvar(nfid(t) , 'mscur' , ncd_int, 1, dim1id , varid, &
long_name = 'current seconds of current day')
long_name = long_name)
call ncd_defvar(nfid(t) , 'nstep' , ncd_int, 1, dim1id , varid, &
long_name = 'time step')

dim2id(1) = hist_interval_dimid; dim2id(2) = time_dimid
call ncd_defvar(nfid(t), 'time_bounds', ncd_double, 2, dim2id, varid, &
long_name = 'history time interval endpoints')
if (tape(t)%hlist(1)%avgflag /= 'I') then ! NOT instantaneous fields tape
call ncd_defvar(nfid(t), 'time_bounds', ncd_double, 2, dim2id, varid, &
long_name = 'history time interval endpoints')
end if

dim2id(1) = strlen_dimid; dim2id(2) = time_dimid
call ncd_defvar(nfid(t), 'date_written', ncd_char, 2, dim2id, varid)
Expand Down Expand Up @@ -3431,13 +3461,16 @@ subroutine htape_timeconst(t, mode)
call ncd_io('mscur' , mscur , 'write', nfid(t), nt=tape(t)%ntimes)
call ncd_io('nstep' , nstep , 'write', nfid(t), nt=tape(t)%ntimes)

time = mdcur + mscur/secspday
timedata(1) = tape(t)%begtime ! beginning time
timedata(2) = mdcur + mscur/secspday ! end time
if (tape(t)%hlist(1)%avgflag /= 'I') then ! NOT instantaneous fields tape
time = (timedata(1) + timedata(2)) * 0.5_r8
call ncd_io('time_bounds', timedata, 'write', nfid(t), nt=tape(t)%ntimes)
else
time = timedata(2)
end if
call ncd_io('time' , time , 'write', nfid(t), nt=tape(t)%ntimes)

timedata(1) = tape(t)%begtime
timedata(2) = time
call ncd_io('time_bounds', timedata, 'write', nfid(t), nt=tape(t)%ntimes)

call getdatetime (cdate, ctime)
call ncd_io('date_written', cdate, 'write', nfid(t), nt=tape(t)%ntimes)

Expand Down Expand Up @@ -5254,6 +5287,10 @@ character(len=max_length_filename) function set_hist_filename (hist_freq, hist_m
write(cdate,'(i4.4,"-",i2.2,"-",i2.2,"-",i5.5)') yr,mon,day,sec
endif
write(hist_index,'(i1.1)') hist_file - 1
! TODO slevis: After hist_index add "i" or "a"
! For guidance on how to split the files, search for
! maxsplitfiles in https://github.com/ESCOMP/CAM/pull/903/files
! See CAM#1003 for a bug-fix in monthly avged output
set_hist_filename = "./"//trim(caseid)//"."//trim(compname)//trim(inst_suffix)//&
".h"//hist_index//"."//trim(cdate)//".nc"

Expand Down

0 comments on commit 258792e

Please sign in to comment.