FV3 Bundle
gsw_linear_interp_sa_ct.f90
Go to the documentation of this file.
1 !==========================================================================
2 pure subroutine gsw_linear_interp_sa_ct (sa, ct, p, p_i, sa_i, ct_i)
3 !==========================================================================
4 ! This function interpolates the cast with respect to the interpolating
5 ! variable p. This function finds the values of SA, CT at p_i on this cast.
6 !
7 ! Assumes that p is monotonically increasing. If p_i is also monotonically
8 ! increasing then this function is even more efficient through the use of
9 ! kstart option to function gsw_util_indx (G.B.Hyland 10/8/2017).
10 !==========================================================================
11 
13 
14 use gsw_mod_kinds
15 
16 implicit none
17 
18 real (r8), intent(in) :: sa(:), ct(:), p(:), p_i(:)
19 real (r8), intent(out) :: sa_i(:), ct_i(:)
20 
21 integer :: i, k, np
22 real (r8) :: r
23 
24 np = size(p)
25 
26 k = 1
27 do i = 1, size(p_i)
28 
29  if (p_i(i) .le. p(1)) then
30 
31  sa_i(i) = sa(1)
32  ct_i(i) = ct(1)
33 
34  else if (p_i(i) .ge. p(np)) then
35 
36  sa_i(i) = sa(np)
37  ct_i(i) = ct(np)
38 
39  else
40 
41  if (i .gt. 1) then
42  if (p_i(i) .lt. p_i(i-1)) k = 1
43  end if
44  k = gsw_util_indx(p,p_i(i),kstart=k)
45 
46  r = (p_i(i)-p(k))/(p(k+1)-p(k))
47  sa_i(i) = sa(k) + r*(sa(k+1)-sa(k))
48  ct_i(i) = ct(k) + r*(ct(k+1)-ct(k))
49 
50  end if
51 end do
52 
53 return
54 
55 end subroutine
56 
57 !--------------------------------------------------------------------------
pure subroutine gsw_linear_interp_sa_ct(sa, ct, p, p_i, sa_i, ct_i)