Skip to content

Commit 9fe1ea8

Browse files
authored
Merge pull request #106 from slevis-lmwg/time_is_mid_of_bounds_iss52
time now equals the middle of the time_bounds
2 parents 41fbf9e + 6e06d77 commit 9fe1ea8

File tree

1 file changed

+45
-15
lines changed

1 file changed

+45
-15
lines changed

src/riverroute/mosart_histfile.F90

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ subroutine htape_addfld (t, f, avgflag)
445445
integer :: n ! field index on defined tape
446446
integer :: begr ! per-proc beginning land runoff index
447447
integer :: endr ! per-proc ending land runoff index
448+
character(len=1) :: avgflag_temp ! local copy of avgflag_pertape(t)
448449
character(len=*),parameter :: subname = 'htape_addfld'
449450
!-------------------------------------------------------
450451

@@ -479,6 +480,17 @@ subroutine htape_addfld (t, f, avgflag)
479480
call shr_sys_abort()
480481
end select
481482

483+
! Override this tape's avgflag if nhtfrq == 1
484+
if (tape(t)%nhtfrq == 1) then ! output is instantaneous
485+
avgflag_pertape(t) = 'I'
486+
end if
487+
! Override this field's avgflag if the namelist has set this tape to
488+
! - instantaneous
489+
avgflag_temp = avgflag_pertape(t)
490+
if (avgflag_temp == 'I') then
491+
tape(t)%hlist(n)%avgflag = avgflag_temp
492+
end if
493+
482494
end subroutine htape_addfld
483495

484496
!-----------------------------------------------------------------------
@@ -593,7 +605,6 @@ subroutine htape_create (t, histrest)
593605
character(len=CL) :: name ! name of attribute
594606
character(len=CL) :: units ! units of attribute
595607
character(len=CL) :: str ! global attribute string
596-
character(len= 1) :: avgflag ! time averaging flag
597608
character(len=*),parameter :: subname = 'htape_create'
598609
!-----------------------------------------------------
599610

@@ -719,6 +730,7 @@ subroutine htape_timeconst(t, mode)
719730
integer :: dtime ! timestep size
720731
integer :: yr,mon,day,nbsec ! year,month,day,seconds components of a date
721732
integer :: hours,minutes,secs ! hours,minutes,seconds of hh:mm:ss
733+
character(len= 12) :: step_or_bounds ! string used in long_name of several time variables
722734
character(len= 10) :: basedate ! base date (yyyymmdd)
723735
character(len= 8) :: basesec ! base seconds
724736
character(len= 8) :: cdate ! system date
@@ -754,32 +766,47 @@ subroutine htape_timeconst(t, mode)
754766

755767
dim1id(1) = time_dimid
756768
str = 'days since ' // basedate // " " // basesec
757-
call ncd_defvar(nfid(t), 'time', tape(t)%ncprec, 1, dim1id, varid, &
758-
long_name='time',units=str)
769+
if (tape(t)%hlist(1)%avgflag /= 'I') then ! NOT instantaneous fields tape
770+
step_or_bounds = 'time_bounds'
771+
long_name = 'time at exact middle of ' // step_or_bounds
772+
call ncd_defvar(nfid(t), 'time', tape(t)%ncprec, 1, dim1id, varid, &
773+
long_name=long_name, units=str)
774+
call ncd_putatt(nfid(t), varid, 'bounds', 'time_bounds')
775+
else ! instantaneous fields tape
776+
step_or_bounds = 'time step'
777+
long_name = 'time at end of ' // step_or_bounds
778+
call ncd_defvar(nfid(t), 'time', tape(t)%ncprec, 1, dim1id, varid, &
779+
long_name=long_name, units=str)
780+
end if
759781
cal = get_calendar()
760782
if ( trim(cal) == NO_LEAP_C )then
761783
caldesc = "noleap"
762784
else if ( trim(cal) == GREGORIAN_C )then
763785
caldesc = "gregorian"
764786
end if
765787
call ncd_putatt(nfid(t), varid, 'calendar', caldesc)
766-
call ncd_putatt(nfid(t), varid, 'bounds', 'time_bounds')
767788

768789
dim1id(1) = time_dimid
790+
long_name = 'current date (YYYYMMDD) at end of ' // step_or_bounds
769791
call ncd_defvar(nfid(t) , 'mcdate', ncd_int, 1, dim1id , varid, &
770-
long_name = 'current date (YYYYMMDD)')
792+
long_name = long_name)
793+
long_name = 'current seconds of current date at end of ' // step_or_bounds
771794
call ncd_defvar(nfid(t) , 'mcsec' , ncd_int, 1, dim1id , varid, &
772-
long_name = 'current seconds of current date', units='s')
795+
long_name = long_name, units='s')
796+
long_name = 'current day (from base day) at end of ' // step_or_bounds
773797
call ncd_defvar(nfid(t) , 'mdcur' , ncd_int, 1, dim1id , varid, &
774-
long_name = 'current day (from base day)')
798+
long_name = long_name)
799+
long_name = 'current seconds of current day at end of ' // step_or_bounds
775800
call ncd_defvar(nfid(t) , 'mscur' , ncd_int, 1, dim1id , varid, &
776-
long_name = 'current seconds of current day')
801+
long_name = long_name)
777802
call ncd_defvar(nfid(t) , 'nstep' , ncd_int, 1, dim1id , varid, &
778803
long_name = 'time step')
779804

780805
dim2id(1) = hist_interval_dimid; dim2id(2) = time_dimid
781-
call ncd_defvar(nfid(t), 'time_bounds', ncd_double, 2, dim2id, varid, &
782-
long_name = 'history time interval endpoints')
806+
if (tape(t)%hlist(1)%avgflag /= 'I') then ! NOT instantaneous fields tape
807+
call ncd_defvar(nfid(t), 'time_bounds', ncd_double, 2, dim2id, varid, &
808+
long_name = 'history time interval endpoints')
809+
end if
783810

784811
dim2id(1) = strlen_dimid; dim2id(2) = time_dimid
785812
call ncd_defvar(nfid(t), 'date_written', ncd_char, 2, dim2id, varid)
@@ -811,13 +838,16 @@ subroutine htape_timeconst(t, mode)
811838
call ncd_io('mscur' , mscur , 'write', nfid(t), nt=tape(t)%ntimes)
812839
call ncd_io('nstep' , nstep , 'write', nfid(t), nt=tape(t)%ntimes)
813840

814-
time = mdcur + mscur/secspday
841+
timedata(1) = tape(t)%begtime ! beginning time
842+
timedata(2) = mdcur + mscur / secspday ! end time
843+
if (tape(t)%hlist(1)%avgflag /= 'I') then ! NOT instantaneous fields tape
844+
time = (timedata(1) + timedata(2)) * 0.5_r8
845+
call ncd_io('time_bounds', timedata, 'write', nfid(t), nt=tape(t)%ntimes)
846+
else
847+
time = timedata(2)
848+
end if
815849
call ncd_io('time' , time , 'write', nfid(t), nt=tape(t)%ntimes)
816850

817-
timedata(1) = tape(t)%begtime
818-
timedata(2) = time
819-
call ncd_io('time_bounds', timedata, 'write', nfid(t), nt=tape(t)%ntimes)
820-
821851
call ncd_getdatetime (cdate, ctime)
822852
call ncd_io('date_written', cdate, 'write', nfid(t), nt=tape(t)%ntimes)
823853

0 commit comments

Comments
 (0)