283 SUBROUTINE zgeevx( BALANC, JOBVL, JOBVR, SENSE, N, A, LDA, W,
285 $ LDVL, VR, LDVR, ILO, IHI, SCALE, ABNRM, RCONDE,
286 $ RCONDV, WORK, LWORK, RWORK, INFO )
294 CHARACTER BALANC, JOBVL, JOBVR, SENSE
295 INTEGER IHI, ILO, INFO, LDA, LDVL, LDVR, LWORK, N
296 DOUBLE PRECISION ABNRM
299 DOUBLE PRECISION RCONDE( * ), RCONDV( * ), RWORK( * ),
301 COMPLEX*16 A( LDA, * ), VL( LDVL, * ), VR( LDVR, * ),
308 DOUBLE PRECISION ZERO, ONE
309 PARAMETER ( ZERO = 0.0d0, one = 1.0d0 )
312 LOGICAL LQUERY, SCALEA, WANTVL, WANTVR, WNTSNB, WNTSNE,
315 INTEGER HSWORK, I, ICOND, IERR, ITAU, IWRK, K,
316 $ LWORK_TREVC, MAXWRK, MINWRK, NOUT
317 DOUBLE PRECISION ANRM, BIGNUM, CSCALE, EPS, SCL, SMLNUM
322 DOUBLE PRECISION DUM( 1 )
332 INTEGER IDAMAX, ILAENV
333 DOUBLE PRECISION DLAMCH, DZNRM2, ZLANGE
334 EXTERNAL lsame, idamax, ilaenv, dlamch, dznrm2,
338 INTRINSIC dble, dcmplx, conjg, aimag, max, sqrt
345 lquery = ( lwork.EQ.-1 )
346 wantvl = lsame( jobvl,
'V' )
347 wantvr = lsame( jobvr,
'V' )
348 wntsnn = lsame( sense,
'N' )
349 wntsne = lsame( sense,
'E' )
350 wntsnv = lsame( sense,
'V' )
351 wntsnb = lsame( sense,
'B' )
352 IF( .NOT.( lsame( balanc,
'N' ) .OR.
353 $ lsame( balanc,
'S' ) .OR.
354 $ lsame( balanc,
'P' ) .OR. lsame( balanc,
'B' ) ) )
THEN
356 ELSE IF( ( .NOT.wantvl ) .AND.
357 $ ( .NOT.lsame( jobvl,
'N' ) ) )
THEN
359 ELSE IF( ( .NOT.wantvr ) .AND.
360 $ ( .NOT.lsame( jobvr,
'N' ) ) )
THEN
362 ELSE IF( .NOT.( wntsnn .OR. wntsne .OR. wntsnb .OR. wntsnv ) .OR.
363 $ ( ( wntsne .OR. wntsnb ) .AND. .NOT.( wantvl .AND.
366 ELSE IF( n.LT.0 )
THEN
368 ELSE IF( lda.LT.max( 1, n ) )
THEN
370 ELSE IF( ldvl.LT.1 .OR. ( wantvl .AND. ldvl.LT.n ) )
THEN
372 ELSE IF( ldvr.LT.1 .OR. ( wantvr .AND. ldvr.LT.n ) )
THEN
392 maxwrk = n + n*ilaenv( 1,
'ZGEHRD',
' ', n, 1, n, 0 )
395 CALL ztrevc3(
'L',
'B',
SELECT, n, a, lda,
396 $ vl, ldvl, vr, ldvr,
397 $ n, nout, work, -1, rwork, -1, ierr )
398 lwork_trevc = int( work(1) )
399 maxwrk = max( maxwrk, lwork_trevc )
400 CALL zhseqr(
'S',
'V', n, 1, n, a, lda, w, vl, ldvl,
402 ELSE IF( wantvr )
THEN
403 CALL ztrevc3(
'R',
'B',
SELECT, n, a, lda,
404 $ vl, ldvl, vr, ldvr,
405 $ n, nout, work, -1, rwork, -1, ierr )
406 lwork_trevc = int( work(1) )
407 maxwrk = max( maxwrk, lwork_trevc )
408 CALL zhseqr(
'S',
'V', n, 1, n, a, lda, w, vr, ldvr,
412 CALL zhseqr(
'E',
'N', n, 1, n, a, lda, w, vr,
416 CALL zhseqr(
'S',
'N', n, 1, n, a, lda, w, vr,
421 hswork = int( work(1) )
423 IF( ( .NOT.wantvl ) .AND. ( .NOT.wantvr ) )
THEN
425 IF( .NOT.( wntsnn .OR. wntsne ) )
426 $ minwrk = max( minwrk, n*n + 2*n )
427 maxwrk = max( maxwrk, hswork )
428 IF( .NOT.( wntsnn .OR. wntsne ) )
429 $ maxwrk = max( maxwrk, n*n + 2*n )
432 IF( .NOT.( wntsnn .OR. wntsne ) )
433 $ minwrk = max( minwrk, n*n + 2*n )
434 maxwrk = max( maxwrk, hswork )
435 maxwrk = max( maxwrk, n + ( n - 1 )*ilaenv( 1,
437 $
' ', n, 1, n, -1 ) )
438 IF( .NOT.( wntsnn .OR. wntsne ) )
439 $ maxwrk = max( maxwrk, n*n + 2*n )
440 maxwrk = max( maxwrk, 2*n )
442 maxwrk = max( maxwrk, minwrk )
446 IF( lwork.LT.minwrk .AND. .NOT.lquery )
THEN
452 CALL xerbla(
'ZGEEVX', -info )
454 ELSE IF( lquery )
THEN
466 smlnum = dlamch(
'S' )
467 bignum = one / smlnum
468 smlnum = sqrt( smlnum ) / eps
469 bignum = one / smlnum
474 anrm = zlange(
'M', n, n, a, lda, dum )
476 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
479 ELSE IF( anrm.GT.bignum )
THEN
484 $
CALL zlascl(
'G', 0, 0, anrm, cscale, n, n, a, lda, ierr )
488 CALL zgebal( balanc, n, a, lda, ilo, ihi, scale, ierr )
489 abnrm = zlange(
'1', n, n, a, lda, dum )
492 CALL dlascl(
'G', 0, 0, cscale, anrm, 1, 1, dum, 1, ierr )
502 CALL zgehrd( n, ilo, ihi, a, lda, work( itau ), work( iwrk ),
503 $ lwork-iwrk+1, ierr )
511 CALL zlacpy(
'L', n, n, a, lda, vl, ldvl )
517 CALL zunghr( n, ilo, ihi, vl, ldvl, work( itau ),
519 $ lwork-iwrk+1, ierr )
526 CALL zhseqr(
'S',
'V', n, ilo, ihi, a, lda, w, vl, ldvl,
527 $ work( iwrk ), lwork-iwrk+1, info )
535 CALL zlacpy(
'F', n, n, vl, ldvl, vr, ldvr )
538 ELSE IF( wantvr )
THEN
544 CALL zlacpy(
'L', n, n, a, lda, vr, ldvr )
550 CALL zunghr( n, ilo, ihi, vr, ldvr, work( itau ),
552 $ lwork-iwrk+1, ierr )
559 CALL zhseqr(
'S',
'V', n, ilo, ihi, a, lda, w, vr, ldvr,
560 $ work( iwrk ), lwork-iwrk+1, info )
577 CALL zhseqr( job,
'N', n, ilo, ihi, a, lda, w, vr, ldvr,
578 $ work( iwrk ), lwork-iwrk+1, info )
586 IF( wantvl .OR. wantvr )
THEN
592 CALL ztrevc3( side,
'B',
SELECT, n, a, lda, vl, ldvl, vr,
594 $ n, nout, work( iwrk ), lwork-iwrk+1,
602 IF( .NOT.wntsnn )
THEN
603 CALL ztrsna( sense,
'A',
SELECT, n, a, lda, vl, ldvl, vr,
605 $ rconde, rcondv, n, nout, work( iwrk ), n, rwork,
613 CALL zgebak( balanc,
'L', n, ilo, ihi, scale, n, vl, ldvl,
619 scl = one / dznrm2( n, vl( 1, i ), 1 )
620 CALL zdscal( n, scl, vl( 1, i ), 1 )
622 rwork( k ) = dble( vl( k, i ) )**2 +
623 $ aimag( vl( k, i ) )**2
625 k = idamax( n, rwork, 1 )
626 tmp = conjg( vl( k, i ) ) / sqrt( rwork( k ) )
627 CALL zscal( n, tmp, vl( 1, i ), 1 )
628 vl( k, i ) = dcmplx( dble( vl( k, i ) ), zero )
636 CALL zgebak( balanc,
'R', n, ilo, ihi, scale, n, vr, ldvr,
642 scl = one / dznrm2( n, vr( 1, i ), 1 )
643 CALL zdscal( n, scl, vr( 1, i ), 1 )
645 rwork( k ) = dble( vr( k, i ) )**2 +
646 $ aimag( vr( k, i ) )**2
648 k = idamax( n, rwork, 1 )
649 tmp = conjg( vr( k, i ) ) / sqrt( rwork( k ) )
650 CALL zscal( n, tmp, vr( 1, i ), 1 )
651 vr( k, i ) = dcmplx( dble( vr( k, i ) ), zero )
659 CALL zlascl(
'G', 0, 0, cscale, anrm, n-info, 1,
661 $ max( n-info, 1 ), ierr )
663 IF( ( wntsnv .OR. wntsnb ) .AND. icond.EQ.0 )
664 $
CALL dlascl(
'G', 0, 0, cscale, anrm, n, 1, rcondv, n,
667 CALL zlascl(
'G', 0, 0, cscale, anrm, ilo-1, 1, w, n,