dbintk.f 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. *DECK DBINTK
  2. SUBROUTINE DBINTK (X, Y, T, N, K, BCOEF, Q, WORK)
  3. C***BEGIN PROLOGUE DBINTK
  4. C***PURPOSE Compute the B-representation of a spline which interpolates
  5. C given data.
  6. C***LIBRARY SLATEC
  7. C***CATEGORY E1A
  8. C***TYPE DOUBLE PRECISION (BINTK-S, DBINTK-D)
  9. C***KEYWORDS B-SPLINE, DATA FITTING, INTERPOLATION
  10. C***AUTHOR Amos, D. E., (SNLA)
  11. C***DESCRIPTION
  12. C
  13. C Written by Carl de Boor and modified by D. E. Amos
  14. C
  15. C Abstract **** a double precision routine ****
  16. C
  17. C DBINTK is the SPLINT routine of the reference.
  18. C
  19. C DBINTK produces the B-spline coefficients, BCOEF, of the
  20. C B-spline of order K with knots T(I), I=1,...,N+K, which
  21. C takes on the value Y(I) at X(I), I=1,...,N. The spline or
  22. C any of its derivatives can be evaluated by calls to DBVALU.
  23. C
  24. C The I-th equation of the linear system A*BCOEF = B for the
  25. C coefficients of the interpolant enforces interpolation at
  26. C X(I), I=1,...,N. Hence, B(I) = Y(I), for all I, and A is
  27. C a band matrix with 2K-1 bands if A is invertible. The matrix
  28. C A is generated row by row and stored, diagonal by diagonal,
  29. C in the rows of Q, with the main diagonal going into row K.
  30. C The banded system is then solved by a call to DBNFAC (which
  31. C constructs the triangular factorization for A and stores it
  32. C again in Q), followed by a call to DBNSLV (which then
  33. C obtains the solution BCOEF by substitution). DBNFAC does no
  34. C pivoting, since the total positivity of the matrix A makes
  35. C this unnecessary. The linear system to be solved is
  36. C (theoretically) invertible if and only if
  37. C T(I) .LT. X(I) .LT. T(I+K), for all I.
  38. C Equality is permitted on the left for I=1 and on the right
  39. C for I=N when K knots are used at X(1) or X(N). Otherwise,
  40. C violation of this condition is certain to lead to an error.
  41. C
  42. C Description of Arguments
  43. C
  44. C Input X,Y,T are double precision
  45. C X - vector of length N containing data point abscissa
  46. C in strictly increasing order.
  47. C Y - corresponding vector of length N containing data
  48. C point ordinates.
  49. C T - knot vector of length N+K
  50. C Since T(1),..,T(K) .LE. X(1) and T(N+1),..,T(N+K)
  51. C .GE. X(N), this leaves only N-K knots (not nec-
  52. C essarily X(I) values) interior to (X(1),X(N))
  53. C N - number of data points, N .GE. K
  54. C K - order of the spline, K .GE. 1
  55. C
  56. C Output BCOEF,Q,WORK are double precision
  57. C BCOEF - a vector of length N containing the B-spline
  58. C coefficients
  59. C Q - a work vector of length (2*K-1)*N, containing
  60. C the triangular factorization of the coefficient
  61. C matrix of the linear system being solved. The
  62. C coefficients for the interpolant of an
  63. C additional data set (X(I),YY(I)), I=1,...,N
  64. C with the same abscissa can be obtained by loading
  65. C YY into BCOEF and then executing
  66. C CALL DBNSLV (Q,2K-1,N,K-1,K-1,BCOEF)
  67. C WORK - work vector of length 2*K
  68. C
  69. C Error Conditions
  70. C Improper input is a fatal error
  71. C Singular system of equations is a fatal error
  72. C
  73. C***REFERENCES D. E. Amos, Computation with splines and B-splines,
  74. C Report SAND78-1968, Sandia Laboratories, March 1979.
  75. C Carl de Boor, Package for calculating with B-splines,
  76. C SIAM Journal on Numerical Analysis 14, 3 (June 1977),
  77. C pp. 441-472.
  78. C Carl de Boor, A Practical Guide to Splines, Applied
  79. C Mathematics Series 27, Springer-Verlag, New York,
  80. C 1978.
  81. C***ROUTINES CALLED DBNFAC, DBNSLV, DBSPVN, XERMSG
  82. C***REVISION HISTORY (YYMMDD)
  83. C 800901 DATE WRITTEN
  84. C 890531 Changed all specific intrinsics to generic. (WRB)
  85. C 890831 Modified array declarations. (WRB)
  86. C 890831 REVISION DATE from Version 3.2
  87. C 891214 Prologue converted to Version 4.0 format. (BAB)
  88. C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
  89. C 900326 Removed duplicate information from DESCRIPTION section.
  90. C (WRB)
  91. C 920501 Reformatted the REFERENCES section. (WRB)
  92. C***END PROLOGUE DBINTK
  93. C
  94. INTEGER IFLAG, IWORK, K, N, I, ILP1MX, J, JJ, KM1, KPKM2, LEFT,
  95. 1 LENQ, NP1
  96. DOUBLE PRECISION BCOEF(*), Y(*), Q(*), T(*), X(*), XI, WORK(*)
  97. C DIMENSION Q(2*K-1,N), T(N+K)
  98. C***FIRST EXECUTABLE STATEMENT DBINTK
  99. IF(K.LT.1) GO TO 100
  100. IF(N.LT.K) GO TO 105
  101. JJ = N - 1
  102. IF(JJ.EQ.0) GO TO 6
  103. DO 5 I=1,JJ
  104. IF(X(I).GE.X(I+1)) GO TO 110
  105. 5 CONTINUE
  106. 6 CONTINUE
  107. NP1 = N + 1
  108. KM1 = K - 1
  109. KPKM2 = 2*KM1
  110. LEFT = K
  111. C ZERO OUT ALL ENTRIES OF Q
  112. LENQ = N*(K+KM1)
  113. DO 10 I=1,LENQ
  114. Q(I) = 0.0D0
  115. 10 CONTINUE
  116. C
  117. C *** LOOP OVER I TO CONSTRUCT THE N INTERPOLATION EQUATIONS
  118. DO 50 I=1,N
  119. XI = X(I)
  120. ILP1MX = MIN(I+K,NP1)
  121. C *** FIND LEFT IN THE CLOSED INTERVAL (I,I+K-1) SUCH THAT
  122. C T(LEFT) .LE. X(I) .LT. T(LEFT+1)
  123. C MATRIX IS SINGULAR IF THIS IS NOT POSSIBLE
  124. LEFT = MAX(LEFT,I)
  125. IF (XI.LT.T(LEFT)) GO TO 80
  126. 20 IF (XI.LT.T(LEFT+1)) GO TO 30
  127. LEFT = LEFT + 1
  128. IF (LEFT.LT.ILP1MX) GO TO 20
  129. LEFT = LEFT - 1
  130. IF (XI.GT.T(LEFT+1)) GO TO 80
  131. C *** THE I-TH EQUATION ENFORCES INTERPOLATION AT XI, HENCE
  132. C A(I,J) = B(J,K,T)(XI), ALL J. ONLY THE K ENTRIES WITH J =
  133. C LEFT-K+1,...,LEFT ACTUALLY MIGHT BE NONZERO. THESE K NUMBERS
  134. C ARE RETURNED, IN BCOEF (USED FOR TEMP. STORAGE HERE), BY THE
  135. C FOLLOWING
  136. 30 CALL DBSPVN(T, K, K, 1, XI, LEFT, BCOEF, WORK, IWORK)
  137. C WE THEREFORE WANT BCOEF(J) = B(LEFT-K+J)(XI) TO GO INTO
  138. C A(I,LEFT-K+J), I.E., INTO Q(I-(LEFT+J)+2*K,(LEFT+J)-K) SINCE
  139. C A(I+J,J) IS TO GO INTO Q(I+K,J), ALL I,J, IF WE CONSIDER Q
  140. C AS A TWO-DIM. ARRAY , WITH 2*K-1 ROWS (SEE COMMENTS IN
  141. C DBNFAC). IN THE PRESENT PROGRAM, WE TREAT Q AS AN EQUIVALENT
  142. C ONE-DIMENSIONAL ARRAY (BECAUSE OF FORTRAN RESTRICTIONS ON
  143. C DIMENSION STATEMENTS) . WE THEREFORE WANT BCOEF(J) TO GO INTO
  144. C ENTRY
  145. C I -(LEFT+J) + 2*K + ((LEFT+J) - K-1)*(2*K-1)
  146. C = I-LEFT+1 + (LEFT -K)*(2*K-1) + (2*K-2)*J
  147. C OF Q .
  148. JJ = I - LEFT + 1 + (LEFT-K)*(K+KM1)
  149. DO 40 J=1,K
  150. JJ = JJ + KPKM2
  151. Q(JJ) = BCOEF(J)
  152. 40 CONTINUE
  153. 50 CONTINUE
  154. C
  155. C ***OBTAIN FACTORIZATION OF A , STORED AGAIN IN Q.
  156. CALL DBNFAC(Q, K+KM1, N, KM1, KM1, IFLAG)
  157. GO TO (60, 90), IFLAG
  158. C *** SOLVE A*BCOEF = Y BY BACKSUBSTITUTION
  159. 60 DO 70 I=1,N
  160. BCOEF(I) = Y(I)
  161. 70 CONTINUE
  162. CALL DBNSLV(Q, K+KM1, N, KM1, KM1, BCOEF)
  163. RETURN
  164. C
  165. C
  166. 80 CONTINUE
  167. CALL XERMSG ('SLATEC', 'DBINTK',
  168. + 'SOME ABSCISSA WAS NOT IN THE SUPPORT OF THE CORRESPONDING ' //
  169. + 'BASIS FUNCTION AND THE SYSTEM IS SINGULAR.', 2, 1)
  170. RETURN
  171. 90 CONTINUE
  172. CALL XERMSG ('SLATEC', 'DBINTK',
  173. + 'THE SYSTEM OF SOLVER DETECTS A SINGULAR SYSTEM ALTHOUGH ' //
  174. + 'THE THEORETICAL CONDITIONS FOR A SOLUTION WERE SATISFIED.',
  175. + 8, 1)
  176. RETURN
  177. 100 CONTINUE
  178. CALL XERMSG ('SLATEC', 'DBINTK', 'K DOES NOT SATISFY K.GE.1', 2,
  179. + 1)
  180. RETURN
  181. 105 CONTINUE
  182. CALL XERMSG ('SLATEC', 'DBINTK', 'N DOES NOT SATISFY N.GE.K', 2,
  183. + 1)
  184. RETURN
  185. 110 CONTINUE
  186. CALL XERMSG ('SLATEC', 'DBINTK',
  187. + 'X(I) DOES NOT SATISFY X(I).LT.X(I+1) FOR SOME I', 2, 1)
  188. RETURN
  189. END