00001 SUBROUTINE ZGELSY( M, N, NRHS, A, LDA, B, LDB, JPVT, RCOND, RANK,
00002 $ WORK, LWORK, RWORK, INFO )
00003
00004
00005
00006
00007
00008
00009
00010 INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS, RANK
00011 DOUBLE PRECISION RCOND
00012
00013
00014 INTEGER JPVT( * )
00015 DOUBLE PRECISION RWORK( * )
00016 COMPLEX*16 A( LDA, * ), B( LDB, * ), WORK( * )
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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 INTEGER IMAX, IMIN
00141 PARAMETER ( IMAX = 1, IMIN = 2 )
00142 DOUBLE PRECISION ZERO, ONE
00143 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
00144 COMPLEX*16 CZERO, CONE
00145 PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ),
00146 $ CONE = ( 1.0D+0, 0.0D+0 ) )
00147
00148
00149 LOGICAL LQUERY
00150 INTEGER I, IASCL, IBSCL, ISMAX, ISMIN, J, LWKOPT, MN,
00151 $ NB, NB1, NB2, NB3, NB4
00152 DOUBLE PRECISION ANRM, BIGNUM, BNRM, SMAX, SMAXPR, SMIN, SMINPR,
00153 $ SMLNUM, WSIZE
00154 COMPLEX*16 C1, C2, S1, S2
00155
00156
00157 EXTERNAL DLABAD, XERBLA, ZCOPY, ZGEQP3, ZLAIC1, ZLASCL,
00158 $ ZLASET, ZTRSM, ZTZRZF, ZUNMQR, ZUNMRZ
00159
00160
00161 INTEGER ILAENV
00162 DOUBLE PRECISION DLAMCH, ZLANGE
00163 EXTERNAL ILAENV, DLAMCH, ZLANGE
00164
00165
00166 INTRINSIC ABS, DBLE, DCMPLX, MAX, MIN
00167
00168
00169
00170 MN = MIN( M, N )
00171 ISMIN = MN + 1
00172 ISMAX = 2*MN + 1
00173
00174
00175
00176 INFO = 0
00177 NB1 = ILAENV( 1, 'ZGEQRF', ' ', M, N, -1, -1 )
00178 NB2 = ILAENV( 1, 'ZGERQF', ' ', M, N, -1, -1 )
00179 NB3 = ILAENV( 1, 'ZUNMQR', ' ', M, N, NRHS, -1 )
00180 NB4 = ILAENV( 1, 'ZUNMRQ', ' ', M, N, NRHS, -1 )
00181 NB = MAX( NB1, NB2, NB3, NB4 )
00182 LWKOPT = MAX( 1, MN+2*N+NB*( N+1 ), 2*MN+NB*NRHS )
00183 WORK( 1 ) = DCMPLX( LWKOPT )
00184 LQUERY = ( LWORK.EQ.-1 )
00185 IF( M.LT.0 ) THEN
00186 INFO = -1
00187 ELSE IF( N.LT.0 ) THEN
00188 INFO = -2
00189 ELSE IF( NRHS.LT.0 ) THEN
00190 INFO = -3
00191 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
00192 INFO = -5
00193 ELSE IF( LDB.LT.MAX( 1, M, N ) ) THEN
00194 INFO = -7
00195 ELSE IF( LWORK.LT.( MN+MAX( 2*MN, N+1, MN+NRHS ) ) .AND. .NOT.
00196 $ LQUERY ) THEN
00197 INFO = -12
00198 END IF
00199
00200 IF( INFO.NE.0 ) THEN
00201 CALL XERBLA( 'ZGELSY', -INFO )
00202 RETURN
00203 ELSE IF( LQUERY ) THEN
00204 RETURN
00205 END IF
00206
00207
00208
00209 IF( MIN( M, N, NRHS ).EQ.0 ) THEN
00210 RANK = 0
00211 RETURN
00212 END IF
00213
00214
00215
00216 SMLNUM = DLAMCH( 'S' ) / DLAMCH( 'P' )
00217 BIGNUM = ONE / SMLNUM
00218 CALL DLABAD( SMLNUM, BIGNUM )
00219
00220
00221
00222 ANRM = ZLANGE( 'M', M, N, A, LDA, RWORK )
00223 IASCL = 0
00224 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
00225
00226
00227
00228 CALL ZLASCL( 'G', 0, 0, ANRM, SMLNUM, M, N, A, LDA, INFO )
00229 IASCL = 1
00230 ELSE IF( ANRM.GT.BIGNUM ) THEN
00231
00232
00233
00234 CALL ZLASCL( 'G', 0, 0, ANRM, BIGNUM, M, N, A, LDA, INFO )
00235 IASCL = 2
00236 ELSE IF( ANRM.EQ.ZERO ) THEN
00237
00238
00239
00240 CALL ZLASET( 'F', MAX( M, N ), NRHS, CZERO, CZERO, B, LDB )
00241 RANK = 0
00242 GO TO 70
00243 END IF
00244
00245 BNRM = ZLANGE( 'M', M, NRHS, B, LDB, RWORK )
00246 IBSCL = 0
00247 IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN
00248
00249
00250
00251 CALL ZLASCL( 'G', 0, 0, BNRM, SMLNUM, M, NRHS, B, LDB, INFO )
00252 IBSCL = 1
00253 ELSE IF( BNRM.GT.BIGNUM ) THEN
00254
00255
00256
00257 CALL ZLASCL( 'G', 0, 0, BNRM, BIGNUM, M, NRHS, B, LDB, INFO )
00258 IBSCL = 2
00259 END IF
00260
00261
00262
00263
00264 CALL ZGEQP3( M, N, A, LDA, JPVT, WORK( 1 ), WORK( MN+1 ),
00265 $ LWORK-MN, RWORK, INFO )
00266 WSIZE = MN + DBLE( WORK( MN+1 ) )
00267
00268
00269
00270
00271
00272
00273 WORK( ISMIN ) = CONE
00274 WORK( ISMAX ) = CONE
00275 SMAX = ABS( A( 1, 1 ) )
00276 SMIN = SMAX
00277 IF( ABS( A( 1, 1 ) ).EQ.ZERO ) THEN
00278 RANK = 0
00279 CALL ZLASET( 'F', MAX( M, N ), NRHS, CZERO, CZERO, B, LDB )
00280 GO TO 70
00281 ELSE
00282 RANK = 1
00283 END IF
00284
00285 10 CONTINUE
00286 IF( RANK.LT.MN ) THEN
00287 I = RANK + 1
00288 CALL ZLAIC1( IMIN, RANK, WORK( ISMIN ), SMIN, A( 1, I ),
00289 $ A( I, I ), SMINPR, S1, C1 )
00290 CALL ZLAIC1( IMAX, RANK, WORK( ISMAX ), SMAX, A( 1, I ),
00291 $ A( I, I ), SMAXPR, S2, C2 )
00292
00293 IF( SMAXPR*RCOND.LE.SMINPR ) THEN
00294 DO 20 I = 1, RANK
00295 WORK( ISMIN+I-1 ) = S1*WORK( ISMIN+I-1 )
00296 WORK( ISMAX+I-1 ) = S2*WORK( ISMAX+I-1 )
00297 20 CONTINUE
00298 WORK( ISMIN+RANK ) = C1
00299 WORK( ISMAX+RANK ) = C2
00300 SMIN = SMINPR
00301 SMAX = SMAXPR
00302 RANK = RANK + 1
00303 GO TO 10
00304 END IF
00305 END IF
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 IF( RANK.LT.N )
00316 $ CALL ZTZRZF( RANK, N, A, LDA, WORK( MN+1 ), WORK( 2*MN+1 ),
00317 $ LWORK-2*MN, INFO )
00318
00319
00320
00321
00322
00323
00324 CALL ZUNMQR( 'Left', 'Conjugate transpose', M, NRHS, MN, A, LDA,
00325 $ WORK( 1 ), B, LDB, WORK( 2*MN+1 ), LWORK-2*MN, INFO )
00326 WSIZE = MAX( WSIZE, 2*MN+DBLE( WORK( 2*MN+1 ) ) )
00327
00328
00329
00330
00331
00332 CALL ZTRSM( 'Left', 'Upper', 'No transpose', 'Non-unit', RANK,
00333 $ NRHS, CONE, A, LDA, B, LDB )
00334
00335 DO 40 J = 1, NRHS
00336 DO 30 I = RANK + 1, N
00337 B( I, J ) = CZERO
00338 30 CONTINUE
00339 40 CONTINUE
00340
00341
00342
00343 IF( RANK.LT.N ) THEN
00344 CALL ZUNMRZ( 'Left', 'Conjugate transpose', N, NRHS, RANK,
00345 $ N-RANK, A, LDA, WORK( MN+1 ), B, LDB,
00346 $ WORK( 2*MN+1 ), LWORK-2*MN, INFO )
00347 END IF
00348
00349
00350
00351
00352
00353 DO 60 J = 1, NRHS
00354 DO 50 I = 1, N
00355 WORK( JPVT( I ) ) = B( I, J )
00356 50 CONTINUE
00357 CALL ZCOPY( N, WORK( 1 ), 1, B( 1, J ), 1 )
00358 60 CONTINUE
00359
00360
00361
00362
00363
00364 IF( IASCL.EQ.1 ) THEN
00365 CALL ZLASCL( 'G', 0, 0, ANRM, SMLNUM, N, NRHS, B, LDB, INFO )
00366 CALL ZLASCL( 'U', 0, 0, SMLNUM, ANRM, RANK, RANK, A, LDA,
00367 $ INFO )
00368 ELSE IF( IASCL.EQ.2 ) THEN
00369 CALL ZLASCL( 'G', 0, 0, ANRM, BIGNUM, N, NRHS, B, LDB, INFO )
00370 CALL ZLASCL( 'U', 0, 0, BIGNUM, ANRM, RANK, RANK, A, LDA,
00371 $ INFO )
00372 END IF
00373 IF( IBSCL.EQ.1 ) THEN
00374 CALL ZLASCL( 'G', 0, 0, SMLNUM, BNRM, N, NRHS, B, LDB, INFO )
00375 ELSE IF( IBSCL.EQ.2 ) THEN
00376 CALL ZLASCL( 'G', 0, 0, BIGNUM, BNRM, N, NRHS, B, LDB, INFO )
00377 END IF
00378
00379 70 CONTINUE
00380 WORK( 1 ) = DCMPLX( LWKOPT )
00381
00382 RETURN
00383
00384
00385
00386 END