pure function hk_corner_h(ic, jc, k, nx, ny, nz, h, wet_T, areaT) result(hc)
!$acc routine seq
!! Corner thickness of the HK PV, recomputed with EXACTLY the Pass 2
!! formula of `coriolis_adv_compute_tendencies_hk` (wet-area-weighted
!! 4-cell mean, array-edge clamps, `CORIOLIS_H_MIN_PV` floor), so the
!! closed-face branch knows the `h_corner` each stored `q` was divided
!! by without a persistent buffer.
integer, intent(in) :: ic, jc, k, nx, ny, nz
real(wp), intent(in) :: h(nx, ny, nz)
real(wp), intent(in) :: wet_T(nx, ny), areaT(nx, ny)
real(wp) :: hc
integer :: iw, ie, js, jn
real(wp) :: aSW, aSE, aNW, aNE, hm_num, hm_den
iw = max(1, ic - 1)
ie = min(nx, ic)
js = max(1, jc - 1)
jn = min(ny, jc)
aSW = wet_T(iw, js)*areaT(iw, js)
aSE = wet_T(ie, js)*areaT(ie, js)
aNW = wet_T(iw, jn)*areaT(iw, jn)
aNE = wet_T(ie, jn)*areaT(ie, jn)
hm_num = aSW*h(iw, js, k) + aSE*h(ie, js, k) + &
aNW*h(iw, jn, k) + aNE*h(ie, jn, k)
hm_den = aSW + aSE + aNW + aNE
hc = hm_num/max(hm_den, H_DIV_EPS)
hc = max(hc, CORIOLIS_H_MIN_PV)
end function hk_corner_h