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]/df(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)
513 /* Table of constant values */
515 static real c_b12 = 0.f;
516 static real c_b13 = 1.f;
517 static integer c__1 = 1;
518 static integer c__3 = 3;
520 /* > \brief \b SHGEQZ */
522 /* =========== DOCUMENTATION =========== */
524 /* Online html documentation available at */
525 /* http://www.netlib.org/lapack/explore-html/ */
528 /* > Download SHGEQZ + dependencies */
529 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/shgeqz.
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/shgeqz.
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/shgeqz.
543 /* SUBROUTINE SHGEQZ( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT, */
544 /* ALPHAR, ALPHAI, BETA, Q, LDQ, Z, LDZ, WORK, */
547 /* CHARACTER COMPQ, COMPZ, JOB */
548 /* INTEGER IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N */
549 /* REAL ALPHAI( * ), ALPHAR( * ), BETA( * ), */
550 /* $ H( LDH, * ), Q( LDQ, * ), T( LDT, * ), */
551 /* $ WORK( * ), Z( LDZ, * ) */
554 /* > \par Purpose: */
559 /* > SHGEQZ computes the eigenvalues of a real matrix pair (H,T), */
560 /* > where H is an upper Hessenberg matrix and T is upper triangular, */
561 /* > using the double-shift QZ method. */
562 /* > Matrix pairs of this type are produced by the reduction to */
563 /* > generalized upper Hessenberg form of a real matrix pair (A,B): */
565 /* > A = Q1*H*Z1**T, B = Q1*T*Z1**T, */
567 /* > as computed by SGGHRD. */
569 /* > If JOB='S', then the Hessenberg-triangular pair (H,T) is */
570 /* > also reduced to generalized Schur form, */
572 /* > H = Q*S*Z**T, T = Q*P*Z**T, */
574 /* > where Q and Z are orthogonal matrices, P is an upper triangular */
575 /* > matrix, and S is a quasi-triangular matrix with 1-by-1 and 2-by-2 */
576 /* > diagonal blocks. */
578 /* > The 1-by-1 blocks correspond to real eigenvalues of the matrix pair */
579 /* > (H,T) and the 2-by-2 blocks correspond to complex conjugate pairs of */
582 /* > Additionally, the 2-by-2 upper triangular diagonal blocks of P */
583 /* > corresponding to 2-by-2 blocks of S are reduced to positive diagonal */
584 /* > form, i.e., if S(j+1,j) is non-zero, then P(j+1,j) = P(j,j+1) = 0, */
585 /* > P(j,j) > 0, and P(j+1,j+1) > 0. */
587 /* > Optionally, the orthogonal matrix Q from the generalized Schur */
588 /* > factorization may be postmultiplied into an input matrix Q1, and the */
589 /* > orthogonal matrix Z may be postmultiplied into an input matrix Z1. */
590 /* > If Q1 and Z1 are the orthogonal matrices from SGGHRD that reduced */
591 /* > the matrix pair (A,B) to generalized upper Hessenberg form, then the */
592 /* > output matrices Q1*Q and Z1*Z are the orthogonal factors from the */
593 /* > generalized Schur factorization of (A,B): */
595 /* > A = (Q1*Q)*S*(Z1*Z)**T, B = (Q1*Q)*P*(Z1*Z)**T. */
597 /* > To avoid overflow, eigenvalues of the matrix pair (H,T) (equivalently, */
598 /* > of (A,B)) are computed as a pair of values (alpha,beta), where alpha is */
599 /* > complex and beta real. */
600 /* > If beta is nonzero, lambda = alpha / beta is an eigenvalue of the */
601 /* > generalized nonsymmetric eigenvalue problem (GNEP) */
602 /* > A*x = lambda*B*x */
603 /* > and if alpha is nonzero, mu = beta / alpha is an eigenvalue of the */
604 /* > alternate form of the GNEP */
605 /* > mu*A*y = B*y. */
606 /* > Real eigenvalues can be read directly from the generalized Schur */
608 /* > alpha = S(i,i), beta = P(i,i). */
610 /* > Ref: C.B. Moler & G.W. Stewart, "An Algorithm for Generalized Matrix */
611 /* > Eigenvalue Problems", SIAM J. Numer. Anal., 10(1973), */
612 /* > pp. 241--256. */
618 /* > \param[in] JOB */
620 /* > JOB is CHARACTER*1 */
621 /* > = 'E': Compute eigenvalues only; */
622 /* > = 'S': Compute eigenvalues and the Schur form. */
625 /* > \param[in] COMPQ */
627 /* > COMPQ is CHARACTER*1 */
628 /* > = 'N': Left Schur vectors (Q) are not computed; */
629 /* > = 'I': Q is initialized to the unit matrix and the matrix Q */
630 /* > of left Schur vectors of (H,T) is returned; */
631 /* > = 'V': Q must contain an orthogonal matrix Q1 on entry and */
632 /* > the product Q1*Q is returned. */
635 /* > \param[in] COMPZ */
637 /* > COMPZ is CHARACTER*1 */
638 /* > = 'N': Right Schur vectors (Z) are not computed; */
639 /* > = 'I': Z is initialized to the unit matrix and the matrix Z */
640 /* > of right Schur vectors of (H,T) is returned; */
641 /* > = 'V': Z must contain an orthogonal matrix Z1 on entry and */
642 /* > the product Z1*Z is returned. */
648 /* > The order of the matrices H, T, Q, and Z. N >= 0. */
651 /* > \param[in] ILO */
653 /* > ILO is INTEGER */
656 /* > \param[in] IHI */
658 /* > IHI is INTEGER */
659 /* > ILO and IHI mark the rows and columns of H which are in */
660 /* > Hessenberg form. It is assumed that A is already upper */
661 /* > triangular in rows and columns 1:ILO-1 and IHI+1:N. */
662 /* > If N > 0, 1 <= ILO <= IHI <= N; if N = 0, ILO=1 and IHI=0. */
665 /* > \param[in,out] H */
667 /* > H is REAL array, dimension (LDH, N) */
668 /* > On entry, the N-by-N upper Hessenberg matrix H. */
669 /* > On exit, if JOB = 'S', H contains the upper quasi-triangular */
670 /* > matrix S from the generalized Schur factorization. */
671 /* > If JOB = 'E', the diagonal blocks of H match those of S, but */
672 /* > the rest of H is unspecified. */
675 /* > \param[in] LDH */
677 /* > LDH is INTEGER */
678 /* > The leading dimension of the array H. LDH >= f2cmax( 1, N ). */
681 /* > \param[in,out] T */
683 /* > T is REAL array, dimension (LDT, N) */
684 /* > On entry, the N-by-N upper triangular matrix T. */
685 /* > On exit, if JOB = 'S', T contains the upper triangular */
686 /* > matrix P from the generalized Schur factorization; */
687 /* > 2-by-2 diagonal blocks of P corresponding to 2-by-2 blocks of S */
688 /* > are reduced to positive diagonal form, i.e., if H(j+1,j) is */
689 /* > non-zero, then T(j+1,j) = T(j,j+1) = 0, T(j,j) > 0, and */
690 /* > T(j+1,j+1) > 0. */
691 /* > If JOB = 'E', the diagonal blocks of T match those of P, but */
692 /* > the rest of T is unspecified. */
695 /* > \param[in] LDT */
697 /* > LDT is INTEGER */
698 /* > The leading dimension of the array T. LDT >= f2cmax( 1, N ). */
701 /* > \param[out] ALPHAR */
703 /* > ALPHAR is REAL array, dimension (N) */
704 /* > The real parts of each scalar alpha defining an eigenvalue */
708 /* > \param[out] ALPHAI */
710 /* > ALPHAI is REAL array, dimension (N) */
711 /* > The imaginary parts of each scalar alpha defining an */
712 /* > eigenvalue of GNEP. */
713 /* > If ALPHAI(j) is zero, then the j-th eigenvalue is real; if */
714 /* > positive, then the j-th and (j+1)-st eigenvalues are a */
715 /* > complex conjugate pair, with ALPHAI(j+1) = -ALPHAI(j). */
718 /* > \param[out] BETA */
720 /* > BETA is REAL array, dimension (N) */
721 /* > The scalars beta that define the eigenvalues of GNEP. */
722 /* > Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and */
723 /* > beta = BETA(j) represent the j-th eigenvalue of the matrix */
724 /* > pair (A,B), in one of the forms lambda = alpha/beta or */
725 /* > mu = beta/alpha. Since either lambda or mu may overflow, */
726 /* > they should not, in general, be computed. */
729 /* > \param[in,out] Q */
731 /* > Q is REAL array, dimension (LDQ, N) */
732 /* > On entry, if COMPQ = 'V', the orthogonal matrix Q1 used in */
733 /* > the reduction of (A,B) to generalized Hessenberg form. */
734 /* > On exit, if COMPQ = 'I', the orthogonal matrix of left Schur */
735 /* > vectors of (H,T), and if COMPQ = 'V', the orthogonal matrix */
736 /* > of left Schur vectors of (A,B). */
737 /* > Not referenced if COMPQ = 'N'. */
740 /* > \param[in] LDQ */
742 /* > LDQ is INTEGER */
743 /* > The leading dimension of the array Q. LDQ >= 1. */
744 /* > If COMPQ='V' or 'I', then LDQ >= N. */
747 /* > \param[in,out] Z */
749 /* > Z is REAL array, dimension (LDZ, N) */
750 /* > On entry, if COMPZ = 'V', the orthogonal matrix Z1 used in */
751 /* > the reduction of (A,B) to generalized Hessenberg form. */
752 /* > On exit, if COMPZ = 'I', the orthogonal matrix of */
753 /* > right Schur vectors of (H,T), and if COMPZ = 'V', the */
754 /* > orthogonal matrix of right Schur vectors of (A,B). */
755 /* > Not referenced if COMPZ = 'N'. */
758 /* > \param[in] LDZ */
760 /* > LDZ is INTEGER */
761 /* > The leading dimension of the array Z. LDZ >= 1. */
762 /* > If COMPZ='V' or 'I', then LDZ >= N. */
765 /* > \param[out] WORK */
767 /* > WORK is REAL array, dimension (MAX(1,LWORK)) */
768 /* > On exit, if INFO >= 0, WORK(1) returns the optimal LWORK. */
771 /* > \param[in] LWORK */
773 /* > LWORK is INTEGER */
774 /* > The dimension of the array WORK. LWORK >= f2cmax(1,N). */
776 /* > If LWORK = -1, then a workspace query is assumed; the routine */
777 /* > only calculates the optimal size of the WORK array, returns */
778 /* > this value as the first entry of the WORK array, and no error */
779 /* > message related to LWORK is issued by XERBLA. */
782 /* > \param[out] INFO */
784 /* > INFO is INTEGER */
785 /* > = 0: successful exit */
786 /* > < 0: if INFO = -i, the i-th argument had an illegal value */
787 /* > = 1,...,N: the QZ iteration did not converge. (H,T) is not */
788 /* > in Schur form, but ALPHAR(i), ALPHAI(i), and */
789 /* > BETA(i), i=INFO+1,...,N should be correct. */
790 /* > = N+1,...,2*N: the shift calculation failed. (H,T) is not */
791 /* > in Schur form, but ALPHAR(i), ALPHAI(i), and */
792 /* > BETA(i), i=INFO-N+1,...,N should be correct. */
798 /* > \author Univ. of Tennessee */
799 /* > \author Univ. of California Berkeley */
800 /* > \author Univ. of Colorado Denver */
801 /* > \author NAG Ltd. */
803 /* > \date June 2016 */
805 /* > \ingroup realGEcomputational */
807 /* > \par Further Details: */
808 /* ===================== */
812 /* > Iteration counters: */
814 /* > JITER -- counts iterations. */
815 /* > IITER -- counts iterations run since ILAST was last */
816 /* > changed. This is therefore reset only when a 1-by-1 or */
817 /* > 2-by-2 block deflates off the bottom. */
820 /* ===================================================================== */
821 /* Subroutine */ int shgeqz_(char *job, char *compq, char *compz, integer *n,
822 integer *ilo, integer *ihi, real *h__, integer *ldh, real *t, integer
823 *ldt, real *alphar, real *alphai, real *beta, real *q, integer *ldq,
824 real *z__, integer *ldz, real *work, integer *lwork, integer *info)
826 /* System generated locals */
827 integer h_dim1, h_offset, q_dim1, q_offset, t_dim1, t_offset, z_dim1,
828 z_offset, i__1, i__2, i__3, i__4;
829 real r__1, r__2, r__3, r__4;
831 /* Local variables */
832 real ad11l, ad12l, ad21l, ad22l, ad32l, wabs, atol, btol, temp;
833 extern /* Subroutine */ int srot_(integer *, real *, integer *, real *,
834 integer *, real *, real *), slag2_(real *, integer *, real *,
835 integer *, real *, real *, real *, real *, real *, real *);
836 real temp2, s1inv, c__;
839 extern logical lsame_(char *, char *);
840 integer iiter, ilast, jiter;
843 real tempi, tempr, s1, s2, t1, u1, u2;
845 real a11, a12, a21, a22, b11, b22, c12, c21;
846 extern real slapy2_(real *, real *);
848 extern real slapy3_(real *, real *, real *);
850 extern /* Subroutine */ int slasv2_(real *, real *, real *, real *, real *
851 , real *, real *, real *, real *);
854 real ascale, bscale, u12, w11;
856 real cz, sl, w12, w21, w22, wi, sr;
857 extern real slamch_(char *);
859 extern /* Subroutine */ int slarfg_(integer *, real *, real *, integer *,
862 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
866 integer icompq, ilastm;
867 extern real slanhs_(char *, integer *, real *, integer *, real *);
872 integer icompz, ifirst, ifrstm;
876 real a2r, b1r, b2i, b2r;
877 extern /* Subroutine */ int slartg_(real *, real *, real *, real *, real *
878 ), slaset_(char *, integer *, integer *, real *, real *, real *,
881 real wr2, ad11, ad12, ad21, ad22, c11i, c22i;
887 real ulp, sqr, szi, szr;
890 /* -- LAPACK computational routine (version 3.7.0) -- */
891 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
892 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
896 /* ===================================================================== */
898 /* $ SAFETY = 1.0E+0 ) */
900 /* Decode JOB, COMPQ, COMPZ */
902 /* Parameter adjustments */
904 h_offset = 1 + h_dim1 * 1;
907 t_offset = 1 + t_dim1 * 1;
913 q_offset = 1 + q_dim1 * 1;
916 z_offset = 1 + z_dim1 * 1;
921 if (lsame_(job, "E")) {
924 } else if (lsame_(job, "S")) {
931 if (lsame_(compq, "N")) {
934 } else if (lsame_(compq, "V")) {
937 } else if (lsame_(compq, "I")) {
944 if (lsame_(compz, "N")) {
947 } else if (lsame_(compz, "V")) {
950 } else if (lsame_(compz, "I")) {
957 /* Check Argument Values */
960 work[1] = (real) f2cmax(1,*n);
961 lquery = *lwork == -1;
964 } else if (icompq == 0) {
966 } else if (icompz == 0) {
970 } else if (*ilo < 1) {
972 } else if (*ihi > *n || *ihi < *ilo - 1) {
974 } else if (*ldh < *n) {
976 } else if (*ldt < *n) {
978 } else if (*ldq < 1 || ilq && *ldq < *n) {
980 } else if (*ldz < 1 || ilz && *ldz < *n) {
982 } else if (*lwork < f2cmax(1,*n) && ! lquery) {
987 xerbla_("SHGEQZ", &i__1, (ftnlen)6);
993 /* Quick return if possible */
1000 /* Initialize Q and Z */
1003 slaset_("Full", n, n, &c_b12, &c_b13, &q[q_offset], ldq);
1006 slaset_("Full", n, n, &c_b12, &c_b13, &z__[z_offset], ldz);
1009 /* Machine Constants */
1011 in = *ihi + 1 - *ilo;
1012 safmin = slamch_("S");
1013 safmax = 1.f / safmin;
1014 ulp = slamch_("E") * slamch_("B");
1015 anorm = slanhs_("F", &in, &h__[*ilo + *ilo * h_dim1], ldh, &work[1]);
1016 bnorm = slanhs_("F", &in, &t[*ilo + *ilo * t_dim1], ldt, &work[1]);
1018 r__1 = safmin, r__2 = ulp * anorm;
1019 atol = f2cmax(r__1,r__2);
1021 r__1 = safmin, r__2 = ulp * bnorm;
1022 btol = f2cmax(r__1,r__2);
1023 ascale = 1.f / f2cmax(safmin,anorm);
1024 bscale = 1.f / f2cmax(safmin,bnorm);
1026 /* Set Eigenvalues IHI+1:N */
1029 for (j = *ihi + 1; j <= i__1; ++j) {
1030 if (t[j + j * t_dim1] < 0.f) {
1033 for (jr = 1; jr <= i__2; ++jr) {
1034 h__[jr + j * h_dim1] = -h__[jr + j * h_dim1];
1035 t[jr + j * t_dim1] = -t[jr + j * t_dim1];
1039 h__[j + j * h_dim1] = -h__[j + j * h_dim1];
1040 t[j + j * t_dim1] = -t[j + j * t_dim1];
1044 for (jr = 1; jr <= i__2; ++jr) {
1045 z__[jr + j * z_dim1] = -z__[jr + j * z_dim1];
1050 alphar[j] = h__[j + j * h_dim1];
1052 beta[j] = t[j + j * t_dim1];
1056 /* If IHI < ILO, skip QZ steps */
1062 /* MAIN QZ ITERATION LOOP */
1064 /* Initialize dynamic indices */
1066 /* Eigenvalues ILAST+1:N have been found. */
1067 /* Column operations modify rows IFRSTM:whatever. */
1068 /* Row operations modify columns whatever:ILASTM. */
1070 /* If only eigenvalues are being computed, then */
1071 /* IFRSTM is the row of the last splitting row above row ILAST; */
1072 /* this is always at least ILO. */
1073 /* IITER counts iterations since the last eigenvalue was found, */
1074 /* to tell when to use an extraordinary shift. */
1075 /* MAXIT is the maximum number of QZ sweeps allowed. */
1087 maxit = (*ihi - *ilo + 1) * 30;
1090 for (jiter = 1; jiter <= i__1; ++jiter) {
1092 /* Split the matrix if possible. */
1095 /* 1: H(j,j-1)=0 or j=ILO */
1098 if (ilast == *ilo) {
1100 /* Special case: j=ILAST */
1104 if ((r__1 = h__[ilast + (ilast - 1) * h_dim1], abs(r__1)) <= atol)
1106 h__[ilast + (ilast - 1) * h_dim1] = 0.f;
1111 if ((r__1 = t[ilast + ilast * t_dim1], abs(r__1)) <= btol) {
1112 t[ilast + ilast * t_dim1] = 0.f;
1116 /* General case: j<ILAST */
1119 for (j = ilast - 1; j >= i__2; --j) {
1121 /* Test 1: for H(j,j-1)=0 or j=ILO */
1126 if ((r__1 = h__[j + (j - 1) * h_dim1], abs(r__1)) <= atol) {
1127 h__[j + (j - 1) * h_dim1] = 0.f;
1134 /* Test 2: for T(j,j)=0 */
1136 if ((r__1 = t[j + j * t_dim1], abs(r__1)) < btol) {
1137 t[j + j * t_dim1] = 0.f;
1139 /* Test 1a: Check for 2 consecutive small subdiagonals in A */
1143 temp = (r__1 = h__[j + (j - 1) * h_dim1], abs(r__1));
1144 temp2 = (r__1 = h__[j + j * h_dim1], abs(r__1));
1145 tempr = f2cmax(temp,temp2);
1146 if (tempr < 1.f && tempr != 0.f) {
1150 if (temp * (ascale * (r__1 = h__[j + 1 + j * h_dim1], abs(
1151 r__1))) <= temp2 * (ascale * atol)) {
1156 /* If both tests pass (1 & 2), i.e., the leading diagonal */
1157 /* element of B in the block is zero, split a 1x1 block off */
1158 /* at the top. (I.e., at the J-th row/column) The leading */
1159 /* diagonal element of the remainder can also be zero, so */
1160 /* this may have to be done repeatedly. */
1162 if (ilazro || ilazr2) {
1164 for (jch = j; jch <= i__3; ++jch) {
1165 temp = h__[jch + jch * h_dim1];
1166 slartg_(&temp, &h__[jch + 1 + jch * h_dim1], &c__, &s,
1167 &h__[jch + jch * h_dim1]);
1168 h__[jch + 1 + jch * h_dim1] = 0.f;
1169 i__4 = ilastm - jch;
1170 srot_(&i__4, &h__[jch + (jch + 1) * h_dim1], ldh, &
1171 h__[jch + 1 + (jch + 1) * h_dim1], ldh, &c__,
1173 i__4 = ilastm - jch;
1174 srot_(&i__4, &t[jch + (jch + 1) * t_dim1], ldt, &t[
1175 jch + 1 + (jch + 1) * t_dim1], ldt, &c__, &s);
1177 srot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
1178 * q_dim1 + 1], &c__1, &c__, &s);
1181 h__[jch + (jch - 1) * h_dim1] *= c__;
1184 if ((r__1 = t[jch + 1 + (jch + 1) * t_dim1], abs(r__1)
1186 if (jch + 1 >= ilast) {
1193 t[jch + 1 + (jch + 1) * t_dim1] = 0.f;
1199 /* Only test 2 passed -- chase the zero to T(ILAST,ILAST) */
1200 /* Then process as in the case T(ILAST,ILAST)=0 */
1203 for (jch = j; jch <= i__3; ++jch) {
1204 temp = t[jch + (jch + 1) * t_dim1];
1205 slartg_(&temp, &t[jch + 1 + (jch + 1) * t_dim1], &c__,
1206 &s, &t[jch + (jch + 1) * t_dim1]);
1207 t[jch + 1 + (jch + 1) * t_dim1] = 0.f;
1208 if (jch < ilastm - 1) {
1209 i__4 = ilastm - jch - 1;
1210 srot_(&i__4, &t[jch + (jch + 2) * t_dim1], ldt, &
1211 t[jch + 1 + (jch + 2) * t_dim1], ldt, &
1214 i__4 = ilastm - jch + 2;
1215 srot_(&i__4, &h__[jch + (jch - 1) * h_dim1], ldh, &
1216 h__[jch + 1 + (jch - 1) * h_dim1], ldh, &c__,
1219 srot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
1220 * q_dim1 + 1], &c__1, &c__, &s);
1222 temp = h__[jch + 1 + jch * h_dim1];
1223 slartg_(&temp, &h__[jch + 1 + (jch - 1) * h_dim1], &
1224 c__, &s, &h__[jch + 1 + jch * h_dim1]);
1225 h__[jch + 1 + (jch - 1) * h_dim1] = 0.f;
1226 i__4 = jch + 1 - ifrstm;
1227 srot_(&i__4, &h__[ifrstm + jch * h_dim1], &c__1, &h__[
1228 ifrstm + (jch - 1) * h_dim1], &c__1, &c__, &s)
1230 i__4 = jch - ifrstm;
1231 srot_(&i__4, &t[ifrstm + jch * t_dim1], &c__1, &t[
1232 ifrstm + (jch - 1) * t_dim1], &c__1, &c__, &s)
1235 srot_(n, &z__[jch * z_dim1 + 1], &c__1, &z__[(jch
1236 - 1) * z_dim1 + 1], &c__1, &c__, &s);
1242 } else if (ilazro) {
1244 /* Only test 1 passed -- work on J:ILAST */
1250 /* Neither test passed -- try next J */
1255 /* (Drop-through is "impossible") */
1260 /* T(ILAST,ILAST)=0 -- clear H(ILAST,ILAST-1) to split off a */
1264 temp = h__[ilast + ilast * h_dim1];
1265 slartg_(&temp, &h__[ilast + (ilast - 1) * h_dim1], &c__, &s, &h__[
1266 ilast + ilast * h_dim1]);
1267 h__[ilast + (ilast - 1) * h_dim1] = 0.f;
1268 i__2 = ilast - ifrstm;
1269 srot_(&i__2, &h__[ifrstm + ilast * h_dim1], &c__1, &h__[ifrstm + (
1270 ilast - 1) * h_dim1], &c__1, &c__, &s);
1271 i__2 = ilast - ifrstm;
1272 srot_(&i__2, &t[ifrstm + ilast * t_dim1], &c__1, &t[ifrstm + (ilast -
1273 1) * t_dim1], &c__1, &c__, &s);
1275 srot_(n, &z__[ilast * z_dim1 + 1], &c__1, &z__[(ilast - 1) *
1276 z_dim1 + 1], &c__1, &c__, &s);
1279 /* H(ILAST,ILAST-1)=0 -- Standardize B, set ALPHAR, ALPHAI, */
1283 if (t[ilast + ilast * t_dim1] < 0.f) {
1286 for (j = ifrstm; j <= i__2; ++j) {
1287 h__[j + ilast * h_dim1] = -h__[j + ilast * h_dim1];
1288 t[j + ilast * t_dim1] = -t[j + ilast * t_dim1];
1292 h__[ilast + ilast * h_dim1] = -h__[ilast + ilast * h_dim1];
1293 t[ilast + ilast * t_dim1] = -t[ilast + ilast * t_dim1];
1297 for (j = 1; j <= i__2; ++j) {
1298 z__[j + ilast * z_dim1] = -z__[j + ilast * z_dim1];
1303 alphar[ilast] = h__[ilast + ilast * h_dim1];
1304 alphai[ilast] = 0.f;
1305 beta[ilast] = t[ilast + ilast * t_dim1];
1307 /* Go to next block -- exit if finished. */
1314 /* Reset counters */
1320 if (ifrstm > ilast) {
1328 /* This iteration only involves rows/columns IFIRST:ILAST. We */
1329 /* assume IFIRST < ILAST, and that the diagonal of B is non-zero. */
1337 /* Compute single shifts. */
1339 /* At this point, IFIRST < ILAST, and the diagonal elements of */
1340 /* T(IFIRST:ILAST,IFIRST,ILAST) are larger than BTOL (in */
1343 if (iiter / 10 * 10 == iiter) {
1345 /* Exceptional shift. Chosen for no particularly good reason. */
1346 /* (Single shift only.) */
1348 if ((real) maxit * safmin * (r__1 = h__[ilast + (ilast - 1) *
1349 h_dim1], abs(r__1)) < (r__2 = t[ilast - 1 + (ilast - 1) *
1350 t_dim1], abs(r__2))) {
1351 eshift = h__[ilast + (ilast - 1) * h_dim1] / t[ilast - 1 + (
1352 ilast - 1) * t_dim1];
1354 eshift += 1.f / (safmin * (real) maxit);
1361 /* Shifts based on the generalized eigenvalues of the */
1362 /* bottom-right 2x2 block of A and B. The first eigenvalue */
1363 /* returned by SLAG2 is the Wilkinson shift (AEP p.512), */
1365 r__1 = safmin * 100.f;
1366 slag2_(&h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &t[ilast - 1
1367 + (ilast - 1) * t_dim1], ldt, &r__1, &s1, &s2, &wr, &wr2,
1370 if ((r__1 = wr / s1 * t[ilast + ilast * t_dim1] - h__[ilast +
1371 ilast * h_dim1], abs(r__1)) > (r__2 = wr2 / s2 * t[ilast
1372 + ilast * t_dim1] - h__[ilast + ilast * h_dim1], abs(r__2)
1383 r__3 = 1.f, r__4 = abs(wr), r__3 = f2cmax(r__3,r__4), r__4 = abs(wi);
1384 r__1 = s1, r__2 = safmin * f2cmax(r__3,r__4);
1385 temp = f2cmax(r__1,r__2);
1391 /* Fiddle with shift to avoid overflow */
1393 temp = f2cmin(ascale,1.f) * (safmax * .5f);
1400 temp = f2cmin(bscale,1.f) * (safmax * .5f);
1401 if (abs(wr) > temp) {
1403 r__1 = scale, r__2 = temp / abs(wr);
1404 scale = f2cmin(r__1,r__2);
1409 /* Now check for two consecutive small subdiagonals. */
1412 for (j = ilast - 1; j >= i__2; --j) {
1414 temp = (r__1 = s1 * h__[j + (j - 1) * h_dim1], abs(r__1));
1415 temp2 = (r__1 = s1 * h__[j + j * h_dim1] - wr * t[j + j * t_dim1],
1417 tempr = f2cmax(temp,temp2);
1418 if (tempr < 1.f && tempr != 0.f) {
1422 if ((r__1 = ascale * h__[j + 1 + j * h_dim1] * temp, abs(r__1)) <=
1423 ascale * atol * temp2) {
1432 /* Do an implicit single-shift QZ sweep. */
1436 temp = s1 * h__[istart + istart * h_dim1] - wr * t[istart + istart *
1438 temp2 = s1 * h__[istart + 1 + istart * h_dim1];
1439 slartg_(&temp, &temp2, &c__, &s, &tempr);
1444 for (j = istart; j <= i__2; ++j) {
1446 temp = h__[j + (j - 1) * h_dim1];
1447 slartg_(&temp, &h__[j + 1 + (j - 1) * h_dim1], &c__, &s, &h__[
1448 j + (j - 1) * h_dim1]);
1449 h__[j + 1 + (j - 1) * h_dim1] = 0.f;
1453 for (jc = j; jc <= i__3; ++jc) {
1454 temp = c__ * h__[j + jc * h_dim1] + s * h__[j + 1 + jc *
1456 h__[j + 1 + jc * h_dim1] = -s * h__[j + jc * h_dim1] + c__ *
1457 h__[j + 1 + jc * h_dim1];
1458 h__[j + jc * h_dim1] = temp;
1459 temp2 = c__ * t[j + jc * t_dim1] + s * t[j + 1 + jc * t_dim1];
1460 t[j + 1 + jc * t_dim1] = -s * t[j + jc * t_dim1] + c__ * t[j
1462 t[j + jc * t_dim1] = temp2;
1467 for (jr = 1; jr <= i__3; ++jr) {
1468 temp = c__ * q[jr + j * q_dim1] + s * q[jr + (j + 1) *
1470 q[jr + (j + 1) * q_dim1] = -s * q[jr + j * q_dim1] + c__ *
1471 q[jr + (j + 1) * q_dim1];
1472 q[jr + j * q_dim1] = temp;
1477 temp = t[j + 1 + (j + 1) * t_dim1];
1478 slartg_(&temp, &t[j + 1 + j * t_dim1], &c__, &s, &t[j + 1 + (j +
1480 t[j + 1 + j * t_dim1] = 0.f;
1484 i__3 = f2cmin(i__4,ilast);
1485 for (jr = ifrstm; jr <= i__3; ++jr) {
1486 temp = c__ * h__[jr + (j + 1) * h_dim1] + s * h__[jr + j *
1488 h__[jr + j * h_dim1] = -s * h__[jr + (j + 1) * h_dim1] + c__ *
1489 h__[jr + j * h_dim1];
1490 h__[jr + (j + 1) * h_dim1] = temp;
1494 for (jr = ifrstm; jr <= i__3; ++jr) {
1495 temp = c__ * t[jr + (j + 1) * t_dim1] + s * t[jr + j * t_dim1]
1497 t[jr + j * t_dim1] = -s * t[jr + (j + 1) * t_dim1] + c__ * t[
1499 t[jr + (j + 1) * t_dim1] = temp;
1504 for (jr = 1; jr <= i__3; ++jr) {
1505 temp = c__ * z__[jr + (j + 1) * z_dim1] + s * z__[jr + j *
1507 z__[jr + j * z_dim1] = -s * z__[jr + (j + 1) * z_dim1] +
1508 c__ * z__[jr + j * z_dim1];
1509 z__[jr + (j + 1) * z_dim1] = temp;
1518 /* Use Francis double-shift */
1520 /* Note: the Francis double-shift should work with real shifts, */
1521 /* but only if the block is at least 3x3. */
1522 /* This code may break if this point is reached with */
1523 /* a 2x2 block with real eigenvalues. */
1526 if (ifirst + 1 == ilast) {
1528 /* Special case -- 2x2 block with complex eigenvectors */
1530 /* Step 1: Standardize, that is, rotate so that */
1533 /* B = ( ) with B11 non-negative. */
1536 slasv2_(&t[ilast - 1 + (ilast - 1) * t_dim1], &t[ilast - 1 +
1537 ilast * t_dim1], &t[ilast + ilast * t_dim1], &b22, &b11, &
1547 i__2 = ilastm + 1 - ifirst;
1548 srot_(&i__2, &h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &h__[
1549 ilast + (ilast - 1) * h_dim1], ldh, &cl, &sl);
1550 i__2 = ilast + 1 - ifrstm;
1551 srot_(&i__2, &h__[ifrstm + (ilast - 1) * h_dim1], &c__1, &h__[
1552 ifrstm + ilast * h_dim1], &c__1, &cr, &sr);
1554 if (ilast < ilastm) {
1555 i__2 = ilastm - ilast;
1556 srot_(&i__2, &t[ilast - 1 + (ilast + 1) * t_dim1], ldt, &t[
1557 ilast + (ilast + 1) * t_dim1], ldt, &cl, &sl);
1559 if (ifrstm < ilast - 1) {
1560 i__2 = ifirst - ifrstm;
1561 srot_(&i__2, &t[ifrstm + (ilast - 1) * t_dim1], &c__1, &t[
1562 ifrstm + ilast * t_dim1], &c__1, &cr, &sr);
1566 srot_(n, &q[(ilast - 1) * q_dim1 + 1], &c__1, &q[ilast *
1567 q_dim1 + 1], &c__1, &cl, &sl);
1570 srot_(n, &z__[(ilast - 1) * z_dim1 + 1], &c__1, &z__[ilast *
1571 z_dim1 + 1], &c__1, &cr, &sr);
1574 t[ilast - 1 + (ilast - 1) * t_dim1] = b11;
1575 t[ilast - 1 + ilast * t_dim1] = 0.f;
1576 t[ilast + (ilast - 1) * t_dim1] = 0.f;
1577 t[ilast + ilast * t_dim1] = b22;
1579 /* If B22 is negative, negate column ILAST */
1583 for (j = ifrstm; j <= i__2; ++j) {
1584 h__[j + ilast * h_dim1] = -h__[j + ilast * h_dim1];
1585 t[j + ilast * t_dim1] = -t[j + ilast * t_dim1];
1591 for (j = 1; j <= i__2; ++j) {
1592 z__[j + ilast * z_dim1] = -z__[j + ilast * z_dim1];
1599 /* Step 2: Compute ALPHAR, ALPHAI, and BETA (see refs.) */
1601 /* Recompute shift */
1603 r__1 = safmin * 100.f;
1604 slag2_(&h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &t[ilast - 1
1605 + (ilast - 1) * t_dim1], ldt, &r__1, &s1, &temp, &wr, &
1608 /* If standardization has perturbed the shift onto real line, */
1609 /* do another (real single-shift) QR step. */
1616 /* Do EISPACK (QZVAL) computation of alpha and beta */
1618 a11 = h__[ilast - 1 + (ilast - 1) * h_dim1];
1619 a21 = h__[ilast + (ilast - 1) * h_dim1];
1620 a12 = h__[ilast - 1 + ilast * h_dim1];
1621 a22 = h__[ilast + ilast * h_dim1];
1623 /* Compute complex Givens rotation on right */
1624 /* (Assume some element of C = (sA - wB) > unfl ) */
1626 /* (sA - wB) ( CZ -SZ ) */
1629 c11r = s1 * a11 - wr * b11;
1633 c22r = s1 * a22 - wr * b22;
1636 if (abs(c11r) + abs(c11i) + abs(c12) > abs(c21) + abs(c22r) + abs(
1638 t1 = slapy3_(&c12, &c11r, &c11i);
1643 cz = slapy2_(&c22r, &c22i);
1651 t1 = slapy2_(&cz, &c21);
1653 szr = -c21 * tempr / t1;
1654 szi = c21 * tempi / t1;
1658 /* Compute Givens rotation on left */
1664 an = abs(a11) + abs(a12) + abs(a21) + abs(a22);
1665 bn = abs(b11) + abs(b22);
1666 wabs = abs(wr) + abs(wi);
1667 if (s1 * an > wabs * bn) {
1672 a1r = cz * a11 + szr * a12;
1674 a2r = cz * a21 + szr * a22;
1676 cq = slapy2_(&a1r, &a1i);
1684 sqr = tempr * a2r + tempi * a2i;
1685 sqi = tempi * a2r - tempr * a2i;
1688 t1 = slapy3_(&cq, &sqr, &sqi);
1693 /* Compute diagonal elements of QBZ */
1695 tempr = sqr * szr - sqi * szi;
1696 tempi = sqr * szi + sqi * szr;
1697 b1r = cq * cz * b11 + tempr * b22;
1699 b1a = slapy2_(&b1r, &b1i);
1700 b2r = cq * cz * b22 + tempr * b11;
1702 b2a = slapy2_(&b2r, &b2i);
1704 /* Normalize so beta > 0, and Im( alpha1 ) > 0 */
1706 beta[ilast - 1] = b1a;
1708 alphar[ilast - 1] = wr * b1a * s1inv;
1709 alphai[ilast - 1] = wi * b1a * s1inv;
1710 alphar[ilast] = wr * b2a * s1inv;
1711 alphai[ilast] = -(wi * b2a) * s1inv;
1713 /* Step 3: Go to next block -- exit if finished. */
1720 /* Reset counters */
1726 if (ifrstm > ilast) {
1733 /* Usual case: 3x3 or larger block, using Francis implicit */
1737 /* Eigenvalue equation is w - c w + d = 0, */
1740 /* so compute 1st column of (A B ) - c A B + d */
1741 /* using the formula in QZIT (from EISPACK) */
1743 /* We assume that the block is at least 3x3 */
1745 ad11 = ascale * h__[ilast - 1 + (ilast - 1) * h_dim1] / (bscale *
1746 t[ilast - 1 + (ilast - 1) * t_dim1]);
1747 ad21 = ascale * h__[ilast + (ilast - 1) * h_dim1] / (bscale * t[
1748 ilast - 1 + (ilast - 1) * t_dim1]);
1749 ad12 = ascale * h__[ilast - 1 + ilast * h_dim1] / (bscale * t[
1750 ilast + ilast * t_dim1]);
1751 ad22 = ascale * h__[ilast + ilast * h_dim1] / (bscale * t[ilast +
1753 u12 = t[ilast - 1 + ilast * t_dim1] / t[ilast + ilast * t_dim1];
1754 ad11l = ascale * h__[ifirst + ifirst * h_dim1] / (bscale * t[
1755 ifirst + ifirst * t_dim1]);
1756 ad21l = ascale * h__[ifirst + 1 + ifirst * h_dim1] / (bscale * t[
1757 ifirst + ifirst * t_dim1]);
1758 ad12l = ascale * h__[ifirst + (ifirst + 1) * h_dim1] / (bscale *
1759 t[ifirst + 1 + (ifirst + 1) * t_dim1]);
1760 ad22l = ascale * h__[ifirst + 1 + (ifirst + 1) * h_dim1] / (
1761 bscale * t[ifirst + 1 + (ifirst + 1) * t_dim1]);
1762 ad32l = ascale * h__[ifirst + 2 + (ifirst + 1) * h_dim1] / (
1763 bscale * t[ifirst + 1 + (ifirst + 1) * t_dim1]);
1764 u12l = t[ifirst + (ifirst + 1) * t_dim1] / t[ifirst + 1 + (ifirst
1767 v[0] = (ad11 - ad11l) * (ad22 - ad11l) - ad12 * ad21 + ad21 * u12
1768 * ad11l + (ad12l - ad11l * u12l) * ad21l;
1769 v[1] = (ad22l - ad11l - ad21l * u12l - (ad11 - ad11l) - (ad22 -
1770 ad11l) + ad21 * u12) * ad21l;
1771 v[2] = ad32l * ad21l;
1775 slarfg_(&c__3, v, &v[1], &c__1, &tau);
1781 for (j = istart; j <= i__2; ++j) {
1783 /* All but last elements: use 3x3 Householder transforms. */
1785 /* Zero (j-1)st column of A */
1788 v[0] = h__[j + (j - 1) * h_dim1];
1789 v[1] = h__[j + 1 + (j - 1) * h_dim1];
1790 v[2] = h__[j + 2 + (j - 1) * h_dim1];
1792 slarfg_(&c__3, &h__[j + (j - 1) * h_dim1], &v[1], &c__1, &
1795 h__[j + 1 + (j - 1) * h_dim1] = 0.f;
1796 h__[j + 2 + (j - 1) * h_dim1] = 0.f;
1800 for (jc = j; jc <= i__3; ++jc) {
1801 temp = tau * (h__[j + jc * h_dim1] + v[1] * h__[j + 1 +
1802 jc * h_dim1] + v[2] * h__[j + 2 + jc * h_dim1]);
1803 h__[j + jc * h_dim1] -= temp;
1804 h__[j + 1 + jc * h_dim1] -= temp * v[1];
1805 h__[j + 2 + jc * h_dim1] -= temp * v[2];
1806 temp2 = tau * (t[j + jc * t_dim1] + v[1] * t[j + 1 + jc *
1807 t_dim1] + v[2] * t[j + 2 + jc * t_dim1]);
1808 t[j + jc * t_dim1] -= temp2;
1809 t[j + 1 + jc * t_dim1] -= temp2 * v[1];
1810 t[j + 2 + jc * t_dim1] -= temp2 * v[2];
1815 for (jr = 1; jr <= i__3; ++jr) {
1816 temp = tau * (q[jr + j * q_dim1] + v[1] * q[jr + (j +
1817 1) * q_dim1] + v[2] * q[jr + (j + 2) * q_dim1]
1819 q[jr + j * q_dim1] -= temp;
1820 q[jr + (j + 1) * q_dim1] -= temp * v[1];
1821 q[jr + (j + 2) * q_dim1] -= temp * v[2];
1826 /* Zero j-th column of B (see SLAGBC for details) */
1828 /* Swap rows to pivot */
1832 r__3 = (r__1 = t[j + 1 + (j + 1) * t_dim1], abs(r__1)), r__4 =
1833 (r__2 = t[j + 1 + (j + 2) * t_dim1], abs(r__2));
1834 temp = f2cmax(r__3,r__4);
1836 r__3 = (r__1 = t[j + 2 + (j + 1) * t_dim1], abs(r__1)), r__4 =
1837 (r__2 = t[j + 2 + (j + 2) * t_dim1], abs(r__2));
1838 temp2 = f2cmax(r__3,r__4);
1839 if (f2cmax(temp,temp2) < safmin) {
1844 } else if (temp >= temp2) {
1845 w11 = t[j + 1 + (j + 1) * t_dim1];
1846 w21 = t[j + 2 + (j + 1) * t_dim1];
1847 w12 = t[j + 1 + (j + 2) * t_dim1];
1848 w22 = t[j + 2 + (j + 2) * t_dim1];
1849 u1 = t[j + 1 + j * t_dim1];
1850 u2 = t[j + 2 + j * t_dim1];
1852 w21 = t[j + 1 + (j + 1) * t_dim1];
1853 w11 = t[j + 2 + (j + 1) * t_dim1];
1854 w22 = t[j + 1 + (j + 2) * t_dim1];
1855 w12 = t[j + 2 + (j + 2) * t_dim1];
1856 u2 = t[j + 1 + j * t_dim1];
1857 u1 = t[j + 2 + j * t_dim1];
1860 /* Swap columns if nec. */
1862 if (abs(w12) > abs(w11)) {
1882 if (abs(w22) < safmin) {
1888 if (abs(w22) < abs(u2)) {
1889 scale = (r__1 = w22 / u2, abs(r__1));
1891 if (abs(w11) < abs(u1)) {
1893 r__2 = scale, r__3 = (r__1 = w11 / u1, abs(r__1));
1894 scale = f2cmin(r__2,r__3);
1899 u2 = scale * u2 / w22;
1900 u1 = (scale * u1 - w12 * u2) / w11;
1909 /* Compute Householder Vector */
1911 /* Computing 2nd power */
1913 /* Computing 2nd power */
1915 /* Computing 2nd power */
1917 t1 = sqrt(r__1 * r__1 + r__2 * r__2 + r__3 * r__3);
1918 tau = scale / t1 + 1.f;
1919 vs = -1.f / (scale + t1);
1924 /* Apply transformations from the right. */
1928 i__3 = f2cmin(i__4,ilast);
1929 for (jr = ifrstm; jr <= i__3; ++jr) {
1930 temp = tau * (h__[jr + j * h_dim1] + v[1] * h__[jr + (j +
1931 1) * h_dim1] + v[2] * h__[jr + (j + 2) * h_dim1]);
1932 h__[jr + j * h_dim1] -= temp;
1933 h__[jr + (j + 1) * h_dim1] -= temp * v[1];
1934 h__[jr + (j + 2) * h_dim1] -= temp * v[2];
1938 for (jr = ifrstm; jr <= i__3; ++jr) {
1939 temp = tau * (t[jr + j * t_dim1] + v[1] * t[jr + (j + 1) *
1940 t_dim1] + v[2] * t[jr + (j + 2) * t_dim1]);
1941 t[jr + j * t_dim1] -= temp;
1942 t[jr + (j + 1) * t_dim1] -= temp * v[1];
1943 t[jr + (j + 2) * t_dim1] -= temp * v[2];
1948 for (jr = 1; jr <= i__3; ++jr) {
1949 temp = tau * (z__[jr + j * z_dim1] + v[1] * z__[jr + (
1950 j + 1) * z_dim1] + v[2] * z__[jr + (j + 2) *
1952 z__[jr + j * z_dim1] -= temp;
1953 z__[jr + (j + 1) * z_dim1] -= temp * v[1];
1954 z__[jr + (j + 2) * z_dim1] -= temp * v[2];
1958 t[j + 1 + j * t_dim1] = 0.f;
1959 t[j + 2 + j * t_dim1] = 0.f;
1963 /* Last elements: Use Givens rotations */
1965 /* Rotations from the left */
1968 temp = h__[j + (j - 1) * h_dim1];
1969 slartg_(&temp, &h__[j + 1 + (j - 1) * h_dim1], &c__, &s, &h__[j +
1971 h__[j + 1 + (j - 1) * h_dim1] = 0.f;
1974 for (jc = j; jc <= i__2; ++jc) {
1975 temp = c__ * h__[j + jc * h_dim1] + s * h__[j + 1 + jc *
1977 h__[j + 1 + jc * h_dim1] = -s * h__[j + jc * h_dim1] + c__ *
1978 h__[j + 1 + jc * h_dim1];
1979 h__[j + jc * h_dim1] = temp;
1980 temp2 = c__ * t[j + jc * t_dim1] + s * t[j + 1 + jc * t_dim1];
1981 t[j + 1 + jc * t_dim1] = -s * t[j + jc * t_dim1] + c__ * t[j
1983 t[j + jc * t_dim1] = temp2;
1988 for (jr = 1; jr <= i__2; ++jr) {
1989 temp = c__ * q[jr + j * q_dim1] + s * q[jr + (j + 1) *
1991 q[jr + (j + 1) * q_dim1] = -s * q[jr + j * q_dim1] + c__ *
1992 q[jr + (j + 1) * q_dim1];
1993 q[jr + j * q_dim1] = temp;
1998 /* Rotations from the right. */
2000 temp = t[j + 1 + (j + 1) * t_dim1];
2001 slartg_(&temp, &t[j + 1 + j * t_dim1], &c__, &s, &t[j + 1 + (j +
2003 t[j + 1 + j * t_dim1] = 0.f;
2006 for (jr = ifrstm; jr <= i__2; ++jr) {
2007 temp = c__ * h__[jr + (j + 1) * h_dim1] + s * h__[jr + j *
2009 h__[jr + j * h_dim1] = -s * h__[jr + (j + 1) * h_dim1] + c__ *
2010 h__[jr + j * h_dim1];
2011 h__[jr + (j + 1) * h_dim1] = temp;
2015 for (jr = ifrstm; jr <= i__2; ++jr) {
2016 temp = c__ * t[jr + (j + 1) * t_dim1] + s * t[jr + j * t_dim1]
2018 t[jr + j * t_dim1] = -s * t[jr + (j + 1) * t_dim1] + c__ * t[
2020 t[jr + (j + 1) * t_dim1] = temp;
2025 for (jr = 1; jr <= i__2; ++jr) {
2026 temp = c__ * z__[jr + (j + 1) * z_dim1] + s * z__[jr + j *
2028 z__[jr + j * z_dim1] = -s * z__[jr + (j + 1) * z_dim1] +
2029 c__ * z__[jr + j * z_dim1];
2030 z__[jr + (j + 1) * z_dim1] = temp;
2035 /* End of Double-Shift code */
2041 /* End of iteration loop */
2048 /* Drop-through = non-convergence */
2053 /* Successful completion of all QZ steps */
2057 /* Set Eigenvalues 1:ILO-1 */
2060 for (j = 1; j <= i__1; ++j) {
2061 if (t[j + j * t_dim1] < 0.f) {
2064 for (jr = 1; jr <= i__2; ++jr) {
2065 h__[jr + j * h_dim1] = -h__[jr + j * h_dim1];
2066 t[jr + j * t_dim1] = -t[jr + j * t_dim1];
2070 h__[j + j * h_dim1] = -h__[j + j * h_dim1];
2071 t[j + j * t_dim1] = -t[j + j * t_dim1];
2075 for (jr = 1; jr <= i__2; ++jr) {
2076 z__[jr + j * z_dim1] = -z__[jr + j * z_dim1];
2081 alphar[j] = h__[j + j * h_dim1];
2083 beta[j] = t[j + j * t_dim1];
2087 /* Normal Termination */
2091 /* Exit (other than argument error) -- return optimal workspace size */
2094 work[1] = (real) (*n);