| 1 |
SUBROUTINE DGGES( JOBVSL, JOBVSR, SORT, DELCTG, N, A, LDA, B, LDB, |
| 2 |
$ SDIM, ALPHAR, ALPHAI, BETA, VSL, LDVSL, VSR, |
| 3 |
$ LDVSR, WORK, LWORK, BWORK, INFO ) |
| 4 |
* |
| 5 |
* -- LAPACK driver routine (version 3.0) -- |
| 6 |
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., |
| 7 |
* Courant Institute, Argonne National Lab, and Rice University |
| 8 |
* June 30, 1999 |
| 9 |
* |
| 10 |
* .. Scalar Arguments .. |
| 11 |
CHARACTER JOBVSL, JOBVSR, SORT |
| 12 |
INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LWORK, N, SDIM |
| 13 |
* .. |
| 14 |
* .. Array Arguments .. |
| 15 |
LOGICAL BWORK( * ) |
| 16 |
DOUBLE PRECISION A( LDA, * ), ALPHAI( * ), ALPHAR( * ), |
| 17 |
$ B( LDB, * ), BETA( * ), VSL( LDVSL, * ), |
| 18 |
$ VSR( LDVSR, * ), WORK( * ) |
| 19 |
* .. |
| 20 |
* .. Function Arguments .. |
| 21 |
LOGICAL DELCTG |
| 22 |
EXTERNAL DELCTG |
| 23 |
* .. |
| 24 |
* |
| 25 |
* Purpose |
| 26 |
* ======= |
| 27 |
* |
| 28 |
* DGGES computes for a pair of N-by-N real nonsymmetric matrices (A,B), |
| 29 |
* the generalized eigenvalues, the generalized real Schur form (S,T), |
| 30 |
* optionally, the left and/or right matrices of Schur vectors (VSL and |
| 31 |
* VSR). This gives the generalized Schur factorization |
| 32 |
* |
| 33 |
* (A,B) = ( (VSL)*S*(VSR)**T, (VSL)*T*(VSR)**T ) |
| 34 |
* |
| 35 |
* Optionally, it also orders the eigenvalues so that a selected cluster |
| 36 |
* of eigenvalues appears in the leading diagonal blocks of the upper |
| 37 |
* quasi-triangular matrix S and the upper triangular matrix T.The |
| 38 |
* leading columns of VSL and VSR then form an orthonormal basis for the |
| 39 |
* corresponding left and right eigenspaces (deflating subspaces). |
| 40 |
* |
| 41 |
* (If only the generalized eigenvalues are needed, use the driver |
| 42 |
* DGGEV instead, which is faster.) |
| 43 |
* |
| 44 |
* A generalized eigenvalue for a pair of matrices (A,B) is a scalar w |
| 45 |
* or a ratio alpha/beta = w, such that A - w*B is singular. It is |
| 46 |
* usually represented as the pair (alpha,beta), as there is a |
| 47 |
* reasonable interpretation for beta=0 or both being zero. |
| 48 |
* |
| 49 |
* A pair of matrices (S,T) is in generalized real Schur form if T is |
| 50 |
* upper triangular with non-negative diagonal and S is block upper |
| 51 |
* triangular with 1-by-1 and 2-by-2 blocks. 1-by-1 blocks correspond |
| 52 |
* to real generalized eigenvalues, while 2-by-2 blocks of S will be |
| 53 |
* "standardized" by making the corresponding elements of T have the |
| 54 |
* form: |
| 55 |
* [ a 0 ] |
| 56 |
* [ 0 b ] |
| 57 |
* |
| 58 |
* and the pair of corresponding 2-by-2 blocks in S and T will have a |
| 59 |
* complex conjugate pair of generalized eigenvalues. |
| 60 |
* |
| 61 |
* |
| 62 |
* Arguments |
| 63 |
* ========= |
| 64 |
* |
| 65 |
* JOBVSL (input) CHARACTER*1 |
| 66 |
* = 'N': do not compute the left Schur vectors; |
| 67 |
* = 'V': compute the left Schur vectors. |
| 68 |
* |
| 69 |
* JOBVSR (input) CHARACTER*1 |
| 70 |
* = 'N': do not compute the right Schur vectors; |
| 71 |
* = 'V': compute the right Schur vectors. |
| 72 |
* |
| 73 |
* SORT (input) CHARACTER*1 |
| 74 |
* Specifies whether or not to order the eigenvalues on the |
| 75 |
* diagonal of the generalized Schur form. |
| 76 |
* = 'N': Eigenvalues are not ordered; |
| 77 |
* = 'S': Eigenvalues are ordered (see DELZTG); |
| 78 |
* |
| 79 |
* DELZTG (input) LOGICAL FUNCTION of three DOUBLE PRECISION arguments |
| 80 |
* DELZTG must be declared EXTERNAL in the calling subroutine. |
| 81 |
* If SORT = 'N', DELZTG is not referenced. |
| 82 |
* If SORT = 'S', DELZTG is used to select eigenvalues to sort |
| 83 |
* to the top left of the Schur form. |
| 84 |
* An eigenvalue (ALPHAR(j)+ALPHAI(j))/BETA(j) is selected if |
| 85 |
* DELZTG(ALPHAR(j),ALPHAI(j),BETA(j)) is true; i.e. if either |
| 86 |
* one of a complex conjugate pair of eigenvalues is selected, |
| 87 |
* then both complex eigenvalues are selected. |
| 88 |
* |
| 89 |
* Note that in the ill-conditioned case, a selected complex |
| 90 |
* eigenvalue may no longer satisfy DELZTG(ALPHAR(j),ALPHAI(j), |
| 91 |
* BETA(j)) = .TRUE. after ordering. INFO is to be set to N+2 |
| 92 |
* in this case. |
| 93 |
* |
| 94 |
* N (input) INTEGER |
| 95 |
* The order of the matrices A, B, VSL, and VSR. N >= 0. |
| 96 |
* |
| 97 |
* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) |
| 98 |
* On entry, the first of the pair of matrices. |
| 99 |
* On exit, A has been overwritten by its generalized Schur |
| 100 |
* form S. |
| 101 |
* |
| 102 |
* LDA (input) INTEGER |
| 103 |
* The leading dimension of A. LDA >= max(1,N). |
| 104 |
* |
| 105 |
* B (input/output) DOUBLE PRECISION array, dimension (LDB, N) |
| 106 |
* On entry, the second of the pair of matrices. |
| 107 |
* On exit, B has been overwritten by its generalized Schur |
| 108 |
* form T. |
| 109 |
* |
| 110 |
* LDB (input) INTEGER |
| 111 |
* The leading dimension of B. LDB >= max(1,N). |
| 112 |
* |
| 113 |
* SDIM (output) INTEGER |
| 114 |
* If SORT = 'N', SDIM = 0. |
| 115 |
* If SORT = 'S', SDIM = number of eigenvalues (after sorting) |
| 116 |
* for which DELZTG is true. (Complex conjugate pairs for which |
| 117 |
* DELZTG is true for either eigenvalue count as 2.) |
| 118 |
* |
| 119 |
* ALPHAR (output) DOUBLE PRECISION array, dimension (N) |
| 120 |
* ALPHAI (output) DOUBLE PRECISION array, dimension (N) |
| 121 |
* BETA (output) DOUBLE PRECISION array, dimension (N) |
| 122 |
* On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will |
| 123 |
* be the generalized eigenvalues. ALPHAR(j) + ALPHAI(j)*i, |
| 124 |
* and BETA(j),j=1,...,N are the diagonals of the complex Schur |
| 125 |
* form (S,T) that would result if the 2-by-2 diagonal blocks of |
| 126 |
* the real Schur form of (A,B) were further reduced to |
| 127 |
* triangular form using 2-by-2 complex unitary transformations. |
| 128 |
* If ALPHAI(j) is zero, then the j-th eigenvalue is real; if |
| 129 |
* positive, then the j-th and (j+1)-st eigenvalues are a |
| 130 |
* complex conjugate pair, with ALPHAI(j+1) negative. |
| 131 |
* |
| 132 |
* Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j) |
| 133 |
* may easily over- or underflow, and BETA(j) may even be zero. |
| 134 |
* Thus, the user should avoid naively computing the ratio. |
| 135 |
* However, ALPHAR and ALPHAI will be always less than and |
| 136 |
* usually comparable with norm(A) in magnitude, and BETA always |
| 137 |
* less than and usually comparable with norm(B). |
| 138 |
* |
| 139 |
* VSL (output) DOUBLE PRECISION array, dimension (LDVSL,N) |
| 140 |
* If JOBVSL = 'V', VSL will contain the left Schur vectors. |
| 141 |
* Not referenced if JOBVSL = 'N'. |
| 142 |
* |
| 143 |
* LDVSL (input) INTEGER |
| 144 |
* The leading dimension of the matrix VSL. LDVSL >=1, and |
| 145 |
* if JOBVSL = 'V', LDVSL >= N. |
| 146 |
* |
| 147 |
* VSR (output) DOUBLE PRECISION array, dimension (LDVSR,N) |
| 148 |
* If JOBVSR = 'V', VSR will contain the right Schur vectors. |
| 149 |
* Not referenced if JOBVSR = 'N'. |
| 150 |
* |
| 151 |
* LDVSR (input) INTEGER |
| 152 |
* The leading dimension of the matrix VSR. LDVSR >= 1, and |
| 153 |
* if JOBVSR = 'V', LDVSR >= N. |
| 154 |
* |
| 155 |
* WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK) |
| 156 |
* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. |
| 157 |
* |
| 158 |
* LWORK (input) INTEGER |
| 159 |
* The dimension of the array WORK. LWORK >= 8*N+16. |
| 160 |
* |
| 161 |
* If LWORK = -1, then a workspace query is assumed; the routine |
| 162 |
* only calculates the optimal size of the WORK array, returns |
| 163 |
* this value as the first entry of the WORK array, and no error |
| 164 |
* message related to LWORK is issued by XERBLA. |
| 165 |
* |
| 166 |
* BWORK (workspace) LOGICAL array, dimension (N) |
| 167 |
* Not referenced if SORT = 'N'. |
| 168 |
* |
| 169 |
* INFO (output) INTEGER |
| 170 |
* = 0: successful exit |
| 171 |
* < 0: if INFO = -i, the i-th argument had an illegal value. |
| 172 |
* = 1,...,N: |
| 173 |
* The QZ iteration failed. (A,B) are not in Schur |
| 174 |
* form, but ALPHAR(j), ALPHAI(j), and BETA(j) should |
| 175 |
* be correct for j=INFO+1,...,N. |
| 176 |
* > N: =N+1: other than QZ iteration failed in DHGEQZ. |
| 177 |
* =N+2: after reordering, roundoff changed values of |
| 178 |
* some complex eigenvalues so that leading |
| 179 |
* eigenvalues in the Generalized Schur form no |
| 180 |
* longer satisfy DELZTG=.TRUE. This could also |
| 181 |
* be caused due to scaling. |
| 182 |
* =N+3: reordering failed in DTGSEN. |
| 183 |
* |
| 184 |
* ===================================================================== |
| 185 |
* |
| 186 |
* .. Parameters .. |
| 187 |
DOUBLE PRECISION ZERO, ONE |
| 188 |
PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) |
| 189 |
* .. |
| 190 |
* .. Local Scalars .. |
| 191 |
LOGICAL CURSL, ILASCL, ILBSCL, ILVSL, ILVSR, LASTSL, |
| 192 |
$ LQUERY, LST2SL, WANTST |
| 193 |
INTEGER I, ICOLS, IERR, IHI, IJOBVL, IJOBVR, ILEFT, |
| 194 |
$ ILO, IP, IRIGHT, IROWS, ITAU, IWRK, MAXWRK, |
| 195 |
$ MINWRK |
| 196 |
DOUBLE PRECISION ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS, PVSL, |
| 197 |
$ PVSR, SAFMAX, SAFMIN, SMLNUM |
| 198 |
* .. |
| 199 |
* .. Local Arrays .. |
| 200 |
INTEGER IDUM( 1 ) |
| 201 |
DOUBLE PRECISION DIF( 2 ) |
| 202 |
* .. |
| 203 |
* .. External Subroutines .. |
| 204 |
EXTERNAL DGEQRF, DGGBAK, DGGBAL, DGGHRD, DHGEQZ, DLABAD, |
| 205 |
$ DLACPY, DLASCL, DLASET, DORGQR, DORMQR, DTGSEN, |
| 206 |
$ XERBLA |
| 207 |
* .. |
| 208 |
* .. External Functions .. |
| 209 |
LOGICAL LSAME |
| 210 |
INTEGER ILAENV |
| 211 |
DOUBLE PRECISION DLAMCH, DLANGE |
| 212 |
EXTERNAL LSAME, ILAENV, DLAMCH, DLANGE |
| 213 |
* .. |
| 214 |
* .. Intrinsic Functions .. |
| 215 |
INTRINSIC ABS, MAX, SQRT |
| 216 |
* .. |
| 217 |
* .. Executable Statements .. |
| 218 |
* |
| 219 |
* Decode the input arguments |
| 220 |
* |
| 221 |
IF( LSAME( JOBVSL, 'N' ) ) THEN |
| 222 |
IJOBVL = 1 |
| 223 |
ILVSL = .FALSE. |
| 224 |
ELSE IF( LSAME( JOBVSL, 'V' ) ) THEN |
| 225 |
IJOBVL = 2 |
| 226 |
ILVSL = .TRUE. |
| 227 |
ELSE |
| 228 |
IJOBVL = -1 |
| 229 |
ILVSL = .FALSE. |
| 230 |
END IF |
| 231 |
* |
| 232 |
IF( LSAME( JOBVSR, 'N' ) ) THEN |
| 233 |
IJOBVR = 1 |
| 234 |
ILVSR = .FALSE. |
| 235 |
ELSE IF( LSAME( JOBVSR, 'V' ) ) THEN |
| 236 |
IJOBVR = 2 |
| 237 |
ILVSR = .TRUE. |
| 238 |
ELSE |
| 239 |
IJOBVR = -1 |
| 240 |
ILVSR = .FALSE. |
| 241 |
END IF |
| 242 |
* |
| 243 |
WANTST = LSAME( SORT, 'S' ) |
| 244 |
* |
| 245 |
* Test the input arguments |
| 246 |
* |
| 247 |
INFO = 0 |
| 248 |
LQUERY = ( LWORK.EQ.-1 ) |
| 249 |
IF( IJOBVL.LE.0 ) THEN |
| 250 |
INFO = -1 |
| 251 |
ELSE IF( IJOBVR.LE.0 ) THEN |
| 252 |
INFO = -2 |
| 253 |
ELSE IF( ( .NOT.WANTST ) .AND. ( .NOT.LSAME( SORT, 'N' ) ) ) THEN |
| 254 |
INFO = -3 |
| 255 |
ELSE IF( N.LT.0 ) THEN |
| 256 |
INFO = -5 |
| 257 |
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN |
| 258 |
INFO = -7 |
| 259 |
ELSE IF( LDB.LT.MAX( 1, N ) ) THEN |
| 260 |
INFO = -9 |
| 261 |
ELSE IF( LDVSL.LT.1 .OR. ( ILVSL .AND. LDVSL.LT.N ) ) THEN |
| 262 |
INFO = -15 |
| 263 |
ELSE IF( LDVSR.LT.1 .OR. ( ILVSR .AND. LDVSR.LT.N ) ) THEN |
| 264 |
INFO = -17 |
| 265 |
END IF |
| 266 |
* |
| 267 |
* Compute workspace |
| 268 |
* (Note: Comments in the code beginning "Workspace:" describe the |
| 269 |
* minimal amount of workspace needed at that point in the code, |
| 270 |
* as well as the preferred amount for good performance. |
| 271 |
* NB refers to the optimal block size for the immediately |
| 272 |
* following subroutine, as returned by ILAENV.) |
| 273 |
* |
| 274 |
MINWRK = 1 |
| 275 |
IF( INFO.EQ.0 .AND. ( LWORK.GE.1 .OR. LQUERY ) ) THEN |
| 276 |
MINWRK = 7*( N+1 ) + 16 |
| 277 |
MAXWRK = 7*( N+1 ) + N*ILAENV( 1, 'DGEQRF', ' ', N, 1, N, 0 ) + |
| 278 |
$ 16 |
| 279 |
IF( ILVSL ) THEN |
| 280 |
MAXWRK = MAX( MAXWRK, 7*( N+1 )+N* |
| 281 |
$ ILAENV( 1, 'DORGQR', ' ', N, 1, N, -1 ) ) |
| 282 |
END IF |
| 283 |
WORK( 1 ) = MAXWRK |
| 284 |
END IF |
| 285 |
* |
| 286 |
IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY ) |
| 287 |
$ INFO = -19 |
| 288 |
IF( INFO.NE.0 ) THEN |
| 289 |
CALL XERBLA( 'DGGES ', -INFO ) |
| 290 |
RETURN |
| 291 |
ELSE IF( LQUERY ) THEN |
| 292 |
RETURN |
| 293 |
END IF |
| 294 |
* |
| 295 |
* Quick return if possible |
| 296 |
* |
| 297 |
IF( N.EQ.0 ) THEN |
| 298 |
SDIM = 0 |
| 299 |
RETURN |
| 300 |
END IF |
| 301 |
* |
| 302 |
* Get machine constants |
| 303 |
* |
| 304 |
EPS = DLAMCH( 'P' ) |
| 305 |
SAFMIN = DLAMCH( 'S' ) |
| 306 |
SAFMAX = ONE / SAFMIN |
| 307 |
CALL DLABAD( SAFMIN, SAFMAX ) |
| 308 |
SMLNUM = SQRT( SAFMIN ) / EPS |
| 309 |
BIGNUM = ONE / SMLNUM |
| 310 |
* |
| 311 |
* Scale A if max element outside range [SMLNUM,BIGNUM] |
| 312 |
* |
| 313 |
ANRM = DLANGE( 'M', N, N, A, LDA, WORK ) |
| 314 |
ILASCL = .FALSE. |
| 315 |
IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN |
| 316 |
ANRMTO = SMLNUM |
| 317 |
ILASCL = .TRUE. |
| 318 |
ELSE IF( ANRM.GT.BIGNUM ) THEN |
| 319 |
ANRMTO = BIGNUM |
| 320 |
ILASCL = .TRUE. |
| 321 |
END IF |
| 322 |
IF( ILASCL ) |
| 323 |
$ CALL DLASCL( 'G', 0, 0, ANRM, ANRMTO, N, N, A, LDA, IERR ) |
| 324 |
* |
| 325 |
* Scale B if max element outside range [SMLNUM,BIGNUM] |
| 326 |
* |
| 327 |
BNRM = DLANGE( 'M', N, N, B, LDB, WORK ) |
| 328 |
ILBSCL = .FALSE. |
| 329 |
IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN |
| 330 |
BNRMTO = SMLNUM |
| 331 |
ILBSCL = .TRUE. |
| 332 |
ELSE IF( BNRM.GT.BIGNUM ) THEN |
| 333 |
BNRMTO = BIGNUM |
| 334 |
ILBSCL = .TRUE. |
| 335 |
END IF |
| 336 |
IF( ILBSCL ) |
| 337 |
$ CALL DLASCL( 'G', 0, 0, BNRM, BNRMTO, N, N, B, LDB, IERR ) |
| 338 |
* |
| 339 |
* Permute the matrix to make it more nearly triangular |
| 340 |
* (Workspace: need 6*N + 2*N space for storing balancing factors) |
| 341 |
* |
| 342 |
ILEFT = 1 |
| 343 |
IRIGHT = N + 1 |
| 344 |
IWRK = IRIGHT + N |
| 345 |
CALL DGGBAL( 'P', N, A, LDA, B, LDB, ILO, IHI, WORK( ILEFT ), |
| 346 |
$ WORK( IRIGHT ), WORK( IWRK ), IERR ) |
| 347 |
* |
| 348 |
* Reduce B to triangular form (QR decomposition of B) |
| 349 |
* (Workspace: need N, prefer N*NB) |
| 350 |
* |
| 351 |
IROWS = IHI + 1 - ILO |
| 352 |
ICOLS = N + 1 - ILO |
| 353 |
ITAU = IWRK |
| 354 |
IWRK = ITAU + IROWS |
| 355 |
CALL DGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ), |
| 356 |
$ WORK( IWRK ), LWORK+1-IWRK, IERR ) |
| 357 |
* |
| 358 |
* Apply the orthogonal transformation to matrix A |
| 359 |
* (Workspace: need N, prefer N*NB) |
| 360 |
* |
| 361 |
CALL DORMQR( 'L', 'T', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB, |
| 362 |
$ WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWRK ), |
| 363 |
$ LWORK+1-IWRK, IERR ) |
| 364 |
* |
| 365 |
* Initialize VSL |
| 366 |
* (Workspace: need N, prefer N*NB) |
| 367 |
* |
| 368 |
IF( ILVSL ) THEN |
| 369 |
CALL DLASET( 'Full', N, N, ZERO, ONE, VSL, LDVSL ) |
| 370 |
CALL DLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB, |
| 371 |
$ VSL( ILO+1, ILO ), LDVSL ) |
| 372 |
CALL DORGQR( IROWS, IROWS, IROWS, VSL( ILO, ILO ), LDVSL, |
| 373 |
$ WORK( ITAU ), WORK( IWRK ), LWORK+1-IWRK, IERR ) |
| 374 |
END IF |
| 375 |
* |
| 376 |
* Initialize VSR |
| 377 |
* |
| 378 |
IF( ILVSR ) |
| 379 |
$ CALL DLASET( 'Full', N, N, ZERO, ONE, VSR, LDVSR ) |
| 380 |
* |
| 381 |
* Reduce to generalized Hessenberg form |
| 382 |
* (Workspace: none needed) |
| 383 |
* |
| 384 |
CALL DGGHRD( JOBVSL, JOBVSR, N, ILO, IHI, A, LDA, B, LDB, VSL, |
| 385 |
$ LDVSL, VSR, LDVSR, IERR ) |
| 386 |
* |
| 387 |
* Perform QZ algorithm, computing Schur vectors if desired |
| 388 |
* (Workspace: need N) |
| 389 |
* |
| 390 |
IWRK = ITAU |
| 391 |
CALL DHGEQZ( 'S', JOBVSL, JOBVSR, N, ILO, IHI, A, LDA, B, LDB, |
| 392 |
$ ALPHAR, ALPHAI, BETA, VSL, LDVSL, VSR, LDVSR, |
| 393 |
$ WORK( IWRK ), LWORK+1-IWRK, IERR ) |
| 394 |
IF( IERR.NE.0 ) THEN |
| 395 |
IF( IERR.GT.0 .AND. IERR.LE.N ) THEN |
| 396 |
INFO = IERR |
| 397 |
ELSE IF( IERR.GT.N .AND. IERR.LE.2*N ) THEN |
| 398 |
INFO = IERR - N |
| 399 |
ELSE |
| 400 |
INFO = N + 1 |
| 401 |
END IF |
| 402 |
GO TO 50 |
| 403 |
END IF |
| 404 |
* |
| 405 |
* Sort eigenvalues ALPHA/BETA if desired |
| 406 |
* (Workspace: need 4*N+16 ) |
| 407 |
* |
| 408 |
SDIM = 0 |
| 409 |
IF( WANTST ) THEN |
| 410 |
* |
| 411 |
* Undo scaling on eigenvalues before DELZTGing |
| 412 |
* |
| 413 |
IF( ILASCL ) THEN |
| 414 |
CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAR, N, |
| 415 |
$ IERR ) |
| 416 |
CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAI, N, |
| 417 |
$ IERR ) |
| 418 |
END IF |
| 419 |
IF( ILBSCL ) |
| 420 |
$ CALL DLASCL( 'G', 0, 0, BNRMTO, BNRM, N, 1, BETA, N, IERR ) |
| 421 |
* |
| 422 |
* Select eigenvalues |
| 423 |
* |
| 424 |
DO 10 I = 1, N |
| 425 |
BWORK( I ) = DELCTG( ALPHAR( I ), ALPHAI( I ), BETA( I ) ) |
| 426 |
10 CONTINUE |
| 427 |
* |
| 428 |
CALL DTGSEN( 0, ILVSL, ILVSR, BWORK, N, A, LDA, B, LDB, ALPHAR, |
| 429 |
$ ALPHAI, BETA, VSL, LDVSL, VSR, LDVSR, SDIM, PVSL, |
| 430 |
$ PVSR, DIF, WORK( IWRK ), LWORK-IWRK+1, IDUM, 1, |
| 431 |
$ IERR ) |
| 432 |
IF( IERR.EQ.1 ) |
| 433 |
$ INFO = N + 3 |
| 434 |
* |
| 435 |
END IF |
| 436 |
* |
| 437 |
* Apply back-permutation to VSL and VSR |
| 438 |
* (Workspace: none needed) |
| 439 |
* |
| 440 |
IF( ILVSL ) |
| 441 |
$ CALL DGGBAK( 'P', 'L', N, ILO, IHI, WORK( ILEFT ), |
| 442 |
$ WORK( IRIGHT ), N, VSL, LDVSL, IERR ) |
| 443 |
* |
| 444 |
IF( ILVSR ) |
| 445 |
$ CALL DGGBAK( 'P', 'R', N, ILO, IHI, WORK( ILEFT ), |
| 446 |
$ WORK( IRIGHT ), N, VSR, LDVSR, IERR ) |
| 447 |
* |
| 448 |
* Check if unscaling would cause over/underflow, if so, rescale |
| 449 |
* (ALPHAR(I),ALPHAI(I),BETA(I)) so BETA(I) is on the order of |
| 450 |
* B(I,I) and ALPHAR(I) and ALPHAI(I) are on the order of A(I,I) |
| 451 |
* |
| 452 |
IF( ILASCL ) THEN |
| 453 |
DO 20 I = 1, N |
| 454 |
IF( ALPHAI( I ).NE.ZERO ) THEN |
| 455 |
IF( ( ALPHAR( I ) / SAFMAX ).GT.( ANRMTO / ANRM ) .OR. |
| 456 |
$ ( SAFMIN / ALPHAR( I ) ).GT.( ANRM / ANRMTO ) ) THEN |
| 457 |
WORK( 1 ) = ABS( A( I, I ) / ALPHAR( I ) ) |
| 458 |
BETA( I ) = BETA( I )*WORK( 1 ) |
| 459 |
ALPHAR( I ) = ALPHAR( I )*WORK( 1 ) |
| 460 |
ALPHAI( I ) = ALPHAI( I )*WORK( 1 ) |
| 461 |
ELSE IF( ( ALPHAI( I ) / SAFMAX ).GT. |
| 462 |
$ ( ANRMTO / ANRM ) .OR. |
| 463 |
$ ( SAFMIN / ALPHAI( I ) ).GT.( ANRM / ANRMTO ) ) |
| 464 |
$ THEN |
| 465 |
WORK( 1 ) = ABS( A( I, I+1 ) / ALPHAI( I ) ) |
| 466 |
BETA( I ) = BETA( I )*WORK( 1 ) |
| 467 |
ALPHAR( I ) = ALPHAR( I )*WORK( 1 ) |
| 468 |
ALPHAI( I ) = ALPHAI( I )*WORK( 1 ) |
| 469 |
END IF |
| 470 |
END IF |
| 471 |
20 CONTINUE |
| 472 |
END IF |
| 473 |
* |
| 474 |
IF( ILBSCL ) THEN |
| 475 |
DO 30 I = 1, N |
| 476 |
IF( ALPHAI( I ).NE.ZERO ) THEN |
| 477 |
IF( ( BETA( I ) / SAFMAX ).GT.( BNRMTO / BNRM ) .OR. |
| 478 |
$ ( SAFMIN / BETA( I ) ).GT.( BNRM / BNRMTO ) ) THEN |
| 479 |
WORK( 1 ) = ABS( B( I, I ) / BETA( I ) ) |
| 480 |
BETA( I ) = BETA( I )*WORK( 1 ) |
| 481 |
ALPHAR( I ) = ALPHAR( I )*WORK( 1 ) |
| 482 |
ALPHAI( I ) = ALPHAI( I )*WORK( 1 ) |
| 483 |
END IF |
| 484 |
END IF |
| 485 |
30 CONTINUE |
| 486 |
END IF |
| 487 |
* |
| 488 |
* Undo scaling |
| 489 |
* |
| 490 |
IF( ILASCL ) THEN |
| 491 |
CALL DLASCL( 'H', 0, 0, ANRMTO, ANRM, N, N, A, LDA, IERR ) |
| 492 |
CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAR, N, IERR ) |
| 493 |
CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAI, N, IERR ) |
| 494 |
END IF |
| 495 |
* |
| 496 |
IF( ILBSCL ) THEN |
| 497 |
CALL DLASCL( 'U', 0, 0, BNRMTO, BNRM, N, N, B, LDB, IERR ) |
| 498 |
CALL DLASCL( 'G', 0, 0, BNRMTO, BNRM, N, 1, BETA, N, IERR ) |
| 499 |
END IF |
| 500 |
* |
| 501 |
IF( WANTST ) THEN |
| 502 |
* |
| 503 |
* Check if reordering is correct |
| 504 |
* |
| 505 |
LASTSL = .TRUE. |
| 506 |
LST2SL = .TRUE. |
| 507 |
SDIM = 0 |
| 508 |
IP = 0 |
| 509 |
DO 40 I = 1, N |
| 510 |
CURSL = DELCTG( ALPHAR( I ), ALPHAI( I ), BETA( I ) ) |
| 511 |
IF( ALPHAI( I ).EQ.ZERO ) THEN |
| 512 |
IF( CURSL ) |
| 513 |
$ SDIM = SDIM + 1 |
| 514 |
IP = 0 |
| 515 |
IF( CURSL .AND. .NOT.LASTSL ) |
| 516 |
$ INFO = N + 2 |
| 517 |
ELSE |
| 518 |
IF( IP.EQ.1 ) THEN |
| 519 |
* |
| 520 |
* Last eigenvalue of conjugate pair |
| 521 |
* |
| 522 |
CURSL = CURSL .OR. LASTSL |
| 523 |
LASTSL = CURSL |
| 524 |
IF( CURSL ) |
| 525 |
$ SDIM = SDIM + 2 |
| 526 |
IP = -1 |
| 527 |
IF( CURSL .AND. .NOT.LST2SL ) |
| 528 |
$ INFO = N + 2 |
| 529 |
ELSE |
| 530 |
* |
| 531 |
* First eigenvalue of conjugate pair |
| 532 |
* |
| 533 |
IP = 1 |
| 534 |
END IF |
| 535 |
END IF |
| 536 |
LST2SL = LASTSL |
| 537 |
LASTSL = CURSL |
| 538 |
40 CONTINUE |
| 539 |
* |
| 540 |
END IF |
| 541 |
* |
| 542 |
50 CONTINUE |
| 543 |
* |
| 544 |
WORK( 1 ) = MAXWRK |
| 545 |
* |
| 546 |
RETURN |
| 547 |
* |
| 548 |
* End of DGGES |
| 549 |
* |
| 550 |
END |