Annotation of rpl/lapack/lapack/dhgeqz.f, revision 1.21

1.9       bertrand    1: *> \brief \b DHGEQZ
                      2: *
                      3: *  =========== DOCUMENTATION ===========
                      4: *
1.18      bertrand    5: * Online html documentation available at
                      6: *            http://www.netlib.org/lapack/explore-html/
1.9       bertrand    7: *
                      8: *> \htmlonly
1.18      bertrand    9: *> Download DHGEQZ + dependencies
                     10: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dhgeqz.f">
                     11: *> [TGZ]</a>
                     12: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dhgeqz.f">
                     13: *> [ZIP]</a>
                     14: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dhgeqz.f">
1.9       bertrand   15: *> [TXT]</a>
1.18      bertrand   16: *> \endhtmlonly
1.9       bertrand   17: *
                     18: *  Definition:
                     19: *  ===========
                     20: *
                     21: *       SUBROUTINE DHGEQZ( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT,
                     22: *                          ALPHAR, ALPHAI, BETA, Q, LDQ, Z, LDZ, WORK,
                     23: *                          LWORK, INFO )
1.18      bertrand   24: *
1.9       bertrand   25: *       .. Scalar Arguments ..
                     26: *       CHARACTER          COMPQ, COMPZ, JOB
                     27: *       INTEGER            IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N
                     28: *       ..
                     29: *       .. Array Arguments ..
                     30: *       DOUBLE PRECISION   ALPHAI( * ), ALPHAR( * ), BETA( * ),
                     31: *      $                   H( LDH, * ), Q( LDQ, * ), T( LDT, * ),
                     32: *      $                   WORK( * ), Z( LDZ, * )
                     33: *       ..
1.18      bertrand   34: *
1.9       bertrand   35: *
                     36: *> \par Purpose:
                     37: *  =============
                     38: *>
                     39: *> \verbatim
                     40: *>
                     41: *> DHGEQZ computes the eigenvalues of a real matrix pair (H,T),
                     42: *> where H is an upper Hessenberg matrix and T is upper triangular,
                     43: *> using the double-shift QZ method.
                     44: *> Matrix pairs of this type are produced by the reduction to
                     45: *> generalized upper Hessenberg form of a real matrix pair (A,B):
                     46: *>
                     47: *>    A = Q1*H*Z1**T,  B = Q1*T*Z1**T,
                     48: *>
                     49: *> as computed by DGGHRD.
                     50: *>
                     51: *> If JOB='S', then the Hessenberg-triangular pair (H,T) is
                     52: *> also reduced to generalized Schur form,
1.18      bertrand   53: *>
1.9       bertrand   54: *>    H = Q*S*Z**T,  T = Q*P*Z**T,
1.18      bertrand   55: *>
1.9       bertrand   56: *> where Q and Z are orthogonal matrices, P is an upper triangular
                     57: *> matrix, and S is a quasi-triangular matrix with 1-by-1 and 2-by-2
                     58: *> diagonal blocks.
                     59: *>
                     60: *> The 1-by-1 blocks correspond to real eigenvalues of the matrix pair
                     61: *> (H,T) and the 2-by-2 blocks correspond to complex conjugate pairs of
                     62: *> eigenvalues.
                     63: *>
                     64: *> Additionally, the 2-by-2 upper triangular diagonal blocks of P
                     65: *> corresponding to 2-by-2 blocks of S are reduced to positive diagonal
                     66: *> form, i.e., if S(j+1,j) is non-zero, then P(j+1,j) = P(j,j+1) = 0,
                     67: *> P(j,j) > 0, and P(j+1,j+1) > 0.
                     68: *>
                     69: *> Optionally, the orthogonal matrix Q from the generalized Schur
                     70: *> factorization may be postmultiplied into an input matrix Q1, and the
                     71: *> orthogonal matrix Z may be postmultiplied into an input matrix Z1.
                     72: *> If Q1 and Z1 are the orthogonal matrices from DGGHRD that reduced
                     73: *> the matrix pair (A,B) to generalized upper Hessenberg form, then the
                     74: *> output matrices Q1*Q and Z1*Z are the orthogonal factors from the
                     75: *> generalized Schur factorization of (A,B):
                     76: *>
                     77: *>    A = (Q1*Q)*S*(Z1*Z)**T,  B = (Q1*Q)*P*(Z1*Z)**T.
1.18      bertrand   78: *>
1.9       bertrand   79: *> To avoid overflow, eigenvalues of the matrix pair (H,T) (equivalently,
                     80: *> of (A,B)) are computed as a pair of values (alpha,beta), where alpha is
                     81: *> complex and beta real.
                     82: *> If beta is nonzero, lambda = alpha / beta is an eigenvalue of the
                     83: *> generalized nonsymmetric eigenvalue problem (GNEP)
                     84: *>    A*x = lambda*B*x
                     85: *> and if alpha is nonzero, mu = beta / alpha is an eigenvalue of the
                     86: *> alternate form of the GNEP
                     87: *>    mu*A*y = B*y.
                     88: *> Real eigenvalues can be read directly from the generalized Schur
1.18      bertrand   89: *> form:
1.9       bertrand   90: *>   alpha = S(i,i), beta = P(i,i).
                     91: *>
                     92: *> Ref: C.B. Moler & G.W. Stewart, "An Algorithm for Generalized Matrix
                     93: *>      Eigenvalue Problems", SIAM J. Numer. Anal., 10(1973),
                     94: *>      pp. 241--256.
                     95: *> \endverbatim
                     96: *
                     97: *  Arguments:
                     98: *  ==========
                     99: *
                    100: *> \param[in] JOB
                    101: *> \verbatim
                    102: *>          JOB is CHARACTER*1
                    103: *>          = 'E': Compute eigenvalues only;
1.18      bertrand  104: *>          = 'S': Compute eigenvalues and the Schur form.
1.9       bertrand  105: *> \endverbatim
                    106: *>
                    107: *> \param[in] COMPQ
                    108: *> \verbatim
                    109: *>          COMPQ is CHARACTER*1
                    110: *>          = 'N': Left Schur vectors (Q) are not computed;
                    111: *>          = 'I': Q is initialized to the unit matrix and the matrix Q
                    112: *>                 of left Schur vectors of (H,T) is returned;
                    113: *>          = 'V': Q must contain an orthogonal matrix Q1 on entry and
                    114: *>                 the product Q1*Q is returned.
                    115: *> \endverbatim
                    116: *>
                    117: *> \param[in] COMPZ
                    118: *> \verbatim
                    119: *>          COMPZ is CHARACTER*1
                    120: *>          = 'N': Right Schur vectors (Z) are not computed;
                    121: *>          = 'I': Z is initialized to the unit matrix and the matrix Z
                    122: *>                 of right Schur vectors of (H,T) is returned;
                    123: *>          = 'V': Z must contain an orthogonal matrix Z1 on entry and
                    124: *>                 the product Z1*Z is returned.
                    125: *> \endverbatim
                    126: *>
                    127: *> \param[in] N
                    128: *> \verbatim
                    129: *>          N is INTEGER
                    130: *>          The order of the matrices H, T, Q, and Z.  N >= 0.
                    131: *> \endverbatim
                    132: *>
                    133: *> \param[in] ILO
                    134: *> \verbatim
                    135: *>          ILO is INTEGER
                    136: *> \endverbatim
                    137: *>
                    138: *> \param[in] IHI
                    139: *> \verbatim
                    140: *>          IHI is INTEGER
                    141: *>          ILO and IHI mark the rows and columns of H which are in
                    142: *>          Hessenberg form.  It is assumed that A is already upper
                    143: *>          triangular in rows and columns 1:ILO-1 and IHI+1:N.
                    144: *>          If N > 0, 1 <= ILO <= IHI <= N; if N = 0, ILO=1 and IHI=0.
                    145: *> \endverbatim
                    146: *>
                    147: *> \param[in,out] H
                    148: *> \verbatim
                    149: *>          H is DOUBLE PRECISION array, dimension (LDH, N)
                    150: *>          On entry, the N-by-N upper Hessenberg matrix H.
                    151: *>          On exit, if JOB = 'S', H contains the upper quasi-triangular
                    152: *>          matrix S from the generalized Schur factorization.
                    153: *>          If JOB = 'E', the diagonal blocks of H match those of S, but
                    154: *>          the rest of H is unspecified.
                    155: *> \endverbatim
                    156: *>
                    157: *> \param[in] LDH
                    158: *> \verbatim
                    159: *>          LDH is INTEGER
                    160: *>          The leading dimension of the array H.  LDH >= max( 1, N ).
                    161: *> \endverbatim
                    162: *>
                    163: *> \param[in,out] T
                    164: *> \verbatim
                    165: *>          T is DOUBLE PRECISION array, dimension (LDT, N)
                    166: *>          On entry, the N-by-N upper triangular matrix T.
                    167: *>          On exit, if JOB = 'S', T contains the upper triangular
                    168: *>          matrix P from the generalized Schur factorization;
                    169: *>          2-by-2 diagonal blocks of P corresponding to 2-by-2 blocks of S
                    170: *>          are reduced to positive diagonal form, i.e., if H(j+1,j) is
                    171: *>          non-zero, then T(j+1,j) = T(j,j+1) = 0, T(j,j) > 0, and
                    172: *>          T(j+1,j+1) > 0.
                    173: *>          If JOB = 'E', the diagonal blocks of T match those of P, but
                    174: *>          the rest of T is unspecified.
                    175: *> \endverbatim
                    176: *>
                    177: *> \param[in] LDT
                    178: *> \verbatim
                    179: *>          LDT is INTEGER
                    180: *>          The leading dimension of the array T.  LDT >= max( 1, N ).
                    181: *> \endverbatim
                    182: *>
                    183: *> \param[out] ALPHAR
                    184: *> \verbatim
                    185: *>          ALPHAR is DOUBLE PRECISION array, dimension (N)
                    186: *>          The real parts of each scalar alpha defining an eigenvalue
                    187: *>          of GNEP.
                    188: *> \endverbatim
                    189: *>
                    190: *> \param[out] ALPHAI
                    191: *> \verbatim
                    192: *>          ALPHAI is DOUBLE PRECISION array, dimension (N)
                    193: *>          The imaginary parts of each scalar alpha defining an
                    194: *>          eigenvalue of GNEP.
                    195: *>          If ALPHAI(j) is zero, then the j-th eigenvalue is real; if
                    196: *>          positive, then the j-th and (j+1)-st eigenvalues are a
                    197: *>          complex conjugate pair, with ALPHAI(j+1) = -ALPHAI(j).
                    198: *> \endverbatim
                    199: *>
                    200: *> \param[out] BETA
                    201: *> \verbatim
                    202: *>          BETA is DOUBLE PRECISION array, dimension (N)
                    203: *>          The scalars beta that define the eigenvalues of GNEP.
                    204: *>          Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and
                    205: *>          beta = BETA(j) represent the j-th eigenvalue of the matrix
                    206: *>          pair (A,B), in one of the forms lambda = alpha/beta or
                    207: *>          mu = beta/alpha.  Since either lambda or mu may overflow,
                    208: *>          they should not, in general, be computed.
                    209: *> \endverbatim
                    210: *>
                    211: *> \param[in,out] Q
                    212: *> \verbatim
                    213: *>          Q is DOUBLE PRECISION array, dimension (LDQ, N)
1.16      bertrand  214: *>          On entry, if COMPQ = 'V', the orthogonal matrix Q1 used in
1.9       bertrand  215: *>          the reduction of (A,B) to generalized Hessenberg form.
1.16      bertrand  216: *>          On exit, if COMPQ = 'I', the orthogonal matrix of left Schur
                    217: *>          vectors of (H,T), and if COMPQ = 'V', the orthogonal matrix
1.9       bertrand  218: *>          of left Schur vectors of (A,B).
1.16      bertrand  219: *>          Not referenced if COMPQ = 'N'.
1.9       bertrand  220: *> \endverbatim
                    221: *>
                    222: *> \param[in] LDQ
                    223: *> \verbatim
                    224: *>          LDQ is INTEGER
                    225: *>          The leading dimension of the array Q.  LDQ >= 1.
                    226: *>          If COMPQ='V' or 'I', then LDQ >= N.
                    227: *> \endverbatim
                    228: *>
                    229: *> \param[in,out] Z
                    230: *> \verbatim
                    231: *>          Z is DOUBLE PRECISION array, dimension (LDZ, N)
                    232: *>          On entry, if COMPZ = 'V', the orthogonal matrix Z1 used in
                    233: *>          the reduction of (A,B) to generalized Hessenberg form.
                    234: *>          On exit, if COMPZ = 'I', the orthogonal matrix of
                    235: *>          right Schur vectors of (H,T), and if COMPZ = 'V', the
                    236: *>          orthogonal matrix of right Schur vectors of (A,B).
                    237: *>          Not referenced if COMPZ = 'N'.
                    238: *> \endverbatim
                    239: *>
                    240: *> \param[in] LDZ
                    241: *> \verbatim
                    242: *>          LDZ is INTEGER
                    243: *>          The leading dimension of the array Z.  LDZ >= 1.
                    244: *>          If COMPZ='V' or 'I', then LDZ >= N.
                    245: *> \endverbatim
                    246: *>
                    247: *> \param[out] WORK
                    248: *> \verbatim
                    249: *>          WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))
                    250: *>          On exit, if INFO >= 0, WORK(1) returns the optimal LWORK.
                    251: *> \endverbatim
                    252: *>
                    253: *> \param[in] LWORK
                    254: *> \verbatim
                    255: *>          LWORK is INTEGER
                    256: *>          The dimension of the array WORK.  LWORK >= max(1,N).
                    257: *>
                    258: *>          If LWORK = -1, then a workspace query is assumed; the routine
                    259: *>          only calculates the optimal size of the WORK array, returns
                    260: *>          this value as the first entry of the WORK array, and no error
                    261: *>          message related to LWORK is issued by XERBLA.
                    262: *> \endverbatim
                    263: *>
                    264: *> \param[out] INFO
                    265: *> \verbatim
                    266: *>          INFO is INTEGER
                    267: *>          = 0: successful exit
                    268: *>          < 0: if INFO = -i, the i-th argument had an illegal value
                    269: *>          = 1,...,N: the QZ iteration did not converge.  (H,T) is not
                    270: *>                     in Schur form, but ALPHAR(i), ALPHAI(i), and
                    271: *>                     BETA(i), i=INFO+1,...,N should be correct.
                    272: *>          = N+1,...,2*N: the shift calculation failed.  (H,T) is not
                    273: *>                     in Schur form, but ALPHAR(i), ALPHAI(i), and
                    274: *>                     BETA(i), i=INFO-N+1,...,N should be correct.
                    275: *> \endverbatim
                    276: *
                    277: *  Authors:
                    278: *  ========
                    279: *
1.18      bertrand  280: *> \author Univ. of Tennessee
                    281: *> \author Univ. of California Berkeley
                    282: *> \author Univ. of Colorado Denver
                    283: *> \author NAG Ltd.
1.9       bertrand  284: *
                    285: *> \ingroup doubleGEcomputational
                    286: *
                    287: *> \par Further Details:
                    288: *  =====================
                    289: *>
                    290: *> \verbatim
                    291: *>
                    292: *>  Iteration counters:
                    293: *>
                    294: *>  JITER  -- counts iterations.
                    295: *>  IITER  -- counts iterations run since ILAST was last
                    296: *>            changed.  This is therefore reset only when a 1-by-1 or
                    297: *>            2-by-2 block deflates off the bottom.
                    298: *> \endverbatim
                    299: *>
                    300: *  =====================================================================
1.1       bertrand  301:       SUBROUTINE DHGEQZ( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT,
                    302:      $                   ALPHAR, ALPHAI, BETA, Q, LDQ, Z, LDZ, WORK,
                    303:      $                   LWORK, INFO )
                    304: *
1.21    ! bertrand  305: *  -- LAPACK computational routine --
1.1       bertrand  306: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
                    307: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
                    308: *
                    309: *     .. Scalar Arguments ..
                    310:       CHARACTER          COMPQ, COMPZ, JOB
                    311:       INTEGER            IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N
                    312: *     ..
                    313: *     .. Array Arguments ..
                    314:       DOUBLE PRECISION   ALPHAI( * ), ALPHAR( * ), BETA( * ),
                    315:      $                   H( LDH, * ), Q( LDQ, * ), T( LDT, * ),
                    316:      $                   WORK( * ), Z( LDZ, * )
                    317: *     ..
                    318: *
                    319: *  =====================================================================
                    320: *
                    321: *     .. Parameters ..
                    322: *    $                     SAFETY = 1.0E+0 )
                    323:       DOUBLE PRECISION   HALF, ZERO, ONE, SAFETY
                    324:       PARAMETER          ( HALF = 0.5D+0, ZERO = 0.0D+0, ONE = 1.0D+0,
                    325:      $                   SAFETY = 1.0D+2 )
                    326: *     ..
                    327: *     .. Local Scalars ..
                    328:       LOGICAL            ILAZR2, ILAZRO, ILPIVT, ILQ, ILSCHR, ILZ,
                    329:      $                   LQUERY
                    330:       INTEGER            ICOMPQ, ICOMPZ, IFIRST, IFRSTM, IITER, ILAST,
                    331:      $                   ILASTM, IN, ISCHUR, ISTART, J, JC, JCH, JITER,
                    332:      $                   JR, MAXIT
                    333:       DOUBLE PRECISION   A11, A12, A1I, A1R, A21, A22, A2I, A2R, AD11,
                    334:      $                   AD11L, AD12, AD12L, AD21, AD21L, AD22, AD22L,
                    335:      $                   AD32L, AN, ANORM, ASCALE, ATOL, B11, B1A, B1I,
                    336:      $                   B1R, B22, B2A, B2I, B2R, BN, BNORM, BSCALE,
                    337:      $                   BTOL, C, C11I, C11R, C12, C21, C22I, C22R, CL,
                    338:      $                   CQ, CR, CZ, ESHIFT, S, S1, S1INV, S2, SAFMAX,
                    339:      $                   SAFMIN, SCALE, SL, SQI, SQR, SR, SZI, SZR, T1,
                    340:      $                   TAU, TEMP, TEMP2, TEMPI, TEMPR, U1, U12, U12L,
                    341:      $                   U2, ULP, VS, W11, W12, W21, W22, WABS, WI, WR,
                    342:      $                   WR2
                    343: *     ..
                    344: *     .. Local Arrays ..
                    345:       DOUBLE PRECISION   V( 3 )
                    346: *     ..
                    347: *     .. External Functions ..
                    348:       LOGICAL            LSAME
                    349:       DOUBLE PRECISION   DLAMCH, DLANHS, DLAPY2, DLAPY3
                    350:       EXTERNAL           LSAME, DLAMCH, DLANHS, DLAPY2, DLAPY3
                    351: *     ..
                    352: *     .. External Subroutines ..
                    353:       EXTERNAL           DLAG2, DLARFG, DLARTG, DLASET, DLASV2, DROT,
                    354:      $                   XERBLA
                    355: *     ..
                    356: *     .. Intrinsic Functions ..
                    357:       INTRINSIC          ABS, DBLE, MAX, MIN, SQRT
                    358: *     ..
                    359: *     .. Executable Statements ..
                    360: *
                    361: *     Decode JOB, COMPQ, COMPZ
                    362: *
                    363:       IF( LSAME( JOB, 'E' ) ) THEN
                    364:          ILSCHR = .FALSE.
                    365:          ISCHUR = 1
                    366:       ELSE IF( LSAME( JOB, 'S' ) ) THEN
                    367:          ILSCHR = .TRUE.
                    368:          ISCHUR = 2
                    369:       ELSE
                    370:          ISCHUR = 0
                    371:       END IF
                    372: *
                    373:       IF( LSAME( COMPQ, 'N' ) ) THEN
                    374:          ILQ = .FALSE.
                    375:          ICOMPQ = 1
                    376:       ELSE IF( LSAME( COMPQ, 'V' ) ) THEN
                    377:          ILQ = .TRUE.
                    378:          ICOMPQ = 2
                    379:       ELSE IF( LSAME( COMPQ, 'I' ) ) THEN
                    380:          ILQ = .TRUE.
                    381:          ICOMPQ = 3
                    382:       ELSE
                    383:          ICOMPQ = 0
                    384:       END IF
                    385: *
                    386:       IF( LSAME( COMPZ, 'N' ) ) THEN
                    387:          ILZ = .FALSE.
                    388:          ICOMPZ = 1
                    389:       ELSE IF( LSAME( COMPZ, 'V' ) ) THEN
                    390:          ILZ = .TRUE.
                    391:          ICOMPZ = 2
                    392:       ELSE IF( LSAME( COMPZ, 'I' ) ) THEN
                    393:          ILZ = .TRUE.
                    394:          ICOMPZ = 3
                    395:       ELSE
                    396:          ICOMPZ = 0
                    397:       END IF
                    398: *
                    399: *     Check Argument Values
                    400: *
                    401:       INFO = 0
                    402:       WORK( 1 ) = MAX( 1, N )
                    403:       LQUERY = ( LWORK.EQ.-1 )
                    404:       IF( ISCHUR.EQ.0 ) THEN
                    405:          INFO = -1
                    406:       ELSE IF( ICOMPQ.EQ.0 ) THEN
                    407:          INFO = -2
                    408:       ELSE IF( ICOMPZ.EQ.0 ) THEN
                    409:          INFO = -3
                    410:       ELSE IF( N.LT.0 ) THEN
                    411:          INFO = -4
                    412:       ELSE IF( ILO.LT.1 ) THEN
                    413:          INFO = -5
                    414:       ELSE IF( IHI.GT.N .OR. IHI.LT.ILO-1 ) THEN
                    415:          INFO = -6
                    416:       ELSE IF( LDH.LT.N ) THEN
                    417:          INFO = -8
                    418:       ELSE IF( LDT.LT.N ) THEN
                    419:          INFO = -10
                    420:       ELSE IF( LDQ.LT.1 .OR. ( ILQ .AND. LDQ.LT.N ) ) THEN
                    421:          INFO = -15
                    422:       ELSE IF( LDZ.LT.1 .OR. ( ILZ .AND. LDZ.LT.N ) ) THEN
                    423:          INFO = -17
                    424:       ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
                    425:          INFO = -19
                    426:       END IF
                    427:       IF( INFO.NE.0 ) THEN
                    428:          CALL XERBLA( 'DHGEQZ', -INFO )
                    429:          RETURN
                    430:       ELSE IF( LQUERY ) THEN
                    431:          RETURN
                    432:       END IF
                    433: *
                    434: *     Quick return if possible
                    435: *
                    436:       IF( N.LE.0 ) THEN
                    437:          WORK( 1 ) = DBLE( 1 )
                    438:          RETURN
                    439:       END IF
                    440: *
                    441: *     Initialize Q and Z
                    442: *
                    443:       IF( ICOMPQ.EQ.3 )
                    444:      $   CALL DLASET( 'Full', N, N, ZERO, ONE, Q, LDQ )
                    445:       IF( ICOMPZ.EQ.3 )
                    446:      $   CALL DLASET( 'Full', N, N, ZERO, ONE, Z, LDZ )
                    447: *
                    448: *     Machine Constants
                    449: *
                    450:       IN = IHI + 1 - ILO
                    451:       SAFMIN = DLAMCH( 'S' )
                    452:       SAFMAX = ONE / SAFMIN
                    453:       ULP = DLAMCH( 'E' )*DLAMCH( 'B' )
                    454:       ANORM = DLANHS( 'F', IN, H( ILO, ILO ), LDH, WORK )
                    455:       BNORM = DLANHS( 'F', IN, T( ILO, ILO ), LDT, WORK )
                    456:       ATOL = MAX( SAFMIN, ULP*ANORM )
                    457:       BTOL = MAX( SAFMIN, ULP*BNORM )
                    458:       ASCALE = ONE / MAX( SAFMIN, ANORM )
                    459:       BSCALE = ONE / MAX( SAFMIN, BNORM )
                    460: *
                    461: *     Set Eigenvalues IHI+1:N
                    462: *
                    463:       DO 30 J = IHI + 1, N
                    464:          IF( T( J, J ).LT.ZERO ) THEN
                    465:             IF( ILSCHR ) THEN
                    466:                DO 10 JR = 1, J
                    467:                   H( JR, J ) = -H( JR, J )
                    468:                   T( JR, J ) = -T( JR, J )
                    469:    10          CONTINUE
                    470:             ELSE
                    471:                H( J, J ) = -H( J, J )
                    472:                T( J, J ) = -T( J, J )
                    473:             END IF
                    474:             IF( ILZ ) THEN
                    475:                DO 20 JR = 1, N
                    476:                   Z( JR, J ) = -Z( JR, J )
                    477:    20          CONTINUE
                    478:             END IF
                    479:          END IF
                    480:          ALPHAR( J ) = H( J, J )
                    481:          ALPHAI( J ) = ZERO
                    482:          BETA( J ) = T( J, J )
                    483:    30 CONTINUE
                    484: *
                    485: *     If IHI < ILO, skip QZ steps
                    486: *
                    487:       IF( IHI.LT.ILO )
                    488:      $   GO TO 380
                    489: *
                    490: *     MAIN QZ ITERATION LOOP
                    491: *
                    492: *     Initialize dynamic indices
                    493: *
                    494: *     Eigenvalues ILAST+1:N have been found.
                    495: *        Column operations modify rows IFRSTM:whatever.
                    496: *        Row operations modify columns whatever:ILASTM.
                    497: *
                    498: *     If only eigenvalues are being computed, then
                    499: *        IFRSTM is the row of the last splitting row above row ILAST;
                    500: *        this is always at least ILO.
                    501: *     IITER counts iterations since the last eigenvalue was found,
                    502: *        to tell when to use an extraordinary shift.
                    503: *     MAXIT is the maximum number of QZ sweeps allowed.
                    504: *
                    505:       ILAST = IHI
                    506:       IF( ILSCHR ) THEN
                    507:          IFRSTM = 1
                    508:          ILASTM = N
                    509:       ELSE
                    510:          IFRSTM = ILO
                    511:          ILASTM = IHI
                    512:       END IF
                    513:       IITER = 0
                    514:       ESHIFT = ZERO
                    515:       MAXIT = 30*( IHI-ILO+1 )
                    516: *
                    517:       DO 360 JITER = 1, MAXIT
                    518: *
                    519: *        Split the matrix if possible.
                    520: *
                    521: *        Two tests:
                    522: *           1: H(j,j-1)=0  or  j=ILO
                    523: *           2: T(j,j)=0
                    524: *
                    525:          IF( ILAST.EQ.ILO ) THEN
                    526: *
                    527: *           Special case: j=ILAST
                    528: *
                    529:             GO TO 80
                    530:          ELSE
1.21    ! bertrand  531:             IF( ABS( H( ILAST, ILAST-1 ) ).LE.MAX( SAFMIN, ULP*( 
        !           532:      $         ABS( H( ILAST, ILAST ) ) + ABS( H( ILAST-1, ILAST-1 ) ) 
        !           533:      $         ) ) ) THEN
1.1       bertrand  534:                H( ILAST, ILAST-1 ) = ZERO
                    535:                GO TO 80
                    536:             END IF
                    537:          END IF
                    538: *
                    539:          IF( ABS( T( ILAST, ILAST ) ).LE.BTOL ) THEN
                    540:             T( ILAST, ILAST ) = ZERO
                    541:             GO TO 70
                    542:          END IF
                    543: *
                    544: *        General case: j<ILAST
                    545: *
                    546:          DO 60 J = ILAST - 1, ILO, -1
                    547: *
                    548: *           Test 1: for H(j,j-1)=0 or j=ILO
                    549: *
                    550:             IF( J.EQ.ILO ) THEN
                    551:                ILAZRO = .TRUE.
                    552:             ELSE
1.21    ! bertrand  553:                IF( ABS( H( J, J-1 ) ).LE.MAX( SAFMIN, ULP*( 
        !           554:      $         ABS( H( J, J ) ) + ABS( H( J-1, J-1 ) ) 
        !           555:      $         ) ) ) THEN
1.1       bertrand  556:                   H( J, J-1 ) = ZERO
                    557:                   ILAZRO = .TRUE.
                    558:                ELSE
                    559:                   ILAZRO = .FALSE.
                    560:                END IF
                    561:             END IF
                    562: *
                    563: *           Test 2: for T(j,j)=0
                    564: *
                    565:             IF( ABS( T( J, J ) ).LT.BTOL ) THEN
                    566:                T( J, J ) = ZERO
                    567: *
                    568: *              Test 1a: Check for 2 consecutive small subdiagonals in A
                    569: *
                    570:                ILAZR2 = .FALSE.
                    571:                IF( .NOT.ILAZRO ) THEN
                    572:                   TEMP = ABS( H( J, J-1 ) )
                    573:                   TEMP2 = ABS( H( J, J ) )
                    574:                   TEMPR = MAX( TEMP, TEMP2 )
                    575:                   IF( TEMPR.LT.ONE .AND. TEMPR.NE.ZERO ) THEN
                    576:                      TEMP = TEMP / TEMPR
                    577:                      TEMP2 = TEMP2 / TEMPR
                    578:                   END IF
                    579:                   IF( TEMP*( ASCALE*ABS( H( J+1, J ) ) ).LE.TEMP2*
                    580:      $                ( ASCALE*ATOL ) )ILAZR2 = .TRUE.
                    581:                END IF
                    582: *
                    583: *              If both tests pass (1 & 2), i.e., the leading diagonal
                    584: *              element of B in the block is zero, split a 1x1 block off
                    585: *              at the top. (I.e., at the J-th row/column) The leading
                    586: *              diagonal element of the remainder can also be zero, so
                    587: *              this may have to be done repeatedly.
                    588: *
                    589:                IF( ILAZRO .OR. ILAZR2 ) THEN
                    590:                   DO 40 JCH = J, ILAST - 1
                    591:                      TEMP = H( JCH, JCH )
                    592:                      CALL DLARTG( TEMP, H( JCH+1, JCH ), C, S,
                    593:      $                            H( JCH, JCH ) )
                    594:                      H( JCH+1, JCH ) = ZERO
                    595:                      CALL DROT( ILASTM-JCH, H( JCH, JCH+1 ), LDH,
                    596:      $                          H( JCH+1, JCH+1 ), LDH, C, S )
                    597:                      CALL DROT( ILASTM-JCH, T( JCH, JCH+1 ), LDT,
                    598:      $                          T( JCH+1, JCH+1 ), LDT, C, S )
                    599:                      IF( ILQ )
                    600:      $                  CALL DROT( N, Q( 1, JCH ), 1, Q( 1, JCH+1 ), 1,
                    601:      $                             C, S )
                    602:                      IF( ILAZR2 )
                    603:      $                  H( JCH, JCH-1 ) = H( JCH, JCH-1 )*C
                    604:                      ILAZR2 = .FALSE.
                    605:                      IF( ABS( T( JCH+1, JCH+1 ) ).GE.BTOL ) THEN
                    606:                         IF( JCH+1.GE.ILAST ) THEN
                    607:                            GO TO 80
                    608:                         ELSE
                    609:                            IFIRST = JCH + 1
                    610:                            GO TO 110
                    611:                         END IF
                    612:                      END IF
                    613:                      T( JCH+1, JCH+1 ) = ZERO
                    614:    40             CONTINUE
                    615:                   GO TO 70
                    616:                ELSE
                    617: *
                    618: *                 Only test 2 passed -- chase the zero to T(ILAST,ILAST)
                    619: *                 Then process as in the case T(ILAST,ILAST)=0
                    620: *
                    621:                   DO 50 JCH = J, ILAST - 1
                    622:                      TEMP = T( JCH, JCH+1 )
                    623:                      CALL DLARTG( TEMP, T( JCH+1, JCH+1 ), C, S,
                    624:      $                            T( JCH, JCH+1 ) )
                    625:                      T( JCH+1, JCH+1 ) = ZERO
                    626:                      IF( JCH.LT.ILASTM-1 )
                    627:      $                  CALL DROT( ILASTM-JCH-1, T( JCH, JCH+2 ), LDT,
                    628:      $                             T( JCH+1, JCH+2 ), LDT, C, S )
                    629:                      CALL DROT( ILASTM-JCH+2, H( JCH, JCH-1 ), LDH,
                    630:      $                          H( JCH+1, JCH-1 ), LDH, C, S )
                    631:                      IF( ILQ )
                    632:      $                  CALL DROT( N, Q( 1, JCH ), 1, Q( 1, JCH+1 ), 1,
                    633:      $                             C, S )
                    634:                      TEMP = H( JCH+1, JCH )
                    635:                      CALL DLARTG( TEMP, H( JCH+1, JCH-1 ), C, S,
                    636:      $                            H( JCH+1, JCH ) )
                    637:                      H( JCH+1, JCH-1 ) = ZERO
                    638:                      CALL DROT( JCH+1-IFRSTM, H( IFRSTM, JCH ), 1,
                    639:      $                          H( IFRSTM, JCH-1 ), 1, C, S )
                    640:                      CALL DROT( JCH-IFRSTM, T( IFRSTM, JCH ), 1,
                    641:      $                          T( IFRSTM, JCH-1 ), 1, C, S )
                    642:                      IF( ILZ )
                    643:      $                  CALL DROT( N, Z( 1, JCH ), 1, Z( 1, JCH-1 ), 1,
                    644:      $                             C, S )
                    645:    50             CONTINUE
                    646:                   GO TO 70
                    647:                END IF
                    648:             ELSE IF( ILAZRO ) THEN
                    649: *
                    650: *              Only test 1 passed -- work on J:ILAST
                    651: *
                    652:                IFIRST = J
                    653:                GO TO 110
                    654:             END IF
                    655: *
                    656: *           Neither test passed -- try next J
                    657: *
                    658:    60    CONTINUE
                    659: *
                    660: *        (Drop-through is "impossible")
                    661: *
                    662:          INFO = N + 1
                    663:          GO TO 420
                    664: *
                    665: *        T(ILAST,ILAST)=0 -- clear H(ILAST,ILAST-1) to split off a
                    666: *        1x1 block.
                    667: *
                    668:    70    CONTINUE
                    669:          TEMP = H( ILAST, ILAST )
                    670:          CALL DLARTG( TEMP, H( ILAST, ILAST-1 ), C, S,
                    671:      $                H( ILAST, ILAST ) )
                    672:          H( ILAST, ILAST-1 ) = ZERO
                    673:          CALL DROT( ILAST-IFRSTM, H( IFRSTM, ILAST ), 1,
                    674:      $              H( IFRSTM, ILAST-1 ), 1, C, S )
                    675:          CALL DROT( ILAST-IFRSTM, T( IFRSTM, ILAST ), 1,
                    676:      $              T( IFRSTM, ILAST-1 ), 1, C, S )
                    677:          IF( ILZ )
                    678:      $      CALL DROT( N, Z( 1, ILAST ), 1, Z( 1, ILAST-1 ), 1, C, S )
                    679: *
                    680: *        H(ILAST,ILAST-1)=0 -- Standardize B, set ALPHAR, ALPHAI,
                    681: *                              and BETA
                    682: *
                    683:    80    CONTINUE
                    684:          IF( T( ILAST, ILAST ).LT.ZERO ) THEN
                    685:             IF( ILSCHR ) THEN
                    686:                DO 90 J = IFRSTM, ILAST
                    687:                   H( J, ILAST ) = -H( J, ILAST )
                    688:                   T( J, ILAST ) = -T( J, ILAST )
                    689:    90          CONTINUE
                    690:             ELSE
                    691:                H( ILAST, ILAST ) = -H( ILAST, ILAST )
                    692:                T( ILAST, ILAST ) = -T( ILAST, ILAST )
                    693:             END IF
                    694:             IF( ILZ ) THEN
                    695:                DO 100 J = 1, N
                    696:                   Z( J, ILAST ) = -Z( J, ILAST )
                    697:   100          CONTINUE
                    698:             END IF
                    699:          END IF
                    700:          ALPHAR( ILAST ) = H( ILAST, ILAST )
                    701:          ALPHAI( ILAST ) = ZERO
                    702:          BETA( ILAST ) = T( ILAST, ILAST )
                    703: *
                    704: *        Go to next block -- exit if finished.
                    705: *
                    706:          ILAST = ILAST - 1
                    707:          IF( ILAST.LT.ILO )
                    708:      $      GO TO 380
                    709: *
                    710: *        Reset counters
                    711: *
                    712:          IITER = 0
                    713:          ESHIFT = ZERO
                    714:          IF( .NOT.ILSCHR ) THEN
                    715:             ILASTM = ILAST
                    716:             IF( IFRSTM.GT.ILAST )
                    717:      $         IFRSTM = ILO
                    718:          END IF
                    719:          GO TO 350
                    720: *
                    721: *        QZ step
                    722: *
                    723: *        This iteration only involves rows/columns IFIRST:ILAST. We
                    724: *        assume IFIRST < ILAST, and that the diagonal of B is non-zero.
                    725: *
                    726:   110    CONTINUE
                    727:          IITER = IITER + 1
                    728:          IF( .NOT.ILSCHR ) THEN
                    729:             IFRSTM = IFIRST
                    730:          END IF
                    731: *
                    732: *        Compute single shifts.
                    733: *
                    734: *        At this point, IFIRST < ILAST, and the diagonal elements of
                    735: *        T(IFIRST:ILAST,IFIRST,ILAST) are larger than BTOL (in
                    736: *        magnitude)
                    737: *
                    738:          IF( ( IITER / 10 )*10.EQ.IITER ) THEN
                    739: *
                    740: *           Exceptional shift.  Chosen for no particularly good reason.
                    741: *           (Single shift only.)
                    742: *
1.14      bertrand  743:             IF( ( DBLE( MAXIT )*SAFMIN )*ABS( H( ILAST, ILAST-1 ) ).LT.
1.1       bertrand  744:      $          ABS( T( ILAST-1, ILAST-1 ) ) ) THEN
1.14      bertrand  745:                ESHIFT = H( ILAST, ILAST-1 ) /
1.1       bertrand  746:      $                  T( ILAST-1, ILAST-1 )
                    747:             ELSE
                    748:                ESHIFT = ESHIFT + ONE / ( SAFMIN*DBLE( MAXIT ) )
                    749:             END IF
                    750:             S1 = ONE
                    751:             WR = ESHIFT
                    752: *
                    753:          ELSE
                    754: *
                    755: *           Shifts based on the generalized eigenvalues of the
                    756: *           bottom-right 2x2 block of A and B. The first eigenvalue
                    757: *           returned by DLAG2 is the Wilkinson shift (AEP p.512),
                    758: *
                    759:             CALL DLAG2( H( ILAST-1, ILAST-1 ), LDH,
                    760:      $                  T( ILAST-1, ILAST-1 ), LDT, SAFMIN*SAFETY, S1,
                    761:      $                  S2, WR, WR2, WI )
                    762: *
1.14      bertrand  763:             IF ( ABS( (WR/S1)*T( ILAST, ILAST ) - H( ILAST, ILAST ) )
1.18      bertrand  764:      $         .GT. ABS( (WR2/S2)*T( ILAST, ILAST )
1.14      bertrand  765:      $         - H( ILAST, ILAST ) ) ) THEN
                    766:                TEMP = WR
                    767:                WR = WR2
                    768:                WR2 = TEMP
                    769:                TEMP = S1
                    770:                S1 = S2
                    771:                S2 = TEMP
                    772:             END IF
1.1       bertrand  773:             TEMP = MAX( S1, SAFMIN*MAX( ONE, ABS( WR ), ABS( WI ) ) )
                    774:             IF( WI.NE.ZERO )
                    775:      $         GO TO 200
                    776:          END IF
                    777: *
                    778: *        Fiddle with shift to avoid overflow
                    779: *
                    780:          TEMP = MIN( ASCALE, ONE )*( HALF*SAFMAX )
                    781:          IF( S1.GT.TEMP ) THEN
                    782:             SCALE = TEMP / S1
                    783:          ELSE
                    784:             SCALE = ONE
                    785:          END IF
                    786: *
                    787:          TEMP = MIN( BSCALE, ONE )*( HALF*SAFMAX )
                    788:          IF( ABS( WR ).GT.TEMP )
                    789:      $      SCALE = MIN( SCALE, TEMP / ABS( WR ) )
                    790:          S1 = SCALE*S1
                    791:          WR = SCALE*WR
                    792: *
                    793: *        Now check for two consecutive small subdiagonals.
                    794: *
                    795:          DO 120 J = ILAST - 1, IFIRST + 1, -1
                    796:             ISTART = J
                    797:             TEMP = ABS( S1*H( J, J-1 ) )
                    798:             TEMP2 = ABS( S1*H( J, J )-WR*T( J, J ) )
                    799:             TEMPR = MAX( TEMP, TEMP2 )
                    800:             IF( TEMPR.LT.ONE .AND. TEMPR.NE.ZERO ) THEN
                    801:                TEMP = TEMP / TEMPR
                    802:                TEMP2 = TEMP2 / TEMPR
                    803:             END IF
                    804:             IF( ABS( ( ASCALE*H( J+1, J ) )*TEMP ).LE.( ASCALE*ATOL )*
                    805:      $          TEMP2 )GO TO 130
                    806:   120    CONTINUE
                    807: *
                    808:          ISTART = IFIRST
                    809:   130    CONTINUE
                    810: *
                    811: *        Do an implicit single-shift QZ sweep.
                    812: *
                    813: *        Initial Q
                    814: *
                    815:          TEMP = S1*H( ISTART, ISTART ) - WR*T( ISTART, ISTART )
                    816:          TEMP2 = S1*H( ISTART+1, ISTART )
                    817:          CALL DLARTG( TEMP, TEMP2, C, S, TEMPR )
                    818: *
                    819: *        Sweep
                    820: *
                    821:          DO 190 J = ISTART, ILAST - 1
                    822:             IF( J.GT.ISTART ) THEN
                    823:                TEMP = H( J, J-1 )
                    824:                CALL DLARTG( TEMP, H( J+1, J-1 ), C, S, H( J, J-1 ) )
                    825:                H( J+1, J-1 ) = ZERO
                    826:             END IF
                    827: *
                    828:             DO 140 JC = J, ILASTM
                    829:                TEMP = C*H( J, JC ) + S*H( J+1, JC )
                    830:                H( J+1, JC ) = -S*H( J, JC ) + C*H( J+1, JC )
                    831:                H( J, JC ) = TEMP
                    832:                TEMP2 = C*T( J, JC ) + S*T( J+1, JC )
                    833:                T( J+1, JC ) = -S*T( J, JC ) + C*T( J+1, JC )
                    834:                T( J, JC ) = TEMP2
                    835:   140       CONTINUE
                    836:             IF( ILQ ) THEN
                    837:                DO 150 JR = 1, N
                    838:                   TEMP = C*Q( JR, J ) + S*Q( JR, J+1 )
                    839:                   Q( JR, J+1 ) = -S*Q( JR, J ) + C*Q( JR, J+1 )
                    840:                   Q( JR, J ) = TEMP
                    841:   150          CONTINUE
                    842:             END IF
                    843: *
                    844:             TEMP = T( J+1, J+1 )
                    845:             CALL DLARTG( TEMP, T( J+1, J ), C, S, T( J+1, J+1 ) )
                    846:             T( J+1, J ) = ZERO
                    847: *
                    848:             DO 160 JR = IFRSTM, MIN( J+2, ILAST )
                    849:                TEMP = C*H( JR, J+1 ) + S*H( JR, J )
                    850:                H( JR, J ) = -S*H( JR, J+1 ) + C*H( JR, J )
                    851:                H( JR, J+1 ) = TEMP
                    852:   160       CONTINUE
                    853:             DO 170 JR = IFRSTM, J
                    854:                TEMP = C*T( JR, J+1 ) + S*T( JR, J )
                    855:                T( JR, J ) = -S*T( JR, J+1 ) + C*T( JR, J )
                    856:                T( JR, J+1 ) = TEMP
                    857:   170       CONTINUE
                    858:             IF( ILZ ) THEN
                    859:                DO 180 JR = 1, N
                    860:                   TEMP = C*Z( JR, J+1 ) + S*Z( JR, J )
                    861:                   Z( JR, J ) = -S*Z( JR, J+1 ) + C*Z( JR, J )
                    862:                   Z( JR, J+1 ) = TEMP
                    863:   180          CONTINUE
                    864:             END IF
                    865:   190    CONTINUE
                    866: *
                    867:          GO TO 350
                    868: *
                    869: *        Use Francis double-shift
                    870: *
                    871: *        Note: the Francis double-shift should work with real shifts,
                    872: *              but only if the block is at least 3x3.
                    873: *              This code may break if this point is reached with
                    874: *              a 2x2 block with real eigenvalues.
                    875: *
                    876:   200    CONTINUE
                    877:          IF( IFIRST+1.EQ.ILAST ) THEN
                    878: *
                    879: *           Special case -- 2x2 block with complex eigenvectors
                    880: *
                    881: *           Step 1: Standardize, that is, rotate so that
                    882: *
                    883: *                       ( B11  0  )
                    884: *                   B = (         )  with B11 non-negative.
                    885: *                       (  0  B22 )
                    886: *
                    887:             CALL DLASV2( T( ILAST-1, ILAST-1 ), T( ILAST-1, ILAST ),
                    888:      $                   T( ILAST, ILAST ), B22, B11, SR, CR, SL, CL )
                    889: *
                    890:             IF( B11.LT.ZERO ) THEN
                    891:                CR = -CR
                    892:                SR = -SR
                    893:                B11 = -B11
                    894:                B22 = -B22
                    895:             END IF
                    896: *
                    897:             CALL DROT( ILASTM+1-IFIRST, H( ILAST-1, ILAST-1 ), LDH,
                    898:      $                 H( ILAST, ILAST-1 ), LDH, CL, SL )
                    899:             CALL DROT( ILAST+1-IFRSTM, H( IFRSTM, ILAST-1 ), 1,
                    900:      $                 H( IFRSTM, ILAST ), 1, CR, SR )
                    901: *
                    902:             IF( ILAST.LT.ILASTM )
                    903:      $         CALL DROT( ILASTM-ILAST, T( ILAST-1, ILAST+1 ), LDT,
                    904:      $                    T( ILAST, ILAST+1 ), LDT, CL, SL )
                    905:             IF( IFRSTM.LT.ILAST-1 )
                    906:      $         CALL DROT( IFIRST-IFRSTM, T( IFRSTM, ILAST-1 ), 1,
                    907:      $                    T( IFRSTM, ILAST ), 1, CR, SR )
                    908: *
                    909:             IF( ILQ )
                    910:      $         CALL DROT( N, Q( 1, ILAST-1 ), 1, Q( 1, ILAST ), 1, CL,
                    911:      $                    SL )
                    912:             IF( ILZ )
                    913:      $         CALL DROT( N, Z( 1, ILAST-1 ), 1, Z( 1, ILAST ), 1, CR,
                    914:      $                    SR )
                    915: *
                    916:             T( ILAST-1, ILAST-1 ) = B11
                    917:             T( ILAST-1, ILAST ) = ZERO
                    918:             T( ILAST, ILAST-1 ) = ZERO
                    919:             T( ILAST, ILAST ) = B22
                    920: *
                    921: *           If B22 is negative, negate column ILAST
                    922: *
                    923:             IF( B22.LT.ZERO ) THEN
                    924:                DO 210 J = IFRSTM, ILAST
                    925:                   H( J, ILAST ) = -H( J, ILAST )
                    926:                   T( J, ILAST ) = -T( J, ILAST )
                    927:   210          CONTINUE
                    928: *
                    929:                IF( ILZ ) THEN
                    930:                   DO 220 J = 1, N
                    931:                      Z( J, ILAST ) = -Z( J, ILAST )
                    932:   220             CONTINUE
                    933:                END IF
1.11      bertrand  934:                B22 = -B22
1.1       bertrand  935:             END IF
                    936: *
                    937: *           Step 2: Compute ALPHAR, ALPHAI, and BETA (see refs.)
                    938: *
                    939: *           Recompute shift
                    940: *
                    941:             CALL DLAG2( H( ILAST-1, ILAST-1 ), LDH,
                    942:      $                  T( ILAST-1, ILAST-1 ), LDT, SAFMIN*SAFETY, S1,
                    943:      $                  TEMP, WR, TEMP2, WI )
                    944: *
                    945: *           If standardization has perturbed the shift onto real line,
                    946: *           do another (real single-shift) QR step.
                    947: *
                    948:             IF( WI.EQ.ZERO )
                    949:      $         GO TO 350
                    950:             S1INV = ONE / S1
                    951: *
                    952: *           Do EISPACK (QZVAL) computation of alpha and beta
                    953: *
                    954:             A11 = H( ILAST-1, ILAST-1 )
                    955:             A21 = H( ILAST, ILAST-1 )
                    956:             A12 = H( ILAST-1, ILAST )
                    957:             A22 = H( ILAST, ILAST )
                    958: *
                    959: *           Compute complex Givens rotation on right
                    960: *           (Assume some element of C = (sA - wB) > unfl )
                    961: *                            __
                    962: *           (sA - wB) ( CZ   -SZ )
                    963: *                     ( SZ    CZ )
                    964: *
                    965:             C11R = S1*A11 - WR*B11
                    966:             C11I = -WI*B11
                    967:             C12 = S1*A12
                    968:             C21 = S1*A21
                    969:             C22R = S1*A22 - WR*B22
                    970:             C22I = -WI*B22
                    971: *
                    972:             IF( ABS( C11R )+ABS( C11I )+ABS( C12 ).GT.ABS( C21 )+
                    973:      $          ABS( C22R )+ABS( C22I ) ) THEN
                    974:                T1 = DLAPY3( C12, C11R, C11I )
                    975:                CZ = C12 / T1
                    976:                SZR = -C11R / T1
                    977:                SZI = -C11I / T1
                    978:             ELSE
                    979:                CZ = DLAPY2( C22R, C22I )
                    980:                IF( CZ.LE.SAFMIN ) THEN
                    981:                   CZ = ZERO
                    982:                   SZR = ONE
                    983:                   SZI = ZERO
                    984:                ELSE
                    985:                   TEMPR = C22R / CZ
                    986:                   TEMPI = C22I / CZ
                    987:                   T1 = DLAPY2( CZ, C21 )
                    988:                   CZ = CZ / T1
                    989:                   SZR = -C21*TEMPR / T1
                    990:                   SZI = C21*TEMPI / T1
                    991:                END IF
                    992:             END IF
                    993: *
                    994: *           Compute Givens rotation on left
                    995: *
                    996: *           (  CQ   SQ )
                    997: *           (  __      )  A or B
                    998: *           ( -SQ   CQ )
                    999: *
                   1000:             AN = ABS( A11 ) + ABS( A12 ) + ABS( A21 ) + ABS( A22 )
                   1001:             BN = ABS( B11 ) + ABS( B22 )
                   1002:             WABS = ABS( WR ) + ABS( WI )
                   1003:             IF( S1*AN.GT.WABS*BN ) THEN
                   1004:                CQ = CZ*B11
                   1005:                SQR = SZR*B22
                   1006:                SQI = -SZI*B22
                   1007:             ELSE
                   1008:                A1R = CZ*A11 + SZR*A12
                   1009:                A1I = SZI*A12
                   1010:                A2R = CZ*A21 + SZR*A22
                   1011:                A2I = SZI*A22
                   1012:                CQ = DLAPY2( A1R, A1I )
                   1013:                IF( CQ.LE.SAFMIN ) THEN
                   1014:                   CQ = ZERO
                   1015:                   SQR = ONE
                   1016:                   SQI = ZERO
                   1017:                ELSE
                   1018:                   TEMPR = A1R / CQ
                   1019:                   TEMPI = A1I / CQ
                   1020:                   SQR = TEMPR*A2R + TEMPI*A2I
                   1021:                   SQI = TEMPI*A2R - TEMPR*A2I
                   1022:                END IF
                   1023:             END IF
                   1024:             T1 = DLAPY3( CQ, SQR, SQI )
                   1025:             CQ = CQ / T1
                   1026:             SQR = SQR / T1
                   1027:             SQI = SQI / T1
                   1028: *
                   1029: *           Compute diagonal elements of QBZ
                   1030: *
                   1031:             TEMPR = SQR*SZR - SQI*SZI
                   1032:             TEMPI = SQR*SZI + SQI*SZR
                   1033:             B1R = CQ*CZ*B11 + TEMPR*B22
                   1034:             B1I = TEMPI*B22
                   1035:             B1A = DLAPY2( B1R, B1I )
                   1036:             B2R = CQ*CZ*B22 + TEMPR*B11
                   1037:             B2I = -TEMPI*B11
                   1038:             B2A = DLAPY2( B2R, B2I )
                   1039: *
                   1040: *           Normalize so beta > 0, and Im( alpha1 ) > 0
                   1041: *
                   1042:             BETA( ILAST-1 ) = B1A
                   1043:             BETA( ILAST ) = B2A
                   1044:             ALPHAR( ILAST-1 ) = ( WR*B1A )*S1INV
                   1045:             ALPHAI( ILAST-1 ) = ( WI*B1A )*S1INV
                   1046:             ALPHAR( ILAST ) = ( WR*B2A )*S1INV
                   1047:             ALPHAI( ILAST ) = -( WI*B2A )*S1INV
                   1048: *
                   1049: *           Step 3: Go to next block -- exit if finished.
                   1050: *
                   1051:             ILAST = IFIRST - 1
                   1052:             IF( ILAST.LT.ILO )
                   1053:      $         GO TO 380
                   1054: *
                   1055: *           Reset counters
                   1056: *
                   1057:             IITER = 0
                   1058:             ESHIFT = ZERO
                   1059:             IF( .NOT.ILSCHR ) THEN
                   1060:                ILASTM = ILAST
                   1061:                IF( IFRSTM.GT.ILAST )
                   1062:      $            IFRSTM = ILO
                   1063:             END IF
                   1064:             GO TO 350
                   1065:          ELSE
                   1066: *
                   1067: *           Usual case: 3x3 or larger block, using Francis implicit
                   1068: *                       double-shift
                   1069: *
                   1070: *                                    2
                   1071: *           Eigenvalue equation is  w  - c w + d = 0,
                   1072: *
                   1073: *                                         -1 2        -1
                   1074: *           so compute 1st column of  (A B  )  - c A B   + d
                   1075: *           using the formula in QZIT (from EISPACK)
                   1076: *
                   1077: *           We assume that the block is at least 3x3
                   1078: *
                   1079:             AD11 = ( ASCALE*H( ILAST-1, ILAST-1 ) ) /
                   1080:      $             ( BSCALE*T( ILAST-1, ILAST-1 ) )
                   1081:             AD21 = ( ASCALE*H( ILAST, ILAST-1 ) ) /
                   1082:      $             ( BSCALE*T( ILAST-1, ILAST-1 ) )
                   1083:             AD12 = ( ASCALE*H( ILAST-1, ILAST ) ) /
                   1084:      $             ( BSCALE*T( ILAST, ILAST ) )
                   1085:             AD22 = ( ASCALE*H( ILAST, ILAST ) ) /
                   1086:      $             ( BSCALE*T( ILAST, ILAST ) )
                   1087:             U12 = T( ILAST-1, ILAST ) / T( ILAST, ILAST )
                   1088:             AD11L = ( ASCALE*H( IFIRST, IFIRST ) ) /
                   1089:      $              ( BSCALE*T( IFIRST, IFIRST ) )
                   1090:             AD21L = ( ASCALE*H( IFIRST+1, IFIRST ) ) /
                   1091:      $              ( BSCALE*T( IFIRST, IFIRST ) )
                   1092:             AD12L = ( ASCALE*H( IFIRST, IFIRST+1 ) ) /
                   1093:      $              ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
                   1094:             AD22L = ( ASCALE*H( IFIRST+1, IFIRST+1 ) ) /
                   1095:      $              ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
                   1096:             AD32L = ( ASCALE*H( IFIRST+2, IFIRST+1 ) ) /
                   1097:      $              ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
                   1098:             U12L = T( IFIRST, IFIRST+1 ) / T( IFIRST+1, IFIRST+1 )
                   1099: *
                   1100:             V( 1 ) = ( AD11-AD11L )*( AD22-AD11L ) - AD12*AD21 +
                   1101:      $               AD21*U12*AD11L + ( AD12L-AD11L*U12L )*AD21L
                   1102:             V( 2 ) = ( ( AD22L-AD11L )-AD21L*U12L-( AD11-AD11L )-
                   1103:      $               ( AD22-AD11L )+AD21*U12 )*AD21L
                   1104:             V( 3 ) = AD32L*AD21L
                   1105: *
                   1106:             ISTART = IFIRST
                   1107: *
                   1108:             CALL DLARFG( 3, V( 1 ), V( 2 ), 1, TAU )
                   1109:             V( 1 ) = ONE
                   1110: *
                   1111: *           Sweep
                   1112: *
                   1113:             DO 290 J = ISTART, ILAST - 2
                   1114: *
                   1115: *              All but last elements: use 3x3 Householder transforms.
                   1116: *
                   1117: *              Zero (j-1)st column of A
                   1118: *
                   1119:                IF( J.GT.ISTART ) THEN
                   1120:                   V( 1 ) = H( J, J-1 )
                   1121:                   V( 2 ) = H( J+1, J-1 )
                   1122:                   V( 3 ) = H( J+2, J-1 )
                   1123: *
                   1124:                   CALL DLARFG( 3, H( J, J-1 ), V( 2 ), 1, TAU )
                   1125:                   V( 1 ) = ONE
                   1126:                   H( J+1, J-1 ) = ZERO
                   1127:                   H( J+2, J-1 ) = ZERO
                   1128:                END IF
                   1129: *
                   1130:                DO 230 JC = J, ILASTM
                   1131:                   TEMP = TAU*( H( J, JC )+V( 2 )*H( J+1, JC )+V( 3 )*
                   1132:      $                   H( J+2, JC ) )
                   1133:                   H( J, JC ) = H( J, JC ) - TEMP
                   1134:                   H( J+1, JC ) = H( J+1, JC ) - TEMP*V( 2 )
                   1135:                   H( J+2, JC ) = H( J+2, JC ) - TEMP*V( 3 )
                   1136:                   TEMP2 = TAU*( T( J, JC )+V( 2 )*T( J+1, JC )+V( 3 )*
                   1137:      $                    T( J+2, JC ) )
                   1138:                   T( J, JC ) = T( J, JC ) - TEMP2
                   1139:                   T( J+1, JC ) = T( J+1, JC ) - TEMP2*V( 2 )
                   1140:                   T( J+2, JC ) = T( J+2, JC ) - TEMP2*V( 3 )
                   1141:   230          CONTINUE
                   1142:                IF( ILQ ) THEN
                   1143:                   DO 240 JR = 1, N
                   1144:                      TEMP = TAU*( Q( JR, J )+V( 2 )*Q( JR, J+1 )+V( 3 )*
                   1145:      $                      Q( JR, J+2 ) )
                   1146:                      Q( JR, J ) = Q( JR, J ) - TEMP
                   1147:                      Q( JR, J+1 ) = Q( JR, J+1 ) - TEMP*V( 2 )
                   1148:                      Q( JR, J+2 ) = Q( JR, J+2 ) - TEMP*V( 3 )
                   1149:   240             CONTINUE
                   1150:                END IF
                   1151: *
                   1152: *              Zero j-th column of B (see DLAGBC for details)
                   1153: *
                   1154: *              Swap rows to pivot
                   1155: *
                   1156:                ILPIVT = .FALSE.
                   1157:                TEMP = MAX( ABS( T( J+1, J+1 ) ), ABS( T( J+1, J+2 ) ) )
                   1158:                TEMP2 = MAX( ABS( T( J+2, J+1 ) ), ABS( T( J+2, J+2 ) ) )
                   1159:                IF( MAX( TEMP, TEMP2 ).LT.SAFMIN ) THEN
                   1160:                   SCALE = ZERO
                   1161:                   U1 = ONE
                   1162:                   U2 = ZERO
                   1163:                   GO TO 250
                   1164:                ELSE IF( TEMP.GE.TEMP2 ) THEN
                   1165:                   W11 = T( J+1, J+1 )
                   1166:                   W21 = T( J+2, J+1 )
                   1167:                   W12 = T( J+1, J+2 )
                   1168:                   W22 = T( J+2, J+2 )
                   1169:                   U1 = T( J+1, J )
                   1170:                   U2 = T( J+2, J )
                   1171:                ELSE
                   1172:                   W21 = T( J+1, J+1 )
                   1173:                   W11 = T( J+2, J+1 )
                   1174:                   W22 = T( J+1, J+2 )
                   1175:                   W12 = T( J+2, J+2 )
                   1176:                   U2 = T( J+1, J )
                   1177:                   U1 = T( J+2, J )
                   1178:                END IF
                   1179: *
                   1180: *              Swap columns if nec.
                   1181: *
                   1182:                IF( ABS( W12 ).GT.ABS( W11 ) ) THEN
                   1183:                   ILPIVT = .TRUE.
                   1184:                   TEMP = W12
                   1185:                   TEMP2 = W22
                   1186:                   W12 = W11
                   1187:                   W22 = W21
                   1188:                   W11 = TEMP
                   1189:                   W21 = TEMP2
                   1190:                END IF
                   1191: *
                   1192: *              LU-factor
                   1193: *
                   1194:                TEMP = W21 / W11
                   1195:                U2 = U2 - TEMP*U1
                   1196:                W22 = W22 - TEMP*W12
                   1197:                W21 = ZERO
                   1198: *
                   1199: *              Compute SCALE
                   1200: *
                   1201:                SCALE = ONE
                   1202:                IF( ABS( W22 ).LT.SAFMIN ) THEN
                   1203:                   SCALE = ZERO
                   1204:                   U2 = ONE
                   1205:                   U1 = -W12 / W11
                   1206:                   GO TO 250
                   1207:                END IF
                   1208:                IF( ABS( W22 ).LT.ABS( U2 ) )
                   1209:      $            SCALE = ABS( W22 / U2 )
                   1210:                IF( ABS( W11 ).LT.ABS( U1 ) )
                   1211:      $            SCALE = MIN( SCALE, ABS( W11 / U1 ) )
                   1212: *
                   1213: *              Solve
                   1214: *
                   1215:                U2 = ( SCALE*U2 ) / W22
                   1216:                U1 = ( SCALE*U1-W12*U2 ) / W11
                   1217: *
                   1218:   250          CONTINUE
                   1219:                IF( ILPIVT ) THEN
                   1220:                   TEMP = U2
                   1221:                   U2 = U1
                   1222:                   U1 = TEMP
                   1223:                END IF
                   1224: *
                   1225: *              Compute Householder Vector
                   1226: *
                   1227:                T1 = SQRT( SCALE**2+U1**2+U2**2 )
                   1228:                TAU = ONE + SCALE / T1
                   1229:                VS = -ONE / ( SCALE+T1 )
                   1230:                V( 1 ) = ONE
                   1231:                V( 2 ) = VS*U1
                   1232:                V( 3 ) = VS*U2
                   1233: *
                   1234: *              Apply transformations from the right.
                   1235: *
                   1236:                DO 260 JR = IFRSTM, MIN( J+3, ILAST )
                   1237:                   TEMP = TAU*( H( JR, J )+V( 2 )*H( JR, J+1 )+V( 3 )*
                   1238:      $                   H( JR, J+2 ) )
                   1239:                   H( JR, J ) = H( JR, J ) - TEMP
                   1240:                   H( JR, J+1 ) = H( JR, J+1 ) - TEMP*V( 2 )
                   1241:                   H( JR, J+2 ) = H( JR, J+2 ) - TEMP*V( 3 )
                   1242:   260          CONTINUE
                   1243:                DO 270 JR = IFRSTM, J + 2
                   1244:                   TEMP = TAU*( T( JR, J )+V( 2 )*T( JR, J+1 )+V( 3 )*
                   1245:      $                   T( JR, J+2 ) )
                   1246:                   T( JR, J ) = T( JR, J ) - TEMP
                   1247:                   T( JR, J+1 ) = T( JR, J+1 ) - TEMP*V( 2 )
                   1248:                   T( JR, J+2 ) = T( JR, J+2 ) - TEMP*V( 3 )
                   1249:   270          CONTINUE
                   1250:                IF( ILZ ) THEN
                   1251:                   DO 280 JR = 1, N
                   1252:                      TEMP = TAU*( Z( JR, J )+V( 2 )*Z( JR, J+1 )+V( 3 )*
                   1253:      $                      Z( JR, J+2 ) )
                   1254:                      Z( JR, J ) = Z( JR, J ) - TEMP
                   1255:                      Z( JR, J+1 ) = Z( JR, J+1 ) - TEMP*V( 2 )
                   1256:                      Z( JR, J+2 ) = Z( JR, J+2 ) - TEMP*V( 3 )
                   1257:   280             CONTINUE
                   1258:                END IF
                   1259:                T( J+1, J ) = ZERO
                   1260:                T( J+2, J ) = ZERO
                   1261:   290       CONTINUE
                   1262: *
                   1263: *           Last elements: Use Givens rotations
                   1264: *
                   1265: *           Rotations from the left
                   1266: *
                   1267:             J = ILAST - 1
                   1268:             TEMP = H( J, J-1 )
                   1269:             CALL DLARTG( TEMP, H( J+1, J-1 ), C, S, H( J, J-1 ) )
                   1270:             H( J+1, J-1 ) = ZERO
                   1271: *
                   1272:             DO 300 JC = J, ILASTM
                   1273:                TEMP = C*H( J, JC ) + S*H( J+1, JC )
                   1274:                H( J+1, JC ) = -S*H( J, JC ) + C*H( J+1, JC )
                   1275:                H( J, JC ) = TEMP
                   1276:                TEMP2 = C*T( J, JC ) + S*T( J+1, JC )
                   1277:                T( J+1, JC ) = -S*T( J, JC ) + C*T( J+1, JC )
                   1278:                T( J, JC ) = TEMP2
                   1279:   300       CONTINUE
                   1280:             IF( ILQ ) THEN
                   1281:                DO 310 JR = 1, N
                   1282:                   TEMP = C*Q( JR, J ) + S*Q( JR, J+1 )
                   1283:                   Q( JR, J+1 ) = -S*Q( JR, J ) + C*Q( JR, J+1 )
                   1284:                   Q( JR, J ) = TEMP
                   1285:   310          CONTINUE
                   1286:             END IF
                   1287: *
                   1288: *           Rotations from the right.
                   1289: *
                   1290:             TEMP = T( J+1, J+1 )
                   1291:             CALL DLARTG( TEMP, T( J+1, J ), C, S, T( J+1, J+1 ) )
                   1292:             T( J+1, J ) = ZERO
                   1293: *
                   1294:             DO 320 JR = IFRSTM, ILAST
                   1295:                TEMP = C*H( JR, J+1 ) + S*H( JR, J )
                   1296:                H( JR, J ) = -S*H( JR, J+1 ) + C*H( JR, J )
                   1297:                H( JR, J+1 ) = TEMP
                   1298:   320       CONTINUE
                   1299:             DO 330 JR = IFRSTM, ILAST - 1
                   1300:                TEMP = C*T( JR, J+1 ) + S*T( JR, J )
                   1301:                T( JR, J ) = -S*T( JR, J+1 ) + C*T( JR, J )
                   1302:                T( JR, J+1 ) = TEMP
                   1303:   330       CONTINUE
                   1304:             IF( ILZ ) THEN
                   1305:                DO 340 JR = 1, N
                   1306:                   TEMP = C*Z( JR, J+1 ) + S*Z( JR, J )
                   1307:                   Z( JR, J ) = -S*Z( JR, J+1 ) + C*Z( JR, J )
                   1308:                   Z( JR, J+1 ) = TEMP
                   1309:   340          CONTINUE
                   1310:             END IF
                   1311: *
                   1312: *           End of Double-Shift code
                   1313: *
                   1314:          END IF
                   1315: *
                   1316:          GO TO 350
                   1317: *
                   1318: *        End of iteration loop
                   1319: *
                   1320:   350    CONTINUE
                   1321:   360 CONTINUE
                   1322: *
                   1323: *     Drop-through = non-convergence
                   1324: *
                   1325:       INFO = ILAST
                   1326:       GO TO 420
                   1327: *
                   1328: *     Successful completion of all QZ steps
                   1329: *
                   1330:   380 CONTINUE
                   1331: *
                   1332: *     Set Eigenvalues 1:ILO-1
                   1333: *
                   1334:       DO 410 J = 1, ILO - 1
                   1335:          IF( T( J, J ).LT.ZERO ) THEN
                   1336:             IF( ILSCHR ) THEN
                   1337:                DO 390 JR = 1, J
                   1338:                   H( JR, J ) = -H( JR, J )
                   1339:                   T( JR, J ) = -T( JR, J )
                   1340:   390          CONTINUE
                   1341:             ELSE
                   1342:                H( J, J ) = -H( J, J )
                   1343:                T( J, J ) = -T( J, J )
                   1344:             END IF
                   1345:             IF( ILZ ) THEN
                   1346:                DO 400 JR = 1, N
                   1347:                   Z( JR, J ) = -Z( JR, J )
                   1348:   400          CONTINUE
                   1349:             END IF
                   1350:          END IF
                   1351:          ALPHAR( J ) = H( J, J )
                   1352:          ALPHAI( J ) = ZERO
                   1353:          BETA( J ) = T( J, J )
                   1354:   410 CONTINUE
                   1355: *
                   1356: *     Normal Termination
                   1357: *
                   1358:       INFO = 0
                   1359: *
                   1360: *     Exit (other than argument error) -- return optimal workspace size
                   1361: *
                   1362:   420 CONTINUE
                   1363:       WORK( 1 ) = DBLE( N )
                   1364:       RETURN
                   1365: *
                   1366: *     End of DHGEQZ
                   1367: *
                   1368:       END

CVSweb interface <joel.bertrand@systella.fr>