Skip to content

Commit

Permalink
ice_history: fix history averaging over multiple time steps
Browse files Browse the repository at this point in the history
The code at the beginning of subroutine 'accum_hist' is responsible for
resetting the accumulation arrays a2D, a3Dc, etc. to zero when writing
snapshots, but it also resets them if "histfreq(ns) == '1'".

This has been the case since ab1c53e (Many thanks to Dave Bailey (NCAR)
for getting this ball rolling., 2009-06-01) [1], which implemented the
multiple-stream history functionality in CICE 5.

This means that averaging over multiple time steps, i.e.

    histfreq   = '1'
    histfreq_n =  m     ! m > 1
    hist_avg   = .true.

does not work: the accumulation arrays will always be reset to zero at
the beginning of 'accum_hist' and no accumulation will happen. This also
means that the variable 'time_beg' is not initialized in that
configuration, since this it is initialized in the 'else' branch of that
'if' statement.

Commit ab1c53e also *removed* the following line in ice_init::input_data:

    if (histfreq == '1') hist_avg = .false.         ! potential conflict

so it's unclear if that configuration was forgotten at the time.

Allow overaging over multiple time steps by only resetting the
accumulation arrays if 'hist_avg' is false.

As a side effect, this correctly initializes the 'time_beg' variable,
which avoids writing that variable uninitialized to the output files, which can
lead to analysis tools failing if compiling with '-init=snan,arrays' (or
similar [2].

While at it, remove a commented line in the 'else' branch since it's
implemented just below.

This commit does not modify neither
ice_history_shared::construct_filename nor the different
ice_history_write::ice_write_hist subroutines, that also assume that
'histfreq = 1' implies 'histfreq_n = 1'. They will be modified in
subsequent commits.

[1] CICE-Consortium/CICE-svn-trunk@ab1c53e?branch=ab1c53eaf0c4a0b0dbc65e582a5e1b35c2208a88&diff=unified#diff-aebd77751eba77ed6b6c194d4cd2e4b353258f7e903cc7877343911c9b25c283L1296-L1306
[2] Closes CICE-Consortium#551
  • Loading branch information
phil-blain committed Jan 12, 2021
1 parent de60856 commit 191d5cc
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions cicecore/cicedynB/analysis/ice_history.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1814,7 +1814,7 @@ subroutine accum_hist (dt)
n4Dfcum = n4Dscum + num_avail_hist_fields_4Df ! should equal num_avail_hist_fields_tot

do ns = 1,nstreams
if (.not. hist_avg .or. histfreq(ns) == '1') then ! write snapshots
if (.not. hist_avg) then ! write snapshots
do n = 1,n2D
if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) &
a2D(:,:,n,:) = c0
Expand Down Expand Up @@ -1862,7 +1862,6 @@ subroutine accum_hist (dt)
avgct(ns) = c1
else ! write averages over time histfreq
avgct(ns) = avgct(ns) + c1
! if (avgct(ns) == c1) time_beg(ns) = (time-dt)/int(secday)
if (avgct(ns) == c1) then
time_beg(ns) = (time-dt)/int(secday)
time_beg(ns) = real(time_beg(ns),kind=real_kind)
Expand Down

0 comments on commit 191d5cc

Please sign in to comment.