rdb_ocean_z_init Module

Puts a GEOPOTENTIAL T(z)/S(z) profile onto the seeded layer centres (&ocean_zinit_nml) and writes the multilayer tracer slots as hTr = value * h_layer. Two sources, &ocean_zinit_nml source:

  • "file" (default) — reads pre-regridded T + S from a model-grid NetCDF and interpolates linearly in depth. File is PRE-REGRIDDED to nx_phys x ny_phys — no in-core horizontal interpolation. Vertical interp is point-linear-in-depth, constant extrapolation beyond the source range. Dry columns (wet_mask <= 0) get the namelist land_fill_t/_s constants. Interior cells only — ghosts keep whatever the analytical IC seeded, because the file carries no data for them.
  • "linear" — an ANALYTIC affine profile, T(z) = lin_t_ref + lin_dt_dz*z (and the salinity twin) with z the GEOPOTENTIAL height, positive UP, zero at the z = 0 datum, i.e. z = -z_ctr. Needs no file, so it fills the FULL array INCLUDING ghosts and land columns (the analytic formula is defined everywhere — same reasoning as the formula bathymetry setters, and it keeps a wall-adjacent EOS evaluation off the rho_0 fallback). This is the profile an idealised ice-shelf cavity needs: &tracer_nml T_init_surface / T_init_bottom are linear in LAYER INDEX, which under a terrain-following coordinate with a SLOPING lid tilts the isopycnals with the coordinate and is therefore NOT a state of rest.

Depth is measured from z = 0, not from the column top

build_z_ctr takes the geopotential depth of the column TOP (z_top, positive-down) and adds the thickness above each layer centre. In the open ocean z_top = 0 and this is the free-surface datum. Under an ice shelf the water column starts z_draft metres down, so z_top = metrics%z_draft(i,j); without it a geopotential profile lands z_draft metres too shallow on every shelf column and the isopycnals tilt with the ice base. z_draft reaches here as an OPTIONAL ghosted (nx_total, ny_total) argument: absent (the no-cavity path) is z_top = 0 and bit-identical to the original.

Runs at seed time, HOST-side, BEFORE ocean_state_enter_data, so it uses plain host do loops (NOT do concurrent); the later enter_data copies the host-resident arrays up. The module is only compiled with RDB_ENABLE_NETCDF=ON (the file reader needs it), so the "linear" source currently inherits that build requirement even though it opens nothing.


Uses

  • module~~rdb_ocean_z_init~~UsesGraph module~rdb_ocean_z_init rdb_ocean_z_init module~rdb_config rdb_config module~rdb_ocean_z_init->module~rdb_config module~rdb_constants rdb_constants module~rdb_ocean_z_init->module~rdb_constants module~rdb_error_ring rdb_error_ring module~rdb_ocean_z_init->module~rdb_error_ring module~rdb_grid rdb_grid module~rdb_ocean_z_init->module~rdb_grid module~rdb_io_netcdf rdb_io_netcdf module~rdb_ocean_z_init->module~rdb_io_netcdf module~rdb_multilayer_state rdb_multilayer_state module~rdb_ocean_z_init->module~rdb_multilayer_state module~rdb_ocean_status rdb_ocean_status module~rdb_ocean_z_init->module~rdb_ocean_status netcdf netcdf module~rdb_ocean_z_init->netcdf pic_logger pic_logger module~rdb_ocean_z_init->pic_logger pic_strings pic_strings module~rdb_ocean_z_init->pic_strings module~rdb_config->module~rdb_constants module~rdb_config->module~rdb_error_ring module~rdb_config->module~rdb_ocean_status module~rdb_config->pic_logger module~rdb_config->pic_strings module~rdb_ice_enthalpy rdb_ice_enthalpy module~rdb_config->module~rdb_ice_enthalpy module~rdb_ice_init rdb_ice_init module~rdb_config->module~rdb_ice_init module~rdb_nml_schema rdb_nml_schema module~rdb_config->module~rdb_nml_schema pic_ascii pic_ascii module~rdb_config->pic_ascii pic_types pic_types module~rdb_constants->pic_types module~rdb_error_ring->pic_logger module~rdb_grid->module~rdb_constants module~rdb_io_netcdf->module~rdb_constants module~rdb_io_netcdf->module~rdb_error_ring module~rdb_io_netcdf->netcdf module~rdb_io_netcdf->pic_logger module~rdb_io_netcdf->pic_strings iso_c_binding iso_c_binding module~rdb_io_netcdf->iso_c_binding iso_fortran_env iso_fortran_env module~rdb_io_netcdf->iso_fortran_env module~rdb_multilayer_state->module~rdb_constants module~rdb_multilayer_state->module~rdb_error_ring module~rdb_multilayer_state->module~rdb_grid module~rdb_multilayer_state->pic_logger module~rdb_multilayer_state->iso_fortran_env module~rdb_efp rdb_efp module~rdb_multilayer_state->module~rdb_efp module~rdb_mem_report rdb_mem_report module~rdb_multilayer_state->module~rdb_mem_report module~rdb_tracer rdb_tracer module~rdb_multilayer_state->module~rdb_tracer module~rdb_efp->iso_fortran_env ieee_arithmetic ieee_arithmetic module~rdb_efp->ieee_arithmetic module~rdb_ice_enthalpy->module~rdb_constants module~rdb_ice_init->module~rdb_constants module~rdb_ice_init->module~rdb_grid module~rdb_ice_init->module~rdb_multilayer_state module~rdb_ice_init->module~rdb_ice_enthalpy module~rdb_ice_column rdb_ice_column module~rdb_ice_init->module~rdb_ice_column module~rdb_ice_state rdb_ice_state module~rdb_ice_init->module~rdb_ice_state module~rdb_ocean_metrics rdb_ocean_metrics module~rdb_ice_init->module~rdb_ocean_metrics module~rdb_mem_report->module~rdb_constants module~rdb_mem_report->pic_logger module~rdb_mem_report->pic_strings module~rdb_mem_report->iso_fortran_env module~rdb_nml_schema->module~rdb_constants module~rdb_nml_schema->module~rdb_error_ring module~rdb_nml_schema->pic_logger module~rdb_tracer->module~rdb_constants module~rdb_tracer->module~rdb_grid module~rdb_tracer->iso_fortran_env module~rdb_tracer->module~rdb_mem_report module~rdb_ice_column->module~rdb_constants module~rdb_ice_column->module~rdb_ice_enthalpy module~rdb_ice_mass rdb_ice_mass module~rdb_ice_column->module~rdb_ice_mass module~rdb_ice_optics rdb_ice_optics module~rdb_ice_column->module~rdb_ice_optics module~rdb_ice_state->module~rdb_constants module~rdb_ice_state->module~rdb_grid module~rdb_ice_state->iso_fortran_env module~rdb_ice_state->module~rdb_ice_enthalpy module~rdb_ice_state->module~rdb_mem_report module~rdb_ice_state->module~rdb_ice_column module~rdb_ocean_metrics->module~rdb_constants module~rdb_ocean_metrics->module~rdb_error_ring module~rdb_ocean_metrics->module~rdb_grid module~rdb_ocean_metrics->module~rdb_io_netcdf module~rdb_ocean_metrics->module~rdb_ocean_status module~rdb_ocean_metrics->netcdf module~rdb_ocean_metrics->pic_logger module~rdb_ocean_metrics->pic_strings module~rdb_ocean_metrics->iso_fortran_env module~rdb_ocean_metrics->module~rdb_mem_report module~rdb_ocean_bipolar rdb_ocean_bipolar module~rdb_ocean_metrics->module~rdb_ocean_bipolar module~rdb_ocean_fold rdb_ocean_fold module~rdb_ocean_metrics->module~rdb_ocean_fold module~rdb_ice_mass->module~rdb_constants module~rdb_ice_mass->module~rdb_ice_enthalpy module~rdb_ice_optics->module~rdb_constants module~rdb_ice_optics->module~rdb_ice_enthalpy module~rdb_ocean_bipolar->module~rdb_constants module~rdb_ocean_fold->module~rdb_constants

Used by

  • module~~rdb_ocean_z_init~~UsedByGraph module~rdb_ocean_z_init rdb_ocean_z_init module~rdb_ocean_state rdb_ocean_state module~rdb_ocean_state->module~rdb_ocean_z_init module~rdb_driver rdb_driver module~rdb_driver->module~rdb_ocean_state module~rdb_ocean_engine rdb_ocean_engine module~rdb_driver->module~rdb_ocean_engine module~rdb_handle rdb_handle module~rdb_handle->module~rdb_ocean_state module~rdb_handle->module~rdb_ocean_engine module~rdb_ocean_diag_derived rdb_ocean_diag_derived module~rdb_ocean_diag_derived->module~rdb_ocean_state module~rdb_ocean_diag_fills rdb_ocean_diag_fills module~rdb_ocean_diag_derived->module~rdb_ocean_diag_fills module~rdb_ocean_diag_fills->module~rdb_ocean_state module~rdb_ocean_engine->module~rdb_ocean_state module~rdb_ocean_engine->module~rdb_ocean_diag_derived module~rdb_ocean_engine->module~rdb_ocean_diag_fills module~rdb_ocean_setup rdb_ocean_setup module~rdb_ocean_engine->module~rdb_ocean_setup module~rdb_ocean_setup->module~rdb_ocean_state module~rdb_ocean_api rdb_ocean_api module~rdb_ocean_api->module~rdb_handle module~rdb_ocean_api->module~rdb_ocean_diag_derived module~rdb_ocean_api->module~rdb_ocean_diag_fills module~rdb_ocean_api->module~rdb_ocean_engine

Functions

public function zinit_dims_ok(filename, t_var, nx_phys, ny_phys) result(ok)

match (nx_phys, ny_phys). Returns .false. on mismatch or I/O error; does NOT error stop — safe from test code.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename
character(len=*), intent(in) :: t_var
integer, intent(in) :: nx_phys
integer, intent(in) :: ny_phys

Return Value logical

private pure function draft_shape_ok(z_draft, ms) result(ok)

True iff z_draft is the FULL ghosted (nx_total, ny_total) array the seeders index with (ng+i, ng+j) — i.e. it matches h_layer’s horizontal extent. Guards the (1, 1) placeholder ocean_metrics_t allocates when the cavity is off from ever being read as a field.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: z_draft(:,:)
type(multilayer_state_t), intent(in) :: ms

Return Value logical

private pure elemental function linear_in_z(v_ref, dv_dz, z_depth) result(v)

Affine profile v(z) = v_ref + dv_dz*z evaluated at geopotential height z = -z_depth, i.e. v = v_ref - dv_dz*z_depth.

Read more…

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: v_ref
real(kind=wp), intent(in) :: dv_dz
real(kind=wp), intent(in) :: z_depth

Return Value real(kind=wp)

private function zinit_io_ok(local_ierr, ierr, ncid) result(ok)

Translate a raw nc_check-style status (0 = ok) from one of the nc_* reader calls in seed_ts_from_zfile/read_dims into the caller’s ierr contract: .true. on success; on failure, .false. with ierr = OCEAN_STATUS_ERR_IO when ierr is present (closing ncid first, when given, so a mid-read failure does not leak the file handle), or error stops with the SAME generic text nc_check itself would have used had ierr never been threaded through — keeps the legacy (no ierr) behaviour byte-identical while unblocking the ierr-present return path (F1/F2 of the P0.1 review).

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: local_ierr
integer, intent(out), optional :: ierr
integer, intent(in), optional :: ncid

Return Value logical


Subroutines

public pure subroutine build_z_ctr(h_layer, nz_ml, z_top, z_ctr)

Layer-centre GEOPOTENTIAL depths (positive-down from the z = 0 datum) from a column of layer thicknesses. Bottom-up: k=1 bed, k=nz_ml surface. z_ctr(k) = z_top + sum_{k'=k+1..nz_ml} h(k') + 0.5*h(k).

Read more…

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: h_layer(nz_ml)
integer, intent(in) :: nz_ml
real(kind=wp), intent(in) :: z_top
real(kind=wp), intent(out) :: z_ctr(nz_ml)

public pure subroutine interp_column_linear_z(z_src, v_src, nz_src, z_ctr, nz_ml, v_out)

Linear-in-depth interpolation of source profile v_src on ascending depths z_src onto target depths z_ctr, with CONSTANT extrapolation beyond the source range. Comparisons in depth space so index orientations never need reconciling.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: z_src(nz_src)
real(kind=wp), intent(in) :: v_src(nz_src)
integer, intent(in) :: nz_src
real(kind=wp), intent(in) :: z_ctr(nz_ml)
integer, intent(in) :: nz_ml
real(kind=wp), intent(out) :: v_out(nz_ml)

public subroutine seed_ts_from_zfile(ms, grid, cfg, ierr, z_draft)

Read T/S from the configured z-level NetCDF and overwrite the tracer slots with the depth-interpolated profiles. Wet columns interpolate; dry columns get the namelist land-fill constants. Must be called AFTER bathymetry, the uniform h_layer seed, and wet_mask are in place. Takes the multilayer slot directly (not the full ocean state) to avoid a circular dependency.

Arguments

Type IntentOptional Attributes Name
type(multilayer_state_t), intent(inout) :: ms
type(hgrid_t), intent(in) :: grid
type(ocean_zinit_config_t), intent(in) :: cfg
integer, intent(out), optional :: ierr

Non-zero on a malformed/mismatched z-level IC file when present; absent behaves as today (error stop).

real(kind=wp), intent(in), optional :: z_draft(:,:)

Ice-base depth (m, positive-down, >= 0), FULL ghosted (nx_total, ny_total) shape — metrics%z_draft. The geopotential depth of every layer centre is measured from z = 0, so the column top sits at z_draft under a shelf. Absent ⇒ z_top = 0 (open ocean), bit-identical to the pre-cavity behaviour.

public subroutine seed_ts_linear_z(ms, cfg, ierr, z_draft)

Seed T and S from the ANALYTIC affine geopotential profiles T(z) = lin_t_ref + lin_dt_dz*z, S(z) = lin_s_ref + lin_ds_dz*z (z positive UP, zero at the z = 0 datum), sampled at each layer centre’s TRUE geopotential depth and written as hTr = value * h_layer.

Read more…

Arguments

Type IntentOptional Attributes Name
type(multilayer_state_t), intent(inout) :: ms
type(ocean_zinit_config_t), intent(in) :: cfg
integer, intent(out), optional :: ierr

Non-zero on a malformed z_draft when present; absent behaves like the rest of the seed path (error stop).

real(kind=wp), intent(in), optional :: z_draft(:,:)

Ice-base depth (m, positive-down), FULL ghosted (nx_total, ny_total) shape. Absent ⇒ open ocean.

private subroutine find_var(ncid, override, fallbacks, label, varid, ierr)

Resolve a variable id: try the namelist override name first (when non-blank), then the documented fallbacks in order. Error-stops with a descriptive message when none is found.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: ncid
character(len=*), intent(in) :: override
character(len=*), intent(in) :: fallbacks(:)
character(len=*), intent(in) :: label
integer, intent(out) :: varid
integer, intent(out), optional :: ierr

Non-zero when no matching variable is found, when present; absent behaves as today (error stop).

private subroutine read_dims(ncid, varid, grid, nz_src, needs_transpose, ierr)

Validate the T/S variable’s dims against the model grid and detect whether the file is C-ordered (z, y, x) => needs_transpose = .true. (by the first Fortran dim name). Returns source z-level count nz_src; error-stops on mismatch.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: ncid
integer, intent(in) :: varid
type(hgrid_t), intent(in) :: grid
integer, intent(out) :: nz_src
logical, intent(out) :: needs_transpose
integer, intent(out), optional :: ierr

Non-zero on a dimensionality/shape mismatch when present; absent behaves as today (error stop).

private subroutine read_field_xyz(ncid, varid, dst, nx, ny, nz_src, needs_transpose, io, jo, ierr)

Read this tile’s (nx, ny, nz_src) window of a 3D T/S variable (the file holds the WHOLE grid; the window starts at global cell (io+1, jo+1)) with a start/count read, permuting from the file’s Fortran storage order. On an undecomposed grid the window is the whole variable.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: ncid
integer, intent(in) :: varid
real(kind=wp), intent(out) :: dst(nx,ny,nz_src)
integer, intent(in) :: nx
integer, intent(in) :: ny
integer, intent(in) :: nz_src
logical, intent(in) :: needs_transpose
integer, intent(in) :: io

Global offsets of the tile (grid%i/j_offset_global).

integer, intent(in) :: jo

Global offsets of the tile (grid%i/j_offset_global).

integer, intent(out), optional :: ierr

Non-zero on a read failure when present; absent behaves as today (error stop).