222 SUBROUTINE sggev( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR,
224 $ BETA, VL, LDVL, VR, LDVR, WORK, LWORK, INFO )
231 CHARACTER JOBVL, JOBVR
232 INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N
235 REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ),
236 $ B( LDB, * ), BETA( * ), VL( LDVL, * ),
237 $ vr( ldvr, * ), work( * )
244 PARAMETER ( ZERO = 0.0e+0, one = 1.0e+0 )
247 LOGICAL ILASCL, ILBSCL, ILV, ILVL, ILVR, LQUERY
249 INTEGER ICOLS, IERR, IHI, IJOBVL, IJOBVR, ILEFT, ILO,
250 $ in, iright, irows, itau, iwrk, jc, jr, maxwrk,
252 REAL ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS,
266 REAL SLAMCH, SLANGE, SROUNDUP_LWORK
267 EXTERNAL lsame, ilaenv, slamch,
268 $ slange, sroundup_lwork
271 INTRINSIC abs, max, sqrt
277 IF( lsame( jobvl,
'N' ) )
THEN
280 ELSE IF( lsame( jobvl,
'V' ) )
THEN
288 IF( lsame( jobvr,
'N' ) )
THEN
291 ELSE IF( lsame( jobvr,
'V' ) )
THEN
303 lquery = ( lwork.EQ.-1 )
304 IF( ijobvl.LE.0 )
THEN
306 ELSE IF( ijobvr.LE.0 )
THEN
308 ELSE IF( n.LT.0 )
THEN
310 ELSE IF( lda.LT.max( 1, n ) )
THEN
312 ELSE IF( ldb.LT.max( 1, n ) )
THEN
314 ELSE IF( ldvl.LT.1 .OR. ( ilvl .AND. ldvl.LT.n ) )
THEN
316 ELSE IF( ldvr.LT.1 .OR. ( ilvr .AND. ldvr.LT.n ) )
THEN
329 minwrk = max( 1, 8*n )
330 maxwrk = max( 1, n*( 7 +
331 $ ilaenv( 1,
'SGEQRF',
' ', n, 1, n, 0 ) ) )
332 maxwrk = max( maxwrk, n*( 7 +
333 $ ilaenv( 1,
'SORMQR',
' ', n, 1, n, 0 ) ) )
335 maxwrk = max( maxwrk, n*( 7 +
336 $ ilaenv( 1,
'SORGQR',
' ', n, 1, n, -1 ) ) )
338 work( 1 ) = sroundup_lwork(maxwrk)
340 IF( lwork.LT.minwrk .AND. .NOT.lquery )
345 CALL xerbla(
'SGGEV ', -info )
347 ELSE IF( lquery )
THEN
359 smlnum = slamch(
'S' )
360 bignum = one / smlnum
361 smlnum = sqrt( smlnum ) / eps
362 bignum = one / smlnum
366 anrm = slange(
'M', n, n, a, lda, work )
368 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
371 ELSE IF( anrm.GT.bignum )
THEN
376 $
CALL slascl(
'G', 0, 0, anrm, anrmto, n, n, a, lda, ierr )
380 bnrm = slange(
'M', n, n, b, ldb, work )
382 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
385 ELSE IF( bnrm.GT.bignum )
THEN
390 $
CALL slascl(
'G', 0, 0, bnrm, bnrmto, n, n, b, ldb, ierr )
398 CALL sggbal(
'P', n, a, lda, b, ldb, ilo, ihi, work( ileft ),
399 $ work( iright ), work( iwrk ), ierr )
404 irows = ihi + 1 - ilo
412 CALL sgeqrf( irows, icols, b( ilo, ilo ), ldb, work( itau ),
413 $ work( iwrk ), lwork+1-iwrk, ierr )
418 CALL sormqr(
'L',
'T', irows, icols, irows, b( ilo, ilo ), ldb,
419 $ work( itau ), a( ilo, ilo ), lda, work( iwrk ),
420 $ lwork+1-iwrk, ierr )
426 CALL slaset(
'Full', n, n, zero, one, vl, ldvl )
427 IF( irows.GT.1 )
THEN
428 CALL slacpy(
'L', irows-1, irows-1, b( ilo+1, ilo ), ldb,
429 $ vl( ilo+1, ilo ), ldvl )
431 CALL sorgqr( irows, irows, irows, vl( ilo, ilo ), ldvl,
432 $ work( itau ), work( iwrk ), lwork+1-iwrk, ierr )
438 $
CALL slaset(
'Full', n, n, zero, one, vr, ldvr )
447 CALL sgghrd( jobvl, jobvr, n, ilo, ihi, a, lda, b, ldb, vl,
448 $ ldvl, vr, ldvr, ierr )
450 CALL sgghrd(
'N',
'N', irows, 1, irows, a( ilo, ilo ), lda,
451 $ b( ilo, ilo ), ldb, vl, ldvl, vr, ldvr, ierr )
464 CALL shgeqz( chtemp, jobvl, jobvr, n, ilo, ihi, a, lda, b, ldb,
465 $ alphar, alphai, beta, vl, ldvl, vr, ldvr,
466 $ work( iwrk ), lwork+1-iwrk, ierr )
468 IF( ierr.GT.0 .AND. ierr.LE.n )
THEN
470 ELSE IF( ierr.GT.n .AND. ierr.LE.2*n )
THEN
491 CALL stgevc( chtemp,
'B', ldumma, n, a, lda, b, ldb, vl,
493 $ vr, ldvr, n, in, work( iwrk ), ierr )
503 CALL sggbak(
'P',
'L', n, ilo, ihi, work( ileft ),
504 $ work( iright ), n, vl, ldvl, ierr )
506 IF( alphai( jc ).LT.zero )
509 IF( alphai( jc ).EQ.zero )
THEN
511 temp = max( temp, abs( vl( jr, jc ) ) )
515 temp = max( temp, abs( vl( jr, jc ) )+
516 $ abs( vl( jr, jc+1 ) ) )
522 IF( alphai( jc ).EQ.zero )
THEN
524 vl( jr, jc ) = vl( jr, jc )*temp
528 vl( jr, jc ) = vl( jr, jc )*temp
529 vl( jr, jc+1 ) = vl( jr, jc+1 )*temp
535 CALL sggbak(
'P',
'R', n, ilo, ihi, work( ileft ),
536 $ work( iright ), n, vr, ldvr, ierr )
538 IF( alphai( jc ).LT.zero )
541 IF( alphai( jc ).EQ.zero )
THEN
543 temp = max( temp, abs( vr( jr, jc ) ) )
547 temp = max( temp, abs( vr( jr, jc ) )+
548 $ abs( vr( jr, jc+1 ) ) )
554 IF( alphai( jc ).EQ.zero )
THEN
556 vr( jr, jc ) = vr( jr, jc )*temp
560 vr( jr, jc ) = vr( jr, jc )*temp
561 vr( jr, jc+1 ) = vr( jr, jc+1 )*temp
576 CALL slascl(
'G', 0, 0, anrmto, anrm, n, 1, alphar, n,
578 CALL slascl(
'G', 0, 0, anrmto, anrm, n, 1, alphai, n,
583 CALL slascl(
'G', 0, 0, bnrmto, bnrm, n, 1, beta, n, ierr )
586 work( 1 ) = sroundup_lwork(maxwrk)