00001 RECURSIVE SUBROUTINE ZUNCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS,
00002 $ SIGNS, M, P, Q, X11, LDX11, X12,
00003 $ LDX12, X21, LDX21, X22, LDX22, THETA,
00004 $ U1, LDU1, U2, LDU2, V1T, LDV1T, V2T,
00005 $ LDV2T, WORK, LWORK, RWORK, LRWORK,
00006 $ IWORK, INFO )
00007 IMPLICIT NONE
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 CHARACTER JOBU1, JOBU2, JOBV1T, JOBV2T, SIGNS, TRANS
00019 INTEGER INFO, LDU1, LDU2, LDV1T, LDV2T, LDX11, LDX12,
00020 $ LDX21, LDX22, LRWORK, LWORK, M, P, Q
00021
00022
00023 INTEGER IWORK( * )
00024 DOUBLE PRECISION THETA( * )
00025 DOUBLE PRECISION RWORK( * )
00026 COMPLEX*16 U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ),
00027 $ V2T( LDV2T, * ), WORK( * ), X11( LDX11, * ),
00028 $ X12( LDX12, * ), X21( LDX21, * ), X22( LDX22,
00029 $ * )
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 DOUBLE PRECISION REALONE
00178 PARAMETER ( REALONE = 1.0D0 )
00179 COMPLEX*16 NEGONE, ONE, PIOVER2, ZERO
00180 PARAMETER ( NEGONE = (-1.0D0,0.0D0), ONE = (1.0D0,0.0D0),
00181 $ PIOVER2 = 1.57079632679489662D0,
00182 $ ZERO = (0.0D0,0.0D0) )
00183
00184
00185 CHARACTER TRANST, SIGNST
00186 INTEGER CHILDINFO, I, IB11D, IB11E, IB12D, IB12E,
00187 $ IB21D, IB21E, IB22D, IB22E, IBBCSD, IORBDB,
00188 $ IORGLQ, IORGQR, IPHI, ITAUP1, ITAUP2, ITAUQ1,
00189 $ ITAUQ2, J, LBBCSDWORK, LBBCSDWORKMIN,
00190 $ LBBCSDWORKOPT, LORBDBWORK, LORBDBWORKMIN,
00191 $ LORBDBWORKOPT, LORGLQWORK, LORGLQWORKMIN,
00192 $ LORGLQWORKOPT, LORGQRWORK, LORGQRWORKMIN,
00193 $ LORGQRWORKOPT, LWORKMIN, LWORKOPT
00194 LOGICAL COLMAJOR, DEFAULTSIGNS, LQUERY, WANTU1, WANTU2,
00195 $ WANTV1T, WANTV2T
00196 INTEGER LRWORKMIN, LRWORKOPT
00197 LOGICAL LRQUERY
00198
00199
00200 EXTERNAL XERBLA, ZBBCSD, ZLACPY, ZLAPMR, ZLAPMT, ZLASCL,
00201 $ ZLASET, ZUNBDB, ZUNGLQ, ZUNGQR
00202
00203
00204 LOGICAL LSAME
00205 EXTERNAL LSAME
00206
00207
00208 INTRINSIC COS, INT, MAX, MIN, SIN
00209
00210
00211
00212
00213
00214 INFO = 0
00215 WANTU1 = LSAME( JOBU1, 'Y' )
00216 WANTU2 = LSAME( JOBU2, 'Y' )
00217 WANTV1T = LSAME( JOBV1T, 'Y' )
00218 WANTV2T = LSAME( JOBV2T, 'Y' )
00219 COLMAJOR = .NOT. LSAME( TRANS, 'T' )
00220 DEFAULTSIGNS = .NOT. LSAME( SIGNS, 'O' )
00221 LQUERY = LWORK .EQ. -1
00222 LRQUERY = LRWORK .EQ. -1
00223 IF( M .LT. 0 ) THEN
00224 INFO = -7
00225 ELSE IF( P .LT. 0 .OR. P .GT. M ) THEN
00226 INFO = -8
00227 ELSE IF( Q .LT. 0 .OR. Q .GT. M ) THEN
00228 INFO = -9
00229 ELSE IF( ( COLMAJOR .AND. LDX11 .LT. MAX(1,P) ) .OR.
00230 $ ( .NOT.COLMAJOR .AND. LDX11 .LT. MAX(1,Q) ) ) THEN
00231 INFO = -11
00232 ELSE IF( WANTU1 .AND. LDU1 .LT. P ) THEN
00233 INFO = -14
00234 ELSE IF( WANTU2 .AND. LDU2 .LT. M-P ) THEN
00235 INFO = -16
00236 ELSE IF( WANTV1T .AND. LDV1T .LT. Q ) THEN
00237 INFO = -18
00238 ELSE IF( WANTV2T .AND. LDV2T .LT. M-Q ) THEN
00239 INFO = -20
00240 END IF
00241
00242
00243
00244 IF( INFO .EQ. 0 .AND. MIN( P, M-P ) .LT. MIN( Q, M-Q ) ) THEN
00245 IF( COLMAJOR ) THEN
00246 TRANST = 'T'
00247 ELSE
00248 TRANST = 'N'
00249 END IF
00250 IF( DEFAULTSIGNS ) THEN
00251 SIGNST = 'O'
00252 ELSE
00253 SIGNST = 'D'
00254 END IF
00255 CALL ZUNCSD( JOBV1T, JOBV2T, JOBU1, JOBU2, TRANST, SIGNST, M,
00256 $ Q, P, X11, LDX11, X21, LDX21, X12, LDX12, X22,
00257 $ LDX22, THETA, V1T, LDV1T, V2T, LDV2T, U1, LDU1,
00258 $ U2, LDU2, WORK, LWORK, RWORK, LRWORK, IWORK,
00259 $ INFO )
00260 RETURN
00261 END IF
00262
00263
00264
00265
00266 IF( INFO .EQ. 0 .AND. M-Q .LT. Q ) THEN
00267 IF( DEFAULTSIGNS ) THEN
00268 SIGNST = 'O'
00269 ELSE
00270 SIGNST = 'D'
00271 END IF
00272 CALL ZUNCSD( JOBU2, JOBU1, JOBV2T, JOBV1T, TRANS, SIGNST, M,
00273 $ M-P, M-Q, X22, LDX22, X21, LDX21, X12, LDX12, X11,
00274 $ LDX11, THETA, U2, LDU2, U1, LDU1, V2T, LDV2T, V1T,
00275 $ LDV1T, WORK, LWORK, RWORK, LRWORK, IWORK, INFO )
00276 RETURN
00277 END IF
00278
00279
00280
00281 IF( INFO .EQ. 0 ) THEN
00282
00283
00284
00285 IPHI = 2
00286 IB11D = IPHI + MAX( 1, Q - 1 )
00287 IB11E = IB11D + MAX( 1, Q )
00288 IB12D = IB11E + MAX( 1, Q - 1 )
00289 IB12E = IB12D + MAX( 1, Q )
00290 IB21D = IB12E + MAX( 1, Q - 1 )
00291 IB21E = IB21D + MAX( 1, Q )
00292 IB22D = IB21E + MAX( 1, Q - 1 )
00293 IB22E = IB22D + MAX( 1, Q )
00294 IBBCSD = IB22E + MAX( 1, Q - 1 )
00295 CALL ZBBCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, M, P, Q, 0,
00296 $ 0, U1, LDU1, U2, LDU2, V1T, LDV1T, V2T, LDV2T, 0,
00297 $ 0, 0, 0, 0, 0, 0, 0, RWORK, -1, CHILDINFO )
00298 LBBCSDWORKOPT = INT( RWORK(1) )
00299 LBBCSDWORKMIN = LBBCSDWORKOPT
00300 LRWORKOPT = IBBCSD + LBBCSDWORKOPT - 1
00301 LRWORKMIN = IBBCSD + LBBCSDWORKMIN - 1
00302 RWORK(1) = LRWORKOPT
00303
00304
00305
00306 ITAUP1 = 2
00307 ITAUP2 = ITAUP1 + MAX( 1, P )
00308 ITAUQ1 = ITAUP2 + MAX( 1, M - P )
00309 ITAUQ2 = ITAUQ1 + MAX( 1, Q )
00310 IORGQR = ITAUQ2 + MAX( 1, M - Q )
00311 CALL ZUNGQR( M-Q, M-Q, M-Q, 0, MAX(1,M-Q), 0, WORK, -1,
00312 $ CHILDINFO )
00313 LORGQRWORKOPT = INT( WORK(1) )
00314 LORGQRWORKMIN = MAX( 1, M - Q )
00315 IORGLQ = ITAUQ2 + MAX( 1, M - Q )
00316 CALL ZUNGLQ( M-Q, M-Q, M-Q, 0, MAX(1,M-Q), 0, WORK, -1,
00317 $ CHILDINFO )
00318 LORGLQWORKOPT = INT( WORK(1) )
00319 LORGLQWORKMIN = MAX( 1, M - Q )
00320 IORBDB = ITAUQ2 + MAX( 1, M - Q )
00321 CALL ZUNBDB( TRANS, SIGNS, M, P, Q, X11, LDX11, X12, LDX12,
00322 $ X21, LDX21, X22, LDX22, 0, 0, 0, 0, 0, 0, WORK,
00323 $ -1, CHILDINFO )
00324 LORBDBWORKOPT = INT( WORK(1) )
00325 LORBDBWORKMIN = LORBDBWORKOPT
00326 LWORKOPT = MAX( IORGQR + LORGQRWORKOPT, IORGLQ + LORGLQWORKOPT,
00327 $ IORBDB + LORBDBWORKOPT ) - 1
00328 LWORKMIN = MAX( IORGQR + LORGQRWORKMIN, IORGLQ + LORGLQWORKMIN,
00329 $ IORBDB + LORBDBWORKMIN ) - 1
00330 WORK(1) = LWORKOPT
00331
00332 IF( LWORK .LT. LWORKMIN
00333 $ .AND. .NOT. ( LQUERY .OR. LRQUERY ) ) THEN
00334 INFO = -22
00335 ELSE IF( LRWORK .LT. LRWORKMIN
00336 $ .AND. .NOT. ( LQUERY .OR. LRQUERY ) ) THEN
00337 INFO = -24
00338 ELSE
00339 LORGQRWORK = LWORK - IORGQR + 1
00340 LORGLQWORK = LWORK - IORGLQ + 1
00341 LORBDBWORK = LWORK - IORBDB + 1
00342 LBBCSDWORK = LRWORK - IBBCSD + 1
00343 END IF
00344 END IF
00345
00346
00347
00348 IF( INFO .NE. 0 ) THEN
00349 CALL XERBLA( 'ZUNCSD', -INFO )
00350 RETURN
00351 ELSE IF( LQUERY .OR. LRQUERY ) THEN
00352 RETURN
00353 END IF
00354
00355
00356
00357 CALL ZUNBDB( TRANS, SIGNS, M, P, Q, X11, LDX11, X12, LDX12, X21,
00358 $ LDX21, X22, LDX22, THETA, RWORK(IPHI), WORK(ITAUP1),
00359 $ WORK(ITAUP2), WORK(ITAUQ1), WORK(ITAUQ2),
00360 $ WORK(IORBDB), LORBDBWORK, CHILDINFO )
00361
00362
00363
00364 IF( COLMAJOR ) THEN
00365 IF( WANTU1 .AND. P .GT. 0 ) THEN
00366 CALL ZLACPY( 'L', P, Q, X11, LDX11, U1, LDU1 )
00367 CALL ZUNGQR( P, P, Q, U1, LDU1, WORK(ITAUP1), WORK(IORGQR),
00368 $ LORGQRWORK, INFO)
00369 END IF
00370 IF( WANTU2 .AND. M-P .GT. 0 ) THEN
00371 CALL ZLACPY( 'L', M-P, Q, X21, LDX21, U2, LDU2 )
00372 CALL ZUNGQR( M-P, M-P, Q, U2, LDU2, WORK(ITAUP2),
00373 $ WORK(IORGQR), LORGQRWORK, INFO )
00374 END IF
00375 IF( WANTV1T .AND. Q .GT. 0 ) THEN
00376 CALL ZLACPY( 'U', Q-1, Q-1, X11(1,2), LDX11, V1T(2,2),
00377 $ LDV1T )
00378 V1T(1, 1) = ONE
00379 DO J = 2, Q
00380 V1T(1,J) = ZERO
00381 V1T(J,1) = ZERO
00382 END DO
00383 CALL ZUNGLQ( Q-1, Q-1, Q-1, V1T(2,2), LDV1T, WORK(ITAUQ1),
00384 $ WORK(IORGLQ), LORGLQWORK, INFO )
00385 END IF
00386 IF( WANTV2T .AND. M-Q .GT. 0 ) THEN
00387 CALL ZLACPY( 'U', P, M-Q, X12, LDX12, V2T, LDV2T )
00388 CALL ZLACPY( 'U', M-P-Q, M-P-Q, X22(Q+1,P+1), LDX22,
00389 $ V2T(P+1,P+1), LDV2T )
00390 CALL ZUNGLQ( M-Q, M-Q, M-Q, V2T, LDV2T, WORK(ITAUQ2),
00391 $ WORK(IORGLQ), LORGLQWORK, INFO )
00392 END IF
00393 ELSE
00394 IF( WANTU1 .AND. P .GT. 0 ) THEN
00395 CALL ZLACPY( 'U', Q, P, X11, LDX11, U1, LDU1 )
00396 CALL ZUNGLQ( P, P, Q, U1, LDU1, WORK(ITAUP1), WORK(IORGLQ),
00397 $ LORGLQWORK, INFO)
00398 END IF
00399 IF( WANTU2 .AND. M-P .GT. 0 ) THEN
00400 CALL ZLACPY( 'U', Q, M-P, X21, LDX21, U2, LDU2 )
00401 CALL ZUNGLQ( M-P, M-P, Q, U2, LDU2, WORK(ITAUP2),
00402 $ WORK(IORGLQ), LORGLQWORK, INFO )
00403 END IF
00404 IF( WANTV1T .AND. Q .GT. 0 ) THEN
00405 CALL ZLACPY( 'L', Q-1, Q-1, X11(2,1), LDX11, V1T(2,2),
00406 $ LDV1T )
00407 V1T(1, 1) = ONE
00408 DO J = 2, Q
00409 V1T(1,J) = ZERO
00410 V1T(J,1) = ZERO
00411 END DO
00412 CALL ZUNGQR( Q-1, Q-1, Q-1, V1T(2,2), LDV1T, WORK(ITAUQ1),
00413 $ WORK(IORGQR), LORGQRWORK, INFO )
00414 END IF
00415 IF( WANTV2T .AND. M-Q .GT. 0 ) THEN
00416 CALL ZLACPY( 'L', M-Q, P, X12, LDX12, V2T, LDV2T )
00417 CALL ZLACPY( 'L', M-P-Q, M-P-Q, X22(P+1,Q+1), LDX22,
00418 $ V2T(P+1,P+1), LDV2T )
00419 CALL ZUNGQR( M-Q, M-Q, M-Q, V2T, LDV2T, WORK(ITAUQ2),
00420 $ WORK(IORGQR), LORGQRWORK, INFO )
00421 END IF
00422 END IF
00423
00424
00425
00426 CALL ZBBCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, M, P, Q, THETA,
00427 $ RWORK(IPHI), U1, LDU1, U2, LDU2, V1T, LDV1T, V2T,
00428 $ LDV2T, RWORK(IB11D), RWORK(IB11E), RWORK(IB12D),
00429 $ RWORK(IB12E), RWORK(IB21D), RWORK(IB21E),
00430 $ RWORK(IB22D), RWORK(IB22E), RWORK(IBBCSD),
00431 $ LBBCSDWORK, INFO )
00432
00433
00434
00435
00436
00437
00438 IF( Q .GT. 0 .AND. WANTU2 ) THEN
00439 DO I = 1, Q
00440 IWORK(I) = M - P - Q + I
00441 END DO
00442 DO I = Q + 1, M - P
00443 IWORK(I) = I - Q
00444 END DO
00445 IF( COLMAJOR ) THEN
00446 CALL ZLAPMT( .FALSE., M-P, M-P, U2, LDU2, IWORK )
00447 ELSE
00448 CALL ZLAPMR( .FALSE., M-P, M-P, U2, LDU2, IWORK )
00449 END IF
00450 END IF
00451 IF( M .GT. 0 .AND. WANTV2T ) THEN
00452 DO I = 1, P
00453 IWORK(I) = M - P - Q + I
00454 END DO
00455 DO I = P + 1, M - Q
00456 IWORK(I) = I - P
00457 END DO
00458 IF( .NOT. COLMAJOR ) THEN
00459 CALL ZLAPMT( .FALSE., M-Q, M-Q, V2T, LDV2T, IWORK )
00460 ELSE
00461 CALL ZLAPMR( .FALSE., M-Q, M-Q, V2T, LDV2T, IWORK )
00462 END IF
00463 END IF
00464
00465 RETURN
00466
00467
00468
00469 END
00470