interp_column_linear_z Subroutine

public 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.

Arguments

Type IntentOptional 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)

Called by

proc~~interp_column_linear_z~~CalledByGraph proc~interp_column_linear_z interp_column_linear_z proc~seed_ts_from_zfile seed_ts_from_zfile proc~seed_ts_from_zfile->proc~interp_column_linear_z proc~seed_zinit_overlay seed_zinit_overlay proc~seed_zinit_overlay->proc~seed_ts_from_zfile proc~ocean_state_seed_from_cfg ocean_state_seed_from_cfg proc~ocean_state_seed_from_cfg->proc~seed_zinit_overlay proc~engine_setup engine_setup proc~engine_setup->proc~ocean_state_seed_from_cfg proc~complete_ocean_create complete_ocean_create proc~complete_ocean_create->proc~engine_setup proc~driver_run_ocean driver_run_ocean proc~driver_run_ocean->proc~engine_setup proc~driver_validate driver_validate proc~driver_validate->proc~engine_setup

Variables

Type Visibility Attributes Name Initial
integer, private :: k
integer, private :: m
real(kind=wp), private :: w
real(kind=wp), private :: zt

Source Code

   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