pure subroutine scan_vanished_one_impl(nx, ny, nz, h_layer, hTr, n_bad, worst)
!! Flat-impl of the I1′ scan for ONE tracer. Per column: find the
!! topmost live layer, then walk DOWN carrying the nearest live layer
!! above — the donor map `rdb_vl_merge_content` / `rdb_vl_column_conc`
!! use — and test each filler against its donor's `hTr/h`.
integer, intent(in) :: nx, ny, nz
real(wp), intent(in) :: h_layer(nx, ny, nz)
real(wp), intent(in) :: hTr(nx, ny, nz)
integer, intent(out) :: n_bad
real(wp), intent(out) :: worst
integer :: i, j, k, k_top, k_don
real(wp) :: c_live
n_bad = 0
worst = 0.0_wp
! No explicit data clause: nvfortran emits `implicit copyin(...) [if not
! already present]`, which is a no-op for the production state (mapped by
! `enter_data`) and still correct for a host-only unit test. `present(...)`
! here would make the test abort with a present-table lookup failure.
!$acc parallel loop collapse(2) private(k, k_top, k_don, c_live) &
!$acc reduction(+:n_bad) reduction(max:worst)
do j = 1, ny
do i = 1, nx
k_top = 0
!$acc loop seq
do k = nz, 1, -1
if (rdb_vl_is_live(h_layer(i, j, k))) then
k_top = k
exit
end if
end do
k_don = k_top
!$acc loop seq
do k = nz, 1, -1
if (rdb_vl_is_live(h_layer(i, j, k))) then
k_don = k
else
c_live = 0.0_wp
if (k_don > 0) c_live = hTr(i, j, k_don)/h_layer(i, j, k_don)
if (.not. rdb_vl_holds_live_conc(hTr(i, j, k), h_layer(i, j, k), c_live)) then
n_bad = n_bad + 1
worst = max(worst, abs(hTr(i, j, k) - h_layer(i, j, k)*c_live))
end if
end if
end do
end do
end do
end subroutine scan_vanished_one_impl