pure subroutine ice_validity_reduce_impl(mca_ice, mca_snow, nghost, nx_phys, ny_phys, &
ncat, nx, ny, ok)
!! `ok = .false.` when `min(mca_ice) < 0`, `min(mca_snow) < 0`, or
!! an "orphan snow" cell exists (`mca_snow > 0` where `mca_ice <= 0`
!! by more than `H_NEGLECT_ICE_TRANSPORT`) — SIS2 FATALs on any of
!! these; ported as a post-pass reduction (GPU-safe fail-loud, D7)
!! rather than an in-loop abort. Physical cells only.
integer, intent(in) :: nghost, nx_phys, ny_phys, ncat, nx, ny
real(wp), intent(in) :: mca_ice(nx, ny, ncat)
real(wp), intent(in) :: mca_snow(nx, ny, ncat)
logical, intent(out) :: ok
integer :: i, j, c, i_lo, i_hi, j_lo, j_hi
real(wp) :: min_ice, min_snow, max_orphan
i_lo = nghost + 1
i_hi = nghost + nx_phys
j_lo = nghost + 1
j_hi = nghost + ny_phys
min_ice = 0.0_wp
min_snow = 0.0_wp
max_orphan = 0.0_wp
do concurrent(c=1:ncat, j=j_lo:j_hi, i=i_lo:i_hi) reduce(min:min_ice, min_snow)
min_ice = min(min_ice, mca_ice(i, j, c))
min_snow = min(min_snow, mca_snow(i, j, c))
end do
do concurrent(c=1:ncat, j=j_lo:j_hi, i=i_lo:i_hi) reduce(max:max_orphan)
if (mca_ice(i, j, c) <= 0.0_wp) then
max_orphan = max(max_orphan, mca_snow(i, j, c))
end if
end do
ok = (min_ice >= 0.0_wp) .and. (min_snow >= 0.0_wp) &
.and. (max_orphan <= H_NEGLECT_ICE_TRANSPORT)
end subroutine ice_validity_reduce_impl