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)
513 /* Table of constant values */
515 static integer c__1 = 1;
516 static integer c__2 = 2;
518 /* > \brief \b ZLAHQR computes the eigenvalues and Schur factorization of an upper Hessenberg matrix, using th
519 e double-shift/single-shift QR algorithm. */
521 /* =========== DOCUMENTATION =========== */
523 /* Online html documentation available at */
524 /* http://www.netlib.org/lapack/explore-html/ */
527 /* > Download ZLAHQR + dependencies */
528 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlahqr.
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlahqr.
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlahqr.
542 /* SUBROUTINE ZLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ, */
543 /* IHIZ, Z, LDZ, INFO ) */
545 /* INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, N */
546 /* LOGICAL WANTT, WANTZ */
547 /* COMPLEX*16 H( LDH, * ), W( * ), Z( LDZ, * ) */
550 /* > \par Purpose: */
555 /* > ZLAHQR is an auxiliary routine called by CHSEQR to update the */
556 /* > eigenvalues and Schur decomposition already computed by CHSEQR, by */
557 /* > dealing with the Hessenberg submatrix in rows and columns ILO to */
564 /* > \param[in] WANTT */
566 /* > WANTT is LOGICAL */
567 /* > = .TRUE. : the full Schur form T is required; */
568 /* > = .FALSE.: only eigenvalues are required. */
571 /* > \param[in] WANTZ */
573 /* > WANTZ is LOGICAL */
574 /* > = .TRUE. : the matrix of Schur vectors Z is required; */
575 /* > = .FALSE.: Schur vectors are not required. */
581 /* > The order of the matrix H. N >= 0. */
584 /* > \param[in] ILO */
586 /* > ILO is INTEGER */
589 /* > \param[in] IHI */
591 /* > IHI is INTEGER */
592 /* > It is assumed that H is already upper triangular in rows and */
593 /* > columns IHI+1:N, and that H(ILO,ILO-1) = 0 (unless ILO = 1). */
594 /* > ZLAHQR works primarily with the Hessenberg submatrix in rows */
595 /* > and columns ILO to IHI, but applies transformations to all of */
596 /* > H if WANTT is .TRUE.. */
597 /* > 1 <= ILO <= f2cmax(1,IHI); IHI <= N. */
600 /* > \param[in,out] H */
602 /* > H is COMPLEX*16 array, dimension (LDH,N) */
603 /* > On entry, the upper Hessenberg matrix H. */
604 /* > On exit, if INFO is zero and if WANTT is .TRUE., then H */
605 /* > is upper triangular in rows and columns ILO:IHI. If INFO */
606 /* > is zero and if WANTT is .FALSE., then the contents of H */
607 /* > are unspecified on exit. The output state of H in case */
608 /* > INF is positive is below under the description of INFO. */
611 /* > \param[in] LDH */
613 /* > LDH is INTEGER */
614 /* > The leading dimension of the array H. LDH >= f2cmax(1,N). */
617 /* > \param[out] W */
619 /* > W is COMPLEX*16 array, dimension (N) */
620 /* > The computed eigenvalues ILO to IHI are stored in the */
621 /* > corresponding elements of W. If WANTT is .TRUE., the */
622 /* > eigenvalues are stored in the same order as on the diagonal */
623 /* > of the Schur form returned in H, with W(i) = H(i,i). */
626 /* > \param[in] ILOZ */
628 /* > ILOZ is INTEGER */
631 /* > \param[in] IHIZ */
633 /* > IHIZ is INTEGER */
634 /* > Specify the rows of Z to which transformations must be */
635 /* > applied if WANTZ is .TRUE.. */
636 /* > 1 <= ILOZ <= ILO; IHI <= IHIZ <= N. */
639 /* > \param[in,out] Z */
641 /* > Z is COMPLEX*16 array, dimension (LDZ,N) */
642 /* > If WANTZ is .TRUE., on entry Z must contain the current */
643 /* > matrix Z of transformations accumulated by CHSEQR, and on */
644 /* > exit Z has been updated; transformations are applied only to */
645 /* > the submatrix Z(ILOZ:IHIZ,ILO:IHI). */
646 /* > If WANTZ is .FALSE., Z is not referenced. */
649 /* > \param[in] LDZ */
651 /* > LDZ is INTEGER */
652 /* > The leading dimension of the array Z. LDZ >= f2cmax(1,N). */
655 /* > \param[out] INFO */
657 /* > INFO is INTEGER */
658 /* > = 0: successful exit */
659 /* > > 0: if INFO = i, ZLAHQR failed to compute all the */
660 /* > eigenvalues ILO to IHI in a total of 30 iterations */
661 /* > per eigenvalue; elements i+1:ihi of W contain */
662 /* > those eigenvalues which have been successfully */
665 /* > If INFO > 0 and WANTT is .FALSE., then on exit, */
666 /* > the remaining unconverged eigenvalues are the */
667 /* > eigenvalues of the upper Hessenberg matrix */
668 /* > rows and columns ILO through INFO of the final, */
669 /* > output value of H. */
671 /* > If INFO > 0 and WANTT is .TRUE., then on exit */
672 /* > (*) (initial value of H)*U = U*(final value of H) */
673 /* > where U is an orthogonal matrix. The final */
674 /* > value of H is upper Hessenberg and triangular in */
675 /* > rows and columns INFO+1 through IHI. */
677 /* > If INFO > 0 and WANTZ is .TRUE., then on exit */
678 /* > (final value of Z) = (initial value of Z)*U */
679 /* > where U is the orthogonal matrix in (*) */
680 /* > (regardless of the value of WANTT.) */
686 /* > \author Univ. of Tennessee */
687 /* > \author Univ. of California Berkeley */
688 /* > \author Univ. of Colorado Denver */
689 /* > \author NAG Ltd. */
691 /* > \date December 2016 */
693 /* > \ingroup complex16OTHERauxiliary */
695 /* > \par Contributors: */
696 /* ================== */
700 /* > 02-96 Based on modifications by */
701 /* > David Day, Sandia National Laboratory, USA */
703 /* > 12-04 Further modifications by */
704 /* > Ralph Byers, University of Kansas, USA */
705 /* > This is a modified version of ZLAHQR from LAPACK version 3.0. */
706 /* > It is (1) more robust against overflow and underflow and */
707 /* > (2) adopts the more conservative Ahues & Tisseur stopping */
708 /* > criterion (LAWN 122, 1997). */
711 /* ===================================================================== */
712 /* Subroutine */ int zlahqr_(logical *wantt, logical *wantz, integer *n,
713 integer *ilo, integer *ihi, doublecomplex *h__, integer *ldh,
714 doublecomplex *w, integer *iloz, integer *ihiz, doublecomplex *z__,
715 integer *ldz, integer *info)
717 /* System generated locals */
718 integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
719 doublereal d__1, d__2, d__3, d__4, d__5, d__6;
720 doublecomplex z__1, z__2, z__3, z__4, z__5, z__6, z__7;
722 /* Local variables */
724 integer i__, j, k, l, m;
726 doublecomplex t, u, v[2], x, y;
727 extern /* Subroutine */ int zscal_(integer *, doublecomplex *,
728 doublecomplex *, integer *);
732 extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *,
733 doublecomplex *, integer *);
737 doublereal aa, ab, ba, bb;
738 extern /* Subroutine */ int dlabad_(doublereal *, doublereal *);
742 doublecomplex h22, sc;
744 extern doublereal dlamch_(char *);
746 doublereal sx, safmin, safmax;
747 extern /* Subroutine */ int zlarfg_(integer *, doublecomplex *,
748 doublecomplex *, integer *, doublecomplex *);
749 extern /* Double Complex */ VOID zladiv_(doublecomplex *, doublecomplex *,
760 /* -- LAPACK auxiliary routine (version 3.7.0) -- */
761 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
762 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
766 /* ========================================================= */
769 /* Parameter adjustments */
771 h_offset = 1 + h_dim1 * 1;
775 z_offset = 1 + z_dim1 * 1;
781 /* Quick return if possible */
788 i__2 = *ilo + *ilo * h_dim1;
789 w[i__1].r = h__[i__2].r, w[i__1].i = h__[i__2].i;
793 /* ==== clear out the trash ==== */
795 for (j = *ilo; j <= i__1; ++j) {
796 i__2 = j + 2 + j * h_dim1;
797 h__[i__2].r = 0., h__[i__2].i = 0.;
798 i__2 = j + 3 + j * h_dim1;
799 h__[i__2].r = 0., h__[i__2].i = 0.;
802 if (*ilo <= *ihi - 2) {
803 i__1 = *ihi + (*ihi - 2) * h_dim1;
804 h__[i__1].r = 0., h__[i__1].i = 0.;
806 /* ==== ensure that subdiagonal entries are real ==== */
815 for (i__ = *ilo + 1; i__ <= i__1; ++i__) {
816 if (d_imag(&h__[i__ + (i__ - 1) * h_dim1]) != 0.) {
817 /* ==== The following redundant normalization */
818 /* . avoids problems with both gradual and */
819 /* . sudden underflow in ABS(H(I,I-1)) ==== */
820 i__2 = i__ + (i__ - 1) * h_dim1;
821 i__3 = i__ + (i__ - 1) * h_dim1;
822 d__3 = (d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&h__[i__
823 + (i__ - 1) * h_dim1]), abs(d__2));
824 z__1.r = h__[i__2].r / d__3, z__1.i = h__[i__2].i / d__3;
825 sc.r = z__1.r, sc.i = z__1.i;
828 z__1.r = z__2.r / d__1, z__1.i = z__2.i / d__1;
829 sc.r = z__1.r, sc.i = z__1.i;
830 i__2 = i__ + (i__ - 1) * h_dim1;
831 d__1 = z_abs(&h__[i__ + (i__ - 1) * h_dim1]);
832 h__[i__2].r = d__1, h__[i__2].i = 0.;
833 i__2 = jhi - i__ + 1;
834 zscal_(&i__2, &sc, &h__[i__ + i__ * h_dim1], ldh);
836 i__3 = jhi, i__4 = i__ + 1;
837 i__2 = f2cmin(i__3,i__4) - jlo + 1;
839 zscal_(&i__2, &z__1, &h__[jlo + i__ * h_dim1], &c__1);
841 i__2 = *ihiz - *iloz + 1;
843 zscal_(&i__2, &z__1, &z__[*iloz + i__ * z_dim1], &c__1);
849 nh = *ihi - *ilo + 1;
850 nz = *ihiz - *iloz + 1;
852 /* Set machine-dependent constants for the stopping criterion. */
854 safmin = dlamch_("SAFE MINIMUM");
855 safmax = 1. / safmin;
856 dlabad_(&safmin, &safmax);
857 ulp = dlamch_("PRECISION");
858 smlnum = safmin * ((doublereal) nh / ulp);
860 /* I1 and I2 are the indices of the first row and last column of H */
861 /* to which transformations must be applied. If eigenvalues only are */
862 /* being computed, I1 and I2 are set inside the main loop. */
869 /* ITMAX is the total number of QR iterations allowed. */
871 itmax = f2cmax(10,nh) * 30;
873 /* The main loop begins here. I is the loop index and decreases from */
874 /* IHI to ILO in steps of 1. Each iteration of the loop works */
875 /* with the active submatrix in rows and columns L to I. */
876 /* Eigenvalues I+1 to IHI have already converged. Either L = ILO, or */
877 /* H(L,L-1) is negligible so that the matrix splits. */
885 /* Perform QR iterations on rows and columns ILO to I until a */
886 /* submatrix of order 1 splits off at the bottom because a */
887 /* subdiagonal element has become negligible. */
891 for (its = 0; its <= i__1; ++its) {
893 /* Look for a single small subdiagonal element. */
896 for (k = i__; k >= i__2; --k) {
897 i__3 = k + (k - 1) * h_dim1;
898 if ((d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&h__[k + (k
899 - 1) * h_dim1]), abs(d__2)) <= smlnum) {
902 i__3 = k - 1 + (k - 1) * h_dim1;
903 i__4 = k + k * h_dim1;
904 tst = (d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&h__[k - 1
905 + (k - 1) * h_dim1]), abs(d__2)) + ((d__3 = h__[i__4].r,
906 abs(d__3)) + (d__4 = d_imag(&h__[k + k * h_dim1]), abs(
910 i__3 = k - 1 + (k - 2) * h_dim1;
911 tst += (d__1 = h__[i__3].r, abs(d__1));
914 i__3 = k + 1 + k * h_dim1;
915 tst += (d__1 = h__[i__3].r, abs(d__1));
918 /* ==== The following is a conservative small subdiagonal */
919 /* . deflation criterion due to Ahues & Tisseur (LAWN 122, */
920 /* . 1997). It has better mathematical foundation and */
921 /* . improves accuracy in some examples. ==== */
922 i__3 = k + (k - 1) * h_dim1;
923 if ((d__1 = h__[i__3].r, abs(d__1)) <= ulp * tst) {
925 i__3 = k + (k - 1) * h_dim1;
926 i__4 = k - 1 + k * h_dim1;
927 d__5 = (d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&h__[
928 k + (k - 1) * h_dim1]), abs(d__2)), d__6 = (d__3 =
929 h__[i__4].r, abs(d__3)) + (d__4 = d_imag(&h__[k - 1 +
930 k * h_dim1]), abs(d__4));
931 ab = f2cmax(d__5,d__6);
933 i__3 = k + (k - 1) * h_dim1;
934 i__4 = k - 1 + k * h_dim1;
935 d__5 = (d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&h__[
936 k + (k - 1) * h_dim1]), abs(d__2)), d__6 = (d__3 =
937 h__[i__4].r, abs(d__3)) + (d__4 = d_imag(&h__[k - 1 +
938 k * h_dim1]), abs(d__4));
939 ba = f2cmin(d__5,d__6);
940 i__3 = k - 1 + (k - 1) * h_dim1;
941 i__4 = k + k * h_dim1;
942 z__2.r = h__[i__3].r - h__[i__4].r, z__2.i = h__[i__3].i -
944 z__1.r = z__2.r, z__1.i = z__2.i;
946 i__5 = k + k * h_dim1;
947 d__5 = (d__1 = h__[i__5].r, abs(d__1)) + (d__2 = d_imag(&h__[
948 k + k * h_dim1]), abs(d__2)), d__6 = (d__3 = z__1.r,
949 abs(d__3)) + (d__4 = d_imag(&z__1), abs(d__4));
950 aa = f2cmax(d__5,d__6);
951 i__3 = k - 1 + (k - 1) * h_dim1;
952 i__4 = k + k * h_dim1;
953 z__2.r = h__[i__3].r - h__[i__4].r, z__2.i = h__[i__3].i -
955 z__1.r = z__2.r, z__1.i = z__2.i;
957 i__5 = k + k * h_dim1;
958 d__5 = (d__1 = h__[i__5].r, abs(d__1)) + (d__2 = d_imag(&h__[
959 k + k * h_dim1]), abs(d__2)), d__6 = (d__3 = z__1.r,
960 abs(d__3)) + (d__4 = d_imag(&z__1), abs(d__4));
961 bb = f2cmin(d__5,d__6);
964 d__1 = smlnum, d__2 = ulp * (bb * (aa / s));
965 if (ba * (ab / s) <= f2cmax(d__1,d__2)) {
975 /* H(L,L-1) is negligible */
977 i__2 = l + (l - 1) * h_dim1;
978 h__[i__2].r = 0., h__[i__2].i = 0.;
981 /* Exit from loop if a submatrix of order 1 has split off. */
987 /* Now the active submatrix is in rows and columns L to I. If */
988 /* eigenvalues only are being computed, only the active submatrix */
989 /* need be transformed. */
998 /* Exceptional shift. */
1000 i__2 = l + 1 + l * h_dim1;
1001 s = (d__1 = h__[i__2].r, abs(d__1)) * .75;
1002 i__2 = l + l * h_dim1;
1003 z__1.r = s + h__[i__2].r, z__1.i = h__[i__2].i;
1004 t.r = z__1.r, t.i = z__1.i;
1005 } else if (its == 20) {
1007 /* Exceptional shift. */
1009 i__2 = i__ + (i__ - 1) * h_dim1;
1010 s = (d__1 = h__[i__2].r, abs(d__1)) * .75;
1011 i__2 = i__ + i__ * h_dim1;
1012 z__1.r = s + h__[i__2].r, z__1.i = h__[i__2].i;
1013 t.r = z__1.r, t.i = z__1.i;
1016 /* Wilkinson's shift. */
1018 i__2 = i__ + i__ * h_dim1;
1019 t.r = h__[i__2].r, t.i = h__[i__2].i;
1020 z_sqrt(&z__2, &h__[i__ - 1 + i__ * h_dim1]);
1021 z_sqrt(&z__3, &h__[i__ + (i__ - 1) * h_dim1]);
1022 z__1.r = z__2.r * z__3.r - z__2.i * z__3.i, z__1.i = z__2.r *
1023 z__3.i + z__2.i * z__3.r;
1024 u.r = z__1.r, u.i = z__1.i;
1025 s = (d__1 = u.r, abs(d__1)) + (d__2 = d_imag(&u), abs(d__2));
1027 i__2 = i__ - 1 + (i__ - 1) * h_dim1;
1028 z__2.r = h__[i__2].r - t.r, z__2.i = h__[i__2].i - t.i;
1029 z__1.r = z__2.r * .5, z__1.i = z__2.i * .5;
1030 x.r = z__1.r, x.i = z__1.i;
1031 sx = (d__1 = x.r, abs(d__1)) + (d__2 = d_imag(&x), abs(d__2));
1033 d__3 = s, d__4 = (d__1 = x.r, abs(d__1)) + (d__2 = d_imag(&x),
1035 s = f2cmax(d__3,d__4);
1036 z__5.r = x.r / s, z__5.i = x.i / s;
1037 pow_zi(&z__4, &z__5, &c__2);
1038 z__7.r = u.r / s, z__7.i = u.i / s;
1039 pow_zi(&z__6, &z__7, &c__2);
1040 z__3.r = z__4.r + z__6.r, z__3.i = z__4.i + z__6.i;
1041 z_sqrt(&z__2, &z__3);
1042 z__1.r = s * z__2.r, z__1.i = s * z__2.i;
1043 y.r = z__1.r, y.i = z__1.i;
1045 z__1.r = x.r / sx, z__1.i = x.i / sx;
1046 z__2.r = x.r / sx, z__2.i = x.i / sx;
1047 if (z__1.r * y.r + d_imag(&z__2) * d_imag(&y) < 0.) {
1048 z__3.r = -y.r, z__3.i = -y.i;
1049 y.r = z__3.r, y.i = z__3.i;
1052 z__4.r = x.r + y.r, z__4.i = x.i + y.i;
1053 zladiv_(&z__3, &u, &z__4);
1054 z__2.r = u.r * z__3.r - u.i * z__3.i, z__2.i = u.r * z__3.i +
1056 z__1.r = t.r - z__2.r, z__1.i = t.i - z__2.i;
1057 t.r = z__1.r, t.i = z__1.i;
1061 /* Look for two consecutive small subdiagonal elements. */
1064 for (m = i__ - 1; m >= i__2; --m) {
1066 /* Determine the effect of starting the single-shift QR */
1067 /* iteration at row M, and see if this would make H(M,M-1) */
1070 i__3 = m + m * h_dim1;
1071 h11.r = h__[i__3].r, h11.i = h__[i__3].i;
1072 i__3 = m + 1 + (m + 1) * h_dim1;
1073 h22.r = h__[i__3].r, h22.i = h__[i__3].i;
1074 z__1.r = h11.r - t.r, z__1.i = h11.i - t.i;
1075 h11s.r = z__1.r, h11s.i = z__1.i;
1076 i__3 = m + 1 + m * h_dim1;
1078 s = (d__1 = h11s.r, abs(d__1)) + (d__2 = d_imag(&h11s), abs(d__2))
1080 z__1.r = h11s.r / s, z__1.i = h11s.i / s;
1081 h11s.r = z__1.r, h11s.i = z__1.i;
1083 v[0].r = h11s.r, v[0].i = h11s.i;
1084 v[1].r = h21, v[1].i = 0.;
1085 i__3 = m + (m - 1) * h_dim1;
1087 if (abs(h10) * abs(h21) <= ulp * (((d__1 = h11s.r, abs(d__1)) + (
1088 d__2 = d_imag(&h11s), abs(d__2))) * ((d__3 = h11.r, abs(
1089 d__3)) + (d__4 = d_imag(&h11), abs(d__4)) + ((d__5 =
1090 h22.r, abs(d__5)) + (d__6 = d_imag(&h22), abs(d__6)))))) {
1095 i__2 = l + l * h_dim1;
1096 h11.r = h__[i__2].r, h11.i = h__[i__2].i;
1097 i__2 = l + 1 + (l + 1) * h_dim1;
1098 h22.r = h__[i__2].r, h22.i = h__[i__2].i;
1099 z__1.r = h11.r - t.r, z__1.i = h11.i - t.i;
1100 h11s.r = z__1.r, h11s.i = z__1.i;
1101 i__2 = l + 1 + l * h_dim1;
1103 s = (d__1 = h11s.r, abs(d__1)) + (d__2 = d_imag(&h11s), abs(d__2)) +
1105 z__1.r = h11s.r / s, z__1.i = h11s.i / s;
1106 h11s.r = z__1.r, h11s.i = z__1.i;
1108 v[0].r = h11s.r, v[0].i = h11s.i;
1109 v[1].r = h21, v[1].i = 0.;
1112 /* Single-shift QR step */
1115 for (k = m; k <= i__2; ++k) {
1117 /* The first iteration of this loop determines a reflection G */
1118 /* from the vector V and applies it from left and right to H, */
1119 /* thus creating a nonzero bulge below the subdiagonal. */
1121 /* Each subsequent iteration determines a reflection G to */
1122 /* restore the Hessenberg form in the (K-1)th column, and thus */
1123 /* chases the bulge one step toward the bottom of the active */
1126 /* V(2) is always real before the call to ZLARFG, and hence */
1127 /* after the call T2 ( = T1*V(2) ) is also real. */
1130 zcopy_(&c__2, &h__[k + (k - 1) * h_dim1], &c__1, v, &c__1);
1132 zlarfg_(&c__2, v, &v[1], &c__1, &t1);
1134 i__3 = k + (k - 1) * h_dim1;
1135 h__[i__3].r = v[0].r, h__[i__3].i = v[0].i;
1136 i__3 = k + 1 + (k - 1) * h_dim1;
1137 h__[i__3].r = 0., h__[i__3].i = 0.;
1139 v2.r = v[1].r, v2.i = v[1].i;
1140 z__1.r = t1.r * v2.r - t1.i * v2.i, z__1.i = t1.r * v2.i + t1.i *
1144 /* Apply G from the left to transform the rows of the matrix */
1145 /* in columns K to I2. */
1148 for (j = k; j <= i__3; ++j) {
1150 i__4 = k + j * h_dim1;
1151 z__2.r = z__3.r * h__[i__4].r - z__3.i * h__[i__4].i, z__2.i =
1152 z__3.r * h__[i__4].i + z__3.i * h__[i__4].r;
1153 i__5 = k + 1 + j * h_dim1;
1154 z__4.r = t2 * h__[i__5].r, z__4.i = t2 * h__[i__5].i;
1155 z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
1156 sum.r = z__1.r, sum.i = z__1.i;
1157 i__4 = k + j * h_dim1;
1158 i__5 = k + j * h_dim1;
1159 z__1.r = h__[i__5].r - sum.r, z__1.i = h__[i__5].i - sum.i;
1160 h__[i__4].r = z__1.r, h__[i__4].i = z__1.i;
1161 i__4 = k + 1 + j * h_dim1;
1162 i__5 = k + 1 + j * h_dim1;
1163 z__2.r = sum.r * v2.r - sum.i * v2.i, z__2.i = sum.r * v2.i +
1165 z__1.r = h__[i__5].r - z__2.r, z__1.i = h__[i__5].i - z__2.i;
1166 h__[i__4].r = z__1.r, h__[i__4].i = z__1.i;
1170 /* Apply G from the right to transform the columns of the */
1171 /* matrix in rows I1 to f2cmin(K+2,I). */
1175 i__3 = f2cmin(i__4,i__);
1176 for (j = i1; j <= i__3; ++j) {
1177 i__4 = j + k * h_dim1;
1178 z__2.r = t1.r * h__[i__4].r - t1.i * h__[i__4].i, z__2.i =
1179 t1.r * h__[i__4].i + t1.i * h__[i__4].r;
1180 i__5 = j + (k + 1) * h_dim1;
1181 z__3.r = t2 * h__[i__5].r, z__3.i = t2 * h__[i__5].i;
1182 z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1183 sum.r = z__1.r, sum.i = z__1.i;
1184 i__4 = j + k * h_dim1;
1185 i__5 = j + k * h_dim1;
1186 z__1.r = h__[i__5].r - sum.r, z__1.i = h__[i__5].i - sum.i;
1187 h__[i__4].r = z__1.r, h__[i__4].i = z__1.i;
1188 i__4 = j + (k + 1) * h_dim1;
1189 i__5 = j + (k + 1) * h_dim1;
1191 z__2.r = sum.r * z__3.r - sum.i * z__3.i, z__2.i = sum.r *
1192 z__3.i + sum.i * z__3.r;
1193 z__1.r = h__[i__5].r - z__2.r, z__1.i = h__[i__5].i - z__2.i;
1194 h__[i__4].r = z__1.r, h__[i__4].i = z__1.i;
1200 /* Accumulate transformations in the matrix Z */
1203 for (j = *iloz; j <= i__3; ++j) {
1204 i__4 = j + k * z_dim1;
1205 z__2.r = t1.r * z__[i__4].r - t1.i * z__[i__4].i, z__2.i =
1206 t1.r * z__[i__4].i + t1.i * z__[i__4].r;
1207 i__5 = j + (k + 1) * z_dim1;
1208 z__3.r = t2 * z__[i__5].r, z__3.i = t2 * z__[i__5].i;
1209 z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1210 sum.r = z__1.r, sum.i = z__1.i;
1211 i__4 = j + k * z_dim1;
1212 i__5 = j + k * z_dim1;
1213 z__1.r = z__[i__5].r - sum.r, z__1.i = z__[i__5].i -
1215 z__[i__4].r = z__1.r, z__[i__4].i = z__1.i;
1216 i__4 = j + (k + 1) * z_dim1;
1217 i__5 = j + (k + 1) * z_dim1;
1219 z__2.r = sum.r * z__3.r - sum.i * z__3.i, z__2.i = sum.r *
1220 z__3.i + sum.i * z__3.r;
1221 z__1.r = z__[i__5].r - z__2.r, z__1.i = z__[i__5].i -
1223 z__[i__4].r = z__1.r, z__[i__4].i = z__1.i;
1228 if (k == m && m > l) {
1230 /* If the QR step was started at row M > L because two */
1231 /* consecutive small subdiagonals were found, then extra */
1232 /* scaling must be performed to ensure that H(M,M-1) remains */
1235 z__1.r = 1. - t1.r, z__1.i = 0. - t1.i;
1236 temp.r = z__1.r, temp.i = z__1.i;
1237 d__1 = z_abs(&temp);
1238 z__1.r = temp.r / d__1, z__1.i = temp.i / d__1;
1239 temp.r = z__1.r, temp.i = z__1.i;
1240 i__3 = m + 1 + m * h_dim1;
1241 i__4 = m + 1 + m * h_dim1;
1242 d_cnjg(&z__2, &temp);
1243 z__1.r = h__[i__4].r * z__2.r - h__[i__4].i * z__2.i, z__1.i =
1244 h__[i__4].r * z__2.i + h__[i__4].i * z__2.r;
1245 h__[i__3].r = z__1.r, h__[i__3].i = z__1.i;
1247 i__3 = m + 2 + (m + 1) * h_dim1;
1248 i__4 = m + 2 + (m + 1) * h_dim1;
1249 z__1.r = h__[i__4].r * temp.r - h__[i__4].i * temp.i,
1250 z__1.i = h__[i__4].r * temp.i + h__[i__4].i *
1252 h__[i__3].r = z__1.r, h__[i__3].i = z__1.i;
1255 for (j = m; j <= i__3; ++j) {
1259 zscal_(&i__4, &temp, &h__[j + (j + 1) * h_dim1],
1263 d_cnjg(&z__1, &temp);
1264 zscal_(&i__4, &z__1, &h__[i1 + j * h_dim1], &c__1);
1266 d_cnjg(&z__1, &temp);
1267 zscal_(&nz, &z__1, &z__[*iloz + j * z_dim1], &
1277 /* Ensure that H(I,I-1) is real. */
1279 i__2 = i__ + (i__ - 1) * h_dim1;
1280 temp.r = h__[i__2].r, temp.i = h__[i__2].i;
1281 if (d_imag(&temp) != 0.) {
1282 rtemp = z_abs(&temp);
1283 i__2 = i__ + (i__ - 1) * h_dim1;
1284 h__[i__2].r = rtemp, h__[i__2].i = 0.;
1285 z__1.r = temp.r / rtemp, z__1.i = temp.i / rtemp;
1286 temp.r = z__1.r, temp.i = z__1.i;
1289 d_cnjg(&z__1, &temp);
1290 zscal_(&i__2, &z__1, &h__[i__ + (i__ + 1) * h_dim1], ldh);
1293 zscal_(&i__2, &temp, &h__[i1 + i__ * h_dim1], &c__1);
1295 zscal_(&nz, &temp, &z__[*iloz + i__ * z_dim1], &c__1);
1302 /* Failure to converge in remaining number of iterations */
1309 /* H(I,I-1) is negligible: one eigenvalue has converged. */
1312 i__2 = i__ + i__ * h_dim1;
1313 w[i__1].r = h__[i__2].r, w[i__1].i = h__[i__2].i;
1315 /* return to start of the main loop with new value of I. */