001:       SUBROUTINE SGEEVX( BALANC, JOBVL, JOBVR, SENSE, N, A, LDA, WR, WI,
002:      $                   VL, LDVL, VR, LDVR, ILO, IHI, SCALE, ABNRM,
003:      $                   RCONDE, RCONDV, WORK, LWORK, IWORK, INFO )
004: *
005: *  -- LAPACK driver routine (version 3.2) --
006: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
007: *     November 2006
008: *
009: *     .. Scalar Arguments ..
010:       CHARACTER          BALANC, JOBVL, JOBVR, SENSE
011:       INTEGER            IHI, ILO, INFO, LDA, LDVL, LDVR, LWORK, N
012:       REAL               ABNRM
013: *     ..
014: *     .. Array Arguments ..
015:       INTEGER            IWORK( * )
016:       REAL               A( LDA, * ), RCONDE( * ), RCONDV( * ),
017:      $                   SCALE( * ), VL( LDVL, * ), VR( LDVR, * ),
018:      $                   WI( * ), WORK( * ), WR( * )
019: *     ..
020: *
021: *  Purpose
022: *  =======
023: *
024: *  SGEEVX computes for an N-by-N real nonsymmetric matrix A, the
025: *  eigenvalues and, optionally, the left and/or right eigenvectors.
026: *
027: *  Optionally also, it computes a balancing transformation to improve
028: *  the conditioning of the eigenvalues and eigenvectors (ILO, IHI,
029: *  SCALE, and ABNRM), reciprocal condition numbers for the eigenvalues
030: *  (RCONDE), and reciprocal condition numbers for the right
031: *  eigenvectors (RCONDV).
032: *
033: *  The right eigenvector v(j) of A satisfies
034: *                   A * v(j) = lambda(j) * v(j)
035: *  where lambda(j) is its eigenvalue.
036: *  The left eigenvector u(j) of A satisfies
037: *                u(j)**H * A = lambda(j) * u(j)**H
038: *  where u(j)**H denotes the conjugate transpose of u(j).
039: *
040: *  The computed eigenvectors are normalized to have Euclidean norm
041: *  equal to 1 and largest component real.
042: *
043: *  Balancing a matrix means permuting the rows and columns to make it
044: *  more nearly upper triangular, and applying a diagonal similarity
045: *  transformation D * A * D**(-1), where D is a diagonal matrix, to
046: *  make its rows and columns closer in norm and the condition numbers
047: *  of its eigenvalues and eigenvectors smaller.  The computed
048: *  reciprocal condition numbers correspond to the balanced matrix.
049: *  Permuting rows and columns will not change the condition numbers
050: *  (in exact arithmetic) but diagonal scaling will.  For further
051: *  explanation of balancing, see section 4.10.2 of the LAPACK
052: *  Users' Guide.
053: *
054: *  Arguments
055: *  =========
056: *
057: *  BALANC  (input) CHARACTER*1
058: *          Indicates how the input matrix should be diagonally scaled
059: *          and/or permuted to improve the conditioning of its
060: *          eigenvalues.
061: *          = 'N': Do not diagonally scale or permute;
062: *          = 'P': Perform permutations to make the matrix more nearly
063: *                 upper triangular. Do not diagonally scale;
064: *          = 'S': Diagonally scale the matrix, i.e. replace A by
065: *                 D*A*D**(-1), where D is a diagonal matrix chosen
066: *                 to make the rows and columns of A more equal in
067: *                 norm. Do not permute;
068: *          = 'B': Both diagonally scale and permute A.
069: *
070: *          Computed reciprocal condition numbers will be for the matrix
071: *          after balancing and/or permuting. Permuting does not change
072: *          condition numbers (in exact arithmetic), but balancing does.
073: *
074: *  JOBVL   (input) CHARACTER*1
075: *          = 'N': left eigenvectors of A are not computed;
076: *          = 'V': left eigenvectors of A are computed.
077: *          If SENSE = 'E' or 'B', JOBVL must = 'V'.
078: *
079: *  JOBVR   (input) CHARACTER*1
080: *          = 'N': right eigenvectors of A are not computed;
081: *          = 'V': right eigenvectors of A are computed.
082: *          If SENSE = 'E' or 'B', JOBVR must = 'V'.
083: *
084: *  SENSE   (input) CHARACTER*1
085: *          Determines which reciprocal condition numbers are computed.
086: *          = 'N': None are computed;
087: *          = 'E': Computed for eigenvalues only;
088: *          = 'V': Computed for right eigenvectors only;
089: *          = 'B': Computed for eigenvalues and right eigenvectors.
090: *
091: *          If SENSE = 'E' or 'B', both left and right eigenvectors
092: *          must also be computed (JOBVL = 'V' and JOBVR = 'V').
093: *
094: *  N       (input) INTEGER
095: *          The order of the matrix A. N >= 0.
096: *
097: *  A       (input/output) REAL array, dimension (LDA,N)
098: *          On entry, the N-by-N matrix A.
099: *          On exit, A has been overwritten.  If JOBVL = 'V' or
100: *          JOBVR = 'V', A contains the real Schur form of the balanced
101: *          version of the input matrix A.
102: *
103: *  LDA     (input) INTEGER
104: *          The leading dimension of the array A.  LDA >= max(1,N).
105: *
106: *  WR      (output) REAL array, dimension (N)
107: *  WI      (output) REAL array, dimension (N)
108: *          WR and WI contain the real and imaginary parts,
109: *          respectively, of the computed eigenvalues.  Complex
110: *          conjugate pairs of eigenvalues will appear consecutively
111: *          with the eigenvalue having the positive imaginary part
112: *          first.
113: *
114: *  VL      (output) REAL array, dimension (LDVL,N)
115: *          If JOBVL = 'V', the left eigenvectors u(j) are stored one
116: *          after another in the columns of VL, in the same order
117: *          as their eigenvalues.
118: *          If JOBVL = 'N', VL is not referenced.
119: *          If the j-th eigenvalue is real, then u(j) = VL(:,j),
120: *          the j-th column of VL.
121: *          If the j-th and (j+1)-st eigenvalues form a complex
122: *          conjugate pair, then u(j) = VL(:,j) + i*VL(:,j+1) and
123: *          u(j+1) = VL(:,j) - i*VL(:,j+1).
124: *
125: *  LDVL    (input) INTEGER
126: *          The leading dimension of the array VL.  LDVL >= 1; if
127: *          JOBVL = 'V', LDVL >= N.
128: *
129: *  VR      (output) REAL array, dimension (LDVR,N)
130: *          If JOBVR = 'V', the right eigenvectors v(j) are stored one
131: *          after another in the columns of VR, in the same order
132: *          as their eigenvalues.
133: *          If JOBVR = 'N', VR is not referenced.
134: *          If the j-th eigenvalue is real, then v(j) = VR(:,j),
135: *          the j-th column of VR.
136: *          If the j-th and (j+1)-st eigenvalues form a complex
137: *          conjugate pair, then v(j) = VR(:,j) + i*VR(:,j+1) and
138: *          v(j+1) = VR(:,j) - i*VR(:,j+1).
139: *
140: *  LDVR    (input) INTEGER
141: *          The leading dimension of the array VR.  LDVR >= 1, and if
142: *          JOBVR = 'V', LDVR >= N.
143: *
144: *  ILO     (output) INTEGER
145: *  IHI     (output) INTEGER
146: *          ILO and IHI are integer values determined when A was
147: *          balanced.  The balanced A(i,j) = 0 if I > J and 
148: *          J = 1,...,ILO-1 or I = IHI+1,...,N.
149: *
150: *  SCALE   (output) REAL array, dimension (N)
151: *          Details of the permutations and scaling factors applied
152: *          when balancing A.  If P(j) is the index of the row and column
153: *          interchanged with row and column j, and D(j) is the scaling
154: *          factor applied to row and column j, then
155: *          SCALE(J) = P(J),    for J = 1,...,ILO-1
156: *                   = D(J),    for J = ILO,...,IHI
157: *                   = P(J)     for J = IHI+1,...,N.
158: *          The order in which the interchanges are made is N to IHI+1,
159: *          then 1 to ILO-1.
160: *
161: *  ABNRM   (output) REAL
162: *          The one-norm of the balanced matrix (the maximum
163: *          of the sum of absolute values of elements of any column).
164: *
165: *  RCONDE  (output) REAL array, dimension (N)
166: *          RCONDE(j) is the reciprocal condition number of the j-th
167: *          eigenvalue.
168: *
169: *  RCONDV  (output) REAL array, dimension (N)
170: *          RCONDV(j) is the reciprocal condition number of the j-th
171: *          right eigenvector.
172: *
173: *  WORK    (workspace/output) REAL array, dimension (MAX(1,LWORK))
174: *          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
175: *
176: *  LWORK   (input) INTEGER
177: *          The dimension of the array WORK.   If SENSE = 'N' or 'E',
178: *          LWORK >= max(1,2*N), and if JOBVL = 'V' or JOBVR = 'V',
179: *          LWORK >= 3*N.  If SENSE = 'V' or 'B', LWORK >= N*(N+6).
180: *          For good performance, LWORK must generally be larger.
181: *
182: *          If LWORK = -1, then a workspace query is assumed; the routine
183: *          only calculates the optimal size of the WORK array, returns
184: *          this value as the first entry of the WORK array, and no error
185: *          message related to LWORK is issued by XERBLA.
186: *
187: *  IWORK   (workspace) INTEGER array, dimension (2*N-2)
188: *          If SENSE = 'N' or 'E', not referenced.
189: *
190: *  INFO    (output) INTEGER
191: *          = 0:  successful exit
192: *          < 0:  if INFO = -i, the i-th argument had an illegal value.
193: *          > 0:  if INFO = i, the QR algorithm failed to compute all the
194: *                eigenvalues, and no eigenvectors or condition numbers
195: *                have been computed; elements 1:ILO-1 and i+1:N of WR
196: *                and WI contain eigenvalues which have converged.
197: *
198: *  =====================================================================
199: *
200: *     .. Parameters ..
201:       REAL               ZERO, ONE
202:       PARAMETER          ( ZERO = 0.0E0, ONE = 1.0E0 )
203: *     ..
204: *     .. Local Scalars ..
205:       LOGICAL            LQUERY, SCALEA, WANTVL, WANTVR, WNTSNB, WNTSNE,
206:      $                   WNTSNN, WNTSNV
207:       CHARACTER          JOB, SIDE
208:       INTEGER            HSWORK, I, ICOND, IERR, ITAU, IWRK, K, MAXWRK,
209:      $                   MINWRK, NOUT
210:       REAL               ANRM, BIGNUM, CS, CSCALE, EPS, R, SCL, SMLNUM,
211:      $                   SN
212: *     ..
213: *     .. Local Arrays ..
214:       LOGICAL            SELECT( 1 )
215:       REAL               DUM( 1 )
216: *     ..
217: *     .. External Subroutines ..
218:       EXTERNAL           SGEBAK, SGEBAL, SGEHRD, SHSEQR, SLABAD, SLACPY,
219:      $                   SLARTG, SLASCL, SORGHR, SROT, SSCAL, STREVC,
220:      $                   STRSNA, XERBLA
221: *     ..
222: *     .. External Functions ..
223:       LOGICAL            LSAME
224:       INTEGER            ILAENV, ISAMAX
225:       REAL               SLAMCH, SLANGE, SLAPY2, SNRM2
226:       EXTERNAL           LSAME, ILAENV, ISAMAX, SLAMCH, SLANGE, SLAPY2,
227:      $                   SNRM2
228: *     ..
229: *     .. Intrinsic Functions ..
230:       INTRINSIC          MAX, SQRT
231: *     ..
232: *     .. Executable Statements ..
233: *
234: *     Test the input arguments
235: *
236:       INFO = 0
237:       LQUERY = ( LWORK.EQ.-1 )
238:       WANTVL = LSAME( JOBVL, 'V' )
239:       WANTVR = LSAME( JOBVR, 'V' )
240:       WNTSNN = LSAME( SENSE, 'N' )
241:       WNTSNE = LSAME( SENSE, 'E' )
242:       WNTSNV = LSAME( SENSE, 'V' )
243:       WNTSNB = LSAME( SENSE, 'B' )
244:       IF( .NOT.( LSAME( BALANC, 'N' ) .OR. LSAME( BALANC, 'S' ) .OR.
245:      $    LSAME( BALANC, 'P' ) .OR. LSAME( BALANC, 'B' ) ) ) THEN
246:          INFO = -1
247:       ELSE IF( ( .NOT.WANTVL ) .AND. ( .NOT.LSAME( JOBVL, 'N' ) ) ) THEN
248:          INFO = -2
249:       ELSE IF( ( .NOT.WANTVR ) .AND. ( .NOT.LSAME( JOBVR, 'N' ) ) ) THEN
250:          INFO = -3
251:       ELSE IF( .NOT.( WNTSNN .OR. WNTSNE .OR. WNTSNB .OR. WNTSNV ) .OR.
252:      $         ( ( WNTSNE .OR. WNTSNB ) .AND. .NOT.( WANTVL .AND.
253:      $         WANTVR ) ) ) THEN
254:          INFO = -4
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( LDVL.LT.1 .OR. ( WANTVL .AND. LDVL.LT.N ) ) THEN
260:          INFO = -11
261:       ELSE IF( LDVR.LT.1 .OR. ( WANTVR .AND. LDVR.LT.N ) ) THEN
262:          INFO = -13
263:       END IF
264: *
265: *     Compute workspace
266: *      (Note: Comments in the code beginning "Workspace:" describe the
267: *       minimal amount of workspace needed at that point in the code,
268: *       as well as the preferred amount for good performance.
269: *       NB refers to the optimal block size for the immediately
270: *       following subroutine, as returned by ILAENV.
271: *       HSWORK refers to the workspace preferred by SHSEQR, as
272: *       calculated below. HSWORK is computed assuming ILO=1 and IHI=N,
273: *       the worst case.)
274: *
275:       IF( INFO.EQ.0 ) THEN
276:          IF( N.EQ.0 ) THEN
277:             MINWRK = 1
278:             MAXWRK = 1
279:          ELSE
280:             MAXWRK = N + N*ILAENV( 1, 'SGEHRD', ' ', N, 1, N, 0 )
281: *
282:             IF( WANTVL ) THEN
283:                CALL SHSEQR( 'S', 'V', N, 1, N, A, LDA, WR, WI, VL, LDVL,
284:      $                WORK, -1, INFO )
285:             ELSE IF( WANTVR ) THEN
286:                CALL SHSEQR( 'S', 'V', N, 1, N, A, LDA, WR, WI, VR, LDVR,
287:      $                WORK, -1, INFO )
288:             ELSE
289:                IF( WNTSNN ) THEN
290:                   CALL SHSEQR( 'E', 'N', N, 1, N, A, LDA, WR, WI, VR,
291:      $                LDVR, WORK, -1, INFO )
292:                ELSE
293:                   CALL SHSEQR( 'S', 'N', N, 1, N, A, LDA, WR, WI, VR,
294:      $                LDVR, WORK, -1, INFO )
295:                END IF
296:             END IF
297:             HSWORK = WORK( 1 )
298: *
299:             IF( ( .NOT.WANTVL ) .AND. ( .NOT.WANTVR ) ) THEN
300:                MINWRK = 2*N
301:                IF( .NOT.WNTSNN )
302:      $            MINWRK = MAX( MINWRK, N*N+6*N )
303:                MAXWRK = MAX( MAXWRK, HSWORK )
304:                IF( .NOT.WNTSNN )
305:      $            MAXWRK = MAX( MAXWRK, N*N + 6*N )
306:             ELSE
307:                MINWRK = 3*N
308:                IF( ( .NOT.WNTSNN ) .AND. ( .NOT.WNTSNE ) )
309:      $            MINWRK = MAX( MINWRK, N*N + 6*N )
310:                MAXWRK = MAX( MAXWRK, HSWORK )
311:                MAXWRK = MAX( MAXWRK, N + ( N - 1 )*ILAENV( 1, 'SORGHR',
312:      $                       ' ', N, 1, N, -1 ) )
313:                IF( ( .NOT.WNTSNN ) .AND. ( .NOT.WNTSNE ) )
314:      $            MAXWRK = MAX( MAXWRK, N*N + 6*N )
315:                MAXWRK = MAX( MAXWRK, 3*N )
316:             END IF
317:             MAXWRK = MAX( MAXWRK, MINWRK )
318:          END IF
319:          WORK( 1 ) = MAXWRK
320: *
321:          IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN
322:             INFO = -21
323:          END IF
324:       END IF
325: *
326:       IF( INFO.NE.0 ) THEN
327:          CALL XERBLA( 'SGEEVX', -INFO )
328:          RETURN
329:       ELSE IF( LQUERY ) THEN
330:          RETURN
331:       END IF
332: *
333: *     Quick return if possible
334: *
335:       IF( N.EQ.0 )
336:      $   RETURN
337: *
338: *     Get machine constants
339: *
340:       EPS = SLAMCH( 'P' )
341:       SMLNUM = SLAMCH( 'S' )
342:       BIGNUM = ONE / SMLNUM
343:       CALL SLABAD( SMLNUM, BIGNUM )
344:       SMLNUM = SQRT( SMLNUM ) / EPS
345:       BIGNUM = ONE / SMLNUM
346: *
347: *     Scale A if max element outside range [SMLNUM,BIGNUM]
348: *
349:       ICOND = 0
350:       ANRM = SLANGE( 'M', N, N, A, LDA, DUM )
351:       SCALEA = .FALSE.
352:       IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
353:          SCALEA = .TRUE.
354:          CSCALE = SMLNUM
355:       ELSE IF( ANRM.GT.BIGNUM ) THEN
356:          SCALEA = .TRUE.
357:          CSCALE = BIGNUM
358:       END IF
359:       IF( SCALEA )
360:      $   CALL SLASCL( 'G', 0, 0, ANRM, CSCALE, N, N, A, LDA, IERR )
361: *
362: *     Balance the matrix and compute ABNRM
363: *
364:       CALL SGEBAL( BALANC, N, A, LDA, ILO, IHI, SCALE, IERR )
365:       ABNRM = SLANGE( '1', N, N, A, LDA, DUM )
366:       IF( SCALEA ) THEN
367:          DUM( 1 ) = ABNRM
368:          CALL SLASCL( 'G', 0, 0, CSCALE, ANRM, 1, 1, DUM, 1, IERR )
369:          ABNRM = DUM( 1 )
370:       END IF
371: *
372: *     Reduce to upper Hessenberg form
373: *     (Workspace: need 2*N, prefer N+N*NB)
374: *
375:       ITAU = 1
376:       IWRK = ITAU + N
377:       CALL SGEHRD( N, ILO, IHI, A, LDA, WORK( ITAU ), WORK( IWRK ),
378:      $             LWORK-IWRK+1, IERR )
379: *
380:       IF( WANTVL ) THEN
381: *
382: *        Want left eigenvectors
383: *        Copy Householder vectors to VL
384: *
385:          SIDE = 'L'
386:          CALL SLACPY( 'L', N, N, A, LDA, VL, LDVL )
387: *
388: *        Generate orthogonal matrix in VL
389: *        (Workspace: need 2*N-1, prefer N+(N-1)*NB)
390: *
391:          CALL SORGHR( N, ILO, IHI, VL, LDVL, WORK( ITAU ), WORK( IWRK ),
392:      $                LWORK-IWRK+1, IERR )
393: *
394: *        Perform QR iteration, accumulating Schur vectors in VL
395: *        (Workspace: need 1, prefer HSWORK (see comments) )
396: *
397:          IWRK = ITAU
398:          CALL SHSEQR( 'S', 'V', N, ILO, IHI, A, LDA, WR, WI, VL, LDVL,
399:      $                WORK( IWRK ), LWORK-IWRK+1, INFO )
400: *
401:          IF( WANTVR ) THEN
402: *
403: *           Want left and right eigenvectors
404: *           Copy Schur vectors to VR
405: *
406:             SIDE = 'B'
407:             CALL SLACPY( 'F', N, N, VL, LDVL, VR, LDVR )
408:          END IF
409: *
410:       ELSE IF( WANTVR ) THEN
411: *
412: *        Want right eigenvectors
413: *        Copy Householder vectors to VR
414: *
415:          SIDE = 'R'
416:          CALL SLACPY( 'L', N, N, A, LDA, VR, LDVR )
417: *
418: *        Generate orthogonal matrix in VR
419: *        (Workspace: need 2*N-1, prefer N+(N-1)*NB)
420: *
421:          CALL SORGHR( N, ILO, IHI, VR, LDVR, WORK( ITAU ), WORK( IWRK ),
422:      $                LWORK-IWRK+1, IERR )
423: *
424: *        Perform QR iteration, accumulating Schur vectors in VR
425: *        (Workspace: need 1, prefer HSWORK (see comments) )
426: *
427:          IWRK = ITAU
428:          CALL SHSEQR( 'S', 'V', N, ILO, IHI, A, LDA, WR, WI, VR, LDVR,
429:      $                WORK( IWRK ), LWORK-IWRK+1, INFO )
430: *
431:       ELSE
432: *
433: *        Compute eigenvalues only
434: *        If condition numbers desired, compute Schur form
435: *
436:          IF( WNTSNN ) THEN
437:             JOB = 'E'
438:          ELSE
439:             JOB = 'S'
440:          END IF
441: *
442: *        (Workspace: need 1, prefer HSWORK (see comments) )
443: *
444:          IWRK = ITAU
445:          CALL SHSEQR( JOB, 'N', N, ILO, IHI, A, LDA, WR, WI, VR, LDVR,
446:      $                WORK( IWRK ), LWORK-IWRK+1, INFO )
447:       END IF
448: *
449: *     If INFO > 0 from SHSEQR, then quit
450: *
451:       IF( INFO.GT.0 )
452:      $   GO TO 50
453: *
454:       IF( WANTVL .OR. WANTVR ) THEN
455: *
456: *        Compute left and/or right eigenvectors
457: *        (Workspace: need 3*N)
458: *
459:          CALL STREVC( SIDE, 'B', SELECT, N, A, LDA, VL, LDVL, VR, LDVR,
460:      $                N, NOUT, WORK( IWRK ), IERR )
461:       END IF
462: *
463: *     Compute condition numbers if desired
464: *     (Workspace: need N*N+6*N unless SENSE = 'E')
465: *
466:       IF( .NOT.WNTSNN ) THEN
467:          CALL STRSNA( SENSE, 'A', SELECT, N, A, LDA, VL, LDVL, VR, LDVR,
468:      $                RCONDE, RCONDV, N, NOUT, WORK( IWRK ), N, IWORK,
469:      $                ICOND )
470:       END IF
471: *
472:       IF( WANTVL ) THEN
473: *
474: *        Undo balancing of left eigenvectors
475: *
476:          CALL SGEBAK( BALANC, 'L', N, ILO, IHI, SCALE, N, VL, LDVL,
477:      $                IERR )
478: *
479: *        Normalize left eigenvectors and make largest component real
480: *
481:          DO 20 I = 1, N
482:             IF( WI( I ).EQ.ZERO ) THEN
483:                SCL = ONE / SNRM2( N, VL( 1, I ), 1 )
484:                CALL SSCAL( N, SCL, VL( 1, I ), 1 )
485:             ELSE IF( WI( I ).GT.ZERO ) THEN
486:                SCL = ONE / SLAPY2( SNRM2( N, VL( 1, I ), 1 ),
487:      $               SNRM2( N, VL( 1, I+1 ), 1 ) )
488:                CALL SSCAL( N, SCL, VL( 1, I ), 1 )
489:                CALL SSCAL( N, SCL, VL( 1, I+1 ), 1 )
490:                DO 10 K = 1, N
491:                   WORK( K ) = VL( K, I )**2 + VL( K, I+1 )**2
492:    10          CONTINUE
493:                K = ISAMAX( N, WORK, 1 )
494:                CALL SLARTG( VL( K, I ), VL( K, I+1 ), CS, SN, R )
495:                CALL SROT( N, VL( 1, I ), 1, VL( 1, I+1 ), 1, CS, SN )
496:                VL( K, I+1 ) = ZERO
497:             END IF
498:    20    CONTINUE
499:       END IF
500: *
501:       IF( WANTVR ) THEN
502: *
503: *        Undo balancing of right eigenvectors
504: *
505:          CALL SGEBAK( BALANC, 'R', N, ILO, IHI, SCALE, N, VR, LDVR,
506:      $                IERR )
507: *
508: *        Normalize right eigenvectors and make largest component real
509: *
510:          DO 40 I = 1, N
511:             IF( WI( I ).EQ.ZERO ) THEN
512:                SCL = ONE / SNRM2( N, VR( 1, I ), 1 )
513:                CALL SSCAL( N, SCL, VR( 1, I ), 1 )
514:             ELSE IF( WI( I ).GT.ZERO ) THEN
515:                SCL = ONE / SLAPY2( SNRM2( N, VR( 1, I ), 1 ),
516:      $               SNRM2( N, VR( 1, I+1 ), 1 ) )
517:                CALL SSCAL( N, SCL, VR( 1, I ), 1 )
518:                CALL SSCAL( N, SCL, VR( 1, I+1 ), 1 )
519:                DO 30 K = 1, N
520:                   WORK( K ) = VR( K, I )**2 + VR( K, I+1 )**2
521:    30          CONTINUE
522:                K = ISAMAX( N, WORK, 1 )
523:                CALL SLARTG( VR( K, I ), VR( K, I+1 ), CS, SN, R )
524:                CALL SROT( N, VR( 1, I ), 1, VR( 1, I+1 ), 1, CS, SN )
525:                VR( K, I+1 ) = ZERO
526:             END IF
527:    40    CONTINUE
528:       END IF
529: *
530: *     Undo scaling if necessary
531: *
532:    50 CONTINUE
533:       IF( SCALEA ) THEN
534:          CALL SLASCL( 'G', 0, 0, CSCALE, ANRM, N-INFO, 1, WR( INFO+1 ),
535:      $                MAX( N-INFO, 1 ), IERR )
536:          CALL SLASCL( 'G', 0, 0, CSCALE, ANRM, N-INFO, 1, WI( INFO+1 ),
537:      $                MAX( N-INFO, 1 ), IERR )
538:          IF( INFO.EQ.0 ) THEN
539:             IF( ( WNTSNV .OR. WNTSNB ) .AND. ICOND.EQ.0 )
540:      $         CALL SLASCL( 'G', 0, 0, CSCALE, ANRM, N, 1, RCONDV, N,
541:      $                      IERR )
542:          ELSE
543:             CALL SLASCL( 'G', 0, 0, CSCALE, ANRM, ILO-1, 1, WR, N,
544:      $                   IERR )
545:             CALL SLASCL( 'G', 0, 0, CSCALE, ANRM, ILO-1, 1, WI, N,
546:      $                   IERR )
547:          END IF
548:       END IF
549: *
550:       WORK( 1 ) = MAXWRK
551:       RETURN
552: *
553: *     End of SGEEVX
554: *
555:       END
556: