00001 SUBROUTINE CGELS( TRANS, M, N, NRHS, A, LDA, B, LDB, WORK, LWORK,
00002 $ INFO )
00003
00004
00005
00006
00007
00008
00009
00010 CHARACTER TRANS
00011 INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS
00012
00013
00014 COMPLEX A( LDA, * ), B( LDB, * ), WORK( * )
00015
00016
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 REAL ZERO, ONE
00121 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
00122 COMPLEX CZERO
00123 PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ) )
00124
00125
00126 LOGICAL LQUERY, TPSD
00127 INTEGER BROW, I, IASCL, IBSCL, J, MN, NB, SCLLEN, WSIZE
00128 REAL ANRM, BIGNUM, BNRM, SMLNUM
00129
00130
00131 REAL RWORK( 1 )
00132
00133
00134 LOGICAL LSAME
00135 INTEGER ILAENV
00136 REAL CLANGE, SLAMCH
00137 EXTERNAL LSAME, ILAENV, CLANGE, SLAMCH
00138
00139
00140 EXTERNAL CGELQF, CGEQRF, CLASCL, CLASET, CTRTRS, CUNMLQ,
00141 $ CUNMQR, SLABAD, XERBLA
00142
00143
00144 INTRINSIC MAX, MIN, REAL
00145
00146
00147
00148
00149
00150 INFO = 0
00151 MN = MIN( M, N )
00152 LQUERY = ( LWORK.EQ.-1 )
00153 IF( .NOT.( LSAME( TRANS, 'N' ) .OR. LSAME( TRANS, 'C' ) ) ) THEN
00154 INFO = -1
00155 ELSE IF( M.LT.0 ) THEN
00156 INFO = -2
00157 ELSE IF( N.LT.0 ) THEN
00158 INFO = -3
00159 ELSE IF( NRHS.LT.0 ) THEN
00160 INFO = -4
00161 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
00162 INFO = -6
00163 ELSE IF( LDB.LT.MAX( 1, M, N ) ) THEN
00164 INFO = -8
00165 ELSE IF( LWORK.LT.MAX( 1, MN+MAX( MN, NRHS ) ) .AND.
00166 $ .NOT.LQUERY ) THEN
00167 INFO = -10
00168 END IF
00169
00170
00171
00172 IF( INFO.EQ.0 .OR. INFO.EQ.-10 ) THEN
00173
00174 TPSD = .TRUE.
00175 IF( LSAME( TRANS, 'N' ) )
00176 $ TPSD = .FALSE.
00177
00178 IF( M.GE.N ) THEN
00179 NB = ILAENV( 1, 'CGEQRF', ' ', M, N, -1, -1 )
00180 IF( TPSD ) THEN
00181 NB = MAX( NB, ILAENV( 1, 'CUNMQR', 'LN', M, NRHS, N,
00182 $ -1 ) )
00183 ELSE
00184 NB = MAX( NB, ILAENV( 1, 'CUNMQR', 'LC', M, NRHS, N,
00185 $ -1 ) )
00186 END IF
00187 ELSE
00188 NB = ILAENV( 1, 'CGELQF', ' ', M, N, -1, -1 )
00189 IF( TPSD ) THEN
00190 NB = MAX( NB, ILAENV( 1, 'CUNMLQ', 'LC', N, NRHS, M,
00191 $ -1 ) )
00192 ELSE
00193 NB = MAX( NB, ILAENV( 1, 'CUNMLQ', 'LN', N, NRHS, M,
00194 $ -1 ) )
00195 END IF
00196 END IF
00197
00198 WSIZE = MAX( 1, MN + MAX( MN, NRHS )*NB )
00199 WORK( 1 ) = REAL( WSIZE )
00200
00201 END IF
00202
00203 IF( INFO.NE.0 ) THEN
00204 CALL XERBLA( 'CGELS ', -INFO )
00205 RETURN
00206 ELSE IF( LQUERY ) THEN
00207 RETURN
00208 END IF
00209
00210
00211
00212 IF( MIN( M, N, NRHS ).EQ.0 ) THEN
00213 CALL CLASET( 'Full', MAX( M, N ), NRHS, CZERO, CZERO, B, LDB )
00214 RETURN
00215 END IF
00216
00217
00218
00219 SMLNUM = SLAMCH( 'S' ) / SLAMCH( 'P' )
00220 BIGNUM = ONE / SMLNUM
00221 CALL SLABAD( SMLNUM, BIGNUM )
00222
00223
00224
00225 ANRM = CLANGE( 'M', M, N, A, LDA, RWORK )
00226 IASCL = 0
00227 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
00228
00229
00230
00231 CALL CLASCL( 'G', 0, 0, ANRM, SMLNUM, M, N, A, LDA, INFO )
00232 IASCL = 1
00233 ELSE IF( ANRM.GT.BIGNUM ) THEN
00234
00235
00236
00237 CALL CLASCL( 'G', 0, 0, ANRM, BIGNUM, M, N, A, LDA, INFO )
00238 IASCL = 2
00239 ELSE IF( ANRM.EQ.ZERO ) THEN
00240
00241
00242
00243 CALL CLASET( 'F', MAX( M, N ), NRHS, CZERO, CZERO, B, LDB )
00244 GO TO 50
00245 END IF
00246
00247 BROW = M
00248 IF( TPSD )
00249 $ BROW = N
00250 BNRM = CLANGE( 'M', BROW, NRHS, B, LDB, RWORK )
00251 IBSCL = 0
00252 IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN
00253
00254
00255
00256 CALL CLASCL( 'G', 0, 0, BNRM, SMLNUM, BROW, NRHS, B, LDB,
00257 $ INFO )
00258 IBSCL = 1
00259 ELSE IF( BNRM.GT.BIGNUM ) THEN
00260
00261
00262
00263 CALL CLASCL( 'G', 0, 0, BNRM, BIGNUM, BROW, NRHS, B, LDB,
00264 $ INFO )
00265 IBSCL = 2
00266 END IF
00267
00268 IF( M.GE.N ) THEN
00269
00270
00271
00272 CALL CGEQRF( M, N, A, LDA, WORK( 1 ), WORK( MN+1 ), LWORK-MN,
00273 $ INFO )
00274
00275
00276
00277 IF( .NOT.TPSD ) THEN
00278
00279
00280
00281
00282
00283 CALL CUNMQR( 'Left', 'Conjugate transpose', M, NRHS, N, A,
00284 $ LDA, WORK( 1 ), B, LDB, WORK( MN+1 ), LWORK-MN,
00285 $ INFO )
00286
00287
00288
00289
00290
00291 CALL CTRTRS( 'Upper', 'No transpose', 'Non-unit', N, NRHS,
00292 $ A, LDA, B, LDB, INFO )
00293
00294 IF( INFO.GT.0 ) THEN
00295 RETURN
00296 END IF
00297
00298 SCLLEN = N
00299
00300 ELSE
00301
00302
00303
00304
00305
00306 CALL CTRTRS( 'Upper', 'Conjugate transpose','Non-unit',
00307 $ N, NRHS, A, LDA, B, LDB, INFO )
00308
00309 IF( INFO.GT.0 ) THEN
00310 RETURN
00311 END IF
00312
00313
00314
00315 DO 20 J = 1, NRHS
00316 DO 10 I = N + 1, M
00317 B( I, J ) = CZERO
00318 10 CONTINUE
00319 20 CONTINUE
00320
00321
00322
00323 CALL CUNMQR( 'Left', 'No transpose', M, NRHS, N, A, LDA,
00324 $ WORK( 1 ), B, LDB, WORK( MN+1 ), LWORK-MN,
00325 $ INFO )
00326
00327
00328
00329 SCLLEN = M
00330
00331 END IF
00332
00333 ELSE
00334
00335
00336
00337 CALL CGELQF( M, N, A, LDA, WORK( 1 ), WORK( MN+1 ), LWORK-MN,
00338 $ INFO )
00339
00340
00341
00342 IF( .NOT.TPSD ) THEN
00343
00344
00345
00346
00347
00348 CALL CTRTRS( 'Lower', 'No transpose', 'Non-unit', M, NRHS,
00349 $ A, LDA, B, LDB, INFO )
00350
00351 IF( INFO.GT.0 ) THEN
00352 RETURN
00353 END IF
00354
00355
00356
00357 DO 40 J = 1, NRHS
00358 DO 30 I = M + 1, N
00359 B( I, J ) = CZERO
00360 30 CONTINUE
00361 40 CONTINUE
00362
00363
00364
00365 CALL CUNMLQ( 'Left', 'Conjugate transpose', N, NRHS, M, A,
00366 $ LDA, WORK( 1 ), B, LDB, WORK( MN+1 ), LWORK-MN,
00367 $ INFO )
00368
00369
00370
00371 SCLLEN = N
00372
00373 ELSE
00374
00375
00376
00377
00378
00379 CALL CUNMLQ( 'Left', 'No transpose', N, NRHS, M, A, LDA,
00380 $ WORK( 1 ), B, LDB, WORK( MN+1 ), LWORK-MN,
00381 $ INFO )
00382
00383
00384
00385
00386
00387 CALL CTRTRS( 'Lower', 'Conjugate transpose', 'Non-unit',
00388 $ M, NRHS, A, LDA, B, LDB, INFO )
00389
00390 IF( INFO.GT.0 ) THEN
00391 RETURN
00392 END IF
00393
00394 SCLLEN = M
00395
00396 END IF
00397
00398 END IF
00399
00400
00401
00402 IF( IASCL.EQ.1 ) THEN
00403 CALL CLASCL( 'G', 0, 0, ANRM, SMLNUM, SCLLEN, NRHS, B, LDB,
00404 $ INFO )
00405 ELSE IF( IASCL.EQ.2 ) THEN
00406 CALL CLASCL( 'G', 0, 0, ANRM, BIGNUM, SCLLEN, NRHS, B, LDB,
00407 $ INFO )
00408 END IF
00409 IF( IBSCL.EQ.1 ) THEN
00410 CALL CLASCL( 'G', 0, 0, SMLNUM, BNRM, SCLLEN, NRHS, B, LDB,
00411 $ INFO )
00412 ELSE IF( IBSCL.EQ.2 ) THEN
00413 CALL CLASCL( 'G', 0, 0, BIGNUM, BNRM, SCLLEN, NRHS, B, LDB,
00414 $ INFO )
00415 END IF
00416
00417 50 CONTINUE
00418 WORK( 1 ) = REAL( WSIZE )
00419
00420 RETURN
00421
00422
00423
00424 END