199 SUBROUTINE cgelst( TRANS, M, N, NRHS, A, LDA, B, LDB, WORK,
209 INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS
212 COMPLEX A( LDA, * ), B( LDB, * ), WORK( * )
219 PARAMETER ( ZERO = 0.0e+0, one = 1.0e+0 )
221 parameter( czero = ( 0.0e+0, 0.0e+0 ) )
225 INTEGER BROW, I, IASCL, IBSCL, J, LWOPT, MN, MNNRHS,
227 REAL ANRM, BIGNUM, BNRM, SMLNUM
235 REAL SLAMCH, CLANGE, SROUNDUP_LWORK
236 EXTERNAL lsame, ilaenv, slamch, clange,
252 lquery = ( lwork.EQ.-1 )
253 IF( .NOT.( lsame( trans,
'N' ) .OR.
254 $ lsame( trans,
'C' ) ) )
THEN
256 ELSE IF( m.LT.0 )
THEN
258 ELSE IF( n.LT.0 )
THEN
260 ELSE IF( nrhs.LT.0 )
THEN
262 ELSE IF( lda.LT.max( 1, m ) )
THEN
264 ELSE IF( ldb.LT.max( 1, m, n ) )
THEN
266 ELSE IF( lwork.LT.max( 1, mn+max( mn, nrhs ) ) .AND. .NOT.lquery )
273 IF( info.EQ.0 .OR. info.EQ.-10 )
THEN
276 IF( lsame( trans,
'N' ) )
279 nb = ilaenv( 1,
'CGELST',
' ', m, n, -1, -1 )
281 mnnrhs = max( mn, nrhs )
282 lwopt = max( 1, (mn+mnnrhs)*nb )
283 work( 1 ) = sroundup_lwork( lwopt )
288 CALL xerbla(
'CGELST ', -info )
290 ELSE IF( lquery )
THEN
296 IF( min( m, n, nrhs ).EQ.0 )
THEN
297 CALL claset(
'Full', max( m, n ), nrhs, czero, czero,
299 work( 1 ) = sroundup_lwork( lwopt )
305 IF( nb.GT.mn ) nb = mn
311 nb = min( nb, lwork/( mn + mnnrhs ) )
315 nbmin = max( 2, ilaenv( 2,
'CGELST',
' ', m, n, -1, -1 ) )
317 IF( nb.LT.nbmin )
THEN
323 smlnum = slamch(
'S' ) / slamch(
'P' )
324 bignum = one / smlnum
328 anrm = clange(
'M', m, n, a, lda, rwork )
330 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
334 CALL clascl(
'G', 0, 0, anrm, smlnum, m, n, a, lda, info )
336 ELSE IF( anrm.GT.bignum )
THEN
340 CALL clascl(
'G', 0, 0, anrm, bignum, m, n, a, lda, info )
342 ELSE IF( anrm.EQ.zero )
THEN
346 CALL claset(
'Full', max( m, n ), nrhs, czero, czero,
348 work( 1 ) = sroundup_lwork( lwopt )
355 bnrm = clange(
'M', brow, nrhs, b, ldb, rwork )
357 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
361 CALL clascl(
'G', 0, 0, bnrm, smlnum, brow, nrhs, b, ldb,
364 ELSE IF( bnrm.GT.bignum )
THEN
368 CALL clascl(
'G', 0, 0, bnrm, bignum, brow, nrhs, b, ldb,
380 CALL cgeqrt( m, n, nb, a, lda, work( 1 ), nb,
381 $ work( mn*nb+1 ), info )
393 CALL cgemqrt(
'Left',
'Conjugate transpose', m, nrhs, n,
395 $ a, lda, work( 1 ), nb, b, ldb,
396 $ work( mn*nb+1 ), info )
400 CALL ctrtrs(
'Upper',
'No transpose',
'Non-unit', n,
402 $ a, lda, b, ldb, info )
420 CALL ctrtrs(
'Upper',
'Conjugate transpose',
'Non-unit',
421 $ n, nrhs, a, lda, b, ldb, info )
440 CALL cgemqrt(
'Left',
'No transpose', m, nrhs, n, nb,
441 $ a, lda, work( 1 ), nb, b, ldb,
442 $ work( mn*nb+1 ), info )
455 CALL cgelqt( m, n, nb, a, lda, work( 1 ), nb,
456 $ work( mn*nb+1 ), info )
468 CALL ctrtrs(
'Lower',
'No transpose',
'Non-unit', m,
470 $ a, lda, b, ldb, info )
489 CALL cgemlqt(
'Left',
'Conjugate transpose', n, nrhs, m,
491 $ a, lda, work( 1 ), nb, b, ldb,
492 $ work( mn*nb+1 ), info )
506 CALL cgemlqt(
'Left',
'No transpose', n, nrhs, m, nb,
507 $ a, lda, work( 1 ), nb, b, ldb,
508 $ work( mn*nb+1), info )
512 CALL ctrtrs(
'Lower',
'Conjugate transpose',
'Non-unit',
513 $ m, nrhs, a, lda, b, ldb, info )
527 IF( iascl.EQ.1 )
THEN
528 CALL clascl(
'G', 0, 0, anrm, smlnum, scllen, nrhs, b, ldb,
530 ELSE IF( iascl.EQ.2 )
THEN
531 CALL clascl(
'G', 0, 0, anrm, bignum, scllen, nrhs, b, ldb,
534 IF( ibscl.EQ.1 )
THEN
535 CALL clascl(
'G', 0, 0, smlnum, bnrm, scllen, nrhs, b, ldb,
537 ELSE IF( ibscl.EQ.2 )
THEN
538 CALL clascl(
'G', 0, 0, bignum, bnrm, scllen, nrhs, b, ldb,
542 work( 1 ) = sroundup_lwork( lwopt )