178 SUBROUTINE dgelsx( M, N, NRHS, A, LDA, B, LDB, JPVT, RCOND, RANK,
187 INTEGER info, lda, ldb, m, n, nrhs, rank
188 DOUBLE PRECISION rcond
192 DOUBLE PRECISION a( lda, * ), b( ldb, * ), work( * )
199 parameter( imax = 1, imin = 2 )
200 DOUBLE PRECISION zero, one, done, ntdone
201 parameter( zero = 0.0d0, one = 1.0d0, done = zero,
205 INTEGER i, iascl, ibscl, ismax, ismin, j, k, mn
206 DOUBLE PRECISION anrm, bignum, bnrm, c1, c2, s1, s2, smax,
207 $ smaxpr, smin, sminpr, smlnum, t1, t2
218 INTRINSIC abs, max, min
231 ELSE IF( n.LT.0 )
THEN
233 ELSE IF( nrhs.LT.0 )
THEN
235 ELSE IF( lda.LT.max( 1, m ) )
THEN
237 ELSE IF( ldb.LT.max( 1, m, n ) )
THEN
242 CALL
xerbla(
'DGELSX', -info )
248 IF( min( m, n, nrhs ).EQ.0 )
THEN
256 bignum = one / smlnum
257 CALL
dlabad( smlnum, bignum )
261 anrm =
dlange(
'M', m, n, a, lda, work )
263 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
267 CALL
dlascl(
'G', 0, 0, anrm, smlnum, m, n, a, lda, info )
269 ELSE IF( anrm.GT.bignum )
THEN
273 CALL
dlascl(
'G', 0, 0, anrm, bignum, m, n, a, lda, info )
275 ELSE IF( anrm.EQ.zero )
THEN
279 CALL
dlaset(
'F', max( m, n ), nrhs, zero, zero, b, ldb )
284 bnrm =
dlange(
'M', m, nrhs, b, ldb, work )
286 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
290 CALL
dlascl(
'G', 0, 0, bnrm, smlnum, m, nrhs, b, ldb, info )
292 ELSE IF( bnrm.GT.bignum )
THEN
296 CALL
dlascl(
'G', 0, 0, bnrm, bignum, m, nrhs, b, ldb, info )
303 CALL
dgeqpf( m, n, a, lda, jpvt, work( 1 ), work( mn+1 ), info )
312 smax = abs( a( 1, 1 ) )
314 IF( abs( a( 1, 1 ) ).EQ.zero )
THEN
316 CALL
dlaset(
'F', max( m, n ), nrhs, zero, zero, b, ldb )
323 IF( rank.LT.mn )
THEN
325 CALL
dlaic1( imin, rank, work( ismin ), smin, a( 1, i ),
326 $ a( i, i ), sminpr, s1, c1 )
327 CALL
dlaic1( imax, rank, work( ismax ), smax, a( 1, i ),
328 $ a( i, i ), smaxpr, s2, c2 )
330 IF( smaxpr*rcond.LE.sminpr )
THEN
332 work( ismin+i-1 ) = s1*work( ismin+i-1 )
333 work( ismax+i-1 ) = s2*work( ismax+i-1 )
335 work( ismin+rank ) = c1
336 work( ismax+rank ) = c2
351 $ CALL
dtzrqf( rank, n, a, lda, work( mn+1 ), info )
357 CALL
dorm2r(
'Left',
'Transpose', m, nrhs, mn, a, lda, work( 1 ),
358 $ b, ldb, work( 2*mn+1 ), info )
364 CALL
dtrsm(
'Left',
'Upper',
'No transpose',
'Non-unit', rank,
365 $ nrhs, one, a, lda, b, ldb )
367 DO 40 i = rank + 1, n
377 CALL
dlatzm(
'Left', n-rank+1, nrhs, a( i, rank+1 ), lda,
378 $ work( mn+i ), b( i, 1 ), b( rank+1, 1 ), ldb,
389 work( 2*mn+i ) = ntdone
392 IF( work( 2*mn+i ).EQ.ntdone )
THEN
393 IF( jpvt( i ).NE.i )
THEN
396 t2 = b( jpvt( k ), j )
398 b( jpvt( k ), j ) = t1
399 work( 2*mn+k ) = done
402 t2 = b( jpvt( k ), j )
406 work( 2*mn+k ) = done
414 IF( iascl.EQ.1 )
THEN
415 CALL
dlascl(
'G', 0, 0, anrm, smlnum, n, nrhs, b, ldb, info )
416 CALL
dlascl(
'U', 0, 0, smlnum, anrm, rank, rank, a, lda,
418 ELSE IF( iascl.EQ.2 )
THEN
419 CALL
dlascl(
'G', 0, 0, anrm, bignum, n, nrhs, b, ldb, info )
420 CALL
dlascl(
'U', 0, 0, bignum, anrm, rank, rank, a, lda,
423 IF( ibscl.EQ.1 )
THEN
424 CALL
dlascl(
'G', 0, 0, smlnum, bnrm, n, nrhs, b, ldb, info )
425 ELSE IF( ibscl.EQ.2 )
THEN
426 CALL
dlascl(
'G', 0, 0, bignum, bnrm, n, nrhs, b, ldb, info )