Public only for the unit-test suite (no production module imports it);
ignore when developing production code in other modules.
Helper: write per-layer density from layer_rho_init(:) when the
caller has set at least one non-sentinel value. Sentinel is
< 0; we expect exactly nz_ml non-sentinel entries listed
in k=1..nz_ml order (bed → surface).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(multilayer_state_t), | intent(inout) | :: | ms | |||
| real(kind=wp), | intent(in) | :: | layer_rho_init(:) | |||
| integer, | intent(in) | :: | nz_ml | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero when the non-sentinel count mismatches |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private | :: | i | ||||
| integer, | private | :: | j | ||||
| integer, | private | :: | k | ||||
| integer, | private | :: | n_set |
subroutine apply_layer_rho_init(ms, layer_rho_init, nz_ml, ierr) !! Public only for the unit-test suite (no production module imports it); !! ignore when developing production code in other modules. !! Helper: write per-layer density from `layer_rho_init(:)` when the !! caller has set at least one non-sentinel value. Sentinel is !! `< 0`; we expect exactly `nz_ml` non-sentinel entries listed !! in `k=1..nz_ml` order (bed → surface). type(multilayer_state_t), intent(inout) :: ms real(wp), intent(in) :: layer_rho_init(:) integer, intent(in) :: nz_ml integer, intent(out), optional :: ierr !! Non-zero when the non-sentinel count mismatches `nz_ml`, when !! present; absent behaves as today (`error stop`). integer :: i, j, k, n_set n_set = count(layer_rho_init >= 0.0_wp) if (n_set == 0) then if (present(ierr)) ierr = OCEAN_STATUS_OK return ! sentinel everywhere — leave rho_layer alone end if if (n_set /= nz_ml) then call fail("ocean_layer_rho_init: count of non-sentinel "// & "entries ("//to_string(n_set)//") does not match "// & "nz_layers ("//to_string(nz_ml)//").", ierr, OCEAN_STATUS_ERR_IC_SEED) return end if do k = 1, nz_ml do j = 1, size(ms%rho_layer, 2) do i = 1, size(ms%rho_layer, 1) ms%rho_layer(i, j, k) = layer_rho_init(k) end do end do end do ! Root-only: this is a once-per-run init note, not per-rank state — on a ! multi-rank run it would otherwise print nranks identical copies. if (comm_env_rank() == 0) then call logger%info("ocean_layer_rho_init: wrote per-layer ρ directly, "// & "bypassing EOS init. ρ(k=1, bed) = "// & to_string(layer_rho_init(1))//" kg/m³, "// & "ρ(k="//to_string(nz_ml)//", surf) = "// & to_string(layer_rho_init(nz_ml))//" kg/m³.") end if if (present(ierr)) ierr = OCEAN_STATUS_OK end subroutine apply_layer_rho_init