Skip to content

Add netcdf output of the hemispheric diagnostics (area, extent, etc) - #1145

Draft
anton-seaice wants to merge 21 commits into
CICE-Consortium:mainfrom
anton-seaice:diag_netcdf
Draft

anton-seaice wants to merge 21 commits into
CICE-Consortium:mainfrom
anton-seaice:diag_netcdf

Conversation

@anton-seaice

@anton-seaice anton-seaice commented Oct 20, 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:
    Adds calendar units for diagfreq and an option to write the hemispheric diagnostics (CMIP sea-ice area, extent, volume and snow mass, the other log diagnostics and the conservation diagnostics) to a netcdf file, as time averages or instantaneous values, with its own frequency and restarts. Closes Global Scalars in History Output #1074.
  • Developer(s):
    Anton Steketee (ACCESS-NRI)
  • Suggest PR reviewers from list in the column to the right.
    @apcraig
  • Please copy the PR test results link or provide a summary of testing completed below.
    On Gadi (NCI) with ifx (oneapi):
    • New tests diagnc, diagncr (restart) and diagncinst1 in base_suite pass, plus existing gx3 debug, alt03, isotope, tx1 and gbox128 (one hemisphere) cases with netcdf diagnostics on.
    • Log diagnostics are bit-for-bit with the base commit, with and without print_global, and model answers and restarts are unchanged.
    • Instantaneous netcdf values match the log every timestep (to float32 precision). Daily means equal the mean of hourly instantaneous values, and daily maxima the maximum.
    • A run restarted in the middle of an averaging interval gives bit-for-bit the same file as a continuous run.
    • Appending to an existing file at a restart, and overwriting records when a segment is rerun.
    • netcdf and pio2 builds, with cdf1, cdf5 and hdf5 (with deflate) formats. gfortran build.
    • Output passes the IOOS compliance checker for CF-1.8.
    • ACCESS-OM3 at 25 km (MOM6-CICE6, 2704 cores, earlier version of this PR): answers unchanged, the cost is about 0.2% of the CICE time loop, and the daily mean siarean/sivols match the sums of the daily mean history fields to ~1e-16.
    • base_suite results: all pass, and bit-for-bit with main (da68b70) for all tests with a baseline (the 3 new tests have none).
  • 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.

#1074 asks for hemispheric totals (area, extent, volume, ...) in netcdf output. These are useful for quick checks of runs, especially at high resolution where computing them from many large history files is slow. Following the discussion in #1074, they are built on the diagnostics already written to the log, rather than added to the history streams. CMIP7 requests the area, extent, volume and snow mass as daily means, so time averages are supported as well as instantaneous values.

Parameter Default Description
diagfreq_unit '1' Units of diagfreq (log diagnostics): '1' (timesteps, unchanged behaviour), 'h', 'd', 'm', 'y'. Calendar units are aligned with the calendar, eg 'd' is the end of each day.
diag_netcdf_freq 'x' Units of the netcdf diagnostics frequency: 'x' (off), '1', 'h', 'd', 'm', 'y'.
diag_netcdf_freq_n 1 Netcdf diagnostics every diag_netcdf_freq_n diag_netcdf_freq units.
diag_netcdf_avg .true. Time averages over each interval (maxima are the maximum over the interval), like hist_avg, otherwise instantaneous values.

diagfreq = 0 now turns the log diagnostics off (previously a mod by zero).

  • The hemispheric diagnostics are now computed by shared code in ice_diagnostics (hdiag_cell_values, hdiag_reduce, hdiag_derived, hdiag_global), used by both the log and the netcdf output, so the values are consistent. The log output is unchanged.
  • New module ice_diagnostics_netcdf, called from the drivers with diag_netcdf_step after the other diagnostics:
    • Variables: siarean/s, siextentn/s, sivoln/s, sisnmassn/s (CMIP names and units, snow mass is rhos*vsno as for the history field sisnmass), and kinetic_energy, ice_speed_rms, albedo, ice_volume_max, ice_speed_max, ice_strength_max with _nh/_sh suffixes.
    • The conservation diagnostics from print_global (mass, energy and salt stocks, water, salt and heat fluxes as rates, isotopes and aerosols) are always in the file; print_global only affects the log. The changes and conservation errors are over a single timestep, so are only written for instantaneous output.
    • File <history_dir><history_file>_diag_avg.nc (or _diag_inst.nc), written serially by the master task in netcdf and pio builds. If it exists at the start of a run it is appended to, with records at or after the current time overwritten for reruns. Format, compression and precision follow history_format, history_deflate and history_precision.
    • With write_histrest, the partial averages are written to their own restart file with the history restarts (<restart_dir><history_file>_diag_r.YYYY-MM-DD-SSSSS.nc), so averaging continues across restarts. Otherwise the averaging restarts at the start of each run (shown by time_bounds).

🤖 Generated with Claude Code

@anton-seaice

Copy link
Copy Markdown
Contributor Author

@apcraig @eclare108213 @dabail10

Just putting this up for discussion

  • this writes 1d variable (area, extent, volume etc) to a new netcdf diagnostic output file. the file is reopened and extended if it's already present in the model configuration folder. However, there's no support for restarting averaging (but could be if needed)
  • output is controlled through the existing diagfreq and the new diagfreq_unit and diag_netcdf in the namelist

@apcraig

apcraig commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Please update your branch to the Consortium trunk to get the updated Github Actions workflow script. You can merge or rebase, both should work just as well.

# to merge upstream main,
  git remote add upstream https://github.com/cice-consortium/cice
  git pull upstream main

# or if you prefer to rebase instead of merge,
  git remote add upstream https://github.com/cice-consortium/cice
  git pull upstream main --rebase

@eclare108213 eclare108213 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.

This looks like a very useful upgrade. My only comment at this point is that whatever is done (or not) for history restarts should be the same for netcdf diagnostics.

@apcraig

apcraig commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

This looks very nice. A few thoughts

  • What about diagnostic restarts for average diagnostics. For consistency, I think it would be good to have this feature, but we could see whether others feel this is useful.
  • There is only one namelist to define the diagnostic output. Does this apply to both the log output and the netcdf file? Is the log output still always instantaneous? Do we need to have a separate control for log output frequency and diag history file frequency?
  • Time averaging will naturally be quite expensive. I assume you're accumulating the spatial averages which means doing a global sum each timestep. Could also consider accumulating the fields and averaging when the file is written if that might save a bunch of time.
  • Do we want to aggregate the diagnostic fields and do a single global sum call for all fields. Maybe this could be implemented in both the log and history diagnostic output?
  • I will look at the code closer, but are there other ways to leverage code reuse between the log and history diagnostic implementation.

@dabail10

Copy link
Copy Markdown
Contributor

My comments are similar to @apcraig.

  • Global sums online at every timestep and averaging are going to be expensive. I understand that SIMIP/CMIP asks for this, but why can't it be done offline? There are daily average siconc, sithick, sisnthick, etc. I understand this could be switched off for some groups.
  • I might argue that this is also related to the history files. Just a 1D variable instead of 3D / 4D. That would include the accumulation part if necessary.
  • I like the capability of keeping multiple time values in the same file. Would this be difficult to extend to the history files?

@anton-seaice

Copy link
Copy Markdown
Contributor Author

Thanks for the comments all !

  • What about diagnostic restarts for average diagnostics. For consistency, I think it would be good to have this feature, but we could see whether others feel this is useful.

Yep - can do this. Should it go in a seperate restart file or the history restart file ?

  • There is only one namelist to define the diagnostic output. Does this apply to both the log output and the netcdf file?

Do you mean print_global ? if so, print_global only adds extra diagnostics to the log not netcdf

The log includes diagnostics which are always on (area, extent, volume) and extra's turned on through print_global. The netcdf implementation as written only captures the always on diagnostics.

Is the log output still always instantaneous?

For reasons I don't 100% recall it seemed simpler not to change the log output. So yes, log output is instantaneous

it's not that clear to me that time averaging some of the variables in the log would be useful if averaged. e.g. water flux error is a fraction of total ice + snow + pond mass . it would need a minor refactor to make sense over the time interval

Do we need to have a separate control for log output frequency and diag history file frequency?

the diagfreq settings ? if so, these would apply to both the log and netcdf (e.g. you couldn't have monthly logged output and daily netcdf output)

  • Time averaging will naturally be quite expensive. I assume you're accumulating the spatial averages which means doing a global sum each timestep. Could also consider accumulating the fields and averaging when the file is written if that might save a bunch of time.

Actually it's accumulating the spatial fields and then summing at the diagnostic frequency. Global sum should be being done at the diagnostic frequency, not every thermo/coupling timestep. Cost is nominal.

  • Do we want to aggregate the diagnostic fields and do a single global sum call for all fields. Maybe this could be implemented in both the log and history diagnostic output?

On our hardware, there's no performance improvement in doing this is small (at least for the netcdf diagnostics).

  • I will look at the code closer, but are there other ways to leverage code reuse between the log and history diagnostic implementation.

Possibly, but it quickly leads to not progressing this change - and instead adding 1d variables as history fields (which in my view needs more history streams)

The accumulation code is very small :

https://github.com/CICE-Consortium/CICE/pull/1145/changes#diff-03993354b872b06362360cb8ac7eae87cb2c7d6b7c52ace76db84c106a2660fbR347

The other overlap is in the netcdf file definition ? Which could overlap a bit with history files

p.s. did you mean code reuse between the log and history diagnostic implementation ? or code reuse between the log and netcdf diagnostic implementation ?

My comments are similar to @apcraig.

* Global sums online at every timestep and averaging are going to be expensive. I understand that SIMIP/CMIP asks for this, but why can't it be done offline? There are daily average siconc, sithick, sisnthick, etc. I understand this could be switched off for some groups.

The global sum is only done at the diagnostic frequency. The cost is small (and off by default).

* I might argue that this is also related to the history files. Just a 1D variable instead of 3D / 4D. That would include the accumulation part if necessary.

yep, this is an option. In my view it needs more history streams which bring different complications. My medium term goal here is configuring one 3d/4d variable per history file, whilst keeping the 2d (hemsiphere & time) variables in a single file. So ice_diag fills the second goal (the 2d variables in a single file)

* I like the capability of keeping multiple time values in the same file. Would this be difficult to extend to the history files?

yep, should be fine. ill work on this soon. Are you thinking of one file per run? or the same file over consecutive model runs ?

@apcraig

apcraig commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Thanks for the comments all !

  • What about diagnostic restarts for average diagnostics. For consistency, I think it would be good to have this feature, but we could see whether others feel this is useful.

Yep - can do this. Should it go in a seperate restart file or the history restart file ?

The current implementation has each history file with it's own restart history file. I would keep that standard.

  • There is only one namelist to define the diagnostic output. Does this apply to both the log output and the netcdf file?

Do you mean print_global ? if so, print_global only adds extra diagnostics to the log not netcdf

The log includes diagnostics which are always on (area, extent, volume) and extra's turned on through print_global. The netcdf implementation as written only captures the always on diagnostics.

Do we need to have a separate control for log output frequency and diag history file frequency?

the diagfreq settings ? if so, these would apply to both the log and netcdf (e.g. you couldn't have monthly logged output and daily netcdf output)

I'm asking about "diagfreq". This seems to control the frequency of output to the log file AND to the netcdf file. These seem like distinct features that probably require distinct frequency control mechanisms. So yes, you might want different frequencies for log and netcdf output.

  • Time averaging will naturally be quite expensive. I assume you're accumulating the spatial averages which means doing a global sum each timestep. Could also consider accumulating the fields and averaging when the file is written if that might save a bunch of time.

Actually it's accumulating the spatial fields and then summing at the diagnostic frequency. Global sum should be being done at the diagnostic frequency, not every thermo/coupling timestep. Cost is nominal.

Good, that should work well.

  • Do we want to aggregate the diagnostic fields and do a single global sum call for all fields. Maybe this could be implemented in both the log and history diagnostic output?

On our hardware, there's no performance improvement in doing this is small (at least for the netcdf diagnostics).

Great.

  • I will look at the code closer, but are there other ways to leverage code reuse between the log and history diagnostic implementation.

Possibly, but it quickly leads to not progressing this change - and instead adding 1d variables as history fields (which in my view needs more history streams)

The accumulation code is very small :

https://github.com/CICE-Consortium/CICE/pull/1145/changes#diff-03993354b872b06362360cb8ac7eae87cb2c7d6b7c52ace76db84c106a2660fbR347

The other overlap is in the netcdf file definition ? Which could overlap a bit with history files

p.s. did you mean code reuse between the log and history diagnostic implementation ? or code reuse between the log and netcdf diagnostic implementation ?

I was concerned that the log diagnostics and 1D history diagnostics were computed using duplicate code. If the code that computes the global sums could be shared between the log and 1D history output to ensure "ice area", "ice volume", and other diagnostic would always be guaranteed to be exactly the same, I think that would be very useful.

  • I might argue that this is also related to the history files. Just a 1D variable instead of 3D / 4D. That would include the accumulation part if necessary.

yep, this is an option. In my view it needs more history streams which bring different complications. My medium term goal here is configuring one 3d/4d variable per history file, whilst keeping the 2d (hemsiphere & time) variables in a single file. So ice_diag fills the second goal (the 2d variables in a single file)

I think the history diagnostics are different enough that they deserve their own history file. The history streams are largely model output fields possibly aggregated in time. The history diagnostics are model fields aggregated possibly in time and always in space (by hemisphere). These new files sort of break our standard x,y,z,n,t history mechanism and require another step (aggregating in space). I like the simplicity of just turning the feature on or off and not having to manage which fields go into the history diagnostics file. Having said that, maybe the 1d history diagnostic netcdf output should be part of the history mechanism in the sense that we should be able to add 1 more stream for it, all the temporal aggregation, time axis stuff, and history restart features are there. And we would just have to add the global sums and ability to write 1D by hemisphere output.

* I like the capability of keeping multiple time values in the same file. Would this be difficult to extend to the history files?

yep, should be fine. ill work on this soon. Are you thinking of one file per run? or the same file over consecutive model runs ?

I think that's a separate feature, although it clearly overlaps with the history diagnostics. If the history diagnostics are going to support multiple time slices per file, how is that going to be managed?

@anton-seaice anton-seaice changed the title Add diag_netcdf for 1d hemispheric diagnostics (area, etc) Add netcdf output of the hemispheric diagnostics (area, extent, etc) Oct 29, 2026
anton-seaice and others added 16 commits October 30, 2026 09:02
- diagfreq_unit ('1','h','d','m','y') sets the units of diagfreq, default '1'
  (timesteps) is unchanged. Calendar units are aligned with the calendar,
  e.g. 'd' writes at the end of each day and 'm' at the end of each month.
- write_diag is computed once in calendar and used by all drivers, replacing
  mod(istep,diagfreq) in each driver.
- diag_netcdf writes the hemispheric diagnostics from the log (and the
  print_global set) to a netcdf file, one file per run named
  <history_file>_diag.<run start date>.nc, as instantaneous values with
  _nh/_sh variables.
- Add set_nml.diagnc and a base_suite test, update docs.

Addresses CICE-Consortium#1074

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… compliance

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cs file

cdf2/cdf5 (and pnetcdf2/5) use 64-bit offset/data, hdf5 uses netcdf4 with
history_deflate compression, otherwise classic. The file is always written
serially on the master task.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Move the netcdf diagnostics to ice_diagnostics_netcdf.F90, called from the
  drivers with diag_netcdf_step, so runtime_diags is unchanged apart from the
  kinetic energy and ice speed helpers it now shares.
- diag_netcdf_avg (default true) writes time averages over each diagfreq
  interval, accumulated every timestep from per grid cell values, with one
  global reduction per record. Maxima are maxima over the interval.
- Each diagnostic is defined once (init_ncdiag) and computed per grid cell
  (ncdiag_cell_values), and used for both averages and instantaneous values.
- CMIP names and units for sea-ice area, extent, volume and snow mass.
- One file per mode (<history_file>_diag_mean.nc or _diag_inst.nc), appended
  to at the start of a run, with records from a rerun overwritten.
- Precision follows history_precision, time_bounds and cell_methods for means,
  missing values for a hemisphere without grid cells.
- print_global diagnostics are only written to the log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Rename the hemisphere loop index nh to hemi.
- Add units_metadata = "leap_seconds: none" to time for proleptic_gregorian.
- Use half a timestep as the tolerance when finding records to overwrite.
- Clarify comments and document that averages restart at the start of a run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the diag_netcdf and diag_netcdf_avg logicals with one string, so there
are no meaningless combinations, matching hist_avg and the planned hist_mode.
Files are <history_file>_diag_avg.nc or _diag_inst.nc.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- diag_netcdf_freq and diag_netcdf_freq_n set the netcdf diagnostics frequency
  ('x' off), separate from the log diagnostics (diagfreq, diagfreq_unit), with
  a shared calendar helper.
- diag_netcdf_avg (like hist_avg) replaces diag_netcdf.
- With write_histrest, the accumulation for time averages is written to
  <history_file>_diag_r.<date>.nc in restart_dir with the history restarts and
  read at the start of the next run, so averages are continuous across restarts.
- Add set_nml.diagncr and a restart test with 3 day means.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the hemispheric diagnostic definitions, per grid cell values, reductions and derived values to ice_diagnostics (hdiag_*), used by runtime_diags and ice_diagnostics_netcdf, so the log and netcdf values are computed by the same code. The log output is unchanged. Snow is summed as volume, with rhos as the netcdf scale for sisnmass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Add the print_global per grid cell quantities (energy, salt, water, salt
  and heat fluxes, brine, ponds, isotopes, aerosols) to the shared
  hemispheric diagnostics when they are used, and derive the conservation
  budgets in hdiag_global, used by the log and netcdf.  The log is unchanged.
- With print_global, the netcdf file has masses, energy, salt and tracer
  totals, and fluxes as rates.  The changes and conservation errors are over
  a single timestep, so are only written for instantaneous values.
- Add a base_suite test with netcdf diagnostics every timestep.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nt_global only affects the log

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Previously no filename was set, so the previous stream's path was reused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anton-seaice and others added 3 commits November 4, 2026 11:57
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ctions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The print_points diagnostics in ice_diagnostics and ice_diagnostics_bgc
were broadcast from the owning task to all tasks, each followed by an
MPI_BARRIER, although only the master task writes them. Add a generic
send_to_master (dbl scalar, 1d and 2d) to ice_communicate and use it
instead, so only the owning and master tasks communicate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anton-seaice

anton-seaice commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

This change is ready to go, it ended up being a bit bigger than hoped.

I've harmonised the code between the log file and netcdf versions.
Writing lots of point logs should be faster now with the new method to send data to master task.
Netcdf diags now also writes a restart file (iceh_diag_r.2005-01-06-00000.nc) when writing average netcdf diags and write_histrest = .true.

base_suite results: all pass, and bit-for-bit with main (da68b70) for all tests with a baseline (the 3 new tests have none).

@anton-seaice anton-seaice self-assigned this Nov 11, 2026
@anton-seaice
anton-seaice marked this pull request as ready for review November 11, 2026 03:59

@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.

This looks great overall. A lot of good cleanup of code and looks like a robust implementation and excellent test coverage and documentation of the testing. I've added several comments inline about possible additional improvements and a couple questions.

hd_aice = 1 , & ! sea-ice area
hd_extent = 2 , & ! sea-ice extent
hd_vice = 3 , & ! sea-ice volume
hd_vsno = 4 , & ! snow volume, netcdf snow mass

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.

remove extra space

if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
file=__FILE__, line=__LINE__)

allocate(hdiag(n_hdiag_core + 16 + 4*n_iso + 4*n_aero))

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.

Document the number if indices here, where does that come from?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks, I made these parameters

16 optional ones for the conservation budgets (hd_ptot to hd_frz in the module header);
4 per isotope and per aerosol tracer (flux from the atmosphere, flux to the ocean, total, maximum)

diagfreq_unit = '1' ! units of diagfreq 'y', 'm', 'd', 'h', '1'
diag_netcdf_freq = 'x' ! netcdf hemispheric diagnostics frequency, 'x' off
diag_netcdf_freq_n = 1 ! netcdf hemispheric diagnostics frequency count
diag_netcdf_avg = .true. ! if true, netcdf diagnostics are time averages

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.

wondering if diagfreq_netcdf, diagfreq_netcdf_n, diagavg_netcdf might be easier to read? Also, we need to make sure it's clear that log out is instantaneous at the frequency requested, while the netcdf output can be instantaneous or averaged.

Do we need a diagfreq_base like the history output for some phase control?

!=======================================================================

! Write hemispheric diagnostics to the netcdf diagnostics file, master task only.
! There is one file for each of time averages and instantaneous values. It is

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.

Change to "There is one file for all of the history diagnostics". I read it as one file per field as written.


! filename, _avg for time averages or _inst for instantaneous values,
! as for history files
if (diag_netcdf_avg) then

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.

OK, so there is one file per case or experiment. That makes sense. Will these files be OK if a run fails in the middle and the run is resubmitted and starts at the last restart file? Will the diagnostics and time axis be written/rewritten/overwritten correctly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

OK, so as I understand, this is handled gracefully. That loop opens the file and figures out the records that exist after the model time and then overwrites them. Thanks!

if (n == 0) return

select case (unit)
case ("y", "Y")

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.

There is some inconsistency in support for capital letter options "Y", "M", "D", etc. For the history/restart files, the freq option is not checked anywhere (from what I can see) and then "y" and "Y" are supported internally. I think if someone sets "a" for histfreq, it just won't do anything and it won't abort? For the new diagfreq option, the lower case options are checked in ice_init and aborted if not valid which means the upper case cannot be used and there is a clean check.

Can we make this more consistent and robust. A few options

  1. we only support lower case and they are all check in ice_init for valid values (like diagfreq is currently implemented). We clean up the implementation so capital letters are no longer valid internally.
  2. we support upper and lower case options for all freq settings, they are NOT checked in ice_init, but we add a "case default" option in ice_calendar or elsewhere where the model will abort if a freq setting is not valid.
  3. we support upper and lower case options, but upper case is converted to lower case in ice_init and then we follow step 1 above.

I think 3 works the best. Both upper and lower case are supported for all freq settings, we can remove the "upper case" implementation throughout the code, and each freq feature (hist, rest, diag) can have their own set of supported options checked in ice_init. We can also have a single general ice_calendar method to compute the "freq_now" value that doesn't need to worry whether "g" or "n" are valid values for one or another freq feature because those will be checked in ice_init. This should be backwards compatible and improve robustness and consistency. Does that sound like something that could be done in this PR? Happy to help with any of this.

@@ -0,0 +1,3 @@
diagfreq = 1
diagfreq_unit = 'd'
diag_netcdf_freq = 'd'

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.

Suggest diag_netcdf_freq_n is set explicitly as well.

@@ -0,0 +1,2 @@
diag_netcdf_freq = '1'

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.

Suggest diag_netcdf_freq_n be set explicitly as well.

@@ -0,0 +1,4 @@
diagfreq = 12

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.

Suggest diagfreq_unit be set explicitly as well.

dump_last = .false.
bfbflag = 'off'
diagfreq = 24
diagfreq_unit = '1'

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.

I'm wondering if we should clean up the namelist names now. We have diagfreq_unit/diagfreq and npt_unit/npt. Then we have dumpfreq/dumpfreq_n/dumpfreq_base, histfreq/histfreq_n/histfreq_base, and now diag_netcdf_freq/diag_netcdf_freq_n.

Some of this is due to the history of the namelist names and support for backwards compatibility. I think now might be a good time to make this more consistent and provide backwards compatibility (for now). There are a bunch of challenges with cleaning this up. I suggest we use histfreq_unit/histfreq_n/histfreq_base as the standard naming convention. So that would mean we would have to rename the following variables

diagfreq -> diagfreq_n
npt -> npt_n
dumpfreq -> dumpfreq_unit
histfreq -> histfreq_unit
diag_netcdf_freq -> diag_netcdf_freq_unit

We could continue to allow the old namelist for the time being and have ice_init copy the value into the new namelist name and write a warning message about use of a deprecated namelist name. We could also check that the old and new are both not set in the namelist. Documentation would be updated to reflect only the new namelist variable names.

As part of this, maybe we should use something other than "npt". Maybe "runlen" so runlen_unit/runlen_n? And I'll again promote diagfreq_netcdf_unit and diagfreq_netcdf_n or maybe even diaghistfreq_unit and diaghistfreq_n? So that would mean

diagfreq -> diagfreq_n
npt_unit -> runlen_unit
npt -> runlen_n
dumpfreq -> dumpfreq_unit
histfreq -> histfreq_unit
diag_netcdf_freq -> diaghistfreq_unit
diag_netcdf_freq_n -> diaghistfreq_n

And maybe add _base as needed for the options that need an _base that don't have it yet. We should verify I haven't missed any. Again, more than happy to discuss whether we should take this step (now would be a good time to do it), what nomenclature we should establish, and I'm happy to help with the implementation.

@apcraig

apcraig commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

I will run some tests on derecho with multiple compilers once we feel this is close to being in final review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anton-seaice

Copy link
Copy Markdown
Contributor Author

I made an issue about the namelist:

#1164

@apcraig

apcraig commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

@anton-seaice, what's the status of this PR. Are you waiting for discussion of #1164? Do you want to defer that issue? There were a few other suggested changes to get this ready for testing and merge. No rush, just checking in.

@anton-seaice

Copy link
Copy Markdown
Contributor Author

Yeah I think it's best to agree on the namelist names first, so we don't end up needed to change them again ?

if (print_global) then
! conservation diagnostics, the same as the netcdf diagnostics
call hdiag_global(hdiag_n, 1, dt, budget_n)
call hdiag_global(hdiag_s, 2, dt, budget_s)

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.

I like what you've done here


character (len=*), intent(in) :: &
vname_n , & ! netcdf variable name, northern hemisphere
vname_s , & ! netcdf variable name, southern hemisphere

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.

Are these attributes only used for the netcdf output? If so, could this routine be put in that module? Or is it here due to a circular dependency?

! Values to be summed are per unit area; they are multiplied by the cell
! area when reduced.

subroutine hdiag_cell_values(hdiag_fld)

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.

I recommend changing this to hdiag_values_cell

! from the start of the timestep (init_mass_diags), so are only meaningful
! for instantaneous values.

subroutine hdiag_global(val, hemi, dt, budget)

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.

if this is just for one hemisphere, could it be named hdiag_hemisphere?

use ice_blocks, only: nx_block, ny_block
use ice_communicate, only: my_task, master_task
use ice_constants, only: c0, c1
use ice_diagnostics, only: hdiag, n_hdiag, hdiag_initialized, hdiag_hemi, &

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.

To reduce the amount of searching needed in ice_diagnostics.F90, it would be helpful to list the variables one-per-line with a comment on each that describes what they are . That could be done for subroutines too, or just make sure what they are doing is clearly indicated when they are called.

The subroutine names are not completely intuitive to me. E.g. 'h' means hemispheric not thickness, 'cell_values' refers to per cell, not a gridded field (values_cell would be clearer), 'global_values' is the 2 hemispheres, not 1 total global value, etc. And yes I know a lot of this is based on what's in the current code, but we didn't need to search another module to figure it out.

! Options for histfreq: '1','h','d','m','y','x', where x means that
! output stream will not be used (recommended for efficiency).
! Options for histfreq: '1','h','d','m','y','n','x', where n means
! day histfreq_n of each month and x means that the output stream

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.

Why is the n option needed? Is there not a histfreq_n for every histfreq?


use ice_boundary, only: ice_HaloUpdate
use ice_calendar, only: dt, dt_dyn, ndtd, diagfreq, write_restart, istep
use ice_calendar, only: dt, dt_dyn, ndtd, write_diag, write_restart

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.

diagfreq and write_diag are not used in this module

@manodeep

Copy link
Copy Markdown
Contributor

@anton-seaice These lines in the base code call init_mass_diags and init_history_bgc unconditionally on every step. Can this be avoided? Basically, only call init_mass_diags with a check on diagfreq (and possibly the value of print_global/print_points) and only call init_history_bgc when there is at least one bgc field

@anton-seaice

Copy link
Copy Markdown
Contributor Author

ill mark this as draft, and look at #1164 first

@anton-seaice
anton-seaice marked this pull request as draft November 23, 2026 01:44

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.

Global Scalars in History Output

5 participants