File:  [local] / rpl / lapack / lapack / dhgeqz.f
Revision 1.12: download - view: text, annotated - select for diffs - revision graph
Wed Aug 22 09:48:15 2012 UTC (11 years, 8 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_9, rpl-4_1_10, HEAD
Cohérence

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

CVSweb interface <joel.bertrand@systella.fr>