pure subroutine cavity_mask_impl(src, active, buf)
!! Copy a 2-D cavity field into the diag buffer, writing IEEE NaN
!! wherever the column was not solved. Every cavity fill that is
!! a plain read of a slot array routes through here, so the
!! missing-value convention cannot drift between them.
! 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(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))
! Sentinel computed once on the HOST before the device loop —
! `ieee_value` is a host intrinsic (the `fill_tracer_impl` pattern).
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) = src(i, j)
else
buf(i, j, 1) = qnan
end if
end do
end subroutine cavity_mask_impl