add em color
[sddekit.git] / lapack.f
blob908f9cf0c3ea5189c040721e7af16602ef7e5837
1 ! from expokit, free for non-commercial use
3 * This is a lightweight substitute to the external LAPACK routines
4 * used by EXPOKIT. It is supplied to ensure that EXPOKIT is
5 * self-contained and can still run if LAPACK is not yet installed
6 * in your environement.
7 *----------------------------------------------------------------------|
8 subroutine DGESV( N, M, A,LDA, IPIV, B,LDB, IFLAG )
9 integer N, M, LDA, LDB, IPIV(N), IFLAG
10 double precision A(LDA,N), B(LDB,M)
11 call DGEFA( A,LDA, N, IPIV, IFLAG )
12 if ( IFLAG.ne.0 ) stop "Error in DGESV (LU factorisation)"
13 do j = 1,M
14 call DGESL( A,LDA, N, IPIV,B(1,j), 0 )
15 enddo
16 end
17 *----------------------------------------------------------------------|
18 subroutine DSYSV(UPLO, N,M, A,LDA, IPIV, B,LDB, WRK,LWRK, IFLAG )
19 character UPLO*1
20 integer N, M, LDA, LDB, LWRK, IFLAG, IPIV(N)
21 double precision A(LDA,N), B(LDB,M), WRK(LWRK)
22 call DSIFA( A,LDA, N, IPIV, IFLAG )
23 if ( IFLAG.ne.0 ) stop "Error in DSYSV (LDL' factorisation)"
24 do j = 1,M
25 call DSISL( A,LDA, N, IPIV, B(1,j) )
26 enddo
27 end
28 *----------------------------------------------------------------------|
29 subroutine ZGESV( N, M, A,LDA, IPIV, B,LDB, IFLAG )
30 integer N, M, LDA, LDB, IPIV(N), IFLAG
31 complex*16 A(LDA,N), B(LDB,M)
32 call ZGEFA( A,LDA, N, IPIV, IFLAG )
33 if ( IFLAG.ne.0 ) stop "Error in ZGESV (LU factorisation)"
34 do j = 1,M
35 call ZGESL( A,LDA, N, IPIV,B(1,j), 0 )
36 enddo
37 end
38 *----------------------------------------------------------------------|
39 subroutine ZHESV(UPLO, N,M, A,LDA, IPIV, B,LDB, WRK,LWRK, IFLAG )
40 character UPLO*1
41 integer N, M, LDA, LDB, LWRK, IFLAG, IPIV(N)
42 complex*16 A(LDA,N), B(LDB,M), WRK(LWRK)
43 call ZHIFA( A,LDA, N, IPIV, IFLAG )
44 if ( IFLAG.ne.0 ) stop "Error in ZHESV (LDL' factorisation)"
45 do j = 1,M
46 call ZHISL( A,LDA, N, IPIV,B(1,j) )
47 enddo
48 end
49 *----------------------------------------------------------------------|
50 subroutine ZSYSV(UPLO, N,M, A,LDA, IPIV, B,LDB, WRK,LWRK, IFLAG )
51 character UPLO*1
52 integer N, M, LDA, LDB, LWRK, IFLAG, IPIV(N)
53 complex*16 A(LDA,N), B(LDB,M), WRK(LWRK)
54 call ZSIFA( A,LDA, N, IPIV, IFLAG )
55 if ( IFLAG.ne.0 ) stop "Error in ZSYSV (LDL' factorisation)"
56 do j = 1,M
57 call ZSISL( A,LDA, N, IPIV, B(1,j) )
58 enddo
59 end
60 *----------------------------------------------------------------------|
61 *----------------------------------------------------------------------|
62 *----------------------------------------------------------------------|
63 subroutine dgefa(a,lda,n,ipvt,info)
64 integer lda,n,ipvt(n),info
65 double precision a(lda,n)
67 c dgefa factors a double precision matrix by gaussian elimination.
69 c dgefa is usually called by dgeco, but it can be called
70 c directly with a saving in time if rcond is not needed.
71 c (time for dgeco) = (1 + 9/n)*(time for dgefa) .
73 c on entry
75 c a double precision(lda, n)
76 c the matrix to be factored.
78 c lda integer
79 c the leading dimension of the array a .
81 c n integer
82 c the order of the matrix a .
84 c on return
86 c a an upper triangular matrix and the multipliers
87 c which were used to obtain it.
88 c the factorization can be written a = l*u where
89 c l is a product of permutation and unit lower
90 c triangular matrices and u is upper triangular.
92 c ipvt integer(n)
93 c an integer vector of pivot indices.
95 c info integer
96 c = 0 normal value.
97 c = k if u(k,k) .eq. 0.0 . this is not an error
98 c condition for this subroutine, but it does
99 c indicate that dgesl or dgedi will divide by zero
100 c if called. use rcond in dgeco for a reliable
101 c indication of singularity.
103 c linpack. this version dated 08/14/78 .
104 c cleve moler, university of new mexico, argonne national lab.
106 c subroutines and functions
108 c blas daxpy,dscal,idamax
110 c internal variables
112 double precision t
113 integer idamax,j,k,kp1,l,nm1
116 c gaussian elimination with partial pivoting
118 info = 0
119 nm1 = n - 1
120 if (nm1 .lt. 1) go to 70
121 do 60 k = 1, nm1
122 kp1 = k + 1
124 c find l = pivot index
126 l = idamax(n-k+1,a(k,k),1) + k - 1
127 ipvt(k) = l
129 c zero pivot implies this column already triangularized
131 if (a(l,k) .eq. 0.0d0) go to 40
133 c interchange if necessary
135 if (l .eq. k) go to 10
136 t = a(l,k)
137 a(l,k) = a(k,k)
138 a(k,k) = t
139 10 continue
141 c compute multipliers
143 t = -1.0d0/a(k,k)
144 call dscal(n-k,t,a(k+1,k),1)
146 c row elimination with column indexing
148 do 30 j = kp1, n
149 t = a(l,j)
150 if (l .eq. k) go to 20
151 a(l,j) = a(k,j)
152 a(k,j) = t
153 20 continue
154 call daxpy(n-k,t,a(k+1,k),1,a(k+1,j),1)
155 30 continue
156 go to 50
157 40 continue
158 info = k
159 50 continue
160 60 continue
161 70 continue
162 ipvt(n) = n
163 if (a(n,n) .eq. 0.0d0) info = n
164 return
166 *----------------------------------------------------------------------|
167 subroutine dgesl(a,lda,n,ipvt,b,job)
168 integer lda,n,ipvt(n),job
169 double precision a(lda,n),b(n)
171 c dgesl solves the double precision system
172 c a * x = b or trans(a) * x = b
173 c using the factors computed by dgeco or dgefa.
175 c on entry
177 c a double precision(lda, n)
178 c the output from dgeco or dgefa.
180 c lda integer
181 c the leading dimension of the array a .
183 c n integer
184 c the order of the matrix a .
186 c ipvt integer(n)
187 c the pivot vector from dgeco or dgefa.
189 c b double precision(n)
190 c the right hand side vector.
192 c job integer
193 c = 0 to solve a*x = b ,
194 c = nonzero to solve trans(a)*x = b where
195 c trans(a) is the transpose.
197 c on return
199 c b the solution vector x .
201 c error condition
203 c a division by zero will occur if the input factor contains a
204 c zero on the diagonal. technically this indicates singularity
205 c but it is often caused by improper arguments or improper
206 c setting of lda . it will not occur if the subroutines are
207 c called correctly and if dgeco has set rcond .gt. 0.0
208 c or dgefa has set info .eq. 0 .
210 c to compute inverse(a) * c where c is a matrix
211 c with p columns
212 c call dgeco(a,lda,n,ipvt,rcond,z)
213 c if (rcond is too small) go to ...
214 c do 10 j = 1, p
215 c call dgesl(a,lda,n,ipvt,c(1,j),0)
216 c 10 continue
218 c linpack. this version dated 08/14/78 .
219 c cleve moler, university of new mexico, argonne national lab.
221 c subroutines and functions
223 c blas daxpy,ddot
225 c internal variables
227 double precision ddot,t
228 integer k,kb,l,nm1
230 nm1 = n - 1
231 if (job .ne. 0) go to 50
233 c job = 0 , solve a * x = b
234 c first solve l*y = b
236 if (nm1 .lt. 1) go to 30
237 do 20 k = 1, nm1
238 l = ipvt(k)
239 t = b(l)
240 if (l .eq. k) go to 10
241 b(l) = b(k)
242 b(k) = t
243 10 continue
244 call daxpy(n-k,t,a(k+1,k),1,b(k+1),1)
245 20 continue
246 30 continue
248 c now solve u*x = y
250 do 40 kb = 1, n
251 k = n + 1 - kb
252 b(k) = b(k)/a(k,k)
253 t = -b(k)
254 call daxpy(k-1,t,a(1,k),1,b(1),1)
255 40 continue
256 go to 100
257 50 continue
259 c job = nonzero, solve trans(a) * x = b
260 c first solve trans(u)*y = b
262 do 60 k = 1, n
263 t = ddot(k-1,a(1,k),1,b(1),1)
264 b(k) = (b(k) - t)/a(k,k)
265 60 continue
267 c now solve trans(l)*x = y
269 if (nm1 .lt. 1) go to 90
270 do 80 kb = 1, nm1
271 k = n - kb
272 b(k) = b(k) + ddot(n-k,a(k+1,k),1,b(k+1),1)
273 l = ipvt(k)
274 if (l .eq. k) go to 70
275 t = b(l)
276 b(l) = b(k)
277 b(k) = t
278 70 continue
279 80 continue
280 90 continue
281 100 continue
282 return
285 subroutine dsifa(a,lda,n,kpvt,info)
286 integer lda,n,kpvt(1),info
287 double precision a(lda,1)
289 c dsifa factors a double precision symmetric matrix by elimination
290 c with symmetric pivoting.
292 c to solve a*x = b , follow dsifa by dsisl.
293 c to compute inverse(a)*c , follow dsifa by dsisl.
294 c to compute determinant(a) , follow dsifa by dsidi.
295 c to compute inertia(a) , follow dsifa by dsidi.
296 c to compute inverse(a) , follow dsifa by dsidi.
298 c on entry
300 c a double precision(lda,n)
301 c the symmetric matrix to be factored.
302 c only the diagonal and upper triangle are used.
304 c lda integer
305 c the leading dimension of the array a .
307 c n integer
308 c the order of the matrix a .
310 c on return
312 c a a block diagonal matrix and the multipliers which
313 c were used to obtain it.
314 c the factorization can be written a = u*d*trans(u)
315 c where u is a product of permutation and unit
316 c upper triangular matrices , trans(u) is the
317 c transpose of u , and d is block diagonal
318 c with 1 by 1 and 2 by 2 blocks.
320 c kpvt integer(n)
321 c an integer vector of pivot indices.
323 c info integer
324 c = 0 normal value.
325 c = k if the k-th pivot block is singular. this is
326 c not an error condition for this subroutine,
327 c but it does indicate that dsisl or dsidi may
328 c divide by zero if called.
330 c linpack. this version dated 08/14/78 .
331 c james bunch, univ. calif. san diego, argonne nat. lab.
333 c subroutines and functions
335 c blas daxpy,dswap,idamax
336 c fortran dabs,dmax1,dsqrt
338 c internal variables
340 double precision ak,akm1,bk,bkm1,denom,mulk,mulkm1,t
341 double precision absakk,alpha,colmax,rowmax
342 integer imax,imaxp1,j,jj,jmax,k,km1,km2,kstep,idamax
343 logical swap
346 c initialize
348 c alpha is used in choosing pivot block size.
349 alpha = (1.0d0 + dsqrt(17.0d0))/8.0d0
351 info = 0
353 c main loop on k, which goes from n to 1.
355 k = n
356 10 continue
358 c leave the loop if k=0 or k=1.
360 c ...exit
361 if (k .eq. 0) go to 200
362 if (k .gt. 1) go to 20
363 kpvt(1) = 1
364 if (a(1,1) .eq. 0.0d0) info = 1
365 c ......exit
366 go to 200
367 20 continue
369 c this section of code determines the kind of
370 c elimination to be performed. when it is completed,
371 c kstep will be set to the size of the pivot block, and
372 c swap will be set to .true. if an interchange is
373 c required.
375 km1 = k - 1
376 absakk = dabs(a(k,k))
378 c determine the largest off-diagonal element in
379 c column k.
381 imax = idamax(k-1,a(1,k),1)
382 colmax = dabs(a(imax,k))
383 if (absakk .lt. alpha*colmax) go to 30
384 kstep = 1
385 swap = .false.
386 go to 90
387 30 continue
389 c determine the largest off-diagonal element in
390 c row imax.
392 rowmax = 0.0d0
393 imaxp1 = imax + 1
394 do 40 j = imaxp1, k
395 rowmax = dmax1(rowmax,dabs(a(imax,j)))
396 40 continue
397 if (imax .eq. 1) go to 50
398 jmax = idamax(imax-1,a(1,imax),1)
399 rowmax = dmax1(rowmax,dabs(a(jmax,imax)))
400 50 continue
401 if (dabs(a(imax,imax)) .lt. alpha*rowmax) go to 60
402 kstep = 1
403 swap = .true.
404 go to 80
405 60 continue
406 if (absakk .lt. alpha*colmax*(colmax/rowmax)) go to 70
407 kstep = 1
408 swap = .false.
409 go to 80
410 70 continue
411 kstep = 2
412 swap = imax .ne. km1
413 80 continue
414 90 continue
415 if (dmax1(absakk,colmax) .ne. 0.0d0) go to 100
417 c column k is zero. set info and iterate the loop.
419 kpvt(k) = k
420 info = k
421 go to 190
422 100 continue
423 if (kstep .eq. 2) go to 140
425 c 1 x 1 pivot block.
427 if (.not.swap) go to 120
429 c perform an interchange.
431 call dswap(imax,a(1,imax),1,a(1,k),1)
432 do 110 jj = imax, k
433 j = k + imax - jj
434 t = a(j,k)
435 a(j,k) = a(imax,j)
436 a(imax,j) = t
437 110 continue
438 120 continue
440 c perform the elimination.
442 do 130 jj = 1, km1
443 j = k - jj
444 mulk = -a(j,k)/a(k,k)
445 t = mulk
446 call daxpy(j,t,a(1,k),1,a(1,j),1)
447 a(j,k) = mulk
448 130 continue
450 c set the pivot array.
452 kpvt(k) = k
453 if (swap) kpvt(k) = imax
454 go to 190
455 140 continue
457 c 2 x 2 pivot block.
459 if (.not.swap) go to 160
461 c perform an interchange.
463 call dswap(imax,a(1,imax),1,a(1,k-1),1)
464 do 150 jj = imax, km1
465 j = km1 + imax - jj
466 t = a(j,k-1)
467 a(j,k-1) = a(imax,j)
468 a(imax,j) = t
469 150 continue
470 t = a(k-1,k)
471 a(k-1,k) = a(imax,k)
472 a(imax,k) = t
473 160 continue
475 c perform the elimination.
477 km2 = k - 2
478 if (km2 .eq. 0) go to 180
479 ak = a(k,k)/a(k-1,k)
480 akm1 = a(k-1,k-1)/a(k-1,k)
481 denom = 1.0d0 - ak*akm1
482 do 170 jj = 1, km2
483 j = km1 - jj
484 bk = a(j,k)/a(k-1,k)
485 bkm1 = a(j,k-1)/a(k-1,k)
486 mulk = (akm1*bk - bkm1)/denom
487 mulkm1 = (ak*bkm1 - bk)/denom
488 t = mulk
489 call daxpy(j,t,a(1,k),1,a(1,j),1)
490 t = mulkm1
491 call daxpy(j,t,a(1,k-1),1,a(1,j),1)
492 a(j,k) = mulk
493 a(j,k-1) = mulkm1
494 170 continue
495 180 continue
497 c set the pivot array.
499 kpvt(k) = 1 - k
500 if (swap) kpvt(k) = -imax
501 kpvt(k-1) = kpvt(k)
502 190 continue
503 k = k - kstep
504 go to 10
505 200 continue
506 return
508 subroutine dsisl(a,lda,n,kpvt,b)
509 integer lda,n,kpvt(1)
510 double precision a(lda,1),b(1)
512 c dsisl solves the double precision symmetric system
513 c a * x = b
514 c using the factors computed by dsifa.
516 c on entry
518 c a double precision(lda,n)
519 c the output from dsifa.
521 c lda integer
522 c the leading dimension of the array a .
524 c n integer
525 c the order of the matrix a .
527 c kpvt integer(n)
528 c the pivot vector from dsifa.
530 c b double precision(n)
531 c the right hand side vector.
533 c on return
535 c b the solution vector x .
537 c error condition
539 c a division by zero may occur if dsico has set rcond .eq. 0.0
540 c or dsifa has set info .ne. 0 .
542 c to compute inverse(a) * c where c is a matrix
543 c with p columns
544 c call dsifa(a,lda,n,kpvt,info)
545 c if (info .ne. 0) go to ...
546 c do 10 j = 1, p
547 c call dsisl(a,lda,n,kpvt,c(1,j))
548 c 10 continue
550 c linpack. this version dated 08/14/78 .
551 c james bunch, univ. calif. san diego, argonne nat. lab.
553 c subroutines and functions
555 c blas daxpy,ddot
556 c fortran iabs
558 c internal variables.
560 double precision ak,akm1,bk,bkm1,ddot,denom,temp
561 integer k,kp
563 c loop backward applying the transformations and
564 c d inverse to b.
566 k = n
567 10 if (k .eq. 0) go to 80
568 if (kpvt(k) .lt. 0) go to 40
570 c 1 x 1 pivot block.
572 if (k .eq. 1) go to 30
573 kp = kpvt(k)
574 if (kp .eq. k) go to 20
576 c interchange.
578 temp = b(k)
579 b(k) = b(kp)
580 b(kp) = temp
581 20 continue
583 c apply the transformation.
585 call daxpy(k-1,b(k),a(1,k),1,b(1),1)
586 30 continue
588 c apply d inverse.
590 b(k) = b(k)/a(k,k)
591 k = k - 1
592 go to 70
593 40 continue
595 c 2 x 2 pivot block.
597 if (k .eq. 2) go to 60
598 kp = iabs(kpvt(k))
599 if (kp .eq. k - 1) go to 50
601 c interchange.
603 temp = b(k-1)
604 b(k-1) = b(kp)
605 b(kp) = temp
606 50 continue
608 c apply the transformation.
610 call daxpy(k-2,b(k),a(1,k),1,b(1),1)
611 call daxpy(k-2,b(k-1),a(1,k-1),1,b(1),1)
612 60 continue
614 c apply d inverse.
616 ak = a(k,k)/a(k-1,k)
617 akm1 = a(k-1,k-1)/a(k-1,k)
618 bk = b(k)/a(k-1,k)
619 bkm1 = b(k-1)/a(k-1,k)
620 denom = ak*akm1 - 1.0d0
621 b(k) = (akm1*bk - bkm1)/denom
622 b(k-1) = (ak*bkm1 - bk)/denom
623 k = k - 2
624 70 continue
625 go to 10
626 80 continue
628 c loop forward applying the transformations.
630 k = 1
631 90 if (k .gt. n) go to 160
632 if (kpvt(k) .lt. 0) go to 120
634 c 1 x 1 pivot block.
636 if (k .eq. 1) go to 110
638 c apply the transformation.
640 b(k) = b(k) + ddot(k-1,a(1,k),1,b(1),1)
641 kp = kpvt(k)
642 if (kp .eq. k) go to 100
644 c interchange.
646 temp = b(k)
647 b(k) = b(kp)
648 b(kp) = temp
649 100 continue
650 110 continue
651 k = k + 1
652 go to 150
653 120 continue
655 c 2 x 2 pivot block.
657 if (k .eq. 1) go to 140
659 c apply the transformation.
661 b(k) = b(k) + ddot(k-1,a(1,k),1,b(1),1)
662 b(k+1) = b(k+1) + ddot(k-1,a(1,k+1),1,b(1),1)
663 kp = iabs(kpvt(k))
664 if (kp .eq. k) go to 130
666 c interchange.
668 temp = b(k)
669 b(k) = b(kp)
670 b(kp) = temp
671 130 continue
672 140 continue
673 k = k + 2
674 150 continue
675 go to 90
676 160 continue
677 return
679 subroutine zgefa(a,lda,n,ipvt,info)
680 integer lda,n,ipvt(1),info
681 complex*16 a(lda,1)
683 c zgefa factors a complex*16 matrix by gaussian elimination.
685 c zgefa is usually called by zgeco, but it can be called
686 c directly with a saving in time if rcond is not needed.
687 c (time for zgeco) = (1 + 9/n)*(time for zgefa) .
689 c on entry
691 c a complex*16(lda, n)
692 c the matrix to be factored.
694 c lda integer
695 c the leading dimension of the array a .
697 c n integer
698 c the order of the matrix a .
700 c on return
702 c a an upper triangular matrix and the multipliers
703 c which were used to obtain it.
704 c the factorization can be written a = l*u where
705 c l is a product of permutation and unit lower
706 c triangular matrices and u is upper triangular.
708 c ipvt integer(n)
709 c an integer vector of pivot indices.
711 c info integer
712 c = 0 normal value.
713 c = k if u(k,k) .eq. 0.0 . this is not an error
714 c condition for this subroutine, but it does
715 c indicate that zgesl or zgedi will divide by zero
716 c if called. use rcond in zgeco for a reliable
717 c indication of singularity.
719 c linpack. this version dated 08/14/78 .
720 c cleve moler, university of new mexico, argonne national lab.
722 c subroutines and functions
724 c blas zaxpy,zscal,izamax
725 c fortran dabs
727 c internal variables
729 complex*16 t
730 integer izamax,j,k,kp1,l,nm1
732 complex*16 zdum
733 double precision cabs1
734 double precision dreal,dimag
735 complex*16 zdumr,zdumi
736 dreal(zdumr) = zdumr
737 dimag(zdumi) = (0.0d0,-1.0d0)*zdumi
738 cabs1(zdum) = dabs(dreal(zdum)) + dabs(dimag(zdum))
740 c gaussian elimination with partial pivoting
742 info = 0
743 nm1 = n - 1
744 if (nm1 .lt. 1) go to 70
745 do 60 k = 1, nm1
746 kp1 = k + 1
748 c find l = pivot index
750 l = izamax(n-k+1,a(k,k),1) + k - 1
751 ipvt(k) = l
753 c zero pivot implies this column already triangularized
755 if (cabs1(a(l,k)) .eq. 0.0d0) go to 40
757 c interchange if necessary
759 if (l .eq. k) go to 10
760 t = a(l,k)
761 a(l,k) = a(k,k)
762 a(k,k) = t
763 10 continue
765 c compute multipliers
767 t = -(1.0d0,0.0d0)/a(k,k)
768 call zscal(n-k,t,a(k+1,k),1)
770 c row elimination with column indexing
772 do 30 j = kp1, n
773 t = a(l,j)
774 if (l .eq. k) go to 20
775 a(l,j) = a(k,j)
776 a(k,j) = t
777 20 continue
778 call zaxpy(n-k,t,a(k+1,k),1,a(k+1,j),1)
779 30 continue
780 go to 50
781 40 continue
782 info = k
783 50 continue
784 60 continue
785 70 continue
786 ipvt(n) = n
787 if (cabs1(a(n,n)) .eq. 0.0d0) info = n
788 return
790 subroutine zgesl(a,lda,n,ipvt,b,job)
791 integer lda,n,ipvt(1),job
792 complex*16 a(lda,1),b(1)
794 c zgesl solves the complex*16 system
795 c a * x = b or ctrans(a) * x = b
796 c using the factors computed by zgeco or zgefa.
798 c on entry
800 c a complex*16(lda, n)
801 c the output from zgeco or zgefa.
803 c lda integer
804 c the leading dimension of the array a .
806 c n integer
807 c the order of the matrix a .
809 c ipvt integer(n)
810 c the pivot vector from zgeco or zgefa.
812 c b complex*16(n)
813 c the right hand side vector.
815 c job integer
816 c = 0 to solve a*x = b ,
817 c = nonzero to solve ctrans(a)*x = b where
818 c ctrans(a) is the conjugate transpose.
820 c on return
822 c b the solution vector x .
824 c error condition
826 c a division by zero will occur if the input factor contains a
827 c zero on the diagonal. technically this indicates singularity
828 c but it is often caused by improper arguments or improper
829 c setting of lda . it will not occur if the subroutines are
830 c called correctly and if zgeco has set rcond .gt. 0.0
831 c or zgefa has set info .eq. 0 .
833 c to compute inverse(a) * c where c is a matrix
834 c with p columns
835 c call zgeco(a,lda,n,ipvt,rcond,z)
836 c if (rcond is too small) go to ...
837 c do 10 j = 1, p
838 c call zgesl(a,lda,n,ipvt,c(1,j),0)
839 c 10 continue
841 c linpack. this version dated 08/14/78 .
842 c cleve moler, university of new mexico, argonne national lab.
844 c subroutines and functions
846 c blas zaxpy,zdotc
847 c fortran dconjg
849 c internal variables
851 complex*16 zdotc,t
852 integer k,kb,l,nm1
853 double precision dreal,dimag
854 complex*16 zdumr,zdumi
855 dreal(zdumr) = zdumr
856 dimag(zdumi) = (0.0d0,-1.0d0)*zdumi
858 nm1 = n - 1
859 if (job .ne. 0) go to 50
861 c job = 0 , solve a * x = b
862 c first solve l*y = b
864 if (nm1 .lt. 1) go to 30
865 do 20 k = 1, nm1
866 l = ipvt(k)
867 t = b(l)
868 if (l .eq. k) go to 10
869 b(l) = b(k)
870 b(k) = t
871 10 continue
872 call zaxpy(n-k,t,a(k+1,k),1,b(k+1),1)
873 20 continue
874 30 continue
876 c now solve u*x = y
878 do 40 kb = 1, n
879 k = n + 1 - kb
880 b(k) = b(k)/a(k,k)
881 t = -b(k)
882 call zaxpy(k-1,t,a(1,k),1,b(1),1)
883 40 continue
884 go to 100
885 50 continue
887 c job = nonzero, solve ctrans(a) * x = b
888 c first solve ctrans(u)*y = b
890 do 60 k = 1, n
891 t = zdotc(k-1,a(1,k),1,b(1),1)
892 b(k) = (b(k) - t)/dconjg(a(k,k))
893 60 continue
895 c now solve ctrans(l)*x = y
897 if (nm1 .lt. 1) go to 90
898 do 80 kb = 1, nm1
899 k = n - kb
900 b(k) = b(k) + zdotc(n-k,a(k+1,k),1,b(k+1),1)
901 l = ipvt(k)
902 if (l .eq. k) go to 70
903 t = b(l)
904 b(l) = b(k)
905 b(k) = t
906 70 continue
907 80 continue
908 90 continue
909 100 continue
910 return
912 subroutine zhifa(a,lda,n,kpvt,info)
913 integer lda,n,kpvt(1),info
914 complex*16 a(lda,1)
916 c zhifa factors a complex*16 hermitian matrix by elimination
917 c with symmetric pivoting.
919 c to solve a*x = b , follow zhifa by zhisl.
920 c to compute inverse(a)*c , follow zhifa by zhisl.
921 c to compute determinant(a) , follow zhifa by zhidi.
922 c to compute inertia(a) , follow zhifa by zhidi.
923 c to compute inverse(a) , follow zhifa by zhidi.
925 c on entry
927 c a complex*16(lda,n)
928 c the hermitian matrix to be factored.
929 c only the diagonal and upper triangle are used.
931 c lda integer
932 c the leading dimension of the array a .
934 c n integer
935 c the order of the matrix a .
937 c on return
939 c a a block diagonal matrix and the multipliers which
940 c were used to obtain it.
941 c the factorization can be written a = u*d*ctrans(u)
942 c where u is a product of permutation and unit
943 c upper triangular matrices , ctrans(u) is the
944 c conjugate transpose of u , and d is block diagonal
945 c with 1 by 1 and 2 by 2 blocks.
947 c kpvt integer(n)
948 c an integer vector of pivot indices.
950 c info integer
951 c = 0 normal value.
952 c = k if the k-th pivot block is singular. this is
953 c not an error condition for this subroutine,
954 c but it does indicate that zhisl or zhidi may
955 c divide by zero if called.
957 c linpack. this version dated 08/14/78 .
958 c james bunch, univ. calif. san diego, argonne nat. lab.
960 c subroutines and functions
962 c blas zaxpy,zswap,izamax
963 c fortran dabs,dmax1,dcmplx,dconjg,dsqrt
965 c internal variables
967 complex*16 ak,akm1,bk,bkm1,denom,mulk,mulkm1,t
968 double precision absakk,alpha,colmax,rowmax
969 integer imax,imaxp1,j,jj,jmax,k,km1,km2,kstep,izamax
970 logical swap
972 complex*16 zdum
973 double precision cabs1
974 double precision dreal,dimag
975 complex*16 zdumr,zdumi
976 dreal(zdumr) = zdumr
977 dimag(zdumi) = (0.0d0,-1.0d0)*zdumi
978 cabs1(zdum) = dabs(dreal(zdum)) + dabs(dimag(zdum))
980 c initialize
982 c alpha is used in choosing pivot block size.
983 alpha = (1.0d0 + dsqrt(17.0d0))/8.0d0
985 info = 0
987 c main loop on k, which goes from n to 1.
989 k = n
990 10 continue
992 c leave the loop if k=0 or k=1.
994 c ...exit
995 if (k .eq. 0) go to 200
996 if (k .gt. 1) go to 20
997 kpvt(1) = 1
998 if (cabs1(a(1,1)) .eq. 0.0d0) info = 1
999 c ......exit
1000 go to 200
1001 20 continue
1003 c this section of code determines the kind of
1004 c elimination to be performed. when it is completed,
1005 c kstep will be set to the size of the pivot block, and
1006 c swap will be set to .true. if an interchange is
1007 c required.
1009 km1 = k - 1
1010 absakk = cabs1(a(k,k))
1012 c determine the largest off-diagonal element in
1013 c column k.
1015 imax = izamax(k-1,a(1,k),1)
1016 colmax = cabs1(a(imax,k))
1017 if (absakk .lt. alpha*colmax) go to 30
1018 kstep = 1
1019 swap = .false.
1020 go to 90
1021 30 continue
1023 c determine the largest off-diagonal element in
1024 c row imax.
1026 rowmax = 0.0d0
1027 imaxp1 = imax + 1
1028 do 40 j = imaxp1, k
1029 rowmax = dmax1(rowmax,cabs1(a(imax,j)))
1030 40 continue
1031 if (imax .eq. 1) go to 50
1032 jmax = izamax(imax-1,a(1,imax),1)
1033 rowmax = dmax1(rowmax,cabs1(a(jmax,imax)))
1034 50 continue
1035 if (cabs1(a(imax,imax)) .lt. alpha*rowmax) go to 60
1036 kstep = 1
1037 swap = .true.
1038 go to 80
1039 60 continue
1040 if (absakk .lt. alpha*colmax*(colmax/rowmax)) go to 70
1041 kstep = 1
1042 swap = .false.
1043 go to 80
1044 70 continue
1045 kstep = 2
1046 swap = imax .ne. km1
1047 80 continue
1048 90 continue
1049 if (dmax1(absakk,colmax) .ne. 0.0d0) go to 100
1051 c column k is zero. set info and iterate the loop.
1053 kpvt(k) = k
1054 info = k
1055 go to 190
1056 100 continue
1057 if (kstep .eq. 2) go to 140
1059 c 1 x 1 pivot block.
1061 if (.not.swap) go to 120
1063 c perform an interchange.
1065 call zswap(imax,a(1,imax),1,a(1,k),1)
1066 do 110 jj = imax, k
1067 j = k + imax - jj
1068 t = dconjg(a(j,k))
1069 a(j,k) = dconjg(a(imax,j))
1070 a(imax,j) = t
1071 110 continue
1072 120 continue
1074 c perform the elimination.
1076 do 130 jj = 1, km1
1077 j = k - jj
1078 mulk = -a(j,k)/a(k,k)
1079 t = dconjg(mulk)
1080 call zaxpy(j,t,a(1,k),1,a(1,j),1)
1081 a(j,j) = dcmplx(dreal(a(j,j)),0.0d0)
1082 a(j,k) = mulk
1083 130 continue
1085 c set the pivot array.
1087 kpvt(k) = k
1088 if (swap) kpvt(k) = imax
1089 go to 190
1090 140 continue
1092 c 2 x 2 pivot block.
1094 if (.not.swap) go to 160
1096 c perform an interchange.
1098 call zswap(imax,a(1,imax),1,a(1,k-1),1)
1099 do 150 jj = imax, km1
1100 j = km1 + imax - jj
1101 t = dconjg(a(j,k-1))
1102 a(j,k-1) = dconjg(a(imax,j))
1103 a(imax,j) = t
1104 150 continue
1105 t = a(k-1,k)
1106 a(k-1,k) = a(imax,k)
1107 a(imax,k) = t
1108 160 continue
1110 c perform the elimination.
1112 km2 = k - 2
1113 if (km2 .eq. 0) go to 180
1114 ak = a(k,k)/a(k-1,k)
1115 akm1 = a(k-1,k-1)/dconjg(a(k-1,k))
1116 denom = 1.0d0 - ak*akm1
1117 do 170 jj = 1, km2
1118 j = km1 - jj
1119 bk = a(j,k)/a(k-1,k)
1120 bkm1 = a(j,k-1)/dconjg(a(k-1,k))
1121 mulk = (akm1*bk - bkm1)/denom
1122 mulkm1 = (ak*bkm1 - bk)/denom
1123 t = dconjg(mulk)
1124 call zaxpy(j,t,a(1,k),1,a(1,j),1)
1125 t = dconjg(mulkm1)
1126 call zaxpy(j,t,a(1,k-1),1,a(1,j),1)
1127 a(j,k) = mulk
1128 a(j,k-1) = mulkm1
1129 a(j,j) = dcmplx(dreal(a(j,j)),0.0d0)
1130 170 continue
1131 180 continue
1133 c set the pivot array.
1135 kpvt(k) = 1 - k
1136 if (swap) kpvt(k) = -imax
1137 kpvt(k-1) = kpvt(k)
1138 190 continue
1139 k = k - kstep
1140 go to 10
1141 200 continue
1142 return
1144 subroutine zhisl(a,lda,n,kpvt,b)
1145 integer lda,n,kpvt(1)
1146 complex*16 a(lda,1),b(1)
1148 c zhisl solves the complex*16 hermitian system
1149 c a * x = b
1150 c using the factors computed by zhifa.
1152 c on entry
1154 c a complex*16(lda,n)
1155 c the output from zhifa.
1157 c lda integer
1158 c the leading dimension of the array a .
1160 c n integer
1161 c the order of the matrix a .
1163 c kpvt integer(n)
1164 c the pivot vector from zhifa.
1166 c b complex*16(n)
1167 c the right hand side vector.
1169 c on return
1171 c b the solution vector x .
1173 c error condition
1175 c a division by zero may occur if zhico has set rcond .eq. 0.0
1176 c or zhifa has set info .ne. 0 .
1178 c to compute inverse(a) * c where c is a matrix
1179 c with p columns
1180 c call zhifa(a,lda,n,kpvt,info)
1181 c if (info .ne. 0) go to ...
1182 c do 10 j = 1, p
1183 c call zhisl(a,lda,n,kpvt,c(1,j))
1184 c 10 continue
1186 c linpack. this version dated 08/14/78 .
1187 c james bunch, univ. calif. san diego, argonne nat. lab.
1189 c subroutines and functions
1191 c blas zaxpy,zdotc
1192 c fortran dconjg,iabs
1194 c internal variables.
1196 complex*16 ak,akm1,bk,bkm1,zdotc,denom,temp
1197 integer k,kp
1199 c loop backward applying the transformations and
1200 c d inverse to b.
1202 k = n
1203 10 if (k .eq. 0) go to 80
1204 if (kpvt(k) .lt. 0) go to 40
1206 c 1 x 1 pivot block.
1208 if (k .eq. 1) go to 30
1209 kp = kpvt(k)
1210 if (kp .eq. k) go to 20
1212 c interchange.
1214 temp = b(k)
1215 b(k) = b(kp)
1216 b(kp) = temp
1217 20 continue
1219 c apply the transformation.
1221 call zaxpy(k-1,b(k),a(1,k),1,b(1),1)
1222 30 continue
1224 c apply d inverse.
1226 b(k) = b(k)/a(k,k)
1227 k = k - 1
1228 go to 70
1229 40 continue
1231 c 2 x 2 pivot block.
1233 if (k .eq. 2) go to 60
1234 kp = iabs(kpvt(k))
1235 if (kp .eq. k - 1) go to 50
1237 c interchange.
1239 temp = b(k-1)
1240 b(k-1) = b(kp)
1241 b(kp) = temp
1242 50 continue
1244 c apply the transformation.
1246 call zaxpy(k-2,b(k),a(1,k),1,b(1),1)
1247 call zaxpy(k-2,b(k-1),a(1,k-1),1,b(1),1)
1248 60 continue
1250 c apply d inverse.
1252 ak = a(k,k)/dconjg(a(k-1,k))
1253 akm1 = a(k-1,k-1)/a(k-1,k)
1254 bk = b(k)/dconjg(a(k-1,k))
1255 bkm1 = b(k-1)/a(k-1,k)
1256 denom = ak*akm1 - 1.0d0
1257 b(k) = (akm1*bk - bkm1)/denom
1258 b(k-1) = (ak*bkm1 - bk)/denom
1259 k = k - 2
1260 70 continue
1261 go to 10
1262 80 continue
1264 c loop forward applying the transformations.
1266 k = 1
1267 90 if (k .gt. n) go to 160
1268 if (kpvt(k) .lt. 0) go to 120
1270 c 1 x 1 pivot block.
1272 if (k .eq. 1) go to 110
1274 c apply the transformation.
1276 b(k) = b(k) + zdotc(k-1,a(1,k),1,b(1),1)
1277 kp = kpvt(k)
1278 if (kp .eq. k) go to 100
1280 c interchange.
1282 temp = b(k)
1283 b(k) = b(kp)
1284 b(kp) = temp
1285 100 continue
1286 110 continue
1287 k = k + 1
1288 go to 150
1289 120 continue
1291 c 2 x 2 pivot block.
1293 if (k .eq. 1) go to 140
1295 c apply the transformation.
1297 b(k) = b(k) + zdotc(k-1,a(1,k),1,b(1),1)
1298 b(k+1) = b(k+1) + zdotc(k-1,a(1,k+1),1,b(1),1)
1299 kp = iabs(kpvt(k))
1300 if (kp .eq. k) go to 130
1302 c interchange.
1304 temp = b(k)
1305 b(k) = b(kp)
1306 b(kp) = temp
1307 130 continue
1308 140 continue
1309 k = k + 2
1310 150 continue
1311 go to 90
1312 160 continue
1313 return
1315 subroutine zsifa(a,lda,n,kpvt,info)
1316 integer lda,n,kpvt(1),info
1317 complex*16 a(lda,1)
1319 c zsifa factors a complex*16 symmetric matrix by elimination
1320 c with symmetric pivoting.
1322 c to solve a*x = b , follow zsifa by zsisl.
1323 c to compute inverse(a)*c , follow zsifa by zsisl.
1324 c to compute determinant(a) , follow zsifa by zsidi.
1325 c to compute inverse(a) , follow zsifa by zsidi.
1327 c on entry
1329 c a complex*16(lda,n)
1330 c the symmetric matrix to be factored.
1331 c only the diagonal and upper triangle are used.
1333 c lda integer
1334 c the leading dimension of the array a .
1336 c n integer
1337 c the order of the matrix a .
1339 c on return
1341 c a a block diagonal matrix and the multipliers which
1342 c were used to obtain it.
1343 c the factorization can be written a = u*d*trans(u)
1344 c where u is a product of permutation and unit
1345 c upper triangular matrices , trans(u) is the
1346 c transpose of u , and d is block diagonal
1347 c with 1 by 1 and 2 by 2 blocks.
1349 c kpvt integer(n)
1350 c an integer vector of pivot indices.
1352 c info integer
1353 c = 0 normal value.
1354 c = k if the k-th pivot block is singular. this is
1355 c not an error condition for this subroutine,
1356 c but it does indicate that zsisl or zsidi may
1357 c divide by zero if called.
1359 c linpack. this version dated 08/14/78 .
1360 c james bunch, univ. calif. san diego, argonne nat. lab.
1362 c subroutines and functions
1364 c blas zaxpy,zswap,izamax
1365 c fortran dabs,dmax1,dsqrt
1367 c internal variables
1369 complex*16 ak,akm1,bk,bkm1,denom,mulk,mulkm1,t
1370 double precision absakk,alpha,colmax,rowmax
1371 integer imax,imaxp1,j,jj,jmax,k,km1,km2,kstep,izamax
1372 logical swap
1374 complex*16 zdum
1375 double precision cabs1
1376 double precision dreal,dimag
1377 complex*16 zdumr,zdumi
1378 dreal(zdumr) = zdumr
1379 dimag(zdumi) = (0.0d0,-1.0d0)*zdumi
1380 cabs1(zdum) = dabs(dreal(zdum)) + dabs(dimag(zdum))
1382 c initialize
1384 c alpha is used in choosing pivot block size.
1385 alpha = (1.0d0 + dsqrt(17.0d0))/8.0d0
1387 info = 0
1389 c main loop on k, which goes from n to 1.
1391 k = n
1392 10 continue
1394 c leave the loop if k=0 or k=1.
1396 c ...exit
1397 if (k .eq. 0) go to 200
1398 if (k .gt. 1) go to 20
1399 kpvt(1) = 1
1400 if (cabs1(a(1,1)) .eq. 0.0d0) info = 1
1401 c ......exit
1402 go to 200
1403 20 continue
1405 c this section of code determines the kind of
1406 c elimination to be performed. when it is completed,
1407 c kstep will be set to the size of the pivot block, and
1408 c swap will be set to .true. if an interchange is
1409 c required.
1411 km1 = k - 1
1412 absakk = cabs1(a(k,k))
1414 c determine the largest off-diagonal element in
1415 c column k.
1417 imax = izamax(k-1,a(1,k),1)
1418 colmax = cabs1(a(imax,k))
1419 if (absakk .lt. alpha*colmax) go to 30
1420 kstep = 1
1421 swap = .false.
1422 go to 90
1423 30 continue
1425 c determine the largest off-diagonal element in
1426 c row imax.
1428 rowmax = 0.0d0
1429 imaxp1 = imax + 1
1430 do 40 j = imaxp1, k
1431 rowmax = dmax1(rowmax,cabs1(a(imax,j)))
1432 40 continue
1433 if (imax .eq. 1) go to 50
1434 jmax = izamax(imax-1,a(1,imax),1)
1435 rowmax = dmax1(rowmax,cabs1(a(jmax,imax)))
1436 50 continue
1437 if (cabs1(a(imax,imax)) .lt. alpha*rowmax) go to 60
1438 kstep = 1
1439 swap = .true.
1440 go to 80
1441 60 continue
1442 if (absakk .lt. alpha*colmax*(colmax/rowmax)) go to 70
1443 kstep = 1
1444 swap = .false.
1445 go to 80
1446 70 continue
1447 kstep = 2
1448 swap = imax .ne. km1
1449 80 continue
1450 90 continue
1451 if (dmax1(absakk,colmax) .ne. 0.0d0) go to 100
1453 c column k is zero. set info and iterate the loop.
1455 kpvt(k) = k
1456 info = k
1457 go to 190
1458 100 continue
1459 if (kstep .eq. 2) go to 140
1461 c 1 x 1 pivot block.
1463 if (.not.swap) go to 120
1465 c perform an interchange.
1467 call zswap(imax,a(1,imax),1,a(1,k),1)
1468 do 110 jj = imax, k
1469 j = k + imax - jj
1470 t = a(j,k)
1471 a(j,k) = a(imax,j)
1472 a(imax,j) = t
1473 110 continue
1474 120 continue
1476 c perform the elimination.
1478 do 130 jj = 1, km1
1479 j = k - jj
1480 mulk = -a(j,k)/a(k,k)
1481 t = mulk
1482 call zaxpy(j,t,a(1,k),1,a(1,j),1)
1483 a(j,k) = mulk
1484 130 continue
1486 c set the pivot array.
1488 kpvt(k) = k
1489 if (swap) kpvt(k) = imax
1490 go to 190
1491 140 continue
1493 c 2 x 2 pivot block.
1495 if (.not.swap) go to 160
1497 c perform an interchange.
1499 call zswap(imax,a(1,imax),1,a(1,k-1),1)
1500 do 150 jj = imax, km1
1501 j = km1 + imax - jj
1502 t = a(j,k-1)
1503 a(j,k-1) = a(imax,j)
1504 a(imax,j) = t
1505 150 continue
1506 t = a(k-1,k)
1507 a(k-1,k) = a(imax,k)
1508 a(imax,k) = t
1509 160 continue
1511 c perform the elimination.
1513 km2 = k - 2
1514 if (km2 .eq. 0) go to 180
1515 ak = a(k,k)/a(k-1,k)
1516 akm1 = a(k-1,k-1)/a(k-1,k)
1517 denom = 1.0d0 - ak*akm1
1518 do 170 jj = 1, km2
1519 j = km1 - jj
1520 bk = a(j,k)/a(k-1,k)
1521 bkm1 = a(j,k-1)/a(k-1,k)
1522 mulk = (akm1*bk - bkm1)/denom
1523 mulkm1 = (ak*bkm1 - bk)/denom
1524 t = mulk
1525 call zaxpy(j,t,a(1,k),1,a(1,j),1)
1526 t = mulkm1
1527 call zaxpy(j,t,a(1,k-1),1,a(1,j),1)
1528 a(j,k) = mulk
1529 a(j,k-1) = mulkm1
1530 170 continue
1531 180 continue
1533 c set the pivot array.
1535 kpvt(k) = 1 - k
1536 if (swap) kpvt(k) = -imax
1537 kpvt(k-1) = kpvt(k)
1538 190 continue
1539 k = k - kstep
1540 go to 10
1541 200 continue
1542 return
1544 subroutine zsisl(a,lda,n,kpvt,b)
1545 integer lda,n,kpvt(1)
1546 complex*16 a(lda,1),b(1)
1548 c zsisl solves the complex*16 symmetric system
1549 c a * x = b
1550 c using the factors computed by zsifa.
1552 c on entry
1554 c a complex*16(lda,n)
1555 c the output from zsifa.
1557 c lda integer
1558 c the leading dimension of the array a .
1560 c n integer
1561 c the order of the matrix a .
1563 c kpvt integer(n)
1564 c the pivot vector from zsifa.
1566 c b complex*16(n)
1567 c the right hand side vector.
1569 c on return
1571 c b the solution vector x .
1573 c error condition
1575 c a division by zero may occur if zsico has set rcond .eq. 0.0
1576 c or zsifa has set info .ne. 0 .
1578 c to compute inverse(a) * c where c is a matrix
1579 c with p columns
1580 c call zsifa(a,lda,n,kpvt,info)
1581 c if (info .ne. 0) go to ...
1582 c do 10 j = 1, p
1583 c call zsisl(a,lda,n,kpvt,c(1,j))
1584 c 10 continue
1586 c linpack. this version dated 08/14/78 .
1587 c james bunch, univ. calif. san diego, argonne nat. lab.
1589 c subroutines and functions
1591 c blas zaxpy,zdotu
1592 c fortran iabs
1594 c internal variables.
1596 complex*16 ak,akm1,bk,bkm1,zdotu,denom,temp
1597 integer k,kp
1599 c loop backward applying the transformations and
1600 c d inverse to b.
1602 k = n
1603 10 if (k .eq. 0) go to 80
1604 if (kpvt(k) .lt. 0) go to 40
1606 c 1 x 1 pivot block.
1608 if (k .eq. 1) go to 30
1609 kp = kpvt(k)
1610 if (kp .eq. k) go to 20
1612 c interchange.
1614 temp = b(k)
1615 b(k) = b(kp)
1616 b(kp) = temp
1617 20 continue
1619 c apply the transformation.
1621 call zaxpy(k-1,b(k),a(1,k),1,b(1),1)
1622 30 continue
1624 c apply d inverse.
1626 b(k) = b(k)/a(k,k)
1627 k = k - 1
1628 go to 70
1629 40 continue
1631 c 2 x 2 pivot block.
1633 if (k .eq. 2) go to 60
1634 kp = iabs(kpvt(k))
1635 if (kp .eq. k - 1) go to 50
1637 c interchange.
1639 temp = b(k-1)
1640 b(k-1) = b(kp)
1641 b(kp) = temp
1642 50 continue
1644 c apply the transformation.
1646 call zaxpy(k-2,b(k),a(1,k),1,b(1),1)
1647 call zaxpy(k-2,b(k-1),a(1,k-1),1,b(1),1)
1648 60 continue
1650 c apply d inverse.
1652 ak = a(k,k)/a(k-1,k)
1653 akm1 = a(k-1,k-1)/a(k-1,k)
1654 bk = b(k)/a(k-1,k)
1655 bkm1 = b(k-1)/a(k-1,k)
1656 denom = ak*akm1 - 1.0d0
1657 b(k) = (akm1*bk - bkm1)/denom
1658 b(k-1) = (ak*bkm1 - bk)/denom
1659 k = k - 2
1660 70 continue
1661 go to 10
1662 80 continue
1664 c loop forward applying the transformations.
1666 k = 1
1667 90 if (k .gt. n) go to 160
1668 if (kpvt(k) .lt. 0) go to 120
1670 c 1 x 1 pivot block.
1672 if (k .eq. 1) go to 110
1674 c apply the transformation.
1676 b(k) = b(k) + zdotu(k-1,a(1,k),1,b(1),1)
1677 kp = kpvt(k)
1678 if (kp .eq. k) go to 100
1680 c interchange.
1682 temp = b(k)
1683 b(k) = b(kp)
1684 b(kp) = temp
1685 100 continue
1686 110 continue
1687 k = k + 1
1688 go to 150
1689 120 continue
1691 c 2 x 2 pivot block.
1693 if (k .eq. 1) go to 140
1695 c apply the transformation.
1697 b(k) = b(k) + zdotu(k-1,a(1,k),1,b(1),1)
1698 b(k+1) = b(k+1) + zdotu(k-1,a(1,k+1),1,b(1),1)
1699 kp = iabs(kpvt(k))
1700 if (kp .eq. k) go to 130
1702 c interchange.
1704 temp = b(k)
1705 b(k) = b(kp)
1706 b(kp) = temp
1707 130 continue
1708 140 continue
1709 k = k + 2
1710 150 continue
1711 go to 90
1712 160 continue
1713 return