bnfac.f 5.6 KB

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