14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
22 typedef BLASLONG blasint;
24 #define blasabs(x) llabs(x)
26 #define blasabs(x) labs(x)
30 #define blasabs(x) abs(x)
33 typedef blasint integer;
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
63 /* Extern is for use with -E */
74 /*external read, write*/
83 /*internal read, write*/
113 /*rewind, backspace, endfile*/
125 ftnint *inex; /*parameters in standard's order*/
151 union Multitype { /* for multiple entry points */
162 typedef union Multitype Multitype;
164 struct Vardesc { /* for Namelist */
170 typedef struct Vardesc Vardesc;
177 typedef struct Namelist Namelist;
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b) ((a) >> (b) & 1)
186 #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/Cd(b)._Val[1]);}
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
261 /* procedure parameter types for -A and -C++ */
263 #define F2C_proc_par_types 1
265 typedef logical (*L_fp)(...);
267 typedef logical (*L_fp)();
270 static float spow_ui(float x, integer n) {
271 float pow=1.0; unsigned long int u;
273 if(n < 0) n = -n, x = 1/x;
282 static double dpow_ui(double x, integer n) {
283 double pow=1.0; unsigned long int u;
285 if(n < 0) n = -n, x = 1/x;
295 static _Fcomplex cpow_ui(complex x, integer n) {
296 complex pow={1.0,0.0}; unsigned long int u;
298 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
300 if(u & 01) pow.r *= x.r, pow.i *= x.i;
301 if(u >>= 1) x.r *= x.r, x.i *= x.i;
305 _Fcomplex p={pow.r, pow.i};
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310 _Complex float pow=1.0; unsigned long int u;
312 if(n < 0) n = -n, x = 1/x;
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324 _Dcomplex pow={1.0,0.0}; unsigned long int u;
326 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
328 if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329 if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
333 _Dcomplex p = {pow._Val[0], pow._Val[1]};
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338 _Complex double pow=1.0; unsigned long int u;
340 if(n < 0) n = -n, x = 1/x;
350 static integer pow_ii(integer x, integer n) {
351 integer pow; unsigned long int u;
353 if (n == 0 || x == 1) pow = 1;
354 else if (x != -1) pow = x == 0 ? 1/x : 0;
357 if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
369 double m; integer i, mi;
370 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371 if (w[i-1]>m) mi=i ,m=w[i-1];
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
376 float m; integer i, mi;
377 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378 if (w[i-1]>m) mi=i ,m=w[i-1];
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382 integer n = *n_, incx = *incx_, incy = *incy_, i;
384 _Fcomplex zdotc = {0.0, 0.0};
385 if (incx == 1 && incy == 1) {
386 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387 zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388 zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
391 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392 zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393 zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
399 _Complex float zdotc = 0.0;
400 if (incx == 1 && incy == 1) {
401 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402 zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
405 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406 zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413 integer n = *n_, incx = *incx_, incy = *incy_, i;
415 _Dcomplex zdotc = {0.0, 0.0};
416 if (incx == 1 && incy == 1) {
417 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418 zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419 zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
422 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423 zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424 zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
430 _Complex double zdotc = 0.0;
431 if (incx == 1 && incy == 1) {
432 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433 zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
436 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437 zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444 integer n = *n_, incx = *incx_, incy = *incy_, i;
446 _Fcomplex zdotc = {0.0, 0.0};
447 if (incx == 1 && incy == 1) {
448 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449 zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450 zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
453 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454 zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455 zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
461 _Complex float zdotc = 0.0;
462 if (incx == 1 && incy == 1) {
463 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464 zdotc += Cf(&x[i]) * Cf(&y[i]);
467 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468 zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475 integer n = *n_, incx = *incx_, incy = *incy_, i;
477 _Dcomplex zdotc = {0.0, 0.0};
478 if (incx == 1 && incy == 1) {
479 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480 zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481 zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
484 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485 zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486 zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
492 _Complex double zdotc = 0.0;
493 if (incx == 1 && incy == 1) {
494 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495 zdotc += Cd(&x[i]) * Cd(&y[i]);
498 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499 zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
505 /* -- translated by f2c (version 20000121).
506 You must link the resulting object file with the libraries:
507 -lf2c -lm (in that order)
514 /* Table of constant values */
516 static doublecomplex c_b1 = {0.,0.};
517 static doublecomplex c_b2 = {1.,0.};
518 static integer c__1 = 1;
519 static integer c__2 = 2;
521 /* > \brief \b ZHGEQZ */
523 /* =========== DOCUMENTATION =========== */
525 /* Online html documentation available at */
526 /* http://www.netlib.org/lapack/explore-html/ */
529 /* > Download ZHGEQZ + dependencies */
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhgeqz.
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhgeqz.
536 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhgeqz.
544 /* SUBROUTINE ZHGEQZ( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT, */
545 /* ALPHA, BETA, Q, LDQ, Z, LDZ, WORK, LWORK, */
548 /* CHARACTER COMPQ, COMPZ, JOB */
549 /* INTEGER IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N */
550 /* DOUBLE PRECISION RWORK( * ) */
551 /* COMPLEX*16 ALPHA( * ), BETA( * ), H( LDH, * ), */
552 /* $ Q( LDQ, * ), T( LDT, * ), WORK( * ), */
556 /* > \par Purpose: */
561 /* > ZHGEQZ computes the eigenvalues of a complex matrix pair (H,T), */
562 /* > where H is an upper Hessenberg matrix and T is upper triangular, */
563 /* > using the single-shift QZ method. */
564 /* > Matrix pairs of this type are produced by the reduction to */
565 /* > generalized upper Hessenberg form of a complex matrix pair (A,B): */
567 /* > A = Q1*H*Z1**H, B = Q1*T*Z1**H, */
569 /* > as computed by ZGGHRD. */
571 /* > If JOB='S', then the Hessenberg-triangular pair (H,T) is */
572 /* > also reduced to generalized Schur form, */
574 /* > H = Q*S*Z**H, T = Q*P*Z**H, */
576 /* > where Q and Z are unitary matrices and S and P are upper triangular. */
578 /* > Optionally, the unitary matrix Q from the generalized Schur */
579 /* > factorization may be postmultiplied into an input matrix Q1, and the */
580 /* > unitary matrix Z may be postmultiplied into an input matrix Z1. */
581 /* > If Q1 and Z1 are the unitary matrices from ZGGHRD that reduced */
582 /* > the matrix pair (A,B) to generalized Hessenberg form, then the output */
583 /* > matrices Q1*Q and Z1*Z are the unitary factors from the generalized */
584 /* > Schur factorization of (A,B): */
586 /* > A = (Q1*Q)*S*(Z1*Z)**H, B = (Q1*Q)*P*(Z1*Z)**H. */
588 /* > To avoid overflow, eigenvalues of the matrix pair (H,T) */
589 /* > (equivalently, of (A,B)) are computed as a pair of complex values */
590 /* > (alpha,beta). If beta is nonzero, lambda = alpha / beta is an */
591 /* > eigenvalue of the generalized nonsymmetric eigenvalue problem (GNEP) */
592 /* > A*x = lambda*B*x */
593 /* > and if alpha is nonzero, mu = beta / alpha is an eigenvalue of the */
594 /* > alternate form of the GNEP */
595 /* > mu*A*y = B*y. */
596 /* > The values of alpha and beta for the i-th eigenvalue can be read */
597 /* > directly from the generalized Schur form: alpha = S(i,i), */
598 /* > beta = P(i,i). */
600 /* > Ref: C.B. Moler & G.W. Stewart, "An Algorithm for Generalized Matrix */
601 /* > Eigenvalue Problems", SIAM J. Numer. Anal., 10(1973), */
602 /* > pp. 241--256. */
608 /* > \param[in] JOB */
610 /* > JOB is CHARACTER*1 */
611 /* > = 'E': Compute eigenvalues only; */
612 /* > = 'S': Computer eigenvalues and the Schur form. */
615 /* > \param[in] COMPQ */
617 /* > COMPQ is CHARACTER*1 */
618 /* > = 'N': Left Schur vectors (Q) are not computed; */
619 /* > = 'I': Q is initialized to the unit matrix and the matrix Q */
620 /* > of left Schur vectors of (H,T) is returned; */
621 /* > = 'V': Q must contain a unitary matrix Q1 on entry and */
622 /* > the product Q1*Q is returned. */
625 /* > \param[in] COMPZ */
627 /* > COMPZ is CHARACTER*1 */
628 /* > = 'N': Right Schur vectors (Z) are not computed; */
629 /* > = 'I': Q is initialized to the unit matrix and the matrix Z */
630 /* > of right Schur vectors of (H,T) is returned; */
631 /* > = 'V': Z must contain a unitary matrix Z1 on entry and */
632 /* > the product Z1*Z is returned. */
638 /* > The order of the matrices H, T, Q, and Z. N >= 0. */
641 /* > \param[in] ILO */
643 /* > ILO is INTEGER */
646 /* > \param[in] IHI */
648 /* > IHI is INTEGER */
649 /* > ILO and IHI mark the rows and columns of H which are in */
650 /* > Hessenberg form. It is assumed that A is already upper */
651 /* > triangular in rows and columns 1:ILO-1 and IHI+1:N. */
652 /* > If N > 0, 1 <= ILO <= IHI <= N; if N = 0, ILO=1 and IHI=0. */
655 /* > \param[in,out] H */
657 /* > H is COMPLEX*16 array, dimension (LDH, N) */
658 /* > On entry, the N-by-N upper Hessenberg matrix H. */
659 /* > On exit, if JOB = 'S', H contains the upper triangular */
660 /* > matrix S from the generalized Schur factorization. */
661 /* > If JOB = 'E', the diagonal of H matches that of S, but */
662 /* > the rest of H is unspecified. */
665 /* > \param[in] LDH */
667 /* > LDH is INTEGER */
668 /* > The leading dimension of the array H. LDH >= f2cmax( 1, N ). */
671 /* > \param[in,out] T */
673 /* > T is COMPLEX*16 array, dimension (LDT, N) */
674 /* > On entry, the N-by-N upper triangular matrix T. */
675 /* > On exit, if JOB = 'S', T contains the upper triangular */
676 /* > matrix P from the generalized Schur factorization. */
677 /* > If JOB = 'E', the diagonal of T matches that of P, but */
678 /* > the rest of T is unspecified. */
681 /* > \param[in] LDT */
683 /* > LDT is INTEGER */
684 /* > The leading dimension of the array T. LDT >= f2cmax( 1, N ). */
687 /* > \param[out] ALPHA */
689 /* > ALPHA is COMPLEX*16 array, dimension (N) */
690 /* > The complex scalars alpha that define the eigenvalues of */
691 /* > GNEP. ALPHA(i) = S(i,i) in the generalized Schur */
692 /* > factorization. */
695 /* > \param[out] BETA */
697 /* > BETA is COMPLEX*16 array, dimension (N) */
698 /* > The real non-negative scalars beta that define the */
699 /* > eigenvalues of GNEP. BETA(i) = P(i,i) in the generalized */
700 /* > Schur factorization. */
702 /* > Together, the quantities alpha = ALPHA(j) and beta = BETA(j) */
703 /* > represent the j-th eigenvalue of the matrix pair (A,B), in */
704 /* > one of the forms lambda = alpha/beta or mu = beta/alpha. */
705 /* > Since either lambda or mu may overflow, they should not, */
706 /* > in general, be computed. */
709 /* > \param[in,out] Q */
711 /* > Q is COMPLEX*16 array, dimension (LDQ, N) */
712 /* > On entry, if COMPQ = 'V', the unitary matrix Q1 used in the */
713 /* > reduction of (A,B) to generalized Hessenberg form. */
714 /* > On exit, if COMPQ = 'I', the unitary matrix of left Schur */
715 /* > vectors of (H,T), and if COMPQ = 'V', the unitary matrix of */
716 /* > left Schur vectors of (A,B). */
717 /* > Not referenced if COMPQ = 'N'. */
720 /* > \param[in] LDQ */
722 /* > LDQ is INTEGER */
723 /* > The leading dimension of the array Q. LDQ >= 1. */
724 /* > If COMPQ='V' or 'I', then LDQ >= N. */
727 /* > \param[in,out] Z */
729 /* > Z is COMPLEX*16 array, dimension (LDZ, N) */
730 /* > On entry, if COMPZ = 'V', the unitary matrix Z1 used in the */
731 /* > reduction of (A,B) to generalized Hessenberg form. */
732 /* > On exit, if COMPZ = 'I', the unitary matrix of right Schur */
733 /* > vectors of (H,T), and if COMPZ = 'V', the unitary matrix of */
734 /* > right Schur vectors of (A,B). */
735 /* > Not referenced if COMPZ = 'N'. */
738 /* > \param[in] LDZ */
740 /* > LDZ is INTEGER */
741 /* > The leading dimension of the array Z. LDZ >= 1. */
742 /* > If COMPZ='V' or 'I', then LDZ >= N. */
745 /* > \param[out] WORK */
747 /* > WORK is COMPLEX*16 array, dimension (MAX(1,LWORK)) */
748 /* > On exit, if INFO >= 0, WORK(1) returns the optimal LWORK. */
751 /* > \param[in] LWORK */
753 /* > LWORK is INTEGER */
754 /* > The dimension of the array WORK. LWORK >= f2cmax(1,N). */
756 /* > If LWORK = -1, then a workspace query is assumed; the routine */
757 /* > only calculates the optimal size of the WORK array, returns */
758 /* > this value as the first entry of the WORK array, and no error */
759 /* > message related to LWORK is issued by XERBLA. */
762 /* > \param[out] RWORK */
764 /* > RWORK is DOUBLE PRECISION array, dimension (N) */
767 /* > \param[out] INFO */
769 /* > INFO is INTEGER */
770 /* > = 0: successful exit */
771 /* > < 0: if INFO = -i, the i-th argument had an illegal value */
772 /* > = 1,...,N: the QZ iteration did not converge. (H,T) is not */
773 /* > in Schur form, but ALPHA(i) and BETA(i), */
774 /* > i=INFO+1,...,N should be correct. */
775 /* > = N+1,...,2*N: the shift calculation failed. (H,T) is not */
776 /* > in Schur form, but ALPHA(i) and BETA(i), */
777 /* > i=INFO-N+1,...,N should be correct. */
783 /* > \author Univ. of Tennessee */
784 /* > \author Univ. of California Berkeley */
785 /* > \author Univ. of Colorado Denver */
786 /* > \author NAG Ltd. */
788 /* > \date April 2012 */
790 /* > \ingroup complex16GEcomputational */
792 /* > \par Further Details: */
793 /* ===================== */
797 /* > We assume that complex ABS works as long as its value is less than */
801 /* ===================================================================== */
802 /* Subroutine */ int zhgeqz_(char *job, char *compq, char *compz, integer *n,
803 integer *ilo, integer *ihi, doublecomplex *h__, integer *ldh,
804 doublecomplex *t, integer *ldt, doublecomplex *alpha, doublecomplex *
805 beta, doublecomplex *q, integer *ldq, doublecomplex *z__, integer *
806 ldz, doublecomplex *work, integer *lwork, doublereal *rwork, integer *
809 /* System generated locals */
810 integer h_dim1, h_offset, q_dim1, q_offset, t_dim1, t_offset, z_dim1,
811 z_offset, i__1, i__2, i__3, i__4, i__5, i__6;
812 doublereal d__1, d__2, d__3, d__4, d__5, d__6;
813 doublecomplex z__1, z__2, z__3, z__4, z__5, z__6, z__7;
815 /* Local variables */
816 doublereal absb, atol, btol, temp;
817 extern /* Subroutine */ int zrot_(integer *, doublecomplex *, integer *,
818 doublecomplex *, integer *, doublereal *, doublecomplex *);
819 doublereal temp2, c__;
821 doublecomplex s, x, y;
822 extern logical lsame_(char *, char *);
824 integer iiter, ilast, jiter;
825 doublereal anorm, bnorm;
828 extern /* Subroutine */ int zscal_(integer *, doublecomplex *,
829 doublecomplex *, integer *);
831 doublecomplex ctemp2, ctemp3;
834 doublereal ascale, bscale;
836 extern doublereal dlamch_(char *);
838 doublecomplex signbc;
840 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
841 doublecomplex eshift;
843 integer icompq, ilastm;
844 extern /* Double Complex */ VOID zladiv_(doublecomplex *, doublecomplex *,
847 extern doublereal zlanhs_(char *, integer *, doublecomplex *, integer *,
850 integer icompz, ifirst;
851 extern /* Subroutine */ int zlartg_(doublecomplex *, doublecomplex *,
852 doublereal *, doublecomplex *, doublecomplex *);
854 extern /* Subroutine */ int zlaset_(char *, integer *, integer *,
855 doublecomplex *, doublecomplex *, doublecomplex *, integer *);
858 doublecomplex ad11, ad12, ad21, ad22;
862 doublecomplex abi12, abi22;
865 /* -- LAPACK computational routine (version 3.7.0) -- */
866 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
867 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
871 /* ===================================================================== */
874 /* Decode JOB, COMPQ, COMPZ */
876 /* Parameter adjustments */
878 h_offset = 1 + h_dim1 * 1;
881 t_offset = 1 + t_dim1 * 1;
886 q_offset = 1 + q_dim1 * 1;
889 z_offset = 1 + z_dim1 * 1;
895 if (lsame_(job, "E")) {
898 } else if (lsame_(job, "S")) {
906 if (lsame_(compq, "N")) {
909 } else if (lsame_(compq, "V")) {
912 } else if (lsame_(compq, "I")) {
920 if (lsame_(compz, "N")) {
923 } else if (lsame_(compz, "V")) {
926 } else if (lsame_(compz, "I")) {
934 /* Check Argument Values */
938 work[1].r = (doublereal) i__1, work[1].i = 0.;
939 lquery = *lwork == -1;
942 } else if (icompq == 0) {
944 } else if (icompz == 0) {
948 } else if (*ilo < 1) {
950 } else if (*ihi > *n || *ihi < *ilo - 1) {
952 } else if (*ldh < *n) {
954 } else if (*ldt < *n) {
956 } else if (*ldq < 1 || ilq && *ldq < *n) {
958 } else if (*ldz < 1 || ilz && *ldz < *n) {
960 } else if (*lwork < f2cmax(1,*n) && ! lquery) {
965 xerbla_("ZHGEQZ", &i__1, (ftnlen)6);
971 /* Quick return if possible */
973 /* WORK( 1 ) = CMPLX( 1 ) */
975 work[1].r = 1., work[1].i = 0.;
979 /* Initialize Q and Z */
982 zlaset_("Full", n, n, &c_b1, &c_b2, &q[q_offset], ldq);
985 zlaset_("Full", n, n, &c_b1, &c_b2, &z__[z_offset], ldz);
988 /* Machine Constants */
990 in = *ihi + 1 - *ilo;
991 safmin = dlamch_("S");
992 ulp = dlamch_("E") * dlamch_("B");
993 anorm = zlanhs_("F", &in, &h__[*ilo + *ilo * h_dim1], ldh, &rwork[1]);
994 bnorm = zlanhs_("F", &in, &t[*ilo + *ilo * t_dim1], ldt, &rwork[1]);
996 d__1 = safmin, d__2 = ulp * anorm;
997 atol = f2cmax(d__1,d__2);
999 d__1 = safmin, d__2 = ulp * bnorm;
1000 btol = f2cmax(d__1,d__2);
1001 ascale = 1. / f2cmax(safmin,anorm);
1002 bscale = 1. / f2cmax(safmin,bnorm);
1005 /* Set Eigenvalues IHI+1:N */
1008 for (j = *ihi + 1; j <= i__1; ++j) {
1009 absb = z_abs(&t[j + j * t_dim1]);
1010 if (absb > safmin) {
1011 i__2 = j + j * t_dim1;
1012 z__2.r = t[i__2].r / absb, z__2.i = t[i__2].i / absb;
1013 d_cnjg(&z__1, &z__2);
1014 signbc.r = z__1.r, signbc.i = z__1.i;
1015 i__2 = j + j * t_dim1;
1016 t[i__2].r = absb, t[i__2].i = 0.;
1019 zscal_(&i__2, &signbc, &t[j * t_dim1 + 1], &c__1);
1020 zscal_(&j, &signbc, &h__[j * h_dim1 + 1], &c__1);
1022 zscal_(&c__1, &signbc, &h__[j + j * h_dim1], &c__1);
1025 zscal_(n, &signbc, &z__[j * z_dim1 + 1], &c__1);
1028 i__2 = j + j * t_dim1;
1029 t[i__2].r = 0., t[i__2].i = 0.;
1032 i__3 = j + j * h_dim1;
1033 alpha[i__2].r = h__[i__3].r, alpha[i__2].i = h__[i__3].i;
1035 i__3 = j + j * t_dim1;
1036 beta[i__2].r = t[i__3].r, beta[i__2].i = t[i__3].i;
1040 /* If IHI < ILO, skip QZ steps */
1046 /* MAIN QZ ITERATION LOOP */
1048 /* Initialize dynamic indices */
1050 /* Eigenvalues ILAST+1:N have been found. */
1051 /* Column operations modify rows IFRSTM:whatever */
1052 /* Row operations modify columns whatever:ILASTM */
1054 /* If only eigenvalues are being computed, then */
1055 /* IFRSTM is the row of the last splitting row above row ILAST; */
1056 /* this is always at least ILO. */
1057 /* IITER counts iterations since the last eigenvalue was found, */
1058 /* to tell when to use an extraordinary shift. */
1059 /* MAXIT is the maximum number of QZ sweeps allowed. */
1070 eshift.r = 0., eshift.i = 0.;
1071 maxit = (*ihi - *ilo + 1) * 30;
1074 for (jiter = 1; jiter <= i__1; ++jiter) {
1076 /* Check for too many iterations. */
1078 if (jiter > maxit) {
1082 /* Split the matrix if possible. */
1085 /* 1: H(j,j-1)=0 or j=ILO */
1088 /* Special case: j=ILAST */
1090 if (ilast == *ilo) {
1093 i__2 = ilast + (ilast - 1) * h_dim1;
1094 if ((d__1 = h__[i__2].r, abs(d__1)) + (d__2 = d_imag(&h__[ilast +
1095 (ilast - 1) * h_dim1]), abs(d__2)) <= atol) {
1096 i__2 = ilast + (ilast - 1) * h_dim1;
1097 h__[i__2].r = 0., h__[i__2].i = 0.;
1102 if (z_abs(&t[ilast + ilast * t_dim1]) <= btol) {
1103 i__2 = ilast + ilast * t_dim1;
1104 t[i__2].r = 0., t[i__2].i = 0.;
1108 /* General case: j<ILAST */
1111 for (j = ilast - 1; j >= i__2; --j) {
1113 /* Test 1: for H(j,j-1)=0 or j=ILO */
1118 i__3 = j + (j - 1) * h_dim1;
1119 if ((d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&h__[j +
1120 (j - 1) * h_dim1]), abs(d__2)) <= atol) {
1121 i__3 = j + (j - 1) * h_dim1;
1122 h__[i__3].r = 0., h__[i__3].i = 0.;
1129 /* Test 2: for T(j,j)=0 */
1131 if (z_abs(&t[j + j * t_dim1]) < btol) {
1132 i__3 = j + j * t_dim1;
1133 t[i__3].r = 0., t[i__3].i = 0.;
1135 /* Test 1a: Check for 2 consecutive small subdiagonals in A */
1139 i__3 = j + (j - 1) * h_dim1;
1140 i__4 = j + 1 + j * h_dim1;
1141 i__5 = j + j * h_dim1;
1142 if (((d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&
1143 h__[j + (j - 1) * h_dim1]), abs(d__2))) * (ascale
1144 * ((d__3 = h__[i__4].r, abs(d__3)) + (d__4 =
1145 d_imag(&h__[j + 1 + j * h_dim1]), abs(d__4)))) <=
1146 ((d__5 = h__[i__5].r, abs(d__5)) + (d__6 = d_imag(
1147 &h__[j + j * h_dim1]), abs(d__6))) * (ascale *
1153 /* If both tests pass (1 & 2), i.e., the leading diagonal */
1154 /* element of B in the block is zero, split a 1x1 block off */
1155 /* at the top. (I.e., at the J-th row/column) The leading */
1156 /* diagonal element of the remainder can also be zero, so */
1157 /* this may have to be done repeatedly. */
1159 if (ilazro || ilazr2) {
1161 for (jch = j; jch <= i__3; ++jch) {
1162 i__4 = jch + jch * h_dim1;
1163 ctemp.r = h__[i__4].r, ctemp.i = h__[i__4].i;
1164 zlartg_(&ctemp, &h__[jch + 1 + jch * h_dim1], &c__, &
1165 s, &h__[jch + jch * h_dim1]);
1166 i__4 = jch + 1 + jch * h_dim1;
1167 h__[i__4].r = 0., h__[i__4].i = 0.;
1168 i__4 = ilastm - jch;
1169 zrot_(&i__4, &h__[jch + (jch + 1) * h_dim1], ldh, &
1170 h__[jch + 1 + (jch + 1) * h_dim1], ldh, &c__,
1172 i__4 = ilastm - jch;
1173 zrot_(&i__4, &t[jch + (jch + 1) * t_dim1], ldt, &t[
1174 jch + 1 + (jch + 1) * t_dim1], ldt, &c__, &s);
1177 zrot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
1178 * q_dim1 + 1], &c__1, &c__, &z__1);
1181 i__4 = jch + (jch - 1) * h_dim1;
1182 i__5 = jch + (jch - 1) * h_dim1;
1183 z__1.r = c__ * h__[i__5].r, z__1.i = c__ * h__[
1185 h__[i__4].r = z__1.r, h__[i__4].i = z__1.i;
1188 i__4 = jch + 1 + (jch + 1) * t_dim1;
1189 if ((d__1 = t[i__4].r, abs(d__1)) + (d__2 = d_imag(&t[
1190 jch + 1 + (jch + 1) * t_dim1]), abs(d__2)) >=
1192 if (jch + 1 >= ilast) {
1199 i__4 = jch + 1 + (jch + 1) * t_dim1;
1200 t[i__4].r = 0., t[i__4].i = 0.;
1206 /* Only test 2 passed -- chase the zero to T(ILAST,ILAST) */
1207 /* Then process as in the case T(ILAST,ILAST)=0 */
1210 for (jch = j; jch <= i__3; ++jch) {
1211 i__4 = jch + (jch + 1) * t_dim1;
1212 ctemp.r = t[i__4].r, ctemp.i = t[i__4].i;
1213 zlartg_(&ctemp, &t[jch + 1 + (jch + 1) * t_dim1], &
1214 c__, &s, &t[jch + (jch + 1) * t_dim1]);
1215 i__4 = jch + 1 + (jch + 1) * t_dim1;
1216 t[i__4].r = 0., t[i__4].i = 0.;
1217 if (jch < ilastm - 1) {
1218 i__4 = ilastm - jch - 1;
1219 zrot_(&i__4, &t[jch + (jch + 2) * t_dim1], ldt, &
1220 t[jch + 1 + (jch + 2) * t_dim1], ldt, &
1223 i__4 = ilastm - jch + 2;
1224 zrot_(&i__4, &h__[jch + (jch - 1) * h_dim1], ldh, &
1225 h__[jch + 1 + (jch - 1) * h_dim1], ldh, &c__,
1229 zrot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
1230 * q_dim1 + 1], &c__1, &c__, &z__1);
1232 i__4 = jch + 1 + jch * h_dim1;
1233 ctemp.r = h__[i__4].r, ctemp.i = h__[i__4].i;
1234 zlartg_(&ctemp, &h__[jch + 1 + (jch - 1) * h_dim1], &
1235 c__, &s, &h__[jch + 1 + jch * h_dim1]);
1236 i__4 = jch + 1 + (jch - 1) * h_dim1;
1237 h__[i__4].r = 0., h__[i__4].i = 0.;
1238 i__4 = jch + 1 - ifrstm;
1239 zrot_(&i__4, &h__[ifrstm + jch * h_dim1], &c__1, &h__[
1240 ifrstm + (jch - 1) * h_dim1], &c__1, &c__, &s)
1242 i__4 = jch - ifrstm;
1243 zrot_(&i__4, &t[ifrstm + jch * t_dim1], &c__1, &t[
1244 ifrstm + (jch - 1) * t_dim1], &c__1, &c__, &s)
1247 zrot_(n, &z__[jch * z_dim1 + 1], &c__1, &z__[(jch
1248 - 1) * z_dim1 + 1], &c__1, &c__, &s);
1254 } else if (ilazro) {
1256 /* Only test 1 passed -- work on J:ILAST */
1262 /* Neither test passed -- try next J */
1267 /* (Drop-through is "impossible") */
1269 *info = (*n << 1) + 1;
1272 /* T(ILAST,ILAST)=0 -- clear H(ILAST,ILAST-1) to split off a */
1276 i__2 = ilast + ilast * h_dim1;
1277 ctemp.r = h__[i__2].r, ctemp.i = h__[i__2].i;
1278 zlartg_(&ctemp, &h__[ilast + (ilast - 1) * h_dim1], &c__, &s, &h__[
1279 ilast + ilast * h_dim1]);
1280 i__2 = ilast + (ilast - 1) * h_dim1;
1281 h__[i__2].r = 0., h__[i__2].i = 0.;
1282 i__2 = ilast - ifrstm;
1283 zrot_(&i__2, &h__[ifrstm + ilast * h_dim1], &c__1, &h__[ifrstm + (
1284 ilast - 1) * h_dim1], &c__1, &c__, &s);
1285 i__2 = ilast - ifrstm;
1286 zrot_(&i__2, &t[ifrstm + ilast * t_dim1], &c__1, &t[ifrstm + (ilast -
1287 1) * t_dim1], &c__1, &c__, &s);
1289 zrot_(n, &z__[ilast * z_dim1 + 1], &c__1, &z__[(ilast - 1) *
1290 z_dim1 + 1], &c__1, &c__, &s);
1293 /* H(ILAST,ILAST-1)=0 -- Standardize B, set ALPHA and BETA */
1296 absb = z_abs(&t[ilast + ilast * t_dim1]);
1297 if (absb > safmin) {
1298 i__2 = ilast + ilast * t_dim1;
1299 z__2.r = t[i__2].r / absb, z__2.i = t[i__2].i / absb;
1300 d_cnjg(&z__1, &z__2);
1301 signbc.r = z__1.r, signbc.i = z__1.i;
1302 i__2 = ilast + ilast * t_dim1;
1303 t[i__2].r = absb, t[i__2].i = 0.;
1305 i__2 = ilast - ifrstm;
1306 zscal_(&i__2, &signbc, &t[ifrstm + ilast * t_dim1], &c__1);
1307 i__2 = ilast + 1 - ifrstm;
1308 zscal_(&i__2, &signbc, &h__[ifrstm + ilast * h_dim1], &c__1);
1310 zscal_(&c__1, &signbc, &h__[ilast + ilast * h_dim1], &c__1);
1313 zscal_(n, &signbc, &z__[ilast * z_dim1 + 1], &c__1);
1316 i__2 = ilast + ilast * t_dim1;
1317 t[i__2].r = 0., t[i__2].i = 0.;
1320 i__3 = ilast + ilast * h_dim1;
1321 alpha[i__2].r = h__[i__3].r, alpha[i__2].i = h__[i__3].i;
1323 i__3 = ilast + ilast * t_dim1;
1324 beta[i__2].r = t[i__3].r, beta[i__2].i = t[i__3].i;
1326 /* Go to next block -- exit if finished. */
1333 /* Reset counters */
1336 eshift.r = 0., eshift.i = 0.;
1339 if (ifrstm > ilast) {
1347 /* This iteration only involves rows/columns IFIRST:ILAST. We */
1348 /* assume IFIRST < ILAST, and that the diagonal of B is non-zero. */
1356 /* Compute the Shift. */
1358 /* At this point, IFIRST < ILAST, and the diagonal elements of */
1359 /* T(IFIRST:ILAST,IFIRST,ILAST) are larger than BTOL (in */
1362 if (iiter / 10 * 10 != iiter) {
1364 /* The Wilkinson shift (AEP p.512), i.e., the eigenvalue of */
1365 /* the bottom-right 2x2 block of A inv(B) which is nearest to */
1366 /* the bottom-right element. */
1368 /* We factor B as U*D, where U has unit diagonals, and */
1369 /* compute (A*inv(D))*inv(U). */
1371 i__2 = ilast - 1 + ilast * t_dim1;
1372 z__2.r = bscale * t[i__2].r, z__2.i = bscale * t[i__2].i;
1373 i__3 = ilast + ilast * t_dim1;
1374 z__3.r = bscale * t[i__3].r, z__3.i = bscale * t[i__3].i;
1375 z_div(&z__1, &z__2, &z__3);
1376 u12.r = z__1.r, u12.i = z__1.i;
1377 i__2 = ilast - 1 + (ilast - 1) * h_dim1;
1378 z__2.r = ascale * h__[i__2].r, z__2.i = ascale * h__[i__2].i;
1379 i__3 = ilast - 1 + (ilast - 1) * t_dim1;
1380 z__3.r = bscale * t[i__3].r, z__3.i = bscale * t[i__3].i;
1381 z_div(&z__1, &z__2, &z__3);
1382 ad11.r = z__1.r, ad11.i = z__1.i;
1383 i__2 = ilast + (ilast - 1) * h_dim1;
1384 z__2.r = ascale * h__[i__2].r, z__2.i = ascale * h__[i__2].i;
1385 i__3 = ilast - 1 + (ilast - 1) * t_dim1;
1386 z__3.r = bscale * t[i__3].r, z__3.i = bscale * t[i__3].i;
1387 z_div(&z__1, &z__2, &z__3);
1388 ad21.r = z__1.r, ad21.i = z__1.i;
1389 i__2 = ilast - 1 + ilast * h_dim1;
1390 z__2.r = ascale * h__[i__2].r, z__2.i = ascale * h__[i__2].i;
1391 i__3 = ilast + ilast * t_dim1;
1392 z__3.r = bscale * t[i__3].r, z__3.i = bscale * t[i__3].i;
1393 z_div(&z__1, &z__2, &z__3);
1394 ad12.r = z__1.r, ad12.i = z__1.i;
1395 i__2 = ilast + ilast * h_dim1;
1396 z__2.r = ascale * h__[i__2].r, z__2.i = ascale * h__[i__2].i;
1397 i__3 = ilast + ilast * t_dim1;
1398 z__3.r = bscale * t[i__3].r, z__3.i = bscale * t[i__3].i;
1399 z_div(&z__1, &z__2, &z__3);
1400 ad22.r = z__1.r, ad22.i = z__1.i;
1401 z__2.r = u12.r * ad21.r - u12.i * ad21.i, z__2.i = u12.r * ad21.i
1403 z__1.r = ad22.r - z__2.r, z__1.i = ad22.i - z__2.i;
1404 abi22.r = z__1.r, abi22.i = z__1.i;
1405 z__2.r = u12.r * ad11.r - u12.i * ad11.i, z__2.i = u12.r * ad11.i
1407 z__1.r = ad12.r - z__2.r, z__1.i = ad12.i - z__2.i;
1408 abi12.r = z__1.r, abi12.i = z__1.i;
1410 shift.r = abi22.r, shift.i = abi22.i;
1411 z_sqrt(&z__2, &abi12);
1412 z_sqrt(&z__3, &ad21);
1413 z__1.r = z__2.r * z__3.r - z__2.i * z__3.i, z__1.i = z__2.r *
1414 z__3.i + z__2.i * z__3.r;
1415 ctemp.r = z__1.r, ctemp.i = z__1.i;
1416 temp = (d__1 = ctemp.r, abs(d__1)) + (d__2 = d_imag(&ctemp), abs(
1418 if (ctemp.r != 0. || ctemp.i != 0.) {
1419 z__2.r = ad11.r - shift.r, z__2.i = ad11.i - shift.i;
1420 z__1.r = z__2.r * .5, z__1.i = z__2.i * .5;
1421 x.r = z__1.r, x.i = z__1.i;
1422 temp2 = (d__1 = x.r, abs(d__1)) + (d__2 = d_imag(&x), abs(
1425 d__3 = temp, d__4 = (d__1 = x.r, abs(d__1)) + (d__2 = d_imag(&
1427 temp = f2cmax(d__3,d__4);
1428 z__5.r = x.r / temp, z__5.i = x.i / temp;
1429 pow_zi(&z__4, &z__5, &c__2);
1430 z__7.r = ctemp.r / temp, z__7.i = ctemp.i / temp;
1431 pow_zi(&z__6, &z__7, &c__2);
1432 z__3.r = z__4.r + z__6.r, z__3.i = z__4.i + z__6.i;
1433 z_sqrt(&z__2, &z__3);
1434 z__1.r = temp * z__2.r, z__1.i = temp * z__2.i;
1435 y.r = z__1.r, y.i = z__1.i;
1437 z__1.r = x.r / temp2, z__1.i = x.i / temp2;
1438 z__2.r = x.r / temp2, z__2.i = x.i / temp2;
1439 if (z__1.r * y.r + d_imag(&z__2) * d_imag(&y) < 0.) {
1440 z__3.r = -y.r, z__3.i = -y.i;
1441 y.r = z__3.r, y.i = z__3.i;
1444 z__4.r = x.r + y.r, z__4.i = x.i + y.i;
1445 zladiv_(&z__3, &ctemp, &z__4);
1446 z__2.r = ctemp.r * z__3.r - ctemp.i * z__3.i, z__2.i =
1447 ctemp.r * z__3.i + ctemp.i * z__3.r;
1448 z__1.r = shift.r - z__2.r, z__1.i = shift.i - z__2.i;
1449 shift.r = z__1.r, shift.i = z__1.i;
1453 /* Exceptional shift. Chosen for no particularly good reason. */
1455 i__2 = ilast + ilast * t_dim1;
1456 if (iiter / 20 * 20 == iiter && bscale * ((d__1 = t[i__2].r, abs(
1457 d__1)) + (d__2 = d_imag(&t[ilast + ilast * t_dim1]), abs(
1459 i__2 = ilast + ilast * h_dim1;
1460 z__3.r = ascale * h__[i__2].r, z__3.i = ascale * h__[i__2].i;
1461 i__3 = ilast + ilast * t_dim1;
1462 z__4.r = bscale * t[i__3].r, z__4.i = bscale * t[i__3].i;
1463 z_div(&z__2, &z__3, &z__4);
1464 z__1.r = eshift.r + z__2.r, z__1.i = eshift.i + z__2.i;
1465 eshift.r = z__1.r, eshift.i = z__1.i;
1467 i__2 = ilast + (ilast - 1) * h_dim1;
1468 z__3.r = ascale * h__[i__2].r, z__3.i = ascale * h__[i__2].i;
1469 i__3 = ilast - 1 + (ilast - 1) * t_dim1;
1470 z__4.r = bscale * t[i__3].r, z__4.i = bscale * t[i__3].i;
1471 z_div(&z__2, &z__3, &z__4);
1472 z__1.r = eshift.r + z__2.r, z__1.i = eshift.i + z__2.i;
1473 eshift.r = z__1.r, eshift.i = z__1.i;
1475 shift.r = eshift.r, shift.i = eshift.i;
1478 /* Now check for two consecutive small subdiagonals. */
1481 for (j = ilast - 1; j >= i__2; --j) {
1483 i__3 = j + j * h_dim1;
1484 z__2.r = ascale * h__[i__3].r, z__2.i = ascale * h__[i__3].i;
1485 i__4 = j + j * t_dim1;
1486 z__4.r = bscale * t[i__4].r, z__4.i = bscale * t[i__4].i;
1487 z__3.r = shift.r * z__4.r - shift.i * z__4.i, z__3.i = shift.r *
1488 z__4.i + shift.i * z__4.r;
1489 z__1.r = z__2.r - z__3.r, z__1.i = z__2.i - z__3.i;
1490 ctemp.r = z__1.r, ctemp.i = z__1.i;
1491 temp = (d__1 = ctemp.r, abs(d__1)) + (d__2 = d_imag(&ctemp), abs(
1493 i__3 = j + 1 + j * h_dim1;
1494 temp2 = ascale * ((d__1 = h__[i__3].r, abs(d__1)) + (d__2 =
1495 d_imag(&h__[j + 1 + j * h_dim1]), abs(d__2)));
1496 tempr = f2cmax(temp,temp2);
1497 if (tempr < 1. && tempr != 0.) {
1501 i__3 = j + (j - 1) * h_dim1;
1502 if (((d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&h__[j + (j
1503 - 1) * h_dim1]), abs(d__2))) * temp2 <= temp * atol) {
1510 i__2 = ifirst + ifirst * h_dim1;
1511 z__2.r = ascale * h__[i__2].r, z__2.i = ascale * h__[i__2].i;
1512 i__3 = ifirst + ifirst * t_dim1;
1513 z__4.r = bscale * t[i__3].r, z__4.i = bscale * t[i__3].i;
1514 z__3.r = shift.r * z__4.r - shift.i * z__4.i, z__3.i = shift.r *
1515 z__4.i + shift.i * z__4.r;
1516 z__1.r = z__2.r - z__3.r, z__1.i = z__2.i - z__3.i;
1517 ctemp.r = z__1.r, ctemp.i = z__1.i;
1520 /* Do an implicit-shift QZ sweep. */
1524 i__2 = istart + 1 + istart * h_dim1;
1525 z__1.r = ascale * h__[i__2].r, z__1.i = ascale * h__[i__2].i;
1526 ctemp2.r = z__1.r, ctemp2.i = z__1.i;
1527 zlartg_(&ctemp, &ctemp2, &c__, &s, &ctemp3);
1532 for (j = istart; j <= i__2; ++j) {
1534 i__3 = j + (j - 1) * h_dim1;
1535 ctemp.r = h__[i__3].r, ctemp.i = h__[i__3].i;
1536 zlartg_(&ctemp, &h__[j + 1 + (j - 1) * h_dim1], &c__, &s, &
1537 h__[j + (j - 1) * h_dim1]);
1538 i__3 = j + 1 + (j - 1) * h_dim1;
1539 h__[i__3].r = 0., h__[i__3].i = 0.;
1543 for (jc = j; jc <= i__3; ++jc) {
1544 i__4 = j + jc * h_dim1;
1545 z__2.r = c__ * h__[i__4].r, z__2.i = c__ * h__[i__4].i;
1546 i__5 = j + 1 + jc * h_dim1;
1547 z__3.r = s.r * h__[i__5].r - s.i * h__[i__5].i, z__3.i = s.r *
1548 h__[i__5].i + s.i * h__[i__5].r;
1549 z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1550 ctemp.r = z__1.r, ctemp.i = z__1.i;
1551 i__4 = j + 1 + jc * h_dim1;
1553 z__3.r = -z__4.r, z__3.i = -z__4.i;
1554 i__5 = j + jc * h_dim1;
1555 z__2.r = z__3.r * h__[i__5].r - z__3.i * h__[i__5].i, z__2.i =
1556 z__3.r * h__[i__5].i + z__3.i * h__[i__5].r;
1557 i__6 = j + 1 + jc * h_dim1;
1558 z__5.r = c__ * h__[i__6].r, z__5.i = c__ * h__[i__6].i;
1559 z__1.r = z__2.r + z__5.r, z__1.i = z__2.i + z__5.i;
1560 h__[i__4].r = z__1.r, h__[i__4].i = z__1.i;
1561 i__4 = j + jc * h_dim1;
1562 h__[i__4].r = ctemp.r, h__[i__4].i = ctemp.i;
1563 i__4 = j + jc * t_dim1;
1564 z__2.r = c__ * t[i__4].r, z__2.i = c__ * t[i__4].i;
1565 i__5 = j + 1 + jc * t_dim1;
1566 z__3.r = s.r * t[i__5].r - s.i * t[i__5].i, z__3.i = s.r * t[
1567 i__5].i + s.i * t[i__5].r;
1568 z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1569 ctemp2.r = z__1.r, ctemp2.i = z__1.i;
1570 i__4 = j + 1 + jc * t_dim1;
1572 z__3.r = -z__4.r, z__3.i = -z__4.i;
1573 i__5 = j + jc * t_dim1;
1574 z__2.r = z__3.r * t[i__5].r - z__3.i * t[i__5].i, z__2.i =
1575 z__3.r * t[i__5].i + z__3.i * t[i__5].r;
1576 i__6 = j + 1 + jc * t_dim1;
1577 z__5.r = c__ * t[i__6].r, z__5.i = c__ * t[i__6].i;
1578 z__1.r = z__2.r + z__5.r, z__1.i = z__2.i + z__5.i;
1579 t[i__4].r = z__1.r, t[i__4].i = z__1.i;
1580 i__4 = j + jc * t_dim1;
1581 t[i__4].r = ctemp2.r, t[i__4].i = ctemp2.i;
1586 for (jr = 1; jr <= i__3; ++jr) {
1587 i__4 = jr + j * q_dim1;
1588 z__2.r = c__ * q[i__4].r, z__2.i = c__ * q[i__4].i;
1590 i__5 = jr + (j + 1) * q_dim1;
1591 z__3.r = z__4.r * q[i__5].r - z__4.i * q[i__5].i, z__3.i =
1592 z__4.r * q[i__5].i + z__4.i * q[i__5].r;
1593 z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1594 ctemp.r = z__1.r, ctemp.i = z__1.i;
1595 i__4 = jr + (j + 1) * q_dim1;
1596 z__3.r = -s.r, z__3.i = -s.i;
1597 i__5 = jr + j * q_dim1;
1598 z__2.r = z__3.r * q[i__5].r - z__3.i * q[i__5].i, z__2.i =
1599 z__3.r * q[i__5].i + z__3.i * q[i__5].r;
1600 i__6 = jr + (j + 1) * q_dim1;
1601 z__4.r = c__ * q[i__6].r, z__4.i = c__ * q[i__6].i;
1602 z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
1603 q[i__4].r = z__1.r, q[i__4].i = z__1.i;
1604 i__4 = jr + j * q_dim1;
1605 q[i__4].r = ctemp.r, q[i__4].i = ctemp.i;
1610 i__3 = j + 1 + (j + 1) * t_dim1;
1611 ctemp.r = t[i__3].r, ctemp.i = t[i__3].i;
1612 zlartg_(&ctemp, &t[j + 1 + j * t_dim1], &c__, &s, &t[j + 1 + (j +
1614 i__3 = j + 1 + j * t_dim1;
1615 t[i__3].r = 0., t[i__3].i = 0.;
1619 i__3 = f2cmin(i__4,ilast);
1620 for (jr = ifrstm; jr <= i__3; ++jr) {
1621 i__4 = jr + (j + 1) * h_dim1;
1622 z__2.r = c__ * h__[i__4].r, z__2.i = c__ * h__[i__4].i;
1623 i__5 = jr + j * h_dim1;
1624 z__3.r = s.r * h__[i__5].r - s.i * h__[i__5].i, z__3.i = s.r *
1625 h__[i__5].i + s.i * h__[i__5].r;
1626 z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1627 ctemp.r = z__1.r, ctemp.i = z__1.i;
1628 i__4 = jr + j * h_dim1;
1630 z__3.r = -z__4.r, z__3.i = -z__4.i;
1631 i__5 = jr + (j + 1) * h_dim1;
1632 z__2.r = z__3.r * h__[i__5].r - z__3.i * h__[i__5].i, z__2.i =
1633 z__3.r * h__[i__5].i + z__3.i * h__[i__5].r;
1634 i__6 = jr + j * h_dim1;
1635 z__5.r = c__ * h__[i__6].r, z__5.i = c__ * h__[i__6].i;
1636 z__1.r = z__2.r + z__5.r, z__1.i = z__2.i + z__5.i;
1637 h__[i__4].r = z__1.r, h__[i__4].i = z__1.i;
1638 i__4 = jr + (j + 1) * h_dim1;
1639 h__[i__4].r = ctemp.r, h__[i__4].i = ctemp.i;
1643 for (jr = ifrstm; jr <= i__3; ++jr) {
1644 i__4 = jr + (j + 1) * t_dim1;
1645 z__2.r = c__ * t[i__4].r, z__2.i = c__ * t[i__4].i;
1646 i__5 = jr + j * t_dim1;
1647 z__3.r = s.r * t[i__5].r - s.i * t[i__5].i, z__3.i = s.r * t[
1648 i__5].i + s.i * t[i__5].r;
1649 z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1650 ctemp.r = z__1.r, ctemp.i = z__1.i;
1651 i__4 = jr + j * t_dim1;
1653 z__3.r = -z__4.r, z__3.i = -z__4.i;
1654 i__5 = jr + (j + 1) * t_dim1;
1655 z__2.r = z__3.r * t[i__5].r - z__3.i * t[i__5].i, z__2.i =
1656 z__3.r * t[i__5].i + z__3.i * t[i__5].r;
1657 i__6 = jr + j * t_dim1;
1658 z__5.r = c__ * t[i__6].r, z__5.i = c__ * t[i__6].i;
1659 z__1.r = z__2.r + z__5.r, z__1.i = z__2.i + z__5.i;
1660 t[i__4].r = z__1.r, t[i__4].i = z__1.i;
1661 i__4 = jr + (j + 1) * t_dim1;
1662 t[i__4].r = ctemp.r, t[i__4].i = ctemp.i;
1667 for (jr = 1; jr <= i__3; ++jr) {
1668 i__4 = jr + (j + 1) * z_dim1;
1669 z__2.r = c__ * z__[i__4].r, z__2.i = c__ * z__[i__4].i;
1670 i__5 = jr + j * z_dim1;
1671 z__3.r = s.r * z__[i__5].r - s.i * z__[i__5].i, z__3.i =
1672 s.r * z__[i__5].i + s.i * z__[i__5].r;
1673 z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1674 ctemp.r = z__1.r, ctemp.i = z__1.i;
1675 i__4 = jr + j * z_dim1;
1677 z__3.r = -z__4.r, z__3.i = -z__4.i;
1678 i__5 = jr + (j + 1) * z_dim1;
1679 z__2.r = z__3.r * z__[i__5].r - z__3.i * z__[i__5].i,
1680 z__2.i = z__3.r * z__[i__5].i + z__3.i * z__[i__5]
1682 i__6 = jr + j * z_dim1;
1683 z__5.r = c__ * z__[i__6].r, z__5.i = c__ * z__[i__6].i;
1684 z__1.r = z__2.r + z__5.r, z__1.i = z__2.i + z__5.i;
1685 z__[i__4].r = z__1.r, z__[i__4].i = z__1.i;
1686 i__4 = jr + (j + 1) * z_dim1;
1687 z__[i__4].r = ctemp.r, z__[i__4].i = ctemp.i;
1700 /* Drop-through = non-convergence */
1706 /* Successful completion of all QZ steps */
1710 /* Set Eigenvalues 1:ILO-1 */
1713 for (j = 1; j <= i__1; ++j) {
1714 absb = z_abs(&t[j + j * t_dim1]);
1715 if (absb > safmin) {
1716 i__2 = j + j * t_dim1;
1717 z__2.r = t[i__2].r / absb, z__2.i = t[i__2].i / absb;
1718 d_cnjg(&z__1, &z__2);
1719 signbc.r = z__1.r, signbc.i = z__1.i;
1720 i__2 = j + j * t_dim1;
1721 t[i__2].r = absb, t[i__2].i = 0.;
1724 zscal_(&i__2, &signbc, &t[j * t_dim1 + 1], &c__1);
1725 zscal_(&j, &signbc, &h__[j * h_dim1 + 1], &c__1);
1727 zscal_(&c__1, &signbc, &h__[j + j * h_dim1], &c__1);
1730 zscal_(n, &signbc, &z__[j * z_dim1 + 1], &c__1);
1733 i__2 = j + j * t_dim1;
1734 t[i__2].r = 0., t[i__2].i = 0.;
1737 i__3 = j + j * h_dim1;
1738 alpha[i__2].r = h__[i__3].r, alpha[i__2].i = h__[i__3].i;
1740 i__3 = j + j * t_dim1;
1741 beta[i__2].r = t[i__3].r, beta[i__2].i = t[i__3].i;
1745 /* Normal Termination */
1749 /* Exit (other than argument error) -- return optimal workspace size */
1752 z__1.r = (doublereal) (*n), z__1.i = 0.;
1753 work[1].r = z__1.r, work[1].i = z__1.i;