V3FIT
li_gbfa.f
1  SUBROUTINE sgbfa1 (ABD, LDA, N, ML, MU, IPVT, INFO)
2  USE liprec, ONLY: wp => sp
3  IMPLICIT NONE
4 !-----------------------------------------------
5 ! D U M M Y A R G U M E N T S
6 !-----------------------------------------------
7  INTEGER LDA, N, ML, MU, INFO
8  INTEGER, DIMENSION(N) :: IPVT
9  REAL(WP), DIMENSION(*) :: ABD
10 
11  CALL sgbfa (abd, lda, n, ml, mu, ipvt, info)
12 
13  END SUBROUTINE sgbfa1
14 
15 
16  SUBROUTINE dgbfa1 (ABD, LDA, N, ML, MU, IPVT, INFO)
17  USE liprec, ONLY: wp => dp
18  IMPLICIT NONE
19 !-----------------------------------------------
20 ! D U M M Y A R G U M E N T S
21 !-----------------------------------------------
22  INTEGER LDA, N, ML, MU, INFO
23  INTEGER, DIMENSION(N) :: IPVT
24  REAL(WP), DIMENSION(*) :: ABD
25 
26  CALL dgbfa (abd, lda, n, ml, mu, ipvt, info)
27 
28  END SUBROUTINE dgbfa1
29 
30 #ifndef CRAY
31  SUBROUTINE sgbfa (ABD, LDA, N, ML, MU, IPVT, INFO)
32  USE liprec, ONLY: wp => sp
33  IMPLICIT NONE
34 !-----------------------------------------------
35 ! D U M M Y A R G U M E N T S
36 !-----------------------------------------------
37  INTEGER LDA, N, ML, MU, INFO
38  INTEGER, DIMENSION(N) :: IPVT
39  REAL(WP), DIMENSION(LDA,N) :: ABD
40 !-----------------------------------------------
41 ! L O C A L V A R I A B L E S
42 !-----------------------------------------------
43  REAL(WP), PARAMETER :: ZERO = 0, one = 1
44  INTEGER :: I0, J, JU, JZ, J0, J1, K, KP1, L, LM, M, MM, NM1
45  REAL(WP) :: T
46  INTEGER :: ISAMAX1(1)
47 !-----------------------------------------------
48  EXTERNAL sscal, saxpy
49 !
50 ! sgbfa factors a REAL band matrix by elimination.
51 !
52 ! sgbfa is usually called by sgbco, but it can be called
53 ! directly with a saving in time if rcond is not needed.
54 !
55 ! on entry
56 !
57 ! abd real(lda, n)
58 ! contains the matrix in band storage. the columns
59 ! of the matrix are stored in the columns of abd and
60 ! the diagonals of the matrix are stored in rows
61 ! ml+1 through 2*ml+mu+1 of abd .
62 ! see the comments below for details.
63 !
64 ! lda integer
65 ! the leading dimension of the array abd .
66 ! lda must be .ge. 2*ml + mu + 1 .
67 !
68 ! n integer
69 ! the order of the original matrix.
70 !
71 ! ml integer
72 ! number of diagonals below the main diagonal.
73 ! 0 .le. ml .lt. n .
74 !
75 ! mu integer
76 ! number of diagonals above the main diagonal.
77 ! 0 .le. mu .lt. n .
78 ! more efficient if ml .le. mu .
79 ! on return
80 !
81 ! abd an upper triangular matrix in band storage and
82 ! the multipliers which were used to obtain it.
83 ! the factorization can be written a = l*u where
84 ! l is a product of permutation and unit lower
85 ! triangular matrices and u is upper triangular.
86 !
87 ! ipvt integer(n)
88 ! an integer vector of pivot indices.
89 !
90 ! info integer
91 ! = 0 normal value.
92 ! = k if u(k,k) .eq. 0.0 . this is not an error
93 ! condition for this subroutine, but it does
94 ! indicate that sgbsl will divide by zero if
95 ! called. use rcond in sgbco for a reliable
96 ! indication of singularity.
97 !
98 ! band storage
99 !
100 ! if a is a band matrix, the following program segment
101 ! will set up the input.
102 !
103 ! ml = (band width below the diagonal)
104 ! mu = (band width above the diagonal)
105 ! m = ml + mu + 1
106 ! do 20 j = 1, n
107 ! i1 = max(1, j-mu)
108 ! i2 = min(n, j+ml)
109 ! do 10 i = i1, i2
110 ! k = i - j + m
111 ! abd(k,j) = a(i,j)
112 ! 10 continue
113 ! 20 continue
114 !
115 ! this uses rows ml+1 through 2*ml+mu+1 of abd .
116 ! in addition, the first ml rows in abd are used for
117 ! elements generated during the triangularization.
118 ! the total number of rows needed in abd is 2*ml+mu+1 .
119 ! the ml+mu by ml+mu upper left triangle and the
120 ! ml by ml lower right triangle are not referenced.
121 !
122 ! linpack. this version dated 08/14/78 .
123 ! cleve moler, university of new mexico, argonne national lab.
124 !
125 ! subroutines and functions
126 !
127 ! blas saxpy ,sscal
128 ! fortran max,min
129 !
130 ! internal variables
131 !
132 !
133  m = ml + mu + 1
134  info = 0
135 !
136 ! zero initial fill-in columns
137 !
138  j0 = mu + 2
139  j1 = min(n,m) - 1
140  DO jz = j0, j1
141  i0 = m + 1 - jz
142  abd(i0:ml,jz) = zero
143  END DO
144  jz = j1
145  ju = 0
146 !
147 ! gaussian elimination with partial pivoting
148 !
149  nm1 = n - 1
150  IF (nm1 .ge. 1) THEN
151  DO k = 1, nm1
152  kp1 = k + 1
153 !
154 ! zero next fill-in column
155 !
156  jz = jz + 1
157  IF (jz .le. n) THEN
158  abd(:ml,jz) = zero
159  END IF
160 !
161 ! find l = pivot INDEX
162 !
163  lm = min(ml,n - k)
164  isamax1 = maxloc(abs(abd(m:m+lm,k)))
165  l = isamax1(1) + m - 1
166 ! l = isamax(lm + 1,abd(m,k),1) + m - 1
167  ipvt(k) = l + k - m
168 !
169 ! zero pivot implies this column already triangularized
170 !
171  IF (abd(l,k) .ne. zero) THEN
172 !
173 ! interchange if necessary
174 !
175  IF (l .ne. m) THEN
176  t = abd(l,k)
177  abd(l,k) = abd(m,k)
178  abd(m,k) = t
179  END IF
180 !
181 ! compute multipliers
182 !
183  t = -one/abd(m,k)
184  CALL sscal (lm, t, abd(m+1,k), 1)
185 !
186 ! row elimination with column indexing
187 !
188  ju = min(max(ju,mu + ipvt(k)),n)
189  mm = m
190  DO j = kp1, ju
191  l = l - 1
192  mm = mm - 1
193  t = abd(l,j)
194  IF (l .ne. mm) THEN
195  abd(l,j) = abd(mm,j)
196  abd(mm,j) = t
197  END IF
198  CALL saxpy (lm, t, abd(m+1,k), 1, abd(mm+1,j), 1)
199  END DO
200  ELSE
201  info = k
202  END IF
203  END DO
204  END IF
205  ipvt(n) = n
206  IF (abd(m,n) .eq. zero) info = n
207 
208  END SUBROUTINE sgbfa
209 
210  SUBROUTINE dgbfa (ABD, LDA, N, ML, MU, IPVT, INFO)
211  USE liprec, ONLY: wp => dp
212  IMPLICIT NONE
213 !-----------------------------------------------
214 ! D U M M Y A R G U M E N T S
215 !-----------------------------------------------
216  INTEGER LDA, N, ML, MU, INFO
217  INTEGER, DIMENSION(N) :: IPVT
218  REAL(WP), DIMENSION(LDA,N) :: ABD
219 !-----------------------------------------------
220 ! L O C A L V A R I A B L E S
221 !-----------------------------------------------
222  REAL(WP), PARAMETER :: ZERO = 0, one = 1
223  INTEGER :: I0, J, JU, JZ, J0, J1, K, KP1, L, LM, M, MM, NM1
224  REAL(WP) :: T
225  INTEGER :: ISAMAX1(1)
226 !-----------------------------------------------
227  EXTERNAL dscal, daxpy
228 !
229 ! sgbfa factors a REAL band matrix by elimination.
230 !
231 ! sgbfa is usually called by sgbco, but it can be called
232 ! directly with a saving in time if rcond is not needed.
233 !
234 ! on entry
235 !
236 ! abd real(lda, n)
237 ! contains the matrix in band storage. the columns
238 ! of the matrix are stored in the columns of abd and
239 ! the diagonals of the matrix are stored in rows
240 ! ml+1 through 2*ml+mu+1 of abd .
241 ! see the comments below for details.
242 !
243 ! lda integer
244 ! the leading dimension of the array abd .
245 ! lda must be .ge. 2*ml + mu + 1 .
246 !
247 ! n integer
248 ! the order of the original matrix.
249 !
250 ! ml integer
251 ! number of diagonals below the main diagonal.
252 ! 0 .le. ml .lt. n .
253 !
254 ! mu integer
255 ! number of diagonals above the main diagonal.
256 ! 0 .le. mu .lt. n .
257 ! more efficient if ml .le. mu .
258 ! on return
259 !
260 ! abd an upper triangular matrix in band storage and
261 ! the multipliers which were used to obtain it.
262 ! the factorization can be written a = l*u where
263 ! l is a product of permutation and unit lower
264 ! triangular matrices and u is upper triangular.
265 !
266 ! ipvt integer(n)
267 ! an integer vector of pivot indices.
268 !
269 ! info integer
270 ! = 0 normal value.
271 ! = k if u(k,k) .eq. 0.0 . this is not an error
272 ! condition for this subroutine, but it does
273 ! indicate that sgbsl will divide by zero if
274 ! called. use rcond in sgbco for a reliable
275 ! indication of singularity.
276 !
277 ! band storage
278 !
279 ! if a is a band matrix, the following program segment
280 ! will set up the input.
281 !
282 ! ml = (band width below the diagonal)
283 ! mu = (band width above the diagonal)
284 ! m = ml + mu + 1
285 ! do 20 j = 1, n
286 ! i1 = max(1, j-mu)
287 ! i2 = min(n, j+ml)
288 ! do 10 i = i1, i2
289 ! k = i - j + m
290 ! abd(k,j) = a(i,j)
291 ! 10 continue
292 ! 20 continue
293 !
294 ! this uses rows ml+1 through 2*ml+mu+1 of abd .
295 ! in addition, the first ml rows in abd are used for
296 ! elements generated during the triangularization.
297 ! the total number of rows needed in abd is 2*ml+mu+1 .
298 ! the ml+mu by ml+mu upper left triangle and the
299 ! ml by ml lower right triangle are not referenced.
300 !
301 ! linpack. this version dated 08/14/78 .
302 ! cleve moler, university of new mexico, argonne national lab.
303 !
304 ! subroutines and functions
305 !
306 ! blas saxpy ,sscal
307 ! fortran max,min
308 !
309 ! internal variables
310 !
311  m = ml + mu + 1
312  info = 0
313 !
314 ! zero initial fill-in columns
315 !
316  j0 = mu + 2
317  j1 = min(n,m) - 1
318  DO jz = j0, j1
319  i0 = m + 1 - jz
320  abd(i0:ml,jz) = zero
321  END DO
322  jz = j1
323  ju = 0
324 !
325 ! gaussian elimination with partial pivoting
326 !
327  nm1 = n - 1
328  IF (nm1 .ge. 1) THEN
329  DO k = 1, nm1
330  kp1 = k + 1
331 !
332 ! zero next fill-in column
333 !
334  jz = jz + 1
335  IF (jz .le. n) THEN
336  abd(:ml,jz) = zero
337  END IF
338 !
339 ! find l = pivot INDEX
340 !
341  lm = min(ml,n - k)
342  isamax1 = maxloc(abs(abd(m:m+lm,k)))
343  l = isamax1(1) + m - 1
344 ! l = isamax(lm + 1,abd(m,k),1) + m - 1
345  ipvt(k) = l + k - m
346 !
347 ! zero pivot implies this column already triangularized
348 !
349  IF (abd(l,k) .ne. zero) THEN
350 !
351 ! interchange if necessary
352 !
353  IF (l .ne. m) THEN
354  t = abd(l,k)
355  abd(l,k) = abd(m,k)
356  abd(m,k) = t
357  END IF
358 !
359 ! compute multipliers
360 !
361  t = -one/abd(m,k)
362  CALL dscal (lm, t, abd(m+1,k), 1)
363 !
364 ! row elimination with column indexing
365 !
366  ju = min(max(ju,mu + ipvt(k)),n)
367  mm = m
368  DO j = kp1, ju
369  l = l - 1
370  mm = mm - 1
371  t = abd(l,j)
372  IF (l .ne. mm) THEN
373  abd(l,j) = abd(mm,j)
374  abd(mm,j) = t
375  END IF
376  CALL daxpy (lm, t, abd(m+1,k), 1, abd(mm+1,j), 1)
377  END DO
378  ELSE
379  info = k
380  END IF
381  END DO
382  END IF
383  ipvt(n) = n
384  IF (abd(m,n) .eq. zero) info = n
385 
386  END SUBROUTINE dgbfa
387 #endif