430 SUBROUTINE ctgsen( IJOB, WANTQ, WANTZ, SELECT, N, A, LDA, B, LDB,
431 $ ALPHA, BETA, Q, LDQ, Z, LDZ, M, PL, PR, DIF,
432 $ WORK, LWORK, IWORK, LIWORK, INFO )
440 INTEGER IJOB, INFO, LDA, LDB, LDQ, LDZ, LIWORK, LWORK,
448 COMPLEX A( LDA, * ), ALPHA( * ), B( LDB, * ),
449 $ beta( * ), q( ldq, * ), work( * ), z( ldz, * )
456 PARAMETER ( IDIFJB = 3 )
458 parameter( zero = 0.0e+0, one = 1.0e+0 )
461 LOGICAL LQUERY, SWAP, WANTD, WANTD1, WANTD2, WANTP
462 INTEGER I, IERR, IJB, K, KASE, KS, LIWMIN, LWMIN, MN2,
464 REAL DSCALE, DSUM, RDSCAL, SAFMIN
472 EXTERNAL SROUNDUP_LWORK
476 EXTERNAL CLACN2, CLACPY, CLASSQ, CSCAL, CTGEXC, CTGSYL,
480 INTRINSIC abs, cmplx, conjg, max, sqrt
487 lquery = ( lwork.EQ.-1 .OR. liwork.EQ.-1 )
489 IF( ijob.LT.0 .OR. ijob.GT.5 )
THEN
491 ELSE IF( n.LT.0 )
THEN
493 ELSE IF( lda.LT.max( 1, n ) )
THEN
495 ELSE IF( ldb.LT.max( 1, n ) )
THEN
497 ELSE IF( ldq.LT.1 .OR. ( wantq .AND. ldq.LT.n ) )
THEN
499 ELSE IF( ldz.LT.1 .OR. ( wantz .AND. ldz.LT.n ) )
THEN
504 CALL xerbla(
'CTGSEN', -info )
510 wantp = ijob.EQ.1 .OR. ijob.GE.4
511 wantd1 = ijob.EQ.2 .OR. ijob.EQ.4
512 wantd2 = ijob.EQ.3 .OR. ijob.EQ.5
513 wantd = wantd1 .OR. wantd2
519 IF( .NOT.lquery .OR. ijob.NE.0 )
THEN
521 alpha( k ) = a( k, k )
522 beta( k ) = b( k, k )
533 IF( ijob.EQ.1 .OR. ijob.EQ.2 .OR. ijob.EQ.4 )
THEN
534 lwmin = max( 1, 2*m*(n-m) )
535 liwmin = max( 1, n+2 )
536 ELSE IF( ijob.EQ.3 .OR. ijob.EQ.5 )
THEN
537 lwmin = max( 1, 4*m*(n-m) )
538 liwmin = max( 1, 2*m*(n-m), n+2 )
544 work( 1 ) = sroundup_lwork(lwmin)
547 IF( lwork.LT.lwmin .AND. .NOT.lquery )
THEN
549 ELSE IF( liwork.LT.liwmin .AND. .NOT.lquery )
THEN
554 CALL xerbla(
'CTGSEN', -info )
556 ELSE IF( lquery )
THEN
562 IF( m.EQ.n .OR. m.EQ.0 )
THEN
571 CALL classq( n, a( 1, i ), 1, dscale, dsum )
572 CALL classq( n, b( 1, i ), 1, dscale, dsum )
574 dif( 1 ) = dscale*sqrt( dsum )
582 safmin = slamch(
'S' )
596 $
CALL ctgexc( wantq, wantz, n, a, lda, b, ldb, q, ldq, z,
625 CALL clacpy(
'Full', n1, n2, a( 1, i ), lda, work, n1 )
626 CALL clacpy(
'Full', n1, n2, b( 1, i ), ldb, work( n1*n2+1 ),
629 CALL ctgsyl(
'N', ijb, n1, n2, a, lda, a( i, i ), lda, work,
630 $ n1, b, ldb, b( i, i ), ldb, work( n1*n2+1 ), n1,
631 $ dscale, dif( 1 ), work( n1*n2*2+1 ),
632 $ lwork-2*n1*n2, iwork, ierr )
639 CALL classq( n1*n2, work, 1, rdscal, dsum )
640 pl = rdscal*sqrt( dsum )
641 IF( pl.EQ.zero )
THEN
644 pl = dscale / ( sqrt( dscale*dscale / pl+pl )*sqrt( pl ) )
648 CALL classq( n1*n2, work( n1*n2+1 ), 1, rdscal, dsum )
649 pr = rdscal*sqrt( dsum )
650 IF( pr.EQ.zero )
THEN
653 pr = dscale / ( sqrt( dscale*dscale / pr+pr )*sqrt( pr ) )
668 CALL ctgsyl(
'N', ijb, n1, n2, a, lda, a( i, i ), lda, work,
669 $ n1, b, ldb, b( i, i ), ldb, work( n1*n2+1 ),
670 $ n1, dscale, dif( 1 ), work( n1*n2*2+1 ),
671 $ lwork-2*n1*n2, iwork, ierr )
675 CALL ctgsyl(
'N', ijb, n2, n1, a( i, i ), lda, a, lda, work,
676 $ n2, b( i, i ), ldb, b, ldb, work( n1*n2+1 ),
677 $ n2, dscale, dif( 2 ), work( n1*n2*2+1 ),
678 $ lwork-2*n1*n2, iwork, ierr )
696 CALL clacn2( mn2, work( mn2+1 ), work, dif( 1 ), kase,
703 CALL ctgsyl(
'N', ijb, n1, n2, a, lda, a( i, i ), lda,
704 $ work, n1, b, ldb, b( i, i ), ldb,
705 $ work( n1*n2+1 ), n1, dscale, dif( 1 ),
706 $ work( n1*n2*2+1 ), lwork-2*n1*n2, iwork,
712 CALL ctgsyl(
'C', ijb, n1, n2, a, lda, a( i, i ), lda,
713 $ work, n1, b, ldb, b( i, i ), ldb,
714 $ work( n1*n2+1 ), n1, dscale, dif( 1 ),
715 $ work( n1*n2*2+1 ), lwork-2*n1*n2, iwork,
720 dif( 1 ) = dscale / dif( 1 )
725 CALL clacn2( mn2, work( mn2+1 ), work, dif( 2 ), kase,
732 CALL ctgsyl(
'N', ijb, n2, n1, a( i, i ), lda, a, lda,
733 $ work, n2, b( i, i ), ldb, b, ldb,
734 $ work( n1*n2+1 ), n2, dscale, dif( 2 ),
735 $ work( n1*n2*2+1 ), lwork-2*n1*n2, iwork,
741 CALL ctgsyl(
'C', ijb, n2, n1, a( i, i ), lda, a, lda,
742 $ work, n2, b, ldb, b( i, i ), ldb,
743 $ work( n1*n2+1 ), n2, dscale, dif( 2 ),
744 $ work( n1*n2*2+1 ), lwork-2*n1*n2, iwork,
749 dif( 2 ) = dscale / dif( 2 )
758 dscale = abs( b( k, k ) )
759 IF( dscale.GT.safmin )
THEN
760 temp1 = conjg( b( k, k ) / dscale )
761 temp2 = b( k, k ) / dscale
763 CALL cscal( n-k, temp1, b( k, k+1 ), ldb )
764 CALL cscal( n-k+1, temp1, a( k, k ), lda )
766 $
CALL cscal( n, temp2, q( 1, k ), 1 )
768 b( k, k ) = cmplx( zero, zero )
771 alpha( k ) = a( k, k )
772 beta( k ) = b( k, k )
778 work( 1 ) = sroundup_lwork(lwmin)
subroutine xerbla(srname, info)
subroutine ctgsen(ijob, wantq, wantz, select, n, a, lda, b, ldb, alpha, beta, q, ldq, z, ldz, m, pl, pr, dif, work, lwork, iwork, liwork, info)
CTGSEN