engine_configure_diag Subroutine

private subroutine engine_configure_diag(cfg, state, mpi_rank, decomp, ierr, open_stream_file)

Register the default diag-manager variable set and open the per-rank NetCDF stream. No-op when diagnostics are disabled. open_stream_file = .false. (the --validate-only path) runs the level/selection checks but creates neither the output directory nor the stream. Moved verbatim from driver_run_ocean’s private configure_ocean_diag helper (P2.4) so the API/bench setup paths can reach it too; F5 residual — now takes optional ierr instead of error stopping (see rdb_ocean_diag’s set_output_*_levels for the leaf-level conversions this threads through).

Arguments

Type IntentOptional Attributes Name
type(config_t), intent(in) :: cfg
type(ocean_state_t), intent(inout) :: state
integer, intent(in) :: mpi_rank
type(decomp_t), intent(in) :: decomp
integer, intent(out), optional :: ierr
logical, intent(in), optional :: open_stream_file

Default .true..


Calls

proc~~engine_configure_diag~~CallsGraph proc~engine_configure_diag engine_configure_diag proc~apply_diag_selection apply_diag_selection proc~engine_configure_diag->proc~apply_diag_selection proc~diag_vgrid_from_name diag_vgrid_from_name proc~engine_configure_diag->proc~diag_vgrid_from_name proc~ensure_directory_exists ensure_directory_exists proc~engine_configure_diag->proc~ensure_directory_exists proc~ocean_diag_set_output_density_levels ocean_diag_t%ocean_diag_set_output_density_levels proc~engine_configure_diag->proc~ocean_diag_set_output_density_levels proc~ocean_diag_set_output_sigma_levels ocean_diag_t%ocean_diag_set_output_sigma_levels proc~engine_configure_diag->proc~ocean_diag_set_output_sigma_levels proc~ocean_diag_set_output_z_levels ocean_diag_t%ocean_diag_set_output_z_levels proc~engine_configure_diag->proc~ocean_diag_set_output_z_levels proc~ocean_diag_set_output_zstar_levels ocean_diag_t%ocean_diag_set_output_zstar_levels proc~engine_configure_diag->proc~ocean_diag_set_output_zstar_levels proc~open_stream open_stream proc~engine_configure_diag->proc~open_stream proc~output_rank_filename output_rank_filename proc~engine_configure_diag->proc~output_rank_filename proc~parse_diag_remap_scheme parse_diag_remap_scheme proc~engine_configure_diag->proc~parse_diag_remap_scheme proc~set_diag_mask_vanished set_diag_mask_vanished proc~engine_configure_diag->proc~set_diag_mask_vanished proc~set_diag_remap_method set_diag_remap_method proc~engine_configure_diag->proc~set_diag_remap_method proc~setup_failed setup_failed proc~engine_configure_diag->proc~setup_failed proc~uniform_diag_levels uniform_diag_levels proc~engine_configure_diag->proc~uniform_diag_levels 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 none~c_mkdir c_mkdir proc~ensure_directory_exists->none~c_mkdir proc~path_to_c_string path_to_c_string proc~ensure_directory_exists->proc~path_to_c_string to_string to_string proc~ensure_directory_exists->to_string proc~ensure_directory_exists->warning proc~fail fail proc~ocean_diag_set_output_density_levels->proc~fail proc~ocean_diag_set_output_sigma_levels->proc~fail proc~ocean_diag_set_output_z_levels->proc~fail proc~ocean_diag_set_output_zstar_levels->proc~fail proc~diag_io_ok diag_io_ok proc~open_stream->proc~diag_io_ok proc~diag_xtype_from_name diag_xtype_from_name proc~open_stream->proc~diag_xtype_from_name proc~nc_create_file nc_create_file proc~open_stream->proc~nc_create_file proc~nc_def_dim nc_def_dim proc~open_stream->proc~nc_def_dim proc~nc_def_var_3d nc_def_var_3d proc~open_stream->proc~nc_def_var_3d proc~nc_def_var_4d nc_def_var_4d proc~open_stream->proc~nc_def_var_4d proc~nc_enddef nc_enddef proc~open_stream->proc~nc_enddef proc~nc_put_att nc_put_att proc~open_stream->proc~nc_put_att proc~nc_put_att_global nc_put_att_global proc~open_stream->proc~nc_put_att_global proc~nc_put_att_global_int nc_put_att_global_int proc~open_stream->proc~nc_put_att_global_int proc~nc_put_att_real nc_put_att_real proc~open_stream->proc~nc_put_att_real proc~nc_put_att_real_r4 nc_put_att_real_r4 proc~open_stream->proc~nc_put_att_real_r4 proc~rdb_def_var_1d rdb_def_var_1d proc~open_stream->proc~rdb_def_var_1d proc~nc_close nc_close proc~diag_io_ok->proc~nc_close proc~diag_xtype_from_name->warning error error proc~fail->error proc~error_ring_push error_ring_push proc~fail->proc~error_ring_push proc~canonical_diag_gate_hint canonical_diag_gate_hint proc~gate_clause->proc~canonical_diag_gate_hint nf90_create nf90_create proc~nc_create_file->nf90_create proc~nc_check nc_check proc~nc_create_file->proc~nc_check nf90_def_dim nf90_def_dim proc~nc_def_dim->nf90_def_dim proc~nc_def_dim->proc~nc_check nf90_def_var nf90_def_var proc~nc_def_var_3d->nf90_def_var nf90_def_var_deflate nf90_def_var_deflate proc~nc_def_var_3d->nf90_def_var_deflate proc~nc_def_var_3d->proc~nc_check proc~nc_def_var_4d->nf90_def_var proc~nc_def_var_4d->nf90_def_var_deflate proc~nc_def_var_4d->proc~nc_check nf90_enddef nf90_enddef proc~nc_enddef->nf90_enddef proc~nc_enddef->proc~nc_check nf90_put_att nf90_put_att proc~nc_put_att->nf90_put_att proc~nc_put_att->proc~nc_check proc~nc_put_att_global->nf90_put_att proc~nc_put_att_global->proc~nc_check proc~nc_put_att_global_int->nf90_put_att proc~nc_put_att_global_int->proc~nc_check proc~nc_put_att_real->nf90_put_att proc~nc_put_att_real->proc~nc_check proc~nc_put_att_real_r4->nf90_put_att proc~nc_put_att_real_r4->proc~nc_check proc~parse_one_spec_token parse_one_spec_token proc~parse_diag_spec->proc~parse_one_spec_token proc~rdb_def_var_1d->nf90_def_var proc~rdb_def_var_1d->nf90_def_var_deflate proc~rdb_def_var_1d->proc~nc_check proc~register_one_canonical register_one_canonical proc~register_default_diags->proc~register_one_canonical 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~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~nc_check->proc~fail nf90_strerror nf90_strerror proc~nc_check->nf90_strerror proc~nc_close->proc~nc_check nf90_close nf90_close proc~nc_close->nf90_close 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~~engine_configure_diag~~CalledByGraph proc~engine_configure_diag engine_configure_diag 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

Source Code

   subroutine engine_configure_diag(cfg, state, mpi_rank, decomp, ierr, open_stream_file)
      !! Register the default diag-manager variable set and open the
      !! per-rank NetCDF stream. No-op when diagnostics are disabled.
      !! `open_stream_file = .false.` (the `--validate-only` path) runs the
      !! level/selection checks but creates neither the output directory
      !! nor the stream.
      !! Moved verbatim from `driver_run_ocean`'s private
      !! `configure_ocean_diag` helper (P2.4) so the API/bench setup
      !! paths can reach it too; F5 residual — now takes optional
      !! `ierr` instead of `error stop`ping (see `rdb_ocean_diag`'s
      !! `set_output_*_levels` for the leaf-level conversions this
      !! threads through).
      type(config_t), intent(in) :: cfg
      type(ocean_state_t), intent(inout) :: state
      integer, intent(in) :: mpi_rank
      type(decomp_t), intent(in) :: decomp
      integer, intent(out), optional :: ierr
      logical, intent(in), optional :: open_stream_file
         !! Default `.true.`.

      if (present(ierr)) ierr = OCEAN_STATUS_OK
      if (.not. cfg%ocean%diag%enabled) return

#ifdef RDB_NO_NETCDF
      call fail("engine_configure_diag: &ocean_diag_nml enabled = .true. but this build "// &
                "has no NetCDF support (RDB_ENABLE_NETCDF=OFF)", ierr, OCEAN_STATUS_ERR_SETUP)
#else
      block
         character(len=512) :: rank_filename
         logical :: multi_rank_diag

         call set_diag_remap_method(parse_diag_remap_scheme(cfg%ocean%diag%diag_remap_scheme))
         call set_diag_mask_vanished(cfg%ocean%diag%mask_vanished_layers)

         if (cfg%ocean%diag%n_z_levels > 0) then
            call state%diag%set_output_z_levels( &
               cfg%ocean%diag%z_levels(1:cfg%ocean%diag%n_z_levels), ierr=ierr)
            if (setup_failed(ierr)) return
         end if
         if (cfg%ocean%diag%n_sigma_levels > 0) then
            call state%diag%set_output_sigma_levels( &
               cfg%ocean%diag%sigma_levels(1:cfg%ocean%diag%n_sigma_levels), ierr=ierr)
         else
            call state%diag%set_output_sigma_levels( &
               uniform_diag_levels(state%multilayer%nz_ml), ierr=ierr)
         end if
         if (setup_failed(ierr)) return
         if (cfg%ocean%diag%n_zstar_levels > 0) then
            call state%diag%set_output_zstar_levels( &
               cfg%ocean%diag%zstar_levels(1:cfg%ocean%diag%n_zstar_levels), ierr=ierr)
         else
            call state%diag%set_output_zstar_levels( &
               uniform_diag_levels(state%multilayer%nz_ml), ierr=ierr)
         end if
         if (setup_failed(ierr)) return
         if (cfg%ocean%diag%n_rho_levels > 0) then
            call state%diag%set_output_density_levels( &
               cfg%ocean%diag%rho_levels(1:cfg%ocean%diag%n_rho_levels), ierr=ierr)
            if (setup_failed(ierr)) return
         end if
         call apply_diag_selection(state, trim(cfg%ocean%diag%diags), &
                                   dt_out=cfg%ocean%diag%dt_out, &
                                   default_coord=diag_vgrid_from_name(cfg%ocean%diag%vgrid))
         if (present(open_stream_file)) then
            if (.not. open_stream_file) return
         end if

         ! P7 F1: a fresh checkout's default `output_dir = "./output"`
         ! (rdb_config.F90:2316) does not exist until something creates
         ! it, and `nc_create_file` used to `error stop` the whole host
         ! process on the resulting ENOENT — the single most likely
         ! real-world `create()` failure for a first-time caller.
         ! Best-effort `mkdir`; a still-missing directory (e.g. a missing
         ! GRANDPARENT, or an unwritable parent) surfaces as the ordinary
         ! `open_stream` ierr/error-stop below, naming the exact path via
         ! the underlying `nf90_create` failure message.
         call ensure_directory_exists(trim(cfg%output_dir))

         rank_filename = output_rank_filename(trim(cfg%output_dir), &
                                              trim(cfg%ocean%diag%filename), mpi_rank)
         multi_rank_diag = decomp%px*decomp%py > 1
         if (multi_rank_diag) then
            if (cfg%compress_output) then
               call open_stream(state%diag, trim(rank_filename), &
                                deflate_level=cfg%compress_level, &
                                px=decomp%px, py=decomp%py, &
                                i_start=decomp%i_start, j_start=decomp%j_start, &
                                nx_global=decomp%nx_global, ny_global=decomp%ny_global, &
                                nx_local=decomp%nx_local, ny_local=decomp%ny_local, &
                                nghost=cfg%nghost, &
                                output_precision=trim(cfg%ocean%diag%output_precision), &
                                ierr=ierr)
            else
               call open_stream(state%diag, trim(rank_filename), &
                                px=decomp%px, py=decomp%py, &
                                i_start=decomp%i_start, j_start=decomp%j_start, &
                                nx_global=decomp%nx_global, ny_global=decomp%ny_global, &
                                nx_local=decomp%nx_local, ny_local=decomp%ny_local, &
                                nghost=cfg%nghost, &
                                output_precision=trim(cfg%ocean%diag%output_precision), &
                                ierr=ierr)
            end if
         else
            if (cfg%compress_output) then
               call open_stream(state%diag, trim(rank_filename), &
                                deflate_level=cfg%compress_level, &
                                output_precision=trim(cfg%ocean%diag%output_precision), &
                                ierr=ierr)
            else
               call open_stream(state%diag, trim(rank_filename), &
                                output_precision=trim(cfg%ocean%diag%output_precision), &
                                ierr=ierr)
            end if
         end if
         if (setup_failed(ierr)) return
      end block
#endif
   end subroutine engine_configure_diag