fill_mld_density_impl Subroutine

private pure subroutine fill_mld_density_impl(h_layer, rho_layer, k_top, nz_ml, buf)

Per-column scan from the first LIVE layer (k_top, which is nz_ml unless a rigid top has vanished the layers above it) toward the bed; first layer whose ρ exceeds (surface ρ + MLD_DENSITY_THRESHOLD) marks the MLD as the cumulative h-sum above it. No crossing → MLD = full column depth. Threshold met at the surface itself → MLD = 0.

A vanished layer cannot mark the crossing: its rho_layer is the EOS’s reference-density substitution (rho_0), not the density of any water, so a filler bed layer would otherwise read as a pycnocline whenever rho_0 happens to exceed the surface density by the threshold. Its (sub-H_VANISHED) thickness still counts toward the depth, so a column with no crossing still reports its full depth.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: h_layer(:,:,:)
real(kind=wp), intent(in) :: rho_layer(:,:,:)
integer, intent(in) :: k_top(:,:)
integer, intent(in) :: nz_ml
real(kind=wp), intent(inout) :: buf(:,:,:)

Calls

proc~~fill_mld_density_impl~~CallsGraph proc~fill_mld_density_impl fill_mld_density_impl local local proc~fill_mld_density_impl->local rdb_vl_is_live rdb_vl_is_live proc~fill_mld_density_impl->rdb_vl_is_live

Called by

proc~~fill_mld_density_impl~~CalledByGraph proc~fill_mld_density_impl fill_mld_density_impl proc~fill_mld_density fill_mld_density proc~fill_mld_density->proc~fill_mld_density_impl

Variables

Type Visibility Attributes Name Initial
logical, private :: crossed
real(kind=wp), private :: d_acc
integer, private :: i
integer, private :: j
integer, private :: k
integer, private :: kt
real(kind=wp), private :: mld
integer, private :: nx
integer, private :: ny
real(kind=wp), private :: rho_surf

Source Code

   pure subroutine fill_mld_density_impl(h_layer, rho_layer, k_top, nz_ml, buf)
      !! Per-column scan from the first LIVE layer (`k_top`, which is
      !! `nz_ml` unless a rigid top has vanished the layers above it)
      !! toward the bed; first layer whose ρ exceeds (surface ρ +
      !! MLD_DENSITY_THRESHOLD) marks the MLD as the cumulative h-sum
      !! above it.  No crossing → MLD = full column depth.  Threshold met
      !! at the surface itself → MLD = 0.
      !!
      !! A vanished layer cannot mark the crossing: its `rho_layer` is the
      !! EOS's reference-density substitution (`rho_0`), not the density
      !! of any water, so a filler bed layer would otherwise read as a
      !! pycnocline whenever `rho_0` happens to exceed the surface density
      !! by the threshold.  Its (sub-`H_VANISHED`) thickness still counts
      !! toward the depth, so a column with no crossing still reports its
      !! full depth.
      ! assumed-shape-ok: diag fill — fires once per output frame (cadence-bounded).
      real(wp), intent(in)    :: h_layer(:, :, :), rho_layer(:, :, :)
      integer, intent(in)    :: k_top(:, :)  ! assumed-shape-ok: diag fill — cadence-bounded
      integer, intent(in)    :: nz_ml
      real(wp), intent(inout) :: buf(:, :, :)  ! assumed-shape-ok: diag fill — cadence-bounded
      integer :: i, j, k, kt, nx, ny
      real(wp) :: rho_surf, d_acc, mld
      logical :: crossed
      nx = min(size(buf, 1), size(rho_layer, 1))
      ny = min(size(buf, 2), size(rho_layer, 2))
      do concurrent(j=1:ny, i=1:nx) &
         local(rho_surf, d_acc, mld, crossed, k, kt)
         kt = k_top(i, j)
         rho_surf = rho_layer(i, j, kt)
         d_acc = 0.0_wp
         mld = 0.0_wp
         crossed = .false.
         do k = kt, 1, -1
            if (rdb_vl_is_live(h_layer(i, j, k)) .and. &
                rho_layer(i, j, k) - rho_surf >= MLD_DENSITY_THRESHOLD) then
               mld = d_acc
               crossed = .true.
               exit
            end if
            d_acc = d_acc + h_layer(i, j, k)
         end do
         if (.not. crossed) mld = d_acc
         buf(i, j, 1) = mld
      end do
   end subroutine fill_mld_density_impl