446 SUBROUTINE stgsen( IJOB, WANTQ, WANTZ, SELECT, N, A, LDA, B,
448 $ ALPHAR, ALPHAI, BETA, Q, LDQ, Z, LDZ, M, PL,
449 $ PR, DIF, WORK, LWORK, IWORK, LIWORK, INFO )
457 INTEGER IJOB, INFO, LDA, LDB, LDQ, LDZ, LIWORK, LWORK,
464 REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ),
465 $ b( ldb, * ), beta( * ), dif( * ), q( ldq, * ),
466 $ work( * ), z( ldz, * )
473 PARAMETER ( IDIFJB = 3 )
475 parameter( zero = 0.0e+0, one = 1.0e+0 )
478 LOGICAL LQUERY, PAIR, SWAP, WANTD, WANTD1, WANTD2,
480 INTEGER I, IERR, IJB, K, KASE, KK, KS, LIWMIN, LWMIN,
482 REAL DSCALE, DSUM, EPS, RDSCAL, SMLNUM
493 REAL SLAMCH, SROUNDUP_LWORK
494 EXTERNAL SLAMCH, SROUNDUP_LWORK
497 INTRINSIC max, sign, sqrt
504 lquery = ( lwork.EQ.-1 .OR. liwork.EQ.-1 )
506 IF( ijob.LT.0 .OR. ijob.GT.5 )
THEN
508 ELSE IF( n.LT.0 )
THEN
510 ELSE IF( lda.LT.max( 1, n ) )
THEN
512 ELSE IF( ldb.LT.max( 1, n ) )
THEN
514 ELSE IF( ldq.LT.1 .OR. ( wantq .AND. ldq.LT.n ) )
THEN
516 ELSE IF( ldz.LT.1 .OR. ( wantz .AND. ldz.LT.n ) )
THEN
521 CALL xerbla(
'STGSEN', -info )
528 smlnum = slamch(
'S' ) / eps
531 wantp = ijob.EQ.1 .OR. ijob.GE.4
532 wantd1 = ijob.EQ.2 .OR. ijob.EQ.4
533 wantd2 = ijob.EQ.3 .OR. ijob.EQ.5
534 wantd = wantd1 .OR. wantd2
541 IF( .NOT.lquery .OR. ijob.NE.0 )
THEN
547 IF( a( k+1, k ).EQ.zero )
THEN
552 IF(
SELECT( k ) .OR.
SELECT( k+1 ) )
563 IF( ijob.EQ.1 .OR. ijob.EQ.2 .OR. ijob.EQ.4 )
THEN
564 lwmin = max( 1, 4*n+16, 2*m*(n-m) )
565 liwmin = max( 1, n+6 )
566 ELSE IF( ijob.EQ.3 .OR. ijob.EQ.5 )
THEN
567 lwmin = max( 1, 4*n+16, 4*m*(n-m) )
568 liwmin = max( 1, 2*m*(n-m), n+6 )
570 lwmin = max( 1, 4*n+16 )
574 work( 1 ) = sroundup_lwork(lwmin)
577 IF( lwork.LT.lwmin .AND. .NOT.lquery )
THEN
579 ELSE IF( liwork.LT.liwmin .AND. .NOT.lquery )
THEN
584 CALL xerbla(
'STGSEN', -info )
586 ELSE IF( lquery )
THEN
592 IF( m.EQ.n .OR. m.EQ.0 )
THEN
601 CALL slassq( n, a( 1, i ), 1, dscale, dsum )
602 CALL slassq( n, b( 1, i ), 1, dscale, dsum )
604 dif( 1 ) = dscale*sqrt( dsum )
621 IF( a( k+1, k ).NE.zero )
THEN
623 swap = swap .OR.
SELECT( k+1 )
637 $
CALL stgexc( wantq, wantz, n, a, lda, b, ldb, q,
639 $ z, ldz, kk, ks, work, lwork, ierr )
671 CALL slacpy(
'Full', n1, n2, a( 1, i ), lda, work, n1 )
672 CALL slacpy(
'Full', n1, n2, b( 1, i ), ldb,
675 CALL stgsyl(
'N', ijb, n1, n2, a, lda, a( i, i ), lda, work,
676 $ n1, b, ldb, b( i, i ), ldb, work( n1*n2+1 ), n1,
677 $ dscale, dif( 1 ), work( n1*n2*2+1 ),
678 $ lwork-2*n1*n2, iwork, ierr )
685 CALL slassq( n1*n2, work, 1, rdscal, dsum )
686 pl = rdscal*sqrt( dsum )
687 IF( pl.EQ.zero )
THEN
690 pl = dscale / ( sqrt( dscale*dscale / pl+pl )*sqrt( pl ) )
694 CALL slassq( n1*n2, work( n1*n2+1 ), 1, rdscal, dsum )
695 pr = rdscal*sqrt( dsum )
696 IF( pr.EQ.zero )
THEN
699 pr = dscale / ( sqrt( dscale*dscale / pr+pr )*sqrt( pr ) )
715 CALL stgsyl(
'N', ijb, n1, n2, a, lda, a( i, i ), lda,
717 $ n1, b, ldb, b( i, i ), ldb, work( n1*n2+1 ),
718 $ n1, dscale, dif( 1 ), work( 2*n1*n2+1 ),
719 $ lwork-2*n1*n2, iwork, ierr )
723 CALL stgsyl(
'N', ijb, n2, n1, a( i, i ), lda, a, lda,
725 $ n2, b( i, i ), ldb, b, ldb, work( n1*n2+1 ),
726 $ n2, dscale, dif( 2 ), work( 2*n1*n2+1 ),
727 $ lwork-2*n1*n2, iwork, ierr )
746 CALL slacn2( mn2, work( mn2+1 ), work, iwork, dif( 1 ),
753 CALL stgsyl(
'N', ijb, n1, n2, a, lda, a( i, i ),
755 $ work, n1, b, ldb, b( i, i ), ldb,
756 $ work( n1*n2+1 ), n1, dscale, dif( 1 ),
757 $ work( 2*n1*n2+1 ), lwork-2*n1*n2, iwork,
763 CALL stgsyl(
'T', ijb, n1, n2, a, lda, a( i, i ),
765 $ work, n1, b, ldb, b( i, i ), ldb,
766 $ work( n1*n2+1 ), n1, dscale, dif( 1 ),
767 $ work( 2*n1*n2+1 ), lwork-2*n1*n2, iwork,
772 dif( 1 ) = dscale / dif( 1 )
777 CALL slacn2( mn2, work( mn2+1 ), work, iwork, dif( 2 ),
784 CALL stgsyl(
'N', ijb, n2, n1, a( i, i ), lda, a,
786 $ work, n2, b( i, i ), ldb, b, ldb,
787 $ work( n1*n2+1 ), n2, dscale, dif( 2 ),
788 $ work( 2*n1*n2+1 ), lwork-2*n1*n2, iwork,
794 CALL stgsyl(
'T', ijb, n2, n1, a( i, i ), lda, a,
796 $ work, n2, b( i, i ), ldb, b, ldb,
797 $ work( n1*n2+1 ), n2, dscale, dif( 2 ),
798 $ work( 2*n1*n2+1 ), lwork-2*n1*n2, iwork,
803 dif( 2 ) = dscale / dif( 2 )
820 IF( a( k+1, k ).NE.zero )
THEN
829 work( 1 ) = a( k, k )
830 work( 2 ) = a( k+1, k )
831 work( 3 ) = a( k, k+1 )
832 work( 4 ) = a( k+1, k+1 )
833 work( 5 ) = b( k, k )
834 work( 6 ) = b( k+1, k )
835 work( 7 ) = b( k, k+1 )
836 work( 8 ) = b( k+1, k+1 )
837 CALL slag2( work, 2, work( 5 ), 2, smlnum*eps,
839 $ beta( k+1 ), alphar( k ), alphar( k+1 ),
841 alphai( k+1 ) = -alphai( k )
845 IF( sign( one, b( k, k ) ).LT.zero )
THEN
850 a( k, i ) = -a( k, i )
851 b( k, i ) = -b( k, i )
852 IF( wantq ) q( i, k ) = -q( i, k )
856 alphar( k ) = a( k, k )
858 beta( k ) = b( k, k )
864 work( 1 ) = sroundup_lwork(lwmin)