dbnfac.f 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. *DECK DBNFAC
  2. SUBROUTINE DBNFAC (W, NROWW, NROW, NBANDL, NBANDU, IFLAG)
  3. C***BEGIN PROLOGUE DBNFAC
  4. C***SUBSIDIARY
  5. C***PURPOSE Subsidiary to DBINT4 and DBINTK
  6. C***LIBRARY SLATEC
  7. C***TYPE DOUBLE PRECISION (BNFAC-S, DBNFAC-D)
  8. C***AUTHOR (UNKNOWN)
  9. C***DESCRIPTION
  10. C
  11. C DBNFAC is the BANFAC routine from
  12. C * A Practical Guide to Splines * by C. de Boor
  13. C
  14. C DBNFAC is a double precision routine
  15. C
  16. C Returns in W the LU-factorization (without pivoting) of the banded
  17. C matrix A of order NROW with (NBANDL + 1 + NBANDU) bands or diag-
  18. C onals in the work array W .
  19. C
  20. C ***** I N P U T ****** W is double precision
  21. C W.....Work array of size (NROWW,NROW) containing the interesting
  22. C part of a banded matrix A , with the diagonals or bands of A
  23. C stored in the rows of W , while columns of A correspond to
  24. C columns of W . This is the storage mode used in LINPACK and
  25. C results in efficient innermost loops.
  26. C Explicitly, A has NBANDL bands below the diagonal
  27. C + 1 (main) diagonal
  28. C + NBANDU bands above the diagonal
  29. C and thus, with MIDDLE = NBANDU + 1,
  30. C A(I+J,J) is in W(I+MIDDLE,J) for I=-NBANDU,...,NBANDL
  31. C J=1,...,NROW .
  32. C For example, the interesting entries of A (1,2)-banded matrix
  33. C of order 9 would appear in the first 1+1+2 = 4 rows of W
  34. C as follows.
  35. C 13 24 35 46 57 68 79
  36. C 12 23 34 45 56 67 78 89
  37. C 11 22 33 44 55 66 77 88 99
  38. C 21 32 43 54 65 76 87 98
  39. C
  40. C All other entries of W not identified in this way with an en-
  41. C try of A are never referenced .
  42. C NROWW.....Row dimension of the work array W .
  43. C must be .GE. NBANDL + 1 + NBANDU .
  44. C NBANDL.....Number of bands of A below the main diagonal
  45. C NBANDU.....Number of bands of A above the main diagonal .
  46. C
  47. C ***** O U T P U T ****** W is double precision
  48. C IFLAG.....Integer indicating success( = 1) or failure ( = 2) .
  49. C If IFLAG = 1, then
  50. C W.....contains the LU-factorization of A into a unit lower triangu-
  51. C lar matrix L and an upper triangular matrix U (both banded)
  52. C and stored in customary fashion over the corresponding entries
  53. C of A . This makes it possible to solve any particular linear
  54. C system A*X = B for X by a
  55. C CALL DBNSLV ( W, NROWW, NROW, NBANDL, NBANDU, B )
  56. C with the solution X contained in B on return .
  57. C If IFLAG = 2, then
  58. C one of NROW-1, NBANDL,NBANDU failed to be nonnegative, or else
  59. C one of the potential pivots was found to be zero indicating
  60. C that A does not have an LU-factorization. This implies that
  61. C A is singular in case it is totally positive .
  62. C
  63. C ***** M E T H O D ******
  64. C Gauss elimination W I T H O U T pivoting is used. The routine is
  65. C intended for use with matrices A which do not require row inter-
  66. C changes during factorization, especially for the T O T A L L Y
  67. C P O S I T I V E matrices which occur in spline calculations.
  68. C The routine should NOT be used for an arbitrary banded matrix.
  69. C
  70. C***SEE ALSO DBINT4, DBINTK
  71. C***ROUTINES CALLED (NONE)
  72. C***REVISION HISTORY (YYMMDD)
  73. C 800901 DATE WRITTEN
  74. C 890531 Changed all specific intrinsics to generic. (WRB)
  75. C 890831 Modified array declarations. (WRB)
  76. C 891214 Prologue converted to Version 4.0 format. (BAB)
  77. C 900328 Added TYPE section. (WRB)
  78. C***END PROLOGUE DBNFAC
  79. C
  80. INTEGER IFLAG, NBANDL, NBANDU, NROW, NROWW, I, IPK, J, JMAX, K,
  81. 1 KMAX, MIDDLE, MIDMK, NROWM1
  82. DOUBLE PRECISION W(NROWW,*), FACTOR, PIVOT
  83. C
  84. C***FIRST EXECUTABLE STATEMENT DBNFAC
  85. IFLAG = 1
  86. MIDDLE = NBANDU + 1
  87. C W(MIDDLE,.) CONTAINS THE MAIN DIAGONAL OF A .
  88. NROWM1 = NROW - 1
  89. IF (NROWM1) 120, 110, 10
  90. 10 IF (NBANDL.GT.0) GO TO 30
  91. C A IS UPPER TRIANGULAR. CHECK THAT DIAGONAL IS NONZERO .
  92. DO 20 I=1,NROWM1
  93. IF (W(MIDDLE,I).EQ.0.0D0) GO TO 120
  94. 20 CONTINUE
  95. GO TO 110
  96. 30 IF (NBANDU.GT.0) GO TO 60
  97. C A IS LOWER TRIANGULAR. CHECK THAT DIAGONAL IS NONZERO AND
  98. C DIVIDE EACH COLUMN BY ITS DIAGONAL .
  99. DO 50 I=1,NROWM1
  100. PIVOT = W(MIDDLE,I)
  101. IF (PIVOT.EQ.0.0D0) GO TO 120
  102. JMAX = MIN(NBANDL,NROW-I)
  103. DO 40 J=1,JMAX
  104. W(MIDDLE+J,I) = W(MIDDLE+J,I)/PIVOT
  105. 40 CONTINUE
  106. 50 CONTINUE
  107. RETURN
  108. C
  109. C A IS NOT JUST A TRIANGULAR MATRIX. CONSTRUCT LU FACTORIZATION
  110. 60 DO 100 I=1,NROWM1
  111. C W(MIDDLE,I) IS PIVOT FOR I-TH STEP .
  112. PIVOT = W(MIDDLE,I)
  113. IF (PIVOT.EQ.0.0D0) GO TO 120
  114. C JMAX IS THE NUMBER OF (NONZERO) ENTRIES IN COLUMN I
  115. C BELOW THE DIAGONAL .
  116. JMAX = MIN(NBANDL,NROW-I)
  117. C DIVIDE EACH ENTRY IN COLUMN I BELOW DIAGONAL BY PIVOT .
  118. DO 70 J=1,JMAX
  119. W(MIDDLE+J,I) = W(MIDDLE+J,I)/PIVOT
  120. 70 CONTINUE
  121. C KMAX IS THE NUMBER OF (NONZERO) ENTRIES IN ROW I TO
  122. C THE RIGHT OF THE DIAGONAL .
  123. KMAX = MIN(NBANDU,NROW-I)
  124. C SUBTRACT A(I,I+K)*(I-TH COLUMN) FROM (I+K)-TH COLUMN
  125. C (BELOW ROW I ) .
  126. DO 90 K=1,KMAX
  127. IPK = I + K
  128. MIDMK = MIDDLE - K
  129. FACTOR = W(MIDMK,IPK)
  130. DO 80 J=1,JMAX
  131. W(MIDMK+J,IPK) = W(MIDMK+J,IPK) - W(MIDDLE+J,I)*FACTOR
  132. 80 CONTINUE
  133. 90 CONTINUE
  134. 100 CONTINUE
  135. C CHECK THE LAST DIAGONAL ENTRY .
  136. 110 IF (W(MIDDLE,NROW).NE.0.0D0) RETURN
  137. 120 IFLAG = 2
  138. RETURN
  139. END