@@ -514,6 +514,7 @@ subroutine htape_addfld (t, f, avgflag)
514514 integer :: begrof ! per-proc beginning land runoff index
515515 integer :: endrof ! per-proc ending land runoff index
516516 integer :: numrtm ! total number of rtm cells on all procs
517+ character (len= 1 ) :: avgflag_temp ! local copy of rtmhist_avgflag_pertape(t)
517518 character (len=* ),parameter :: subname = ' htape_addfld'
518519 !- ------------------------------------------------------
519520
@@ -551,6 +552,16 @@ subroutine htape_addfld (t, f, avgflag)
551552 call shr_sys_abort()
552553 end select
553554
555+ ! Override this tape's avgflag if nhtfrq == 1
556+ if (tape(t)% nhtfrq == 1 ) then ! output is instantaneous
557+ rtmhist_avgflag_pertape(t) = ' I'
558+ end if
559+ ! Override this field's avgflag if the namelist has set this tape to
560+ ! - instantaneous
561+ avgflag_temp = rtmhist_avgflag_pertape(t)
562+ if (avgflag_temp == ' I' ) then
563+ tape(t)% hlist(n)% avgflag = avgflag_temp
564+ end if
554565
555566 end subroutine htape_addfld
556567
@@ -678,7 +689,6 @@ subroutine htape_create (t, histrest)
678689 character (len= 256 ) :: name ! name of attribute
679690 character (len= 256 ) :: units ! units of attribute
680691 character (len= 256 ) :: str ! global attribute string
681- character (len= 1 ) :: avgflag ! time averaging flag
682692 character (len=* ),parameter :: subname = ' htape_create'
683693 !- ----------------------------------------------------
684694
@@ -821,6 +831,7 @@ subroutine htape_timeconst(t, mode)
821831 integer :: dtime ! timestep size
822832 integer :: yr,mon,day,nbsec ! year,month,day,seconds components of a date
823833 integer :: hours,minutes,secs ! hours,minutes,seconds of hh:mm:ss
834+ character (len= 12 ) :: step_or_bounds ! string used in long_name of several time variables
824835 character (len= 10 ) :: basedate ! base date (yyyymmdd)
825836 character (len= 8 ) :: basesec ! base seconds
826837 character (len= 8 ) :: cdate ! system date
@@ -857,32 +868,47 @@ subroutine htape_timeconst(t, mode)
857868
858869 dim1id(1 ) = time_dimid
859870 str = ' days since ' // basedate // " " // basesec
860- call ncd_defvar(nfid(t), ' time' , tape(t)% ncprec, 1 , dim1id, varid, &
861- long_name= ' time' ,units= str)
871+ if (tape(t)% hlist(1 )% avgflag /= ' I' ) then ! NOT instantaneous fields tape
872+ step_or_bounds = ' time_bounds'
873+ long_name = ' time at exact middle of ' // step_or_bounds
874+ call ncd_defvar(nfid(t), ' time' , tape(t)% ncprec, 1 , dim1id, varid, &
875+ long_name= long_name, units= str)
876+ call ncd_putatt(nfid(t), varid, ' bounds' , ' time_bounds' )
877+ else ! instantaneous fields tape
878+ step_or_bounds = ' time step'
879+ long_name = ' time at end of ' // step_or_bounds
880+ call ncd_defvar(nfid(t), ' time' , tape(t)% ncprec, 1 , dim1id, varid, &
881+ long_name= long_name, units= str)
882+ end if
862883 cal = get_calendar()
863884 if ( trim (cal) == NO_LEAP_C )then
864885 caldesc = " noleap"
865886 else if ( trim (cal) == GREGORIAN_C )then
866887 caldesc = " gregorian"
867888 end if
868889 call ncd_putatt(nfid(t), varid, ' calendar' , caldesc)
869- call ncd_putatt(nfid(t), varid, ' bounds' , ' time_bounds' )
870890
871891 dim1id(1 ) = time_dimid
892+ long_name = ' current date (YYYYMMDD) at end of ' // step_or_bounds
872893 call ncd_defvar(nfid(t) , ' mcdate' , ncd_int, 1 , dim1id , varid, &
873- long_name = ' current date (YYYYMMDD)' )
894+ long_name = long_name)
895+ long_name = ' current seconds of current date at end of ' // step_or_bounds
874896 call ncd_defvar(nfid(t) , ' mcsec' , ncd_int, 1 , dim1id , varid, &
875- long_name = ' current seconds of current date' , units= ' s' )
897+ long_name = long_name, units= ' s' )
898+ long_name = ' current day (from base day) at end of ' // step_or_bounds
876899 call ncd_defvar(nfid(t) , ' mdcur' , ncd_int, 1 , dim1id , varid, &
877- long_name = ' current day (from base day)' )
900+ long_name = long_name)
901+ long_name = ' current seconds of current day at end of ' // step_or_bounds
878902 call ncd_defvar(nfid(t) , ' mscur' , ncd_int, 1 , dim1id , varid, &
879- long_name = ' current seconds of current day ' )
903+ long_name = long_name )
880904 call ncd_defvar(nfid(t) , ' nstep' , ncd_int, 1 , dim1id , varid, &
881905 long_name = ' time step' )
882906
883907 dim2id(1 ) = hist_interval_dimid; dim2id(2 ) = time_dimid
884- call ncd_defvar(nfid(t), ' time_bounds' , ncd_double, 2 , dim2id, varid, &
885- long_name = ' history time interval endpoints' )
908+ if (tape(t)% hlist(1 )% avgflag /= ' I' ) then ! NOT instantaneous fields tape
909+ call ncd_defvar(nfid(t), ' time_bounds' , ncd_double, 2 , dim2id, varid, &
910+ long_name = ' history time interval endpoints' )
911+ end if
886912
887913 dim2id(1 ) = strlen_dimid; dim2id(2 ) = time_dimid
888914 call ncd_defvar(nfid(t), ' date_written' , ncd_char, 2 , dim2id, varid)
@@ -911,13 +937,16 @@ subroutine htape_timeconst(t, mode)
911937 call ncd_io(' mscur' , mscur , ' write' , nfid(t), nt= tape(t)% ntimes)
912938 call ncd_io(' nstep' , nstep , ' write' , nfid(t), nt= tape(t)% ntimes)
913939
914- time = mdcur + mscur/ secspday
940+ timedata(1 ) = tape(t)% begtime ! beginning time
941+ timedata(2 ) = mdcur + mscur / secspday ! end time
942+ if (tape(t)% hlist(1 )% avgflag /= ' I' ) then ! NOT instantaneous fields tape
943+ time = (timedata(1 ) + timedata(2 )) * 0.5_r8
944+ call ncd_io(' time_bounds' , timedata, ' write' , nfid(t), nt= tape(t)% ntimes)
945+ else
946+ time = timedata(2 )
947+ end if
915948 call ncd_io(' time' , time , ' write' , nfid(t), nt= tape(t)% ntimes)
916949
917- timedata(1 ) = tape(t)% begtime
918- timedata(2 ) = time
919- call ncd_io(' time_bounds' , timedata, ' write' , nfid(t), nt= tape(t)% ntimes)
920-
921950 call getdatetime (cdate, ctime)
922951 call ncd_io(' date_written' , cdate, ' write' , nfid(t), nt= tape(t)% ntimes)
923952
0 commit comments