shgeqz.c
Go to the documentation of this file.
00001 /* shgeqz.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static real c_b12 = 0.f;
00019 static real c_b13 = 1.f;
00020 static integer c__1 = 1;
00021 static integer c__3 = 3;
00022 
00023 /* Subroutine */ int shgeqz_(char *job, char *compq, char *compz, integer *n, 
00024         integer *ilo, integer *ihi, real *h__, integer *ldh, real *t, integer 
00025         *ldt, real *alphar, real *alphai, real *beta, real *q, integer *ldq, 
00026         real *z__, integer *ldz, real *work, integer *lwork, integer *info)
00027 {
00028     /* System generated locals */
00029     integer h_dim1, h_offset, q_dim1, q_offset, t_dim1, t_offset, z_dim1, 
00030             z_offset, i__1, i__2, i__3, i__4;
00031     real r__1, r__2, r__3, r__4;
00032 
00033     /* Builtin functions */
00034     double sqrt(doublereal);
00035 
00036     /* Local variables */
00037     real c__;
00038     integer j;
00039     real s, v[3], s1, s2, t1, u1, u2, a11, a12, a21, a22, b11, b22, c12, c21;
00040     integer jc;
00041     real an, bn, cl, cq, cr;
00042     integer in;
00043     real u12, w11, w12, w21;
00044     integer jr;
00045     real cz, w22, sl, wi, sr, vs, wr, b1a, b2a, a1i, a2i, b1i, b2i, a1r, a2r, 
00046             b1r, b2r, wr2, ad11, ad12, ad21, ad22, c11i, c22i;
00047     integer jch;
00048     real c11r, c22r;
00049     logical ilq;
00050     real u12l, tau, sqi;
00051     logical ilz;
00052     real ulp, sqr, szi, szr, ad11l, ad12l, ad21l, ad22l, ad32l, wabs, atol, 
00053             btol, temp;
00054     extern /* Subroutine */ int srot_(integer *, real *, integer *, real *, 
00055             integer *, real *, real *), slag2_(real *, integer *, real *, 
00056             integer *, real *, real *, real *, real *, real *, real *);
00057     real temp2, s1inv, scale;
00058     extern logical lsame_(char *, char *);
00059     integer iiter, ilast, jiter;
00060     real anorm, bnorm;
00061     integer maxit;
00062     real tempi, tempr;
00063     logical ilazr2;
00064     extern doublereal slapy2_(real *, real *), slapy3_(real *, real *, real *)
00065             ;
00066     extern /* Subroutine */ int slasv2_(real *, real *, real *, real *, real *
00067 , real *, real *, real *, real *);
00068     real ascale, bscale;
00069     extern doublereal slamch_(char *);
00070     real safmin;
00071     extern /* Subroutine */ int slarfg_(integer *, real *, real *, integer *, 
00072             real *);
00073     real safmax;
00074     extern /* Subroutine */ int xerbla_(char *, integer *);
00075     real eshift;
00076     logical ilschr;
00077     integer icompq, ilastm;
00078     extern doublereal slanhs_(char *, integer *, real *, integer *, real *);
00079     extern /* Subroutine */ int slartg_(real *, real *, real *, real *, real *
00080 );
00081     integer ischur;
00082     extern /* Subroutine */ int slaset_(char *, integer *, integer *, real *, 
00083             real *, real *, integer *);
00084     logical ilazro;
00085     integer icompz, ifirst, ifrstm, istart;
00086     logical ilpivt, lquery;
00087 
00088 
00089 /*  -- LAPACK routine (version 3.2.1)                                  -- */
00090 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
00091 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
00092 /*  -- April 2009                                                      -- */
00093 
00094 /*     .. Scalar Arguments .. */
00095 /*     .. */
00096 /*     .. Array Arguments .. */
00097 /*     .. */
00098 
00099 /*  Purpose */
00100 /*  ======= */
00101 
00102 /*  SHGEQZ computes the eigenvalues of a real matrix pair (H,T), */
00103 /*  where H is an upper Hessenberg matrix and T is upper triangular, */
00104 /*  using the double-shift QZ method. */
00105 /*  Matrix pairs of this type are produced by the reduction to */
00106 /*  generalized upper Hessenberg form of a real matrix pair (A,B): */
00107 
00108 /*     A = Q1*H*Z1**T,  B = Q1*T*Z1**T, */
00109 
00110 /*  as computed by SGGHRD. */
00111 
00112 /*  If JOB='S', then the Hessenberg-triangular pair (H,T) is */
00113 /*  also reduced to generalized Schur form, */
00114 
00115 /*     H = Q*S*Z**T,  T = Q*P*Z**T, */
00116 
00117 /*  where Q and Z are orthogonal matrices, P is an upper triangular */
00118 /*  matrix, and S is a quasi-triangular matrix with 1-by-1 and 2-by-2 */
00119 /*  diagonal blocks. */
00120 
00121 /*  The 1-by-1 blocks correspond to real eigenvalues of the matrix pair */
00122 /*  (H,T) and the 2-by-2 blocks correspond to complex conjugate pairs of */
00123 /*  eigenvalues. */
00124 
00125 /*  Additionally, the 2-by-2 upper triangular diagonal blocks of P */
00126 /*  corresponding to 2-by-2 blocks of S are reduced to positive diagonal */
00127 /*  form, i.e., if S(j+1,j) is non-zero, then P(j+1,j) = P(j,j+1) = 0, */
00128 /*  P(j,j) > 0, and P(j+1,j+1) > 0. */
00129 
00130 /*  Optionally, the orthogonal matrix Q from the generalized Schur */
00131 /*  factorization may be postmultiplied into an input matrix Q1, and the */
00132 /*  orthogonal matrix Z may be postmultiplied into an input matrix Z1. */
00133 /*  If Q1 and Z1 are the orthogonal matrices from SGGHRD that reduced */
00134 /*  the matrix pair (A,B) to generalized upper Hessenberg form, then the */
00135 /*  output matrices Q1*Q and Z1*Z are the orthogonal factors from the */
00136 /*  generalized Schur factorization of (A,B): */
00137 
00138 /*     A = (Q1*Q)*S*(Z1*Z)**T,  B = (Q1*Q)*P*(Z1*Z)**T. */
00139 
00140 /*  To avoid overflow, eigenvalues of the matrix pair (H,T) (equivalently, */
00141 /*  of (A,B)) are computed as a pair of values (alpha,beta), where alpha is */
00142 /*  complex and beta real. */
00143 /*  If beta is nonzero, lambda = alpha / beta is an eigenvalue of the */
00144 /*  generalized nonsymmetric eigenvalue problem (GNEP) */
00145 /*     A*x = lambda*B*x */
00146 /*  and if alpha is nonzero, mu = beta / alpha is an eigenvalue of the */
00147 /*  alternate form of the GNEP */
00148 /*     mu*A*y = B*y. */
00149 /*  Real eigenvalues can be read directly from the generalized Schur */
00150 /*  form: */
00151 /*    alpha = S(i,i), beta = P(i,i). */
00152 
00153 /*  Ref: C.B. Moler & G.W. Stewart, "An Algorithm for Generalized Matrix */
00154 /*       Eigenvalue Problems", SIAM J. Numer. Anal., 10(1973), */
00155 /*       pp. 241--256. */
00156 
00157 /*  Arguments */
00158 /*  ========= */
00159 
00160 /*  JOB     (input) CHARACTER*1 */
00161 /*          = 'E': Compute eigenvalues only; */
00162 /*          = 'S': Compute eigenvalues and the Schur form. */
00163 
00164 /*  COMPQ   (input) CHARACTER*1 */
00165 /*          = 'N': Left Schur vectors (Q) are not computed; */
00166 /*          = 'I': Q is initialized to the unit matrix and the matrix Q */
00167 /*                 of left Schur vectors of (H,T) is returned; */
00168 /*          = 'V': Q must contain an orthogonal matrix Q1 on entry and */
00169 /*                 the product Q1*Q is returned. */
00170 
00171 /*  COMPZ   (input) CHARACTER*1 */
00172 /*          = 'N': Right Schur vectors (Z) are not computed; */
00173 /*          = 'I': Z is initialized to the unit matrix and the matrix Z */
00174 /*                 of right Schur vectors of (H,T) is returned; */
00175 /*          = 'V': Z must contain an orthogonal matrix Z1 on entry and */
00176 /*                 the product Z1*Z is returned. */
00177 
00178 /*  N       (input) INTEGER */
00179 /*          The order of the matrices H, T, Q, and Z.  N >= 0. */
00180 
00181 /*  ILO     (input) INTEGER */
00182 /*  IHI     (input) INTEGER */
00183 /*          ILO and IHI mark the rows and columns of H which are in */
00184 /*          Hessenberg form.  It is assumed that A is already upper */
00185 /*          triangular in rows and columns 1:ILO-1 and IHI+1:N. */
00186 /*          If N > 0, 1 <= ILO <= IHI <= N; if N = 0, ILO=1 and IHI=0. */
00187 
00188 /*  H       (input/output) REAL array, dimension (LDH, N) */
00189 /*          On entry, the N-by-N upper Hessenberg matrix H. */
00190 /*          On exit, if JOB = 'S', H contains the upper quasi-triangular */
00191 /*          matrix S from the generalized Schur factorization; */
00192 /*          2-by-2 diagonal blocks (corresponding to complex conjugate */
00193 /*          pairs of eigenvalues) are returned in standard form, with */
00194 /*          H(i,i) = H(i+1,i+1) and H(i+1,i)*H(i,i+1) < 0. */
00195 /*          If JOB = 'E', the diagonal blocks of H match those of S, but */
00196 /*          the rest of H is unspecified. */
00197 
00198 /*  LDH     (input) INTEGER */
00199 /*          The leading dimension of the array H.  LDH >= max( 1, N ). */
00200 
00201 /*  T       (input/output) REAL array, dimension (LDT, N) */
00202 /*          On entry, the N-by-N upper triangular matrix T. */
00203 /*          On exit, if JOB = 'S', T contains the upper triangular */
00204 /*          matrix P from the generalized Schur factorization; */
00205 /*          2-by-2 diagonal blocks of P corresponding to 2-by-2 blocks of S */
00206 /*          are reduced to positive diagonal form, i.e., if H(j+1,j) is */
00207 /*          non-zero, then T(j+1,j) = T(j,j+1) = 0, T(j,j) > 0, and */
00208 /*          T(j+1,j+1) > 0. */
00209 /*          If JOB = 'E', the diagonal blocks of T match those of P, but */
00210 /*          the rest of T is unspecified. */
00211 
00212 /*  LDT     (input) INTEGER */
00213 /*          The leading dimension of the array T.  LDT >= max( 1, N ). */
00214 
00215 /*  ALPHAR  (output) REAL array, dimension (N) */
00216 /*          The real parts of each scalar alpha defining an eigenvalue */
00217 /*          of GNEP. */
00218 
00219 /*  ALPHAI  (output) REAL array, dimension (N) */
00220 /*          The imaginary parts of each scalar alpha defining an */
00221 /*          eigenvalue of GNEP. */
00222 /*          If ALPHAI(j) is zero, then the j-th eigenvalue is real; if */
00223 /*          positive, then the j-th and (j+1)-st eigenvalues are a */
00224 /*          complex conjugate pair, with ALPHAI(j+1) = -ALPHAI(j). */
00225 
00226 /*  BETA    (output) REAL array, dimension (N) */
00227 /*          The scalars beta that define the eigenvalues of GNEP. */
00228 /*          Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and */
00229 /*          beta = BETA(j) represent the j-th eigenvalue of the matrix */
00230 /*          pair (A,B), in one of the forms lambda = alpha/beta or */
00231 /*          mu = beta/alpha.  Since either lambda or mu may overflow, */
00232 /*          they should not, in general, be computed. */
00233 
00234 /*  Q       (input/output) REAL array, dimension (LDQ, N) */
00235 /*          On entry, if COMPZ = 'V', the orthogonal matrix Q1 used in */
00236 /*          the reduction of (A,B) to generalized Hessenberg form. */
00237 /*          On exit, if COMPZ = 'I', the orthogonal matrix of left Schur */
00238 /*          vectors of (H,T), and if COMPZ = 'V', the orthogonal matrix */
00239 /*          of left Schur vectors of (A,B). */
00240 /*          Not referenced if COMPZ = 'N'. */
00241 
00242 /*  LDQ     (input) INTEGER */
00243 /*          The leading dimension of the array Q.  LDQ >= 1. */
00244 /*          If COMPQ='V' or 'I', then LDQ >= N. */
00245 
00246 /*  Z       (input/output) REAL array, dimension (LDZ, N) */
00247 /*          On entry, if COMPZ = 'V', the orthogonal matrix Z1 used in */
00248 /*          the reduction of (A,B) to generalized Hessenberg form. */
00249 /*          On exit, if COMPZ = 'I', the orthogonal matrix of */
00250 /*          right Schur vectors of (H,T), and if COMPZ = 'V', the */
00251 /*          orthogonal matrix of right Schur vectors of (A,B). */
00252 /*          Not referenced if COMPZ = 'N'. */
00253 
00254 /*  LDZ     (input) INTEGER */
00255 /*          The leading dimension of the array Z.  LDZ >= 1. */
00256 /*          If COMPZ='V' or 'I', then LDZ >= N. */
00257 
00258 /*  WORK    (workspace/output) REAL array, dimension (MAX(1,LWORK)) */
00259 /*          On exit, if INFO >= 0, WORK(1) returns the optimal LWORK. */
00260 
00261 /*  LWORK   (input) INTEGER */
00262 /*          The dimension of the array WORK.  LWORK >= max(1,N). */
00263 
00264 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00265 /*          only calculates the optimal size of the WORK array, returns */
00266 /*          this value as the first entry of the WORK array, and no error */
00267 /*          message related to LWORK is issued by XERBLA. */
00268 
00269 /*  INFO    (output) INTEGER */
00270 /*          = 0: successful exit */
00271 /*          < 0: if INFO = -i, the i-th argument had an illegal value */
00272 /*          = 1,...,N: the QZ iteration did not converge.  (H,T) is not */
00273 /*                     in Schur form, but ALPHAR(i), ALPHAI(i), and */
00274 /*                     BETA(i), i=INFO+1,...,N should be correct. */
00275 /*          = N+1,...,2*N: the shift calculation failed.  (H,T) is not */
00276 /*                     in Schur form, but ALPHAR(i), ALPHAI(i), and */
00277 /*                     BETA(i), i=INFO-N+1,...,N should be correct. */
00278 
00279 /*  Further Details */
00280 /*  =============== */
00281 
00282 /*  Iteration counters: */
00283 
00284 /*  JITER  -- counts iterations. */
00285 /*  IITER  -- counts iterations run since ILAST was last */
00286 /*            changed.  This is therefore reset only when a 1-by-1 or */
00287 /*            2-by-2 block deflates off the bottom. */
00288 
00289 /*  ===================================================================== */
00290 
00291 /*     .. Parameters .. */
00292 /*    $                     SAFETY = 1.0E+0 ) */
00293 /*     .. */
00294 /*     .. Local Scalars .. */
00295 /*     .. */
00296 /*     .. Local Arrays .. */
00297 /*     .. */
00298 /*     .. External Functions .. */
00299 /*     .. */
00300 /*     .. External Subroutines .. */
00301 /*     .. */
00302 /*     .. Intrinsic Functions .. */
00303 /*     .. */
00304 /*     .. Executable Statements .. */
00305 
00306 /*     Decode JOB, COMPQ, COMPZ */
00307 
00308     /* Parameter adjustments */
00309     h_dim1 = *ldh;
00310     h_offset = 1 + h_dim1;
00311     h__ -= h_offset;
00312     t_dim1 = *ldt;
00313     t_offset = 1 + t_dim1;
00314     t -= t_offset;
00315     --alphar;
00316     --alphai;
00317     --beta;
00318     q_dim1 = *ldq;
00319     q_offset = 1 + q_dim1;
00320     q -= q_offset;
00321     z_dim1 = *ldz;
00322     z_offset = 1 + z_dim1;
00323     z__ -= z_offset;
00324     --work;
00325 
00326     /* Function Body */
00327     if (lsame_(job, "E")) {
00328         ilschr = FALSE_;
00329         ischur = 1;
00330     } else if (lsame_(job, "S")) {
00331         ilschr = TRUE_;
00332         ischur = 2;
00333     } else {
00334         ischur = 0;
00335     }
00336 
00337     if (lsame_(compq, "N")) {
00338         ilq = FALSE_;
00339         icompq = 1;
00340     } else if (lsame_(compq, "V")) {
00341         ilq = TRUE_;
00342         icompq = 2;
00343     } else if (lsame_(compq, "I")) {
00344         ilq = TRUE_;
00345         icompq = 3;
00346     } else {
00347         icompq = 0;
00348     }
00349 
00350     if (lsame_(compz, "N")) {
00351         ilz = FALSE_;
00352         icompz = 1;
00353     } else if (lsame_(compz, "V")) {
00354         ilz = TRUE_;
00355         icompz = 2;
00356     } else if (lsame_(compz, "I")) {
00357         ilz = TRUE_;
00358         icompz = 3;
00359     } else {
00360         icompz = 0;
00361     }
00362 
00363 /*     Check Argument Values */
00364 
00365     *info = 0;
00366     work[1] = (real) max(1,*n);
00367     lquery = *lwork == -1;
00368     if (ischur == 0) {
00369         *info = -1;
00370     } else if (icompq == 0) {
00371         *info = -2;
00372     } else if (icompz == 0) {
00373         *info = -3;
00374     } else if (*n < 0) {
00375         *info = -4;
00376     } else if (*ilo < 1) {
00377         *info = -5;
00378     } else if (*ihi > *n || *ihi < *ilo - 1) {
00379         *info = -6;
00380     } else if (*ldh < *n) {
00381         *info = -8;
00382     } else if (*ldt < *n) {
00383         *info = -10;
00384     } else if (*ldq < 1 || ilq && *ldq < *n) {
00385         *info = -15;
00386     } else if (*ldz < 1 || ilz && *ldz < *n) {
00387         *info = -17;
00388     } else if (*lwork < max(1,*n) && ! lquery) {
00389         *info = -19;
00390     }
00391     if (*info != 0) {
00392         i__1 = -(*info);
00393         xerbla_("SHGEQZ", &i__1);
00394         return 0;
00395     } else if (lquery) {
00396         return 0;
00397     }
00398 
00399 /*     Quick return if possible */
00400 
00401     if (*n <= 0) {
00402         work[1] = 1.f;
00403         return 0;
00404     }
00405 
00406 /*     Initialize Q and Z */
00407 
00408     if (icompq == 3) {
00409         slaset_("Full", n, n, &c_b12, &c_b13, &q[q_offset], ldq);
00410     }
00411     if (icompz == 3) {
00412         slaset_("Full", n, n, &c_b12, &c_b13, &z__[z_offset], ldz);
00413     }
00414 
00415 /*     Machine Constants */
00416 
00417     in = *ihi + 1 - *ilo;
00418     safmin = slamch_("S");
00419     safmax = 1.f / safmin;
00420     ulp = slamch_("E") * slamch_("B");
00421     anorm = slanhs_("F", &in, &h__[*ilo + *ilo * h_dim1], ldh, &work[1]);
00422     bnorm = slanhs_("F", &in, &t[*ilo + *ilo * t_dim1], ldt, &work[1]);
00423 /* Computing MAX */
00424     r__1 = safmin, r__2 = ulp * anorm;
00425     atol = dmax(r__1,r__2);
00426 /* Computing MAX */
00427     r__1 = safmin, r__2 = ulp * bnorm;
00428     btol = dmax(r__1,r__2);
00429     ascale = 1.f / dmax(safmin,anorm);
00430     bscale = 1.f / dmax(safmin,bnorm);
00431 
00432 /*     Set Eigenvalues IHI+1:N */
00433 
00434     i__1 = *n;
00435     for (j = *ihi + 1; j <= i__1; ++j) {
00436         if (t[j + j * t_dim1] < 0.f) {
00437             if (ilschr) {
00438                 i__2 = j;
00439                 for (jr = 1; jr <= i__2; ++jr) {
00440                     h__[jr + j * h_dim1] = -h__[jr + j * h_dim1];
00441                     t[jr + j * t_dim1] = -t[jr + j * t_dim1];
00442 /* L10: */
00443                 }
00444             } else {
00445                 h__[j + j * h_dim1] = -h__[j + j * h_dim1];
00446                 t[j + j * t_dim1] = -t[j + j * t_dim1];
00447             }
00448             if (ilz) {
00449                 i__2 = *n;
00450                 for (jr = 1; jr <= i__2; ++jr) {
00451                     z__[jr + j * z_dim1] = -z__[jr + j * z_dim1];
00452 /* L20: */
00453                 }
00454             }
00455         }
00456         alphar[j] = h__[j + j * h_dim1];
00457         alphai[j] = 0.f;
00458         beta[j] = t[j + j * t_dim1];
00459 /* L30: */
00460     }
00461 
00462 /*     If IHI < ILO, skip QZ steps */
00463 
00464     if (*ihi < *ilo) {
00465         goto L380;
00466     }
00467 
00468 /*     MAIN QZ ITERATION LOOP */
00469 
00470 /*     Initialize dynamic indices */
00471 
00472 /*     Eigenvalues ILAST+1:N have been found. */
00473 /*        Column operations modify rows IFRSTM:whatever. */
00474 /*        Row operations modify columns whatever:ILASTM. */
00475 
00476 /*     If only eigenvalues are being computed, then */
00477 /*        IFRSTM is the row of the last splitting row above row ILAST; */
00478 /*        this is always at least ILO. */
00479 /*     IITER counts iterations since the last eigenvalue was found, */
00480 /*        to tell when to use an extraordinary shift. */
00481 /*     MAXIT is the maximum number of QZ sweeps allowed. */
00482 
00483     ilast = *ihi;
00484     if (ilschr) {
00485         ifrstm = 1;
00486         ilastm = *n;
00487     } else {
00488         ifrstm = *ilo;
00489         ilastm = *ihi;
00490     }
00491     iiter = 0;
00492     eshift = 0.f;
00493     maxit = (*ihi - *ilo + 1) * 30;
00494 
00495     i__1 = maxit;
00496     for (jiter = 1; jiter <= i__1; ++jiter) {
00497 
00498 /*        Split the matrix if possible. */
00499 
00500 /*        Two tests: */
00501 /*           1: H(j,j-1)=0  or  j=ILO */
00502 /*           2: T(j,j)=0 */
00503 
00504         if (ilast == *ilo) {
00505 
00506 /*           Special case: j=ILAST */
00507 
00508             goto L80;
00509         } else {
00510             if ((r__1 = h__[ilast + (ilast - 1) * h_dim1], dabs(r__1)) <= 
00511                     atol) {
00512                 h__[ilast + (ilast - 1) * h_dim1] = 0.f;
00513                 goto L80;
00514             }
00515         }
00516 
00517         if ((r__1 = t[ilast + ilast * t_dim1], dabs(r__1)) <= btol) {
00518             t[ilast + ilast * t_dim1] = 0.f;
00519             goto L70;
00520         }
00521 
00522 /*        General case: j<ILAST */
00523 
00524         i__2 = *ilo;
00525         for (j = ilast - 1; j >= i__2; --j) {
00526 
00527 /*           Test 1: for H(j,j-1)=0 or j=ILO */
00528 
00529             if (j == *ilo) {
00530                 ilazro = TRUE_;
00531             } else {
00532                 if ((r__1 = h__[j + (j - 1) * h_dim1], dabs(r__1)) <= atol) {
00533                     h__[j + (j - 1) * h_dim1] = 0.f;
00534                     ilazro = TRUE_;
00535                 } else {
00536                     ilazro = FALSE_;
00537                 }
00538             }
00539 
00540 /*           Test 2: for T(j,j)=0 */
00541 
00542             if ((r__1 = t[j + j * t_dim1], dabs(r__1)) < btol) {
00543                 t[j + j * t_dim1] = 0.f;
00544 
00545 /*              Test 1a: Check for 2 consecutive small subdiagonals in A */
00546 
00547                 ilazr2 = FALSE_;
00548                 if (! ilazro) {
00549                     temp = (r__1 = h__[j + (j - 1) * h_dim1], dabs(r__1));
00550                     temp2 = (r__1 = h__[j + j * h_dim1], dabs(r__1));
00551                     tempr = dmax(temp,temp2);
00552                     if (tempr < 1.f && tempr != 0.f) {
00553                         temp /= tempr;
00554                         temp2 /= tempr;
00555                     }
00556                     if (temp * (ascale * (r__1 = h__[j + 1 + j * h_dim1], 
00557                             dabs(r__1))) <= temp2 * (ascale * atol)) {
00558                         ilazr2 = TRUE_;
00559                     }
00560                 }
00561 
00562 /*              If both tests pass (1 & 2), i.e., the leading diagonal */
00563 /*              element of B in the block is zero, split a 1x1 block off */
00564 /*              at the top. (I.e., at the J-th row/column) The leading */
00565 /*              diagonal element of the remainder can also be zero, so */
00566 /*              this may have to be done repeatedly. */
00567 
00568                 if (ilazro || ilazr2) {
00569                     i__3 = ilast - 1;
00570                     for (jch = j; jch <= i__3; ++jch) {
00571                         temp = h__[jch + jch * h_dim1];
00572                         slartg_(&temp, &h__[jch + 1 + jch * h_dim1], &c__, &s, 
00573                                  &h__[jch + jch * h_dim1]);
00574                         h__[jch + 1 + jch * h_dim1] = 0.f;
00575                         i__4 = ilastm - jch;
00576                         srot_(&i__4, &h__[jch + (jch + 1) * h_dim1], ldh, &
00577                                 h__[jch + 1 + (jch + 1) * h_dim1], ldh, &c__, 
00578                                 &s);
00579                         i__4 = ilastm - jch;
00580                         srot_(&i__4, &t[jch + (jch + 1) * t_dim1], ldt, &t[
00581                                 jch + 1 + (jch + 1) * t_dim1], ldt, &c__, &s);
00582                         if (ilq) {
00583                             srot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
00584                                      * q_dim1 + 1], &c__1, &c__, &s);
00585                         }
00586                         if (ilazr2) {
00587                             h__[jch + (jch - 1) * h_dim1] *= c__;
00588                         }
00589                         ilazr2 = FALSE_;
00590                         if ((r__1 = t[jch + 1 + (jch + 1) * t_dim1], dabs(
00591                                 r__1)) >= btol) {
00592                             if (jch + 1 >= ilast) {
00593                                 goto L80;
00594                             } else {
00595                                 ifirst = jch + 1;
00596                                 goto L110;
00597                             }
00598                         }
00599                         t[jch + 1 + (jch + 1) * t_dim1] = 0.f;
00600 /* L40: */
00601                     }
00602                     goto L70;
00603                 } else {
00604 
00605 /*                 Only test 2 passed -- chase the zero to T(ILAST,ILAST) */
00606 /*                 Then process as in the case T(ILAST,ILAST)=0 */
00607 
00608                     i__3 = ilast - 1;
00609                     for (jch = j; jch <= i__3; ++jch) {
00610                         temp = t[jch + (jch + 1) * t_dim1];
00611                         slartg_(&temp, &t[jch + 1 + (jch + 1) * t_dim1], &c__, 
00612                                  &s, &t[jch + (jch + 1) * t_dim1]);
00613                         t[jch + 1 + (jch + 1) * t_dim1] = 0.f;
00614                         if (jch < ilastm - 1) {
00615                             i__4 = ilastm - jch - 1;
00616                             srot_(&i__4, &t[jch + (jch + 2) * t_dim1], ldt, &
00617                                     t[jch + 1 + (jch + 2) * t_dim1], ldt, &
00618                                     c__, &s);
00619                         }
00620                         i__4 = ilastm - jch + 2;
00621                         srot_(&i__4, &h__[jch + (jch - 1) * h_dim1], ldh, &
00622                                 h__[jch + 1 + (jch - 1) * h_dim1], ldh, &c__, 
00623                                 &s);
00624                         if (ilq) {
00625                             srot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
00626                                      * q_dim1 + 1], &c__1, &c__, &s);
00627                         }
00628                         temp = h__[jch + 1 + jch * h_dim1];
00629                         slartg_(&temp, &h__[jch + 1 + (jch - 1) * h_dim1], &
00630                                 c__, &s, &h__[jch + 1 + jch * h_dim1]);
00631                         h__[jch + 1 + (jch - 1) * h_dim1] = 0.f;
00632                         i__4 = jch + 1 - ifrstm;
00633                         srot_(&i__4, &h__[ifrstm + jch * h_dim1], &c__1, &h__[
00634                                 ifrstm + (jch - 1) * h_dim1], &c__1, &c__, &s)
00635                                 ;
00636                         i__4 = jch - ifrstm;
00637                         srot_(&i__4, &t[ifrstm + jch * t_dim1], &c__1, &t[
00638                                 ifrstm + (jch - 1) * t_dim1], &c__1, &c__, &s)
00639                                 ;
00640                         if (ilz) {
00641                             srot_(n, &z__[jch * z_dim1 + 1], &c__1, &z__[(jch 
00642                                     - 1) * z_dim1 + 1], &c__1, &c__, &s);
00643                         }
00644 /* L50: */
00645                     }
00646                     goto L70;
00647                 }
00648             } else if (ilazro) {
00649 
00650 /*              Only test 1 passed -- work on J:ILAST */
00651 
00652                 ifirst = j;
00653                 goto L110;
00654             }
00655 
00656 /*           Neither test passed -- try next J */
00657 
00658 /* L60: */
00659         }
00660 
00661 /*        (Drop-through is "impossible") */
00662 
00663         *info = *n + 1;
00664         goto L420;
00665 
00666 /*        T(ILAST,ILAST)=0 -- clear H(ILAST,ILAST-1) to split off a */
00667 /*        1x1 block. */
00668 
00669 L70:
00670         temp = h__[ilast + ilast * h_dim1];
00671         slartg_(&temp, &h__[ilast + (ilast - 1) * h_dim1], &c__, &s, &h__[
00672                 ilast + ilast * h_dim1]);
00673         h__[ilast + (ilast - 1) * h_dim1] = 0.f;
00674         i__2 = ilast - ifrstm;
00675         srot_(&i__2, &h__[ifrstm + ilast * h_dim1], &c__1, &h__[ifrstm + (
00676                 ilast - 1) * h_dim1], &c__1, &c__, &s);
00677         i__2 = ilast - ifrstm;
00678         srot_(&i__2, &t[ifrstm + ilast * t_dim1], &c__1, &t[ifrstm + (ilast - 
00679                 1) * t_dim1], &c__1, &c__, &s);
00680         if (ilz) {
00681             srot_(n, &z__[ilast * z_dim1 + 1], &c__1, &z__[(ilast - 1) * 
00682                     z_dim1 + 1], &c__1, &c__, &s);
00683         }
00684 
00685 /*        H(ILAST,ILAST-1)=0 -- Standardize B, set ALPHAR, ALPHAI, */
00686 /*                              and BETA */
00687 
00688 L80:
00689         if (t[ilast + ilast * t_dim1] < 0.f) {
00690             if (ilschr) {
00691                 i__2 = ilast;
00692                 for (j = ifrstm; j <= i__2; ++j) {
00693                     h__[j + ilast * h_dim1] = -h__[j + ilast * h_dim1];
00694                     t[j + ilast * t_dim1] = -t[j + ilast * t_dim1];
00695 /* L90: */
00696                 }
00697             } else {
00698                 h__[ilast + ilast * h_dim1] = -h__[ilast + ilast * h_dim1];
00699                 t[ilast + ilast * t_dim1] = -t[ilast + ilast * t_dim1];
00700             }
00701             if (ilz) {
00702                 i__2 = *n;
00703                 for (j = 1; j <= i__2; ++j) {
00704                     z__[j + ilast * z_dim1] = -z__[j + ilast * z_dim1];
00705 /* L100: */
00706                 }
00707             }
00708         }
00709         alphar[ilast] = h__[ilast + ilast * h_dim1];
00710         alphai[ilast] = 0.f;
00711         beta[ilast] = t[ilast + ilast * t_dim1];
00712 
00713 /*        Go to next block -- exit if finished. */
00714 
00715         --ilast;
00716         if (ilast < *ilo) {
00717             goto L380;
00718         }
00719 
00720 /*        Reset counters */
00721 
00722         iiter = 0;
00723         eshift = 0.f;
00724         if (! ilschr) {
00725             ilastm = ilast;
00726             if (ifrstm > ilast) {
00727                 ifrstm = *ilo;
00728             }
00729         }
00730         goto L350;
00731 
00732 /*        QZ step */
00733 
00734 /*        This iteration only involves rows/columns IFIRST:ILAST. We */
00735 /*        assume IFIRST < ILAST, and that the diagonal of B is non-zero. */
00736 
00737 L110:
00738         ++iiter;
00739         if (! ilschr) {
00740             ifrstm = ifirst;
00741         }
00742 
00743 /*        Compute single shifts. */
00744 
00745 /*        At this point, IFIRST < ILAST, and the diagonal elements of */
00746 /*        T(IFIRST:ILAST,IFIRST,ILAST) are larger than BTOL (in */
00747 /*        magnitude) */
00748 
00749         if (iiter / 10 * 10 == iiter) {
00750 
00751 /*           Exceptional shift.  Chosen for no particularly good reason. */
00752 /*           (Single shift only.) */
00753 
00754             if ((real) maxit * safmin * (r__1 = h__[ilast - 1 + ilast * 
00755                     h_dim1], dabs(r__1)) < (r__2 = t[ilast - 1 + (ilast - 1) *
00756                      t_dim1], dabs(r__2))) {
00757                 eshift += h__[ilast - 1 + ilast * h_dim1] / t[ilast - 1 + (
00758                         ilast - 1) * t_dim1];
00759             } else {
00760                 eshift += 1.f / (safmin * (real) maxit);
00761             }
00762             s1 = 1.f;
00763             wr = eshift;
00764 
00765         } else {
00766 
00767 /*           Shifts based on the generalized eigenvalues of the */
00768 /*           bottom-right 2x2 block of A and B. The first eigenvalue */
00769 /*           returned by SLAG2 is the Wilkinson shift (AEP p.512), */
00770 
00771             r__1 = safmin * 100.f;
00772             slag2_(&h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &t[ilast - 1 
00773                     + (ilast - 1) * t_dim1], ldt, &r__1, &s1, &s2, &wr, &wr2, 
00774                     &wi);
00775 
00776 /* Computing MAX */
00777 /* Computing MAX */
00778             r__3 = 1.f, r__4 = dabs(wr), r__3 = max(r__3,r__4), r__4 = dabs(
00779                     wi);
00780             r__1 = s1, r__2 = safmin * dmax(r__3,r__4);
00781             temp = dmax(r__1,r__2);
00782             if (wi != 0.f) {
00783                 goto L200;
00784             }
00785         }
00786 
00787 /*        Fiddle with shift to avoid overflow */
00788 
00789         temp = dmin(ascale,1.f) * (safmax * .5f);
00790         if (s1 > temp) {
00791             scale = temp / s1;
00792         } else {
00793             scale = 1.f;
00794         }
00795 
00796         temp = dmin(bscale,1.f) * (safmax * .5f);
00797         if (dabs(wr) > temp) {
00798 /* Computing MIN */
00799             r__1 = scale, r__2 = temp / dabs(wr);
00800             scale = dmin(r__1,r__2);
00801         }
00802         s1 = scale * s1;
00803         wr = scale * wr;
00804 
00805 /*        Now check for two consecutive small subdiagonals. */
00806 
00807         i__2 = ifirst + 1;
00808         for (j = ilast - 1; j >= i__2; --j) {
00809             istart = j;
00810             temp = (r__1 = s1 * h__[j + (j - 1) * h_dim1], dabs(r__1));
00811             temp2 = (r__1 = s1 * h__[j + j * h_dim1] - wr * t[j + j * t_dim1],
00812                      dabs(r__1));
00813             tempr = dmax(temp,temp2);
00814             if (tempr < 1.f && tempr != 0.f) {
00815                 temp /= tempr;
00816                 temp2 /= tempr;
00817             }
00818             if ((r__1 = ascale * h__[j + 1 + j * h_dim1] * temp, dabs(r__1)) 
00819                     <= ascale * atol * temp2) {
00820                 goto L130;
00821             }
00822 /* L120: */
00823         }
00824 
00825         istart = ifirst;
00826 L130:
00827 
00828 /*        Do an implicit single-shift QZ sweep. */
00829 
00830 /*        Initial Q */
00831 
00832         temp = s1 * h__[istart + istart * h_dim1] - wr * t[istart + istart * 
00833                 t_dim1];
00834         temp2 = s1 * h__[istart + 1 + istart * h_dim1];
00835         slartg_(&temp, &temp2, &c__, &s, &tempr);
00836 
00837 /*        Sweep */
00838 
00839         i__2 = ilast - 1;
00840         for (j = istart; j <= i__2; ++j) {
00841             if (j > istart) {
00842                 temp = h__[j + (j - 1) * h_dim1];
00843                 slartg_(&temp, &h__[j + 1 + (j - 1) * h_dim1], &c__, &s, &h__[
00844                         j + (j - 1) * h_dim1]);
00845                 h__[j + 1 + (j - 1) * h_dim1] = 0.f;
00846             }
00847 
00848             i__3 = ilastm;
00849             for (jc = j; jc <= i__3; ++jc) {
00850                 temp = c__ * h__[j + jc * h_dim1] + s * h__[j + 1 + jc * 
00851                         h_dim1];
00852                 h__[j + 1 + jc * h_dim1] = -s * h__[j + jc * h_dim1] + c__ * 
00853                         h__[j + 1 + jc * h_dim1];
00854                 h__[j + jc * h_dim1] = temp;
00855                 temp2 = c__ * t[j + jc * t_dim1] + s * t[j + 1 + jc * t_dim1];
00856                 t[j + 1 + jc * t_dim1] = -s * t[j + jc * t_dim1] + c__ * t[j 
00857                         + 1 + jc * t_dim1];
00858                 t[j + jc * t_dim1] = temp2;
00859 /* L140: */
00860             }
00861             if (ilq) {
00862                 i__3 = *n;
00863                 for (jr = 1; jr <= i__3; ++jr) {
00864                     temp = c__ * q[jr + j * q_dim1] + s * q[jr + (j + 1) * 
00865                             q_dim1];
00866                     q[jr + (j + 1) * q_dim1] = -s * q[jr + j * q_dim1] + c__ *
00867                              q[jr + (j + 1) * q_dim1];
00868                     q[jr + j * q_dim1] = temp;
00869 /* L150: */
00870                 }
00871             }
00872 
00873             temp = t[j + 1 + (j + 1) * t_dim1];
00874             slartg_(&temp, &t[j + 1 + j * t_dim1], &c__, &s, &t[j + 1 + (j + 
00875                     1) * t_dim1]);
00876             t[j + 1 + j * t_dim1] = 0.f;
00877 
00878 /* Computing MIN */
00879             i__4 = j + 2;
00880             i__3 = min(i__4,ilast);
00881             for (jr = ifrstm; jr <= i__3; ++jr) {
00882                 temp = c__ * h__[jr + (j + 1) * h_dim1] + s * h__[jr + j * 
00883                         h_dim1];
00884                 h__[jr + j * h_dim1] = -s * h__[jr + (j + 1) * h_dim1] + c__ *
00885                          h__[jr + j * h_dim1];
00886                 h__[jr + (j + 1) * h_dim1] = temp;
00887 /* L160: */
00888             }
00889             i__3 = j;
00890             for (jr = ifrstm; jr <= i__3; ++jr) {
00891                 temp = c__ * t[jr + (j + 1) * t_dim1] + s * t[jr + j * t_dim1]
00892                         ;
00893                 t[jr + j * t_dim1] = -s * t[jr + (j + 1) * t_dim1] + c__ * t[
00894                         jr + j * t_dim1];
00895                 t[jr + (j + 1) * t_dim1] = temp;
00896 /* L170: */
00897             }
00898             if (ilz) {
00899                 i__3 = *n;
00900                 for (jr = 1; jr <= i__3; ++jr) {
00901                     temp = c__ * z__[jr + (j + 1) * z_dim1] + s * z__[jr + j *
00902                              z_dim1];
00903                     z__[jr + j * z_dim1] = -s * z__[jr + (j + 1) * z_dim1] + 
00904                             c__ * z__[jr + j * z_dim1];
00905                     z__[jr + (j + 1) * z_dim1] = temp;
00906 /* L180: */
00907                 }
00908             }
00909 /* L190: */
00910         }
00911 
00912         goto L350;
00913 
00914 /*        Use Francis double-shift */
00915 
00916 /*        Note: the Francis double-shift should work with real shifts, */
00917 /*              but only if the block is at least 3x3. */
00918 /*              This code may break if this point is reached with */
00919 /*              a 2x2 block with real eigenvalues. */
00920 
00921 L200:
00922         if (ifirst + 1 == ilast) {
00923 
00924 /*           Special case -- 2x2 block with complex eigenvectors */
00925 
00926 /*           Step 1: Standardize, that is, rotate so that */
00927 
00928 /*                       ( B11  0  ) */
00929 /*                   B = (         )  with B11 non-negative. */
00930 /*                       (  0  B22 ) */
00931 
00932             slasv2_(&t[ilast - 1 + (ilast - 1) * t_dim1], &t[ilast - 1 + 
00933                     ilast * t_dim1], &t[ilast + ilast * t_dim1], &b22, &b11, &
00934                     sr, &cr, &sl, &cl);
00935 
00936             if (b11 < 0.f) {
00937                 cr = -cr;
00938                 sr = -sr;
00939                 b11 = -b11;
00940                 b22 = -b22;
00941             }
00942 
00943             i__2 = ilastm + 1 - ifirst;
00944             srot_(&i__2, &h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &h__[
00945                     ilast + (ilast - 1) * h_dim1], ldh, &cl, &sl);
00946             i__2 = ilast + 1 - ifrstm;
00947             srot_(&i__2, &h__[ifrstm + (ilast - 1) * h_dim1], &c__1, &h__[
00948                     ifrstm + ilast * h_dim1], &c__1, &cr, &sr);
00949 
00950             if (ilast < ilastm) {
00951                 i__2 = ilastm - ilast;
00952                 srot_(&i__2, &t[ilast - 1 + (ilast + 1) * t_dim1], ldt, &t[
00953                         ilast + (ilast + 1) * t_dim1], ldt, &cl, &sl);
00954             }
00955             if (ifrstm < ilast - 1) {
00956                 i__2 = ifirst - ifrstm;
00957                 srot_(&i__2, &t[ifrstm + (ilast - 1) * t_dim1], &c__1, &t[
00958                         ifrstm + ilast * t_dim1], &c__1, &cr, &sr);
00959             }
00960 
00961             if (ilq) {
00962                 srot_(n, &q[(ilast - 1) * q_dim1 + 1], &c__1, &q[ilast * 
00963                         q_dim1 + 1], &c__1, &cl, &sl);
00964             }
00965             if (ilz) {
00966                 srot_(n, &z__[(ilast - 1) * z_dim1 + 1], &c__1, &z__[ilast * 
00967                         z_dim1 + 1], &c__1, &cr, &sr);
00968             }
00969 
00970             t[ilast - 1 + (ilast - 1) * t_dim1] = b11;
00971             t[ilast - 1 + ilast * t_dim1] = 0.f;
00972             t[ilast + (ilast - 1) * t_dim1] = 0.f;
00973             t[ilast + ilast * t_dim1] = b22;
00974 
00975 /*           If B22 is negative, negate column ILAST */
00976 
00977             if (b22 < 0.f) {
00978                 i__2 = ilast;
00979                 for (j = ifrstm; j <= i__2; ++j) {
00980                     h__[j + ilast * h_dim1] = -h__[j + ilast * h_dim1];
00981                     t[j + ilast * t_dim1] = -t[j + ilast * t_dim1];
00982 /* L210: */
00983                 }
00984 
00985                 if (ilz) {
00986                     i__2 = *n;
00987                     for (j = 1; j <= i__2; ++j) {
00988                         z__[j + ilast * z_dim1] = -z__[j + ilast * z_dim1];
00989 /* L220: */
00990                     }
00991                 }
00992             }
00993 
00994 /*           Step 2: Compute ALPHAR, ALPHAI, and BETA (see refs.) */
00995 
00996 /*           Recompute shift */
00997 
00998             r__1 = safmin * 100.f;
00999             slag2_(&h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &t[ilast - 1 
01000                     + (ilast - 1) * t_dim1], ldt, &r__1, &s1, &temp, &wr, &
01001                     temp2, &wi);
01002 
01003 /*           If standardization has perturbed the shift onto real line, */
01004 /*           do another (real single-shift) QR step. */
01005 
01006             if (wi == 0.f) {
01007                 goto L350;
01008             }
01009             s1inv = 1.f / s1;
01010 
01011 /*           Do EISPACK (QZVAL) computation of alpha and beta */
01012 
01013             a11 = h__[ilast - 1 + (ilast - 1) * h_dim1];
01014             a21 = h__[ilast + (ilast - 1) * h_dim1];
01015             a12 = h__[ilast - 1 + ilast * h_dim1];
01016             a22 = h__[ilast + ilast * h_dim1];
01017 
01018 /*           Compute complex Givens rotation on right */
01019 /*           (Assume some element of C = (sA - wB) > unfl ) */
01020 /*                            __ */
01021 /*           (sA - wB) ( CZ   -SZ ) */
01022 /*                     ( SZ    CZ ) */
01023 
01024             c11r = s1 * a11 - wr * b11;
01025             c11i = -wi * b11;
01026             c12 = s1 * a12;
01027             c21 = s1 * a21;
01028             c22r = s1 * a22 - wr * b22;
01029             c22i = -wi * b22;
01030 
01031             if (dabs(c11r) + dabs(c11i) + dabs(c12) > dabs(c21) + dabs(c22r) 
01032                     + dabs(c22i)) {
01033                 t1 = slapy3_(&c12, &c11r, &c11i);
01034                 cz = c12 / t1;
01035                 szr = -c11r / t1;
01036                 szi = -c11i / t1;
01037             } else {
01038                 cz = slapy2_(&c22r, &c22i);
01039                 if (cz <= safmin) {
01040                     cz = 0.f;
01041                     szr = 1.f;
01042                     szi = 0.f;
01043                 } else {
01044                     tempr = c22r / cz;
01045                     tempi = c22i / cz;
01046                     t1 = slapy2_(&cz, &c21);
01047                     cz /= t1;
01048                     szr = -c21 * tempr / t1;
01049                     szi = c21 * tempi / t1;
01050                 }
01051             }
01052 
01053 /*           Compute Givens rotation on left */
01054 
01055 /*           (  CQ   SQ ) */
01056 /*           (  __      )  A or B */
01057 /*           ( -SQ   CQ ) */
01058 
01059             an = dabs(a11) + dabs(a12) + dabs(a21) + dabs(a22);
01060             bn = dabs(b11) + dabs(b22);
01061             wabs = dabs(wr) + dabs(wi);
01062             if (s1 * an > wabs * bn) {
01063                 cq = cz * b11;
01064                 sqr = szr * b22;
01065                 sqi = -szi * b22;
01066             } else {
01067                 a1r = cz * a11 + szr * a12;
01068                 a1i = szi * a12;
01069                 a2r = cz * a21 + szr * a22;
01070                 a2i = szi * a22;
01071                 cq = slapy2_(&a1r, &a1i);
01072                 if (cq <= safmin) {
01073                     cq = 0.f;
01074                     sqr = 1.f;
01075                     sqi = 0.f;
01076                 } else {
01077                     tempr = a1r / cq;
01078                     tempi = a1i / cq;
01079                     sqr = tempr * a2r + tempi * a2i;
01080                     sqi = tempi * a2r - tempr * a2i;
01081                 }
01082             }
01083             t1 = slapy3_(&cq, &sqr, &sqi);
01084             cq /= t1;
01085             sqr /= t1;
01086             sqi /= t1;
01087 
01088 /*           Compute diagonal elements of QBZ */
01089 
01090             tempr = sqr * szr - sqi * szi;
01091             tempi = sqr * szi + sqi * szr;
01092             b1r = cq * cz * b11 + tempr * b22;
01093             b1i = tempi * b22;
01094             b1a = slapy2_(&b1r, &b1i);
01095             b2r = cq * cz * b22 + tempr * b11;
01096             b2i = -tempi * b11;
01097             b2a = slapy2_(&b2r, &b2i);
01098 
01099 /*           Normalize so beta > 0, and Im( alpha1 ) > 0 */
01100 
01101             beta[ilast - 1] = b1a;
01102             beta[ilast] = b2a;
01103             alphar[ilast - 1] = wr * b1a * s1inv;
01104             alphai[ilast - 1] = wi * b1a * s1inv;
01105             alphar[ilast] = wr * b2a * s1inv;
01106             alphai[ilast] = -(wi * b2a) * s1inv;
01107 
01108 /*           Step 3: Go to next block -- exit if finished. */
01109 
01110             ilast = ifirst - 1;
01111             if (ilast < *ilo) {
01112                 goto L380;
01113             }
01114 
01115 /*           Reset counters */
01116 
01117             iiter = 0;
01118             eshift = 0.f;
01119             if (! ilschr) {
01120                 ilastm = ilast;
01121                 if (ifrstm > ilast) {
01122                     ifrstm = *ilo;
01123                 }
01124             }
01125             goto L350;
01126         } else {
01127 
01128 /*           Usual case: 3x3 or larger block, using Francis implicit */
01129 /*                       double-shift */
01130 
01131 /*                                    2 */
01132 /*           Eigenvalue equation is  w  - c w + d = 0, */
01133 
01134 /*                                         -1 2        -1 */
01135 /*           so compute 1st column of  (A B  )  - c A B   + d */
01136 /*           using the formula in QZIT (from EISPACK) */
01137 
01138 /*           We assume that the block is at least 3x3 */
01139 
01140             ad11 = ascale * h__[ilast - 1 + (ilast - 1) * h_dim1] / (bscale * 
01141                     t[ilast - 1 + (ilast - 1) * t_dim1]);
01142             ad21 = ascale * h__[ilast + (ilast - 1) * h_dim1] / (bscale * t[
01143                     ilast - 1 + (ilast - 1) * t_dim1]);
01144             ad12 = ascale * h__[ilast - 1 + ilast * h_dim1] / (bscale * t[
01145                     ilast + ilast * t_dim1]);
01146             ad22 = ascale * h__[ilast + ilast * h_dim1] / (bscale * t[ilast + 
01147                     ilast * t_dim1]);
01148             u12 = t[ilast - 1 + ilast * t_dim1] / t[ilast + ilast * t_dim1];
01149             ad11l = ascale * h__[ifirst + ifirst * h_dim1] / (bscale * t[
01150                     ifirst + ifirst * t_dim1]);
01151             ad21l = ascale * h__[ifirst + 1 + ifirst * h_dim1] / (bscale * t[
01152                     ifirst + ifirst * t_dim1]);
01153             ad12l = ascale * h__[ifirst + (ifirst + 1) * h_dim1] / (bscale * 
01154                     t[ifirst + 1 + (ifirst + 1) * t_dim1]);
01155             ad22l = ascale * h__[ifirst + 1 + (ifirst + 1) * h_dim1] / (
01156                     bscale * t[ifirst + 1 + (ifirst + 1) * t_dim1]);
01157             ad32l = ascale * h__[ifirst + 2 + (ifirst + 1) * h_dim1] / (
01158                     bscale * t[ifirst + 1 + (ifirst + 1) * t_dim1]);
01159             u12l = t[ifirst + (ifirst + 1) * t_dim1] / t[ifirst + 1 + (ifirst 
01160                     + 1) * t_dim1];
01161 
01162             v[0] = (ad11 - ad11l) * (ad22 - ad11l) - ad12 * ad21 + ad21 * u12 
01163                     * ad11l + (ad12l - ad11l * u12l) * ad21l;
01164             v[1] = (ad22l - ad11l - ad21l * u12l - (ad11 - ad11l) - (ad22 - 
01165                     ad11l) + ad21 * u12) * ad21l;
01166             v[2] = ad32l * ad21l;
01167 
01168             istart = ifirst;
01169 
01170             slarfg_(&c__3, v, &v[1], &c__1, &tau);
01171             v[0] = 1.f;
01172 
01173 /*           Sweep */
01174 
01175             i__2 = ilast - 2;
01176             for (j = istart; j <= i__2; ++j) {
01177 
01178 /*              All but last elements: use 3x3 Householder transforms. */
01179 
01180 /*              Zero (j-1)st column of A */
01181 
01182                 if (j > istart) {
01183                     v[0] = h__[j + (j - 1) * h_dim1];
01184                     v[1] = h__[j + 1 + (j - 1) * h_dim1];
01185                     v[2] = h__[j + 2 + (j - 1) * h_dim1];
01186 
01187                     slarfg_(&c__3, &h__[j + (j - 1) * h_dim1], &v[1], &c__1, &
01188                             tau);
01189                     v[0] = 1.f;
01190                     h__[j + 1 + (j - 1) * h_dim1] = 0.f;
01191                     h__[j + 2 + (j - 1) * h_dim1] = 0.f;
01192                 }
01193 
01194                 i__3 = ilastm;
01195                 for (jc = j; jc <= i__3; ++jc) {
01196                     temp = tau * (h__[j + jc * h_dim1] + v[1] * h__[j + 1 + 
01197                             jc * h_dim1] + v[2] * h__[j + 2 + jc * h_dim1]);
01198                     h__[j + jc * h_dim1] -= temp;
01199                     h__[j + 1 + jc * h_dim1] -= temp * v[1];
01200                     h__[j + 2 + jc * h_dim1] -= temp * v[2];
01201                     temp2 = tau * (t[j + jc * t_dim1] + v[1] * t[j + 1 + jc * 
01202                             t_dim1] + v[2] * t[j + 2 + jc * t_dim1]);
01203                     t[j + jc * t_dim1] -= temp2;
01204                     t[j + 1 + jc * t_dim1] -= temp2 * v[1];
01205                     t[j + 2 + jc * t_dim1] -= temp2 * v[2];
01206 /* L230: */
01207                 }
01208                 if (ilq) {
01209                     i__3 = *n;
01210                     for (jr = 1; jr <= i__3; ++jr) {
01211                         temp = tau * (q[jr + j * q_dim1] + v[1] * q[jr + (j + 
01212                                 1) * q_dim1] + v[2] * q[jr + (j + 2) * q_dim1]
01213                                 );
01214                         q[jr + j * q_dim1] -= temp;
01215                         q[jr + (j + 1) * q_dim1] -= temp * v[1];
01216                         q[jr + (j + 2) * q_dim1] -= temp * v[2];
01217 /* L240: */
01218                     }
01219                 }
01220 
01221 /*              Zero j-th column of B (see SLAGBC for details) */
01222 
01223 /*              Swap rows to pivot */
01224 
01225                 ilpivt = FALSE_;
01226 /* Computing MAX */
01227                 r__3 = (r__1 = t[j + 1 + (j + 1) * t_dim1], dabs(r__1)), r__4 
01228                         = (r__2 = t[j + 1 + (j + 2) * t_dim1], dabs(r__2));
01229                 temp = dmax(r__3,r__4);
01230 /* Computing MAX */
01231                 r__3 = (r__1 = t[j + 2 + (j + 1) * t_dim1], dabs(r__1)), r__4 
01232                         = (r__2 = t[j + 2 + (j + 2) * t_dim1], dabs(r__2));
01233                 temp2 = dmax(r__3,r__4);
01234                 if (dmax(temp,temp2) < safmin) {
01235                     scale = 0.f;
01236                     u1 = 1.f;
01237                     u2 = 0.f;
01238                     goto L250;
01239                 } else if (temp >= temp2) {
01240                     w11 = t[j + 1 + (j + 1) * t_dim1];
01241                     w21 = t[j + 2 + (j + 1) * t_dim1];
01242                     w12 = t[j + 1 + (j + 2) * t_dim1];
01243                     w22 = t[j + 2 + (j + 2) * t_dim1];
01244                     u1 = t[j + 1 + j * t_dim1];
01245                     u2 = t[j + 2 + j * t_dim1];
01246                 } else {
01247                     w21 = t[j + 1 + (j + 1) * t_dim1];
01248                     w11 = t[j + 2 + (j + 1) * t_dim1];
01249                     w22 = t[j + 1 + (j + 2) * t_dim1];
01250                     w12 = t[j + 2 + (j + 2) * t_dim1];
01251                     u2 = t[j + 1 + j * t_dim1];
01252                     u1 = t[j + 2 + j * t_dim1];
01253                 }
01254 
01255 /*              Swap columns if nec. */
01256 
01257                 if (dabs(w12) > dabs(w11)) {
01258                     ilpivt = TRUE_;
01259                     temp = w12;
01260                     temp2 = w22;
01261                     w12 = w11;
01262                     w22 = w21;
01263                     w11 = temp;
01264                     w21 = temp2;
01265                 }
01266 
01267 /*              LU-factor */
01268 
01269                 temp = w21 / w11;
01270                 u2 -= temp * u1;
01271                 w22 -= temp * w12;
01272                 w21 = 0.f;
01273 
01274 /*              Compute SCALE */
01275 
01276                 scale = 1.f;
01277                 if (dabs(w22) < safmin) {
01278                     scale = 0.f;
01279                     u2 = 1.f;
01280                     u1 = -w12 / w11;
01281                     goto L250;
01282                 }
01283                 if (dabs(w22) < dabs(u2)) {
01284                     scale = (r__1 = w22 / u2, dabs(r__1));
01285                 }
01286                 if (dabs(w11) < dabs(u1)) {
01287 /* Computing MIN */
01288                     r__2 = scale, r__3 = (r__1 = w11 / u1, dabs(r__1));
01289                     scale = dmin(r__2,r__3);
01290                 }
01291 
01292 /*              Solve */
01293 
01294                 u2 = scale * u2 / w22;
01295                 u1 = (scale * u1 - w12 * u2) / w11;
01296 
01297 L250:
01298                 if (ilpivt) {
01299                     temp = u2;
01300                     u2 = u1;
01301                     u1 = temp;
01302                 }
01303 
01304 /*              Compute Householder Vector */
01305 
01306 /* Computing 2nd power */
01307                 r__1 = scale;
01308 /* Computing 2nd power */
01309                 r__2 = u1;
01310 /* Computing 2nd power */
01311                 r__3 = u2;
01312                 t1 = sqrt(r__1 * r__1 + r__2 * r__2 + r__3 * r__3);
01313                 tau = scale / t1 + 1.f;
01314                 vs = -1.f / (scale + t1);
01315                 v[0] = 1.f;
01316                 v[1] = vs * u1;
01317                 v[2] = vs * u2;
01318 
01319 /*              Apply transformations from the right. */
01320 
01321 /* Computing MIN */
01322                 i__4 = j + 3;
01323                 i__3 = min(i__4,ilast);
01324                 for (jr = ifrstm; jr <= i__3; ++jr) {
01325                     temp = tau * (h__[jr + j * h_dim1] + v[1] * h__[jr + (j + 
01326                             1) * h_dim1] + v[2] * h__[jr + (j + 2) * h_dim1]);
01327                     h__[jr + j * h_dim1] -= temp;
01328                     h__[jr + (j + 1) * h_dim1] -= temp * v[1];
01329                     h__[jr + (j + 2) * h_dim1] -= temp * v[2];
01330 /* L260: */
01331                 }
01332                 i__3 = j + 2;
01333                 for (jr = ifrstm; jr <= i__3; ++jr) {
01334                     temp = tau * (t[jr + j * t_dim1] + v[1] * t[jr + (j + 1) *
01335                              t_dim1] + v[2] * t[jr + (j + 2) * t_dim1]);
01336                     t[jr + j * t_dim1] -= temp;
01337                     t[jr + (j + 1) * t_dim1] -= temp * v[1];
01338                     t[jr + (j + 2) * t_dim1] -= temp * v[2];
01339 /* L270: */
01340                 }
01341                 if (ilz) {
01342                     i__3 = *n;
01343                     for (jr = 1; jr <= i__3; ++jr) {
01344                         temp = tau * (z__[jr + j * z_dim1] + v[1] * z__[jr + (
01345                                 j + 1) * z_dim1] + v[2] * z__[jr + (j + 2) * 
01346                                 z_dim1]);
01347                         z__[jr + j * z_dim1] -= temp;
01348                         z__[jr + (j + 1) * z_dim1] -= temp * v[1];
01349                         z__[jr + (j + 2) * z_dim1] -= temp * v[2];
01350 /* L280: */
01351                     }
01352                 }
01353                 t[j + 1 + j * t_dim1] = 0.f;
01354                 t[j + 2 + j * t_dim1] = 0.f;
01355 /* L290: */
01356             }
01357 
01358 /*           Last elements: Use Givens rotations */
01359 
01360 /*           Rotations from the left */
01361 
01362             j = ilast - 1;
01363             temp = h__[j + (j - 1) * h_dim1];
01364             slartg_(&temp, &h__[j + 1 + (j - 1) * h_dim1], &c__, &s, &h__[j + 
01365                     (j - 1) * h_dim1]);
01366             h__[j + 1 + (j - 1) * h_dim1] = 0.f;
01367 
01368             i__2 = ilastm;
01369             for (jc = j; jc <= i__2; ++jc) {
01370                 temp = c__ * h__[j + jc * h_dim1] + s * h__[j + 1 + jc * 
01371                         h_dim1];
01372                 h__[j + 1 + jc * h_dim1] = -s * h__[j + jc * h_dim1] + c__ * 
01373                         h__[j + 1 + jc * h_dim1];
01374                 h__[j + jc * h_dim1] = temp;
01375                 temp2 = c__ * t[j + jc * t_dim1] + s * t[j + 1 + jc * t_dim1];
01376                 t[j + 1 + jc * t_dim1] = -s * t[j + jc * t_dim1] + c__ * t[j 
01377                         + 1 + jc * t_dim1];
01378                 t[j + jc * t_dim1] = temp2;
01379 /* L300: */
01380             }
01381             if (ilq) {
01382                 i__2 = *n;
01383                 for (jr = 1; jr <= i__2; ++jr) {
01384                     temp = c__ * q[jr + j * q_dim1] + s * q[jr + (j + 1) * 
01385                             q_dim1];
01386                     q[jr + (j + 1) * q_dim1] = -s * q[jr + j * q_dim1] + c__ *
01387                              q[jr + (j + 1) * q_dim1];
01388                     q[jr + j * q_dim1] = temp;
01389 /* L310: */
01390                 }
01391             }
01392 
01393 /*           Rotations from the right. */
01394 
01395             temp = t[j + 1 + (j + 1) * t_dim1];
01396             slartg_(&temp, &t[j + 1 + j * t_dim1], &c__, &s, &t[j + 1 + (j + 
01397                     1) * t_dim1]);
01398             t[j + 1 + j * t_dim1] = 0.f;
01399 
01400             i__2 = ilast;
01401             for (jr = ifrstm; jr <= i__2; ++jr) {
01402                 temp = c__ * h__[jr + (j + 1) * h_dim1] + s * h__[jr + j * 
01403                         h_dim1];
01404                 h__[jr + j * h_dim1] = -s * h__[jr + (j + 1) * h_dim1] + c__ *
01405                          h__[jr + j * h_dim1];
01406                 h__[jr + (j + 1) * h_dim1] = temp;
01407 /* L320: */
01408             }
01409             i__2 = ilast - 1;
01410             for (jr = ifrstm; jr <= i__2; ++jr) {
01411                 temp = c__ * t[jr + (j + 1) * t_dim1] + s * t[jr + j * t_dim1]
01412                         ;
01413                 t[jr + j * t_dim1] = -s * t[jr + (j + 1) * t_dim1] + c__ * t[
01414                         jr + j * t_dim1];
01415                 t[jr + (j + 1) * t_dim1] = temp;
01416 /* L330: */
01417             }
01418             if (ilz) {
01419                 i__2 = *n;
01420                 for (jr = 1; jr <= i__2; ++jr) {
01421                     temp = c__ * z__[jr + (j + 1) * z_dim1] + s * z__[jr + j *
01422                              z_dim1];
01423                     z__[jr + j * z_dim1] = -s * z__[jr + (j + 1) * z_dim1] + 
01424                             c__ * z__[jr + j * z_dim1];
01425                     z__[jr + (j + 1) * z_dim1] = temp;
01426 /* L340: */
01427                 }
01428             }
01429 
01430 /*           End of Double-Shift code */
01431 
01432         }
01433 
01434         goto L350;
01435 
01436 /*        End of iteration loop */
01437 
01438 L350:
01439 /* L360: */
01440         ;
01441     }
01442 
01443 /*     Drop-through = non-convergence */
01444 
01445     *info = ilast;
01446     goto L420;
01447 
01448 /*     Successful completion of all QZ steps */
01449 
01450 L380:
01451 
01452 /*     Set Eigenvalues 1:ILO-1 */
01453 
01454     i__1 = *ilo - 1;
01455     for (j = 1; j <= i__1; ++j) {
01456         if (t[j + j * t_dim1] < 0.f) {
01457             if (ilschr) {
01458                 i__2 = j;
01459                 for (jr = 1; jr <= i__2; ++jr) {
01460                     h__[jr + j * h_dim1] = -h__[jr + j * h_dim1];
01461                     t[jr + j * t_dim1] = -t[jr + j * t_dim1];
01462 /* L390: */
01463                 }
01464             } else {
01465                 h__[j + j * h_dim1] = -h__[j + j * h_dim1];
01466                 t[j + j * t_dim1] = -t[j + j * t_dim1];
01467             }
01468             if (ilz) {
01469                 i__2 = *n;
01470                 for (jr = 1; jr <= i__2; ++jr) {
01471                     z__[jr + j * z_dim1] = -z__[jr + j * z_dim1];
01472 /* L400: */
01473                 }
01474             }
01475         }
01476         alphar[j] = h__[j + j * h_dim1];
01477         alphai[j] = 0.f;
01478         beta[j] = t[j + j * t_dim1];
01479 /* L410: */
01480     }
01481 
01482 /*     Normal Termination */
01483 
01484     *info = 0;
01485 
01486 /*     Exit (other than argument error) -- return optimal workspace size */
01487 
01488 L420:
01489     work[1] = (real) (*n);
01490     return 0;
01491 
01492 /*     End of SHGEQZ */
01493 
01494 } /* shgeqz_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:09