@@ -1172,6 +1172,7 @@ subroutine htape_addfld (t, f, avgflag)
11721172 integer :: beg1d,end1d ! beginning and ending indices for this field (assume already set)
11731173 integer :: num1d_out ! history output 1d size
11741174 type (bounds_type) :: bounds
1175+ character (len= avgflag_strlen) :: avgflag_temp ! local copy of hist_avgflag_pertape(t)
11751176 character (len=* ),parameter :: subname = ' htape_addfld'
11761177 !- ----------------------------------------------------------------------
11771178
@@ -1302,6 +1303,19 @@ subroutine htape_addfld (t, f, avgflag)
13021303 tape(t)% hlist(n)% avgflag = avgflag
13031304 end if
13041305
1306+ ! Override this tape's avgflag if nhtfrq == 1
1307+ if (tape(t)% nhtfrq == 1 ) then ! output is instantaneous
1308+ hist_avgflag_pertape(t) = ' I'
1309+ end if
1310+ ! Override this field's avgflag if the namelist or the previous line
1311+ ! has set this tape to
1312+ ! - instantaneous (I) or
1313+ ! - local time (L)
1314+ avgflag_temp = hist_avgflag_pertape(t)
1315+ if (avgflag_temp == ' I' .or. avgflag_temp(1 :1 ) == ' L' ) then
1316+ tape(t)% hlist(n)% avgflag = avgflag_temp
1317+ end if
1318+
13051319 end subroutine htape_addfld
13061320
13071321 !- ----------------------------------------------------------------------
@@ -3098,6 +3112,7 @@ subroutine htape_timeconst(t, mode)
30983112 integer :: mcdate ! current date
30993113 integer :: yr,mon,day,nbsec ! year,month,day,seconds components of a date
31003114 integer :: hours,minutes,secs ! hours,minutes,seconds of hh:mm:ss
3115+ character (len= 12 ) :: step_or_bounds ! string used in long_name of several time variables
31013116 character (len= 10 ) :: basedate ! base date (yyyymmdd)
31023117 character (len= 8 ) :: basesec ! base seconds
31033118 character (len= 8 ) :: cdate ! system date
@@ -3357,20 +3372,30 @@ subroutine htape_timeconst(t, mode)
33573372
33583373 dim1id(1 ) = time_dimid
33593374 str = ' days since ' // basedate // " " // basesec
3360- call ncd_defvar(nfid(t), ' time' , tape(t)% ncprec, 1 , dim1id, varid, &
3361- long_name= ' time' ,units= str)
3375+ if (hist_avgflag_pertape(t) /= ' I' ) then ! NOT instantaneous fields tape
3376+ step_or_bounds = ' time_bounds'
3377+ long_name = ' time at exact middle of ' // step_or_bounds
3378+ call ncd_defvar(nfid(t), ' time' , tape(t)% ncprec, 1 , dim1id, varid, &
3379+ long_name= long_name, units= str)
3380+ call ncd_putatt(nfid(t), varid, ' bounds' , ' time_bounds' )
3381+ else ! instantaneous fields tape
3382+ step_or_bounds = ' time step'
3383+ long_name = ' time at end of ' // step_or_bounds
3384+ call ncd_defvar(nfid(t), ' time' , tape(t)% ncprec, 1 , dim1id, varid, &
3385+ long_name= long_name, units= str)
3386+ end if
33623387 cal = get_calendar()
33633388 if ( trim (cal) == NO_LEAP_C )then
33643389 caldesc = " noleap"
33653390 else if ( trim (cal) == GREGORIAN_C )then
33663391 caldesc = " gregorian"
33673392 end if
33683393 call ncd_putatt(nfid(t), varid, ' calendar' , caldesc)
3369- call ncd_putatt(nfid(t), varid, ' bounds' , ' time_bounds' )
33703394
33713395 dim1id(1 ) = time_dimid
3396+ long_name = ' current date (YYYYMMDD) at end of ' // step_or_bounds
33723397 call ncd_defvar(nfid(t) , ' mcdate' , ncd_int, 1 , dim1id , varid, &
3373- long_name = ' current date (YYYYMMDD) ' )
3398+ long_name = long_name )
33743399 !
33753400 ! add global attribute time_period_freq
33763401 !
@@ -3397,18 +3422,23 @@ subroutine htape_timeconst(t, mode)
33973422 call ncd_putatt(nfid(t), ncd_global, ' time_period_freq' , &
33983423 trim (time_period_freq))
33993424
3425+ long_name = ' current seconds of current date at end of ' // step_or_bounds
34003426 call ncd_defvar(nfid(t) , ' mcsec' , ncd_int, 1 , dim1id , varid, &
3401- long_name = ' current seconds of current date' , units= ' s' )
3427+ long_name = long_name, units= ' s' )
3428+ long_name = ' current day (from base day) at end of ' // step_or_bounds
34023429 call ncd_defvar(nfid(t) , ' mdcur' , ncd_int, 1 , dim1id , varid, &
3403- long_name = ' current day (from base day)' )
3430+ long_name = long_name)
3431+ long_name = ' current seconds of current day at end of ' // step_or_bounds
34043432 call ncd_defvar(nfid(t) , ' mscur' , ncd_int, 1 , dim1id , varid, &
3405- long_name = ' current seconds of current day ' )
3433+ long_name = long_name )
34063434 call ncd_defvar(nfid(t) , ' nstep' , ncd_int, 1 , dim1id , varid, &
34073435 long_name = ' time step' )
34083436
34093437 dim2id(1 ) = hist_interval_dimid; dim2id(2 ) = time_dimid
3410- call ncd_defvar(nfid(t), ' time_bounds' , ncd_double, 2 , dim2id, varid, &
3411- long_name = ' history time interval endpoints' )
3438+ if (hist_avgflag_pertape(t) /= ' I' ) then ! NOT instantaneous fields tape
3439+ call ncd_defvar(nfid(t), ' time_bounds' , ncd_double, 2 , dim2id, varid, &
3440+ long_name = ' history time interval endpoints' )
3441+ end if
34123442
34133443 dim2id(1 ) = strlen_dimid; dim2id(2 ) = time_dimid
34143444 call ncd_defvar(nfid(t), ' date_written' , ncd_char, 2 , dim2id, varid)
@@ -3436,13 +3466,16 @@ subroutine htape_timeconst(t, mode)
34363466 call ncd_io(' mscur' , mscur , ' write' , nfid(t), nt= tape(t)% ntimes)
34373467 call ncd_io(' nstep' , nstep , ' write' , nfid(t), nt= tape(t)% ntimes)
34383468
3439- time = mdcur + mscur/ secspday
3469+ timedata(1 ) = tape(t)% begtime ! beginning time
3470+ timedata(2 ) = mdcur + mscur/ secspday ! end time
3471+ if (hist_avgflag_pertape(t) /= ' I' ) then ! NOT instantaneous fields tape
3472+ time = (timedata(1 ) + timedata(2 )) * 0.5_r8
3473+ call ncd_io(' time_bounds' , timedata, ' write' , nfid(t), nt= tape(t)% ntimes)
3474+ else
3475+ time = timedata(2 )
3476+ end if
34403477 call ncd_io(' time' , time , ' write' , nfid(t), nt= tape(t)% ntimes)
34413478
3442- timedata(1 ) = tape(t)% begtime
3443- timedata(2 ) = time
3444- call ncd_io(' time_bounds' , timedata, ' write' , nfid(t), nt= tape(t)% ntimes)
3445-
34463479 call getdatetime (cdate, ctime)
34473480 call ncd_io(' date_written' , cdate, ' write' , nfid(t), nt= tape(t)% ntimes)
34483481
0 commit comments