pure subroutine chksum_argmax(arr, n1, n2, n3, i0, i1, j0, j1, im, jm, km, amax)
!! Interior argmax of |arr|: first-encountered strict maximum over
!! `i ∈ [i0, i1]`, `j ∈ [j0, j1]`, all k (the ghost ring is excluded
!! by the caller's bounds). Host-side (debug-window cadence only).
integer, intent(in) :: n1, n2, n3
real(wp), intent(in) :: arr(n1, n2, n3)
integer, intent(in) :: i0, i1, j0, j1
integer, intent(out) :: im, jm, km
real(wp), intent(out) :: amax
integer :: i, j, k
amax = -1.0_wp
im = 0
jm = 0
km = 0
do k = 1, n3
do j = j0, j1
do i = i0, i1
if (abs(arr(i, j, k)) > amax) then
amax = abs(arr(i, j, k))
im = i
jm = j
km = k
end if
end do
end do
end do
end subroutine chksum_argmax