267 SUBROUTINE dggsvp3( JOBU, JOBV, JOBQ, M, P, N, A, LDA, B, LDB,
268 $ TOLA, TOLB, K, L, U, LDU, V, LDV, Q, LDQ,
269 $ IWORK, TAU, WORK, LWORK, INFO )
278 CHARACTER JOBQ, JOBU, JOBV
279 INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N, P,
281 DOUBLE PRECISION TOLA, TOLB
285 DOUBLE PRECISION A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
286 $ tau( * ), u( ldu, * ), v( ldv, * ), work( * )
292 DOUBLE PRECISION ZERO, ONE
293 PARAMETER ( ZERO = 0.0d+0, one = 1.0d+0 )
296 LOGICAL FORWRD, WANTQ, WANTU, WANTV, LQUERY
309 INTRINSIC abs, max, min
315 wantu = lsame( jobu,
'U' )
316 wantv = lsame( jobv,
'V' )
317 wantq = lsame( jobq,
'Q' )
319 lquery = ( lwork.EQ.-1 )
325 IF( .NOT.( wantu .OR. lsame( jobu,
'N' ) ) )
THEN
327 ELSE IF( .NOT.( wantv .OR. lsame( jobv,
'N' ) ) )
THEN
329 ELSE IF( .NOT.( wantq .OR. lsame( jobq,
'N' ) ) )
THEN
331 ELSE IF( m.LT.0 )
THEN
333 ELSE IF( p.LT.0 )
THEN
335 ELSE IF( n.LT.0 )
THEN
337 ELSE IF( lda.LT.max( 1, m ) )
THEN
339 ELSE IF( ldb.LT.max( 1, p ) )
THEN
341 ELSE IF( ldu.LT.1 .OR. ( wantu .AND. ldu.LT.m ) )
THEN
343 ELSE IF( ldv.LT.1 .OR. ( wantv .AND. ldv.LT.p ) )
THEN
345 ELSE IF( ldq.LT.1 .OR. ( wantq .AND. ldq.LT.n ) )
THEN
347 ELSE IF( lwork.LT.1 .AND. .NOT.lquery )
THEN
354 CALL dgeqp3( p, n, b, ldb, iwork, tau, work, -1, info )
355 lwkopt = int( work( 1 ) )
357 lwkopt = max( lwkopt, p )
359 lwkopt = max( lwkopt, min( n, p ) )
360 lwkopt = max( lwkopt, m )
362 lwkopt = max( lwkopt, n )
364 CALL dgeqp3( m, n, a, lda, iwork, tau, work, -1, info )
365 lwkopt = max( lwkopt, int( work( 1 ) ) )
366 lwkopt = max( 1, lwkopt )
367 work( 1 ) = dble( lwkopt )
371 CALL xerbla(
'DGGSVP3', -info )
384 CALL dgeqp3( p, n, b, ldb, iwork, tau, work, lwork, info )
388 CALL dlapmt( forwrd, m, n, a, lda, iwork )
393 DO 20 i = 1, min( p, n )
394 IF( abs( b( i, i ) ).GT.tolb )
402 CALL dlaset(
'Full', p, p, zero, zero, v, ldv )
404 $
CALL dlacpy(
'Lower', p-1, n, b( 2, 1 ), ldb, v( 2, 1 ),
406 CALL dorg2r( p, p, min( p, n ), v, ldv, tau, work, info )
417 $
CALL dlaset(
'Full', p-l, n, zero, zero, b( l+1, 1 ), ldb )
423 CALL dlaset(
'Full', n, n, zero, one, q, ldq )
424 CALL dlapmt( forwrd, n, n, q, ldq, iwork )
427 IF( p.GE.l .AND. n.NE.l )
THEN
431 CALL dgerq2( l, n, b, ldb, tau, work, info )
435 CALL dormr2(
'Right',
'Transpose', m, n, l, b, ldb, tau, a,
442 CALL dormr2(
'Right',
'Transpose', n, n, l, b, ldb, tau,
449 CALL dlaset(
'Full', l, n-l, zero, zero, b, ldb )
450 DO 60 j = n - l + 1, n
451 DO 50 i = j - n + l + 1, l
469 CALL dgeqp3( m, n-l, a, lda, iwork, tau, work, lwork, info )
474 DO 80 i = 1, min( m, n-l )
475 IF( abs( a( i, i ) ).GT.tola )
481 CALL dorm2r(
'Left',
'Transpose', m, l, min( m, n-l ), a, lda,
482 $ tau, a( 1, n-l+1 ), lda, work, info )
488 CALL dlaset(
'Full', m, m, zero, zero, u, ldu )
490 $
CALL dlacpy(
'Lower', m-1, n-l, a( 2, 1 ), lda, u( 2,
493 CALL dorg2r( m, m, min( m, n-l ), u, ldu, tau, work, info )
500 CALL dlapmt( forwrd, n, n-l, q, ldq, iwork )
512 $
CALL dlaset(
'Full', m-k, n-l, zero, zero, a( k+1, 1 ),
519 CALL dgerq2( k, n-l, a, lda, tau, work, info )
525 CALL dormr2(
'Right',
'Transpose', n, n-l, k, a, lda,
527 $ q, ldq, work, info )
532 CALL dlaset(
'Full', k, n-l-k, zero, zero, a, lda )
533 DO 120 j = n - l - k + 1, n - l
534 DO 110 i = j - n + l + k + 1, k
545 CALL dgeqr2( m-k, l, a( k+1, n-l+1 ), lda, tau, work, info )
551 CALL dorm2r(
'Right',
'No transpose', m, m-k, min( m-k,
553 $ a( k+1, n-l+1 ), lda, tau, u( 1, k+1 ), ldu,
559 DO 140 j = n - l + 1, n
560 DO 130 i = j - n + k + l + 1, m
567 work( 1 ) = dble( lwkopt )