368 SUBROUTINE cggevx( BALANC, JOBVL, JOBVR, SENSE, N, A, LDA, B,
370 $ ALPHA, BETA, VL, LDVL, VR, LDVR, ILO, IHI,
371 $ LSCALE, RSCALE, ABNRM, BBNRM, RCONDE, RCONDV,
372 $ WORK, LWORK, RWORK, IWORK, BWORK, INFO )
379 CHARACTER BALANC, JOBVL, JOBVR, SENSE
380 INTEGER IHI, ILO, INFO, LDA, LDB, LDVL, LDVR, LWORK, N
386 REAL LSCALE( * ), RCONDE( * ), RCONDV( * ),
387 $ RSCALE( * ), RWORK( * )
388 COMPLEX A( LDA, * ), ALPHA( * ), B( LDB, * ),
389 $ beta( * ), vl( ldvl, * ), vr( ldvr, * ),
397 PARAMETER ( ZERO = 0.0e+0, one = 1.0e+0 )
399 PARAMETER ( CZERO = ( 0.0e+0, 0.0e+0 ),
400 $ cone = ( 1.0e+0, 0.0e+0 ) )
403 LOGICAL ILASCL, ILBSCL, ILV, ILVL, ILVR, LQUERY, NOSCL,
404 $ WANTSB, WANTSE, WANTSN, WANTSV
406 INTEGER I, ICOLS, IERR, IJOBVL, IJOBVR, IN, IROWS,
407 $ itau, iwrk, iwrk1, j, jc, jr, m, maxwrk, minwrk
408 REAL ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS,
424 REAL CLANGE, SLAMCH, SROUNDUP_LWORK
425 EXTERNAL LSAME, ILAENV, CLANGE, SLAMCH,
429 INTRINSIC abs, aimag, max, real, sqrt
435 abs1( x ) = abs( real( x ) ) + abs( aimag( x ) )
441 IF( lsame( jobvl,
'N' ) )
THEN
444 ELSE IF( lsame( jobvl,
'V' ) )
THEN
452 IF( lsame( jobvr,
'N' ) )
THEN
455 ELSE IF( lsame( jobvr,
'V' ) )
THEN
464 noscl = lsame( balanc,
'N' ) .OR. lsame( balanc,
'P' )
465 wantsn = lsame( sense,
'N' )
466 wantse = lsame( sense,
'E' )
467 wantsv = lsame( sense,
'V' )
468 wantsb = lsame( sense,
'B' )
473 lquery = ( lwork.EQ.-1 )
474 IF( .NOT.( noscl .OR. lsame( balanc,
'S' ) .OR.
475 $ lsame( balanc,
'B' ) ) )
THEN
477 ELSE IF( ijobvl.LE.0 )
THEN
479 ELSE IF( ijobvr.LE.0 )
THEN
481 ELSE IF( .NOT.( wantsn .OR. wantse .OR. wantsb .OR. wantsv ) )
484 ELSE IF( n.LT.0 )
THEN
486 ELSE IF( lda.LT.max( 1, n ) )
THEN
488 ELSE IF( ldb.LT.max( 1, n ) )
THEN
490 ELSE IF( ldvl.LT.1 .OR. ( ilvl .AND. ldvl.LT.n ) )
THEN
492 ELSE IF( ldvr.LT.1 .OR. ( ilvr .AND. ldvr.LT.n ) )
THEN
512 ELSE IF( wantsv .OR. wantsb )
THEN
513 minwrk = 2*n*( n + 1)
516 maxwrk = max( maxwrk,
517 $ n + n*ilaenv( 1,
'CGEQRF',
' ', n, 1, n,
519 maxwrk = max( maxwrk,
520 $ n + n*ilaenv( 1,
'CUNMQR',
' ', n, 1, n,
523 maxwrk = max( maxwrk, n +
524 $ n*ilaenv( 1,
'CUNGQR',
' ', n, 1, n,
528 work( 1 ) = sroundup_lwork(maxwrk)
530 IF( lwork.LT.minwrk .AND. .NOT.lquery )
THEN
536 CALL xerbla(
'CGGEVX', -info )
538 ELSE IF( lquery )
THEN
550 smlnum = slamch(
'S' )
551 bignum = one / smlnum
552 smlnum = sqrt( smlnum ) / eps
553 bignum = one / smlnum
557 anrm = clange(
'M', n, n, a, lda, rwork )
559 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
562 ELSE IF( anrm.GT.bignum )
THEN
567 $
CALL clascl(
'G', 0, 0, anrm, anrmto, n, n, a, lda, ierr )
571 bnrm = clange(
'M', n, n, b, ldb, rwork )
573 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
576 ELSE IF( bnrm.GT.bignum )
THEN
581 $
CALL clascl(
'G', 0, 0, bnrm, bnrmto, n, n, b, ldb, ierr )
586 CALL cggbal( balanc, n, a, lda, b, ldb, ilo, ihi, lscale,
592 abnrm = clange(
'1', n, n, a, lda, rwork( 1 ) )
595 CALL slascl(
'G', 0, 0, anrmto, anrm, 1, 1, rwork( 1 ), 1,
600 bbnrm = clange(
'1', n, n, b, ldb, rwork( 1 ) )
603 CALL slascl(
'G', 0, 0, bnrmto, bnrm, 1, 1, rwork( 1 ), 1,
611 irows = ihi + 1 - ilo
612 IF( ilv .OR. .NOT.wantsn )
THEN
619 CALL cgeqrf( irows, icols, b( ilo, ilo ), ldb, work( itau ),
620 $ work( iwrk ), lwork+1-iwrk, ierr )
625 CALL cunmqr(
'L',
'C', irows, icols, irows, b( ilo, ilo ), ldb,
626 $ work( itau ), a( ilo, ilo ), lda, work( iwrk ),
627 $ lwork+1-iwrk, ierr )
633 CALL claset(
'Full', n, n, czero, cone, vl, ldvl )
634 IF( irows.GT.1 )
THEN
635 CALL clacpy(
'L', irows-1, irows-1, b( ilo+1, ilo ), ldb,
636 $ vl( ilo+1, ilo ), ldvl )
638 CALL cungqr( irows, irows, irows, vl( ilo, ilo ), ldvl,
639 $ work( itau ), work( iwrk ), lwork+1-iwrk, ierr )
643 $
CALL claset(
'Full', n, n, czero, cone, vr, ldvr )
648 IF( ilv .OR. .NOT.wantsn )
THEN
652 CALL cgghrd( jobvl, jobvr, n, ilo, ihi, a, lda, b, ldb, vl,
653 $ ldvl, vr, ldvr, ierr )
655 CALL cgghrd(
'N',
'N', irows, 1, irows, a( ilo, ilo ), lda,
656 $ b( ilo, ilo ), ldb, vl, ldvl, vr, ldvr, ierr )
665 IF( ilv .OR. .NOT.wantsn )
THEN
671 CALL chgeqz( chtemp, jobvl, jobvr, n, ilo, ihi, a, lda, b, ldb,
672 $ alpha, beta, vl, ldvl, vr, ldvr, work( iwrk ),
673 $ lwork+1-iwrk, rwork, ierr )
675 IF( ierr.GT.0 .AND. ierr.LE.n )
THEN
677 ELSE IF( ierr.GT.n .AND. ierr.LE.2*n )
THEN
691 IF( ilv .OR. .NOT.wantsn )
THEN
703 CALL ctgevc( chtemp,
'B', ldumma, n, a, lda, b, ldb, vl,
704 $ ldvl, vr, ldvr, n, in, work( iwrk ), rwork,
712 IF( .NOT.wantsn )
THEN
733 IF( wantse .OR. wantsb )
THEN
734 CALL ctgevc(
'B',
'S', bwork, n, a, lda, b, ldb,
735 $ work( 1 ), n, work( iwrk ), n, 1, m,
736 $ work( iwrk1 ), rwork, ierr )
743 CALL ctgsna( sense,
'S', bwork, n, a, lda, b, ldb,
744 $ work( 1 ), n, work( iwrk ), n, rconde( i ),
745 $ rcondv( i ), 1, m, work( iwrk1 ),
746 $ lwork-iwrk1+1, iwork, ierr )
756 CALL cggbak( balanc,
'L', n, ilo, ihi, lscale, rscale, n,
763 temp = max( temp, abs1( vl( jr, jc ) ) )
769 vl( jr, jc ) = vl( jr, jc )*temp
775 CALL cggbak( balanc,
'R', n, ilo, ihi, lscale, rscale, n,
781 temp = max( temp, abs1( vr( jr, jc ) ) )
787 vr( jr, jc ) = vr( jr, jc )*temp
797 $
CALL clascl(
'G', 0, 0, anrmto, anrm, n, 1, alpha, n, ierr )
800 $
CALL clascl(
'G', 0, 0, bnrmto, bnrm, n, 1, beta, n, ierr )
802 work( 1 ) = sroundup_lwork(maxwrk)