312 RECURSIVE SUBROUTINE zuncsd( JOBU1, JOBU2, JOBV1T, JOBV2T,
314 $ SIGNS, M, P, Q, X11, LDX11, X12,
315 $ LDX12, X21, LDX21, X22, LDX22, THETA,
316 $ U1, LDU1, U2, LDU2, V1T, LDV1T, V2T,
317 $ LDV2T, WORK, LWORK, RWORK, LRWORK,
325 CHARACTER jobu1, jobu2, jobv1t, jobv2t, signs, trans
326 INTEGER info, ldu1, ldu2, ldv1t, ldv2t, ldx11, ldx12,
327 $ ldx21, ldx22, lrwork, lwork, m, p, q
331 DOUBLE PRECISION theta( * )
332 DOUBLE PRECISION rwork( * )
333 COMPLEX*16 u1( ldu1, * ), u2( ldu2, * ), v1t( ldv1t, * ),
334 $ v2t( ldv2t, * ), work( * ), x11( ldx11, * ),
335 $ x12( ldx12, * ), x21( ldx21, * ), x22( ldx22,
343 PARAMETER ( one = (1.0d0,0.0d0),
344 $ zero = (0.0d0,0.0d0) )
347 CHARACTER transt, signst
348 INTEGER childinfo, i, ib11d, ib11e, ib12d, ib12e,
349 $ ib21d, ib21e, ib22d, ib22e, ibbcsd, iorbdb,
350 $ iorglq, iorgqr, iphi, itaup1, itaup2, itauq1,
351 $ itauq2, j, lbbcsdwork, lbbcsdworkmin,
352 $ lbbcsdworkopt, lorbdbwork, lorbdbworkmin,
353 $ lorbdbworkopt, lorglqwork, lorglqworkmin,
354 $ lorglqworkopt, lorgqrwork, lorgqrworkmin,
355 $ lorgqrworkopt, lworkmin, lworkopt, p1, q1
356 LOGICAL colmajor, defaultsigns, lquery, wantu1, wantu2,
358 INTEGER lrworkmin, lrworkopt
371 INTRINSIC int, max, min
378 wantu1 =
lsame( jobu1,
'Y' )
379 wantu2 =
lsame( jobu2,
'Y' )
380 wantv1t =
lsame( jobv1t,
'Y' )
381 wantv2t =
lsame( jobv2t,
'Y' )
382 colmajor = .NOT.
lsame( trans,
'T' )
383 defaultsigns = .NOT.
lsame( signs,
'O' )
384 lquery = lwork .EQ. -1
385 lrquery = lrwork .EQ. -1
388 ELSE IF( p .LT. 0 .OR. p .GT. m )
THEN
390 ELSE IF( q .LT. 0 .OR. q .GT. m )
THEN
392 ELSE IF ( colmajor .AND. ldx11 .LT. max( 1, p ) )
THEN
394 ELSE IF (.NOT. colmajor .AND. ldx11 .LT. max( 1, q ) )
THEN
396 ELSE IF (colmajor .AND. ldx12 .LT. max( 1, p ) )
THEN
398 ELSE IF (.NOT. colmajor .AND. ldx12 .LT. max( 1, m-q ) )
THEN
400 ELSE IF (colmajor .AND. ldx21 .LT. max( 1, m-p ) )
THEN
402 ELSE IF (.NOT. colmajor .AND. ldx21 .LT. max( 1, q ) )
THEN
404 ELSE IF (colmajor .AND. ldx22 .LT. max( 1, m-p ) )
THEN
406 ELSE IF (.NOT. colmajor .AND. ldx22 .LT. max( 1, m-q ) )
THEN
408 ELSE IF( wantu1 .AND. ldu1 .LT. p )
THEN
410 ELSE IF( wantu2 .AND. ldu2 .LT. m-p )
THEN
412 ELSE IF( wantv1t .AND. ldv1t .LT. q )
THEN
414 ELSE IF( wantv2t .AND. ldv2t .LT. m-q )
THEN
420 IF( info .EQ. 0 .AND. min( p, m-p ) .LT. min( q, m-q ) )
THEN
426 IF( defaultsigns )
THEN
431 CALL zuncsd( jobv1t, jobv2t, jobu1, jobu2, transt, signst,
433 $ q, p, x11, ldx11, x21, ldx21, x12, ldx12, x22,
434 $ ldx22, theta, v1t, ldv1t, v2t, ldv2t, u1, ldu1,
435 $ u2, ldu2, work, lwork, rwork, lrwork, iwork,
443 IF( info .EQ. 0 .AND. m-q .LT. q )
THEN
444 IF( defaultsigns )
THEN
449 CALL zuncsd( jobu2, jobu1, jobv2t, jobv1t, trans, signst, m,
450 $ m-p, m-q, x22, ldx22, x21, ldx21, x12, ldx12, x11,
451 $ ldx11, theta, u2, ldu2, u1, ldu1, v2t, ldv2t, v1t,
452 $ ldv1t, work, lwork, rwork, lrwork, iwork, info )
458 IF( info .EQ. 0 )
THEN
463 ib11d = iphi + max( 1, q - 1 )
464 ib11e = ib11d + max( 1, q )
465 ib12d = ib11e + max( 1, q - 1 )
466 ib12e = ib12d + max( 1, q )
467 ib21d = ib12e + max( 1, q - 1 )
468 ib21e = ib21d + max( 1, q )
469 ib22d = ib21e + max( 1, q - 1 )
470 ib22e = ib22d + max( 1, q )
471 ibbcsd = ib22e + max( 1, q - 1 )
472 CALL zbbcsd( jobu1, jobu2, jobv1t, jobv2t, trans, m, p, q,
473 $ theta, theta, u1, ldu1, u2, ldu2, v1t, ldv1t,
474 $ v2t, ldv2t, theta, theta, theta, theta, theta,
475 $ theta, theta, theta, rwork, -1, childinfo )
476 lbbcsdworkopt = int( rwork(1) )
477 lbbcsdworkmin = lbbcsdworkopt
478 lrworkopt = ibbcsd + lbbcsdworkopt - 1
479 lrworkmin = ibbcsd + lbbcsdworkmin - 1
485 itaup2 = itaup1 + max( 1, p )
486 itauq1 = itaup2 + max( 1, m - p )
487 itauq2 = itauq1 + max( 1, q )
488 iorgqr = itauq2 + max( 1, m - q )
489 CALL zungqr( m-q, m-q, m-q, u1, max(1,m-q), u1, work, -1,
491 lorgqrworkopt = int( work(1) )
492 lorgqrworkmin = max( 1, m - q )
493 iorglq = itauq2 + max( 1, m - q )
494 CALL zunglq( m-q, m-q, m-q, u1, max(1,m-q), u1, work, -1,
496 lorglqworkopt = int( work(1) )
497 lorglqworkmin = max( 1, m - q )
498 iorbdb = itauq2 + max( 1, m - q )
499 CALL zunbdb( trans, signs, m, p, q, x11, ldx11, x12, ldx12,
500 $ x21, ldx21, x22, ldx22, theta, theta, u1, u2,
501 $ v1t, v2t, work, -1, childinfo )
502 lorbdbworkopt = int( work(1) )
503 lorbdbworkmin = lorbdbworkopt
504 lworkopt = max( iorgqr + lorgqrworkopt, iorglq + lorglqworkopt,
505 $ iorbdb + lorbdbworkopt ) - 1
506 lworkmin = max( iorgqr + lorgqrworkmin, iorglq + lorglqworkmin,
507 $ iorbdb + lorbdbworkmin ) - 1
508 work(1) = max(lworkopt,lworkmin)
510 IF( lwork .LT. lworkmin
511 $ .AND. .NOT. ( lquery .OR. lrquery ) )
THEN
513 ELSE IF( lrwork .LT. lrworkmin
514 $ .AND. .NOT. ( lquery .OR. lrquery ) )
THEN
517 lorgqrwork = lwork - iorgqr + 1
518 lorglqwork = lwork - iorglq + 1
519 lorbdbwork = lwork - iorbdb + 1
520 lbbcsdwork = lrwork - ibbcsd + 1
526 IF( info .NE. 0 )
THEN
527 CALL xerbla(
'ZUNCSD', -info )
529 ELSE IF( lquery .OR. lrquery )
THEN
535 CALL zunbdb( trans, signs, m, p, q, x11, ldx11, x12, ldx12,
537 $ ldx21, x22, ldx22, theta, rwork(iphi), work(itaup1),
538 $ work(itaup2), work(itauq1), work(itauq2),
539 $ work(iorbdb), lorbdbwork, childinfo )
544 IF( wantu1 .AND. p .GT. 0 )
THEN
545 CALL zlacpy(
'L', p, q, x11, ldx11, u1, ldu1 )
546 CALL zungqr( p, p, q, u1, ldu1, work(itaup1),
550 IF( wantu2 .AND. m-p .GT. 0 )
THEN
551 CALL zlacpy(
'L', m-p, q, x21, ldx21, u2, ldu2 )
552 CALL zungqr( m-p, m-p, q, u2, ldu2, work(itaup2),
553 $ work(iorgqr), lorgqrwork, info )
555 IF( wantv1t .AND. q .GT. 0 )
THEN
556 CALL zlacpy(
'U', q-1, q-1, x11(1,2), ldx11, v1t(2,2),
563 CALL zunglq( q-1, q-1, q-1, v1t(2,2), ldv1t,
565 $ work(iorglq), lorglqwork, info )
567 IF( wantv2t .AND. m-q .GT. 0 )
THEN
568 CALL zlacpy(
'U', p, m-q, x12, ldx12, v2t, ldv2t )
570 CALL zlacpy(
'U', m-p-q, m-p-q, x22(q+1,p+1), ldx22,
571 $ v2t(p+1,p+1), ldv2t )
574 CALL zunglq( m-q, m-q, m-q, v2t, ldv2t, work(itauq2),
575 $ work(iorglq), lorglqwork, info )
579 IF( wantu1 .AND. p .GT. 0 )
THEN
580 CALL zlacpy(
'U', q, p, x11, ldx11, u1, ldu1 )
581 CALL zunglq( p, p, q, u1, ldu1, work(itaup1),
585 IF( wantu2 .AND. m-p .GT. 0 )
THEN
586 CALL zlacpy(
'U', q, m-p, x21, ldx21, u2, ldu2 )
587 CALL zunglq( m-p, m-p, q, u2, ldu2, work(itaup2),
588 $ work(iorglq), lorglqwork, info )
590 IF( wantv1t .AND. q .GT. 0 )
THEN
591 CALL zlacpy(
'L', q-1, q-1, x11(2,1), ldx11, v1t(2,2),
598 CALL zungqr( q-1, q-1, q-1, v1t(2,2), ldv1t,
600 $ work(iorgqr), lorgqrwork, info )
602 IF( wantv2t .AND. m-q .GT. 0 )
THEN
605 CALL zlacpy(
'L', m-q, p, x12, ldx12, v2t, ldv2t )
606 IF( m .GT. p+q )
THEN
607 CALL zlacpy(
'L', m-p-q, m-p-q, x22(p1,q1), ldx22,
608 $ v2t(p+1,p+1), ldv2t )
610 CALL zungqr( m-q, m-q, m-q, v2t, ldv2t, work(itauq2),
611 $ work(iorgqr), lorgqrwork, info )
617 CALL zbbcsd( jobu1, jobu2, jobv1t, jobv2t, trans, m, p, q,
619 $ rwork(iphi), u1, ldu1, u2, ldu2, v1t, ldv1t, v2t,
620 $ ldv2t, rwork(ib11d), rwork(ib11e), rwork(ib12d),
621 $ rwork(ib12e), rwork(ib21d), rwork(ib21e),
622 $ rwork(ib22d), rwork(ib22e), rwork(ibbcsd),
630 IF( q .GT. 0 .AND. wantu2 )
THEN
632 iwork(i) = m - p - q + i
638 CALL zlapmt( .false., m-p, m-p, u2, ldu2, iwork )
640 CALL zlapmr( .false., m-p, m-p, u2, ldu2, iwork )
643 IF( m .GT. 0 .AND. wantv2t )
THEN
645 iwork(i) = m - p - q + i
650 IF( .NOT. colmajor )
THEN
651 CALL zlapmt( .false., m-q, m-q, v2t, ldv2t, iwork )
653 CALL zlapmr( .false., m-q, m-q, v2t, ldv2t, iwork )