OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
spline_module.f90
Go to the documentation of this file.
2 
4  implicit none
5 
6 contains
7 
8 SUBROUTINE spline(n, x,y,y2)
9  IMPLICIT NONE
10  REAL(single), DIMENSION(n), INTENT(IN) :: x,y
11  REAL(single), DIMENSION(n), INTENT(OUT) :: y2
12  INTEGER(integer_fourbyte), intent(in) :: n
13  REAL(single) :: yp1,ypn
14  REAL(single), DIMENSION(size(x)) :: a,b,c,r
15 
16  yp1 = 9999.
17  ypn = 9999.
18 
19  c(1:n-1)=x(2:n)-x(1:n-1)
20  r(1:n-1)=6.0_single*((y(2:n)-y(1:n-1))/c(1:n-1))
21  r(2:n-1)=r(2:n-1)-r(1:n-2)
22  a(2:n-1)=c(1:n-2)
23  b(2:n-1)=2.0_single*(c(2:n-1)+a(2:n-1))
24  b(1)=1.0
25  b(n)=1.0
26  if (yp1 > 999.) then
27  r(1)=0.0
28  c(1)=0.0
29  else
30  r(1)=(3.0_single/(x(2)-x(1)))*((y(2)-y(1))/(x(2)-x(1))-yp1)
31  c(1)=0.5
32  end if
33  if (ypn > 999.) then
34  r(n)=0.0
35  a(n)=0.0
36  else
37  r(n)=(-3.0_single/(x(n)-x(n-1)))*((y(n)-y(n-1))/(x(n)-x(n-1))-ypn)
38  a(n)=0.5
39  end if
40  call tridag(a(2:n),b(1:n),c(1:n-1),r(1:n),y2(1:n),n)
41 
42 
43 END SUBROUTINE spline
44 
45 
46 FUNCTION splint(n,x,xa,ya,y2a)
48  IMPLICIT NONE
49  INTEGER(integer_fourbyte), intent(in) :: n
50  REAL(single), DIMENSION(:), INTENT(IN) :: xa,ya,y2a
51  REAL(single), INTENT(IN) :: x
52  REAL(single) :: splint
53  INTEGER(integer_fourbyte) :: khi,klo
54  REAL(double) :: a,b,h, temp_1, temp_2, temp_3
55 
56  klo=max(min(locate(xa,x),n-1),1)
57  khi=klo+1
58 
59  h=xa(khi)-xa(klo)
60 
61  a=(xa(khi)-x)/h
62  b=(x-xa(klo))/h
63 
64  splint=a*ya(klo)+b*ya(khi)+((a**3-a)*y2a(klo)+(b**3-b)*y2a(khi))*(h**2)/6.0_single
65 END FUNCTION splint
66 
67 FUNCTION locate(xx,x)
69  IMPLICIT NONE
70  REAL(single), DIMENSION(:), INTENT(IN) :: xx
71  REAL(single), INTENT(IN) :: x
72  INTEGER(integer_fourbyte) :: locate
73  INTEGER(integer_fourbyte) :: n,jl,jm,ju
74  LOGICAL :: ascnd
75  n=size(xx)
76  ascnd = (xx(n) >= xx(1))
77  jl=0
78  ju=n+1
79  do
80  if (ju-jl <= 1) exit
81  jm=(ju+jl)/2
82  if (ascnd .eqv. (x >= xx(jm))) then
83  jl=jm
84  else
85  ju=jm
86  end if
87  end do
88 
89  if (realsingle_s_equal(x,xx(1))) then
90  locate=1
91  else if (realsingle_s_equal(x,xx(n))) then
92  locate=n-1
93  else
94  locate=jl
95  end if
96 END FUNCTION locate
97 
98 SUBROUTINE tridag(a,b,c,r,u,size)
100  IMPLICIT NONE
101  integer(integer_fourbyte), intent(in) :: size
102  REAL(single), INTENT(IN) :: a(size-1),b(size),c(size-1),r(size)
103  REAL(single), INTENT(OUT) :: u(size)
104  REAL(single) :: gam(size)
105  INTEGER(integer_fourbyte) :: n,j
106  REAL(single) :: bet
107 
108  n=size
109  bet=b(1)
110 
111  u(1)=r(1)/bet
112 
113  do j=2,n
114  gam(j)=c(j-1)/bet
115  bet=b(j)-a(j-1)*gam(j)
116  u(j)=(r(j)-a(j-1)*u(j-1))/bet
117  end do
118 
119  do j=n-1,1,-1
120  u(j)=u(j)-gam(j+1)*u(j+1)
121  end do
122  END SUBROUTINE tridag
123 
124 end module spline_module
subroutine spline(s, x, y, n, in, t, il, iu, vl, vu, e, u)
Definition: phs.f:1348
integer, parameter single
#define max(A, B)
Definition: main_biosmap.c:61
integer, parameter double
void tridag(float a[], float b[], float c[], float r[], float u[], unsigned long n)
#define min(A, B)
Definition: main_biosmap.c:62
subroutine locate(xx, n, x, j)
subroutine splint(xa, ya, y2a, n, x, y)
logical function realsingle_s_equal(x, y)
integer, parameter integer_fourbyte