pure subroutine ocean_slopes_build_e(nx, ny, nz, bathy, h_layer, e_int)
!! Build GEOPOTENTIAL interface heights bottom-up: `e_int(:,:,1) =
!! −bathy` (the bed, below the `z = 0` datum),
!! `e_int(:,:,K+1) = e_int(:,:,K) + h_layer(:,:,K)`. A per-column
!! serial cumulative sum (parallel over i,j). The across-face
!! difference `e_W − e_E` feeds the interface-tilt term, so the bed
!! datum is NOT irrelevant: it must be the true bed depth, or a
!! bathymetry step reads as an isopycnal slope.
integer, intent(in) :: nx, ny, nz
real(wp), intent(in) :: bathy(nx, ny)
real(wp), intent(in) :: h_layer(nx, ny, nz)
real(wp), intent(out) :: e_int(nx, ny, nz + 1)
integer :: i, j, k
do concurrent(j=1:ny, i=1:nx)
e_int(i, j, 1) = -bathy(i, j)
do k = 1, nz
e_int(i, j, k + 1) = e_int(i, j, k) + h_layer(i, j, k)
end do
end do
end subroutine ocean_slopes_build_e