213 SUBROUTINE cggev3( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHA,
215 $ VL, LDVL, VR, LDVR, WORK, LWORK, RWORK, INFO )
222 CHARACTER JOBVL, JOBVR
223 INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N
227 COMPLEX A( LDA, * ), ALPHA( * ), B( LDB, * ),
228 $ beta( * ), vl( ldvl, * ), vr( ldvr, * ),
236 PARAMETER ( ZERO = 0.0e0, one = 1.0e0 )
238 parameter( czero = ( 0.0e0, 0.0e0 ),
239 $ cone = ( 1.0e0, 0.0e0 ) )
242 LOGICAL ILASCL, ILBSCL, ILV, ILVL, ILVR, LQUERY
244 INTEGER ICOLS, IERR, IHI, IJOBVL, IJOBVR, ILEFT, ILO,
245 $ in, iright, irows, irwrk, itau, iwrk, jc, jr,
247 REAL ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS,
261 REAL CLANGE, SLAMCH, SROUNDUP_LWORK
262 EXTERNAL lsame, 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 lwkmin = max( 1, 2*n )
306 IF( ijobvl.LE.0 )
THEN
308 ELSE IF( ijobvr.LE.0 )
THEN
310 ELSE IF( n.LT.0 )
THEN
312 ELSE IF( lda.LT.max( 1, n ) )
THEN
314 ELSE IF( ldb.LT.max( 1, n ) )
THEN
316 ELSE IF( ldvl.LT.1 .OR. ( ilvl .AND. ldvl.LT.n ) )
THEN
318 ELSE IF( ldvr.LT.1 .OR. ( ilvr .AND. ldvr.LT.n ) )
THEN
320 ELSE IF( lwork.LT.lwkmin .AND. .NOT.lquery )
THEN
327 CALL cgeqrf( n, n, b, ldb, work, work, -1, ierr )
328 lwkopt = max( lwkmin, n+int( work( 1 ) ) )
329 CALL cunmqr(
'L',
'C', n, n, n, b, ldb, work, a, lda, work,
331 lwkopt = max( lwkopt, n+int( work( 1 ) ) )
333 CALL cungqr( n, n, n, vl, ldvl, work, work, -1, ierr )
334 lwkopt = max( lwkopt, n+int( work( 1 ) ) )
337 CALL cgghd3( jobvl, jobvr, n, 1, n, a, lda, b, ldb, vl,
338 $ ldvl, vr, ldvr, work, -1, ierr )
339 lwkopt = max( lwkopt, n+int( work( 1 ) ) )
340 CALL claqz0(
'S', jobvl, jobvr, n, 1, n, a, lda, b, ldb,
341 $ alpha, beta, vl, ldvl, vr, ldvr, work, -1,
343 lwkopt = max( lwkopt, n+int( work( 1 ) ) )
345 CALL cgghd3(
'N',
'N', n, 1, n, a, lda, b, ldb, vl, ldvl,
346 $ vr, ldvr, work, -1, ierr )
347 lwkopt = max( lwkopt, n+int( work( 1 ) ) )
348 CALL claqz0(
'E', jobvl, jobvr, n, 1, n, a, lda, b, ldb,
349 $ alpha, beta, vl, ldvl, vr, ldvr, work, -1,
351 lwkopt = max( lwkopt, n+int( work( 1 ) ) )
356 work( 1 ) = sroundup_lwork( lwkopt )
361 CALL xerbla(
'CGGEV3 ', -info )
363 ELSE IF( lquery )
THEN
374 eps = slamch(
'E' )*slamch(
'B' )
375 smlnum = slamch(
'S' )
376 bignum = one / smlnum
377 smlnum = sqrt( smlnum ) / eps
378 bignum = one / smlnum
382 anrm = clange(
'M', n, n, a, lda, rwork )
384 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
387 ELSE IF( anrm.GT.bignum )
THEN
392 $
CALL clascl(
'G', 0, 0, anrm, anrmto, n, n, a, lda, ierr )
396 bnrm = clange(
'M', n, n, b, ldb, rwork )
398 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
401 ELSE IF( bnrm.GT.bignum )
THEN
406 $
CALL clascl(
'G', 0, 0, bnrm, bnrmto, n, n, b, ldb, ierr )
413 CALL cggbal(
'P', n, a, lda, b, ldb, ilo, ihi, rwork( ileft ),
414 $ rwork( iright ), rwork( irwrk ), ierr )
418 irows = ihi + 1 - ilo
426 CALL cgeqrf( irows, icols, b( ilo, ilo ), ldb, work( itau ),
427 $ work( iwrk ), lwork+1-iwrk, ierr )
431 CALL cunmqr(
'L',
'C', irows, icols, irows, b( ilo, ilo ), ldb,
432 $ work( itau ), a( ilo, ilo ), lda, work( iwrk ),
433 $ lwork+1-iwrk, ierr )
438 CALL claset(
'Full', n, n, czero, cone, vl, ldvl )
439 IF( irows.GT.1 )
THEN
440 CALL clacpy(
'L', irows-1, irows-1, b( ilo+1, ilo ), ldb,
441 $ vl( ilo+1, ilo ), ldvl )
443 CALL cungqr( irows, irows, irows, vl( ilo, ilo ), ldvl,
444 $ work( itau ), work( iwrk ), lwork+1-iwrk, ierr )
450 $
CALL claset(
'Full', n, n, czero, cone, vr, ldvr )
458 CALL cgghd3( jobvl, jobvr, n, ilo, ihi, a, lda, b, ldb, vl,
459 $ ldvl, vr, ldvr, work( iwrk ), lwork+1-iwrk,
462 CALL cgghd3(
'N',
'N', irows, 1, irows, a( ilo, ilo ), lda,
463 $ b( ilo, ilo ), ldb, vl, ldvl, vr, ldvr,
464 $ work( iwrk ), lwork+1-iwrk, ierr )
476 CALL claqz0( chtemp, jobvl, jobvr, n, ilo, ihi, a, lda, b, ldb,
477 $ alpha, beta, vl, ldvl, vr, ldvr, work( iwrk ),
478 $ lwork+1-iwrk, rwork( irwrk ), 0, ierr )
480 IF( ierr.GT.0 .AND. ierr.LE.n )
THEN
482 ELSE IF( ierr.GT.n .AND. ierr.LE.2*n )
THEN
503 CALL ctgevc( chtemp,
'B', ldumma, n, a, lda, b, ldb, vl,
505 $ vr, ldvr, n, in, work( iwrk ), rwork( irwrk ),
515 CALL cggbak(
'P',
'L', n, ilo, ihi, rwork( ileft ),
516 $ rwork( iright ), n, vl, ldvl, ierr )
520 temp = max( temp, abs1( vl( jr, jc ) ) )
526 vl( jr, jc ) = vl( jr, jc )*temp
531 CALL cggbak(
'P',
'R', n, ilo, ihi, rwork( ileft ),
532 $ rwork( iright ), n, vr, ldvr, ierr )
536 temp = max( temp, abs1( vr( jr, jc ) ) )
542 vr( jr, jc ) = vr( jr, jc )*temp
553 $
CALL clascl(
'G', 0, 0, anrmto, anrm, n, 1, alpha, n, ierr )
556 $
CALL clascl(
'G', 0, 0, bnrmto, bnrm, n, 1, beta, n, ierr )
558 work( 1 ) = sroundup_lwork( lwkopt )