pure subroutine cavity_scale_impl(src, active, scale, buf)
!! `cavity_mask_impl` with a constant multiplier folded in.
! assumed-shape-ok: diag fill — fires once per output frame (cadence-bounded).
real(wp), intent(in) :: src(:, :) ! assumed-shape-ok: diag fill — cadence-bounded
real(wp), intent(in) :: active(:, :) ! assumed-shape-ok: diag fill — cadence-bounded
real(wp), intent(in) :: scale
real(wp), intent(inout) :: buf(:, :, :) ! assumed-shape-ok: diag fill — cadence-bounded
integer :: i, j, nx, ny
real(wp) :: qnan
nx = min(size(buf, 1), size(src, 1), size(active, 1))
ny = min(size(buf, 2), size(src, 2), size(active, 2))
qnan = ieee_value(0.0_wp, ieee_quiet_nan)
do concurrent(j=1:ny, i=1:nx)
if (active(i, j) > 0.5_wp) then
buf(i, j, 1) = scale*src(i, j)
else
buf(i, j, 1) = qnan
end if
end do
end subroutine cavity_scale_impl