Linear-in-depth interpolation of source profile v_src on
ascending depths z_src onto target depths z_ctr, with
CONSTANT extrapolation beyond the source range. Comparisons in
depth space so index orientations never need reconciling.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | z_src(nz_src) | |||
| real(kind=wp), | intent(in) | :: | v_src(nz_src) | |||
| integer, | intent(in) | :: | nz_src | |||
| real(kind=wp), | intent(in) | :: | z_ctr(nz_ml) | |||
| integer, | intent(in) | :: | nz_ml | |||
| real(kind=wp), | intent(out) | :: | v_out(nz_ml) |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private | :: | k | ||||
| integer, | private | :: | m | ||||
| real(kind=wp), | private | :: | w | ||||
| real(kind=wp), | private | :: | zt |
pure subroutine interp_column_linear_z(z_src, v_src, nz_src, z_ctr, nz_ml, v_out) !! Linear-in-depth interpolation of source profile `v_src` on !! ascending depths `z_src` onto target depths `z_ctr`, with !! CONSTANT extrapolation beyond the source range. Comparisons in !! depth space so index orientations never need reconciling. integer, intent(in) :: nz_src, nz_ml real(wp), intent(in) :: z_src(nz_src), v_src(nz_src) real(wp), intent(in) :: z_ctr(nz_ml) real(wp), intent(out) :: v_out(nz_ml) integer :: k, m real(wp) :: zt, w do k = 1, nz_ml zt = z_ctr(k) if (zt <= z_src(1)) then ! Shallower than the shallowest source level — constant. v_out(k) = v_src(1) else if (zt >= z_src(nz_src)) then ! Deeper than the deepest source level — constant. v_out(k) = v_src(nz_src) else ! Locate the bracketing source levels [m, m+1] and lerp. do m = 1, nz_src - 1 if (zt >= z_src(m) .and. zt <= z_src(m + 1)) then w = (zt - z_src(m))/(z_src(m + 1) - z_src(m)) v_out(k) = (1.0_wp - w)*v_src(m) + w*v_src(m + 1) exit end if end do end if end do end subroutine interp_column_linear_z