subroutine register_ocean_diag(cfg, schema)
!! `&ocean_diag_nml`: ocean diag-manager output controls. `dt_out`
!! is interpreted in `time_unit` and converted by the post-parse
!! cascade in read_config. `vgrid` enum is {layer, z_fixed}.
type(config_t), target, intent(in) :: cfg
type(nml_schema_t), intent(inout) :: schema
type(nml_group_t) :: g
logical, pointer :: pl
real(wp), pointer :: pr
real(wp), pointer :: pra(:)
integer, pointer :: pi
character(len=:), pointer :: ps
g%name = "ocean_diag"
g%doc = "Ocean diag-manager output controls."
pl => cfg%ocean%diag%enabled
call g%add(nml_logical("enabled", pl, "Enable the per-step diag-manager hook"))
ps => cfg%ocean%diag%filename
call g%add(nml_string("filename", ps, "Output file basename (per-rank suffix appended)"))
pr => cfg%ocean%diag%dt_out
call g%add(nml_real("dt_out", pr, "Diag-fire cadence (in time_unit)"))
ps => cfg%ocean%diag%vgrid
call g%add(nml_enum("vgrid", ps, "Default output vertical grid for layer-shaped diags", &
allowed=[character(len=7) :: "layer", "z_fixed", "sigma", "zstar", "density"]))
pra => cfg%ocean%diag%z_levels
call g%add(nml_real_array("z_levels", pra, "Output z-levels when vgrid=z_fixed (positive down)", &
units="m"))
pi => cfg%ocean%diag%n_z_levels
call g%add(nml_int("n_z_levels", pi, "Number of z_levels entries used (0 = none)", min=0))
pra => cfg%ocean%diag%sigma_levels
call g%add(nml_real_array("sigma_levels", pra, &
"Output sigma fractions (0..1) for sigma output; empty = auto-uniform"))
pi => cfg%ocean%diag%n_sigma_levels
call g%add(nml_int("n_sigma_levels", pi, "Number of sigma_levels entries used (0 = auto)", min=0))
pra => cfg%ocean%diag%zstar_levels
call g%add(nml_real_array("zstar_levels", pra, &
"Output z* reference depths for zstar output; empty = auto-uniform", &
units="m"))
pi => cfg%ocean%diag%n_zstar_levels
call g%add(nml_int("n_zstar_levels", pi, "Number of zstar_levels entries used (0 = auto)", min=0))
! NVHPC 26.5 codegen workaround (verified by bisection, see PR-9 report):
! passing a 4th `nml_real_array(...)` function-result temporary
! directly to `g%add(...)` inside THIS subroutine corrupts unrelated
! heap state (manifests as a SIGSEGV deep in an unrelated later
! namelist read, e.g. the old hand-rolled `read_ocean_bc_nml`, since
! removed by the P4.5 schema migration — `register_ocean_bc` uses
! the same workaround for its twelve real_array knobs). z_levels/sigma_levels/
! zstar_levels (the first 3 real_array calls here) are unaffected;
! materialising the result into an explicit local variable before
! `g%add` avoids the miscompile. Do not "simplify" this back to the
! one-line call-expression form.
block
type(nml_real_array_key_t) :: rho_key
pra => cfg%ocean%diag%rho_levels
rho_key = nml_real_array("rho_levels", pra, &
"Output potential-density bin edges when vgrid=density; "// &
"strictly increasing, light->dense", &
units="kg/m^3")
call g%add(rho_key)
end block
pi => cfg%ocean%diag%n_rho_levels
call g%add(nml_int("n_rho_levels", pi, "Number of rho_levels entries used (0 = none)", min=0))
pl => cfg%ocean%diag%mask_vanished_layers
call g%add(nml_logical("mask_vanished_layers", pl, &
"Mask below-bottom/pinched remap cells to missing_value (default off)"))
pl => cfg%ocean%diag%reproducing_sums
call g%add(nml_logical("reproducing_sums", pl, &
"Order-invariant EFP console totals + budget terms: identical "// &
"console on every rank count, exact drift residual "// &
"(.false. = the pre-v0.1.0 FP sums)"))
ps => cfg%ocean%diag%output_precision
call g%add(nml_enum("output_precision", ps, &
"Element width of the diag NetCDF data vars; "// &
"'single' halves the bytes written (restarts/gauges/"// &
"console totals stay double regardless)", &
allowed=[character(len=6) :: "double", "single"]))
ps => cfg%ocean%diag%diag_remap_scheme
call g%add(nml_enum("diag_remap_scheme", ps, &
"Reconstruction for the conservative diagnostic vertical remap", &
allowed=[character(len=6) :: "pcm", "plm", "ppm", "ppm_h4", "pqm"]))
ps => cfg%ocean%diag%diags
call g%add(nml_string("diags", ps, &
"Unified diag list modifying the default set: name[:off][:cadence][:op] "// &
"(e.g. 'vorticity_z:1d KE:off temperature:6h:mean'); "// &
"default empty = canonical set"))
call schema%add_group(g)
end subroutine register_ocean_diag