pure subroutine ice_ist_to_cas_impl(wet_mask, part_size, m_ice, m_snow, mca_ice, mca_snow, &
nghost, ncat, nx, ny)
!! SIS2 `ice_state_to_cell_ave_state` (`:465`): `mca(c) =
!! part_size(c)*m(c)` per category, physical cells only. Ghost
!! cells are zeroed (never read as donors in the flux kernels below
!! — wet mirroring + wall zeroing exclude them).
integer, intent(in) :: nghost, ncat, nx, ny
real(wp), intent(in) :: wet_mask(nx, ny)
real(wp), intent(in) :: part_size(nx, ny, 0:ncat)
real(wp), intent(in) :: m_ice(nx, ny, ncat)
real(wp), intent(in) :: m_snow(nx, ny, ncat)
real(wp), intent(out) :: mca_ice(nx, ny, ncat)
real(wp), intent(out) :: mca_snow(nx, ny, ncat)
integer :: i, j, c, i_lo, i_hi, j_lo, j_hi
i_lo = nghost + 1
i_hi = nx - nghost
j_lo = nghost + 1
j_hi = ny - nghost
do concurrent(j=1:ny, i=1:nx, c=1:ncat)
mca_ice(i, j, c) = 0.0_wp
mca_snow(i, j, c) = 0.0_wp
end do
do concurrent(j=j_lo:j_hi, i=i_lo:i_hi, c=1:ncat)
if (wet_mask(i, j) > 0.5_wp) then
mca_ice(i, j, c) = part_size(i, j, c)*m_ice(i, j, c)
mca_snow(i, j, c) = part_size(i, j, c)*m_snow(i, j, c)
end if
end do
end subroutine ice_ist_to_cas_impl