273 SUBROUTINE cggsvp3( JOBU, JOBV, JOBQ, M, P, N, A, LDA, B, LDB,
274 $ TOLA, TOLB, K, L, U, LDU, V, LDV, Q, LDQ,
275 $ IWORK, RWORK, TAU, WORK, LWORK, INFO )
284 CHARACTER JOBQ, JOBU, JOBV
285 INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N, P,
292 COMPLEX A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
293 $ tau( * ), u( ldu, * ), v( ldv, * ), work( * )
300 PARAMETER ( CZERO = ( 0.0e+0, 0.0e+0 ),
301 $ cone = ( 1.0e+0, 0.0e+0 ) )
304 LOGICAL FORWRD, WANTQ, WANTU, WANTV, LQUERY
317 INTRINSIC abs, aimag, max, min, real
323 wantu = lsame( jobu,
'U' )
324 wantv = lsame( jobv,
'V' )
325 wantq = lsame( jobq,
'Q' )
327 lquery = ( lwork.EQ.-1 )
333 IF( .NOT.( wantu .OR. lsame( jobu,
'N' ) ) )
THEN
335 ELSE IF( .NOT.( wantv .OR. lsame( jobv,
'N' ) ) )
THEN
337 ELSE IF( .NOT.( wantq .OR. lsame( jobq,
'N' ) ) )
THEN
339 ELSE IF( m.LT.0 )
THEN
341 ELSE IF( p.LT.0 )
THEN
343 ELSE IF( n.LT.0 )
THEN
345 ELSE IF( lda.LT.max( 1, m ) )
THEN
347 ELSE IF( ldb.LT.max( 1, p ) )
THEN
349 ELSE IF( ldu.LT.1 .OR. ( wantu .AND. ldu.LT.m ) )
THEN
351 ELSE IF( ldv.LT.1 .OR. ( wantv .AND. ldv.LT.p ) )
THEN
353 ELSE IF( ldq.LT.1 .OR. ( wantq .AND. ldq.LT.n ) )
THEN
355 ELSE IF( lwork.LT.1 .AND. .NOT.lquery )
THEN
362 CALL cgeqp3( p, n, b, ldb, iwork, tau, work, -1, rwork,
364 lwkopt = int( work( 1 ) )
366 lwkopt = max( lwkopt, p )
368 lwkopt = max( lwkopt, min( n, p ) )
369 lwkopt = max( lwkopt, m )
371 lwkopt = max( lwkopt, n )
373 CALL cgeqp3( m, n, a, lda, iwork, tau, work, -1, rwork,
375 lwkopt = max( lwkopt, int( work( 1 ) ) )
376 lwkopt = max( 1, lwkopt )
377 work( 1 ) = cmplx( lwkopt )
381 CALL xerbla(
'CGGSVP3', -info )
394 CALL cgeqp3( p, n, b, ldb, iwork, tau, work, lwork, rwork,
399 CALL clapmt( forwrd, m, n, a, lda, iwork )
404 DO 20 i = 1, min( p, n )
405 IF( abs( b( i, i ) ).GT.tolb )
413 CALL claset(
'Full', p, p, czero, czero, v, ldv )
415 $
CALL clacpy(
'Lower', p-1, n, b( 2, 1 ), ldb, v( 2, 1 ),
417 CALL cung2r( p, p, min( p, n ), v, ldv, tau, work, info )
428 $
CALL claset(
'Full', p-l, n, czero, czero, b( l+1, 1 ),
435 CALL claset(
'Full', n, n, czero, cone, q, ldq )
436 CALL clapmt( forwrd, n, n, q, ldq, iwork )
439 IF( p.GE.l .AND. n.NE.l )
THEN
443 CALL cgerq2( l, n, b, ldb, tau, work, info )
447 CALL cunmr2(
'Right',
'Conjugate transpose', m, n, l, b,
449 $ tau, a, lda, work, info )
454 CALL cunmr2(
'Right',
'Conjugate transpose', n, n, l, b,
455 $ ldb, tau, q, ldq, work, info )
460 CALL claset(
'Full', l, n-l, czero, czero, b, ldb )
461 DO 60 j = n - l + 1, n
462 DO 50 i = j - n + l + 1, l
480 CALL cgeqp3( m, n-l, a, lda, iwork, tau, work, lwork, rwork,
486 DO 80 i = 1, min( m, n-l )
487 IF( abs( a( i, i ) ).GT.tola )
493 CALL cunm2r(
'Left',
'Conjugate transpose', m, l, min( m,
495 $ a, lda, tau, a( 1, n-l+1 ), lda, work, info )
501 CALL claset(
'Full', m, m, czero, czero, u, ldu )
503 $
CALL clacpy(
'Lower', m-1, n-l, a( 2, 1 ), lda, u( 2,
506 CALL cung2r( m, m, min( m, n-l ), u, ldu, tau, work, info )
513 CALL clapmt( forwrd, n, n-l, q, ldq, iwork )
525 $
CALL claset(
'Full', m-k, n-l, czero, czero, a( k+1, 1 ),
532 CALL cgerq2( k, n-l, a, lda, tau, work, info )
538 CALL cunmr2(
'Right',
'Conjugate transpose', n, n-l, k,
540 $ lda, tau, q, ldq, work, info )
545 CALL claset(
'Full', k, n-l-k, czero, czero, a, lda )
546 DO 120 j = n - l - k + 1, n - l
547 DO 110 i = j - n + l + k + 1, k
558 CALL cgeqr2( m-k, l, a( k+1, n-l+1 ), lda, tau, work, info )
564 CALL cunm2r(
'Right',
'No transpose', m, m-k, min( m-k,
566 $ a( k+1, n-l+1 ), lda, tau, u( 1, k+1 ), ldu,
572 DO 140 j = n - l + 1, n
573 DO 130 i = j - n + k + l + 1, m
580 work( 1 ) = cmplx( lwkopt )