gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
cubspl.f
Go to the documentation of this file.
1  subroutine cubspl ( tau, c, n, ibcbeg, ibcend )
2 
3 c*********************************************************************72
4 c
5 cc CUBSPL defines an interpolatory cubic spline.
6 c
7 c from * a practical guide to splines * by c. de boor
8 c ************************ input ***************************
9 c n = number of data points. assumed to be .ge. 2.
10 c (tau(i), c(1,i), i=1,...,n) = abscissae and ordinates of the
11 c data points. tau is assumed to be strictly increasing.
12 c ibcbeg, ibcend = boundary condition indicators, and
13 c c(2,1), c(2,n) = boundary condition information. specifically,
14 c ibcbeg = 0 means no boundary condition at tau(1) is given.
15 c in this case, the not-a-knot condition is used, i.e. the
16 c jump in the third derivative across tau(2) is forced to
17 c zero, thus the first and the second cubic polynomial pieces
18 c are made to coincide.)
19 c ibcbeg = 1 means that the slope at tau(1) is made to equal
20 c c(2,1), supplied by input.
21 c ibcbeg = 2 means that the second derivative at tau(1) is
22 c made to equal c(2,1), supplied by input.
23 c ibcend = 0, 1, or 2 has analogous meaning concerning the
24 c boundary condition at tau(n), with the additional infor-
25 c mation taken from c(2,n).
26 c *********************** output **************************
27 c c(j,i), j=1,...,4; i=1,...,l (= n-1) = the polynomial coefficients
28 c of the cubic interpolating spline with interior knots (or
29 c joints) tau(2), ..., tau(n-1). precisely, in the interval
30 c (tau(i), tau(i+1)), the spline f is given by
31 c f(x) = c(1,i)+h*(c(2,i)+h*(c(3,i)+h*c(4,i)/3.)/2.)
32 c where h = x - tau(i). the function program *ppvalu* may be
33 c used to evaluate f or its derivatives from tau,c, l = n-1,
34 c and k=4.
35 c
36  implicit none
37 
38  integer ibcbeg,ibcend,n, i,j,l,m
39  double precision c(4,n),tau(n), divdf1,divdf3,dtau,g
40 c****** a tridiagonal linear system for the unknown slopes s(i) of
41 c f at tau(i), i=1,...,n, is generated and then solved by gauss elim-
42 c ination, with s(i) ending up in c(2,i), all i.
43 c c(3,.) and c(4,.) are used initially for temporary storage.
44  l = n-1
45 compute first differences of tau sequence and store in c(3,.). also,
46 compute first divided difference of data and store in c(4,.).
47  do 10 m=2,n
48  c(3,m) = tau(m) - tau(m-1)
49  10 c(4,m) = (c(1,m) - c(1,m-1))/c(3,m)
50 construct first equation from the boundary condition, of the form
51 c c(4,1)*s(1) + c(3,1)*s(2) = c(2,1)
52  if (ibcbeg-1) 11,15,16
53  11 if (n .gt. 2) go to 12
54 c no condition at left end and n = 2.
55  c(4,1) = 1.0d+00
56  c(3,1) = 1.0d+00
57  c(2,1) = 2.0d+00*c(4,2)
58  go to 25
59 c not-a-knot condition at left end and n .gt. 2.
60  12 c(4,1) = c(3,3)
61  c(3,1) = c(3,2) + c(3,3)
62  c(2,1) =((c(3,2)+2.0d+00*c(3,1))*c(4,2)*c(3,3)
63  & +c(3,2)**2*c(4,3))/c(3,1)
64  go to 19
65 c slope prescribed at left end.
66  15 c(4,1) = 1.0d+00
67  c(3,1) = 0.0d+00
68  go to 18
69 c second derivative prescribed at left end.
70  16 c(4,1) = 2.0d+00
71  c(3,1) = 1.0d+00
72  c(2,1) = 3.0d+00*c(4,2) - c(3,2)/2.0d+00*c(2,1)
73  18 if(n .eq. 2) go to 25
74 c if there are interior knots, generate the corresp. equations and car-
75 c ry out the forward pass of gauss elimination, after which the m-th
76 c equation reads c(4,m)*s(m) + c(3,m)*s(m+1) = c(2,m).
77  19 do 20 m=2,l
78  g = -c(3,m+1)/c(4,m-1)
79  c(2,m) = g*c(2,m-1) + 3.0d+00*(c(3,m)*c(4,m+1)+c(3,m+1)*c(4,m))
80  20 c(4,m) = g*c(3,m-1) + 2.0d+00*(c(3,m) + c(3,m+1))
81 construct last equation from the second boundary condition, of the form
82 c (-g*c(4,n-1))*s(n-1) + c(4,n)*s(n) = c(2,n)
83 c if slope is prescribed at right end, one can go directly to back-
84 c substitution, since c array happens to be set up just right for it
85 c at this point.
86  if (ibcend-1) 21,30,24
87  21 if (n .eq. 3 .and. ibcbeg .eq. 0) go to 22
88 c not-a-knot and n .ge. 3, and either n.gt.3 or also not-a-knot at
89 c left end point.
90  g = c(3,n-1) + c(3,n)
91  c(2,n) = ((c(3,n)+2.0d+00*g)*c(4,n)*c(3,n-1)
92  * + c(3,n)**2*(c(1,n-1)-c(1,n-2))/c(3,n-1))/g
93  g = -g/c(4,n-1)
94  c(4,n) = c(3,n-1)
95  go to 29
96 c either (n=3 and not-a-knot also at left) or (n=2 and not not-a-
97 c knot at left end point).
98  22 c(2,n) = 2.0d+00*c(4,n)
99  c(4,n) = 1.0d+00
100  go to 28
101 c second derivative prescribed at right endpoint.
102  24 c(2,n) = 3.0d+00*c(4,n) + c(3,n)/2.0d+00*c(2,n)
103  c(4,n) = 2.0d+00
104  go to 28
105  25 if (ibcend-1) 26,30,24
106  26 if (ibcbeg .gt. 0) go to 22
107 c not-a-knot at right endpoint and at left endpoint and n = 2.
108  c(2,n) = c(4,n)
109  go to 30
110  28 g = -1.0d+00/c(4,n-1)
111 complete forward pass of gauss elimination.
112  29 c(4,n) = g*c(3,n-1) + c(4,n)
113  c(2,n) = (g*c(2,n-1) + c(2,n))/c(4,n)
114 carry out back substitution
115  30 j = l
116  40 c(2,j) = (c(2,j) - c(3,j)*c(2,j+1))/c(4,j)
117  j = j - 1
118  if (j .gt. 0) go to 40
119 c****** generate cubic coefficients in each interval, i.e., the deriv.s
120 c at its left endpoint, from value and slope at its endpoints.
121  do 50 i=2,n
122  dtau = c(3,i)
123  divdf1 = (c(1,i) - c(1,i-1))/dtau
124  divdf3 = c(2,i-1) + c(2,i) - 2.0d+00*divdf1
125  c(3,i-1) = 2.0d+00*(divdf1 - c(2,i-1) - divdf3)/dtau
126  50 c(4,i-1) = (divdf3/dtau)*(6.0d+00/dtau)
127  return
128  end
subroutine cubspl(tau, c, n, ibcbeg, ibcend)
Definition: cubspl.f:2
gtkIOStream: /tmp/gtkiostream/src/deBoor/cubspl.f Source File
GTK+ IOStream  Beta