pure subroutine evp_zero_massless_velocity_impl(mask_u, mask_v, mis, ui, vi, nx, ny)
!! SIS2 :899-907 — zero ice velocities where BOTH neighbouring
!! cells are massless (or the face is masked/land).
integer, intent(in) :: nx, ny
real(wp), intent(in) :: mask_u(nx + 1, ny)
real(wp), intent(in) :: mask_v(nx, ny + 1)
real(wp), intent(in) :: mis(nx, ny)
real(wp), intent(inout) :: ui(nx + 1, ny)
real(wp), intent(inout) :: vi(nx, ny + 1)
integer :: i, j
real(wp) :: mleft, mright
! F2: explicit `if` branches — `merge(mis(i-1,j), 0, i>1)` would
! still EVALUATE the OOB `mis(0,j)` reference at i=1 (merge does not
! conditionally evaluate its args), which is UB and traps under
! -Mbounds. Guard the read itself (mirrors `evp_mi_face_impl`).
do concurrent(j=1:ny, i=1:nx + 1) local(mleft, mright)
if (i > 1) then
mleft = mis(i - 1, j)
else
mleft = 0.0_wp
end if
if (i <= nx) then
mright = mis(i, j)
else
mright = 0.0_wp
end if
if (mask_u(i, j)*(mleft + mright) == 0.0_wp) ui(i, j) = 0.0_wp
end do
do concurrent(j=1:ny + 1, i=1:nx) local(mleft, mright)
if (j > 1) then
mleft = mis(i, j - 1)
else
mleft = 0.0_wp
end if
if (j <= ny) then
mright = mis(i, j)
else
mright = 0.0_wp
end if
if (mask_v(i, j)*(mleft + mright) == 0.0_wp) vi(i, j) = 0.0_wp
end do
end subroutine evp_zero_massless_velocity_impl