376 SUBROUTINE ctgsja( JOBU, JOBV, JOBQ, M, P, N, K, L, A, LDA, B,
377 $ LDB, TOLA, TOLB, ALPHA, BETA, U, LDU, V, LDV,
378 $ Q, LDQ, WORK, NCYCLE, INFO )
385 CHARACTER JOBQ, JOBU, JOBV
386 INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N,
391 REAL ALPHA( * ), BETA( * )
392 COMPLEX A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
393 $ u( ldu, * ), v( ldv, * ), work( * )
400 PARAMETER ( MAXIT = 40 )
401 REAL ZERO, ONE, HUGENUM
402 parameter( zero = 0.0e+0, one = 1.0e+0 )
404 parameter( czero = ( 0.0e+0, 0.0e+0 ),
405 $ cone = ( 1.0e+0, 0.0e+0 ) )
409 LOGICAL INITQ, INITU, INITV, UPPER, WANTQ, WANTU, WANTV
411 REAL A1, A3, B1, B3, CSQ, CSU, CSV, ERROR, GAMMA,
413 COMPLEX A2, B2, SNQ, SNU, SNV
424 INTRINSIC abs, conjg, max, min, real, huge
425 parameter( hugenum = huge(zero) )
431 initu = lsame( jobu,
'I' )
432 wantu = initu .OR. lsame( jobu,
'U' )
434 initv = lsame( jobv,
'I' )
435 wantv = initv .OR. lsame( jobv,
'V' )
437 initq = lsame( jobq,
'I' )
438 wantq = initq .OR. lsame( jobq,
'Q' )
441 IF( .NOT.( initu .OR. wantu .OR. lsame( jobu,
'N' ) ) )
THEN
443 ELSE IF( .NOT.( initv .OR. wantv .OR. lsame( jobv,
'N' ) ) )
THEN
445 ELSE IF( .NOT.( initq .OR. wantq .OR. lsame( jobq,
'N' ) ) )
THEN
447 ELSE IF( m.LT.0 )
THEN
449 ELSE IF( p.LT.0 )
THEN
451 ELSE IF( n.LT.0 )
THEN
453 ELSE IF( lda.LT.max( 1, m ) )
THEN
455 ELSE IF( ldb.LT.max( 1, p ) )
THEN
457 ELSE IF( ldu.LT.1 .OR. ( wantu .AND. ldu.LT.m ) )
THEN
459 ELSE IF( ldv.LT.1 .OR. ( wantv .AND. ldv.LT.p ) )
THEN
461 ELSE IF( ldq.LT.1 .OR. ( wantq .AND. ldq.LT.n ) )
THEN
465 CALL xerbla(
'CTGSJA', -info )
472 $
CALL claset(
'Full', m, m, czero, cone, u, ldu )
474 $
CALL claset(
'Full', p, p, czero, cone, v, ldv )
476 $
CALL claset(
'Full', n, n, czero, cone, q, ldq )
481 DO 40 kcycle = 1, maxit
492 $ a1 = real( a( k+i, n-l+i ) )
494 $ a3 = real( a( k+j, n-l+j ) )
496 b1 = real( b( i, n-l+i ) )
497 b3 = real( b( j, n-l+j ) )
501 $ a2 = a( k+i, n-l+j )
505 $ a2 = a( k+j, n-l+i )
509 CALL clags2( upper, a1, a2, a3, b1, b2, b3, csu, snu,
510 $ csv, snv, csq, snq )
515 $
CALL crot( l, a( k+j, n-l+1 ), lda, a( k+i, n-l+1 ),
516 $ lda, csu, conjg( snu ) )
520 CALL crot( l, b( j, n-l+1 ), ldb, b( i, n-l+1 ), ldb,
521 $ csv, conjg( snv ) )
526 CALL crot( min( k+l, m ), a( 1, n-l+j ), 1,
527 $ a( 1, n-l+i ), 1, csq, snq )
529 CALL crot( l, b( 1, n-l+j ), 1, b( 1, n-l+i ), 1, csq,
534 $ a( k+i, n-l+j ) = czero
535 b( i, n-l+j ) = czero
538 $ a( k+j, n-l+i ) = czero
539 b( j, n-l+i ) = czero
545 $ a( k+i, n-l+i ) = real( a( k+i, n-l+i ) )
547 $ a( k+j, n-l+j ) = real( a( k+j, n-l+j ) )
548 b( i, n-l+i ) = real( b( i, n-l+i ) )
549 b( j, n-l+j ) = real( b( j, n-l+j ) )
553 IF( wantu .AND. k+j.LE.m )
554 $
CALL crot( m, u( 1, k+j ), 1, u( 1, k+i ), 1, csu,
558 $
CALL crot( p, v( 1, j ), 1, v( 1, i ), 1, csv, snv )
561 $
CALL crot( n, q( 1, n-l+j ), 1, q( 1, n-l+i ), 1, csq,
567 IF( .NOT.upper )
THEN
576 DO 30 i = 1, min( l, m-k )
577 CALL ccopy( l-i+1, a( k+i, n-l+i ), lda, work, 1 )
578 CALL ccopy( l-i+1, b( i, n-l+i ), ldb, work( l+1 ), 1 )
579 CALL clapll( l-i+1, work, 1, work( l+1 ), 1, ssmin )
580 error = max( error, ssmin )
583 IF( abs( error ).LE.min( tola, tolb ) )
607 DO 70 i = 1, min( l, m-k )
609 a1 = real( a( k+i, n-l+i ) )
610 b1 = real( b( i, n-l+i ) )
613 IF( (gamma.LE.hugenum).AND.(gamma.GE.-hugenum) )
THEN
615 IF( gamma.LT.zero )
THEN
616 CALL csscal( l-i+1, -one, b( i, n-l+i ), ldb )
618 $
CALL csscal( p, -one, v( 1, i ), 1 )
621 CALL slartg( abs( gamma ), one, beta( k+i ), alpha( k+i ),
624 IF( alpha( k+i ).GE.beta( k+i ) )
THEN
625 CALL csscal( l-i+1, one / alpha( k+i ), a( k+i, n-l+i ),
628 CALL csscal( l-i+1, one / beta( k+i ), b( i, n-l+i ),
630 CALL ccopy( l-i+1, b( i, n-l+i ), ldb, a( k+i, n-l+i ),
637 CALL ccopy( l-i+1, b( i, n-l+i ), ldb, a( k+i, n-l+i ),
644 DO 80 i = m + 1, k + l
650 DO 90 i = k + l + 1, n
subroutine xerbla(srname, info)
subroutine ccopy(n, cx, incx, cy, incy)
CCOPY
subroutine clags2(upper, a1, a2, a3, b1, b2, b3, csu, snu, csv, snv, csq, snq)
CLAGS2
subroutine clapll(n, x, incx, y, incy, ssmin)
CLAPLL measures the linear dependence of two vectors.
subroutine slartg(f, g, c, s, r)
SLARTG generates a plane rotation with real cosine and real sine.
subroutine claset(uplo, m, n, alpha, beta, a, lda)
CLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values.
subroutine crot(n, cx, incx, cy, incy, c, s)
CROT applies a plane rotation with real cosine and complex sine to a pair of complex vectors.
subroutine csscal(n, sa, cx, incx)
CSSCAL
subroutine ctgsja(jobu, jobv, jobq, m, p, n, k, l, a, lda, b, ldb, tola, tolb, alpha, beta, u, ldu, v, ldv, q, ldq, work, ncycle, info)
CTGSJA