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).
| Type | Intent | Optional | 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 |
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