213 SUBROUTINE cggev( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHA, BETA,
214 $ VL, LDVL, VR, LDVR, WORK, LWORK, RWORK, INFO )
221 CHARACTER JOBVL, JOBVR
222 INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N
226 COMPLEX A( LDA, * ), ALPHA( * ), B( LDB, * ),
227 $ beta( * ), vl( ldvl, * ), vr( ldvr, * ),
235 parameter( zero = 0.0e0, one = 1.0e0 )
237 parameter( czero = ( 0.0e0, 0.0e0 ),
238 $ cone = ( 1.0e0, 0.0e0 ) )
241 LOGICAL ILASCL, ILBSCL, ILV, ILVL, ILVR, LQUERY
243 INTEGER ICOLS, IERR, IHI, IJOBVL, IJOBVR, ILEFT, ILO,
244 $ in, iright, irows, irwrk, itau, iwrk, jc, jr,
246 REAL ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS,
261 REAL CLANGE, SLAMCH, SROUNDUP_LWORK
262 EXTERNAL lsame, ilaenv, clange, slamch,
266 INTRINSIC abs, aimag, max, real, sqrt
272 abs1( x ) = abs( real( x ) ) + abs( aimag( x ) )
278 IF( lsame( jobvl,
'N' ) )
THEN
281 ELSE IF( lsame( jobvl,
'V' ) )
THEN
289 IF( lsame( jobvr,
'N' ) )
THEN
292 ELSE IF( lsame( jobvr,
'V' ) )
THEN
304 lquery = ( lwork.EQ.-1 )
305 IF( ijobvl.LE.0 )
THEN
307 ELSE IF( ijobvr.LE.0 )
THEN
309 ELSE IF( n.LT.0 )
THEN
311 ELSE IF( lda.LT.max( 1, n ) )
THEN
313 ELSE IF( ldb.LT.max( 1, n ) )
THEN
315 ELSE IF( ldvl.LT.1 .OR. ( ilvl .AND. ldvl.LT.n ) )
THEN
317 ELSE IF( ldvr.LT.1 .OR. ( ilvr .AND. ldvr.LT.n ) )
THEN
330 lwkmin = max( 1, 2*n )
331 lwkopt = max( 1, n + n*ilaenv( 1,
'CGEQRF',
' ', n, 1, n,
333 lwkopt = max( lwkopt, n +
334 $ n*ilaenv( 1,
'CUNMQR',
' ', n, 1, n, 0 ) )
336 lwkopt = max( lwkopt, n +
337 $ n*ilaenv( 1,
'CUNGQR',
' ', n, 1, n, -1 ) )
339 work( 1 ) = sroundup_lwork(lwkopt)
341 IF( lwork.LT.lwkmin .AND. .NOT.lquery )
346 CALL xerbla(
'CGGEV ', -info )
348 ELSE IF( lquery )
THEN
359 eps = slamch(
'E' )*slamch(
'B' )
360 smlnum = slamch(
'S' )
361 bignum = one / smlnum
362 smlnum = sqrt( smlnum ) / eps
363 bignum = one / smlnum
367 anrm = clange(
'M', n, n, a, lda, rwork )
369 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
372 ELSE IF( anrm.GT.bignum )
THEN
377 $
CALL clascl(
'G', 0, 0, anrm, anrmto, n, n, a, lda, ierr )
381 bnrm = clange(
'M', n, n, b, ldb, rwork )
383 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
386 ELSE IF( bnrm.GT.bignum )
THEN
391 $
CALL clascl(
'G', 0, 0, bnrm, bnrmto, n, n, b, ldb, ierr )
399 CALL cggbal(
'P', n, a, lda, b, ldb, ilo, ihi, rwork( ileft ),
400 $ rwork( iright ), rwork( irwrk ), ierr )
405 irows = ihi + 1 - ilo
413 CALL cgeqrf( irows, icols, b( ilo, ilo ), ldb, work( itau ),
414 $ work( iwrk ), lwork+1-iwrk, ierr )
419 CALL cunmqr(
'L',
'C', irows, icols, irows, b( ilo, ilo ), ldb,
420 $ work( itau ), a( ilo, ilo ), lda, work( iwrk ),
421 $ lwork+1-iwrk, ierr )
427 CALL claset(
'Full', n, n, czero, cone, vl, ldvl )
428 IF( irows.GT.1 )
THEN
429 CALL clacpy(
'L', irows-1, irows-1, b( ilo+1, ilo ), ldb,
430 $ vl( ilo+1, ilo ), ldvl )
432 CALL cungqr( irows, irows, irows, vl( ilo, ilo ), ldvl,
433 $ work( itau ), work( iwrk ), lwork+1-iwrk, ierr )
439 $
CALL claset(
'Full', n, n, czero, cone, vr, ldvr )
447 CALL cgghrd( jobvl, jobvr, n, ilo, ihi, a, lda, b, ldb, vl,
448 $ ldvl, vr, ldvr, ierr )
450 CALL cgghrd(
'N',
'N', irows, 1, irows, a( ilo, ilo ), lda,
451 $ b( ilo, ilo ), ldb, vl, ldvl, vr, ldvr, ierr )
465 CALL chgeqz( chtemp, jobvl, jobvr, n, ilo, ihi, a, lda, b, ldb,
466 $ alpha, beta, vl, ldvl, vr, ldvr, work( iwrk ),
467 $ lwork+1-iwrk, rwork( irwrk ), ierr )
469 IF( ierr.GT.0 .AND. ierr.LE.n )
THEN
471 ELSE IF( ierr.GT.n .AND. ierr.LE.2*n )
THEN
494 CALL ctgevc( chtemp,
'B', ldumma, n, a, lda, b, ldb, vl,
496 $ vr, ldvr, n, in, work( iwrk ), rwork( irwrk ),
507 CALL cggbak(
'P',
'L', n, ilo, ihi, rwork( ileft ),
508 $ rwork( iright ), n, vl, ldvl, ierr )
512 temp = max( temp, abs1( vl( jr, jc ) ) )
518 vl( jr, jc ) = vl( jr, jc )*temp
523 CALL cggbak(
'P',
'R', n, ilo, ihi, rwork( ileft ),
524 $ rwork( iright ), n, vr, ldvr, ierr )
528 temp = max( temp, abs1( vr( jr, jc ) ) )
534 vr( jr, jc ) = vr( jr, jc )*temp
545 $
CALL clascl(
'G', 0, 0, anrmto, anrm, n, 1, alpha, n, ierr )
548 $
CALL clascl(
'G', 0, 0, bnrmto, bnrm, n, 1, beta, n, ierr )
550 work( 1 ) = sroundup_lwork(lwkopt)