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