180 SUBROUTINE cgels( TRANS, M, N, NRHS, A, LDA, B, LDB, WORK, LWORK,
189 INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS
192 COMPLEX A( LDA, * ), B( LDB, * ), WORK( * )
199 parameter( zero = 0.0e+0, one = 1.0e+0 )
201 parameter( czero = ( 0.0e+0, 0.0e+0 ) )
205 INTEGER BROW, I, IASCL, IBSCL, J, MN, NB, SCLLEN, WSIZE
206 REAL ANRM, BIGNUM, BNRM, SMLNUM
215 EXTERNAL lsame, ilaenv, clange, slamch
222 INTRINSIC max, min, real
230 lquery = ( lwork.EQ.-1 )
231 IF( .NOT.( lsame( trans,
'N' ) .OR. lsame( trans,
'C' ) ) )
THEN
233 ELSE IF( m.LT.0 )
THEN
235 ELSE IF( n.LT.0 )
THEN
237 ELSE IF( nrhs.LT.0 )
THEN
239 ELSE IF( lda.LT.max( 1, m ) )
THEN
241 ELSE IF( ldb.LT.max( 1, m, n ) )
THEN
243 ELSE IF( lwork.LT.max( 1, mn+max( mn, nrhs ) ) .AND.
250 IF( info.EQ.0 .OR. info.EQ.-10 )
THEN
253 IF( lsame( trans,
'N' ) )
257 nb = ilaenv( 1,
'CGEQRF',
' ', m, n, -1, -1 )
259 nb = max( nb, ilaenv( 1,
'CUNMQR',
'LN', m, nrhs, n,
262 nb = max( nb, ilaenv( 1,
'CUNMQR',
'LC', m, nrhs, n,
266 nb = ilaenv( 1,
'CGELQF',
' ', m, n, -1, -1 )
268 nb = max( nb, ilaenv( 1,
'CUNMLQ',
'LC', n, nrhs, m,
271 nb = max( nb, ilaenv( 1,
'CUNMLQ',
'LN', n, nrhs, m,
276 wsize = max( 1, mn + max( mn, nrhs )*nb )
277 work( 1 ) = real( wsize )
282 CALL xerbla(
'CGELS ', -info )
284 ELSE IF( lquery )
THEN
290 IF( min( m, n, nrhs ).EQ.0 )
THEN
291 CALL claset(
'Full', max( m, n ), nrhs, czero, czero, b, ldb )
297 smlnum = slamch(
'S' ) / slamch(
'P' )
298 bignum = one / smlnum
302 anrm = clange(
'M', m, n, a, lda, rwork )
304 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
308 CALL clascl(
'G', 0, 0, anrm, smlnum, m, n, a, lda, info )
310 ELSE IF( anrm.GT.bignum )
THEN
314 CALL clascl(
'G', 0, 0, anrm, bignum, m, n, a, lda, info )
316 ELSE IF( anrm.EQ.zero )
THEN
320 CALL claset(
'F', max( m, n ), nrhs, czero, czero, b, ldb )
327 bnrm = clange(
'M', brow, nrhs, b, ldb, rwork )
329 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
333 CALL clascl(
'G', 0, 0, bnrm, smlnum, brow, nrhs, b, ldb,
336 ELSE IF( bnrm.GT.bignum )
THEN
340 CALL clascl(
'G', 0, 0, bnrm, bignum, brow, nrhs, b, ldb,
349 CALL cgeqrf( m, n, a, lda, work( 1 ), work( mn+1 ), lwork-mn,
360 CALL cunmqr(
'Left',
'Conjugate transpose', m, nrhs, n, a,
361 $ lda, work( 1 ), b, ldb, work( mn+1 ), lwork-mn,
368 CALL ctrtrs(
'Upper',
'No transpose',
'Non-unit', n, nrhs,
369 $ a, lda, b, ldb, info )
383 CALL ctrtrs(
'Upper',
'Conjugate transpose',
'Non-unit',
384 $ n, nrhs, a, lda, b, ldb, info )
400 CALL cunmqr(
'Left',
'No transpose', m, nrhs, n, a, lda,
401 $ work( 1 ), b, ldb, work( mn+1 ), lwork-mn,
414 CALL cgelqf( m, n, a, lda, work( 1 ), work( mn+1 ), lwork-mn,
425 CALL ctrtrs(
'Lower',
'No transpose',
'Non-unit', m, nrhs,
426 $ a, lda, b, ldb, info )
442 CALL cunmlq(
'Left',
'Conjugate transpose', n, nrhs, m, a,
443 $ lda, work( 1 ), b, ldb, work( mn+1 ), lwork-mn,
456 CALL cunmlq(
'Left',
'No transpose', n, nrhs, m, a, lda,
457 $ work( 1 ), b, ldb, work( mn+1 ), lwork-mn,
464 CALL ctrtrs(
'Lower',
'Conjugate transpose',
'Non-unit',
465 $ m, nrhs, a, lda, b, ldb, info )
479 IF( iascl.EQ.1 )
THEN
480 CALL clascl(
'G', 0, 0, anrm, smlnum, scllen, nrhs, b, ldb,
482 ELSE IF( iascl.EQ.2 )
THEN
483 CALL clascl(
'G', 0, 0, anrm, bignum, scllen, nrhs, b, ldb,
486 IF( ibscl.EQ.1 )
THEN
487 CALL clascl(
'G', 0, 0, smlnum, bnrm, scllen, nrhs, b, ldb,
489 ELSE IF( ibscl.EQ.2 )
THEN
490 CALL clascl(
'G', 0, 0, bignum, bnrm, scllen, nrhs, b, ldb,
495 work( 1 ) = real( wsize )
subroutine xerbla(srname, info)
subroutine cgelqf(m, n, a, lda, tau, work, lwork, info)
CGELQF
subroutine cgels(trans, m, n, nrhs, a, lda, b, ldb, work, lwork, info)
CGELS solves overdetermined or underdetermined systems for GE matrices
subroutine cgeqrf(m, n, a, lda, tau, work, lwork, info)
CGEQRF
subroutine clascl(type, kl, ku, cfrom, cto, m, n, a, lda, info)
CLASCL multiplies a general rectangular matrix by a real scalar defined as cto/cfrom.
subroutine claset(uplo, m, n, alpha, beta, a, lda)
CLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values.
subroutine ctrtrs(uplo, trans, diag, n, nrhs, a, lda, b, ldb, info)
CTRTRS
subroutine cunmlq(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
CUNMLQ
subroutine cunmqr(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
CUNMQR