apply_diag_selection Subroutine

public subroutine apply_diag_selection(state, spec, dt_out, default_coord)

Configure the ocean diagnostic set from the unified &ocean_diag_nml diags selection string. Single production entry point: parses spec once, registers the canonical defaults (consulting the spec for per-diagnostic :off skips and :cadence / :op / :coord overrides), then registers any spec entries that name a derived-catalog diagnostic (with their overrides).

default_coord (a DIAG_VGRID_*, default LAYER) is the global output vgrid (&ocean_diag_nml vgrid) applied to layered diagnostics that don’t carry a per-diag :coord.

An empty / blank spec + LAYER default reproduces the canonical set exactly (bit-identical). A spec name that is neither canonical nor in the derived catalog fails loud via register_derived. A :off on a non-canonical name that is not registered is a harmless no-op.

Must be called AFTER the output-level setters (set_output_z_levels / set_output_sigma_levels / set_output_zstar_levels / set_output_density_levels) so non-layer diagnostics size their remap targets correctly.

Arguments

Type IntentOptional Attributes Name
type(ocean_state_t), intent(inout), target :: state
character(len=*), intent(in) :: spec
real(kind=wp), intent(in), optional :: dt_out
integer, intent(in), optional :: default_coord

Calls

proc~~apply_diag_selection~~CallsGraph proc~apply_diag_selection apply_diag_selection proc~gate_clause gate_clause proc~apply_diag_selection->proc~gate_clause proc~is_canonical_diag_name is_canonical_diag_name proc~apply_diag_selection->proc~is_canonical_diag_name proc~ocean_diag_is_registered ocean_diag_t%ocean_diag_is_registered proc~apply_diag_selection->proc~ocean_diag_is_registered proc~parse_diag_spec parse_diag_spec proc~apply_diag_selection->proc~parse_diag_spec proc~register_default_diags register_default_diags proc~apply_diag_selection->proc~register_default_diags proc~register_derived register_derived proc~apply_diag_selection->proc~register_derived warning warning proc~apply_diag_selection->warning proc~canonical_diag_gate_hint canonical_diag_gate_hint proc~gate_clause->proc~canonical_diag_gate_hint proc~parse_one_spec_token parse_one_spec_token proc~parse_diag_spec->proc~parse_one_spec_token proc~register_one_canonical register_one_canonical proc~register_default_diags->proc~register_one_canonical error error proc~register_derived->error proc~catalog_name_list catalog_name_list proc~register_derived->proc~catalog_name_list proc~coord_remap_proc coord_remap_proc proc~register_derived->proc~coord_remap_proc proc~derived_requires_fail derived_requires_fail proc~register_derived->proc~derived_requires_fail proc~diag_mask_vanished_is_on diag_mask_vanished_is_on proc~register_derived->proc~diag_mask_vanished_is_on proc~ensure_catalog_initialised ensure_catalog_initialised proc~register_derived->proc~ensure_catalog_initialised proc~error_ring_push error_ring_push proc~register_derived->proc~error_ring_push proc~ocean_diag_register ocean_diag_t%ocean_diag_register proc~register_derived->proc~ocean_diag_register proc~catalog_name_list->proc~ensure_catalog_initialised proc~derived_requires_fail->error proc~derived_requires_fail->proc~error_ring_push proc~reset_accumulator reset_accumulator proc~ocean_diag_register->proc~reset_accumulator proc~parse_one_spec_token->error proc~lower_ascii lower_ascii proc~parse_one_spec_token->proc~lower_ascii proc~parse_cadence_attr parse_cadence_attr proc~parse_one_spec_token->proc~parse_cadence_attr proc~register_one_canonical->proc~coord_remap_proc proc~register_one_canonical->proc~ocean_diag_register proc~resolve_canonical_spec resolve_canonical_spec proc~register_one_canonical->proc~resolve_canonical_spec proc~fill_buffer_impl fill_buffer_impl proc~reset_accumulator->proc~fill_buffer_impl

Called by

proc~~apply_diag_selection~~CalledByGraph proc~apply_diag_selection apply_diag_selection proc~engine_configure_diag engine_configure_diag proc~engine_configure_diag->proc~apply_diag_selection proc~engine_setup engine_setup proc~engine_setup->proc~engine_configure_diag proc~complete_ocean_create complete_ocean_create proc~complete_ocean_create->proc~engine_setup proc~driver_run_ocean driver_run_ocean proc~driver_run_ocean->proc~engine_setup proc~driver_validate driver_validate proc~driver_validate->proc~engine_setup proc~driver_run driver_run proc~driver_run->proc~driver_run_ocean proc~rdb_ocean_create_finalize rdb_ocean_create_finalize proc~rdb_ocean_create_finalize->proc~complete_ocean_create proc~rdb_ocean_create_from_string rdb_ocean_create_from_string proc~rdb_ocean_create_from_string->proc~complete_ocean_create

Variables

Type Visibility Attributes Name Initial
integer, private :: coord
integer, private :: dcoord
real(kind=wp), private :: dto
real(kind=wp), private :: dtout
integer, private :: i
integer, private :: op
type(diag_spec_t), private, allocatable :: specs(:)

Source Code

   subroutine apply_diag_selection(state, spec, dt_out, default_coord)
      !! Configure the ocean diagnostic set from the unified
      !! `&ocean_diag_nml diags` selection string.  Single production entry
      !! point: parses `spec` once, registers the canonical defaults
      !! (consulting the spec for per-diagnostic `:off` skips and
      !! `:cadence` / `:op` / `:coord` overrides), then registers any spec
      !! entries that name a derived-catalog diagnostic (with their overrides).
      !!
      !! `default_coord` (a `DIAG_VGRID_*`, default LAYER) is the global
      !! output vgrid (`&ocean_diag_nml vgrid`) applied to layered diagnostics
      !! that don't carry a per-diag `:coord`.
      !!
      !! An empty / blank `spec` + LAYER default reproduces the canonical set
      !! exactly (bit-identical).  A spec name that is neither canonical nor
      !! in the derived catalog fails loud via `register_derived`.  A `:off`
      !! on a non-canonical name that is not registered is a harmless no-op.
      !!
      !! Must be called AFTER the output-level setters (`set_output_z_levels`
      !! / `set_output_sigma_levels` / `set_output_zstar_levels` /
      !! `set_output_density_levels`) so non-layer diagnostics size their
      !! remap targets correctly.
      type(ocean_state_t), intent(inout), target :: state
      character(len=*), intent(in) :: spec
      real(wp), intent(in), optional :: dt_out
      integer, intent(in), optional :: default_coord
      type(diag_spec_t), allocatable :: specs(:)
      integer :: i, op, dcoord, coord
      real(wp) :: dtout, dto

      dtout = 3600.0_wp
      if (present(dt_out)) dtout = dt_out
      dcoord = DIAG_VGRID_LAYER
      if (present(default_coord)) dcoord = default_coord

      specs = parse_diag_spec(spec)

      ! Canonical set, with the spec's per-diagnostic skips / overrides.
      call register_default_diags(state, dt_out=dtout, specs=specs, default_coord=dcoord)

      ! Derived-catalog additions: any spec entry that is not a canonical
      ! diagnostic and is not turned off.
      do i = 1, size(specs)
         if (specs(i)%off) cycle
         if (is_canonical_diag_name(trim(specs(i)%name))) then
            if (.not. state%diag%is_registered(trim(specs(i)%name))) then
               call global_logger%warning( &
                  "&ocean_diag_nml diags requested '"//trim(specs(i)%name)// &
                  "', which is a canonical diagnostic but is NOT registered — it will "// &
                  "be absent from the output. "//gate_clause(trim(specs(i)%name)))
            end if
            cycle
         end if
         op = DIAG_OP_INSTANT
         if (specs(i)%time_op /= DIAG_OP_UNSET) op = specs(i)%time_op
         dto = dtout
         if (specs(i)%dt_out > 0.0_wp) dto = specs(i)%dt_out
         coord = dcoord
         if (specs(i)%coord /= DIAG_COORD_UNSET) coord = specs(i)%coord
         call register_derived(state, trim(specs(i)%name), time_op=op, dt_out=dto, coord=coord)
      end do
   end subroutine apply_diag_selection