188 SUBROUTINE dgeev( JOBVL, JOBVR, N, A, LDA, WR, WI, VL, LDVL,
190 $ LDVR, WORK, LWORK, INFO )
198 CHARACTER JOBVL, JOBVR
199 INTEGER INFO, LDA, LDVL, LDVR, LWORK, N
202 DOUBLE PRECISION A( LDA, * ), VL( LDVL, * ), VR( LDVR, * ),
203 $ WI( * ), WORK( * ), WR( * )
209 DOUBLE PRECISION ZERO, ONE
210 PARAMETER ( ZERO = 0.0d0, one = 1.0d0 )
213 LOGICAL LQUERY, SCALEA, WANTVL, WANTVR
215 INTEGER HSWORK, I, IBAL, IERR, IHI, ILO, ITAU, IWRK, K,
216 $ lwork_trevc, maxwrk, minwrk, nout
217 DOUBLE PRECISION ANRM, BIGNUM, CS, CSCALE, EPS, R, SCL, SMLNUM,
222 DOUBLE PRECISION DUM( 1 )
231 INTEGER IDAMAX, ILAENV
232 DOUBLE PRECISION DLAMCH, DLANGE, DLAPY2, DNRM2
233 EXTERNAL lsame, idamax, ilaenv, dlamch, dlange,
245 lquery = ( lwork.EQ.-1 )
246 wantvl = lsame( jobvl,
'V' )
247 wantvr = lsame( jobvr,
'V' )
248 IF( ( .NOT.wantvl ) .AND. ( .NOT.lsame( jobvl,
'N' ) ) )
THEN
250 ELSE IF( ( .NOT.wantvr ) .AND.
251 $ ( .NOT.lsame( jobvr,
'N' ) ) )
THEN
253 ELSE IF( n.LT.0 )
THEN
255 ELSE IF( lda.LT.max( 1, n ) )
THEN
257 ELSE IF( ldvl.LT.1 .OR. ( wantvl .AND. ldvl.LT.n ) )
THEN
259 ELSE IF( ldvr.LT.1 .OR. ( wantvr .AND. ldvr.LT.n ) )
THEN
278 maxwrk = 2*n + n*ilaenv( 1,
'DGEHRD',
' ', n, 1, n, 0 )
281 maxwrk = max( maxwrk, 2*n + ( n - 1 )*ilaenv( 1,
282 $
'DORGHR',
' ', n, 1, n, -1 ) )
283 CALL dhseqr(
'S',
'V', n, 1, n, a, lda, wr, wi, vl,
286 hswork = int( work(1) )
287 maxwrk = max( maxwrk, n + 1, n + hswork )
288 CALL dtrevc3(
'L',
'B',
SELECT, n, a, lda,
289 $ vl, ldvl, vr, ldvr, n, nout,
291 lwork_trevc = int( work(1) )
292 maxwrk = max( maxwrk, n + lwork_trevc )
293 maxwrk = max( maxwrk, 4*n )
294 ELSE IF( wantvr )
THEN
296 maxwrk = max( maxwrk, 2*n + ( n - 1 )*ilaenv( 1,
297 $
'DORGHR',
' ', n, 1, n, -1 ) )
298 CALL dhseqr(
'S',
'V', n, 1, n, a, lda, wr, wi, vr,
301 hswork = int( work(1) )
302 maxwrk = max( maxwrk, n + 1, n + hswork )
303 CALL dtrevc3(
'R',
'B',
SELECT, n, a, lda,
304 $ vl, ldvl, vr, ldvr, n, nout,
306 lwork_trevc = int( work(1) )
307 maxwrk = max( maxwrk, n + lwork_trevc )
308 maxwrk = max( maxwrk, 4*n )
311 CALL dhseqr(
'E',
'N', n, 1, n, a, lda, wr, wi, vr,
314 hswork = int( work(1) )
315 maxwrk = max( maxwrk, n + 1, n + hswork )
317 maxwrk = max( maxwrk, minwrk )
321 IF( lwork.LT.minwrk .AND. .NOT.lquery )
THEN
327 CALL xerbla(
'DGEEV ', -info )
329 ELSE IF( lquery )
THEN
341 smlnum = dlamch(
'S' )
342 bignum = one / smlnum
343 smlnum = sqrt( smlnum ) / eps
344 bignum = one / smlnum
348 anrm = dlange(
'M', n, n, a, lda, dum )
350 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
353 ELSE IF( anrm.GT.bignum )
THEN
358 $
CALL dlascl(
'G', 0, 0, anrm, cscale, n, n, a, lda, ierr )
364 CALL dgebal(
'B', n, a, lda, ilo, ihi, work( ibal ), ierr )
371 CALL dgehrd( n, ilo, ihi, a, lda, work( itau ), work( iwrk ),
372 $ lwork-iwrk+1, ierr )
380 CALL dlacpy(
'L', n, n, a, lda, vl, ldvl )
385 CALL dorghr( n, ilo, ihi, vl, ldvl, work( itau ),
387 $ lwork-iwrk+1, ierr )
393 CALL dhseqr(
'S',
'V', n, ilo, ihi, a, lda, wr, wi, vl,
395 $ work( iwrk ), lwork-iwrk+1, info )
403 CALL dlacpy(
'F', n, n, vl, ldvl, vr, ldvr )
406 ELSE IF( wantvr )
THEN
412 CALL dlacpy(
'L', n, n, a, lda, vr, ldvr )
417 CALL dorghr( n, ilo, ihi, vr, ldvr, work( itau ),
419 $ lwork-iwrk+1, ierr )
425 CALL dhseqr(
'S',
'V', n, ilo, ihi, a, lda, wr, wi, vr,
427 $ work( iwrk ), lwork-iwrk+1, info )
435 CALL dhseqr(
'E',
'N', n, ilo, ihi, a, lda, wr, wi, vr,
437 $ work( iwrk ), lwork-iwrk+1, info )
445 IF( wantvl .OR. wantvr )
THEN
450 CALL dtrevc3( side,
'B',
SELECT, n, a, lda, vl, ldvl, vr,
452 $ n, nout, work( iwrk ), lwork-iwrk+1, ierr )
460 CALL dgebak(
'B',
'L', n, ilo, ihi, work( ibal ), n, vl,
467 IF( wi( i ).EQ.zero )
THEN
468 scl = one / dnrm2( n, vl( 1, i ), 1 )
469 CALL dscal( n, scl, vl( 1, i ), 1 )
470 ELSE IF( wi( i ).GT.zero )
THEN
471 scl = one / dlapy2( dnrm2( n, vl( 1, i ), 1 ),
472 $ dnrm2( n, vl( 1, i+1 ), 1 ) )
473 CALL dscal( n, scl, vl( 1, i ), 1 )
474 CALL dscal( n, scl, vl( 1, i+1 ), 1 )
476 work( iwrk+k-1 ) = vl( k, i )**2 + vl( k, i+1 )**2
478 k = idamax( n, work( iwrk ), 1 )
479 CALL dlartg( vl( k, i ), vl( k, i+1 ), cs, sn, r )
480 CALL drot( n, vl( 1, i ), 1, vl( 1, i+1 ), 1, cs, sn )
491 CALL dgebak(
'B',
'R', n, ilo, ihi, work( ibal ), n, vr,
498 IF( wi( i ).EQ.zero )
THEN
499 scl = one / dnrm2( n, vr( 1, i ), 1 )
500 CALL dscal( n, scl, vr( 1, i ), 1 )
501 ELSE IF( wi( i ).GT.zero )
THEN
502 scl = one / dlapy2( dnrm2( n, vr( 1, i ), 1 ),
503 $ dnrm2( n, vr( 1, i+1 ), 1 ) )
504 CALL dscal( n, scl, vr( 1, i ), 1 )
505 CALL dscal( n, scl, vr( 1, i+1 ), 1 )
507 work( iwrk+k-1 ) = vr( k, i )**2 + vr( k, i+1 )**2
509 k = idamax( n, work( iwrk ), 1 )
510 CALL dlartg( vr( k, i ), vr( k, i+1 ), cs, sn, r )
511 CALL drot( n, vr( 1, i ), 1, vr( 1, i+1 ), 1, cs, sn )
521 CALL dlascl(
'G', 0, 0, cscale, anrm, n-info, 1,
523 $ max( n-info, 1 ), ierr )
524 CALL dlascl(
'G', 0, 0, cscale, anrm, n-info, 1,
526 $ max( n-info, 1 ), ierr )
528 CALL dlascl(
'G', 0, 0, cscale, anrm, ilo-1, 1, wr, n,
530 CALL dlascl(
'G', 0, 0, cscale, anrm, ilo-1, 1, wi, n,