428 SUBROUTINE ztgsen( IJOB, WANTQ, WANTZ, SELECT, N, A, LDA, B,
430 $ ALPHA, BETA, Q, LDQ, Z, LDZ, M, PL, PR, DIF,
431 $ WORK, LWORK, IWORK, LIWORK, INFO )
439 INTEGER IJOB, INFO, LDA, LDB, LDQ, LDZ, LIWORK, LWORK,
441 DOUBLE PRECISION PL, PR
446 DOUBLE PRECISION DIF( * )
447 COMPLEX*16 A( LDA, * ), ALPHA( * ), B( LDB, * ),
448 $ beta( * ), q( ldq, * ), work( * ), z( ldz, * )
455 PARAMETER ( IDIFJB = 3 )
456 double precision zero, one
457 parameter( zero = 0.0d+0, one = 1.0d+0 )
460 LOGICAL LQUERY, SWAP, WANTD, WANTD1, WANTD2, WANTP
461 INTEGER I, IERR, IJB, K, KASE, KS, LIWMIN, LWMIN, MN2,
463 DOUBLE PRECISION DSCALE, DSUM, RDSCAL, SAFMIN
464 COMPLEX*16 TEMP1, TEMP2
475 INTRINSIC abs, dcmplx, dconjg, max, sqrt
478 DOUBLE PRECISION DLAMCH
486 lquery = ( lwork.EQ.-1 .OR. liwork.EQ.-1 )
488 IF( ijob.LT.0 .OR. ijob.GT.5 )
THEN
490 ELSE IF( n.LT.0 )
THEN
492 ELSE IF( lda.LT.max( 1, n ) )
THEN
494 ELSE IF( ldb.LT.max( 1, n ) )
THEN
496 ELSE IF( ldq.LT.1 .OR. ( wantq .AND. ldq.LT.n ) )
THEN
498 ELSE IF( ldz.LT.1 .OR. ( wantz .AND. ldz.LT.n ) )
THEN
503 CALL xerbla(
'ZTGSEN', -info )
509 wantp = ijob.EQ.1 .OR. ijob.GE.4
510 wantd1 = ijob.EQ.2 .OR. ijob.EQ.4
511 wantd2 = ijob.EQ.3 .OR. ijob.EQ.5
512 wantd = wantd1 .OR. wantd2
518 IF( .NOT.lquery .OR. ijob.NE.0 )
THEN
520 alpha( k ) = a( k, k )
521 beta( k ) = b( k, k )
532 IF( ijob.EQ.1 .OR. ijob.EQ.2 .OR. ijob.EQ.4 )
THEN
533 lwmin = max( 1, 2*m*( n-m ) )
534 liwmin = max( 1, n+2 )
535 ELSE IF( ijob.EQ.3 .OR. ijob.EQ.5 )
THEN
536 lwmin = max( 1, 4*m*( n-m ) )
537 liwmin = max( 1, 2*m*( n-m ), n+2 )
546 IF( lwork.LT.lwmin .AND. .NOT.lquery )
THEN
548 ELSE IF( liwork.LT.liwmin .AND. .NOT.lquery )
THEN
553 CALL xerbla(
'ZTGSEN', -info )
555 ELSE IF( lquery )
THEN
561 IF( m.EQ.n .OR. m.EQ.0 )
THEN
570 CALL zlassq( n, a( 1, i ), 1, dscale, dsum )
571 CALL zlassq( n, b( 1, i ), 1, dscale, dsum )
573 dif( 1 ) = dscale*sqrt( dsum )
581 safmin = dlamch(
'S' )
595 $
CALL ztgexc( wantq, wantz, n, a, lda, b, ldb, q, ldq,
625 CALL zlacpy(
'Full', n1, n2, a( 1, i ), lda, work, n1 )
626 CALL zlacpy(
'Full', n1, n2, b( 1, i ), ldb,
630 CALL ztgsyl(
'N', ijb, n1, n2, a, lda, a( i, i ), lda, work,
631 $ n1, b, ldb, b( i, i ), ldb, work( n1*n2+1 ), n1,
632 $ dscale, dif( 1 ), work( n1*n2*2+1 ),
633 $ lwork-2*n1*n2, iwork, ierr )
640 CALL zlassq( n1*n2, work, 1, rdscal, dsum )
641 pl = rdscal*sqrt( dsum )
642 IF( pl.EQ.zero )
THEN
645 pl = dscale / ( sqrt( dscale*dscale / pl+pl )*sqrt( pl ) )
649 CALL zlassq( n1*n2, work( n1*n2+1 ), 1, rdscal, dsum )
650 pr = rdscal*sqrt( dsum )
651 IF( pr.EQ.zero )
THEN
654 pr = dscale / ( sqrt( dscale*dscale / pr+pr )*sqrt( pr ) )
669 CALL ztgsyl(
'N', ijb, n1, n2, a, lda, a( i, i ), lda,
671 $ n1, b, ldb, b( i, i ), ldb, work( n1*n2+1 ),
672 $ n1, dscale, dif( 1 ), work( n1*n2*2+1 ),
673 $ lwork-2*n1*n2, iwork, ierr )
677 CALL ztgsyl(
'N', ijb, n2, n1, a( i, i ), lda, a, lda,
679 $ n2, b( i, i ), ldb, b, ldb, work( n1*n2+1 ),
680 $ n2, dscale, dif( 2 ), work( n1*n2*2+1 ),
681 $ lwork-2*n1*n2, iwork, ierr )
699 CALL zlacn2( mn2, work( mn2+1 ), work, dif( 1 ), kase,
706 CALL ztgsyl(
'N', ijb, n1, n2, a, lda, a( i, i ),
708 $ work, n1, b, ldb, b( i, i ), ldb,
709 $ work( n1*n2+1 ), n1, dscale, dif( 1 ),
710 $ work( n1*n2*2+1 ), lwork-2*n1*n2, iwork,
716 CALL ztgsyl(
'C', ijb, n1, n2, a, lda, a( i, i ),
718 $ work, n1, b, ldb, b( i, i ), ldb,
719 $ work( n1*n2+1 ), n1, dscale, dif( 1 ),
720 $ work( n1*n2*2+1 ), lwork-2*n1*n2, iwork,
725 dif( 1 ) = dscale / dif( 1 )
730 CALL zlacn2( mn2, work( mn2+1 ), work, dif( 2 ), kase,
737 CALL ztgsyl(
'N', ijb, n2, n1, a( i, i ), lda, a,
739 $ work, n2, b( i, i ), ldb, b, ldb,
740 $ work( n1*n2+1 ), n2, dscale, dif( 2 ),
741 $ work( n1*n2*2+1 ), lwork-2*n1*n2, iwork,
747 CALL ztgsyl(
'C', ijb, n2, n1, a( i, i ), lda, a,
749 $ work, n2, b, ldb, b( i, i ), ldb,
750 $ work( n1*n2+1 ), n2, dscale, dif( 2 ),
751 $ work( n1*n2*2+1 ), lwork-2*n1*n2, iwork,
756 dif( 2 ) = dscale / dif( 2 )
765 dscale = abs( b( k, k ) )
766 IF( dscale.GT.safmin )
THEN
767 temp1 = dconjg( b( k, k ) / dscale )
768 temp2 = b( k, k ) / dscale
770 CALL zscal( n-k, temp1, b( k, k+1 ), ldb )
771 CALL zscal( n-k+1, temp1, a( k, k ), lda )
773 $
CALL zscal( n, temp2, q( 1, k ), 1 )
775 b( k, k ) = dcmplx( zero, zero )
778 alpha( k ) = a( k, k )
779 beta( k ) = b( k, k )