374 SUBROUTINE ztgsja( JOBU, JOBV, JOBQ, M, P, N, K, L, A, LDA, B,
375 $ LDB, TOLA, TOLB, ALPHA, BETA, U, LDU, V, LDV,
376 $ Q, LDQ, WORK, NCYCLE, INFO )
383 CHARACTER JOBQ, JOBU, JOBV
384 INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N,
386 DOUBLE PRECISION TOLA, TOLB
389 DOUBLE PRECISION ALPHA( * ), BETA( * )
390 COMPLEX*16 A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
391 $ u( ldu, * ), v( ldv, * ), work( * )
398 PARAMETER ( MAXIT = 40 )
399 DOUBLE PRECISION ZERO, ONE, HUGENUM
400 parameter( zero = 0.0d+0, one = 1.0d+0 )
401 COMPLEX*16 CZERO, CONE
402 parameter( czero = ( 0.0d+0, 0.0d+0 ),
403 $ cone = ( 1.0d+0, 0.0d+0 ) )
407 LOGICAL INITQ, INITU, INITV, UPPER, WANTQ, WANTU, WANTV
409 DOUBLE PRECISION A1, A3, B1, B3, CSQ, CSU, CSV, ERROR, GAMMA,
411 COMPLEX*16 A2, B2, SNQ, SNU, SNV
423 INTRINSIC abs, dble, dconjg, max, min, huge
424 parameter( hugenum = huge(zero) )
430 initu = lsame( jobu,
'I' )
431 wantu = initu .OR. lsame( jobu,
'U' )
433 initv = lsame( jobv,
'I' )
434 wantv = initv .OR. lsame( jobv,
'V' )
436 initq = lsame( jobq,
'I' )
437 wantq = initq .OR. lsame( jobq,
'Q' )
440 IF( .NOT.( initu .OR. wantu .OR. lsame( jobu,
'N' ) ) )
THEN
442 ELSE IF( .NOT.( initv .OR.
444 $ lsame( jobv,
'N' ) ) )
THEN
446 ELSE IF( .NOT.( initq .OR.
448 $ lsame( jobq,
'N' ) ) )
THEN
450 ELSE IF( m.LT.0 )
THEN
452 ELSE IF( p.LT.0 )
THEN
454 ELSE IF( n.LT.0 )
THEN
456 ELSE IF( lda.LT.max( 1, m ) )
THEN
458 ELSE IF( ldb.LT.max( 1, p ) )
THEN
460 ELSE IF( ldu.LT.1 .OR. ( wantu .AND. ldu.LT.m ) )
THEN
462 ELSE IF( ldv.LT.1 .OR. ( wantv .AND. ldv.LT.p ) )
THEN
464 ELSE IF( ldq.LT.1 .OR. ( wantq .AND. ldq.LT.n ) )
THEN
468 CALL xerbla(
'ZTGSJA', -info )
475 $
CALL zlaset(
'Full', m, m, czero, cone, u, ldu )
477 $
CALL zlaset(
'Full', p, p, czero, cone, v, ldv )
479 $
CALL zlaset(
'Full', n, n, czero, cone, q, ldq )
484 DO 40 kcycle = 1, maxit
495 $ a1 = dble( a( k+i, n-l+i ) )
497 $ a3 = dble( a( k+j, n-l+j ) )
499 b1 = dble( b( i, n-l+i ) )
500 b3 = dble( b( j, n-l+j ) )
504 $ a2 = a( k+i, n-l+j )
508 $ a2 = a( k+j, n-l+i )
512 CALL zlags2( upper, a1, a2, a3, b1, b2, b3, csu, snu,
513 $ csv, snv, csq, snq )
518 $
CALL zrot( l, a( k+j, n-l+1 ), lda, a( k+i,
520 $ lda, csu, dconjg( snu ) )
524 CALL zrot( l, b( j, n-l+1 ), ldb, b( i, n-l+1 ), ldb,
525 $ csv, dconjg( snv ) )
530 CALL zrot( min( k+l, m ), a( 1, n-l+j ), 1,
531 $ a( 1, n-l+i ), 1, csq, snq )
533 CALL zrot( l, b( 1, n-l+j ), 1, b( 1, n-l+i ), 1, csq,
538 $ a( k+i, n-l+j ) = czero
539 b( i, n-l+j ) = czero
542 $ a( k+j, n-l+i ) = czero
543 b( j, n-l+i ) = czero
549 $ a( k+i, n-l+i ) = dble( a( k+i, n-l+i ) )
551 $ a( k+j, n-l+j ) = dble( a( k+j, n-l+j ) )
552 b( i, n-l+i ) = dble( b( i, n-l+i ) )
553 b( j, n-l+j ) = dble( b( j, n-l+j ) )
557 IF( wantu .AND. k+j.LE.m )
558 $
CALL zrot( m, u( 1, k+j ), 1, u( 1, k+i ), 1, csu,
562 $
CALL zrot( p, v( 1, j ), 1, v( 1, i ), 1, csv,
566 $
CALL zrot( n, q( 1, n-l+j ), 1, q( 1, n-l+i ), 1,
573 IF( .NOT.upper )
THEN
582 DO 30 i = 1, min( l, m-k )
583 CALL zcopy( l-i+1, a( k+i, n-l+i ), lda, work, 1 )
584 CALL zcopy( l-i+1, b( i, n-l+i ), ldb, work( l+1 ),
586 CALL zlapll( l-i+1, work, 1, work( l+1 ), 1, ssmin )
587 error = max( error, ssmin )
590 IF( abs( error ).LE.min( tola, tolb ) )
614 DO 70 i = 1, min( l, m-k )
616 a1 = dble( a( k+i, n-l+i ) )
617 b1 = dble( b( i, n-l+i ) )
620 IF( (gamma.LE.hugenum).AND.(gamma.GE.-hugenum) )
THEN
622 IF( gamma.LT.zero )
THEN
623 CALL zdscal( l-i+1, -one, b( i, n-l+i ), ldb )
625 $
CALL zdscal( p, -one, v( 1, i ), 1 )
628 CALL dlartg( abs( gamma ), one, beta( k+i ),
632 IF( alpha( k+i ).GE.beta( k+i ) )
THEN
633 CALL zdscal( l-i+1, one / alpha( k+i ), a( k+i,
637 CALL zdscal( l-i+1, one / beta( k+i ), b( i, n-l+i ),
639 CALL zcopy( l-i+1, b( i, n-l+i ), ldb, a( k+i,
648 CALL zcopy( l-i+1, b( i, n-l+i ), ldb, a( k+i, n-l+i ),
655 DO 80 i = m + 1, k + l
661 DO 90 i = k + l + 1, n