297 RECURSIVE SUBROUTINE sorcsd( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS,
298 $ signs, m, p, q, x11, ldx11, x12,
299 $ ldx12, x21, ldx21, x22, ldx22, theta,
300 $ u1, ldu1, u2, ldu2, v1t, ldv1t, v2t,
301 $ ldv2t, work, lwork, iwork, info )
309 CHARACTER jobu1, jobu2, jobv1t, jobv2t, signs, trans
310 INTEGER info, ldu1, ldu2, ldv1t, ldv2t, ldx11, ldx12,
311 $ ldx21, ldx22, lwork, m, p, q
316 REAL u1( ldu1, * ), u2( ldu2, * ), v1t( ldv1t, * ),
317 $ v2t( ldv2t, * ), work( * ), x11( ldx11, * ),
318 $ x12( ldx12, * ), x21( ldx21, * ), x22( ldx22,
326 parameter( one = 1.0e+0,
333 CHARACTER transt, signst
334 INTEGER childinfo, i, ib11d, ib11e, ib12d, ib12e,
335 $ ib21d, ib21e, ib22d, ib22e, ibbcsd, iorbdb,
336 $ iorglq, iorgqr, iphi, itaup1, itaup2, itauq1,
337 $ itauq2, j, lbbcsdwork, lbbcsdworkmin,
338 $ lbbcsdworkopt, lorbdbwork, lorbdbworkmin,
339 $ lorbdbworkopt, lorglqwork, lorglqworkmin,
340 $ lorglqworkopt, lorgqrwork, lorgqrworkmin,
341 $ lorgqrworkopt, lworkmin, lworkopt
342 LOGICAL colmajor, defaultsigns, lquery, wantu1, wantu2,
354 INTRINSIC int, max, min
361 wantu1 =
lsame( jobu1,
'Y' )
362 wantu2 =
lsame( jobu2,
'Y' )
363 wantv1t =
lsame( jobv1t,
'Y' )
364 wantv2t =
lsame( jobv2t,
'Y' )
365 colmajor = .NOT.
lsame( trans,
'T' )
366 defaultsigns = .NOT.
lsame( signs,
'O' )
367 lquery = lwork .EQ. -1
370 ELSE IF( p .LT. 0 .OR. p .GT. m )
THEN
372 ELSE IF( q .LT. 0 .OR. q .GT. m )
THEN
374 ELSE IF( ( colmajor .AND. ldx11 .LT. max(1,p) ) .OR.
375 $ ( .NOT.colmajor .AND. ldx11 .LT. max(1,q) ) )
THEN
377 ELSE IF( wantu1 .AND. ldu1 .LT. p )
THEN
379 ELSE IF( wantu2 .AND. ldu2 .LT. m-p )
THEN
381 ELSE IF( wantv1t .AND. ldv1t .LT. q )
THEN
383 ELSE IF( wantv2t .AND. ldv2t .LT. m-q )
THEN
389 IF( info .EQ. 0 .AND. min( p, m-p ) .LT. min( q, m-q ) )
THEN
395 IF( defaultsigns )
THEN
400 CALL
sorcsd( jobv1t, jobv2t, jobu1, jobu2, transt, signst, m,
401 $ q, p, x11, ldx11, x21, ldx21, x12, ldx12, x22,
402 $ ldx22, theta, v1t, ldv1t, v2t, ldv2t, u1, ldu1,
403 $ u2, ldu2, work, lwork, iwork, info )
410 IF( info .EQ. 0 .AND. m-q .LT. q )
THEN
411 IF( defaultsigns )
THEN
416 CALL
sorcsd( jobu2, jobu1, jobv2t, jobv1t, trans, signst, m,
417 $ m-p, m-q, x22, ldx22, x21, ldx21, x12, ldx12, x11,
418 $ ldx11, theta, u2, ldu2, u1, ldu1, v2t, ldv2t, v1t,
419 $ ldv1t, work, lwork, iwork, info )
425 IF( info .EQ. 0 )
THEN
428 itaup1 = iphi + max( 1, q - 1 )
429 itaup2 = itaup1 + max( 1, p )
430 itauq1 = itaup2 + max( 1, m - p )
431 itauq2 = itauq1 + max( 1, q )
432 iorgqr = itauq2 + max( 1, m - q )
433 CALL
sorgqr( m-q, m-q, m-q, dummy, max(1,m-q), dummy, work, -1,
435 lorgqrworkopt = int( work(1) )
436 lorgqrworkmin = max( 1, m - q )
437 iorglq = itauq2 + max( 1, m - q )
438 CALL
sorglq( m-q, m-q, m-q, dummy, max(1,m-q), dummy, work, -1,
440 lorglqworkopt = int( work(1) )
441 lorglqworkmin = max( 1, m - q )
442 iorbdb = itauq2 + max( 1, m - q )
443 CALL
sorbdb( trans, signs, m, p, q, x11, ldx11, x12, ldx12,
444 $ x21, ldx21, x22, ldx22, dummy, dummy, dummy, dummy, dummy,
445 $ dummy,work,-1,childinfo )
446 lorbdbworkopt = int( work(1) )
447 lorbdbworkmin = lorbdbworkopt
448 ib11d = itauq2 + max( 1, m - q )
449 ib11e = ib11d + max( 1, q )
450 ib12d = ib11e + max( 1, q - 1 )
451 ib12e = ib12d + max( 1, q )
452 ib21d = ib12e + max( 1, q - 1 )
453 ib21e = ib21d + max( 1, q )
454 ib22d = ib21e + max( 1, q - 1 )
455 ib22e = ib22d + max( 1, q )
456 ibbcsd = ib22e + max( 1, q - 1 )
457 CALL
sbbcsd( jobu1, jobu2, jobv1t, jobv2t, trans, m, p, q,
458 $ dummy, dummy, u1, ldu1, u2, ldu2, v1t, ldv1t, v2t,
459 $ ldv2t, dummy, dummy, dummy, dummy, dummy, dummy,
460 $ dummy, dummy, work, -1, childinfo )
461 lbbcsdworkopt = int( work(1) )
462 lbbcsdworkmin = lbbcsdworkopt
463 lworkopt = max( iorgqr + lorgqrworkopt, iorglq + lorglqworkopt,
464 $ iorbdb + lorbdbworkopt, ibbcsd + lbbcsdworkopt ) - 1
465 lworkmin = max( iorgqr + lorgqrworkmin, iorglq + lorglqworkmin,
466 $ iorbdb + lorbdbworkopt, ibbcsd + lbbcsdworkmin ) - 1
467 work(1) = max(lworkopt,lworkmin)
469 IF( lwork .LT. lworkmin .AND. .NOT. lquery )
THEN
472 lorgqrwork = lwork - iorgqr + 1
473 lorglqwork = lwork - iorglq + 1
474 lorbdbwork = lwork - iorbdb + 1
475 lbbcsdwork = lwork - ibbcsd + 1
481 IF( info .NE. 0 )
THEN
482 CALL
xerbla(
'SORCSD', -info )
484 ELSE IF( lquery )
THEN
490 CALL
sorbdb( trans, signs, m, p, q, x11, ldx11, x12, ldx12, x21,
491 $ ldx21, x22, ldx22, theta, work(iphi), work(itaup1),
492 $ work(itaup2), work(itauq1), work(itauq2),
493 $ work(iorbdb), lorbdbwork, childinfo )
498 IF( wantu1 .AND. p .GT. 0 )
THEN
499 CALL
slacpy(
'L', p, q, x11, ldx11, u1, ldu1 )
500 CALL
sorgqr( p, p, q, u1, ldu1, work(itaup1), work(iorgqr),
503 IF( wantu2 .AND. m-p .GT. 0 )
THEN
504 CALL
slacpy(
'L', m-p, q, x21, ldx21, u2, ldu2 )
505 CALL
sorgqr( m-p, m-p, q, u2, ldu2, work(itaup2),
506 $ work(iorgqr), lorgqrwork, info )
508 IF( wantv1t .AND. q .GT. 0 )
THEN
509 CALL
slacpy(
'U', q-1, q-1, x11(1,2), ldx11, v1t(2,2),
516 CALL
sorglq( q-1, q-1, q-1, v1t(2,2), ldv1t, work(itauq1),
517 $ work(iorglq), lorglqwork, info )
519 IF( wantv2t .AND. m-q .GT. 0 )
THEN
520 CALL
slacpy(
'U', p, m-q, x12, ldx12, v2t, ldv2t )
521 CALL
slacpy(
'U', m-p-q, m-p-q, x22(q+1,p+1), ldx22,
522 $ v2t(p+1,p+1), ldv2t )
523 CALL
sorglq( m-q, m-q, m-q, v2t, ldv2t, work(itauq2),
524 $ work(iorglq), lorglqwork, info )
527 IF( wantu1 .AND. p .GT. 0 )
THEN
528 CALL
slacpy(
'U', q, p, x11, ldx11, u1, ldu1 )
529 CALL
sorglq( p, p, q, u1, ldu1, work(itaup1), work(iorglq),
532 IF( wantu2 .AND. m-p .GT. 0 )
THEN
533 CALL
slacpy(
'U', q, m-p, x21, ldx21, u2, ldu2 )
534 CALL
sorglq( m-p, m-p, q, u2, ldu2, work(itaup2),
535 $ work(iorglq), lorglqwork, info )
537 IF( wantv1t .AND. q .GT. 0 )
THEN
538 CALL
slacpy(
'L', q-1, q-1, x11(2,1), ldx11, v1t(2,2),
545 CALL
sorgqr( q-1, q-1, q-1, v1t(2,2), ldv1t, work(itauq1),
546 $ work(iorgqr), lorgqrwork, info )
548 IF( wantv2t .AND. m-q .GT. 0 )
THEN
549 CALL
slacpy(
'L', m-q, p, x12, ldx12, v2t, ldv2t )
550 CALL
slacpy(
'L', m-p-q, m-p-q, x22(p+1,q+1), ldx22,
551 $ v2t(p+1,p+1), ldv2t )
552 CALL
sorgqr( m-q, m-q, m-q, v2t, ldv2t, work(itauq2),
553 $ work(iorgqr), lorgqrwork, info )
559 CALL
sbbcsd( jobu1, jobu2, jobv1t, jobv2t, trans, m, p, q, theta,
560 $ work(iphi), u1, ldu1, u2, ldu2, v1t, ldv1t, v2t,
561 $ ldv2t, work(ib11d), work(ib11e), work(ib12d),
562 $ work(ib12e), work(ib21d), work(ib21e), work(ib22d),
563 $ work(ib22e), work(ibbcsd), lbbcsdwork, info )
570 IF( q .GT. 0 .AND. wantu2 )
THEN
572 iwork(i) = m - p - q + i
578 CALL
slapmt( .false., m-p, m-p, u2, ldu2, iwork )
580 CALL
slapmr( .false., m-p, m-p, u2, ldu2, iwork )
583 IF( m .GT. 0 .AND. wantv2t )
THEN
585 iwork(i) = m - p - q + i
590 IF( .NOT. colmajor )
THEN
591 CALL
slapmt( .false., m-q, m-q, v2t, ldv2t, iwork )
593 CALL
slapmr( .false., m-q, m-q, v2t, ldv2t, iwork )