222 SUBROUTINE dgegs( JOBVSL, JOBVSR, N, A, LDA, B, LDB, ALPHAR,
223 $ ALPHAI, BETA, VSL, LDVSL, VSR, LDVSR, WORK,
231 CHARACTER JOBVSL, JOBVSR
232 INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LWORK, N
235 DOUBLE PRECISION A( LDA, * ), ALPHAI( * ), ALPHAR( * ),
236 $ B( LDB, * ), BETA( * ), VSL( LDVSL, * ),
237 $ vsr( ldvsr, * ), work( * )
243 DOUBLE PRECISION ZERO, ONE
244 PARAMETER ( ZERO = 0.0d0, one = 1.0d0 )
247 LOGICAL ILASCL, ILBSCL, ILVSL, ILVSR, LQUERY
248 INTEGER ICOLS, IHI, IINFO, IJOBVL, IJOBVR, ILEFT, ILO,
249 $ iright, irows, itau, iwork, lopt, lwkmin,
250 $ lwkopt, nb, nb1, nb2, nb3
251 DOUBLE PRECISION ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS,
261 DOUBLE PRECISION DLAMCH, DLANGE
262 EXTERNAL lsame, ilaenv, dlamch, dlange
271 IF( lsame( jobvsl,
'N' ) )
THEN
274 ELSE IF( lsame( jobvsl,
'V' ) )
THEN
282 IF( lsame( jobvsr,
'N' ) )
THEN
285 ELSE IF( lsame( jobvsr,
'V' ) )
THEN
295 lwkmin = max( 4*n, 1 )
298 lquery = ( lwork.EQ.-1 )
300 IF( ijobvl.LE.0 )
THEN
302 ELSE IF( ijobvr.LE.0 )
THEN
304 ELSE IF( n.LT.0 )
THEN
306 ELSE IF( lda.LT.max( 1, n ) )
THEN
308 ELSE IF( ldb.LT.max( 1, n ) )
THEN
310 ELSE IF( ldvsl.LT.1 .OR. ( ilvsl .AND. ldvsl.LT.n ) )
THEN
312 ELSE IF( ldvsr.LT.1 .OR. ( ilvsr .AND. ldvsr.LT.n ) )
THEN
314 ELSE IF( lwork.LT.lwkmin .AND. .NOT.lquery )
THEN
319 nb1 = ilaenv( 1,
'DGEQRF',
' ', n, n, -1, -1 )
320 nb2 = ilaenv( 1,
'DORMQR',
' ', n, n, n, -1 )
321 nb3 = ilaenv( 1,
'DORGQR',
' ', n, n, n, -1 )
322 nb = max( nb1, nb2, nb3 )
323 lopt = 2*n + n*( nb+1 )
328 CALL xerbla(
'DGEGS ', -info )
330 ELSE IF( lquery )
THEN
341 eps = dlamch(
'E' )*dlamch(
'B' )
342 safmin = dlamch(
'S' )
343 smlnum = n*safmin / eps
344 bignum = one / smlnum
348 anrm = dlange(
'M', n, n, a, lda, work )
350 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
353 ELSE IF( anrm.GT.bignum )
THEN
359 CALL dlascl(
'G', -1, -1, anrm, anrmto, n, n, a, lda,
361 IF( iinfo.NE.0 )
THEN
369 bnrm = dlange(
'M', n, n, b, ldb, work )
371 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
374 ELSE IF( bnrm.GT.bignum )
THEN
380 CALL dlascl(
'G', -1, -1, bnrm, bnrmto, n, n, b, ldb,
382 IF( iinfo.NE.0 )
THEN
395 CALL dggbal(
'P', n, a, lda, b, ldb, ilo, ihi, work( ileft ),
396 $ work( iright ), work( iwork ), iinfo )
397 IF( iinfo.NE.0 )
THEN
406 irows = ihi + 1 - ilo
410 CALL dgeqrf( irows, icols, b( ilo, ilo ), ldb, work( itau ),
411 $ work( iwork ), lwork+1-iwork, iinfo )
413 $ lwkopt = max( lwkopt, int( work( iwork ) )+iwork-1 )
414 IF( iinfo.NE.0 )
THEN
419 CALL dormqr(
'L',
'T', irows, icols, irows, b( ilo, ilo ), ldb,
420 $ work( itau ), a( ilo, ilo ), lda, work( iwork ),
421 $ lwork+1-iwork, iinfo )
423 $ lwkopt = max( lwkopt, int( work( iwork ) )+iwork-1 )
424 IF( iinfo.NE.0 )
THEN
430 CALL dlaset(
'Full', n, n, zero, one, vsl, ldvsl )
431 CALL dlacpy(
'L', irows-1, irows-1, b( ilo+1, ilo ), ldb,
432 $ vsl( ilo+1, ilo ), ldvsl )
433 CALL dorgqr( irows, irows, irows, vsl( ilo, ilo ), ldvsl,
434 $ work( itau ), work( iwork ), lwork+1-iwork,
437 $ lwkopt = max( lwkopt, int( work( iwork ) )+iwork-1 )
438 IF( iinfo.NE.0 )
THEN
445 $
CALL dlaset(
'Full', n, n, zero, one, vsr, ldvsr )
449 CALL dgghrd( jobvsl, jobvsr, n, ilo, ihi, a, lda, b, ldb, vsl,
450 $ ldvsl, vsr, ldvsr, iinfo )
451 IF( iinfo.NE.0 )
THEN
461 CALL dhgeqz(
'S', jobvsl, jobvsr, n, ilo, ihi, a, lda, b, ldb,
462 $ alphar, alphai, beta, vsl, ldvsl, vsr, ldvsr,
463 $ work( iwork ), lwork+1-iwork, iinfo )
465 $ lwkopt = max( lwkopt, int( work( iwork ) )+iwork-1 )
466 IF( iinfo.NE.0 )
THEN
467 IF( iinfo.GT.0 .AND. iinfo.LE.n )
THEN
469 ELSE IF( iinfo.GT.n .AND. iinfo.LE.2*n )
THEN
480 CALL dggbak(
'P',
'L', n, ilo, ihi, work( ileft ),
481 $ work( iright ), n, vsl, ldvsl, iinfo )
482 IF( iinfo.NE.0 )
THEN
488 CALL dggbak(
'P',
'R', n, ilo, ihi, work( ileft ),
489 $ work( iright ), n, vsr, ldvsr, iinfo )
490 IF( iinfo.NE.0 )
THEN
499 CALL dlascl(
'H', -1, -1, anrmto, anrm, n, n, a, lda,
501 IF( iinfo.NE.0 )
THEN
505 CALL dlascl(
'G', -1, -1, anrmto, anrm, n, 1, alphar, n,
507 IF( iinfo.NE.0 )
THEN
511 CALL dlascl(
'G', -1, -1, anrmto, anrm, n, 1, alphai, n,
513 IF( iinfo.NE.0 )
THEN
520 CALL dlascl(
'U', -1, -1, bnrmto, bnrm, n, n, b, ldb,
522 IF( iinfo.NE.0 )
THEN
526 CALL dlascl(
'G', -1, -1, bnrmto, bnrm, n, 1, beta, n,
528 IF( iinfo.NE.0 )
THEN