subroutine rdb_debug_chksum_3d(grid, arr, label, field, stage, step, probe, loc)
!! Location-aware 3D checksum: derives `(nx, ny)` from `grid` + `loc`
!! and `nz` from the array, so a new instrumentation site is one
!! line with no hand-written bounds. Gated by the probe window.
type(hgrid_t), intent(in) :: grid
real(wp), intent(in) :: arr(:, :, :)
! assumed-shape-ok: no device loop here; forwards a contiguous
! actual to the explicit-shape chksum_stats_3d kernel.
character(len=*), intent(in) :: label, field
integer, intent(in) :: stage, step, loc
type(chksum_probe_t), intent(inout) :: probe
integer :: nx, ny, nz, ia, ib, ja, jb
type(chksum_stats_t) :: st
if (.not. chksum_active(probe, step)) return
call chksum_loc_extents(grid, loc, nx, ny)
nz = size(arr, 3)
if (probe%interior) then
call chksum_loc_interior(grid, loc, ia, ib, ja, jb)
call chksum_stats_3d(arr, nx, ny, nz, st, ia, ib, ja, jb)
else
call chksum_stats_3d(arr, nx, ny, nz, st)
end if
call chksum_row(probe, label, stage, step, field, st)
end subroutine rdb_debug_chksum_3d