169 SUBROUTINE zgetsls( TRANS, M, N, NRHS, A, LDA, B, LDB,
170 $ WORK, LWORK, INFO )
178 INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS
181 COMPLEX*16 A( LDA, * ), B( LDB, * ), WORK( * )
188 DOUBLE PRECISION ZERO, ONE
189 parameter( zero = 0.0d0, one = 1.0d0 )
191 parameter( czero = ( 0.0d+0, 0.0d+0 ) )
195 INTEGER I, IASCL, IBSCL, J, MAXMN, BROW,
196 $ scllen, tszo, tszm, lwo, lwm, lw1, lw2,
197 $ wsizeo, wsizem, info2
198 DOUBLE PRECISION ANRM, BIGNUM, BNRM, SMLNUM, DUM( 1 )
199 COMPLEX*16 TQ( 5 ), WORKQ( 1 )
203 DOUBLE PRECISION DLAMCH, ZLANGE
204 EXTERNAL lsame, dlamch, zlange
211 INTRINSIC dble, max, min, int
219 tran = lsame( trans,
'C' )
221 lquery = ( lwork.EQ.-1 .OR. lwork.EQ.-2 )
222 IF( .NOT.( lsame( trans,
'N' ) .OR.
223 $ lsame( trans,
'C' ) ) )
THEN
225 ELSE IF( m.LT.0 )
THEN
227 ELSE IF( n.LT.0 )
THEN
229 ELSE IF( nrhs.LT.0 )
THEN
231 ELSE IF( lda.LT.max( 1, m ) )
THEN
233 ELSE IF( ldb.LT.max( 1, m, n ) )
THEN
241 IF( min( m, n, nrhs ).EQ.0 )
THEN
244 ELSE IF( m.GE.n )
THEN
245 CALL zgeqr( m, n, a, lda, tq, -1, workq, -1, info2 )
246 tszo = int( tq( 1 ) )
247 lwo = int( workq( 1 ) )
248 CALL zgemqr(
'L', trans, m, nrhs, n, a, lda, tq,
249 $ tszo, b, ldb, workq, -1, info2 )
250 lwo = max( lwo, int( workq( 1 ) ) )
251 CALL zgeqr( m, n, a, lda, tq, -2, workq, -2, info2 )
252 tszm = int( tq( 1 ) )
253 lwm = int( workq( 1 ) )
254 CALL zgemqr(
'L', trans, m, nrhs, n, a, lda, tq,
255 $ tszm, b, ldb, workq, -1, info2 )
256 lwm = max( lwm, int( workq( 1 ) ) )
260 CALL zgelq( m, n, a, lda, tq, -1, workq, -1, info2 )
261 tszo = int( tq( 1 ) )
262 lwo = int( workq( 1 ) )
263 CALL zgemlq(
'L', trans, n, nrhs, m, a, lda, tq,
264 $ tszo, b, ldb, workq, -1, info2 )
265 lwo = max( lwo, int( workq( 1 ) ) )
266 CALL zgelq( m, n, a, lda, tq, -2, workq, -2, info2 )
267 tszm = int( tq( 1 ) )
268 lwm = int( workq( 1 ) )
269 CALL zgemlq(
'L', trans, n, nrhs, m, a, lda, tq,
270 $ tszm, b, ldb, workq, -1, info2 )
271 lwm = max( lwm, int( workq( 1 ) ) )
276 IF( ( lwork.LT.wsizem ).AND.( .NOT.lquery ) )
THEN
280 work( 1 ) = dble( wsizeo )
285 CALL xerbla(
'ZGETSLS', -info )
289 IF( lwork.EQ.-2 ) work( 1 ) = dble( wsizem )
292 IF( lwork.LT.wsizeo )
THEN
302 IF( min( m, n, nrhs ).EQ.0 )
THEN
303 CALL zlaset(
'FULL', max( m, n ), nrhs, czero, czero,
310 smlnum = dlamch(
'S' ) / dlamch(
'P' )
311 bignum = one / smlnum
315 anrm = zlange(
'M', m, n, a, lda, dum )
317 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
321 CALL zlascl(
'G', 0, 0, anrm, smlnum, m, n, a, lda, info )
323 ELSE IF( anrm.GT.bignum )
THEN
327 CALL zlascl(
'G', 0, 0, anrm, bignum, m, n, a, lda, info )
329 ELSE IF( anrm.EQ.zero )
THEN
333 CALL zlaset(
'F', maxmn, nrhs, czero, czero, b, ldb )
341 bnrm = zlange(
'M', brow, nrhs, b, ldb, dum )
343 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
347 CALL zlascl(
'G', 0, 0, bnrm, smlnum, brow, nrhs, b, ldb,
350 ELSE IF( bnrm.GT.bignum )
THEN
354 CALL zlascl(
'G', 0, 0, bnrm, bignum, brow, nrhs, b, ldb,
363 CALL zgeqr( m, n, a, lda, work( lw2+1 ), lw1,
364 $ work( 1 ), lw2, info )
365 IF ( .NOT.tran )
THEN
371 CALL zgemqr(
'L' ,
'C', m, nrhs, n, a, lda,
372 $ work( lw2+1 ), lw1, b, ldb, work( 1 ), lw2,
377 CALL ztrtrs(
'U',
'N',
'N', n, nrhs,
378 $ a, lda, b, ldb, info )
389 CALL ztrtrs(
'U',
'C',
'N', n, nrhs,
390 $ a, lda, b, ldb, info )
406 CALL zgemqr(
'L',
'N', m, nrhs, n, a, lda,
407 $ work( lw2+1 ), lw1, b, ldb, work( 1 ), lw2,
418 CALL zgelq( m, n, a, lda, work( lw2+1 ), lw1,
419 $ work( 1 ), lw2, info )
429 CALL ztrtrs(
'L',
'N',
'N', m, nrhs,
430 $ a, lda, b, ldb, info )
446 CALL zgemlq(
'L',
'C', n, nrhs, m, a, lda,
447 $ work( lw2+1 ), lw1, b, ldb, work( 1 ), lw2,
460 CALL zgemlq(
'L',
'N', n, nrhs, m, a, lda,
461 $ work( lw2+1 ), lw1, b, ldb, work( 1 ), lw2,
468 CALL ztrtrs(
'L',
'C',
'N', m, nrhs,
469 $ a, lda, b, ldb, info )
483 IF( iascl.EQ.1 )
THEN
484 CALL zlascl(
'G', 0, 0, anrm, smlnum, scllen, nrhs, b, ldb,
486 ELSE IF( iascl.EQ.2 )
THEN
487 CALL zlascl(
'G', 0, 0, anrm, bignum, scllen, nrhs, b, ldb,
490 IF( ibscl.EQ.1 )
THEN
491 CALL zlascl(
'G', 0, 0, smlnum, bnrm, scllen, nrhs, b, ldb,
493 ELSE IF( ibscl.EQ.2 )
THEN
494 CALL zlascl(
'G', 0, 0, bignum, bnrm, scllen, nrhs, b, ldb,
499 work( 1 ) = dble( tszo + lwo )