1 *> \brief <b> DGGEVX computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE matrices</b>
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DGGEVX + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dggevx.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dggevx.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dggevx.f">
21 * SUBROUTINE DGGEVX( BALANC, JOBVL, JOBVR, SENSE, N, A, LDA, B, LDB,
22 * ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR, ILO,
23 * IHI, LSCALE, RSCALE, ABNRM, BBNRM, RCONDE,
24 * RCONDV, WORK, LWORK, IWORK, BWORK, INFO )
26 * .. Scalar Arguments ..
27 * CHARACTER BALANC, JOBVL, JOBVR, SENSE
28 * INTEGER IHI, ILO, INFO, LDA, LDB, LDVL, LDVR, LWORK, N
29 * DOUBLE PRECISION ABNRM, BBNRM
31 * .. Array Arguments ..
34 * DOUBLE PRECISION A( LDA, * ), ALPHAI( * ), ALPHAR( * ),
35 * $ B( LDB, * ), BETA( * ), LSCALE( * ),
36 * $ RCONDE( * ), RCONDV( * ), RSCALE( * ),
37 * $ VL( LDVL, * ), VR( LDVR, * ), WORK( * )
46 *> DGGEVX computes for a pair of N-by-N real nonsymmetric matrices (A,B)
47 *> the generalized eigenvalues, and optionally, the left and/or right
48 *> generalized eigenvectors.
50 *> Optionally also, it computes a balancing transformation to improve
51 *> the conditioning of the eigenvalues and eigenvectors (ILO, IHI,
52 *> LSCALE, RSCALE, ABNRM, and BBNRM), reciprocal condition numbers for
53 *> the eigenvalues (RCONDE), and reciprocal condition numbers for the
54 *> right eigenvectors (RCONDV).
56 *> A generalized eigenvalue for a pair of matrices (A,B) is a scalar
57 *> lambda or a ratio alpha/beta = lambda, such that A - lambda*B is
58 *> singular. It is usually represented as the pair (alpha,beta), as
59 *> there is a reasonable interpretation for beta=0, and even for both
62 *> The right eigenvector v(j) corresponding to the eigenvalue lambda(j)
65 *> A * v(j) = lambda(j) * B * v(j) .
67 *> The left eigenvector u(j) corresponding to the eigenvalue lambda(j)
70 *> u(j)**H * A = lambda(j) * u(j)**H * B.
72 *> where u(j)**H is the conjugate-transpose of u(j).
81 *> BALANC is CHARACTER*1
82 *> Specifies the balance option to be performed.
83 *> = 'N': do not diagonally scale or permute;
84 *> = 'P': permute only;
86 *> = 'B': both permute and scale.
87 *> Computed reciprocal condition numbers will be for the
88 *> matrices after permuting and/or balancing. Permuting does
89 *> not change condition numbers (in exact arithmetic), but
95 *> JOBVL is CHARACTER*1
96 *> = 'N': do not compute the left generalized eigenvectors;
97 *> = 'V': compute the left generalized eigenvectors.
102 *> JOBVR is CHARACTER*1
103 *> = 'N': do not compute the right generalized eigenvectors;
104 *> = 'V': compute the right generalized eigenvectors.
109 *> SENSE is CHARACTER*1
110 *> Determines which reciprocal condition numbers are computed.
111 *> = 'N': none are computed;
112 *> = 'E': computed for eigenvalues only;
113 *> = 'V': computed for eigenvectors only;
114 *> = 'B': computed for eigenvalues and eigenvectors.
120 *> The order of the matrices A, B, VL, and VR. N >= 0.
125 *> A is DOUBLE PRECISION array, dimension (LDA, N)
126 *> On entry, the matrix A in the pair (A,B).
127 *> On exit, A has been overwritten. If JOBVL='V' or JOBVR='V'
128 *> or both, then A contains the first part of the real Schur
129 *> form of the "balanced" versions of the input A and B.
135 *> The leading dimension of A. LDA >= max(1,N).
140 *> B is DOUBLE PRECISION array, dimension (LDB, N)
141 *> On entry, the matrix B in the pair (A,B).
142 *> On exit, B has been overwritten. If JOBVL='V' or JOBVR='V'
143 *> or both, then B contains the second part of the real Schur
144 *> form of the "balanced" versions of the input A and B.
150 *> The leading dimension of B. LDB >= max(1,N).
153 *> \param[out] ALPHAR
155 *> ALPHAR is DOUBLE PRECISION array, dimension (N)
158 *> \param[out] ALPHAI
160 *> ALPHAI is DOUBLE PRECISION array, dimension (N)
165 *> BETA is DOUBLE PRECISION array, dimension (N)
166 *> On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will
167 *> be the generalized eigenvalues. If ALPHAI(j) is zero, then
168 *> the j-th eigenvalue is real; if positive, then the j-th and
169 *> (j+1)-st eigenvalues are a complex conjugate pair, with
170 *> ALPHAI(j+1) negative.
172 *> Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j)
173 *> may easily over- or underflow, and BETA(j) may even be zero.
174 *> Thus, the user should avoid naively computing the ratio
175 *> ALPHA/BETA. However, ALPHAR and ALPHAI will be always less
176 *> than and usually comparable with norm(A) in magnitude, and
177 *> BETA always less than and usually comparable with norm(B).
182 *> VL is DOUBLE PRECISION array, dimension (LDVL,N)
183 *> If JOBVL = 'V', the left eigenvectors u(j) are stored one
184 *> after another in the columns of VL, in the same order as
185 *> their eigenvalues. If the j-th eigenvalue is real, then
186 *> u(j) = VL(:,j), the j-th column of VL. If the j-th and
187 *> (j+1)-th eigenvalues form a complex conjugate pair, then
188 *> u(j) = VL(:,j)+i*VL(:,j+1) and u(j+1) = VL(:,j)-i*VL(:,j+1).
189 *> Each eigenvector will be scaled so the largest component have
190 *> abs(real part) + abs(imag. part) = 1.
191 *> Not referenced if JOBVL = 'N'.
197 *> The leading dimension of the matrix VL. LDVL >= 1, and
198 *> if JOBVL = 'V', LDVL >= N.
203 *> VR is DOUBLE PRECISION array, dimension (LDVR,N)
204 *> If JOBVR = 'V', the right eigenvectors v(j) are stored one
205 *> after another in the columns of VR, in the same order as
206 *> their eigenvalues. If the j-th eigenvalue is real, then
207 *> v(j) = VR(:,j), the j-th column of VR. If the j-th and
208 *> (j+1)-th eigenvalues form a complex conjugate pair, then
209 *> v(j) = VR(:,j)+i*VR(:,j+1) and v(j+1) = VR(:,j)-i*VR(:,j+1).
210 *> Each eigenvector will be scaled so the largest component have
211 *> abs(real part) + abs(imag. part) = 1.
212 *> Not referenced if JOBVR = 'N'.
218 *> The leading dimension of the matrix VR. LDVR >= 1, and
219 *> if JOBVR = 'V', LDVR >= N.
230 *> ILO and IHI are integer values such that on exit
231 *> A(i,j) = 0 and B(i,j) = 0 if i > j and
232 *> j = 1,...,ILO-1 or i = IHI+1,...,N.
233 *> If BALANC = 'N' or 'S', ILO = 1 and IHI = N.
236 *> \param[out] LSCALE
238 *> LSCALE is DOUBLE PRECISION array, dimension (N)
239 *> Details of the permutations and scaling factors applied
240 *> to the left side of A and B. If PL(j) is the index of the
241 *> row interchanged with row j, and DL(j) is the scaling
242 *> factor applied to row j, then
243 *> LSCALE(j) = PL(j) for j = 1,...,ILO-1
244 *> = DL(j) for j = ILO,...,IHI
245 *> = PL(j) for j = IHI+1,...,N.
246 *> The order in which the interchanges are made is N to IHI+1,
250 *> \param[out] RSCALE
252 *> RSCALE is DOUBLE PRECISION array, dimension (N)
253 *> Details of the permutations and scaling factors applied
254 *> to the right side of A and B. If PR(j) is the index of the
255 *> column interchanged with column j, and DR(j) is the scaling
256 *> factor applied to column j, then
257 *> RSCALE(j) = PR(j) for j = 1,...,ILO-1
258 *> = DR(j) for j = ILO,...,IHI
259 *> = PR(j) for j = IHI+1,...,N
260 *> The order in which the interchanges are made is N to IHI+1,
266 *> ABNRM is DOUBLE PRECISION
267 *> The one-norm of the balanced matrix A.
272 *> BBNRM is DOUBLE PRECISION
273 *> The one-norm of the balanced matrix B.
276 *> \param[out] RCONDE
278 *> RCONDE is DOUBLE PRECISION array, dimension (N)
279 *> If SENSE = 'E' or 'B', the reciprocal condition numbers of
280 *> the eigenvalues, stored in consecutive elements of the array.
281 *> For a complex conjugate pair of eigenvalues two consecutive
282 *> elements of RCONDE are set to the same value. Thus RCONDE(j),
283 *> RCONDV(j), and the j-th columns of VL and VR all correspond
284 *> to the j-th eigenpair.
285 *> If SENSE = 'N or 'V', RCONDE is not referenced.
288 *> \param[out] RCONDV
290 *> RCONDV is DOUBLE PRECISION array, dimension (N)
291 *> If SENSE = 'V' or 'B', the estimated reciprocal condition
292 *> numbers of the eigenvectors, stored in consecutive elements
293 *> of the array. For a complex eigenvector two consecutive
294 *> elements of RCONDV are set to the same value. If the
295 *> eigenvalues cannot be reordered to compute RCONDV(j),
296 *> RCONDV(j) is set to 0; this can only occur when the true
297 *> value would be very small anyway.
298 *> If SENSE = 'N' or 'E', RCONDV is not referenced.
303 *> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))
304 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
310 *> The dimension of the array WORK. LWORK >= max(1,2*N).
311 *> If BALANC = 'S' or 'B', or JOBVL = 'V', or JOBVR = 'V',
312 *> LWORK >= max(1,6*N).
313 *> If SENSE = 'E' or 'B', LWORK >= max(1,10*N).
314 *> If SENSE = 'V' or 'B', LWORK >= 2*N*N+8*N+16.
316 *> If LWORK = -1, then a workspace query is assumed; the routine
317 *> only calculates the optimal size of the WORK array, returns
318 *> this value as the first entry of the WORK array, and no error
319 *> message related to LWORK is issued by XERBLA.
324 *> IWORK is INTEGER array, dimension (N+6)
325 *> If SENSE = 'E', IWORK is not referenced.
330 *> BWORK is LOGICAL array, dimension (N)
331 *> If SENSE = 'N', BWORK is not referenced.
337 *> = 0: successful exit
338 *> < 0: if INFO = -i, the i-th argument had an illegal value.
340 *> The QZ iteration failed. No eigenvectors have been
341 *> calculated, but ALPHAR(j), ALPHAI(j), and BETA(j)
342 *> should be correct for j=INFO+1,...,N.
343 *> > N: =N+1: other than QZ iteration failed in DHGEQZ.
344 *> =N+2: error return from DTGEVC.
350 *> \author Univ. of Tennessee
351 *> \author Univ. of California Berkeley
352 *> \author Univ. of Colorado Denver
357 *> \ingroup doubleGEeigen
359 *> \par Further Details:
360 * =====================
364 *> Balancing a matrix pair (A,B) includes, first, permuting rows and
365 *> columns to isolate eigenvalues, second, applying diagonal similarity
366 *> transformation to the rows and columns to make the rows and columns
367 *> as close in norm as possible. The computed reciprocal condition
368 *> numbers correspond to the balanced matrix. Permuting rows and columns
369 *> will not change the condition numbers (in exact arithmetic) but
370 *> diagonal scaling will. For further explanation of balancing, see
371 *> section 4.11.1.2 of LAPACK Users' Guide.
373 *> An approximate error bound on the chordal distance between the i-th
374 *> computed generalized eigenvalue w and the corresponding exact
375 *> eigenvalue lambda is
377 *> chord(w, lambda) <= EPS * norm(ABNRM, BBNRM) / RCONDE(I)
379 *> An approximate error bound for the angle between the i-th computed
380 *> eigenvector VL(i) or VR(i) is given by
382 *> EPS * norm(ABNRM, BBNRM) / DIF(i).
384 *> For further explanation of the reciprocal condition numbers RCONDE
385 *> and RCONDV, see section 4.11 of LAPACK User's Guide.
388 * =====================================================================
389 SUBROUTINE DGGEVX( BALANC, JOBVL, JOBVR, SENSE, N, A, LDA, B, LDB,
390 $ ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR, ILO,
391 $ IHI, LSCALE, RSCALE, ABNRM, BBNRM, RCONDE,
392 $ RCONDV, WORK, LWORK, IWORK, BWORK, INFO )
394 * -- LAPACK driver routine (version 3.4.1) --
395 * -- LAPACK is a software package provided by Univ. of Tennessee, --
396 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
399 * .. Scalar Arguments ..
400 CHARACTER BALANC, JOBVL, JOBVR, SENSE
401 INTEGER IHI, ILO, INFO, LDA, LDB, LDVL, LDVR, LWORK, N
402 DOUBLE PRECISION ABNRM, BBNRM
404 * .. Array Arguments ..
407 DOUBLE PRECISION A( LDA, * ), ALPHAI( * ), ALPHAR( * ),
408 $ B( LDB, * ), BETA( * ), LSCALE( * ),
409 $ RCONDE( * ), RCONDV( * ), RSCALE( * ),
410 $ VL( LDVL, * ), VR( LDVR, * ), WORK( * )
413 * =====================================================================
416 DOUBLE PRECISION ZERO, ONE
417 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
419 * .. Local Scalars ..
420 LOGICAL ILASCL, ILBSCL, ILV, ILVL, ILVR, LQUERY, NOSCL,
421 $ PAIR, WANTSB, WANTSE, WANTSN, WANTSV
423 INTEGER I, ICOLS, IERR, IJOBVL, IJOBVR, IN, IROWS,
424 $ ITAU, IWRK, IWRK1, J, JC, JR, M, MAXWRK,
426 DOUBLE PRECISION ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS,
432 * .. External Subroutines ..
433 EXTERNAL DGEQRF, DGGBAK, DGGBAL, DGGHRD, DHGEQZ, DLABAD,
434 $ DLACPY, DLASCL, DLASET, DORGQR, DORMQR, DTGEVC,
437 * .. External Functions ..
440 DOUBLE PRECISION DLAMCH, DLANGE
441 EXTERNAL LSAME, ILAENV, DLAMCH, DLANGE
443 * .. Intrinsic Functions ..
444 INTRINSIC ABS, MAX, SQRT
446 * .. Executable Statements ..
448 * Decode the input arguments
450 IF( LSAME( JOBVL, 'N' ) ) THEN
453 ELSE IF( LSAME( JOBVL, 'V' ) ) THEN
461 IF( LSAME( JOBVR, 'N' ) ) THEN
464 ELSE IF( LSAME( JOBVR, 'V' ) ) THEN
473 NOSCL = LSAME( BALANC, 'N' ) .OR. LSAME( BALANC, 'P' )
474 WANTSN = LSAME( SENSE, 'N' )
475 WANTSE = LSAME( SENSE, 'E' )
476 WANTSV = LSAME( SENSE, 'V' )
477 WANTSB = LSAME( SENSE, 'B' )
479 * Test the input arguments
482 LQUERY = ( LWORK.EQ.-1 )
483 IF( .NOT.( LSAME( BALANC, 'N' ) .OR. LSAME( BALANC,
484 $ 'S' ) .OR. LSAME( BALANC, 'P' ) .OR. LSAME( BALANC, 'B' ) ) )
487 ELSE IF( IJOBVL.LE.0 ) THEN
489 ELSE IF( IJOBVR.LE.0 ) THEN
491 ELSE IF( .NOT.( WANTSN .OR. WANTSE .OR. WANTSB .OR. WANTSV ) )
494 ELSE IF( N.LT.0 ) THEN
496 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
498 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
500 ELSE IF( LDVL.LT.1 .OR. ( ILVL .AND. LDVL.LT.N ) ) THEN
502 ELSE IF( LDVR.LT.1 .OR. ( ILVR .AND. LDVR.LT.N ) ) THEN
507 * (Note: Comments in the code beginning "Workspace:" describe the
508 * minimal amount of workspace needed at that point in the code,
509 * as well as the preferred amount for good performance.
510 * NB refers to the optimal block size for the immediately
511 * following subroutine, as returned by ILAENV. The workspace is
512 * computed assuming ILO = 1 and IHI = N, the worst case.)
519 IF( NOSCL .AND. .NOT.ILV ) THEN
524 IF( WANTSE .OR. WANTSB ) THEN
527 IF( WANTSV .OR. WANTSB ) THEN
528 MINWRK = MAX( MINWRK, 2*N*( N + 4 ) + 16 )
531 MAXWRK = MAX( MAXWRK,
532 $ N + N*ILAENV( 1, 'DGEQRF', ' ', N, 1, N, 0 ) )
533 MAXWRK = MAX( MAXWRK,
534 $ N + N*ILAENV( 1, 'DORMQR', ' ', N, 1, N, 0 ) )
536 MAXWRK = MAX( MAXWRK, N +
537 $ N*ILAENV( 1, 'DORGQR', ' ', N, 1, N, 0 ) )
542 IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN
548 CALL XERBLA( 'DGGEVX', -INFO )
550 ELSE IF( LQUERY ) THEN
554 * Quick return if possible
560 * Get machine constants
563 SMLNUM = DLAMCH( 'S' )
564 BIGNUM = ONE / SMLNUM
565 CALL DLABAD( SMLNUM, BIGNUM )
566 SMLNUM = SQRT( SMLNUM ) / EPS
567 BIGNUM = ONE / SMLNUM
569 * Scale A if max element outside range [SMLNUM,BIGNUM]
571 ANRM = DLANGE( 'M', N, N, A, LDA, WORK )
573 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
576 ELSE IF( ANRM.GT.BIGNUM ) THEN
581 $ CALL DLASCL( 'G', 0, 0, ANRM, ANRMTO, N, N, A, LDA, IERR )
583 * Scale B if max element outside range [SMLNUM,BIGNUM]
585 BNRM = DLANGE( 'M', N, N, B, LDB, WORK )
587 IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN
590 ELSE IF( BNRM.GT.BIGNUM ) THEN
595 $ CALL DLASCL( 'G', 0, 0, BNRM, BNRMTO, N, N, B, LDB, IERR )
597 * Permute and/or balance the matrix pair (A,B)
598 * (Workspace: need 6*N if BALANC = 'S' or 'B', 1 otherwise)
600 CALL DGGBAL( BALANC, N, A, LDA, B, LDB, ILO, IHI, LSCALE, RSCALE,
603 * Compute ABNRM and BBNRM
605 ABNRM = DLANGE( '1', N, N, A, LDA, WORK( 1 ) )
608 CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, 1, 1, WORK( 1 ), 1,
613 BBNRM = DLANGE( '1', N, N, B, LDB, WORK( 1 ) )
616 CALL DLASCL( 'G', 0, 0, BNRMTO, BNRM, 1, 1, WORK( 1 ), 1,
621 * Reduce B to triangular form (QR decomposition of B)
622 * (Workspace: need N, prefer N*NB )
624 IROWS = IHI + 1 - ILO
625 IF( ILV .OR. .NOT.WANTSN ) THEN
632 CALL DGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ),
633 $ WORK( IWRK ), LWORK+1-IWRK, IERR )
635 * Apply the orthogonal transformation to A
636 * (Workspace: need N, prefer N*NB)
638 CALL DORMQR( 'L', 'T', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB,
639 $ WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWRK ),
640 $ LWORK+1-IWRK, IERR )
642 * Initialize VL and/or VR
643 * (Workspace: need N, prefer N*NB)
646 CALL DLASET( 'Full', N, N, ZERO, ONE, VL, LDVL )
647 IF( IROWS.GT.1 ) THEN
648 CALL DLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB,
649 $ VL( ILO+1, ILO ), LDVL )
651 CALL DORGQR( IROWS, IROWS, IROWS, VL( ILO, ILO ), LDVL,
652 $ WORK( ITAU ), WORK( IWRK ), LWORK+1-IWRK, IERR )
656 $ CALL DLASET( 'Full', N, N, ZERO, ONE, VR, LDVR )
658 * Reduce to generalized Hessenberg form
659 * (Workspace: none needed)
661 IF( ILV .OR. .NOT.WANTSN ) THEN
663 * Eigenvectors requested -- work on whole matrix.
665 CALL DGGHRD( JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB, VL,
666 $ LDVL, VR, LDVR, IERR )
668 CALL DGGHRD( 'N', 'N', IROWS, 1, IROWS, A( ILO, ILO ), LDA,
669 $ B( ILO, ILO ), LDB, VL, LDVL, VR, LDVR, IERR )
672 * Perform QZ algorithm (Compute eigenvalues, and optionally, the
673 * Schur forms and Schur vectors)
674 * (Workspace: need N)
676 IF( ILV .OR. .NOT.WANTSN ) THEN
682 CALL DHGEQZ( CHTEMP, JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB,
683 $ ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR, WORK,
686 IF( IERR.GT.0 .AND. IERR.LE.N ) THEN
688 ELSE IF( IERR.GT.N .AND. IERR.LE.2*N ) THEN
696 * Compute Eigenvectors and estimate condition numbers if desired
697 * (Workspace: DTGEVC: need 6*N
698 * DTGSNA: need 2*N*(N+2)+16 if SENSE = 'V' or 'B',
701 IF( ILV .OR. .NOT.WANTSN ) THEN
713 CALL DTGEVC( CHTEMP, 'B', LDUMMA, N, A, LDA, B, LDB, VL,
714 $ LDVL, VR, LDVR, N, IN, WORK, IERR )
721 IF( .NOT.WANTSN ) THEN
723 * compute eigenvectors (DTGEVC) and estimate condition
724 * numbers (DTGSNA). Note that the definition of the condition
725 * number is not invariant under transformation (u,v) to
726 * (Q*u, Z*v), where (u,v) are eigenvectors of the generalized
727 * Schur form (S,T), Q and Z are orthogonal matrices. In order
728 * to avoid using extra 2*N*N workspace, we have to recalculate
729 * eigenvectors and estimate one condition numbers at a time.
740 IF( A( I+1, I ).NE.ZERO ) THEN
751 ELSE IF( MM.EQ.2 ) THEN
753 BWORK( I+1 ) = .TRUE.
759 * Compute a pair of left and right eigenvectors.
760 * (compute workspace: need up to 4*N + 6*N)
762 IF( WANTSE .OR. WANTSB ) THEN
763 CALL DTGEVC( 'B', 'S', BWORK, N, A, LDA, B, LDB,
764 $ WORK( 1 ), N, WORK( IWRK ), N, MM, M,
765 $ WORK( IWRK1 ), IERR )
772 CALL DTGSNA( SENSE, 'S', BWORK, N, A, LDA, B, LDB,
773 $ WORK( 1 ), N, WORK( IWRK ), N, RCONDE( I ),
774 $ RCONDV( I ), MM, M, WORK( IWRK1 ),
775 $ LWORK-IWRK1+1, IWORK, IERR )
781 * Undo balancing on VL and VR and normalization
782 * (Workspace: none needed)
785 CALL DGGBAK( BALANC, 'L', N, ILO, IHI, LSCALE, RSCALE, N, VL,
789 IF( ALPHAI( JC ).LT.ZERO )
792 IF( ALPHAI( JC ).EQ.ZERO ) THEN
794 TEMP = MAX( TEMP, ABS( VL( JR, JC ) ) )
798 TEMP = MAX( TEMP, ABS( VL( JR, JC ) )+
799 $ ABS( VL( JR, JC+1 ) ) )
805 IF( ALPHAI( JC ).EQ.ZERO ) THEN
807 VL( JR, JC ) = VL( JR, JC )*TEMP
811 VL( JR, JC ) = VL( JR, JC )*TEMP
812 VL( JR, JC+1 ) = VL( JR, JC+1 )*TEMP
818 CALL DGGBAK( BALANC, 'R', N, ILO, IHI, LSCALE, RSCALE, N, VR,
821 IF( ALPHAI( JC ).LT.ZERO )
824 IF( ALPHAI( JC ).EQ.ZERO ) THEN
826 TEMP = MAX( TEMP, ABS( VR( JR, JC ) ) )
830 TEMP = MAX( TEMP, ABS( VR( JR, JC ) )+
831 $ ABS( VR( JR, JC+1 ) ) )
837 IF( ALPHAI( JC ).EQ.ZERO ) THEN
839 VR( JR, JC ) = VR( JR, JC )*TEMP
843 VR( JR, JC ) = VR( JR, JC )*TEMP
844 VR( JR, JC+1 ) = VR( JR, JC+1 )*TEMP
850 * Undo scaling if necessary
855 CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAR, N, IERR )
856 CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAI, N, IERR )
860 CALL DLASCL( 'G', 0, 0, BNRMTO, BNRM, N, 1, BETA, N, IERR )