V3FIT
All Classes Namespaces Files Functions Variables Enumerations Macros Pages
splint.f
1  SUBROUTINE splint(xa, ya, y2a, n, x, y)
2  USE stel_kinds
3  IMPLICIT NONE
4 C-----------------------------------------------
5 C D u m m y A r g u m e n t s
6 C-----------------------------------------------
7  INTEGER :: n
8  REAL(rprec) :: xa(n), ya(n), y2a(n), x, y
9 C-----------------------------------------------
10 C L o c a l P a r a m e t e r s
11 C-----------------------------------------------
12  REAL(rprec), PARAMETER :: zero = 0, c1o6 = 1._dp/6._dp
13 C-----------------------------------------------
14 C L o c a l V a r i a b l e s
15 C-----------------------------------------------
16  INTEGER :: klo, khi, i, k
17  REAL(rprec) :: h, a, a2, b, b2, h2, y26lo, y26hi
18 C-----------------------------------------------
19 !
20 ! SPLINE INTERPOLATION ROUTINE (Numerical Recipes, pg. 89)
21 ! XA: ordered array of length N of ordinates at which function YA=F(XA)
22 ! is tabulated
23 ! YA: array of length N , = F(XA)
24 ! Y2A: array of second derivatives at XA points
25 ! computed from call to SPLINE
26 ! X : value at which Y = F(X) is to be computed from splines
27 ! YP = dY/dX at X
28 ! NDIM: dimension of X, Y, YP arrays
29 
30 
31  klo = 1
32  khi = n
33  DO WHILE(khi - klo .gt. 1)
34  k = (khi + klo)/2
35  IF (xa(k) .gt. x) THEN
36  khi = k
37  ELSE
38  klo = k
39  ENDIF
40  END DO
41 
42  h = xa(khi) - xa(klo)
43  a = xa(khi) - x
44  b = x - xa(klo)
45  h2 = h*h
46  a2 = a*a
47  b2 = b*b
48  y26lo = c1o6*y2a(klo)
49  y26hi = c1o6*y2a(khi)
50  y = (a*(ya(klo)+(a2-h2)*y26lo)+b*(ya(khi)+(b2-h2)*y26hi))/h
51 
52  END SUBROUTINE splint