451 SUBROUTINE dtgsen( IJOB, WANTQ, WANTZ, SELECT, N, A, LDA, B, LDB,
452 $ alphar, alphai, beta, q, ldq, z, ldz, m, pl,
453 $ pr, dif, work, lwork, iwork, liwork, info )
462 INTEGER ijob, info, lda, ldb, ldq, ldz, liwork, lwork,
464 DOUBLE PRECISION pl, pr
469 DOUBLE PRECISION a( lda, * ), alphai( * ), alphar( * ),
470 $ b( ldb, * ), beta( * ), dif( * ), q( ldq, * ),
471 $ work( * ), z( ldz, * )
478 parameter( idifjb = 3 )
479 DOUBLE PRECISION zero, one
480 parameter( zero = 0.0d+0, one = 1.0d+0 )
483 LOGICAL lquery, pair, swap, wantd, wantd1, wantd2,
485 INTEGER i, ierr, ijb, k, kase, kk, ks, liwmin, lwmin,
487 DOUBLE PRECISION dscale, dsum, eps, rdscal, smlnum
501 INTRINSIC max, sign, sqrt
508 lquery = ( lwork.EQ.-1 .OR. liwork.EQ.-1 )
510 IF( ijob.LT.0 .OR. ijob.GT.5 )
THEN
512 ELSE IF( n.LT.0 )
THEN
514 ELSE IF( lda.LT.max( 1, n ) )
THEN
516 ELSE IF( ldb.LT.max( 1, n ) )
THEN
518 ELSE IF( ldq.LT.1 .OR. ( wantq .AND. ldq.LT.n ) )
THEN
520 ELSE IF( ldz.LT.1 .OR. ( wantz .AND. ldz.LT.n ) )
THEN
525 CALL
xerbla(
'DTGSEN', -info )
532 smlnum =
dlamch(
'S' ) / eps
535 wantp = ijob.EQ.1 .OR. ijob.GE.4
536 wantd1 = ijob.EQ.2 .OR. ijob.EQ.4
537 wantd2 = ijob.EQ.3 .OR. ijob.EQ.5
538 wantd = wantd1 .OR. wantd2
550 IF( a( k+1, k ).EQ.zero )
THEN
555 IF(
SELECT( k ) .OR.
SELECT( k+1 ) )
565 IF( ijob.EQ.1 .OR. ijob.EQ.2 .OR. ijob.EQ.4 )
THEN
566 lwmin = max( 1, 4*n+16, 2*m*( n-m ) )
567 liwmin = max( 1, n+6 )
568 ELSE IF( ijob.EQ.3 .OR. ijob.EQ.5 )
THEN
569 lwmin = max( 1, 4*n+16, 4*m*( n-m ) )
570 liwmin = max( 1, 2*m*( n-m ), n+6 )
572 lwmin = max( 1, 4*n+16 )
579 IF( lwork.LT.lwmin .AND. .NOT.lquery )
THEN
581 ELSE IF( liwork.LT.liwmin .AND. .NOT.lquery )
THEN
586 CALL
xerbla(
'DTGSEN', -info )
588 ELSE IF( lquery )
THEN
594 IF( m.EQ.n .OR. m.EQ.0 )
THEN
603 CALL
dlassq( n, a( 1, i ), 1, dscale, dsum )
604 CALL
dlassq( n, b( 1, i ), 1, dscale, dsum )
606 dif( 1 ) = dscale*sqrt( dsum )
623 IF( a( k+1, k ).NE.zero )
THEN
625 swap = swap .OR.
SELECT( k+1 )
639 $ CALL
dtgexc( wantq, wantz, n, a, lda, b, ldb, q, ldq,
640 $ z, ldz, kk, ks, work, lwork, ierr )
672 CALL
dlacpy(
'Full', n1, n2, a( 1, i ), lda, work, n1 )
673 CALL
dlacpy(
'Full', n1, n2, b( 1, i ), ldb, work( n1*n2+1 ),
675 CALL
dtgsyl(
'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
dlassq( 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
dlassq( 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
dtgsyl(
'N', ijb, n1, n2, a, lda, a( i, i ), lda, work,
716 $ n1, b, ldb, b( i, i ), ldb, work( n1*n2+1 ),
717 $ n1, dscale, dif( 1 ), work( 2*n1*n2+1 ),
718 $ lwork-2*n1*n2, iwork, ierr )
722 CALL
dtgsyl(
'N', ijb, n2, n1, a( i, i ), lda, a, lda, work,
723 $ n2, b( i, i ), ldb, b, ldb, work( n1*n2+1 ),
724 $ n2, dscale, dif( 2 ), work( 2*n1*n2+1 ),
725 $ lwork-2*n1*n2, iwork, ierr )
744 CALL
dlacn2( mn2, work( mn2+1 ), work, iwork, dif( 1 ),
751 CALL
dtgsyl(
'N', ijb, n1, n2, a, lda, a( i, i ), lda,
752 $ work, n1, b, ldb, b( i, i ), ldb,
753 $ work( n1*n2+1 ), n1, dscale, dif( 1 ),
754 $ work( 2*n1*n2+1 ), lwork-2*n1*n2, iwork,
760 CALL
dtgsyl(
'T', ijb, n1, n2, a, lda, a( i, i ), lda,
761 $ work, n1, b, ldb, b( i, i ), ldb,
762 $ work( n1*n2+1 ), n1, dscale, dif( 1 ),
763 $ work( 2*n1*n2+1 ), lwork-2*n1*n2, iwork,
768 dif( 1 ) = dscale / dif( 1 )
773 CALL
dlacn2( mn2, work( mn2+1 ), work, iwork, dif( 2 ),
780 CALL
dtgsyl(
'N', ijb, n2, n1, a( i, i ), lda, a, lda,
781 $ work, n2, b( i, i ), ldb, b, ldb,
782 $ work( n1*n2+1 ), n2, dscale, dif( 2 ),
783 $ work( 2*n1*n2+1 ), lwork-2*n1*n2, iwork,
789 CALL
dtgsyl(
'T', ijb, n2, n1, a( i, i ), lda, a, lda,
790 $ work, n2, b( i, i ), ldb, b, ldb,
791 $ work( n1*n2+1 ), n2, dscale, dif( 2 ),
792 $ work( 2*n1*n2+1 ), lwork-2*n1*n2, iwork,
797 dif( 2 ) = dscale / dif( 2 )
814 IF( a( k+1, k ).NE.zero )
THEN
823 work( 1 ) = a( k, k )
824 work( 2 ) = a( k+1, k )
825 work( 3 ) = a( k, k+1 )
826 work( 4 ) = a( k+1, k+1 )
827 work( 5 ) = b( k, k )
828 work( 6 ) = b( k+1, k )
829 work( 7 ) = b( k, k+1 )
830 work( 8 ) = b( k+1, k+1 )
831 CALL
dlag2( work, 2, work( 5 ), 2, smlnum*eps, beta( k ),
832 $ beta( k+1 ), alphar( k ), alphar( k+1 ),
834 alphai( k+1 ) = -alphai( k )
838 IF( sign( one, b( k, k ) ).LT.zero )
THEN
843 a( k, i ) = -a( k, i )
844 b( k, i ) = -b( k, i )
845 IF( wantq ) q( i, k ) = -q( i, k )
849 alphar( k ) = a( k, k )
851 beta( k ) = b( k, k )