apply_layer_rho_init Subroutine

public 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).

Arguments

Type IntentOptional 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 nz_ml, when present; absent behaves as today (error stop).


Calls

proc~~apply_layer_rho_init~~CallsGraph proc~apply_layer_rho_init apply_layer_rho_init info info proc~apply_layer_rho_init->info proc~comm_env_rank comm_env_rank proc~apply_layer_rho_init->proc~comm_env_rank proc~fail fail proc~apply_layer_rho_init->proc~fail to_string to_string proc~apply_layer_rho_init->to_string error error proc~fail->error proc~error_ring_push error_ring_push proc~fail->proc~error_ring_push

Called by

proc~~apply_layer_rho_init~~CalledByGraph proc~apply_layer_rho_init apply_layer_rho_init proc~ocean_state_seed_from_cfg ocean_state_seed_from_cfg proc~ocean_state_seed_from_cfg->proc~apply_layer_rho_init proc~engine_setup engine_setup proc~engine_setup->proc~ocean_state_seed_from_cfg 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 :: i
integer, private :: j
integer, private :: k
integer, private :: n_set

Source Code

   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