220 SUBROUTINE zgegs( JOBVSL, JOBVSR, N, A, LDA, B, LDB, ALPHA,
221 $ BETA, VSL, LDVSL, VSR, LDVSR, WORK, LWORK,
229 CHARACTER JOBVSL, JOBVSR
230 INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LWORK, N
233 DOUBLE PRECISION RWORK( * )
234 COMPLEX*16 A( LDA, * ), ALPHA( * ), B( LDB, * ),
235 $ beta( * ), vsl( ldvsl, * ), vsr( ldvsr, * ),
242 DOUBLE PRECISION ZERO, ONE
243 PARAMETER ( ZERO = 0.0d0, one = 1.0d0 )
244 COMPLEX*16 CZERO, CONE
245 parameter( czero = ( 0.0d0, 0.0d0 ),
246 $ cone = ( 1.0d0, 0.0d0 ) )
249 LOGICAL ILASCL, ILBSCL, ILVSL, ILVSR, LQUERY
250 INTEGER ICOLS, IHI, IINFO, IJOBVL, IJOBVR, ILEFT, ILO,
251 $ iright, irows, irwork, itau, iwork, lopt,
252 $ lwkmin, lwkopt, nb, nb1, nb2, nb3
253 DOUBLE PRECISION ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS,
263 DOUBLE PRECISION DLAMCH, ZLANGE
264 EXTERNAL lsame, ilaenv, dlamch, zlange
273 IF( lsame( jobvsl,
'N' ) )
THEN
276 ELSE IF( lsame( jobvsl,
'V' ) )
THEN
284 IF( lsame( jobvsr,
'N' ) )
THEN
287 ELSE IF( lsame( jobvsr,
'V' ) )
THEN
297 lwkmin = max( 2*n, 1 )
300 lquery = ( lwork.EQ.-1 )
302 IF( ijobvl.LE.0 )
THEN
304 ELSE IF( ijobvr.LE.0 )
THEN
306 ELSE IF( n.LT.0 )
THEN
308 ELSE IF( lda.LT.max( 1, n ) )
THEN
310 ELSE IF( ldb.LT.max( 1, n ) )
THEN
312 ELSE IF( ldvsl.LT.1 .OR. ( ilvsl .AND. ldvsl.LT.n ) )
THEN
314 ELSE IF( ldvsr.LT.1 .OR. ( ilvsr .AND. ldvsr.LT.n ) )
THEN
316 ELSE IF( lwork.LT.lwkmin .AND. .NOT.lquery )
THEN
321 nb1 = ilaenv( 1,
'ZGEQRF',
' ', n, n, -1, -1 )
322 nb2 = ilaenv( 1,
'ZUNMQR',
' ', n, n, n, -1 )
323 nb3 = ilaenv( 1,
'ZUNGQR',
' ', n, n, n, -1 )
324 nb = max( nb1, nb2, nb3 )
330 CALL xerbla(
'ZGEGS ', -info )
332 ELSE IF( lquery )
THEN
343 eps = dlamch(
'E' )*dlamch(
'B' )
344 safmin = dlamch(
'S' )
345 smlnum = n*safmin / eps
346 bignum = one / smlnum
350 anrm = zlange(
'M', n, n, a, lda, rwork )
352 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
355 ELSE IF( anrm.GT.bignum )
THEN
361 CALL zlascl(
'G', -1, -1, anrm, anrmto, n, n, a, lda,
363 IF( iinfo.NE.0 )
THEN
371 bnrm = zlange(
'M', n, n, b, ldb, rwork )
373 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
376 ELSE IF( bnrm.GT.bignum )
THEN
382 CALL zlascl(
'G', -1, -1, bnrm, bnrmto, n, n, b, ldb,
384 IF( iinfo.NE.0 )
THEN
396 CALL zggbal(
'P', n, a, lda, b, ldb, ilo, ihi, rwork( ileft ),
397 $ rwork( iright ), rwork( irwork ), iinfo )
398 IF( iinfo.NE.0 )
THEN
405 irows = ihi + 1 - ilo
409 CALL zgeqrf( irows, icols, b( ilo, ilo ), ldb, work( itau ),
410 $ work( iwork ), lwork+1-iwork, iinfo )
412 $ lwkopt = max( lwkopt, int( work( iwork ) )+iwork-1 )
413 IF( iinfo.NE.0 )
THEN
418 CALL zunmqr(
'L',
'C', irows, icols, irows, b( ilo, ilo ), ldb,
419 $ work( itau ), a( ilo, ilo ), lda, work( iwork ),
420 $ lwork+1-iwork, iinfo )
422 $ lwkopt = max( lwkopt, int( work( iwork ) )+iwork-1 )
423 IF( iinfo.NE.0 )
THEN
429 CALL zlaset(
'Full', n, n, czero, cone, vsl, ldvsl )
430 CALL zlacpy(
'L', irows-1, irows-1, b( ilo+1, ilo ), ldb,
431 $ vsl( ilo+1, ilo ), ldvsl )
432 CALL zungqr( irows, irows, irows, vsl( ilo, ilo ), ldvsl,
433 $ work( itau ), work( iwork ), lwork+1-iwork,
436 $ lwkopt = max( lwkopt, int( work( iwork ) )+iwork-1 )
437 IF( iinfo.NE.0 )
THEN
444 $
CALL zlaset(
'Full', n, n, czero, cone, vsr, ldvsr )
448 CALL zgghrd( jobvsl, jobvsr, n, ilo, ihi, a, lda, b, ldb, vsl,
449 $ ldvsl, vsr, ldvsr, iinfo )
450 IF( iinfo.NE.0 )
THEN
458 CALL zhgeqz(
'S', jobvsl, jobvsr, n, ilo, ihi, a, lda, b, ldb,
459 $ alpha, beta, vsl, ldvsl, vsr, ldvsr, work( iwork ),
460 $ lwork+1-iwork, rwork( irwork ), iinfo )
462 $ lwkopt = max( lwkopt, int( work( iwork ) )+iwork-1 )
463 IF( iinfo.NE.0 )
THEN
464 IF( iinfo.GT.0 .AND. iinfo.LE.n )
THEN
466 ELSE IF( iinfo.GT.n .AND. iinfo.LE.2*n )
THEN
477 CALL zggbak(
'P',
'L', n, ilo, ihi, rwork( ileft ),
478 $ rwork( iright ), n, vsl, ldvsl, iinfo )
479 IF( iinfo.NE.0 )
THEN
485 CALL zggbak(
'P',
'R', n, ilo, ihi, rwork( ileft ),
486 $ rwork( iright ), n, vsr, ldvsr, iinfo )
487 IF( iinfo.NE.0 )
THEN
496 CALL zlascl(
'U', -1, -1, anrmto, anrm, n, n, a, lda,
498 IF( iinfo.NE.0 )
THEN
502 CALL zlascl(
'G', -1, -1, anrmto, anrm, n, 1, alpha, n,
504 IF( iinfo.NE.0 )
THEN
511 CALL zlascl(
'U', -1, -1, bnrmto, bnrm, n, n, b, ldb,
513 IF( iinfo.NE.0 )
THEN
517 CALL zlascl(
'G', -1, -1, bnrmto, bnrm, n, 1, beta, n,
519 IF( iinfo.NE.0 )
THEN