Skip to content

CESM-compliant CISM history files (h0i/h0a) through CISM's [CF output] machinery - #150

Merged
Katetc merged 12 commits into
masterfrom
lipscomb/cesm_timevars
Oct 9, 2026
Merged

Katetc merged 12 commits into
masterfrom
lipscomb/cesm_timevars

Conversation

@whlipscomb

@whlipscomb whlipscomb commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

This PR makes CISM's history and restart files follow CESM conventions, as discussed in #75
(and #76), and moves CESM history output onto CISM's own [CF output] machinery. It points
source_cism to 76d7dc15 on the CISM branch lipscomb/cesm_timevars (ESCOMP/CISM), which has the
corresponding CISM changes.

Note: This depends on the CISM PR ESCOMP/CISM#92. Before merging, source_cism should be updated
to point to a CISM tag that includes those changes.

What changes for users

  • History file names and streams
    • Instantaneous fields are written to h0i files: <case>.cism.<icesheet>.h0i.YYYY-MM-DD.nc,
      named with the date of the snapshot (e.g., h0i.1862-01-01 holds the state at the end of 1861).
    • Fields whose names end in _tavg are written to annual h0a files:
      <case>.cism.<icesheet>.h0a.YYYY.nc, named with the year of the average.
    • The initial history file is now an ordinary h0i file named with the start date, replacing
      initial_hist.
    • Users still list history fields in esm_history_vars (user_nl_cism); buildnml splits the list
      into the two streams.
  • Time variables (CESM conventions)
    • time is in units of days since 0001-01-01 00:00:00, computed from the CESM clock.
    • h0a files have time_bounds(time, nbnd) for the averaging interval, and their time is its
      midpoint (Set time value for averaged quantities to midpoint of averaging period #76).
    • CISM's own internal_time is kept, in common_years since 0000-01-01 00:00:00.
    • The files open with xarray, with time decoded as noleap dates.
  • Time averages across restarts: averages continue exactly across restarts in continue runs,
    including restarts in the middle of an averaging interval. CISM now saves the averaging state in
    its restart files. Startup, hybrid and branch runs start a new averaging interval.
  • New history_option = 'never': writes no CISM history files at all, including the initial
    h0i file.
  • Logging: CISM's log messages (including the per-timestep diagnostics) now go to the glc log
    file instead of the cesm log, and are no longer written twice. The default log_level is now 1:
    only fatal errors are also written to the cesm log.
  • Config file: cism.<icesheet>.config has two [CF output] sections (h0i and h0a) for the
    history streams. esm_history_vars is no longer written to [esm_output], which now holds only
    history_option and history_frequency.

Default output (no _tavg fields in esm_history_vars) is unchanged apart from the file names and
time variables: the h0i fields are identical to the old history files.

Commits

Each commit message has details, test results, and a "Notes for reviewers" section.

Commit Summary
83ece67 Point to CISM branch lipscomb/cesm_timevars; update glimmer_nc_createfile calls
7660307 time in history and restart files as days since 0001-01-01
6876a83 h0i history files through [CF output]; initial h0i replaces initial_hist; history_option = 'never'; coupler history-alarm fix for two ice sheets
4e6ec75 h0a (annual time-average) history files; new testmods cism/tavg_history
c1f749e Correct a testmods comment (override_glc_frac)
ff15e3d Continue time averages exactly across restarts
3913dc6 Stop writing esm_history_vars to the CISM config file
04753ff Write CISM log output to the glc log; default log_level 1
4f6a5c8 Fix MULTINOAIS/MULTINOGRIS tests for the initial h0i file

Possible conflicts with the namelist PR

  • cime_config/buildnml: new functions _add_history_sections_to_cism_config and
    _write_history_section, and a new group list _CISM_CONFIG_HELPER_GROUPS
  • cime_config/namelist_definition_cism.xml:
    • esm_history_vars moved to the new group cism_history
    • history_option: new value 'never'
    • log_level: default and description
  • cime_config/testdefs/testmods_dirs/cism/: override_glc_frac and noevolve
    (history_option = 'never'), and new tavg_history
  • cime_config/SystemTests/multivssingle.py
  • cime_config/config_archive.xml: history file patterns

No changes to testlist_cism.xml.

Testing (derecho, intel and gnu)

Full aux_glc (minus NCK_Ly3, which fails on unmodified code, #110), plus
ERS_Ld900.f10_f10_mg37.I1850Clm50SpG.derecho_intel.cism-tavg_history, compared with baselines from
CISM-wrapper master + cism_main_3.00.001:

  • All 34 tests build and run.
  • All restart, branch and hybrid comparisons pass, as do the multi-ice-sheet and multi-instance
    comparisons.
  • Expected failures:
    • NLCOMP, from the config file changes above.
    • BASELINE, because the history streams are renamed. Comparing new h0i files directly with the old
      history files showed identical fields.
  • One throughput warning (TPUTCOMP), due to machine load.
  • ERI_Ly10.f10_f10_mg37.I1850Clm50SpG.derecho_intel.cism-isostasy_period4 needs a walltime above
    1 hour (it takes about 70 minutes).
  • New baselines for this branch: cesm_timevars_step3.

h0a output: checked in the files from the tavg_history tests:

  • file names;
  • time_bounds spanning one year from Jan 1;
  • time at the midpoint of the interval;
  • only _tavg fields present.

ERS_Ld900...cism-tavg_history restarts in the middle of a year, after CISM's first timestep. Its
h0a file averaging across the restart is identical between the base and restart runs.

Standalone CISM: the CISM branch was tested separately (Antarctic and Greenland test cases,
including restarts in the middle of averaging intervals with nonzero partial sums).

Known issues and follow-ups

  • Restart before CISM's first timestep: a restart written before CISM's first timestep after a
    startup run (e.g., ERS_Ld540.f10_f10_mg37.I1850Clm50SpG, restarting in late September of year 1)
    is not bit-for-bit.
    • The first CISM substep after the restart has slightly different SMB and calving fluxes, so the
      ice runoff sent to the coupler differs slightly; the ice sheet state is identical.
    • This happens with or without the changes in this PR.
    • The same restart is bit-for-bit in standalone CISM, so the cause is in the CESM/GLAD path. To be
      investigated separately.
  • Runs that don't start on Jan 1: these skip the first, partial-year h0a file. This could not
    be tested, because an evolving CISM run starting mid-year currently aborts in GLAD (Modify naming and attributes of time variables on history files to be consistent with other CESM components #75, item 14).
  • History variable list checks: checking history variable lists in buildnml (e.g., duplicate
    _tavg fields) is deferred.
  • Default history fields: making the default history fluxes their _tavg versions (Modify naming and attributes of time variables on history files to be consistent with other CESM components #75,
    item 11) is planned as a separate step.

🤖 Generated with Claude Code

whlipscomb and others added 9 commits October 3, 2026 14:36
…file calls

Update the source_cism submodule (fxtag and recorded commit) to 3fd09923 on the CISM branch
lipscomb/cesm_timevars. This CISM branch changes the output time variables to be more consistent
with CESM conventions (see issue #75) and adds options that will be used to write CESM history files
(h0i and h0a) through CISM's [CF output] machinery in later commits:
* 'time' and 'internal_time' are double precision; 'time' has long_name 'time' and no standard_name.
* Time units are '<units> since YYYY-01-01 00:00:00'; internal_time uses the UDUNITS spelling
  'common_years', so xarray can decode the time variables and open CISM files.
* Files with time-averaged ('_tavg') fields have time_bounds and internal_time_bounds(time, nbnd);
  instantaneous files and restart files have no time bounds.
* New output-file options one_file_per_write and external_control (not yet used by the wrapper).
* Several fixes to time-average output.

In glc_io.F90, the argument baseline_year of glimmer_nc_createfile was renamed in CISM to
external_baseline_year. The three calls (history file, tavg helper, restart file) are updated.
No other wrapper changes.

Testing: aux_glc on derecho (intel and gnu) with --compare against baselines generated from
CISM-wrapper master + cism_main_3.00.001:
* All tests build and run, and all restart comparisons (ERS, ERP, ERI) pass.
* BASELINE comparisons pass: CISM history fields are identical to the baselines (cprnc compares
  field values; the metadata changes above do not count as differences).
* Exceptions, not related to this change:
  - NCK_Ly3.f09_g17_gris20.T1850Gg.derecho_gnu fails COMPARE_base_multiinst on unmodified code
    as well (known issue #110).
  - ERI_Ly10.f10_f10_mg37.I1850Clm50SpG.derecho_intel.cism-isostasy_period4 exceeded the 1-hour
    walltime requested for the test (in both the baseline and the new run).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Following CESM conventions (see issue #75), the 'time' variable in CISM history and restart files
now has units 'days since 0001-01-01 00:00:00'. Previously, 'time' was the CESM year in units of
common years since 0000-01-01.

The value of 'time' is computed from the CESM clock by a new function, glc_io_days_since_ref,
which uses ESMF to get the time interval from 0001-01-01 00:00:00 to the current time in the
calendar of the CESM clock (e.g., noleap). This is exact (no accumulated roundoff), includes any
time of day as a fraction of a day, and does not assume a particular calendar.
The module parameter baseline_year (= 0) is replaced by time_ref_year (= 1) and time_units ('days'),
which are passed to glimmer_nc_createfile.

For example, the history file written at 0002-01-01 00:00 now has time = 365 days
(previously 2 common years), which is the same instant.

CISM's own time variable, internal_time, is unchanged (units 'common_years since 0000-01-01 00:00:00').

Testing: a subset of aux_glc on derecho (intel and gnu; SMS, ERS, ERP, ERI, multi-instance,
both ice sheets) with --compare against baselines from CISM-wrapper master + cism_main_3.00.001:
all tests build and run, and all restart comparisons pass. The BASELINE comparisons fail
as expected, with 'time' the only field that differs. The time calculation was also tested
standalone with ESMF 8.9.1 (noleap): 0002-01-01 -> 365, 1862-01-01 -> 679265,
1861-07-02 12:00 -> 679082.5.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…t] machinery

This commit replaces the wrapper's history-file code with a new path that uses the
'one_file_per_write' and 'external_control' options added on the CISM branch
lipscomb/cesm_timevars. It handles instantaneous history fields (the 'h0i' stream).
It also updates source_cism to a82a8120 on that branch, which fixes a CISM bug found in this work:
when a file is written by more than one I/O module (glide_io and glad_io), the variable list saved
for later files (vars_copy) lost most of its variables, so only the first file written by each
output object contained the history fields.
Time-average fields (the 'h0a' stream) will be added in the next commit; until then,
'_tavg' fields in esm_history_vars are not written (buildnml prints a warning).
See issue #75 for the design discussion.

How it works:

* buildnml splits esm_history_vars into instantaneous fields and time-average fields (names
  ending in '_tavg'), and writes a [CF output] section to cism.<icesheet>.config:
      [CF output]
      name: h0i
      variables: <instantaneous fields>
      xtype: double
      external_control: .true.
      one_file_per_write: .true.
  CISM creates a persistent output object for this section at initialization, but never writes
  it on its own: no file is opened at initialization, CISM's own writeall only accumulates
  averages, and nothing is written at finalization. CISM also applies its usual checks
  (e.g., no mixing of instantaneous and time-average fields in one section).
  The 'name' is a stream label, not a file name; the wrapper finds the object by this name.

* glc_history_init finds the h0i object in CISM's output list (find_history_output) and checks
  that it has external_control and one_file_per_write set, and that it holds no time-average
  fields; otherwise it aborts with a clear message. If an ice sheet has no h0i section
  (e.g., an empty variable list, or history_option = 'never'), no history files are written.

* The history tape (history_tape_base and its standard/coupler subclasses) now holds the stream
  tag and a pointer to the CISM output object, instead of the variable list and the auxiliary
  oc_tavg_helper object. history_option and history_frequency apply to the h0i stream, as before.
  The standard tape's time flag name now includes the tag (do_hist_<icesheet>_<tag>), so that each
  stream can have its own flag.

* New routine glc_io_write_hfile writes one history file using the CISM calling sequence:
  glimmer_nc_newfile, glimmer_nc_createfile, glide_io_create, glad_io_create, (CESM global
  attributes), glide_nc_filldvars, glimmer_nc_write_timeslice, glide_io_write, glad_io_write,
  glide_avg_reset (if needed), glimmer_nc_closefile. The object persists between files.
  This replaces glc_io_write_history, which built a new output object for each file, and
  glc_io_write_history_tavg_helper, which managed oc_tavg_helper. (The latter also pointed CISM's
  output list at oc_tavg_helper, which would hide the [CF output] objects.)

File names (glc_filename):
* h0i files are named <case>.cism<inst>.<icesheet>.h0i.YYYY-MM-DD.nc (no seconds, as in CTSM).
  The date is the time of the snapshot; e.g., h0i.1862-01-01 holds the state at 1862-01-01 00:00,
  i.e., at the end of 1861.
* The initial history file is now an ordinary h0i file named with the run start date
  (e.g., h0i.0001-01-01), replacing the 'initial_hist' file. As before, it is not written
  on continue runs.
* The 'history', 'initial_history' and 'tavg_helper' file types are removed.

New history_option value 'never':
* history_option = 'never' writes no CISM history files at all, including the initial h0i file.
  (buildnml then writes no history sections.)
* It is used in two testmods directories. CIME fails a restart comparison if a history file exists
  in only one of the two runs, unless the file name contains 'initial'. The old initial_hist files
  were skipped for this reason; the initial h0i file is not.
  - cism/override_glc_frac (ERS_D_Ld9.f10_f10_mg37.I1850Clm50SpG.derecho_gnu): this 9-day test writes
    no regular history files, so the initial run would write an initial h0i file and the restart run
    none. The test is about what is sent to the coupler, not CISM output.
    Note: this differs from item 4 of the summary on issue #75, which proposed history_option = 'coupler'
    for this test; Bill Sacks suggested 'never' as an alternative.
  - cism/noevolve (ERS_D_Ly3.f09_g17_gris4.T1850Gg.derecho_intel, SMS_Lm13.f10_f10_mg37.I1850Clm50SpG):
    with no evolving ice sheet, CISM treats every run (including the restart run of an ERS test) as a
    startup run, so each run writes its own initial h0i file, and no regular h0i files are written.
    (The old code behaved the same way, but CIME ignored the initial_hist files.)
  Production runs are not affected; e.g., non-evolving CESM runs still write an initial h0i file at the
  start of each run segment. An alternative (asked on issue #75) is to put 'initial' in the name of
  the initial h0i file; then CIME would skip it in comparisons, and these testmods changes would not
  be needed.

Bug fix: coupler history alarm with more than one ice sheet
* With history_option = 'coupler' and two ice sheets, only the first ice sheet wrote regular history
  files: the first history tape turned off the coupler's history alarm (alarm_history) before the
  second tape checked it. (The old code had the same bug.) Now, in history_tape_coupler.F90, the tape
  that finds the alarm ringing records the clock time, and any other tape checking at the same clock
  time (i.e., in the same coupling step) also writes.

Other changes:
* config_archive.xml: the history file patterns '.h.' and '.initial_hist.' are replaced by
  '[a-z]+\.h0[ai]\..*\.nc$', which covers both h0i and (later) h0a files; with the existing
  stream regex, the history streams are e.g. 'gris.h0i' and 'gris.h0a'. The test file names
  are updated accordingly.
* buildnml aborts with a clear message if a history variable list is longer than 400 characters,
  the maximum length of a value in CISM's config file reader (longer values would be truncated silently).

Notes for reviewers -- files that may conflict with other open work (e.g., the namelist PR):
* cime_config/buildnml (new functions _add_history_sections_to_cism_config and
  _write_history_section, called from _create_cism_config)
* cime_config/namelist_definition_cism.xml (history_option: new valid value 'never')
* cime_config/testdefs/testmods_dirs/cism/override_glc_frac/user_nl_cism (history_option = 'never')
* cime_config/testdefs/testmods_dirs/cism/noevolve/user_nl_cism (new file; history_option = 'never')
  and cism/noevolve/README
* cime_config/config_archive.xml
No changes to testlist_cism.xml.

Testing: 11 tests on derecho (intel and gnu), compared against baselines generated from the previous
commit (time in days since 0001-01-01):
  SMS_D_Ly1.f09_g17_gris4.T1850Gg (intel and gnu), ERS_Ly7.f09_g17_gris4.T1850Gg,
  ERS_D_Ly3.f09_g17_gris4.T1850Gg.cism-noevolve, ERS_Ly3_C2_D.f09_g17_gris20.T1850Gg,
  ERP_Ly4.f09_g17_gris4.T1850Gg.cism-norenormal, ERI_Ly44.f09_g17_gris20.T1850Gg.cism-isostasy_period4,
  ERS_Ly5.f09_g17_ais8.T1850Ga, ERI_Ly9.f09_g17_ais8gris4.T1850Gag.cism-noevolve_ais (gnu),
  SMS_D_Ld5.f10_f10_ais8gris4_mg37.I1850Clm50SpGag.cism-test_coupling (gnu),
  ERS_D_Ld9.f10_f10_mg37.I1850Clm50SpG.cism-override_glc_frac (gnu)
* All tests build and run. All restart comparisons pass (6 ERS/ERP base_rest; ERI rest_branch and
  branch_hybrid). Each restart test with evolving ice writes at least one regular h0i file after
  initialization.
* NLCOMP fails as expected (new [CF output] section in cism.<icesheet>.config).
* BASELINE fails as expected, because the history streams are renamed (gris.h -> gris.h0i).
  Comparing each new h0i file directly with the corresponding baseline h or initial_hist file
  (20 files), all variables are identical, including time.
* SMS_D_Ld5 (two ice sheets, history_option = 'coupler') writes h0i files for both ais and gris
  at the coupler history time (before the alarm fix, only ais did).
* ERS_D_Ld9 (override_glc_frac) and ERS_D_Ly3 (noevolve) write no CISM history files.
* history files open with xarray.open_dataset, with time decoded as noleap dates.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… output] machinery

This commit adds the time-average history stream (h0a), following the design discussed on issue #75.
History fields whose names end in '_tavg' are written to annual h0a files; the other fields are
written to h0i files (previous commit). It also updates source_cism to 092f9ac0 on the CISM branch
lipscomb/cesm_timevars, which adds two changes needed here:
* 22deed49: In time-average files, internal_time and time are the midpoints of the averaging interval
  (time_bounds still give the start and end). This resolves issue #76.
* 092f9ac0: The maximum length of a value in CISM's config file is raised from 400 to 4096 characters.
  With a few '_tavg' fields added to the default history variables, the esm_history_vars line in
  cism.<icesheet>.config exceeded 400 characters, and the model aborted at initialization.

How it works:

* buildnml writes a second [CF output] section for the time-average fields:
      [CF output]
      name: h0a
      variables: <_tavg fields>
      xtype: double
      external_control: .true.
      one_file_per_write: .true.
      write_init: .false.
  (CISM requires write_init = .false. for time-average output.) If there are no '_tavg' fields,
  there is no h0a section and no h0a files. The default esm_history_vars has no '_tavg' fields,
  so default output is unchanged. The per-stream limit on the length of a variable list in
  buildnml is raised from 400 to 1024 characters (CISM's glimmer_nc_vars_len).

* Each ice sheet can now have two history tapes (glc_history.F90): h0i, which follows
  history_option and history_frequency as before, and h0a, which is always written annually
  (a standard tape with its own time flag, do_hist_<icesheet>_h0a). glc_history_init finds the
  h0a object by name and checks that it holds time-average fields (do_averages = .true.).

* Time-average streams write no initial file (history_tape_base.F90).

* h0a files are named with the year of the average: <case>.cism<inst>.<icesheet>.h0a.YYYY.nc,
  e.g., h0a.1861.nc, written at 1862-01-01 00:00, holds the average over 1861.
  time_period_freq is 'year_1'.

* The start of the first averaging interval is set at initialization in CESM time units
  (glc_io_init_tavg_interval): the start date for startup, hybrid and branch runs, and Jan 1 of the
  current year for continue runs. CISM sets the start in its own time units (internal_time).

* Runs that do not start at the beginning of a year (issue #75, item 5): the first h0a file, which
  would cover only part of a year, is skipped with a log message, and a new averaging interval starts
  at the first year boundary (glc_io_reset_tavg_interval). Note: this could not be tested, because a
  run with an evolving CISM that starts mid-year currently aborts at the first call to GLAD
  ("Unexpected calling of GLAD at time 0"), independent of history output (issue #75, item 14).

* Restart files (issue #75, item 6, first step): partial time-average sums are not yet saved in
  restart files. glc_io_write_restart now aborts with a clear message if a restart file is written
  in the middle of an averaging interval with nonzero sums. In default configurations this does not
  happen: CISM takes its timesteps at year boundaries, where the h0a file is written and the sums are
  reset before the restart file is written. Saving the partial sums will be a follow-up.

* New testmods directory cism/tavg_history, which adds seven '_tavg' fields to the default history
  variables, to exercise the h0a stream. It is not in testlist_cism.xml; tests can use it by name
  (e.g., ERS_Ly7.f09_g17_gris4.T1850Gg.derecho_intel.cism-tavg_history).

Notes for reviewers -- files that may conflict with other open work (e.g., the namelist PR):
* cime_config/buildnml (_add_history_sections_to_cism_config, _write_history_section)
* cime_config/testdefs/testmods_dirs/cism/tavg_history (new)
No changes to testlist_cism.xml or namelist_definition_cism.xml in this commit.

Testing: 14 tests on derecho (intel and gnu), compared against baselines generated from the previous
commit:
* The 11 tests without time-average history fields (SMS, ERS, ERP, ERI, two instances, both ice sheets,
  noevolve, test_coupling, override_glc_frac) pass all comparisons, including BASELINE and NLCOMP:
  default output is unchanged.
* SMS_D_Ly3.f09_g17_gris4.T1850Gg.derecho_intel.cism-tavg_history,
  ERS_Ly7.f09_g17_gris4.T1850Gg.derecho_intel.cism-tavg_history, and
  ERI_Ly9.f09_g17_ais8gris4.T1850Gag.derecho_gnu.cism-tavg_history (two ice sheets) build and run, and
  the restart comparisons pass. (BASELINE and NLCOMP report missing baselines for these new tests.)
  All 16 h0a files written by these tests were checked: the year in the file name is the year of the
  average; time_bounds spans one year starting on Jan 1 (in days since 0001-01-01); time and
  internal_time are the midpoints of their bounds; only '_tavg' fields are present; time_period_freq
  is 'year_1'; and xarray opens the files with time decoded as noleap dates.
* Standalone CISM (8-km Antarctic test, startup and restart) is BFB with the previous CISM commit for
  092f9ac0, and differs only in the time values of time-average files for 22deed49.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…rac testmods

The previous h0i commit set history_option = 'never' in the cism/override_glc_frac testmods
(used by ERS_D_Ld9.f10_f10_mg37.I1850Clm50SpG.derecho_gnu), with a comment saying that the
initial h0i file would otherwise break the restart comparison. That reason was based on reasoning,
not an observed failure, and was wrong. After each run, CIME compares the most recent file in each
history stream, and it copies (does not move) the base run's files. This 9-day test writes no
regular h0i files, so after the restart run the most recent h0i file is still the initial run's
h0i.0001-01-01, and the comparison passes trivially. (Tested: with 'never' removed,
ERS_D_Ld9.f10_f10_mg37.I1850Clm50SpG.derecho_gnu.cism-override_glc_frac passes, including
COMPARE_base_rest, which compared h0i.0001-01-01.nc.base with h0i.0001-01-01.nc.rest.)

As requested on issue #75, history_option = 'never' is kept, since passing this way is accidental
and fragile. This commit changes only the comment, to give the correct reason.

The noevolve testmods needs history_option = 'never' for a different reason: there, a non-evolving
CISM treats the restart run as a startup run and writes its own initial h0i file, so the two runs'
most recent h0i files have different names (observed failure).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit allows restart files to be written in the middle of an averaging interval for the
time-average history stream (h0a), and continues the averages exactly in continue runs
(issue #75, item 6). It updates source_cism to a3bcfe32 on the CISM branch lipscomb/cesm_timevars,
which adds two commits:
* 1020387c: CISM saves the averaging state of each time-average output stream in restart files
  (running sums as '<field>_tavg_sum' variables; total time, start of the averaging interval in
  internal and external time, and the timestep of the most recent accumulation), and restores it
  on a standard restart (restart = 1). Also, restart files are written after all other output at
  the same time.
* a3bcfe32: A flag, tavg_restored, records whether the averaging state was restored.

Wrapper changes:
* glc_io_init_tavg_interval (called from glc_history_init) now sets up the first averaging
  interval as follows:
  - Continue run: CISM has restored the averaging state from the restart file, so the average
    continues exactly; nothing more is done. If the restart file has no averaging state (it was
    written before this change), the interval starts on Jan 1 of the current year, as before.
  - Startup, hybrid or branch run: a new averaging interval starts at the start of the run, with
    zero sums (glc_io_reset_tavg_interval). Evolving hybrid and branch runs start CISM from the
    refcase restart file with restart = 1, so CISM may have restored the refcase's averaging state;
    it is discarded. As before, if the run does not start on Jan 1, the first (partial-year) h0a
    file is skipped.
* glc_io_write_restart no longer aborts when a restart file is written in the middle of an
  averaging interval with nonzero sums. History files are written (in glc_run) before the restart
  file at the same time, so the saved state is the state after any h0a file written at that time.
* glc_history_init: the instance argument is now intent(inout), since the time-average sums may
  be reset.

Note: With the default settings, CESM restart files are written only at mass balance time step
boundaries (glad_okay_to_restart), and CISM's timesteps for a year are taken together at the end
of the year, just before the h0a file is written and the sums are reset. So in practice, a restart
in the middle of a year has zero sums, but the start of the averaging interval must still be
carried over. Restarts with nonzero partial sums were tested with standalone CISM.

Notes for reviewers -- files that may conflict with other open work (e.g., the namelist PR):
none of buildnml, namelist_definition_cism.xml, testmods or testlist_cism.xml is changed.

Testing on derecho (test list /glade/work/lipscomb/cism_wrapper_tests/subset_step3c.txt):
* The 14 tests of the Step 3b subset (SMS, ERS, ERP, ERI; intel and gnu; one and two ice sheets;
  multi-instance; noevolve; I compsets with test_coupling and override_glc_frac; three tests with
  cism-tavg_history) pass all phases, including BASELINE (compared with baselines generated from
  the previous wrapper commit) and NLCOMP, and all restart comparisons. So history output,
  including h0a output, is unchanged when restarts fall at year boundaries.
* New test ERS_Ld900.f10_f10_mg37.I1850Clm50SpG.derecho_intel.cism-tavg_history, which restarts
  at day 451 (late March of year 2), in the middle of the h0a averaging interval for year 2, after
  CISM has taken its year-1 timesteps: COMPARE_base_rest passes, and h0a.0002.nc (the average
  across the restart), the h0i, coupler and MOSART history files are identical between the base
  and restart runs. This test is added to the wrapper test subset (not to testlist_cism.xml).
* Known issue, not related to this commit: ERS_Ld540.f10_f10_mg37.I1850Clm50SpG.derecho_intel,
  which restarts at day 271 of year 1, before CISM's first timestep after a startup, fails
  COMPARE_base_rest, with or without cism-tavg_history (identical differences). The first CISM
  substep after the restart has slightly different SMB and calving fluxes (0.0162 Gt/yr), so the
  ice runoff sent to the coupler and the h0a averages differ slightly; the ice sheet state is
  identical. The averaging state itself is restored correctly. The same restart (from a t = 0
  restart file) is bit-for-bit in standalone CISM (4-km Greenland, marine_margin = 1,
  calving_init = 1), so this is an issue in the CESM/GLAD path; it will be investigated separately.
* Standalone CISM: see the CISM commits above.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The history variable list, esm_history_vars, is no longer needed in the [esm_output] section of
cism.<icesheet>.config: buildnml splits it into the h0i and h0a [CF output] sections, which CISM
uses to write history files. This commit moves esm_history_vars to a new namelist group,
cism_history, which is not written to any file; buildnml still reads it (from user_nl_cism or
the defaults) to write the [CF output] sections. The [esm_output] section now holds only
history_option and history_frequency, which GLAD reads for the wrapper.

It also updates source_cism to 76d7dc15, which removes the unused esm_history_vars
reader from GLAD. (Either change works without the other: CISM ignores unused keys in a config
section.)

Changes:
* namelist_definition_cism.xml: esm_history_vars is in group cism_history (with a comment that
  this group is not written to any file), and its description says which fields go to h0i and
  h0a files. No change to its values or to the user interface (user_nl_cism).
* buildnml: new list _CISM_CONFIG_HELPER_GROUPS = ["cism_history"]; its defaults are skipped when
  writing cism_in, as for the config groups (the default depends on whether the ice sheet is
  evolving).

Notes for reviewers -- files that may conflict with other open work (e.g., the namelist PR):
* cime_config/namelist_definition_cism.xml (esm_history_vars entry)
* cime_config/buildnml (group lists near the top; init_defaults call in _create_cism_in)

Testing:
* preview_namelists for a T1850Gg case (f09_g17_gris4) with the default settings, with the
  cism/tavg_history testmods, with no evolving ice sheet, and with history_option = 'never':
  [esm_output] has only history_frequency and history_option; esm_history_vars does not appear in
  cism.gris.config or cism_in; and the h0i and h0a [CF output] sections are as before (h0i only
  by default; h0i and h0a with tavg_history; the short variable list for a non-evolving ice sheet;
  no history sections with 'never').
* Test subset /glade/work/lipscomb/cism_wrapper_tests/subset_step3c.txt (15 tests), compared with
  baselines generated from the Step 3b wrapper commit: all tests run, BASELINE passes for the 14
  tests that have baselines (history output is unchanged), and all restart comparisons pass
  (COMPARE_base_rest, COMPARE_rest_branch, COMPARE_branch_hybrid). NLCOMP fails for all tests, as
  expected: the only differences are the removed esm_history_vars lines in the CISM config files
  (cism.gris.config, cism.ais.config, and cism_000N.gris.config for multiple instances).
  (ERS_Ld900...cism-tavg_history is new since those baselines, so it has no baseline.)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
CISM's log messages (from write_log, including the per-timestep diagnostics) and CISM output
written to iulog were going to the cesm log, with each write_log message written twice, instead of
to the glc log file. Two changes fix this:

* The cap sets stdout (glc_constants) to the unit of the glc log file (set_component_logging).
  glc_InitMod then did 'stdout = iulog', where iulog is CISM's log unit with its default value of 6
  (standard output). This reset stdout to 6, so CISM's log unit (glimmer_unit, set from stdout by
  set_glimmer_unit) and all later wrapper output written to stdout went to standard output (the
  cesm log). The assignment is now reversed, 'iulog = stdout', so CISM's iulog and glimmer_unit
  are the glc log file. (The old assignment seems to date from when stdout was renamed iulog in
  CISM.)
* The message level for write_log, which controls which messages are also written to standard
  output, was 6 (all messages): first from the CESM default log_level = 6 in the config file
  (read in glide_setup), then from a hard-coded glimmer_set_msg_level(6) in glc_InitMod after
  initialization. With glimmer_unit = 6, this wrote each message twice to the cesm log; with
  glimmer_unit = the glc log, it would copy every message to the cesm log. The CESM default
  log_level is now 1, as in standalone CISM (only fatal errors are also written to standard
  output), and the hard-coded call in glc_InitMod is removed, so a log_level set by the user in
  user_nl_cism applies throughout the run. The description of log_level now says what it
  controls.

Notes for reviewers -- files that may conflict with other open work (e.g., the namelist PR):
* cime_config/namelist_definition_cism.xml (log_level entry: default and description)

Standalone CISM is not affected.

Testing: SMS_D_Ly1.f09_g17_gris4.T1850Gg.derecho_intel and
SMS_D_Ld5.f10_f10_ais8gris4_mg37.I1850Clm50SpGag.derecho_gnu.cism-test_coupling (two ice sheets)
pass. CISM's log output, including the initialization messages and warnings and the diagnostics
for each timestep (written once each), is now in the glc log, and the cesm log has no CISM log
messages. The config files have log_level = 1.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…RIS tests

The MULTINOAIS and MULTINOGRIS tests (MULTIVSSINGLE) compare a run with two ice sheets with a run
in which one ice sheet is removed. To avoid a history file being present in one run but not the
other, the first run turned off history output for the ice sheet that is removed in the second
run, by setting history_frequency = 10000 years. With the old history code, that ice sheet still
wrote an initial history file, but CIME skipped it in the comparison because its name contained
'initial'. The initial history file is now an h0i file (e.g., cism.ais.h0i.0001-01-01.nc), so it
had no partner in the single-ice-sheet run, and COMPARE_base_single failed, although the remaining
ice sheet's history files were identical.

The test now sets history_option = 'never' for that ice sheet (an option added earlier on this
branch), which turns off all its history files, including the initial one.

Testing: MULTINOAIS_Ly2.f10_f10_ais8gris4_mg37.I1850Clm50SpRsGag.derecho_intel.cism-change_params
and MULTINOGRIS_Ly2.f10_f10_ais8gris4_mg37.I1850Clm50SpRsGag.derecho_intel.cism-change_params
pass COMPARE_base_single: the only CISM files compared are the remaining ice sheet's h0i files,
which are identical. (Both failed in the full aux_glc run before this change.)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@billsacks

Copy link
Copy Markdown
Member

Thanks a lot for working on this @whlipscomb ! If possible, I'd like to leave this review to @Katetc . Based on all of our discussions, I feel good about this as long as @Katetc is.

@Katetc

Katetc commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Note that I ran a ERI_Ly44.f09_g17_gris20.T1850Gg.derecho_intel.cism-tavg_history test on the cismwrap_3_00_001 tag and this branch. In the 3_0_01 tag, there is a limit on variables allowed in the history namelist field, so I had to shorten the number of variables in the test. These variables are all written to the same history file, so I compared that history file to each the h0a and the h0i files. We are looking for a diff where the expected numbers of fields don't exist on the given file, and all of the fields compared have zero differences.

cpl.hi.0042 vs cpl.hi.0042

SUMMARY of cprnc:
A total number of 67 fields were compared
of which 0 had non-zero differences
and 0 had differences in fill patterns
and 0 had different dimension sizes
and 0 had different data types
A total number of 0 fields could not be analyzed
A total number of 0 time-varying fields on file 1 were not found on file 2.
A total number of 0 time-constant fields on file 1 were not found on file 2.
A total number of 0 time-varying fields on file 2 were not found on file 1.
A total number of 0 time-constant fields on file 2 were not found on file 1.
diff_test: the two files seem to be IDENTICAL

cism.gris.h.0042 vs cism.gris.h0a.0041
SUMMARY of cprnc:
A total number of 14 fields were compared
of which 0 had non-zero differences
and 0 had differences in fill patterns
and 0 had different dimension sizes
and 0 had different data types
A total number of 44 fields could not be analyzed
A total number of 24 time-varying fields on file 1 were not found on file 2.
A total number of 0 time-constant fields on file 1 were not found on file 2.
A total number of 6 time-varying fields on file 2 were not found on file 1.
A total number of 0 time-constant fields on file 2 were not found on file 1.
diff_test: the two files seem to be DIFFERENT

cism.gris.h.0042 vs cism.gris.h0a.0041
SUMMARY of cprnc:
A total number of 14 fields were compared
of which 0 had non-zero differences
and 0 had differences in fill patterns
and 0 had different dimension sizes
and 0 had different data types
A total number of 44 fields could not be analyzed
A total number of 3 time-varying fields on file 1 were not found on file 2.
A total number of 0 time-constant fields on file 1 were not found on file 2.
A total number of 3 time-varying fields on file 2 were not found on file 1.
A total number of 0 time-constant fields on file 2 were not found on file 1.
diff_test: the two files seem to be DIFFERENT

This is what we're looking for! ✅

@Katetc
Katetc marked this pull request as ready for review October 9, 2026 19:25
@Katetc
Katetc merged commit d6497d2 into master Oct 9, 2026
@whlipscomb

Copy link
Copy Markdown
Contributor Author

Thanks, @Katetc!

jgfouca pushed a commit to ESMCI/cime that referenced this pull request Oct 28, 2026
This special handling was added for CISM. As of cismwrap_3_00_002
(ESCOMP/CISM-wrapper#150), this is no longer
needed.

Resolves #5072
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants