pure subroutine remap_tracer_grounded(nx, ny, nz, h_old, h_new, mask, hTr)
!! Conservative tracer remap gated on the grounded mask. Non-grounded
!! columns are skipped -> hTr byte-unchanged; the concentration
!! divisions only happen on grounded columns.
integer, intent(in) :: nx, ny, nz
real(wp), intent(in) :: h_old(nx, ny, nz)
real(wp), intent(in) :: h_new(nx, ny, nz)
real(wp), intent(in) :: mask(nx, ny, 1)
real(wp), intent(inout) :: hTr(nx, ny, nz)
integer :: i, j, k
real(wp) :: h_old_col(NZ_STACK_MAX), h_new_col(NZ_STACK_MAX)
real(wp) :: c_old(NZ_STACK_MAX), c_new(NZ_STACK_MAX)
do concurrent(j=1:ny, i=1:nx) &
local(k, h_old_col, h_new_col, c_old, c_new)
if (mask(i, j, 1) > 0.5_wp) then
do k = 1, nz
h_old_col(k) = h_old(i, j, k)
h_new_col(k) = h_new(i, j, k)
if (h_old_col(k) > H_CONC_FLOOR) then
c_old(k) = hTr(i, j, k)/h_old_col(k)
else
c_old(k) = 0.0_wp
end if
end do
call remap_column(REMAP_PPM, nz, h_old_col(1:nz), h_new_col(1:nz), &
c_old(1:nz), c_new(1:nz))
do k = 1, nz
hTr(i, j, k) = c_new(k)*h_new_col(k)
end do
end if
end do
end subroutine remap_tracer_grounded