324 SUBROUTINE zggesx( JOBVSL, JOBVSR, SORT, SELCTG, SENSE, N, A,
326 $ B, LDB, SDIM, ALPHA, BETA, VSL, LDVSL, VSR,
327 $ LDVSR, RCONDE, RCONDV, WORK, LWORK, RWORK,
328 $ IWORK, LIWORK, BWORK, INFO )
335 CHARACTER JOBVSL, JOBVSR, SENSE, SORT
336 INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LIWORK, LWORK, N,
342 DOUBLE PRECISION RCONDE( 2 ), RCONDV( 2 ), RWORK( * )
343 COMPLEX*16 A( LDA, * ), ALPHA( * ), B( LDB, * ),
344 $ beta( * ), vsl( ldvsl, * ), vsr( ldvsr, * ),
355 DOUBLE PRECISION ZERO, ONE
356 PARAMETER ( ZERO = 0.0d+0, one = 1.0d+0 )
357 COMPLEX*16 CZERO, CONE
358 PARAMETER ( CZERO = ( 0.0d+0, 0.0d+0 ),
359 $ cone = ( 1.0d+0, 0.0d+0 ) )
362 LOGICAL CURSL, ILASCL, ILBSCL, ILVSL, ILVSR, LASTSL,
363 $ LQUERY, WANTSB, WANTSE, WANTSN, WANTST, WANTSV
364 INTEGER I, ICOLS, IERR, IHI, IJOB, IJOBVL, IJOBVR,
365 $ ILEFT, ILO, IRIGHT, IROWS, IRWRK, ITAU, IWRK,
366 $ liwmin, lwrk, maxwrk, minwrk
367 DOUBLE PRECISION ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS, PL,
371 DOUBLE PRECISION DIF( 2 )
374 EXTERNAL XERBLA, ZGEQRF, ZGGBAK, ZGGBAL, ZGGHRD,
381 DOUBLE PRECISION DLAMCH, ZLANGE
382 EXTERNAL LSAME, ILAENV, DLAMCH, ZLANGE
391 IF( lsame( jobvsl,
'N' ) )
THEN
394 ELSE IF( lsame( jobvsl,
'V' ) )
THEN
402 IF( lsame( jobvsr,
'N' ) )
THEN
405 ELSE IF( lsame( jobvsr,
'V' ) )
THEN
413 wantst = lsame( sort,
'S' )
414 wantsn = lsame( sense,
'N' )
415 wantse = lsame( sense,
'E' )
416 wantsv = lsame( sense,
'V' )
417 wantsb = lsame( sense,
'B' )
418 lquery = ( lwork.EQ.-1 .OR. liwork.EQ.-1 )
421 ELSE IF( wantse )
THEN
423 ELSE IF( wantsv )
THEN
425 ELSE IF( wantsb )
THEN
432 IF( ijobvl.LE.0 )
THEN
434 ELSE IF( ijobvr.LE.0 )
THEN
436 ELSE IF( ( .NOT.wantst ) .AND.
437 $ ( .NOT.lsame( sort,
'N' ) ) )
THEN
439 ELSE IF( .NOT.( wantsn .OR. wantse .OR. wantsv .OR. wantsb ) .OR.
440 $ ( .NOT.wantst .AND. .NOT.wantsn ) )
THEN
442 ELSE IF( n.LT.0 )
THEN
444 ELSE IF( lda.LT.max( 1, n ) )
THEN
446 ELSE IF( ldb.LT.max( 1, n ) )
THEN
448 ELSE IF( ldvsl.LT.1 .OR. ( ilvsl .AND. ldvsl.LT.n ) )
THEN
450 ELSE IF( ldvsr.LT.1 .OR. ( ilvsr .AND. ldvsr.LT.n ) )
THEN
464 maxwrk = n*(1 + ilaenv( 1,
'ZGEQRF',
' ', n, 1, n, 0 ) )
465 maxwrk = max( maxwrk, n*( 1 +
466 $ ilaenv( 1,
'ZUNMQR',
' ', n, 1, n, -1 ) ) )
468 maxwrk = max( maxwrk, n*( 1 +
469 $ ilaenv( 1,
'ZUNGQR',
' ', n, 1, n,
474 $ lwrk = max( lwrk, n*n/2 )
481 IF( wantsn .OR. n.EQ.0 )
THEN
488 IF( lwork.LT.minwrk .AND. .NOT.lquery )
THEN
490 ELSE IF( liwork.LT.liwmin .AND. .NOT.lquery)
THEN
496 CALL xerbla(
'ZGGESX', -info )
498 ELSE IF (lquery)
THEN
512 smlnum = dlamch(
'S' )
513 bignum = one / smlnum
514 smlnum = sqrt( smlnum ) / eps
515 bignum = one / smlnum
519 anrm = zlange(
'M', n, n, a, lda, rwork )
521 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
524 ELSE IF( anrm.GT.bignum )
THEN
529 $
CALL zlascl(
'G', 0, 0, anrm, anrmto, n, n, a, lda, ierr )
533 bnrm = zlange(
'M', n, n, b, ldb, rwork )
535 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
538 ELSE IF( bnrm.GT.bignum )
THEN
543 $
CALL zlascl(
'G', 0, 0, bnrm, bnrmto, n, n, b, ldb, ierr )
551 CALL zggbal(
'P', n, a, lda, b, ldb, ilo, ihi, rwork( ileft ),
552 $ rwork( iright ), rwork( irwrk ), ierr )
557 irows = ihi + 1 - ilo
561 CALL zgeqrf( irows, icols, b( ilo, ilo ), ldb, work( itau ),
562 $ work( iwrk ), lwork+1-iwrk, ierr )
567 CALL zunmqr(
'L',
'C', irows, icols, irows, b( ilo, ilo ), ldb,
568 $ work( itau ), a( ilo, ilo ), lda, work( iwrk ),
569 $ lwork+1-iwrk, ierr )
575 CALL zlaset(
'Full', n, n, czero, cone, vsl, ldvsl )
576 IF( irows.GT.1 )
THEN
577 CALL zlacpy(
'L', irows-1, irows-1, b( ilo+1, ilo ), ldb,
578 $ vsl( ilo+1, ilo ), ldvsl )
580 CALL zungqr( irows, irows, irows, vsl( ilo, ilo ), ldvsl,
581 $ work( itau ), work( iwrk ), lwork+1-iwrk, ierr )
587 $
CALL zlaset(
'Full', n, n, czero, cone, vsr, ldvsr )
592 CALL zgghrd( jobvsl, jobvsr, n, ilo, ihi, a, lda, b, ldb, vsl,
593 $ ldvsl, vsr, ldvsr, ierr )
602 CALL zhgeqz(
'S', jobvsl, jobvsr, n, ilo, ihi, a, lda, b, ldb,
603 $ alpha, beta, vsl, ldvsl, vsr, ldvsr, work( iwrk ),
604 $ lwork+1-iwrk, rwork( irwrk ), ierr )
606 IF( ierr.GT.0 .AND. ierr.LE.n )
THEN
608 ELSE IF( ierr.GT.n .AND. ierr.LE.2*n )
THEN
624 $
CALL zlascl(
'G', 0, 0, anrmto, anrm, n, 1, alpha, n,
627 $
CALL zlascl(
'G', 0, 0, bnrmto, bnrm, n, 1, beta, n,
633 bwork( i ) = selctg( alpha( i ), beta( i ) )
641 CALL ztgsen( ijob, ilvsl, ilvsr, bwork, n, a, lda, b, ldb,
642 $ alpha, beta, vsl, ldvsl, vsr, ldvsr, sdim, pl, pr,
643 $ dif, work( iwrk ), lwork-iwrk+1, iwork, liwork,
647 $ maxwrk = max( maxwrk, 2*sdim*( n-sdim ) )
648 IF( ierr.EQ.-21 )
THEN
654 IF( ijob.EQ.1 .OR. ijob.EQ.4 )
THEN
658 IF( ijob.EQ.2 .OR. ijob.EQ.4 )
THEN
659 rcondv( 1 ) = dif( 1 )
660 rcondv( 2 ) = dif( 2 )
672 $
CALL zggbak(
'P',
'L', n, ilo, ihi, rwork( ileft ),
673 $ rwork( iright ), n, vsl, ldvsl, ierr )
676 $
CALL zggbak(
'P',
'R', n, ilo, ihi, rwork( ileft ),
677 $ rwork( iright ), n, vsr, ldvsr, ierr )
682 CALL zlascl(
'U', 0, 0, anrmto, anrm, n, n, a, lda, ierr )
683 CALL zlascl(
'G', 0, 0, anrmto, anrm, n, 1, alpha, n, ierr )
687 CALL zlascl(
'U', 0, 0, bnrmto, bnrm, n, n, b, ldb, ierr )
688 CALL zlascl(
'G', 0, 0, bnrmto, bnrm, n, 1, beta, n, ierr )
698 cursl = selctg( alpha( i ), beta( i ) )
701 IF( cursl .AND. .NOT.lastsl )