subroutine chksum_state(grid, ms, probe, label, stage, step)
!! Sample the prognostics (h, u, v, every tracer) at a phase seam. Call
!! AFTER the phase named by `label`; drains device queues first so
!! the async apply chain has landed. Bounds come from the
!! location-aware API (LOC_H / LOC_U / LOC_V), not hand-written.
type(hgrid_t), intent(in) :: grid
type(multilayer_state_t), intent(in) :: ms
type(chksum_probe_t), intent(inout) :: probe
character(len=*), intent(in) :: label
integer, intent(in) :: stage, step
integer :: it
character(len=16) :: tname
if (.not. chksum_active(probe, step)) return
!$acc wait
call rdb_debug_chksum(grid, ms%h_layer, label, "h_layer", stage, step, probe, LOC_H)
call rdb_debug_chksum(grid, ms%u_face_x_layer, label, "u_face", stage, step, probe, LOC_U)
call rdb_debug_chksum(grid, ms%v_face_y_layer, label, "v_face", stage, step, probe, LOC_V)
! Every registered tracer (thickness-weighted content), named by its
! registry slot.
if (allocated(ms%tracers)) then
do it = 1, size(ms%tracers)
if (.not. allocated(ms%tracers(it)%hTr)) cycle
write (tname, "(a,i0)") "hTr_", it
call rdb_debug_chksum(grid, ms%tracers(it)%hTr, label, trim(tname), stage, step, &
probe, LOC_H)
end do
end if
end subroutine chksum_state