| 1 | * This is a lightweight substitute to the external LAPACK routines |
| 2 | * used by EXPOKIT. It is supplied to ensure that EXPOKIT is |
| 3 | * self-contained and can still run if LAPACK is not yet installed |
| 4 | * in your environement. |
| 5 | *----------------------------------------------------------------------| |
| 6 | subroutine DGESV( N, M, A,LDA, IPIV, B,LDB, IFLAG ) |
| 7 | integer N, M, LDA, LDB, IPIV(N), IFLAG |
| 8 | double precision A(LDA,N), B(LDB,M) |
| 9 | call DGEFA( A,LDA, N, IPIV, IFLAG ) |
| 10 | if ( IFLAG.ne.0 ) stop "Error in DGESV (LU factorisation)" |
| 11 | do j = 1,M |
| 12 | call DGESL( A,LDA, N, IPIV,B(1,j), 0 ) |
| 13 | enddo |
| 14 | end |
| 15 | *----------------------------------------------------------------------| |
| 16 | subroutine DSYSV(UPLO, N,M, A,LDA, IPIV, B,LDB, WRK,LWRK, IFLAG ) |
| 17 | character UPLO*1 |
| 18 | integer N, M, LDA, LDB, LWRK, IFLAG, IPIV(N) |
| 19 | double precision A(LDA,N), B(LDB,M), WRK(LWRK) |
| 20 | call DSIFA( A,LDA, N, IPIV, IFLAG ) |
| 21 | if ( IFLAG.ne.0 ) stop "Error in DSYSV (LDL' factorisation)" |
| 22 | do j = 1,M |
| 23 | call DSISL( A,LDA, N, IPIV, B(1,j) ) |
| 24 | enddo |
| 25 | end |
| 26 | *----------------------------------------------------------------------| |
| 27 | subroutine ZGESV( N, M, A,LDA, IPIV, B,LDB, IFLAG ) |
| 28 | integer N, M, LDA, LDB, IPIV(N), IFLAG |
| 29 | complex*16 A(LDA,N), B(LDB,M) |
| 30 | call ZGEFA( A,LDA, N, IPIV, IFLAG ) |
| 31 | if ( IFLAG.ne.0 ) stop "Error in ZGESV (LU factorisation)" |
| 32 | do j = 1,M |
| 33 | call ZGESL( A,LDA, N, IPIV,B(1,j), 0 ) |
| 34 | enddo |
| 35 | end |
| 36 | *----------------------------------------------------------------------| |
| 37 | subroutine ZHESV(UPLO, N,M, A,LDA, IPIV, B,LDB, WRK,LWRK, IFLAG ) |
| 38 | character UPLO*1 |
| 39 | integer N, M, LDA, LDB, LWRK, IFLAG, IPIV(N) |
| 40 | complex*16 A(LDA,N), B(LDB,M), WRK(LWRK) |
| 41 | call ZHIFA( A,LDA, N, IPIV, IFLAG ) |
| 42 | if ( IFLAG.ne.0 ) stop "Error in ZHESV (LDL' factorisation)" |
| 43 | do j = 1,M |
| 44 | call ZHISL( A,LDA, N, IPIV,B(1,j) ) |
| 45 | enddo |
| 46 | end |
| 47 | *----------------------------------------------------------------------| |
| 48 | subroutine ZSYSV(UPLO, N,M, A,LDA, IPIV, B,LDB, WRK,LWRK, IFLAG ) |
| 49 | character UPLO*1 |
| 50 | integer N, M, LDA, LDB, LWRK, IFLAG, IPIV(N) |
| 51 | complex*16 A(LDA,N), B(LDB,M), WRK(LWRK) |
| 52 | call ZSIFA( A,LDA, N, IPIV, IFLAG ) |
| 53 | if ( IFLAG.ne.0 ) stop "Error in ZSYSV (LDL' factorisation)" |
| 54 | do j = 1,M |
| 55 | call ZSISL( A,LDA, N, IPIV, B(1,j) ) |
| 56 | enddo |
| 57 | end |
| 58 | *----------------------------------------------------------------------| |
| 59 | *----------------------------------------------------------------------| |
| 60 | *----------------------------------------------------------------------| |
| 61 | subroutine dgefa(a,lda,n,ipvt,info) |
| 62 | integer lda,n,ipvt(n),info |
| 63 | double precision a(lda,n) |
| 64 | c |
| 65 | c dgefa factors a double precision matrix by gaussian elimination. |
| 66 | c |
| 67 | c dgefa is usually called by dgeco, but it can be called |
| 68 | c directly with a saving in time if rcond is not needed. |
| 69 | c (time for dgeco) = (1 + 9/n)*(time for dgefa) . |
| 70 | c |
| 71 | c on entry |
| 72 | c |
| 73 | c a double precision(lda, n) |
| 74 | c the matrix to be factored. |
| 75 | c |
| 76 | c lda integer |
| 77 | c the leading dimension of the array a . |
| 78 | c |
| 79 | c n integer |
| 80 | c the order of the matrix a . |
| 81 | c |
| 82 | c on return |
| 83 | c |
| 84 | c a an upper triangular matrix and the multipliers |
| 85 | c which were used to obtain it. |
| 86 | c the factorization can be written a = l*u where |
| 87 | c l is a product of permutation and unit lower |
| 88 | c triangular matrices and u is upper triangular. |
| 89 | c |
| 90 | c ipvt integer(n) |
| 91 | c an integer vector of pivot indices. |
| 92 | c |
| 93 | c info integer |
| 94 | c = 0 normal value. |
| 95 | c = k if u(k,k) .eq. 0.0 . this is not an error |
| 96 | c condition for this subroutine, but it does |
| 97 | c indicate that dgesl or dgedi will divide by zero |
| 98 | c if called. use rcond in dgeco for a reliable |
| 99 | c indication of singularity. |
| 100 | c |
| 101 | c linpack. this version dated 08/14/78 . |
| 102 | c cleve moler, university of new mexico, argonne national lab. |
| 103 | c |
| 104 | c subroutines and functions |
| 105 | c |
| 106 | c blas daxpy,dscal,idamax |
| 107 | c |
| 108 | c internal variables |
| 109 | c |
| 110 | double precision t |
| 111 | integer idamax,j,k,kp1,l,nm1 |
| 112 | c |
| 113 | c |
| 114 | c gaussian elimination with partial pivoting |
| 115 | c |
| 116 | info = 0 |
| 117 | nm1 = n - 1 |
| 118 | if (nm1 .lt. 1) go to 70 |
| 119 | do 60 k = 1, nm1 |
| 120 | kp1 = k + 1 |
| 121 | c |
| 122 | c find l = pivot index |
| 123 | c |
| 124 | l = idamax(n-k+1,a(k,k),1) + k - 1 |
| 125 | ipvt(k) = l |
| 126 | c |
| 127 | c zero pivot implies this column already triangularized |
| 128 | c |
| 129 | if (a(l,k) .eq. 0.0d0) go to 40 |
| 130 | c |
| 131 | c interchange if necessary |
| 132 | c |
| 133 | if (l .eq. k) go to 10 |
| 134 | t = a(l,k) |
| 135 | a(l,k) = a(k,k) |
| 136 | a(k,k) = t |
| 137 | 10 continue |
| 138 | c |
| 139 | c compute multipliers |
| 140 | c |
| 141 | t = -1.0d0/a(k,k) |
| 142 | call dscal(n-k,t,a(k+1,k),1) |
| 143 | c |
| 144 | c row elimination with column indexing |
| 145 | c |
| 146 | do 30 j = kp1, n |
| 147 | t = a(l,j) |
| 148 | if (l .eq. k) go to 20 |
| 149 | a(l,j) = a(k,j) |
| 150 | a(k,j) = t |
| 151 | 20 continue |
| 152 | call daxpy(n-k,t,a(k+1,k),1,a(k+1,j),1) |
| 153 | 30 continue |
| 154 | go to 50 |
| 155 | 40 continue |
| 156 | info = k |
| 157 | 50 continue |
| 158 | 60 continue |
| 159 | 70 continue |
| 160 | ipvt(n) = n |
| 161 | if (a(n,n) .eq. 0.0d0) info = n |
| 162 | return |
| 163 | end |
| 164 | *----------------------------------------------------------------------| |
| 165 | subroutine dgesl(a,lda,n,ipvt,b,job) |
| 166 | integer lda,n,ipvt(n),job |
| 167 | double precision a(lda,n),b(n) |
| 168 | c |
| 169 | c dgesl solves the double precision system |
| 170 | c a * x = b or trans(a) * x = b |
| 171 | c using the factors computed by dgeco or dgefa. |
| 172 | c |
| 173 | c on entry |
| 174 | c |
| 175 | c a double precision(lda, n) |
| 176 | c the output from dgeco or dgefa. |
| 177 | c |
| 178 | c lda integer |
| 179 | c the leading dimension of the array a . |
| 180 | c |
| 181 | c n integer |
| 182 | c the order of the matrix a . |
| 183 | c |
| 184 | c ipvt integer(n) |
| 185 | c the pivot vector from dgeco or dgefa. |
| 186 | c |
| 187 | c b double precision(n) |
| 188 | c the right hand side vector. |
| 189 | c |
| 190 | c job integer |
| 191 | c = 0 to solve a*x = b , |
| 192 | c = nonzero to solve trans(a)*x = b where |
| 193 | c trans(a) is the transpose. |
| 194 | c |
| 195 | c on return |
| 196 | c |
| 197 | c b the solution vector x . |
| 198 | c |
| 199 | c error condition |
| 200 | c |
| 201 | c a division by zero will occur if the input factor contains a |
| 202 | c zero on the diagonal. technically this indicates singularity |
| 203 | c but it is often caused by improper arguments or improper |
| 204 | c setting of lda . it will not occur if the subroutines are |
| 205 | c called correctly and if dgeco has set rcond .gt. 0.0 |
| 206 | c or dgefa has set info .eq. 0 . |
| 207 | c |
| 208 | c to compute inverse(a) * c where c is a matrix |
| 209 | c with p columns |
| 210 | c call dgeco(a,lda,n,ipvt,rcond,z) |
| 211 | c if (rcond is too small) go to ... |
| 212 | c do 10 j = 1, p |
| 213 | c call dgesl(a,lda,n,ipvt,c(1,j),0) |
| 214 | c 10 continue |
| 215 | c |
| 216 | c linpack. this version dated 08/14/78 . |
| 217 | c cleve moler, university of new mexico, argonne national lab. |
| 218 | c |
| 219 | c subroutines and functions |
| 220 | c |
| 221 | c blas daxpy,ddot |
| 222 | c |
| 223 | c internal variables |
| 224 | c |
| 225 | double precision ddot,t |
| 226 | integer k,kb,l,nm1 |
| 227 | c |
| 228 | nm1 = n - 1 |
| 229 | if (job .ne. 0) go to 50 |
| 230 | c |
| 231 | c job = 0 , solve a * x = b |
| 232 | c first solve l*y = b |
| 233 | c |
| 234 | if (nm1 .lt. 1) go to 30 |
| 235 | do 20 k = 1, nm1 |
| 236 | l = ipvt(k) |
| 237 | t = b(l) |
| 238 | if (l .eq. k) go to 10 |
| 239 | b(l) = b(k) |
| 240 | b(k) = t |
| 241 | 10 continue |
| 242 | call daxpy(n-k,t,a(k+1,k),1,b(k+1),1) |
| 243 | 20 continue |
| 244 | 30 continue |
| 245 | c |
| 246 | c now solve u*x = y |
| 247 | c |
| 248 | do 40 kb = 1, n |
| 249 | k = n + 1 - kb |
| 250 | b(k) = b(k)/a(k,k) |
| 251 | t = -b(k) |
| 252 | call daxpy(k-1,t,a(1,k),1,b(1),1) |
| 253 | 40 continue |
| 254 | go to 100 |
| 255 | 50 continue |
| 256 | c |
| 257 | c job = nonzero, solve trans(a) * x = b |
| 258 | c first solve trans(u)*y = b |
| 259 | c |
| 260 | do 60 k = 1, n |
| 261 | t = ddot(k-1,a(1,k),1,b(1),1) |
| 262 | b(k) = (b(k) - t)/a(k,k) |
| 263 | 60 continue |
| 264 | c |
| 265 | c now solve trans(l)*x = y |
| 266 | c |
| 267 | if (nm1 .lt. 1) go to 90 |
| 268 | do 80 kb = 1, nm1 |
| 269 | k = n - kb |
| 270 | b(k) = b(k) + ddot(n-k,a(k+1,k),1,b(k+1),1) |
| 271 | l = ipvt(k) |
| 272 | if (l .eq. k) go to 70 |
| 273 | t = b(l) |
| 274 | b(l) = b(k) |
| 275 | b(k) = t |
| 276 | 70 continue |
| 277 | 80 continue |
| 278 | 90 continue |
| 279 | 100 continue |
| 280 | return |
| 281 | end |
| 282 | |
| 283 | subroutine dsifa(a,lda,n,kpvt,info) |
| 284 | integer lda,n,kpvt(1),info |
| 285 | double precision a(lda,1) |
| 286 | c |
| 287 | c dsifa factors a double precision symmetric matrix by elimination |
| 288 | c with symmetric pivoting. |
| 289 | c |
| 290 | c to solve a*x = b , follow dsifa by dsisl. |
| 291 | c to compute inverse(a)*c , follow dsifa by dsisl. |
| 292 | c to compute determinant(a) , follow dsifa by dsidi. |
| 293 | c to compute inertia(a) , follow dsifa by dsidi. |
| 294 | c to compute inverse(a) , follow dsifa by dsidi. |
| 295 | c |
| 296 | c on entry |
| 297 | c |
| 298 | c a double precision(lda,n) |
| 299 | c the symmetric matrix to be factored. |
| 300 | c only the diagonal and upper triangle are used. |
| 301 | c |
| 302 | c lda integer |
| 303 | c the leading dimension of the array a . |
| 304 | c |
| 305 | c n integer |
| 306 | c the order of the matrix a . |
| 307 | c |
| 308 | c on return |
| 309 | c |
| 310 | c a a block diagonal matrix and the multipliers which |
| 311 | c were used to obtain it. |
| 312 | c the factorization can be written a = u*d*trans(u) |
| 313 | c where u is a product of permutation and unit |
| 314 | c upper triangular matrices , trans(u) is the |
| 315 | c transpose of u , and d is block diagonal |
| 316 | c with 1 by 1 and 2 by 2 blocks. |
| 317 | c |
| 318 | c kpvt integer(n) |
| 319 | c an integer vector of pivot indices. |
| 320 | c |
| 321 | c info integer |
| 322 | c = 0 normal value. |
| 323 | c = k if the k-th pivot block is singular. this is |
| 324 | c not an error condition for this subroutine, |
| 325 | c but it does indicate that dsisl or dsidi may |
| 326 | c divide by zero if called. |
| 327 | c |
| 328 | c linpack. this version dated 08/14/78 . |
| 329 | c james bunch, univ. calif. san diego, argonne nat. lab. |
| 330 | c |
| 331 | c subroutines and functions |
| 332 | c |
| 333 | c blas daxpy,dswap,idamax |
| 334 | c fortran dabs,dmax1,dsqrt |
| 335 | c |
| 336 | c internal variables |
| 337 | c |
| 338 | double precision ak,akm1,bk,bkm1,denom,mulk,mulkm1,t |
| 339 | double precision absakk,alpha,colmax,rowmax |
| 340 | integer imax,imaxp1,j,jj,jmax,k,km1,km2,kstep,idamax |
| 341 | logical swap |
| 342 | c |
| 343 | c |
| 344 | c initialize |
| 345 | c |
| 346 | c alpha is used in choosing pivot block size. |
| 347 | alpha = (1.0d0 + dsqrt(17.0d0))/8.0d0 |
| 348 | c |
| 349 | info = 0 |
| 350 | c |
| 351 | c main loop on k, which goes from n to 1. |
| 352 | c |
| 353 | k = n |
| 354 | 10 continue |
| 355 | c |
| 356 | c leave the loop if k=0 or k=1. |
| 357 | c |
| 358 | c ...exit |
| 359 | if (k .eq. 0) go to 200 |
| 360 | if (k .gt. 1) go to 20 |
| 361 | kpvt(1) = 1 |
| 362 | if (a(1,1) .eq. 0.0d0) info = 1 |
| 363 | c ......exit |
| 364 | go to 200 |
| 365 | 20 continue |
| 366 | c |
| 367 | c this section of code determines the kind of |
| 368 | c elimination to be performed. when it is completed, |
| 369 | c kstep will be set to the size of the pivot block, and |
| 370 | c swap will be set to .true. if an interchange is |
| 371 | c required. |
| 372 | c |
| 373 | km1 = k - 1 |
| 374 | absakk = dabs(a(k,k)) |
| 375 | c |
| 376 | c determine the largest off-diagonal element in |
| 377 | c column k. |
| 378 | c |
| 379 | imax = idamax(k-1,a(1,k),1) |
| 380 | colmax = dabs(a(imax,k)) |
| 381 | if (absakk .lt. alpha*colmax) go to 30 |
| 382 | kstep = 1 |
| 383 | swap = .false. |
| 384 | go to 90 |
| 385 | 30 continue |
| 386 | c |
| 387 | c determine the largest off-diagonal element in |
| 388 | c row imax. |
| 389 | c |
| 390 | rowmax = 0.0d0 |
| 391 | imaxp1 = imax + 1 |
| 392 | do 40 j = imaxp1, k |
| 393 | rowmax = dmax1(rowmax,dabs(a(imax,j))) |
| 394 | 40 continue |
| 395 | if (imax .eq. 1) go to 50 |
| 396 | jmax = idamax(imax-1,a(1,imax),1) |
| 397 | rowmax = dmax1(rowmax,dabs(a(jmax,imax))) |
| 398 | 50 continue |
| 399 | if (dabs(a(imax,imax)) .lt. alpha*rowmax) go to 60 |
| 400 | kstep = 1 |
| 401 | swap = .true. |
| 402 | go to 80 |
| 403 | 60 continue |
| 404 | if (absakk .lt. alpha*colmax*(colmax/rowmax)) go to 70 |
| 405 | kstep = 1 |
| 406 | swap = .false. |
| 407 | go to 80 |
| 408 | 70 continue |
| 409 | kstep = 2 |
| 410 | swap = imax .ne. km1 |
| 411 | 80 continue |
| 412 | 90 continue |
| 413 | if (dmax1(absakk,colmax) .ne. 0.0d0) go to 100 |
| 414 | c |
| 415 | c column k is zero. set info and iterate the loop. |
| 416 | c |
| 417 | kpvt(k) = k |
| 418 | info = k |
| 419 | go to 190 |
| 420 | 100 continue |
| 421 | if (kstep .eq. 2) go to 140 |
| 422 | c |
| 423 | c 1 x 1 pivot block. |
| 424 | c |
| 425 | if (.not.swap) go to 120 |
| 426 | c |
| 427 | c perform an interchange. |
| 428 | c |
| 429 | call dswap(imax,a(1,imax),1,a(1,k),1) |
| 430 | do 110 jj = imax, k |
| 431 | j = k + imax - jj |
| 432 | t = a(j,k) |
| 433 | a(j,k) = a(imax,j) |
| 434 | a(imax,j) = t |
| 435 | 110 continue |
| 436 | 120 continue |
| 437 | c |
| 438 | c perform the elimination. |
| 439 | c |
| 440 | do 130 jj = 1, km1 |
| 441 | j = k - jj |
| 442 | mulk = -a(j,k)/a(k,k) |
| 443 | t = mulk |
| 444 | call daxpy(j,t,a(1,k),1,a(1,j),1) |
| 445 | a(j,k) = mulk |
| 446 | 130 continue |
| 447 | c |
| 448 | c set the pivot array. |
| 449 | c |
| 450 | kpvt(k) = k |
| 451 | if (swap) kpvt(k) = imax |
| 452 | go to 190 |
| 453 | 140 continue |
| 454 | c |
| 455 | c 2 x 2 pivot block. |
| 456 | c |
| 457 | if (.not.swap) go to 160 |
| 458 | c |
| 459 | c perform an interchange. |
| 460 | c |
| 461 | call dswap(imax,a(1,imax),1,a(1,k-1),1) |
| 462 | do 150 jj = imax, km1 |
| 463 | j = km1 + imax - jj |
| 464 | t = a(j,k-1) |
| 465 | a(j,k-1) = a(imax,j) |
| 466 | a(imax,j) = t |
| 467 | 150 continue |
| 468 | t = a(k-1,k) |
| 469 | a(k-1,k) = a(imax,k) |
| 470 | a(imax,k) = t |
| 471 | 160 continue |
| 472 | c |
| 473 | c perform the elimination. |
| 474 | c |
| 475 | km2 = k - 2 |
| 476 | if (km2 .eq. 0) go to 180 |
| 477 | ak = a(k,k)/a(k-1,k) |
| 478 | akm1 = a(k-1,k-1)/a(k-1,k) |
| 479 | denom = 1.0d0 - ak*akm1 |
| 480 | do 170 jj = 1, km2 |
| 481 | j = km1 - jj |
| 482 | bk = a(j,k)/a(k-1,k) |
| 483 | bkm1 = a(j,k-1)/a(k-1,k) |
| 484 | mulk = (akm1*bk - bkm1)/denom |
| 485 | mulkm1 = (ak*bkm1 - bk)/denom |
| 486 | t = mulk |
| 487 | call daxpy(j,t,a(1,k),1,a(1,j),1) |
| 488 | t = mulkm1 |
| 489 | call daxpy(j,t,a(1,k-1),1,a(1,j),1) |
| 490 | a(j,k) = mulk |
| 491 | a(j,k-1) = mulkm1 |
| 492 | 170 continue |
| 493 | 180 continue |
| 494 | c |
| 495 | c set the pivot array. |
| 496 | c |
| 497 | kpvt(k) = 1 - k |
| 498 | if (swap) kpvt(k) = -imax |
| 499 | kpvt(k-1) = kpvt(k) |
| 500 | 190 continue |
| 501 | k = k - kstep |
| 502 | go to 10 |
| 503 | 200 continue |
| 504 | return |
| 505 | end |
| 506 | subroutine dsisl(a,lda,n,kpvt,b) |
| 507 | integer lda,n,kpvt(1) |
| 508 | double precision a(lda,1),b(1) |
| 509 | c |
| 510 | c dsisl solves the double precision symmetric system |
| 511 | c a * x = b |
| 512 | c using the factors computed by dsifa. |
| 513 | c |
| 514 | c on entry |
| 515 | c |
| 516 | c a double precision(lda,n) |
| 517 | c the output from dsifa. |
| 518 | c |
| 519 | c lda integer |
| 520 | c the leading dimension of the array a . |
| 521 | c |
| 522 | c n integer |
| 523 | c the order of the matrix a . |
| 524 | c |
| 525 | c kpvt integer(n) |
| 526 | c the pivot vector from dsifa. |
| 527 | c |
| 528 | c b double precision(n) |
| 529 | c the right hand side vector. |
| 530 | c |
| 531 | c on return |
| 532 | c |
| 533 | c b the solution vector x . |
| 534 | c |
| 535 | c error condition |
| 536 | c |
| 537 | c a division by zero may occur if dsico has set rcond .eq. 0.0 |
| 538 | c or dsifa has set info .ne. 0 . |
| 539 | c |
| 540 | c to compute inverse(a) * c where c is a matrix |
| 541 | c with p columns |
| 542 | c call dsifa(a,lda,n,kpvt,info) |
| 543 | c if (info .ne. 0) go to ... |
| 544 | c do 10 j = 1, p |
| 545 | c call dsisl(a,lda,n,kpvt,c(1,j)) |
| 546 | c 10 continue |
| 547 | c |
| 548 | c linpack. this version dated 08/14/78 . |
| 549 | c james bunch, univ. calif. san diego, argonne nat. lab. |
| 550 | c |
| 551 | c subroutines and functions |
| 552 | c |
| 553 | c blas daxpy,ddot |
| 554 | c fortran iabs |
| 555 | c |
| 556 | c internal variables. |
| 557 | c |
| 558 | double precision ak,akm1,bk,bkm1,ddot,denom,temp |
| 559 | integer k,kp |
| 560 | c |
| 561 | c loop backward applying the transformations and |
| 562 | c d inverse to b. |
| 563 | c |
| 564 | k = n |
| 565 | 10 if (k .eq. 0) go to 80 |
| 566 | if (kpvt(k) .lt. 0) go to 40 |
| 567 | c |
| 568 | c 1 x 1 pivot block. |
| 569 | c |
| 570 | if (k .eq. 1) go to 30 |
| 571 | kp = kpvt(k) |
| 572 | if (kp .eq. k) go to 20 |
| 573 | c |
| 574 | c interchange. |
| 575 | c |
| 576 | temp = b(k) |
| 577 | b(k) = b(kp) |
| 578 | b(kp) = temp |
| 579 | 20 continue |
| 580 | c |
| 581 | c apply the transformation. |
| 582 | c |
| 583 | call daxpy(k-1,b(k),a(1,k),1,b(1),1) |
| 584 | 30 continue |
| 585 | c |
| 586 | c apply d inverse. |
| 587 | c |
| 588 | b(k) = b(k)/a(k,k) |
| 589 | k = k - 1 |
| 590 | go to 70 |
| 591 | 40 continue |
| 592 | c |
| 593 | c 2 x 2 pivot block. |
| 594 | c |
| 595 | if (k .eq. 2) go to 60 |
| 596 | kp = iabs(kpvt(k)) |
| 597 | if (kp .eq. k - 1) go to 50 |
| 598 | c |
| 599 | c interchange. |
| 600 | c |
| 601 | temp = b(k-1) |
| 602 | b(k-1) = b(kp) |
| 603 | b(kp) = temp |
| 604 | 50 continue |
| 605 | c |
| 606 | c apply the transformation. |
| 607 | c |
| 608 | call daxpy(k-2,b(k),a(1,k),1,b(1),1) |
| 609 | call daxpy(k-2,b(k-1),a(1,k-1),1,b(1),1) |
| 610 | 60 continue |
| 611 | c |
| 612 | c apply d inverse. |
| 613 | c |
| 614 | ak = a(k,k)/a(k-1,k) |
| 615 | akm1 = a(k-1,k-1)/a(k-1,k) |
| 616 | bk = b(k)/a(k-1,k) |
| 617 | bkm1 = b(k-1)/a(k-1,k) |
| 618 | denom = ak*akm1 - 1.0d0 |
| 619 | b(k) = (akm1*bk - bkm1)/denom |
| 620 | b(k-1) = (ak*bkm1 - bk)/denom |
| 621 | k = k - 2 |
| 622 | 70 continue |
| 623 | go to 10 |
| 624 | 80 continue |
| 625 | c |
| 626 | c loop forward applying the transformations. |
| 627 | c |
| 628 | k = 1 |
| 629 | 90 if (k .gt. n) go to 160 |
| 630 | if (kpvt(k) .lt. 0) go to 120 |
| 631 | c |
| 632 | c 1 x 1 pivot block. |
| 633 | c |
| 634 | if (k .eq. 1) go to 110 |
| 635 | c |
| 636 | c apply the transformation. |
| 637 | c |
| 638 | b(k) = b(k) + ddot(k-1,a(1,k),1,b(1),1) |
| 639 | kp = kpvt(k) |
| 640 | if (kp .eq. k) go to 100 |
| 641 | c |
| 642 | c interchange. |
| 643 | c |
| 644 | temp = b(k) |
| 645 | b(k) = b(kp) |
| 646 | b(kp) = temp |
| 647 | 100 continue |
| 648 | 110 continue |
| 649 | k = k + 1 |
| 650 | go to 150 |
| 651 | 120 continue |
| 652 | c |
| 653 | c 2 x 2 pivot block. |
| 654 | c |
| 655 | if (k .eq. 1) go to 140 |
| 656 | c |
| 657 | c apply the transformation. |
| 658 | c |
| 659 | b(k) = b(k) + ddot(k-1,a(1,k),1,b(1),1) |
| 660 | b(k+1) = b(k+1) + ddot(k-1,a(1,k+1),1,b(1),1) |
| 661 | kp = iabs(kpvt(k)) |
| 662 | if (kp .eq. k) go to 130 |
| 663 | c |
| 664 | c interchange. |
| 665 | c |
| 666 | temp = b(k) |
| 667 | b(k) = b(kp) |
| 668 | b(kp) = temp |
| 669 | 130 continue |
| 670 | 140 continue |
| 671 | k = k + 2 |
| 672 | 150 continue |
| 673 | go to 90 |
| 674 | 160 continue |
| 675 | return |
| 676 | end |
| 677 | subroutine zgefa(a,lda,n,ipvt,info) |
| 678 | integer lda,n,ipvt(1),info |
| 679 | complex*16 a(lda,1) |
| 680 | c |
| 681 | c zgefa factors a complex*16 matrix by gaussian elimination. |
| 682 | c |
| 683 | c zgefa is usually called by zgeco, but it can be called |
| 684 | c directly with a saving in time if rcond is not needed. |
| 685 | c (time for zgeco) = (1 + 9/n)*(time for zgefa) . |
| 686 | c |
| 687 | c on entry |
| 688 | c |
| 689 | c a complex*16(lda, n) |
| 690 | c the matrix to be factored. |
| 691 | c |
| 692 | c lda integer |
| 693 | c the leading dimension of the array a . |
| 694 | c |
| 695 | c n integer |
| 696 | c the order of the matrix a . |
| 697 | c |
| 698 | c on return |
| 699 | c |
| 700 | c a an upper triangular matrix and the multipliers |
| 701 | c which were used to obtain it. |
| 702 | c the factorization can be written a = l*u where |
| 703 | c l is a product of permutation and unit lower |
| 704 | c triangular matrices and u is upper triangular. |
| 705 | c |
| 706 | c ipvt integer(n) |
| 707 | c an integer vector of pivot indices. |
| 708 | c |
| 709 | c info integer |
| 710 | c = 0 normal value. |
| 711 | c = k if u(k,k) .eq. 0.0 . this is not an error |
| 712 | c condition for this subroutine, but it does |
| 713 | c indicate that zgesl or zgedi will divide by zero |
| 714 | c if called. use rcond in zgeco for a reliable |
| 715 | c indication of singularity. |
| 716 | c |
| 717 | c linpack. this version dated 08/14/78 . |
| 718 | c cleve moler, university of new mexico, argonne national lab. |
| 719 | c |
| 720 | c subroutines and functions |
| 721 | c |
| 722 | c blas zaxpy,zscal,izamax |
| 723 | c fortran dabs |
| 724 | c |
| 725 | c internal variables |
| 726 | c |
| 727 | complex*16 t |
| 728 | integer izamax,j,k,kp1,l,nm1 |
| 729 | c |
| 730 | complex*16 zdum |
| 731 | double precision cabs1 |
| 732 | double precision dreal,dimag |
| 733 | complex*16 zdumr,zdumi |
| 734 | dreal(zdumr) = zdumr |
| 735 | dimag(zdumi) = (0.0d0,-1.0d0)*zdumi |
| 736 | cabs1(zdum) = dabs(dreal(zdum)) + dabs(dimag(zdum)) |
| 737 | c |
| 738 | c gaussian elimination with partial pivoting |
| 739 | c |
| 740 | info = 0 |
| 741 | nm1 = n - 1 |
| 742 | if (nm1 .lt. 1) go to 70 |
| 743 | do 60 k = 1, nm1 |
| 744 | kp1 = k + 1 |
| 745 | c |
| 746 | c find l = pivot index |
| 747 | c |
| 748 | l = izamax(n-k+1,a(k,k),1) + k - 1 |
| 749 | ipvt(k) = l |
| 750 | c |
| 751 | c zero pivot implies this column already triangularized |
| 752 | c |
| 753 | if (cabs1(a(l,k)) .eq. 0.0d0) go to 40 |
| 754 | c |
| 755 | c interchange if necessary |
| 756 | c |
| 757 | if (l .eq. k) go to 10 |
| 758 | t = a(l,k) |
| 759 | a(l,k) = a(k,k) |
| 760 | a(k,k) = t |
| 761 | 10 continue |
| 762 | c |
| 763 | c compute multipliers |
| 764 | c |
| 765 | t = -(1.0d0,0.0d0)/a(k,k) |
| 766 | call zscal(n-k,t,a(k+1,k),1) |
| 767 | c |
| 768 | c row elimination with column indexing |
| 769 | c |
| 770 | do 30 j = kp1, n |
| 771 | t = a(l,j) |
| 772 | if (l .eq. k) go to 20 |
| 773 | a(l,j) = a(k,j) |
| 774 | a(k,j) = t |
| 775 | 20 continue |
| 776 | call zaxpy(n-k,t,a(k+1,k),1,a(k+1,j),1) |
| 777 | 30 continue |
| 778 | go to 50 |
| 779 | 40 continue |
| 780 | info = k |
| 781 | 50 continue |
| 782 | 60 continue |
| 783 | 70 continue |
| 784 | ipvt(n) = n |
| 785 | if (cabs1(a(n,n)) .eq. 0.0d0) info = n |
| 786 | return |
| 787 | end |
| 788 | subroutine zgesl(a,lda,n,ipvt,b,job) |
| 789 | integer lda,n,ipvt(1),job |
| 790 | complex*16 a(lda,1),b(1) |
| 791 | c |
| 792 | c zgesl solves the complex*16 system |
| 793 | c a * x = b or ctrans(a) * x = b |
| 794 | c using the factors computed by zgeco or zgefa. |
| 795 | c |
| 796 | c on entry |
| 797 | c |
| 798 | c a complex*16(lda, n) |
| 799 | c the output from zgeco or zgefa. |
| 800 | c |
| 801 | c lda integer |
| 802 | c the leading dimension of the array a . |
| 803 | c |
| 804 | c n integer |
| 805 | c the order of the matrix a . |
| 806 | c |
| 807 | c ipvt integer(n) |
| 808 | c the pivot vector from zgeco or zgefa. |
| 809 | c |
| 810 | c b complex*16(n) |
| 811 | c the right hand side vector. |
| 812 | c |
| 813 | c job integer |
| 814 | c = 0 to solve a*x = b , |
| 815 | c = nonzero to solve ctrans(a)*x = b where |
| 816 | c ctrans(a) is the conjugate transpose. |
| 817 | c |
| 818 | c on return |
| 819 | c |
| 820 | c b the solution vector x . |
| 821 | c |
| 822 | c error condition |
| 823 | c |
| 824 | c a division by zero will occur if the input factor contains a |
| 825 | c zero on the diagonal. technically this indicates singularity |
| 826 | c but it is often caused by improper arguments or improper |
| 827 | c setting of lda . it will not occur if the subroutines are |
| 828 | c called correctly and if zgeco has set rcond .gt. 0.0 |
| 829 | c or zgefa has set info .eq. 0 . |
| 830 | c |
| 831 | c to compute inverse(a) * c where c is a matrix |
| 832 | c with p columns |
| 833 | c call zgeco(a,lda,n,ipvt,rcond,z) |
| 834 | c if (rcond is too small) go to ... |
| 835 | c do 10 j = 1, p |
| 836 | c call zgesl(a,lda,n,ipvt,c(1,j),0) |
| 837 | c 10 continue |
| 838 | c |
| 839 | c linpack. this version dated 08/14/78 . |
| 840 | c cleve moler, university of new mexico, argonne national lab. |
| 841 | c |
| 842 | c subroutines and functions |
| 843 | c |
| 844 | c blas zaxpy,zdotc |
| 845 | c fortran dconjg |
| 846 | c |
| 847 | c internal variables |
| 848 | c |
| 849 | complex*16 zdotc,t |
| 850 | integer k,kb,l,nm1 |
| 851 | double precision dreal,dimag |
| 852 | complex*16 zdumr,zdumi |
| 853 | dreal(zdumr) = zdumr |
| 854 | dimag(zdumi) = (0.0d0,-1.0d0)*zdumi |
| 855 | c |
| 856 | nm1 = n - 1 |
| 857 | if (job .ne. 0) go to 50 |
| 858 | c |
| 859 | c job = 0 , solve a * x = b |
| 860 | c first solve l*y = b |
| 861 | c |
| 862 | if (nm1 .lt. 1) go to 30 |
| 863 | do 20 k = 1, nm1 |
| 864 | l = ipvt(k) |
| 865 | t = b(l) |
| 866 | if (l .eq. k) go to 10 |
| 867 | b(l) = b(k) |
| 868 | b(k) = t |
| 869 | 10 continue |
| 870 | call zaxpy(n-k,t,a(k+1,k),1,b(k+1),1) |
| 871 | 20 continue |
| 872 | 30 continue |
| 873 | c |
| 874 | c now solve u*x = y |
| 875 | c |
| 876 | do 40 kb = 1, n |
| 877 | k = n + 1 - kb |
| 878 | b(k) = b(k)/a(k,k) |
| 879 | t = -b(k) |
| 880 | call zaxpy(k-1,t,a(1,k),1,b(1),1) |
| 881 | 40 continue |
| 882 | go to 100 |
| 883 | 50 continue |
| 884 | c |
| 885 | c job = nonzero, solve ctrans(a) * x = b |
| 886 | c first solve ctrans(u)*y = b |
| 887 | c |
| 888 | do 60 k = 1, n |
| 889 | t = zdotc(k-1,a(1,k),1,b(1),1) |
| 890 | b(k) = (b(k) - t)/dconjg(a(k,k)) |
| 891 | 60 continue |
| 892 | c |
| 893 | c now solve ctrans(l)*x = y |
| 894 | c |
| 895 | if (nm1 .lt. 1) go to 90 |
| 896 | do 80 kb = 1, nm1 |
| 897 | k = n - kb |
| 898 | b(k) = b(k) + zdotc(n-k,a(k+1,k),1,b(k+1),1) |
| 899 | l = ipvt(k) |
| 900 | if (l .eq. k) go to 70 |
| 901 | t = b(l) |
| 902 | b(l) = b(k) |
| 903 | b(k) = t |
| 904 | 70 continue |
| 905 | 80 continue |
| 906 | 90 continue |
| 907 | 100 continue |
| 908 | return |
| 909 | end |
| 910 | subroutine zhifa(a,lda,n,kpvt,info) |
| 911 | integer lda,n,kpvt(1),info |
| 912 | complex*16 a(lda,1) |
| 913 | c |
| 914 | c zhifa factors a complex*16 hermitian matrix by elimination |
| 915 | c with symmetric pivoting. |
| 916 | c |
| 917 | c to solve a*x = b , follow zhifa by zhisl. |
| 918 | c to compute inverse(a)*c , follow zhifa by zhisl. |
| 919 | c to compute determinant(a) , follow zhifa by zhidi. |
| 920 | c to compute inertia(a) , follow zhifa by zhidi. |
| 921 | c to compute inverse(a) , follow zhifa by zhidi. |
| 922 | c |
| 923 | c on entry |
| 924 | c |
| 925 | c a complex*16(lda,n) |
| 926 | c the hermitian matrix to be factored. |
| 927 | c only the diagonal and upper triangle are used. |
| 928 | c |
| 929 | c lda integer |
| 930 | c the leading dimension of the array a . |
| 931 | c |
| 932 | c n integer |
| 933 | c the order of the matrix a . |
| 934 | c |
| 935 | c on return |
| 936 | c |
| 937 | c a a block diagonal matrix and the multipliers which |
| 938 | c were used to obtain it. |
| 939 | c the factorization can be written a = u*d*ctrans(u) |
| 940 | c where u is a product of permutation and unit |
| 941 | c upper triangular matrices , ctrans(u) is the |
| 942 | c conjugate transpose of u , and d is block diagonal |
| 943 | c with 1 by 1 and 2 by 2 blocks. |
| 944 | c |
| 945 | c kpvt integer(n) |
| 946 | c an integer vector of pivot indices. |
| 947 | c |
| 948 | c info integer |
| 949 | c = 0 normal value. |
| 950 | c = k if the k-th pivot block is singular. this is |
| 951 | c not an error condition for this subroutine, |
| 952 | c but it does indicate that zhisl or zhidi may |
| 953 | c divide by zero if called. |
| 954 | c |
| 955 | c linpack. this version dated 08/14/78 . |
| 956 | c james bunch, univ. calif. san diego, argonne nat. lab. |
| 957 | c |
| 958 | c subroutines and functions |
| 959 | c |
| 960 | c blas zaxpy,zswap,izamax |
| 961 | c fortran dabs,dmax1,dcmplx,dconjg,dsqrt |
| 962 | c |
| 963 | c internal variables |
| 964 | c |
| 965 | complex*16 ak,akm1,bk,bkm1,denom,mulk,mulkm1,t |
| 966 | double precision absakk,alpha,colmax,rowmax |
| 967 | integer imax,imaxp1,j,jj,jmax,k,km1,km2,kstep,izamax |
| 968 | logical swap |
| 969 | c |
| 970 | complex*16 zdum |
| 971 | double precision cabs1 |
| 972 | double precision dreal,dimag |
| 973 | complex*16 zdumr,zdumi |
| 974 | dreal(zdumr) = zdumr |
| 975 | dimag(zdumi) = (0.0d0,-1.0d0)*zdumi |
| 976 | cabs1(zdum) = dabs(dreal(zdum)) + dabs(dimag(zdum)) |
| 977 | c |
| 978 | c initialize |
| 979 | c |
| 980 | c alpha is used in choosing pivot block size. |
| 981 | alpha = (1.0d0 + dsqrt(17.0d0))/8.0d0 |
| 982 | c |
| 983 | info = 0 |
| 984 | c |
| 985 | c main loop on k, which goes from n to 1. |
| 986 | c |
| 987 | k = n |
| 988 | 10 continue |
| 989 | c |
| 990 | c leave the loop if k=0 or k=1. |
| 991 | c |
| 992 | c ...exit |
| 993 | if (k .eq. 0) go to 200 |
| 994 | if (k .gt. 1) go to 20 |
| 995 | kpvt(1) = 1 |
| 996 | if (cabs1(a(1,1)) .eq. 0.0d0) info = 1 |
| 997 | c ......exit |
| 998 | go to 200 |
| 999 | 20 continue |
| 1000 | c |
| 1001 | c this section of code determines the kind of |
| 1002 | c elimination to be performed. when it is completed, |
| 1003 | c kstep will be set to the size of the pivot block, and |
| 1004 | c swap will be set to .true. if an interchange is |
| 1005 | c required. |
| 1006 | c |
| 1007 | km1 = k - 1 |
| 1008 | absakk = cabs1(a(k,k)) |
| 1009 | c |
| 1010 | c determine the largest off-diagonal element in |
| 1011 | c column k. |
| 1012 | c |
| 1013 | imax = izamax(k-1,a(1,k),1) |
| 1014 | colmax = cabs1(a(imax,k)) |
| 1015 | if (absakk .lt. alpha*colmax) go to 30 |
| 1016 | kstep = 1 |
| 1017 | swap = .false. |
| 1018 | go to 90 |
| 1019 | 30 continue |
| 1020 | c |
| 1021 | c determine the largest off-diagonal element in |
| 1022 | c row imax. |
| 1023 | c |
| 1024 | rowmax = 0.0d0 |
| 1025 | imaxp1 = imax + 1 |
| 1026 | do 40 j = imaxp1, k |
| 1027 | rowmax = dmax1(rowmax,cabs1(a(imax,j))) |
| 1028 | 40 continue |
| 1029 | if (imax .eq. 1) go to 50 |
| 1030 | jmax = izamax(imax-1,a(1,imax),1) |
| 1031 | rowmax = dmax1(rowmax,cabs1(a(jmax,imax))) |
| 1032 | 50 continue |
| 1033 | if (cabs1(a(imax,imax)) .lt. alpha*rowmax) go to 60 |
| 1034 | kstep = 1 |
| 1035 | swap = .true. |
| 1036 | go to 80 |
| 1037 | 60 continue |
| 1038 | if (absakk .lt. alpha*colmax*(colmax/rowmax)) go to 70 |
| 1039 | kstep = 1 |
| 1040 | swap = .false. |
| 1041 | go to 80 |
| 1042 | 70 continue |
| 1043 | kstep = 2 |
| 1044 | swap = imax .ne. km1 |
| 1045 | 80 continue |
| 1046 | 90 continue |
| 1047 | if (dmax1(absakk,colmax) .ne. 0.0d0) go to 100 |
| 1048 | c |
| 1049 | c column k is zero. set info and iterate the loop. |
| 1050 | c |
| 1051 | kpvt(k) = k |
| 1052 | info = k |
| 1053 | go to 190 |
| 1054 | 100 continue |
| 1055 | if (kstep .eq. 2) go to 140 |
| 1056 | c |
| 1057 | c 1 x 1 pivot block. |
| 1058 | c |
| 1059 | if (.not.swap) go to 120 |
| 1060 | c |
| 1061 | c perform an interchange. |
| 1062 | c |
| 1063 | call zswap(imax,a(1,imax),1,a(1,k),1) |
| 1064 | do 110 jj = imax, k |
| 1065 | j = k + imax - jj |
| 1066 | t = dconjg(a(j,k)) |
| 1067 | a(j,k) = dconjg(a(imax,j)) |
| 1068 | a(imax,j) = t |
| 1069 | 110 continue |
| 1070 | 120 continue |
| 1071 | c |
| 1072 | c perform the elimination. |
| 1073 | c |
| 1074 | do 130 jj = 1, km1 |
| 1075 | j = k - jj |
| 1076 | mulk = -a(j,k)/a(k,k) |
| 1077 | t = dconjg(mulk) |
| 1078 | call zaxpy(j,t,a(1,k),1,a(1,j),1) |
| 1079 | a(j,j) = dcmplx(dreal(a(j,j)),0.0d0) |
| 1080 | a(j,k) = mulk |
| 1081 | 130 continue |
| 1082 | c |
| 1083 | c set the pivot array. |
| 1084 | c |
| 1085 | kpvt(k) = k |
| 1086 | if (swap) kpvt(k) = imax |
| 1087 | go to 190 |
| 1088 | 140 continue |
| 1089 | c |
| 1090 | c 2 x 2 pivot block. |
| 1091 | c |
| 1092 | if (.not.swap) go to 160 |
| 1093 | c |
| 1094 | c perform an interchange. |
| 1095 | c |
| 1096 | call zswap(imax,a(1,imax),1,a(1,k-1),1) |
| 1097 | do 150 jj = imax, km1 |
| 1098 | j = km1 + imax - jj |
| 1099 | t = dconjg(a(j,k-1)) |
| 1100 | a(j,k-1) = dconjg(a(imax,j)) |
| 1101 | a(imax,j) = t |
| 1102 | 150 continue |
| 1103 | t = a(k-1,k) |
| 1104 | a(k-1,k) = a(imax,k) |
| 1105 | a(imax,k) = t |
| 1106 | 160 continue |
| 1107 | c |
| 1108 | c perform the elimination. |
| 1109 | c |
| 1110 | km2 = k - 2 |
| 1111 | if (km2 .eq. 0) go to 180 |
| 1112 | ak = a(k,k)/a(k-1,k) |
| 1113 | akm1 = a(k-1,k-1)/dconjg(a(k-1,k)) |
| 1114 | denom = 1.0d0 - ak*akm1 |
| 1115 | do 170 jj = 1, km2 |
| 1116 | j = km1 - jj |
| 1117 | bk = a(j,k)/a(k-1,k) |
| 1118 | bkm1 = a(j,k-1)/dconjg(a(k-1,k)) |
| 1119 | mulk = (akm1*bk - bkm1)/denom |
| 1120 | mulkm1 = (ak*bkm1 - bk)/denom |
| 1121 | t = dconjg(mulk) |
| 1122 | call zaxpy(j,t,a(1,k),1,a(1,j),1) |
| 1123 | t = dconjg(mulkm1) |
| 1124 | call zaxpy(j,t,a(1,k-1),1,a(1,j),1) |
| 1125 | a(j,k) = mulk |
| 1126 | a(j,k-1) = mulkm1 |
| 1127 | a(j,j) = dcmplx(dreal(a(j,j)),0.0d0) |
| 1128 | 170 continue |
| 1129 | 180 continue |
| 1130 | c |
| 1131 | c set the pivot array. |
| 1132 | c |
| 1133 | kpvt(k) = 1 - k |
| 1134 | if (swap) kpvt(k) = -imax |
| 1135 | kpvt(k-1) = kpvt(k) |
| 1136 | 190 continue |
| 1137 | k = k - kstep |
| 1138 | go to 10 |
| 1139 | 200 continue |
| 1140 | return |
| 1141 | end |
| 1142 | subroutine zhisl(a,lda,n,kpvt,b) |
| 1143 | integer lda,n,kpvt(1) |
| 1144 | complex*16 a(lda,1),b(1) |
| 1145 | c |
| 1146 | c zhisl solves the complex*16 hermitian system |
| 1147 | c a * x = b |
| 1148 | c using the factors computed by zhifa. |
| 1149 | c |
| 1150 | c on entry |
| 1151 | c |
| 1152 | c a complex*16(lda,n) |
| 1153 | c the output from zhifa. |
| 1154 | c |
| 1155 | c lda integer |
| 1156 | c the leading dimension of the array a . |
| 1157 | c |
| 1158 | c n integer |
| 1159 | c the order of the matrix a . |
| 1160 | c |
| 1161 | c kpvt integer(n) |
| 1162 | c the pivot vector from zhifa. |
| 1163 | c |
| 1164 | c b complex*16(n) |
| 1165 | c the right hand side vector. |
| 1166 | c |
| 1167 | c on return |
| 1168 | c |
| 1169 | c b the solution vector x . |
| 1170 | c |
| 1171 | c error condition |
| 1172 | c |
| 1173 | c a division by zero may occur if zhico has set rcond .eq. 0.0 |
| 1174 | c or zhifa has set info .ne. 0 . |
| 1175 | c |
| 1176 | c to compute inverse(a) * c where c is a matrix |
| 1177 | c with p columns |
| 1178 | c call zhifa(a,lda,n,kpvt,info) |
| 1179 | c if (info .ne. 0) go to ... |
| 1180 | c do 10 j = 1, p |
| 1181 | c call zhisl(a,lda,n,kpvt,c(1,j)) |
| 1182 | c 10 continue |
| 1183 | c |
| 1184 | c linpack. this version dated 08/14/78 . |
| 1185 | c james bunch, univ. calif. san diego, argonne nat. lab. |
| 1186 | c |
| 1187 | c subroutines and functions |
| 1188 | c |
| 1189 | c blas zaxpy,zdotc |
| 1190 | c fortran dconjg,iabs |
| 1191 | c |
| 1192 | c internal variables. |
| 1193 | c |
| 1194 | complex*16 ak,akm1,bk,bkm1,zdotc,denom,temp |
| 1195 | integer k,kp |
| 1196 | c |
| 1197 | c loop backward applying the transformations and |
| 1198 | c d inverse to b. |
| 1199 | c |
| 1200 | k = n |
| 1201 | 10 if (k .eq. 0) go to 80 |
| 1202 | if (kpvt(k) .lt. 0) go to 40 |
| 1203 | c |
| 1204 | c 1 x 1 pivot block. |
| 1205 | c |
| 1206 | if (k .eq. 1) go to 30 |
| 1207 | kp = kpvt(k) |
| 1208 | if (kp .eq. k) go to 20 |
| 1209 | c |
| 1210 | c interchange. |
| 1211 | c |
| 1212 | temp = b(k) |
| 1213 | b(k) = b(kp) |
| 1214 | b(kp) = temp |
| 1215 | 20 continue |
| 1216 | c |
| 1217 | c apply the transformation. |
| 1218 | c |
| 1219 | call zaxpy(k-1,b(k),a(1,k),1,b(1),1) |
| 1220 | 30 continue |
| 1221 | c |
| 1222 | c apply d inverse. |
| 1223 | c |
| 1224 | b(k) = b(k)/a(k,k) |
| 1225 | k = k - 1 |
| 1226 | go to 70 |
| 1227 | 40 continue |
| 1228 | c |
| 1229 | c 2 x 2 pivot block. |
| 1230 | c |
| 1231 | if (k .eq. 2) go to 60 |
| 1232 | kp = iabs(kpvt(k)) |
| 1233 | if (kp .eq. k - 1) go to 50 |
| 1234 | c |
| 1235 | c interchange. |
| 1236 | c |
| 1237 | temp = b(k-1) |
| 1238 | b(k-1) = b(kp) |
| 1239 | b(kp) = temp |
| 1240 | 50 continue |
| 1241 | c |
| 1242 | c apply the transformation. |
| 1243 | c |
| 1244 | call zaxpy(k-2,b(k),a(1,k),1,b(1),1) |
| 1245 | call zaxpy(k-2,b(k-1),a(1,k-1),1,b(1),1) |
| 1246 | 60 continue |
| 1247 | c |
| 1248 | c apply d inverse. |
| 1249 | c |
| 1250 | ak = a(k,k)/dconjg(a(k-1,k)) |
| 1251 | akm1 = a(k-1,k-1)/a(k-1,k) |
| 1252 | bk = b(k)/dconjg(a(k-1,k)) |
| 1253 | bkm1 = b(k-1)/a(k-1,k) |
| 1254 | denom = ak*akm1 - 1.0d0 |
| 1255 | b(k) = (akm1*bk - bkm1)/denom |
| 1256 | b(k-1) = (ak*bkm1 - bk)/denom |
| 1257 | k = k - 2 |
| 1258 | 70 continue |
| 1259 | go to 10 |
| 1260 | 80 continue |
| 1261 | c |
| 1262 | c loop forward applying the transformations. |
| 1263 | c |
| 1264 | k = 1 |
| 1265 | 90 if (k .gt. n) go to 160 |
| 1266 | if (kpvt(k) .lt. 0) go to 120 |
| 1267 | c |
| 1268 | c 1 x 1 pivot block. |
| 1269 | c |
| 1270 | if (k .eq. 1) go to 110 |
| 1271 | c |
| 1272 | c apply the transformation. |
| 1273 | c |
| 1274 | b(k) = b(k) + zdotc(k-1,a(1,k),1,b(1),1) |
| 1275 | kp = kpvt(k) |
| 1276 | if (kp .eq. k) go to 100 |
| 1277 | c |
| 1278 | c interchange. |
| 1279 | c |
| 1280 | temp = b(k) |
| 1281 | b(k) = b(kp) |
| 1282 | b(kp) = temp |
| 1283 | 100 continue |
| 1284 | 110 continue |
| 1285 | k = k + 1 |
| 1286 | go to 150 |
| 1287 | 120 continue |
| 1288 | c |
| 1289 | c 2 x 2 pivot block. |
| 1290 | c |
| 1291 | if (k .eq. 1) go to 140 |
| 1292 | c |
| 1293 | c apply the transformation. |
| 1294 | c |
| 1295 | b(k) = b(k) + zdotc(k-1,a(1,k),1,b(1),1) |
| 1296 | b(k+1) = b(k+1) + zdotc(k-1,a(1,k+1),1,b(1),1) |
| 1297 | kp = iabs(kpvt(k)) |
| 1298 | if (kp .eq. k) go to 130 |
| 1299 | c |
| 1300 | c interchange. |
| 1301 | c |
| 1302 | temp = b(k) |
| 1303 | b(k) = b(kp) |
| 1304 | b(kp) = temp |
| 1305 | 130 continue |
| 1306 | 140 continue |
| 1307 | k = k + 2 |
| 1308 | 150 continue |
| 1309 | go to 90 |
| 1310 | 160 continue |
| 1311 | return |
| 1312 | end |
| 1313 | subroutine zsifa(a,lda,n,kpvt,info) |
| 1314 | integer lda,n,kpvt(1),info |
| 1315 | complex*16 a(lda,1) |
| 1316 | c |
| 1317 | c zsifa factors a complex*16 symmetric matrix by elimination |
| 1318 | c with symmetric pivoting. |
| 1319 | c |
| 1320 | c to solve a*x = b , follow zsifa by zsisl. |
| 1321 | c to compute inverse(a)*c , follow zsifa by zsisl. |
| 1322 | c to compute determinant(a) , follow zsifa by zsidi. |
| 1323 | c to compute inverse(a) , follow zsifa by zsidi. |
| 1324 | c |
| 1325 | c on entry |
| 1326 | c |
| 1327 | c a complex*16(lda,n) |
| 1328 | c the symmetric matrix to be factored. |
| 1329 | c only the diagonal and upper triangle are used. |
| 1330 | c |
| 1331 | c lda integer |
| 1332 | c the leading dimension of the array a . |
| 1333 | c |
| 1334 | c n integer |
| 1335 | c the order of the matrix a . |
| 1336 | c |
| 1337 | c on return |
| 1338 | c |
| 1339 | c a a block diagonal matrix and the multipliers which |
| 1340 | c were used to obtain it. |
| 1341 | c the factorization can be written a = u*d*trans(u) |
| 1342 | c where u is a product of permutation and unit |
| 1343 | c upper triangular matrices , trans(u) is the |
| 1344 | c transpose of u , and d is block diagonal |
| 1345 | c with 1 by 1 and 2 by 2 blocks. |
| 1346 | c |
| 1347 | c kpvt integer(n) |
| 1348 | c an integer vector of pivot indices. |
| 1349 | c |
| 1350 | c info integer |
| 1351 | c = 0 normal value. |
| 1352 | c = k if the k-th pivot block is singular. this is |
| 1353 | c not an error condition for this subroutine, |
| 1354 | c but it does indicate that zsisl or zsidi may |
| 1355 | c divide by zero if called. |
| 1356 | c |
| 1357 | c linpack. this version dated 08/14/78 . |
| 1358 | c james bunch, univ. calif. san diego, argonne nat. lab. |
| 1359 | c |
| 1360 | c subroutines and functions |
| 1361 | c |
| 1362 | c blas zaxpy,zswap,izamax |
| 1363 | c fortran dabs,dmax1,dsqrt |
| 1364 | c |
| 1365 | c internal variables |
| 1366 | c |
| 1367 | complex*16 ak,akm1,bk,bkm1,denom,mulk,mulkm1,t |
| 1368 | double precision absakk,alpha,colmax,rowmax |
| 1369 | integer imax,imaxp1,j,jj,jmax,k,km1,km2,kstep,izamax |
| 1370 | logical swap |
| 1371 | c |
| 1372 | complex*16 zdum |
| 1373 | double precision cabs1 |
| 1374 | double precision dreal,dimag |
| 1375 | complex*16 zdumr,zdumi |
| 1376 | dreal(zdumr) = zdumr |
| 1377 | dimag(zdumi) = (0.0d0,-1.0d0)*zdumi |
| 1378 | cabs1(zdum) = dabs(dreal(zdum)) + dabs(dimag(zdum)) |
| 1379 | c |
| 1380 | c initialize |
| 1381 | c |
| 1382 | c alpha is used in choosing pivot block size. |
| 1383 | alpha = (1.0d0 + dsqrt(17.0d0))/8.0d0 |
| 1384 | c |
| 1385 | info = 0 |
| 1386 | c |
| 1387 | c main loop on k, which goes from n to 1. |
| 1388 | c |
| 1389 | k = n |
| 1390 | 10 continue |
| 1391 | c |
| 1392 | c leave the loop if k=0 or k=1. |
| 1393 | c |
| 1394 | c ...exit |
| 1395 | if (k .eq. 0) go to 200 |
| 1396 | if (k .gt. 1) go to 20 |
| 1397 | kpvt(1) = 1 |
| 1398 | if (cabs1(a(1,1)) .eq. 0.0d0) info = 1 |
| 1399 | c ......exit |
| 1400 | go to 200 |
| 1401 | 20 continue |
| 1402 | c |
| 1403 | c this section of code determines the kind of |
| 1404 | c elimination to be performed. when it is completed, |
| 1405 | c kstep will be set to the size of the pivot block, and |
| 1406 | c swap will be set to .true. if an interchange is |
| 1407 | c required. |
| 1408 | c |
| 1409 | km1 = k - 1 |
| 1410 | absakk = cabs1(a(k,k)) |
| 1411 | c |
| 1412 | c determine the largest off-diagonal element in |
| 1413 | c column k. |
| 1414 | c |
| 1415 | imax = izamax(k-1,a(1,k),1) |
| 1416 | colmax = cabs1(a(imax,k)) |
| 1417 | if (absakk .lt. alpha*colmax) go to 30 |
| 1418 | kstep = 1 |
| 1419 | swap = .false. |
| 1420 | go to 90 |
| 1421 | 30 continue |
| 1422 | c |
| 1423 | c determine the largest off-diagonal element in |
| 1424 | c row imax. |
| 1425 | c |
| 1426 | rowmax = 0.0d0 |
| 1427 | imaxp1 = imax + 1 |
| 1428 | do 40 j = imaxp1, k |
| 1429 | rowmax = dmax1(rowmax,cabs1(a(imax,j))) |
| 1430 | 40 continue |
| 1431 | if (imax .eq. 1) go to 50 |
| 1432 | jmax = izamax(imax-1,a(1,imax),1) |
| 1433 | rowmax = dmax1(rowmax,cabs1(a(jmax,imax))) |
| 1434 | 50 continue |
| 1435 | if (cabs1(a(imax,imax)) .lt. alpha*rowmax) go to 60 |
| 1436 | kstep = 1 |
| 1437 | swap = .true. |
| 1438 | go to 80 |
| 1439 | 60 continue |
| 1440 | if (absakk .lt. alpha*colmax*(colmax/rowmax)) go to 70 |
| 1441 | kstep = 1 |
| 1442 | swap = .false. |
| 1443 | go to 80 |
| 1444 | 70 continue |
| 1445 | kstep = 2 |
| 1446 | swap = imax .ne. km1 |
| 1447 | 80 continue |
| 1448 | 90 continue |
| 1449 | if (dmax1(absakk,colmax) .ne. 0.0d0) go to 100 |
| 1450 | c |
| 1451 | c column k is zero. set info and iterate the loop. |
| 1452 | c |
| 1453 | kpvt(k) = k |
| 1454 | info = k |
| 1455 | go to 190 |
| 1456 | 100 continue |
| 1457 | if (kstep .eq. 2) go to 140 |
| 1458 | c |
| 1459 | c 1 x 1 pivot block. |
| 1460 | c |
| 1461 | if (.not.swap) go to 120 |
| 1462 | c |
| 1463 | c perform an interchange. |
| 1464 | c |
| 1465 | call zswap(imax,a(1,imax),1,a(1,k),1) |
| 1466 | do 110 jj = imax, k |
| 1467 | j = k + imax - jj |
| 1468 | t = a(j,k) |
| 1469 | a(j,k) = a(imax,j) |
| 1470 | a(imax,j) = t |
| 1471 | 110 continue |
| 1472 | 120 continue |
| 1473 | c |
| 1474 | c perform the elimination. |
| 1475 | c |
| 1476 | do 130 jj = 1, km1 |
| 1477 | j = k - jj |
| 1478 | mulk = -a(j,k)/a(k,k) |
| 1479 | t = mulk |
| 1480 | call zaxpy(j,t,a(1,k),1,a(1,j),1) |
| 1481 | a(j,k) = mulk |
| 1482 | 130 continue |
| 1483 | c |
| 1484 | c set the pivot array. |
| 1485 | c |
| 1486 | kpvt(k) = k |
| 1487 | if (swap) kpvt(k) = imax |
| 1488 | go to 190 |
| 1489 | 140 continue |
| 1490 | c |
| 1491 | c 2 x 2 pivot block. |
| 1492 | c |
| 1493 | if (.not.swap) go to 160 |
| 1494 | c |
| 1495 | c perform an interchange. |
| 1496 | c |
| 1497 | call zswap(imax,a(1,imax),1,a(1,k-1),1) |
| 1498 | do 150 jj = imax, km1 |
| 1499 | j = km1 + imax - jj |
| 1500 | t = a(j,k-1) |
| 1501 | a(j,k-1) = a(imax,j) |
| 1502 | a(imax,j) = t |
| 1503 | 150 continue |
| 1504 | t = a(k-1,k) |
| 1505 | a(k-1,k) = a(imax,k) |
| 1506 | a(imax,k) = t |
| 1507 | 160 continue |
| 1508 | c |
| 1509 | c perform the elimination. |
| 1510 | c |
| 1511 | km2 = k - 2 |
| 1512 | if (km2 .eq. 0) go to 180 |
| 1513 | ak = a(k,k)/a(k-1,k) |
| 1514 | akm1 = a(k-1,k-1)/a(k-1,k) |
| 1515 | denom = 1.0d0 - ak*akm1 |
| 1516 | do 170 jj = 1, km2 |
| 1517 | j = km1 - jj |
| 1518 | bk = a(j,k)/a(k-1,k) |
| 1519 | bkm1 = a(j,k-1)/a(k-1,k) |
| 1520 | mulk = (akm1*bk - bkm1)/denom |
| 1521 | mulkm1 = (ak*bkm1 - bk)/denom |
| 1522 | t = mulk |
| 1523 | call zaxpy(j,t,a(1,k),1,a(1,j),1) |
| 1524 | t = mulkm1 |
| 1525 | call zaxpy(j,t,a(1,k-1),1,a(1,j),1) |
| 1526 | a(j,k) = mulk |
| 1527 | a(j,k-1) = mulkm1 |
| 1528 | 170 continue |
| 1529 | 180 continue |
| 1530 | c |
| 1531 | c set the pivot array. |
| 1532 | c |
| 1533 | kpvt(k) = 1 - k |
| 1534 | if (swap) kpvt(k) = -imax |
| 1535 | kpvt(k-1) = kpvt(k) |
| 1536 | 190 continue |
| 1537 | k = k - kstep |
| 1538 | go to 10 |
| 1539 | 200 continue |
| 1540 | return |
| 1541 | end |
| 1542 | subroutine zsisl(a,lda,n,kpvt,b) |
| 1543 | integer lda,n,kpvt(1) |
| 1544 | complex*16 a(lda,1),b(1) |
| 1545 | c |
| 1546 | c zsisl solves the complex*16 symmetric system |
| 1547 | c a * x = b |
| 1548 | c using the factors computed by zsifa. |
| 1549 | c |
| 1550 | c on entry |
| 1551 | c |
| 1552 | c a complex*16(lda,n) |
| 1553 | c the output from zsifa. |
| 1554 | c |
| 1555 | c lda integer |
| 1556 | c the leading dimension of the array a . |
| 1557 | c |
| 1558 | c n integer |
| 1559 | c the order of the matrix a . |
| 1560 | c |
| 1561 | c kpvt integer(n) |
| 1562 | c the pivot vector from zsifa. |
| 1563 | c |
| 1564 | c b complex*16(n) |
| 1565 | c the right hand side vector. |
| 1566 | c |
| 1567 | c on return |
| 1568 | c |
| 1569 | c b the solution vector x . |
| 1570 | c |
| 1571 | c error condition |
| 1572 | c |
| 1573 | c a division by zero may occur if zsico has set rcond .eq. 0.0 |
| 1574 | c or zsifa has set info .ne. 0 . |
| 1575 | c |
| 1576 | c to compute inverse(a) * c where c is a matrix |
| 1577 | c with p columns |
| 1578 | c call zsifa(a,lda,n,kpvt,info) |
| 1579 | c if (info .ne. 0) go to ... |
| 1580 | c do 10 j = 1, p |
| 1581 | c call zsisl(a,lda,n,kpvt,c(1,j)) |
| 1582 | c 10 continue |
| 1583 | c |
| 1584 | c linpack. this version dated 08/14/78 . |
| 1585 | c james bunch, univ. calif. san diego, argonne nat. lab. |
| 1586 | c |
| 1587 | c subroutines and functions |
| 1588 | c |
| 1589 | c blas zaxpy,zdotu |
| 1590 | c fortran iabs |
| 1591 | c |
| 1592 | c internal variables. |
| 1593 | c |
| 1594 | complex*16 ak,akm1,bk,bkm1,zdotu,denom,temp |
| 1595 | integer k,kp |
| 1596 | c |
| 1597 | c loop backward applying the transformations and |
| 1598 | c d inverse to b. |
| 1599 | c |
| 1600 | k = n |
| 1601 | 10 if (k .eq. 0) go to 80 |
| 1602 | if (kpvt(k) .lt. 0) go to 40 |
| 1603 | c |
| 1604 | c 1 x 1 pivot block. |
| 1605 | c |
| 1606 | if (k .eq. 1) go to 30 |
| 1607 | kp = kpvt(k) |
| 1608 | if (kp .eq. k) go to 20 |
| 1609 | c |
| 1610 | c interchange. |
| 1611 | c |
| 1612 | temp = b(k) |
| 1613 | b(k) = b(kp) |
| 1614 | b(kp) = temp |
| 1615 | 20 continue |
| 1616 | c |
| 1617 | c apply the transformation. |
| 1618 | c |
| 1619 | call zaxpy(k-1,b(k),a(1,k),1,b(1),1) |
| 1620 | 30 continue |
| 1621 | c |
| 1622 | c apply d inverse. |
| 1623 | c |
| 1624 | b(k) = b(k)/a(k,k) |
| 1625 | k = k - 1 |
| 1626 | go to 70 |
| 1627 | 40 continue |
| 1628 | c |
| 1629 | c 2 x 2 pivot block. |
| 1630 | c |
| 1631 | if (k .eq. 2) go to 60 |
| 1632 | kp = iabs(kpvt(k)) |
| 1633 | if (kp .eq. k - 1) go to 50 |
| 1634 | c |
| 1635 | c interchange. |
| 1636 | c |
| 1637 | temp = b(k-1) |
| 1638 | b(k-1) = b(kp) |
| 1639 | b(kp) = temp |
| 1640 | 50 continue |
| 1641 | c |
| 1642 | c apply the transformation. |
| 1643 | c |
| 1644 | call zaxpy(k-2,b(k),a(1,k),1,b(1),1) |
| 1645 | call zaxpy(k-2,b(k-1),a(1,k-1),1,b(1),1) |
| 1646 | 60 continue |
| 1647 | c |
| 1648 | c apply d inverse. |
| 1649 | c |
| 1650 | ak = a(k,k)/a(k-1,k) |
| 1651 | akm1 = a(k-1,k-1)/a(k-1,k) |
| 1652 | bk = b(k)/a(k-1,k) |
| 1653 | bkm1 = b(k-1)/a(k-1,k) |
| 1654 | denom = ak*akm1 - 1.0d0 |
| 1655 | b(k) = (akm1*bk - bkm1)/denom |
| 1656 | b(k-1) = (ak*bkm1 - bk)/denom |
| 1657 | k = k - 2 |
| 1658 | 70 continue |
| 1659 | go to 10 |
| 1660 | 80 continue |
| 1661 | c |
| 1662 | c loop forward applying the transformations. |
| 1663 | c |
| 1664 | k = 1 |
| 1665 | 90 if (k .gt. n) go to 160 |
| 1666 | if (kpvt(k) .lt. 0) go to 120 |
| 1667 | c |
| 1668 | c 1 x 1 pivot block. |
| 1669 | c |
| 1670 | if (k .eq. 1) go to 110 |
| 1671 | c |
| 1672 | c apply the transformation. |
| 1673 | c |
| 1674 | b(k) = b(k) + zdotu(k-1,a(1,k),1,b(1),1) |
| 1675 | kp = kpvt(k) |
| 1676 | if (kp .eq. k) go to 100 |
| 1677 | c |
| 1678 | c interchange. |
| 1679 | c |
| 1680 | temp = b(k) |
| 1681 | b(k) = b(kp) |
| 1682 | b(kp) = temp |
| 1683 | 100 continue |
| 1684 | 110 continue |
| 1685 | k = k + 1 |
| 1686 | go to 150 |
| 1687 | 120 continue |
| 1688 | c |
| 1689 | c 2 x 2 pivot block. |
| 1690 | c |
| 1691 | if (k .eq. 1) go to 140 |
| 1692 | c |
| 1693 | c apply the transformation. |
| 1694 | c |
| 1695 | b(k) = b(k) + zdotu(k-1,a(1,k),1,b(1),1) |
| 1696 | b(k+1) = b(k+1) + zdotu(k-1,a(1,k+1),1,b(1),1) |
| 1697 | kp = iabs(kpvt(k)) |
| 1698 | if (kp .eq. k) go to 130 |
| 1699 | c |
| 1700 | c interchange. |
| 1701 | c |
| 1702 | temp = b(k) |
| 1703 | b(k) = b(kp) |
| 1704 | b(kp) = temp |
| 1705 | 130 continue |
| 1706 | 140 continue |
| 1707 | k = k + 2 |
| 1708 | 150 continue |
| 1709 | go to 90 |
| 1710 | 160 continue |
| 1711 | return |
| 1712 | end |