001:       SUBROUTINE DGEGV( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR, ALPHAI,
002:      $                  BETA, VL, LDVL, VR, LDVR, WORK, LWORK, INFO )
003: *
004: *  -- LAPACK driver routine (version 3.2) --
005: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
006: *     November 2006
007: *
008: *     .. Scalar Arguments ..
009:       CHARACTER          JOBVL, JOBVR
010:       INTEGER            INFO, LDA, LDB, LDVL, LDVR, LWORK, N
011: *     ..
012: *     .. Array Arguments ..
013:       DOUBLE PRECISION   A( LDA, * ), ALPHAI( * ), ALPHAR( * ),
014:      $                   B( LDB, * ), BETA( * ), VL( LDVL, * ),
015:      $                   VR( LDVR, * ), WORK( * )
016: *     ..
017: *
018: *  Purpose
019: *  =======
020: *
021: *  This routine is deprecated and has been replaced by routine DGGEV.
022: *
023: *  DGEGV computes the eigenvalues and, optionally, the left and/or right
024: *  eigenvectors of a real matrix pair (A,B).
025: *  Given two square matrices A and B,
026: *  the generalized nonsymmetric eigenvalue problem (GNEP) is to find the
027: *  eigenvalues lambda and corresponding (non-zero) eigenvectors x such
028: *  that
029: *
030: *     A*x = lambda*B*x.
031: *
032: *  An alternate form is to find the eigenvalues mu and corresponding
033: *  eigenvectors y such that
034: *
035: *     mu*A*y = B*y.
036: *
037: *  These two forms are equivalent with mu = 1/lambda and x = y if
038: *  neither lambda nor mu is zero.  In order to deal with the case that
039: *  lambda or mu is zero or small, two values alpha and beta are returned
040: *  for each eigenvalue, such that lambda = alpha/beta and
041: *  mu = beta/alpha.
042: *
043: *  The vectors x and y in the above equations are right eigenvectors of
044: *  the matrix pair (A,B).  Vectors u and v satisfying
045: *
046: *     u**H*A = lambda*u**H*B  or  mu*v**H*A = v**H*B
047: *
048: *  are left eigenvectors of (A,B).
049: *
050: *  Note: this routine performs "full balancing" on A and B -- see
051: *  "Further Details", below.
052: *
053: *  Arguments
054: *  =========
055: *
056: *  JOBVL   (input) CHARACTER*1
057: *          = 'N':  do not compute the left generalized eigenvectors;
058: *          = 'V':  compute the left generalized eigenvectors (returned
059: *                  in VL).
060: *
061: *  JOBVR   (input) CHARACTER*1
062: *          = 'N':  do not compute the right generalized eigenvectors;
063: *          = 'V':  compute the right generalized eigenvectors (returned
064: *                  in VR).
065: *
066: *  N       (input) INTEGER
067: *          The order of the matrices A, B, VL, and VR.  N >= 0.
068: *
069: *  A       (input/output) DOUBLE PRECISION array, dimension (LDA, N)
070: *          On entry, the matrix A.
071: *          If JOBVL = 'V' or JOBVR = 'V', then on exit A
072: *          contains the real Schur form of A from the generalized Schur
073: *          factorization of the pair (A,B) after balancing.
074: *          If no eigenvectors were computed, then only the diagonal
075: *          blocks from the Schur form will be correct.  See DGGHRD and
076: *          DHGEQZ for details.
077: *
078: *  LDA     (input) INTEGER
079: *          The leading dimension of A.  LDA >= max(1,N).
080: *
081: *  B       (input/output) DOUBLE PRECISION array, dimension (LDB, N)
082: *          On entry, the matrix B.
083: *          If JOBVL = 'V' or JOBVR = 'V', then on exit B contains the
084: *          upper triangular matrix obtained from B in the generalized
085: *          Schur factorization of the pair (A,B) after balancing.
086: *          If no eigenvectors were computed, then only those elements of
087: *          B corresponding to the diagonal blocks from the Schur form of
088: *          A will be correct.  See DGGHRD and DHGEQZ for details.
089: *
090: *  LDB     (input) INTEGER
091: *          The leading dimension of B.  LDB >= max(1,N).
092: *
093: *  ALPHAR  (output) DOUBLE PRECISION array, dimension (N)
094: *          The real parts of each scalar alpha defining an eigenvalue of
095: *          GNEP.
096: *
097: *  ALPHAI  (output) DOUBLE PRECISION array, dimension (N)
098: *          The imaginary parts of each scalar alpha defining an
099: *          eigenvalue of GNEP.  If ALPHAI(j) is zero, then the j-th
100: *          eigenvalue is real; if positive, then the j-th and
101: *          (j+1)-st eigenvalues are a complex conjugate pair, with
102: *          ALPHAI(j+1) = -ALPHAI(j).
103: *
104: *  BETA    (output) DOUBLE PRECISION array, dimension (N)
105: *          The scalars beta that define the eigenvalues of GNEP.
106: *          
107: *          Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and
108: *          beta = BETA(j) represent the j-th eigenvalue of the matrix
109: *          pair (A,B), in one of the forms lambda = alpha/beta or
110: *          mu = beta/alpha.  Since either lambda or mu may overflow,
111: *          they should not, in general, be computed.
112: *
113: *  VL      (output) DOUBLE PRECISION array, dimension (LDVL,N)
114: *          If JOBVL = 'V', the left eigenvectors u(j) are stored
115: *          in the columns of VL, in the same order as their eigenvalues.
116: *          If the j-th eigenvalue is real, then u(j) = VL(:,j).
117: *          If the j-th and (j+1)-st eigenvalues form a complex conjugate
118: *          pair, then
119: *             u(j) = VL(:,j) + i*VL(:,j+1)
120: *          and
121: *            u(j+1) = VL(:,j) - i*VL(:,j+1).
122: *
123: *          Each eigenvector is scaled so that its largest component has
124: *          abs(real part) + abs(imag. part) = 1, except for eigenvectors
125: *          corresponding to an eigenvalue with alpha = beta = 0, which
126: *          are set to zero.
127: *          Not referenced if JOBVL = 'N'.
128: *
129: *  LDVL    (input) INTEGER
130: *          The leading dimension of the matrix VL. LDVL >= 1, and
131: *          if JOBVL = 'V', LDVL >= N.
132: *
133: *  VR      (output) DOUBLE PRECISION array, dimension (LDVR,N)
134: *          If JOBVR = 'V', the right eigenvectors x(j) are stored
135: *          in the columns of VR, in the same order as their eigenvalues.
136: *          If the j-th eigenvalue is real, then x(j) = VR(:,j).
137: *          If the j-th and (j+1)-st eigenvalues form a complex conjugate
138: *          pair, then
139: *            x(j) = VR(:,j) + i*VR(:,j+1)
140: *          and
141: *            x(j+1) = VR(:,j) - i*VR(:,j+1).
142: *
143: *          Each eigenvector is scaled so that its largest component has
144: *          abs(real part) + abs(imag. part) = 1, except for eigenvalues
145: *          corresponding to an eigenvalue with alpha = beta = 0, which
146: *          are set to zero.
147: *          Not referenced if JOBVR = 'N'.
148: *
149: *  LDVR    (input) INTEGER
150: *          The leading dimension of the matrix VR. LDVR >= 1, and
151: *          if JOBVR = 'V', LDVR >= N.
152: *
153: *  WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
154: *          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
155: *
156: *  LWORK   (input) INTEGER
157: *          The dimension of the array WORK.  LWORK >= max(1,8*N).
158: *          For good performance, LWORK must generally be larger.
159: *          To compute the optimal value of LWORK, call ILAENV to get
160: *          blocksizes (for DGEQRF, DORMQR, and DORGQR.)  Then compute:
161: *          NB  -- MAX of the blocksizes for DGEQRF, DORMQR, and DORGQR;
162: *          The optimal LWORK is:
163: *              2*N + MAX( 6*N, N*(NB+1) ).
164: *
165: *          If LWORK = -1, then a workspace query is assumed; the routine
166: *          only calculates the optimal size of the WORK array, returns
167: *          this value as the first entry of the WORK array, and no error
168: *          message related to LWORK is issued by XERBLA.
169: *
170: *  INFO    (output) INTEGER
171: *          = 0:  successful exit
172: *          < 0:  if INFO = -i, the i-th argument had an illegal value.
173: *          = 1,...,N:
174: *                The QZ iteration failed.  No eigenvectors have been
175: *                calculated, but ALPHAR(j), ALPHAI(j), and BETA(j)
176: *                should be correct for j=INFO+1,...,N.
177: *          > N:  errors that usually indicate LAPACK problems:
178: *                =N+1: error return from DGGBAL
179: *                =N+2: error return from DGEQRF
180: *                =N+3: error return from DORMQR
181: *                =N+4: error return from DORGQR
182: *                =N+5: error return from DGGHRD
183: *                =N+6: error return from DHGEQZ (other than failed
184: *                                                iteration)
185: *                =N+7: error return from DTGEVC
186: *                =N+8: error return from DGGBAK (computing VL)
187: *                =N+9: error return from DGGBAK (computing VR)
188: *                =N+10: error return from DLASCL (various calls)
189: *
190: *  Further Details
191: *  ===============
192: *
193: *  Balancing
194: *  ---------
195: *
196: *  This driver calls DGGBAL to both permute and scale rows and columns
197: *  of A and B.  The permutations PL and PR are chosen so that PL*A*PR
198: *  and PL*B*R will be upper triangular except for the diagonal blocks
199: *  A(i:j,i:j) and B(i:j,i:j), with i and j as close together as
200: *  possible.  The diagonal scaling matrices DL and DR are chosen so
201: *  that the pair  DL*PL*A*PR*DR, DL*PL*B*PR*DR have elements close to
202: *  one (except for the elements that start out zero.)
203: *
204: *  After the eigenvalues and eigenvectors of the balanced matrices
205: *  have been computed, DGGBAK transforms the eigenvectors back to what
206: *  they would have been (in perfect arithmetic) if they had not been
207: *  balanced.
208: *
209: *  Contents of A and B on Exit
210: *  -------- -- - --- - -- ----
211: *
212: *  If any eigenvectors are computed (either JOBVL='V' or JOBVR='V' or
213: *  both), then on exit the arrays A and B will contain the real Schur
214: *  form[*] of the "balanced" versions of A and B.  If no eigenvectors
215: *  are computed, then only the diagonal blocks will be correct.
216: *
217: *  [*] See DHGEQZ, DGEGS, or read the book "Matrix Computations",
218: *      by Golub & van Loan, pub. by Johns Hopkins U. Press.
219: *
220: *  =====================================================================
221: *
222: *     .. Parameters ..
223:       DOUBLE PRECISION   ZERO, ONE
224:       PARAMETER          ( ZERO = 0.0D0, ONE = 1.0D0 )
225: *     ..
226: *     .. Local Scalars ..
227:       LOGICAL            ILIMIT, ILV, ILVL, ILVR, LQUERY
228:       CHARACTER          CHTEMP
229:       INTEGER            ICOLS, IHI, IINFO, IJOBVL, IJOBVR, ILEFT, ILO,
230:      $                   IN, IRIGHT, IROWS, ITAU, IWORK, JC, JR, LOPT,
231:      $                   LWKMIN, LWKOPT, NB, NB1, NB2, NB3
232:       DOUBLE PRECISION   ABSAI, ABSAR, ABSB, ANRM, ANRM1, ANRM2, BNRM,
233:      $                   BNRM1, BNRM2, EPS, ONEPLS, SAFMAX, SAFMIN,
234:      $                   SALFAI, SALFAR, SBETA, SCALE, TEMP
235: *     ..
236: *     .. Local Arrays ..
237:       LOGICAL            LDUMMA( 1 )
238: *     ..
239: *     .. External Subroutines ..
240:       EXTERNAL           DGEQRF, DGGBAK, DGGBAL, DGGHRD, DHGEQZ, DLACPY,
241:      $                   DLASCL, DLASET, DORGQR, DORMQR, DTGEVC, XERBLA
242: *     ..
243: *     .. External Functions ..
244:       LOGICAL            LSAME
245:       INTEGER            ILAENV
246:       DOUBLE PRECISION   DLAMCH, DLANGE
247:       EXTERNAL           LSAME, ILAENV, DLAMCH, DLANGE
248: *     ..
249: *     .. Intrinsic Functions ..
250:       INTRINSIC          ABS, INT, MAX
251: *     ..
252: *     .. Executable Statements ..
253: *
254: *     Decode the input arguments
255: *
256:       IF( LSAME( JOBVL, 'N' ) ) THEN
257:          IJOBVL = 1
258:          ILVL = .FALSE.
259:       ELSE IF( LSAME( JOBVL, 'V' ) ) THEN
260:          IJOBVL = 2
261:          ILVL = .TRUE.
262:       ELSE
263:          IJOBVL = -1
264:          ILVL = .FALSE.
265:       END IF
266: *
267:       IF( LSAME( JOBVR, 'N' ) ) THEN
268:          IJOBVR = 1
269:          ILVR = .FALSE.
270:       ELSE IF( LSAME( JOBVR, 'V' ) ) THEN
271:          IJOBVR = 2
272:          ILVR = .TRUE.
273:       ELSE
274:          IJOBVR = -1
275:          ILVR = .FALSE.
276:       END IF
277:       ILV = ILVL .OR. ILVR
278: *
279: *     Test the input arguments
280: *
281:       LWKMIN = MAX( 8*N, 1 )
282:       LWKOPT = LWKMIN
283:       WORK( 1 ) = LWKOPT
284:       LQUERY = ( LWORK.EQ.-1 )
285:       INFO = 0
286:       IF( IJOBVL.LE.0 ) THEN
287:          INFO = -1
288:       ELSE IF( IJOBVR.LE.0 ) THEN
289:          INFO = -2
290:       ELSE IF( N.LT.0 ) THEN
291:          INFO = -3
292:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
293:          INFO = -5
294:       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
295:          INFO = -7
296:       ELSE IF( LDVL.LT.1 .OR. ( ILVL .AND. LDVL.LT.N ) ) THEN
297:          INFO = -12
298:       ELSE IF( LDVR.LT.1 .OR. ( ILVR .AND. LDVR.LT.N ) ) THEN
299:          INFO = -14
300:       ELSE IF( LWORK.LT.LWKMIN .AND. .NOT.LQUERY ) THEN
301:          INFO = -16
302:       END IF
303: *
304:       IF( INFO.EQ.0 ) THEN
305:          NB1 = ILAENV( 1, 'DGEQRF', ' ', N, N, -1, -1 )
306:          NB2 = ILAENV( 1, 'DORMQR', ' ', N, N, N, -1 )
307:          NB3 = ILAENV( 1, 'DORGQR', ' ', N, N, N, -1 )
308:          NB = MAX( NB1, NB2, NB3 )
309:          LOPT = 2*N + MAX( 6*N, N*( NB+1 ) )
310:          WORK( 1 ) = LOPT
311:       END IF
312: *
313:       IF( INFO.NE.0 ) THEN
314:          CALL XERBLA( 'DGEGV ', -INFO )
315:          RETURN
316:       ELSE IF( LQUERY ) THEN
317:          RETURN
318:       END IF
319: *
320: *     Quick return if possible
321: *
322:       IF( N.EQ.0 )
323:      $   RETURN
324: *
325: *     Get machine constants
326: *
327:       EPS = DLAMCH( 'E' )*DLAMCH( 'B' )
328:       SAFMIN = DLAMCH( 'S' )
329:       SAFMIN = SAFMIN + SAFMIN
330:       SAFMAX = ONE / SAFMIN
331:       ONEPLS = ONE + ( 4*EPS )
332: *
333: *     Scale A
334: *
335:       ANRM = DLANGE( 'M', N, N, A, LDA, WORK )
336:       ANRM1 = ANRM
337:       ANRM2 = ONE
338:       IF( ANRM.LT.ONE ) THEN
339:          IF( SAFMAX*ANRM.LT.ONE ) THEN
340:             ANRM1 = SAFMIN
341:             ANRM2 = SAFMAX*ANRM
342:          END IF
343:       END IF
344: *
345:       IF( ANRM.GT.ZERO ) THEN
346:          CALL DLASCL( 'G', -1, -1, ANRM, ONE, N, N, A, LDA, IINFO )
347:          IF( IINFO.NE.0 ) THEN
348:             INFO = N + 10
349:             RETURN
350:          END IF
351:       END IF
352: *
353: *     Scale B
354: *
355:       BNRM = DLANGE( 'M', N, N, B, LDB, WORK )
356:       BNRM1 = BNRM
357:       BNRM2 = ONE
358:       IF( BNRM.LT.ONE ) THEN
359:          IF( SAFMAX*BNRM.LT.ONE ) THEN
360:             BNRM1 = SAFMIN
361:             BNRM2 = SAFMAX*BNRM
362:          END IF
363:       END IF
364: *
365:       IF( BNRM.GT.ZERO ) THEN
366:          CALL DLASCL( 'G', -1, -1, BNRM, ONE, N, N, B, LDB, IINFO )
367:          IF( IINFO.NE.0 ) THEN
368:             INFO = N + 10
369:             RETURN
370:          END IF
371:       END IF
372: *
373: *     Permute the matrix to make it more nearly triangular
374: *     Workspace layout:  (8*N words -- "work" requires 6*N words)
375: *        left_permutation, right_permutation, work...
376: *
377:       ILEFT = 1
378:       IRIGHT = N + 1
379:       IWORK = IRIGHT + N
380:       CALL DGGBAL( 'P', N, A, LDA, B, LDB, ILO, IHI, WORK( ILEFT ),
381:      $             WORK( IRIGHT ), WORK( IWORK ), IINFO )
382:       IF( IINFO.NE.0 ) THEN
383:          INFO = N + 1
384:          GO TO 120
385:       END IF
386: *
387: *     Reduce B to triangular form, and initialize VL and/or VR
388: *     Workspace layout:  ("work..." must have at least N words)
389: *        left_permutation, right_permutation, tau, work...
390: *
391:       IROWS = IHI + 1 - ILO
392:       IF( ILV ) THEN
393:          ICOLS = N + 1 - ILO
394:       ELSE
395:          ICOLS = IROWS
396:       END IF
397:       ITAU = IWORK
398:       IWORK = ITAU + IROWS
399:       CALL DGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ),
400:      $             WORK( IWORK ), LWORK+1-IWORK, IINFO )
401:       IF( IINFO.GE.0 )
402:      $   LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 )
403:       IF( IINFO.NE.0 ) THEN
404:          INFO = N + 2
405:          GO TO 120
406:       END IF
407: *
408:       CALL DORMQR( 'L', 'T', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB,
409:      $             WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWORK ),
410:      $             LWORK+1-IWORK, IINFO )
411:       IF( IINFO.GE.0 )
412:      $   LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 )
413:       IF( IINFO.NE.0 ) THEN
414:          INFO = N + 3
415:          GO TO 120
416:       END IF
417: *
418:       IF( ILVL ) THEN
419:          CALL DLASET( 'Full', N, N, ZERO, ONE, VL, LDVL )
420:          CALL DLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB,
421:      $                VL( ILO+1, ILO ), LDVL )
422:          CALL DORGQR( IROWS, IROWS, IROWS, VL( ILO, ILO ), LDVL,
423:      $                WORK( ITAU ), WORK( IWORK ), LWORK+1-IWORK,
424:      $                IINFO )
425:          IF( IINFO.GE.0 )
426:      $      LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 )
427:          IF( IINFO.NE.0 ) THEN
428:             INFO = N + 4
429:             GO TO 120
430:          END IF
431:       END IF
432: *
433:       IF( ILVR )
434:      $   CALL DLASET( 'Full', N, N, ZERO, ONE, VR, LDVR )
435: *
436: *     Reduce to generalized Hessenberg form
437: *
438:       IF( ILV ) THEN
439: *
440: *        Eigenvectors requested -- work on whole matrix.
441: *
442:          CALL DGGHRD( JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB, VL,
443:      $                LDVL, VR, LDVR, IINFO )
444:       ELSE
445:          CALL DGGHRD( 'N', 'N', IROWS, 1, IROWS, A( ILO, ILO ), LDA,
446:      $                B( ILO, ILO ), LDB, VL, LDVL, VR, LDVR, IINFO )
447:       END IF
448:       IF( IINFO.NE.0 ) THEN
449:          INFO = N + 5
450:          GO TO 120
451:       END IF
452: *
453: *     Perform QZ algorithm
454: *     Workspace layout:  ("work..." must have at least 1 word)
455: *        left_permutation, right_permutation, work...
456: *
457:       IWORK = ITAU
458:       IF( ILV ) THEN
459:          CHTEMP = 'S'
460:       ELSE
461:          CHTEMP = 'E'
462:       END IF
463:       CALL DHGEQZ( CHTEMP, JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB,
464:      $             ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR,
465:      $             WORK( IWORK ), LWORK+1-IWORK, IINFO )
466:       IF( IINFO.GE.0 )
467:      $   LWKOPT = MAX( LWKOPT, INT( WORK( IWORK ) )+IWORK-1 )
468:       IF( IINFO.NE.0 ) THEN
469:          IF( IINFO.GT.0 .AND. IINFO.LE.N ) THEN
470:             INFO = IINFO
471:          ELSE IF( IINFO.GT.N .AND. IINFO.LE.2*N ) THEN
472:             INFO = IINFO - N
473:          ELSE
474:             INFO = N + 6
475:          END IF
476:          GO TO 120
477:       END IF
478: *
479:       IF( ILV ) THEN
480: *
481: *        Compute Eigenvectors  (DTGEVC requires 6*N words of workspace)
482: *
483:          IF( ILVL ) THEN
484:             IF( ILVR ) THEN
485:                CHTEMP = 'B'
486:             ELSE
487:                CHTEMP = 'L'
488:             END IF
489:          ELSE
490:             CHTEMP = 'R'
491:          END IF
492: *
493:          CALL DTGEVC( CHTEMP, 'B', LDUMMA, N, A, LDA, B, LDB, VL, LDVL,
494:      $                VR, LDVR, N, IN, WORK( IWORK ), IINFO )
495:          IF( IINFO.NE.0 ) THEN
496:             INFO = N + 7
497:             GO TO 120
498:          END IF
499: *
500: *        Undo balancing on VL and VR, rescale
501: *
502:          IF( ILVL ) THEN
503:             CALL DGGBAK( 'P', 'L', N, ILO, IHI, WORK( ILEFT ),
504:      $                   WORK( IRIGHT ), N, VL, LDVL, IINFO )
505:             IF( IINFO.NE.0 ) THEN
506:                INFO = N + 8
507:                GO TO 120
508:             END IF
509:             DO 50 JC = 1, N
510:                IF( ALPHAI( JC ).LT.ZERO )
511:      $            GO TO 50
512:                TEMP = ZERO
513:                IF( ALPHAI( JC ).EQ.ZERO ) THEN
514:                   DO 10 JR = 1, N
515:                      TEMP = MAX( TEMP, ABS( VL( JR, JC ) ) )
516:    10             CONTINUE
517:                ELSE
518:                   DO 20 JR = 1, N
519:                      TEMP = MAX( TEMP, ABS( VL( JR, JC ) )+
520:      $                      ABS( VL( JR, JC+1 ) ) )
521:    20             CONTINUE
522:                END IF
523:                IF( TEMP.LT.SAFMIN )
524:      $            GO TO 50
525:                TEMP = ONE / TEMP
526:                IF( ALPHAI( JC ).EQ.ZERO ) THEN
527:                   DO 30 JR = 1, N
528:                      VL( JR, JC ) = VL( JR, JC )*TEMP
529:    30             CONTINUE
530:                ELSE
531:                   DO 40 JR = 1, N
532:                      VL( JR, JC ) = VL( JR, JC )*TEMP
533:                      VL( JR, JC+1 ) = VL( JR, JC+1 )*TEMP
534:    40             CONTINUE
535:                END IF
536:    50       CONTINUE
537:          END IF
538:          IF( ILVR ) THEN
539:             CALL DGGBAK( 'P', 'R', N, ILO, IHI, WORK( ILEFT ),
540:      $                   WORK( IRIGHT ), N, VR, LDVR, IINFO )
541:             IF( IINFO.NE.0 ) THEN
542:                INFO = N + 9
543:                GO TO 120
544:             END IF
545:             DO 100 JC = 1, N
546:                IF( ALPHAI( JC ).LT.ZERO )
547:      $            GO TO 100
548:                TEMP = ZERO
549:                IF( ALPHAI( JC ).EQ.ZERO ) THEN
550:                   DO 60 JR = 1, N
551:                      TEMP = MAX( TEMP, ABS( VR( JR, JC ) ) )
552:    60             CONTINUE
553:                ELSE
554:                   DO 70 JR = 1, N
555:                      TEMP = MAX( TEMP, ABS( VR( JR, JC ) )+
556:      $                      ABS( VR( JR, JC+1 ) ) )
557:    70             CONTINUE
558:                END IF
559:                IF( TEMP.LT.SAFMIN )
560:      $            GO TO 100
561:                TEMP = ONE / TEMP
562:                IF( ALPHAI( JC ).EQ.ZERO ) THEN
563:                   DO 80 JR = 1, N
564:                      VR( JR, JC ) = VR( JR, JC )*TEMP
565:    80             CONTINUE
566:                ELSE
567:                   DO 90 JR = 1, N
568:                      VR( JR, JC ) = VR( JR, JC )*TEMP
569:                      VR( JR, JC+1 ) = VR( JR, JC+1 )*TEMP
570:    90             CONTINUE
571:                END IF
572:   100       CONTINUE
573:          END IF
574: *
575: *        End of eigenvector calculation
576: *
577:       END IF
578: *
579: *     Undo scaling in alpha, beta
580: *
581: *     Note: this does not give the alpha and beta for the unscaled
582: *     problem.
583: *
584: *     Un-scaling is limited to avoid underflow in alpha and beta
585: *     if they are significant.
586: *
587:       DO 110 JC = 1, N
588:          ABSAR = ABS( ALPHAR( JC ) )
589:          ABSAI = ABS( ALPHAI( JC ) )
590:          ABSB = ABS( BETA( JC ) )
591:          SALFAR = ANRM*ALPHAR( JC )
592:          SALFAI = ANRM*ALPHAI( JC )
593:          SBETA = BNRM*BETA( JC )
594:          ILIMIT = .FALSE.
595:          SCALE = ONE
596: *
597: *        Check for significant underflow in ALPHAI
598: *
599:          IF( ABS( SALFAI ).LT.SAFMIN .AND. ABSAI.GE.
600:      $       MAX( SAFMIN, EPS*ABSAR, EPS*ABSB ) ) THEN
601:             ILIMIT = .TRUE.
602:             SCALE = ( ONEPLS*SAFMIN / ANRM1 ) /
603:      $              MAX( ONEPLS*SAFMIN, ANRM2*ABSAI )
604: *
605:          ELSE IF( SALFAI.EQ.ZERO ) THEN
606: *
607: *           If insignificant underflow in ALPHAI, then make the
608: *           conjugate eigenvalue real.
609: *
610:             IF( ALPHAI( JC ).LT.ZERO .AND. JC.GT.1 ) THEN
611:                ALPHAI( JC-1 ) = ZERO
612:             ELSE IF( ALPHAI( JC ).GT.ZERO .AND. JC.LT.N ) THEN
613:                ALPHAI( JC+1 ) = ZERO
614:             END IF
615:          END IF
616: *
617: *        Check for significant underflow in ALPHAR
618: *
619:          IF( ABS( SALFAR ).LT.SAFMIN .AND. ABSAR.GE.
620:      $       MAX( SAFMIN, EPS*ABSAI, EPS*ABSB ) ) THEN
621:             ILIMIT = .TRUE.
622:             SCALE = MAX( SCALE, ( ONEPLS*SAFMIN / ANRM1 ) /
623:      $              MAX( ONEPLS*SAFMIN, ANRM2*ABSAR ) )
624:          END IF
625: *
626: *        Check for significant underflow in BETA
627: *
628:          IF( ABS( SBETA ).LT.SAFMIN .AND. ABSB.GE.
629:      $       MAX( SAFMIN, EPS*ABSAR, EPS*ABSAI ) ) THEN
630:             ILIMIT = .TRUE.
631:             SCALE = MAX( SCALE, ( ONEPLS*SAFMIN / BNRM1 ) /
632:      $              MAX( ONEPLS*SAFMIN, BNRM2*ABSB ) )
633:          END IF
634: *
635: *        Check for possible overflow when limiting scaling
636: *
637:          IF( ILIMIT ) THEN
638:             TEMP = ( SCALE*SAFMIN )*MAX( ABS( SALFAR ), ABS( SALFAI ),
639:      $             ABS( SBETA ) )
640:             IF( TEMP.GT.ONE )
641:      $         SCALE = SCALE / TEMP
642:             IF( SCALE.LT.ONE )
643:      $         ILIMIT = .FALSE.
644:          END IF
645: *
646: *        Recompute un-scaled ALPHAR, ALPHAI, BETA if necessary.
647: *
648:          IF( ILIMIT ) THEN
649:             SALFAR = ( SCALE*ALPHAR( JC ) )*ANRM
650:             SALFAI = ( SCALE*ALPHAI( JC ) )*ANRM
651:             SBETA = ( SCALE*BETA( JC ) )*BNRM
652:          END IF
653:          ALPHAR( JC ) = SALFAR
654:          ALPHAI( JC ) = SALFAI
655:          BETA( JC ) = SBETA
656:   110 CONTINUE
657: *
658:   120 CONTINUE
659:       WORK( 1 ) = LWKOPT
660: *
661:       RETURN
662: *
663: *     End of DGEGV
664: *
665:       END
666: