202 SUBROUTINE dgelsy( M, N, NRHS, A, LDA, B, LDB, JPVT, RCOND,
204 $ WORK, LWORK, INFO )
211 INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS, RANK
212 DOUBLE PRECISION RCOND
216 DOUBLE PRECISION A( LDA, * ), B( LDB, * ), WORK( * )
223 PARAMETER ( IMAX = 1, imin = 2 )
224 DOUBLE PRECISION ZERO, ONE
225 parameter( zero = 0.0d+0, one = 1.0d+0 )
229 INTEGER I, IASCL, IBSCL, ISMAX, ISMIN, J, LWKMIN,
230 $ lwkopt, mn, nb, nb1, nb2, nb3, nb4
231 DOUBLE PRECISION ANRM, BIGNUM, BNRM, C1, C2, S1, S2, SMAX,
232 $ SMAXPR, SMIN, SMINPR, SMLNUM, WSIZE
236 DOUBLE PRECISION DLAMCH, DLANGE
237 EXTERNAL ilaenv, dlamch, dlange
245 INTRINSIC abs, max, min
256 lquery = ( lwork.EQ.-1 )
259 ELSE IF( n.LT.0 )
THEN
261 ELSE IF( nrhs.LT.0 )
THEN
263 ELSE IF( lda.LT.max( 1, m ) )
THEN
265 ELSE IF( ldb.LT.max( 1, m, n ) )
THEN
272 IF( mn.EQ.0 .OR. nrhs.EQ.0 )
THEN
276 nb1 = ilaenv( 1,
'DGEQRF',
' ', m, n, -1, -1 )
277 nb2 = ilaenv( 1,
'DGERQF',
' ', m, n, -1, -1 )
278 nb3 = ilaenv( 1,
'DORMQR',
' ', m, n, nrhs, -1 )
279 nb4 = ilaenv( 1,
'DORMRQ',
' ', m, n, nrhs, -1 )
280 nb = max( nb1, nb2, nb3, nb4 )
281 lwkmin = mn + max( 2*mn, n + 1, mn + nrhs )
282 lwkopt = max( lwkmin,
283 $ mn + 2*n + nb*( n + 1 ), 2*mn + nb*nrhs )
287 IF( lwork.LT.lwkmin .AND. .NOT.lquery )
THEN
293 CALL xerbla(
'DGELSY', -info )
295 ELSE IF( lquery )
THEN
301 IF( mn.EQ.0 .OR. nrhs.EQ.0 )
THEN
308 smlnum = dlamch(
'S' ) / dlamch(
'P' )
309 bignum = one / smlnum
313 anrm = dlange(
'M', m, n, a, lda, work )
315 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
319 CALL dlascl(
'G', 0, 0, anrm, smlnum, m, n, a, lda, info )
321 ELSE IF( anrm.GT.bignum )
THEN
325 CALL dlascl(
'G', 0, 0, anrm, bignum, m, n, a, lda, info )
327 ELSE IF( anrm.EQ.zero )
THEN
331 CALL dlaset(
'F', max( m, n ), nrhs, zero, zero, b, ldb )
336 bnrm = dlange(
'M', m, nrhs, b, ldb, work )
338 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
342 CALL dlascl(
'G', 0, 0, bnrm, smlnum, m, nrhs, b, ldb,
345 ELSE IF( bnrm.GT.bignum )
THEN
349 CALL dlascl(
'G', 0, 0, bnrm, bignum, m, nrhs, b, ldb,
357 CALL dgeqp3( m, n, a, lda, jpvt, work( 1 ), work( mn+1 ),
359 wsize = mn + work( mn+1 )
368 smax = abs( a( 1, 1 ) )
370 IF( abs( a( 1, 1 ) ).EQ.zero )
THEN
372 CALL dlaset(
'F', max( m, n ), nrhs, zero, zero, b, ldb )
379 IF( rank.LT.mn )
THEN
381 CALL dlaic1( imin, rank, work( ismin ), smin, a( 1, i ),
382 $ a( i, i ), sminpr, s1, c1 )
383 CALL dlaic1( imax, rank, work( ismax ), smax, a( 1, i ),
384 $ a( i, i ), smaxpr, s2, c2 )
386 IF( smaxpr*rcond.LE.sminpr )
THEN
388 work( ismin+i-1 ) = s1*work( ismin+i-1 )
389 work( ismax+i-1 ) = s2*work( ismax+i-1 )
391 work( ismin+rank ) = c1
392 work( ismax+rank ) = c2
409 $
CALL dtzrzf( rank, n, a, lda, work( mn+1 ), work( 2*mn+1 ),
417 CALL dormqr(
'Left',
'Transpose', m, nrhs, mn, a, lda,
419 $ b, ldb, work( 2*mn+1 ), lwork-2*mn, info )
420 wsize = max( wsize, 2*mn+work( 2*mn+1 ) )
426 CALL dtrsm(
'Left',
'Upper',
'No transpose',
'Non-unit', rank,
427 $ nrhs, one, a, lda, b, ldb )
430 DO 30 i = rank + 1, n
438 CALL dormrz(
'Left',
'Transpose', n, nrhs, rank, n-rank, a,
439 $ lda, work( mn+1 ), b, ldb, work( 2*mn+1 ),
449 work( jpvt( i ) ) = b( i, j )
451 CALL dcopy( n, work( 1 ), 1, b( 1, j ), 1 )
458 IF( iascl.EQ.1 )
THEN
459 CALL dlascl(
'G', 0, 0, anrm, smlnum, n, nrhs, b, ldb,
461 CALL dlascl(
'U', 0, 0, smlnum, anrm, rank, rank, a, lda,
463 ELSE IF( iascl.EQ.2 )
THEN
464 CALL dlascl(
'G', 0, 0, anrm, bignum, n, nrhs, b, ldb,
466 CALL dlascl(
'U', 0, 0, bignum, anrm, rank, rank, a, lda,
469 IF( ibscl.EQ.1 )
THEN
470 CALL dlascl(
'G', 0, 0, smlnum, bnrm, n, nrhs, b, ldb,
472 ELSE IF( ibscl.EQ.2 )
THEN
473 CALL dlascl(
'G', 0, 0, bignum, bnrm, n, nrhs, b, ldb,