pure subroutine refill_h_ghost_scaled(h_layer, bt_H_ref, nx_total, ny_total, nz, &
i_w, i_e, j_s, j_n, nghost, &
bc_w, bc_e, bc_s, bc_n)
!! Overwrite open-edge h_layer ghost columns with the nearest interior
!! column scaled so `Σ_k h_ghost = bt_H_ref(ghost) + η_interior`
!! (η_interior = `Σ_k h_int − bt_H_ref(int)`). x-pass (west/east) over
!! the full j extent (covers corner rows); y-pass (south/north) over the
!! full i extent, reading the already x-filled corner columns — same
!! corner-coverage order as `fill_h_layer_ghosts`.
integer, intent(in) :: nx_total, ny_total, nz, nghost
real(wp), intent(inout) :: h_layer(nx_total, ny_total, nz)
real(wp), intent(in) :: bt_H_ref(nx_total, ny_total)
integer, intent(in) :: i_w, i_e, j_s, j_n
integer, intent(in) :: bc_w, bc_e, bc_s, bc_n
integer :: i, j, k, g
real(wp) :: sh_int, eta_ref, sc
! West ghosts
if (is_open_ish(bc_w)) then
do concurrent(j=1:ny_total, g=1:nghost) local(k, sh_int, eta_ref, sc)
sh_int = 0.0_wp
do k = 1, nz
sh_int = sh_int + h_layer(i_w, j, k)
end do
eta_ref = sh_int - bt_H_ref(i_w, j)
sc = (bt_H_ref(g, j) + eta_ref)/max(sh_int, H_VANISHED)
do k = 1, nz
h_layer(g, j, k) = h_layer(i_w, j, k)*sc
end do
end do
end if
! East ghosts
if (is_open_ish(bc_e)) then
do concurrent(j=1:ny_total, g=1:nghost) local(k, sh_int, eta_ref, sc)
sh_int = 0.0_wp
do k = 1, nz
sh_int = sh_int + h_layer(i_e, j, k)
end do
eta_ref = sh_int - bt_H_ref(i_e, j)
sc = (bt_H_ref(nx_total - g + 1, j) + eta_ref)/max(sh_int, H_VANISHED)
do k = 1, nz
h_layer(nx_total - g + 1, j, k) = h_layer(i_e, j, k)*sc
end do
end do
end if
! South ghosts (read the x-filled corner columns)
if (is_open_ish(bc_s)) then
do concurrent(i=1:nx_total, g=1:nghost) local(k, sh_int, eta_ref, sc)
sh_int = 0.0_wp
do k = 1, nz
sh_int = sh_int + h_layer(i, j_s, k)
end do
eta_ref = sh_int - bt_H_ref(i, j_s)
sc = (bt_H_ref(i, g) + eta_ref)/max(sh_int, H_VANISHED)
do k = 1, nz
h_layer(i, g, k) = h_layer(i, j_s, k)*sc
end do
end do
end if
! North ghosts (read the x-filled corner columns)
if (is_open_ish(bc_n)) then
do concurrent(i=1:nx_total, g=1:nghost) local(k, sh_int, eta_ref, sc)
sh_int = 0.0_wp
do k = 1, nz
sh_int = sh_int + h_layer(i, j_n, k)
end do
eta_ref = sh_int - bt_H_ref(i, j_n)
sc = (bt_H_ref(i, ny_total - g + 1) + eta_ref)/max(sh_int, H_VANISHED)
do k = 1, nz
h_layer(i, ny_total - g + 1, k) = h_layer(i, j_n, k)*sc
end do
end do
end if
end subroutine refill_h_ghost_scaled