Skip to content

History and diagnostic fixes. - #1158

Open
dabail10 wants to merge 6 commits into
CICE-Consortium:mainfrom
ESCOMP:historyfixes
Open

dabail10 wants to merge 6 commits into
CICE-Consortium:mainfrom
ESCOMP:historyfixes

Conversation

@dabail10

@dabail10 dabail10 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

For detailed information about submitting Pull Requests (PRs) to the CICE-Consortium,
please refer to: https://github.com/CICE-Consortium/About-Us/wiki/Resource-Index#information-for-developers

PR checklist

  • Short (1 sentence) summary of your PR:
    This is a series of fixes for issues found by Claude.ai in issue Ice BGC and history bugs #1151. These are not answer changing, but will change
    answers in some history output.
  • Developer(s):
    dabail10 (D. Bailey)
  • Suggest PR reviewers from list in the column to the right.
  • Please copy the PR test results link or provide a summary of testing completed below.
    https://github.com/CICE-Consortium/Test-Results/wiki/cice_by_hash_forks#2d271f51648078875165b411150248a73e30e400
  • How much do the PR code changes differ from the unmodified code?
    • bit for bit
    • different at roundoff level
    • more substantial
  • Does this PR create or have dependencies on Icepack or any other models?
    • Yes
    • No
  • Does this PR update the Icepack submodule? If so, the Icepack submodule must point to a hash on Icepack's main branch.
    • Yes
    • No
  • Does this PR add any new test cases?
    • Yes
    • No
  • Is the documentation being updated? ("Documentation" includes information on the wiki or in the .rst files from doc/source/, which are used to create the online technical docs at https://readthedocs.org/projects/cice-consortium-cice/. A test build of the technical docs will be performed as part of the PR testing.)
    • Yes
    • No, does the documentation need to be updated at a later time?
      • Yes
      • No
  • Please document the changes in detail, including why the changes are made. This will become part of the PR commit log.

These are the summaries from Claude. They will change some of the history / diagnostic output.

High-confidence bugs affecting model output/correctness

1. ice_history_bgc.F90:1993-1998 — ice isotope mass divided by snow density instead of ice density

call accum_hist_field(n_isosno(n,:), iblk, trcr(:,:,nt_isosno+n-1,iblk)/rhos, a2D)
call accum_hist_field(n_isoice(n,:), iblk, trcr(:,:,nt_isoice+n-1,iblk)/rhos, a2D)

The n_isoice (ice-isotope) term should divide by rhoi, not rhos — the very
next block (aerosols, lines 2017-2024) shows the correct pattern (snow /rhos,
ice /rhoi). Biases the ice-isotope concentration diagnostic by rhoi/rhos
(~3x). Fix: change line 1998's /rhos to /rhoi.

2. ice_history_bgc.F90:1564-1565 — wrong tracer-count variable, n_fed instead of n_fep

if (f_Fepsnow (1:1) /= 'x') then
  do n = 1, n_fed
     ...
     call define_hist_field(n_Fepsnow (n,:), ...)

n_fed (dissolved-Fe count) and n_fep (particulate-Fe count) are independent,
namelist-configurable tracer counts and can differ. Every other Fep block
(lines 924, 1020, 1194/1204, 1434, 1686) correctly loops 1, n_fep. If
n_fed /= n_fep, this under/over-registers n_Fepsnow — likely an
out-of-bounds write or missing history fields. Fix: change n_fed to
n_fep on line 1565.

3. ice_history_bgc.F90:3363-3366 — bgc_hum_cat1 registered under the wrong field-index variable (verified)

if (f_bgc_hum_cat1(1:1) /= 'x') &
     call define_hist_field(n_bgc_hum,"bgc_hum_cat1",...)

Uses n_bgc_hum instead of n_bgc_hum_cat1 (declared at line 250, correctly
used in accum_hist_bgc). Every neighboring _cat1 block (e.g.
bgc_Sil_cat1 immediately above) correctly uses its own dedicated index. This
overwrites the plain bgc_hum field's metadata slot, corrupting that
separately-used output field (referenced at lines 950, 2090, 3027, 3265).
Fix: change n_bgc_hum to n_bgc_hum_cat1 on line 3364.

4. ice_history.F90:3197-3202 — duplicated accumulation call doubles snowfracn (verified)

if (f_snowfracn(1:1) /= 'x') &
    call accum_hist_field(n_snowfracn-n2D, iblk, ncat_hist, &
                          snowfracn(:,:,1:ncat_hist,iblk), a3Dc)
if (f_snowfracn(1:1) /= 'x') &
    call accum_hist_field(n_snowfracn-n2D, iblk, ncat_hist, &
                          snowfracn(:,:,1:ncat_hist,iblk), a3Dc)

accum_hist_field is additive, so issuing the identical call twice silently
doubles the time-accumulated snowfracn category output. Fix: delete one
copy (lines 3200-3202).

5. ice_history_bgc.F90:2656-2672 — top-boundary iDi layer overwritten instead of accumulated

workz(i,j,k) = workz(i,j,k) + iDi(i,j,k,n,iblk)*vicen(i,j,n,iblk)**2/aicen(i,j,n,iblk)
workz(i,j,nzblyr)   = workz(i,j,nzblyr-1)

iDi is dimensioned through nblyr+1, so iDi(i,j,nblyr+1,n,iblk) is a real
boundary value (used correctly by the neighboring iki/zfswin blocks just
above/below). Here the top layer is simply copied from the interior layer
below instead of being accumulated from its own iDi value — the true
boundary value is never used. Fix: accumulate using
iDi(i,j,nblyr+1,n,iblk) the same way the interior layers are.

6. ice_history.F90:3085-3121 — stale dfresh used when update_ocn_f = .true.

if (.not. update_ocn_f) then
   ... dfresh = ...
endif
...
worka(i,j) = aice(i,j,iblk)*(fsalt(i,j,iblk)+dfresh)

dfresh is a loop-scalar with no else branch, so when update_ocn_f is
.true. it retains the value from the previous grid cell (or is undefined on
first use) instead of c0. Corrupts n_siflsaltbot/n_siflfwbot whenever
update_ocn_f=.true.. Fix: add else; dfresh = c0; endif (both
occurrences), or initialize dfresh = c0 at the top of each i,j loop.

7. ice_history.F90:2417-2483 — unconditional +c180 in direction diagnostics (icedir, icedirN, icedirE, atmdir)

if (abs(uvel(i,j,iblk)) > puny .or. abs(vvel(i,j,iblk)) > puny) &
   worka(i,j) = atan2(uvel(i,j,iblk),vvel(i,j,iblk))*rad_to_deg
   worka(i,j) = worka(i,j) + c180

Single-line if covers only the atan2 assignment; the +c180 normalization
runs unconditionally, so calm/near-zero-velocity cells report 180° instead of
the sentinel. Inconsistent with the correctly-guarded ocndir block just
below. Fix: wrap both statements in if (...) then ... endif. (Appears
long-standing, not newly introduced.)

15. io_binary/ice_history_write.F90:242,266 — wrong vertical-dimension loop bound for bio/aerosol 3D history fields

do n = n3Dzcum + 1, n3Dbcum
   do k = 1, nzilyr       ! should be nzblyr
   ...
do n = n3Dbcum + 1, n3Dacum
   do k = 1, nzilyr       ! should be nzalyr

nzilyr, nzblyr, nzalyr are distinct sizes. Both the netCDF backend
(io_netcdf/ice_history_write.F90:1121,1144) and PIO2 backend
(io_pio2/ice_history_write.F90:1127-1128,1163-1164) correctly use the
field-specific vertical dimension; the binary backend uses nzilyr for both,
truncating or overrunning bio/aerosol 3D history fields written in binary
format. Fix: use nzblyr on line 242 and nzalyr on line 266.

16. io_netcdf/ice_history_write.F90:610-621 — "4Df" fields defined without the time dimension, unlike PIO2

dimidcz(1:4),ns) ! ferret   ! only 4 of 5 dims passed — drops timid

The PIO2 backend defines the equivalent fields with the full 5-dim
dimidcz (including timid). Same logical history variables end up with a
different rank/shape (static vs. time-dependent) depending on which I/O
backend wrote the file.


Other credible findings (agent-reported, not independently re-verified)

  • io_binary/ice_history_write.F90 — several further binary-backend-only
    issues reported: a .hdr header-format argument-count mismatch for the 3Dz
    loop (format 993 expects 2 integers, only k supplied); stale/mis-scoped
    nn loop variable reused for 3Db/3Da/3Df .hdr category labels (cosmetic,
    metadata-file only, doesn't affect the actual binary data records); the
    "instantaneous vs. averaged" header flag ignores histfreq_n (so e.g.
    histfreq='1' with histfreq_n>1 is mislabeled, unlike netCDF/PIO2); nrec
    used after being incremented unconditionally even though only initialized
    on my_task==master_task (formally undefined, apparently harmless in
    practice).
  • ice_diagnostics.F90:459-491 — elseif between independent N/S
    umax_stab checks means only the northern warning prints if both
    hemispheres exceed the threshold simultaneously. Low impact: gated behind a
    hardcoded .false. debug flag (check_umax), not reachable in normal runs.

Minor / cosmetic only

  • ice_history_bgc.F90:954-958 — bgc_PON long_name text copy-pasted from
    the Sil (silicate) block above it.
  • ice_history.F90:1424-1427,1439-1442 — s22/yieldstress22 field
    descriptions say "component s12"/"component 12" instead of 22.
  • ice_history_bgc.F90:947,952,957 — "skelelal" typo for "skeletal".
  • ice_restart_driver.F90 (~lines 481, 1411) — two comment-only typos
    (stress12_1 should say stress12_3; aice_o should say aice_m); no
    functional effect.
  • io_pio2/ice_history_write.F90:1194 — loop-closing comment says
    num_avail_hist_fields_3Db but closes the 3Da loop.
  • ice_history_mechred.F90 — an if check missing a (1:1) substring
    compared to the file's other checks; confirmed via git blame as unchanged
    since file creation, functionally reasonable, not reported as a bug.

  answers.
- This is the first part of a list of issues identified by Claude.ai

@anton-seaice anton-seaice left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok to me

@apcraig apcraig left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable, I think the main thing is to check the time_rep "inst" vs "avg" logic.

@apcraig

apcraig commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

@dabail10. This seems close, could we get any final changes in, confirm it's ready, and maybe test and merge this week? I can test if you do make the final changes. Thanks.

@dabail10

Copy link
Copy Markdown
Contributor Author

@dabail10. This seems close, could we get any final changes in, confirm it's ready, and maybe test and merge this week? I can test if you do make the final changes. Thanks.

I think this is ready now.

@dabail10

Copy link
Copy Markdown
Contributor Author

I merged main to hopefully fix the testing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants