subroutine register_one_canonical(state, specs, default_coord, dtout, name, units, &
fill, n3, def_op, long_name, standard_name)
!! Register one canonical diagnostic, applying its `specs` entry:
!! skip if `:off`; override cadence / time-op; pick the output vgrid
!! (`:coord` override, else `default_coord`, else LAYER) and attach the
!! matching conservative remap. 2D diagnostics (`n3 <= 1`) ignore any
!! coord request (no vertical to remap). All canonical diagnostics are
!! INTENSIVE (thickness-weighted average on remap).
type(ocean_state_t), intent(inout), target :: state
type(diag_spec_t), intent(in), optional :: specs(:)
integer, intent(in) :: default_coord, n3, def_op
real(wp), intent(in) :: dtout
character(len=*), intent(in) :: name, units, long_name
character(len=*), intent(in), optional :: standard_name
procedure(diag_fill_proc) :: fill
integer :: nx, ny, op, coord
real(wp) :: dto
logical :: skip
procedure(diag_remap_proc), pointer :: remap
op = def_op
dto = dtout
coord = default_coord
call resolve_canonical_spec(specs, name, op, dto, coord, skip)
if (skip) return
! 2D fields have no vertical axis to remap onto.
if (n3 <= 1) coord = DIAG_VGRID_LAYER
call coord_remap_proc(coord, remap)
nx = size(state%barotropic%h, 1)
ny = size(state%barotropic%h, 2)
if (associated(remap)) then
call state%diag%register(name, units=units, fill=fill, n1=nx, n2=ny, n3=n3, &
long_name=long_name, standard_name=standard_name, &
time_op=op, dt_out=dto, output_vgrid=coord, &
remap=remap, is_extensive=.false., &
has_missing=(diag_mask_vanished .and. &
coord /= DIAG_VGRID_DENSITY))
else
call state%diag%register(name, units=units, fill=fill, n1=nx, n2=ny, n3=n3, &
long_name=long_name, standard_name=standard_name, &
time_op=op, dt_out=dto)
end if
end subroutine register_one_canonical