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(_Fcomplex x, integer n) {
296 _Fcomplex pow={1.0,0.0}; unsigned long int u;
298 if(n < 0) n = -n, x._Val[0] = 1./x._Val[0], x._Val[1]=1./x._Val[1];
300 if(u & 01) pow = _FCmulcc (pow,x);
301 if(u >>= 1) x = _FCmulcc (x,x);
308 static _Complex float cpow_ui(_Complex float x, integer n) {
309 _Complex float pow=1.0; unsigned long int u;
311 if(n < 0) n = -n, x = 1/x;
322 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
323 _Dcomplex pow={1.0,0.0}; unsigned long int u;
325 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
327 if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
328 if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
332 _Dcomplex p = {pow._Val[0], pow._Val[1]};
336 static _Complex double zpow_ui(_Complex double x, integer n) {
337 _Complex double pow=1.0; unsigned long int u;
339 if(n < 0) n = -n, x = 1/x;
349 static integer pow_ii(integer x, integer n) {
350 integer pow; unsigned long int u;
352 if (n == 0 || x == 1) pow = 1;
353 else if (x != -1) pow = x == 0 ? 1/x : 0;
356 if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
366 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
368 double m; integer i, mi;
369 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
370 if (w[i-1]>m) mi=i ,m=w[i-1];
373 static integer smaxloc_(float *w, integer s, integer e, integer *n)
375 float m; integer i, mi;
376 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
377 if (w[i-1]>m) mi=i ,m=w[i-1];
380 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
381 integer n = *n_, incx = *incx_, incy = *incy_, i;
383 _Fcomplex zdotc = {0.0, 0.0};
384 if (incx == 1 && incy == 1) {
385 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
386 zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
387 zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
390 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
391 zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
392 zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
398 _Complex float zdotc = 0.0;
399 if (incx == 1 && incy == 1) {
400 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
401 zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
404 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
405 zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
411 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
412 integer n = *n_, incx = *incx_, incy = *incy_, i;
414 _Dcomplex zdotc = {0.0, 0.0};
415 if (incx == 1 && incy == 1) {
416 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
417 zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
418 zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
421 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
422 zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
423 zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
429 _Complex double zdotc = 0.0;
430 if (incx == 1 && incy == 1) {
431 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
432 zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
435 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
436 zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
442 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
443 integer n = *n_, incx = *incx_, incy = *incy_, i;
445 _Fcomplex zdotc = {0.0, 0.0};
446 if (incx == 1 && incy == 1) {
447 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
448 zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
449 zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
452 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
453 zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
454 zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
460 _Complex float zdotc = 0.0;
461 if (incx == 1 && incy == 1) {
462 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
463 zdotc += Cf(&x[i]) * Cf(&y[i]);
466 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
467 zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
473 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
474 integer n = *n_, incx = *incx_, incy = *incy_, i;
476 _Dcomplex zdotc = {0.0, 0.0};
477 if (incx == 1 && incy == 1) {
478 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
479 zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
480 zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
483 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
484 zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
485 zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
491 _Complex double zdotc = 0.0;
492 if (incx == 1 && incy == 1) {
493 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
494 zdotc += Cd(&x[i]) * Cd(&y[i]);
497 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
498 zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
504 /* -- translated by f2c (version 20000121).
505 You must link the resulting object file with the libraries:
506 -lf2c -lm (in that order)
512 /* Table of constant values */
514 static integer c__1 = 1;
515 static integer c__2 = 2;
517 /* > \brief \b CLAHQR computes the eigenvalues and Schur factorization of an upper Hessenberg matrix, using th
518 e double-shift/single-shift QR algorithm. */
520 /* =========== DOCUMENTATION =========== */
522 /* Online html documentation available at */
523 /* http://www.netlib.org/lapack/explore-html/ */
526 /* > Download CLAHQR + dependencies */
527 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clahqr.
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clahqr.
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clahqr.
541 /* SUBROUTINE CLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ, */
542 /* IHIZ, Z, LDZ, INFO ) */
544 /* INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, N */
545 /* LOGICAL WANTT, WANTZ */
546 /* COMPLEX H( LDH, * ), W( * ), Z( LDZ, * ) */
549 /* > \par Purpose: */
554 /* > CLAHQR is an auxiliary routine called by CHSEQR to update the */
555 /* > eigenvalues and Schur decomposition already computed by CHSEQR, by */
556 /* > dealing with the Hessenberg submatrix in rows and columns ILO to */
563 /* > \param[in] WANTT */
565 /* > WANTT is LOGICAL */
566 /* > = .TRUE. : the full Schur form T is required; */
567 /* > = .FALSE.: only eigenvalues are required. */
570 /* > \param[in] WANTZ */
572 /* > WANTZ is LOGICAL */
573 /* > = .TRUE. : the matrix of Schur vectors Z is required; */
574 /* > = .FALSE.: Schur vectors are not required. */
580 /* > The order of the matrix H. N >= 0. */
583 /* > \param[in] ILO */
585 /* > ILO is INTEGER */
588 /* > \param[in] IHI */
590 /* > IHI is INTEGER */
591 /* > It is assumed that H is already upper triangular in rows and */
592 /* > columns IHI+1:N, and that H(ILO,ILO-1) = 0 (unless ILO = 1). */
593 /* > CLAHQR works primarily with the Hessenberg submatrix in rows */
594 /* > and columns ILO to IHI, but applies transformations to all of */
595 /* > H if WANTT is .TRUE.. */
596 /* > 1 <= ILO <= f2cmax(1,IHI); IHI <= N. */
599 /* > \param[in,out] H */
601 /* > H is COMPLEX array, dimension (LDH,N) */
602 /* > On entry, the upper Hessenberg matrix H. */
603 /* > On exit, if INFO is zero and if WANTT is .TRUE., then H */
604 /* > is upper triangular in rows and columns ILO:IHI. If INFO */
605 /* > is zero and if WANTT is .FALSE., then the contents of H */
606 /* > are unspecified on exit. The output state of H in case */
607 /* > INF is positive is below under the description of INFO. */
610 /* > \param[in] LDH */
612 /* > LDH is INTEGER */
613 /* > The leading dimension of the array H. LDH >= f2cmax(1,N). */
616 /* > \param[out] W */
618 /* > W is COMPLEX array, dimension (N) */
619 /* > The computed eigenvalues ILO to IHI are stored in the */
620 /* > corresponding elements of W. If WANTT is .TRUE., the */
621 /* > eigenvalues are stored in the same order as on the diagonal */
622 /* > of the Schur form returned in H, with W(i) = H(i,i). */
625 /* > \param[in] ILOZ */
627 /* > ILOZ is INTEGER */
630 /* > \param[in] IHIZ */
632 /* > IHIZ is INTEGER */
633 /* > Specify the rows of Z to which transformations must be */
634 /* > applied if WANTZ is .TRUE.. */
635 /* > 1 <= ILOZ <= ILO; IHI <= IHIZ <= N. */
638 /* > \param[in,out] Z */
640 /* > Z is COMPLEX array, dimension (LDZ,N) */
641 /* > If WANTZ is .TRUE., on entry Z must contain the current */
642 /* > matrix Z of transformations accumulated by CHSEQR, and on */
643 /* > exit Z has been updated; transformations are applied only to */
644 /* > the submatrix Z(ILOZ:IHIZ,ILO:IHI). */
645 /* > If WANTZ is .FALSE., Z is not referenced. */
648 /* > \param[in] LDZ */
650 /* > LDZ is INTEGER */
651 /* > The leading dimension of the array Z. LDZ >= f2cmax(1,N). */
654 /* > \param[out] INFO */
656 /* > INFO is INTEGER */
657 /* > = 0: successful exit */
658 /* > > 0: if INFO = i, CLAHQR failed to compute all the */
659 /* > eigenvalues ILO to IHI in a total of 30 iterations */
660 /* > per eigenvalue; elements i+1:ihi of W contain */
661 /* > those eigenvalues which have been successfully */
664 /* > If INFO > 0 and WANTT is .FALSE., then on exit, */
665 /* > the remaining unconverged eigenvalues are the */
666 /* > eigenvalues of the upper Hessenberg matrix */
667 /* > rows and columns ILO through INFO of the final, */
668 /* > output value of H. */
670 /* > If INFO > 0 and WANTT is .TRUE., then on exit */
671 /* > (*) (initial value of H)*U = U*(final value of H) */
672 /* > where U is an orthogonal matrix. The final */
673 /* > value of H is upper Hessenberg and triangular in */
674 /* > rows and columns INFO+1 through IHI. */
676 /* > If INFO > 0 and WANTZ is .TRUE., then on exit */
677 /* > (final value of Z) = (initial value of Z)*U */
678 /* > where U is the orthogonal matrix in (*) */
679 /* > (regardless of the value of WANTT.) */
685 /* > \author Univ. of Tennessee */
686 /* > \author Univ. of California Berkeley */
687 /* > \author Univ. of Colorado Denver */
688 /* > \author NAG Ltd. */
690 /* > \date December 2016 */
692 /* > \ingroup complexOTHERauxiliary */
694 /* > \par Contributors: */
695 /* ================== */
699 /* > 02-96 Based on modifications by */
700 /* > David Day, Sandia National Laboratory, USA */
702 /* > 12-04 Further modifications by */
703 /* > Ralph Byers, University of Kansas, USA */
704 /* > This is a modified version of CLAHQR from LAPACK version 3.0. */
705 /* > It is (1) more robust against overflow and underflow and */
706 /* > (2) adopts the more conservative Ahues & Tisseur stopping */
707 /* > criterion (LAWN 122, 1997). */
710 /* ===================================================================== */
711 /* Subroutine */ int clahqr_(logical *wantt, logical *wantz, integer *n,
712 integer *ilo, integer *ihi, complex *h__, integer *ldh, complex *w,
713 integer *iloz, integer *ihiz, complex *z__, integer *ldz, integer *
716 /* System generated locals */
717 integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
718 real r__1, r__2, r__3, r__4, r__5, r__6;
719 complex q__1, q__2, q__3, q__4, q__5, q__6, q__7;
721 /* Local variables */
723 integer i__, j, k, l, m;
725 complex t, u, v[2], x, y;
726 extern /* Subroutine */ int cscal_(integer *, complex *, complex *,
727 integer *), ccopy_(integer *, complex *, integer *, complex *,
735 real aa, ab, ba, bb, h10;
740 extern /* Subroutine */ int slabad_(real *, real *), clarfg_(integer *,
741 complex *, complex *, integer *, complex *);
742 extern /* Complex */ VOID cladiv_(complex *, complex *, complex *);
743 extern real slamch_(char *);
745 real sx, safmin, safmax, smlnum;
754 /* -- LAPACK auxiliary routine (version 3.7.0) -- */
755 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
756 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
760 /* ========================================================= */
763 /* Parameter adjustments */
765 h_offset = 1 + h_dim1 * 1;
769 z_offset = 1 + z_dim1 * 1;
775 /* Quick return if possible */
782 i__2 = *ilo + *ilo * h_dim1;
783 w[i__1].r = h__[i__2].r, w[i__1].i = h__[i__2].i;
787 /* ==== clear out the trash ==== */
789 for (j = *ilo; j <= i__1; ++j) {
790 i__2 = j + 2 + j * h_dim1;
791 h__[i__2].r = 0.f, h__[i__2].i = 0.f;
792 i__2 = j + 3 + j * h_dim1;
793 h__[i__2].r = 0.f, h__[i__2].i = 0.f;
796 if (*ilo <= *ihi - 2) {
797 i__1 = *ihi + (*ihi - 2) * h_dim1;
798 h__[i__1].r = 0.f, h__[i__1].i = 0.f;
800 /* ==== ensure that subdiagonal entries are real ==== */
809 for (i__ = *ilo + 1; i__ <= i__1; ++i__) {
810 if (r_imag(&h__[i__ + (i__ - 1) * h_dim1]) != 0.f) {
811 /* ==== The following redundant normalization */
812 /* . avoids problems with both gradual and */
813 /* . sudden underflow in ABS(H(I,I-1)) ==== */
814 i__2 = i__ + (i__ - 1) * h_dim1;
815 i__3 = i__ + (i__ - 1) * h_dim1;
816 r__3 = (r__1 = h__[i__3].r, abs(r__1)) + (r__2 = r_imag(&h__[i__
817 + (i__ - 1) * h_dim1]), abs(r__2));
818 q__1.r = h__[i__2].r / r__3, q__1.i = h__[i__2].i / r__3;
819 sc.r = q__1.r, sc.i = q__1.i;
822 q__1.r = q__2.r / r__1, q__1.i = q__2.i / r__1;
823 sc.r = q__1.r, sc.i = q__1.i;
824 i__2 = i__ + (i__ - 1) * h_dim1;
825 r__1 = c_abs(&h__[i__ + (i__ - 1) * h_dim1]);
826 h__[i__2].r = r__1, h__[i__2].i = 0.f;
827 i__2 = jhi - i__ + 1;
828 cscal_(&i__2, &sc, &h__[i__ + i__ * h_dim1], ldh);
830 i__3 = jhi, i__4 = i__ + 1;
831 i__2 = f2cmin(i__3,i__4) - jlo + 1;
833 cscal_(&i__2, &q__1, &h__[jlo + i__ * h_dim1], &c__1);
835 i__2 = *ihiz - *iloz + 1;
837 cscal_(&i__2, &q__1, &z__[*iloz + i__ * z_dim1], &c__1);
843 nh = *ihi - *ilo + 1;
844 nz = *ihiz - *iloz + 1;
846 /* Set machine-dependent constants for the stopping criterion. */
848 safmin = slamch_("SAFE MINIMUM");
849 safmax = 1.f / safmin;
850 slabad_(&safmin, &safmax);
851 ulp = slamch_("PRECISION");
852 smlnum = safmin * ((real) nh / ulp);
854 /* I1 and I2 are the indices of the first row and last column of H */
855 /* to which transformations must be applied. If eigenvalues only are */
856 /* being computed, I1 and I2 are set inside the main loop. */
863 /* ITMAX is the total number of QR iterations allowed. */
865 itmax = f2cmax(10,nh) * 30;
867 /* The main loop begins here. I is the loop index and decreases from */
868 /* IHI to ILO in steps of 1. Each iteration of the loop works */
869 /* with the active submatrix in rows and columns L to I. */
870 /* Eigenvalues I+1 to IHI have already converged. Either L = ILO, or */
871 /* H(L,L-1) is negligible so that the matrix splits. */
879 /* Perform QR iterations on rows and columns ILO to I until a */
880 /* submatrix of order 1 splits off at the bottom because a */
881 /* subdiagonal element has become negligible. */
885 for (its = 0; its <= i__1; ++its) {
887 /* Look for a single small subdiagonal element. */
890 for (k = i__; k >= i__2; --k) {
891 i__3 = k + (k - 1) * h_dim1;
892 if ((r__1 = h__[i__3].r, abs(r__1)) + (r__2 = r_imag(&h__[k + (k
893 - 1) * h_dim1]), abs(r__2)) <= smlnum) {
896 i__3 = k - 1 + (k - 1) * h_dim1;
897 i__4 = k + k * h_dim1;
898 tst = (r__1 = h__[i__3].r, abs(r__1)) + (r__2 = r_imag(&h__[k - 1
899 + (k - 1) * h_dim1]), abs(r__2)) + ((r__3 = h__[i__4].r,
900 abs(r__3)) + (r__4 = r_imag(&h__[k + k * h_dim1]), abs(
904 i__3 = k - 1 + (k - 2) * h_dim1;
905 tst += (r__1 = h__[i__3].r, abs(r__1));
908 i__3 = k + 1 + k * h_dim1;
909 tst += (r__1 = h__[i__3].r, abs(r__1));
912 /* ==== The following is a conservative small subdiagonal */
913 /* . deflation criterion due to Ahues & Tisseur (LAWN 122, */
914 /* . 1997). It has better mathematical foundation and */
915 /* . improves accuracy in some examples. ==== */
916 i__3 = k + (k - 1) * h_dim1;
917 if ((r__1 = h__[i__3].r, abs(r__1)) <= ulp * tst) {
919 i__3 = k + (k - 1) * h_dim1;
920 i__4 = k - 1 + k * h_dim1;
921 r__5 = (r__1 = h__[i__3].r, abs(r__1)) + (r__2 = r_imag(&h__[
922 k + (k - 1) * h_dim1]), abs(r__2)), r__6 = (r__3 =
923 h__[i__4].r, abs(r__3)) + (r__4 = r_imag(&h__[k - 1 +
924 k * h_dim1]), abs(r__4));
925 ab = f2cmax(r__5,r__6);
927 i__3 = k + (k - 1) * h_dim1;
928 i__4 = k - 1 + k * h_dim1;
929 r__5 = (r__1 = h__[i__3].r, abs(r__1)) + (r__2 = r_imag(&h__[
930 k + (k - 1) * h_dim1]), abs(r__2)), r__6 = (r__3 =
931 h__[i__4].r, abs(r__3)) + (r__4 = r_imag(&h__[k - 1 +
932 k * h_dim1]), abs(r__4));
933 ba = f2cmin(r__5,r__6);
934 i__3 = k - 1 + (k - 1) * h_dim1;
935 i__4 = k + k * h_dim1;
936 q__2.r = h__[i__3].r - h__[i__4].r, q__2.i = h__[i__3].i -
938 q__1.r = q__2.r, q__1.i = q__2.i;
940 i__5 = k + k * h_dim1;
941 r__5 = (r__1 = h__[i__5].r, abs(r__1)) + (r__2 = r_imag(&h__[
942 k + k * h_dim1]), abs(r__2)), r__6 = (r__3 = q__1.r,
943 abs(r__3)) + (r__4 = r_imag(&q__1), abs(r__4));
944 aa = f2cmax(r__5,r__6);
945 i__3 = k - 1 + (k - 1) * h_dim1;
946 i__4 = k + k * h_dim1;
947 q__2.r = h__[i__3].r - h__[i__4].r, q__2.i = h__[i__3].i -
949 q__1.r = q__2.r, q__1.i = q__2.i;
951 i__5 = k + k * h_dim1;
952 r__5 = (r__1 = h__[i__5].r, abs(r__1)) + (r__2 = r_imag(&h__[
953 k + k * h_dim1]), abs(r__2)), r__6 = (r__3 = q__1.r,
954 abs(r__3)) + (r__4 = r_imag(&q__1), abs(r__4));
955 bb = f2cmin(r__5,r__6);
958 r__1 = smlnum, r__2 = ulp * (bb * (aa / s));
959 if (ba * (ab / s) <= f2cmax(r__1,r__2)) {
969 /* H(L,L-1) is negligible */
971 i__2 = l + (l - 1) * h_dim1;
972 h__[i__2].r = 0.f, h__[i__2].i = 0.f;
975 /* Exit from loop if a submatrix of order 1 has split off. */
981 /* Now the active submatrix is in rows and columns L to I. If */
982 /* eigenvalues only are being computed, only the active submatrix */
983 /* need be transformed. */
992 /* Exceptional shift. */
994 i__2 = l + 1 + l * h_dim1;
995 s = (r__1 = h__[i__2].r, abs(r__1)) * .75f;
996 i__2 = l + l * h_dim1;
997 q__1.r = s + h__[i__2].r, q__1.i = h__[i__2].i;
998 t.r = q__1.r, t.i = q__1.i;
999 } else if (its == 20) {
1001 /* Exceptional shift. */
1003 i__2 = i__ + (i__ - 1) * h_dim1;
1004 s = (r__1 = h__[i__2].r, abs(r__1)) * .75f;
1005 i__2 = i__ + i__ * h_dim1;
1006 q__1.r = s + h__[i__2].r, q__1.i = h__[i__2].i;
1007 t.r = q__1.r, t.i = q__1.i;
1010 /* Wilkinson's shift. */
1012 i__2 = i__ + i__ * h_dim1;
1013 t.r = h__[i__2].r, t.i = h__[i__2].i;
1014 c_sqrt(&q__2, &h__[i__ - 1 + i__ * h_dim1]);
1015 c_sqrt(&q__3, &h__[i__ + (i__ - 1) * h_dim1]);
1016 q__1.r = q__2.r * q__3.r - q__2.i * q__3.i, q__1.i = q__2.r *
1017 q__3.i + q__2.i * q__3.r;
1018 u.r = q__1.r, u.i = q__1.i;
1019 s = (r__1 = u.r, abs(r__1)) + (r__2 = r_imag(&u), abs(r__2));
1021 i__2 = i__ - 1 + (i__ - 1) * h_dim1;
1022 q__2.r = h__[i__2].r - t.r, q__2.i = h__[i__2].i - t.i;
1023 q__1.r = q__2.r * .5f, q__1.i = q__2.i * .5f;
1024 x.r = q__1.r, x.i = q__1.i;
1025 sx = (r__1 = x.r, abs(r__1)) + (r__2 = r_imag(&x), abs(r__2));
1027 r__3 = s, r__4 = (r__1 = x.r, abs(r__1)) + (r__2 = r_imag(&x),
1029 s = f2cmax(r__3,r__4);
1030 q__5.r = x.r / s, q__5.i = x.i / s;
1031 pow_ci(&q__4, &q__5, &c__2);
1032 q__7.r = u.r / s, q__7.i = u.i / s;
1033 pow_ci(&q__6, &q__7, &c__2);
1034 q__3.r = q__4.r + q__6.r, q__3.i = q__4.i + q__6.i;
1035 c_sqrt(&q__2, &q__3);
1036 q__1.r = s * q__2.r, q__1.i = s * q__2.i;
1037 y.r = q__1.r, y.i = q__1.i;
1039 q__1.r = x.r / sx, q__1.i = x.i / sx;
1040 q__2.r = x.r / sx, q__2.i = x.i / sx;
1041 if (q__1.r * y.r + r_imag(&q__2) * r_imag(&y) < 0.f) {
1042 q__3.r = -y.r, q__3.i = -y.i;
1043 y.r = q__3.r, y.i = q__3.i;
1046 q__4.r = x.r + y.r, q__4.i = x.i + y.i;
1047 cladiv_(&q__3, &u, &q__4);
1048 q__2.r = u.r * q__3.r - u.i * q__3.i, q__2.i = u.r * q__3.i +
1050 q__1.r = t.r - q__2.r, q__1.i = t.i - q__2.i;
1051 t.r = q__1.r, t.i = q__1.i;
1055 /* Look for two consecutive small subdiagonal elements. */
1058 for (m = i__ - 1; m >= i__2; --m) {
1060 /* Determine the effect of starting the single-shift QR */
1061 /* iteration at row M, and see if this would make H(M,M-1) */
1064 i__3 = m + m * h_dim1;
1065 h11.r = h__[i__3].r, h11.i = h__[i__3].i;
1066 i__3 = m + 1 + (m + 1) * h_dim1;
1067 h22.r = h__[i__3].r, h22.i = h__[i__3].i;
1068 q__1.r = h11.r - t.r, q__1.i = h11.i - t.i;
1069 h11s.r = q__1.r, h11s.i = q__1.i;
1070 i__3 = m + 1 + m * h_dim1;
1072 s = (r__1 = h11s.r, abs(r__1)) + (r__2 = r_imag(&h11s), abs(r__2))
1074 q__1.r = h11s.r / s, q__1.i = h11s.i / s;
1075 h11s.r = q__1.r, h11s.i = q__1.i;
1077 v[0].r = h11s.r, v[0].i = h11s.i;
1078 v[1].r = h21, v[1].i = 0.f;
1079 i__3 = m + (m - 1) * h_dim1;
1081 if (abs(h10) * abs(h21) <= ulp * (((r__1 = h11s.r, abs(r__1)) + (
1082 r__2 = r_imag(&h11s), abs(r__2))) * ((r__3 = h11.r, abs(
1083 r__3)) + (r__4 = r_imag(&h11), abs(r__4)) + ((r__5 =
1084 h22.r, abs(r__5)) + (r__6 = r_imag(&h22), abs(r__6)))))) {
1089 i__2 = l + l * h_dim1;
1090 h11.r = h__[i__2].r, h11.i = h__[i__2].i;
1091 i__2 = l + 1 + (l + 1) * h_dim1;
1092 h22.r = h__[i__2].r, h22.i = h__[i__2].i;
1093 q__1.r = h11.r - t.r, q__1.i = h11.i - t.i;
1094 h11s.r = q__1.r, h11s.i = q__1.i;
1095 i__2 = l + 1 + l * h_dim1;
1097 s = (r__1 = h11s.r, abs(r__1)) + (r__2 = r_imag(&h11s), abs(r__2)) +
1099 q__1.r = h11s.r / s, q__1.i = h11s.i / s;
1100 h11s.r = q__1.r, h11s.i = q__1.i;
1102 v[0].r = h11s.r, v[0].i = h11s.i;
1103 v[1].r = h21, v[1].i = 0.f;
1106 /* Single-shift QR step */
1109 for (k = m; k <= i__2; ++k) {
1111 /* The first iteration of this loop determines a reflection G */
1112 /* from the vector V and applies it from left and right to H, */
1113 /* thus creating a nonzero bulge below the subdiagonal. */
1115 /* Each subsequent iteration determines a reflection G to */
1116 /* restore the Hessenberg form in the (K-1)th column, and thus */
1117 /* chases the bulge one step toward the bottom of the active */
1120 /* V(2) is always real before the call to CLARFG, and hence */
1121 /* after the call T2 ( = T1*V(2) ) is also real. */
1124 ccopy_(&c__2, &h__[k + (k - 1) * h_dim1], &c__1, v, &c__1);
1126 clarfg_(&c__2, v, &v[1], &c__1, &t1);
1128 i__3 = k + (k - 1) * h_dim1;
1129 h__[i__3].r = v[0].r, h__[i__3].i = v[0].i;
1130 i__3 = k + 1 + (k - 1) * h_dim1;
1131 h__[i__3].r = 0.f, h__[i__3].i = 0.f;
1133 v2.r = v[1].r, v2.i = v[1].i;
1134 q__1.r = t1.r * v2.r - t1.i * v2.i, q__1.i = t1.r * v2.i + t1.i *
1138 /* Apply G from the left to transform the rows of the matrix */
1139 /* in columns K to I2. */
1142 for (j = k; j <= i__3; ++j) {
1144 i__4 = k + j * h_dim1;
1145 q__2.r = q__3.r * h__[i__4].r - q__3.i * h__[i__4].i, q__2.i =
1146 q__3.r * h__[i__4].i + q__3.i * h__[i__4].r;
1147 i__5 = k + 1 + j * h_dim1;
1148 q__4.r = t2 * h__[i__5].r, q__4.i = t2 * h__[i__5].i;
1149 q__1.r = q__2.r + q__4.r, q__1.i = q__2.i + q__4.i;
1150 sum.r = q__1.r, sum.i = q__1.i;
1151 i__4 = k + j * h_dim1;
1152 i__5 = k + j * h_dim1;
1153 q__1.r = h__[i__5].r - sum.r, q__1.i = h__[i__5].i - sum.i;
1154 h__[i__4].r = q__1.r, h__[i__4].i = q__1.i;
1155 i__4 = k + 1 + j * h_dim1;
1156 i__5 = k + 1 + j * h_dim1;
1157 q__2.r = sum.r * v2.r - sum.i * v2.i, q__2.i = sum.r * v2.i +
1159 q__1.r = h__[i__5].r - q__2.r, q__1.i = h__[i__5].i - q__2.i;
1160 h__[i__4].r = q__1.r, h__[i__4].i = q__1.i;
1164 /* Apply G from the right to transform the columns of the */
1165 /* matrix in rows I1 to f2cmin(K+2,I). */
1169 i__3 = f2cmin(i__4,i__);
1170 for (j = i1; j <= i__3; ++j) {
1171 i__4 = j + k * h_dim1;
1172 q__2.r = t1.r * h__[i__4].r - t1.i * h__[i__4].i, q__2.i =
1173 t1.r * h__[i__4].i + t1.i * h__[i__4].r;
1174 i__5 = j + (k + 1) * h_dim1;
1175 q__3.r = t2 * h__[i__5].r, q__3.i = t2 * h__[i__5].i;
1176 q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
1177 sum.r = q__1.r, sum.i = q__1.i;
1178 i__4 = j + k * h_dim1;
1179 i__5 = j + k * h_dim1;
1180 q__1.r = h__[i__5].r - sum.r, q__1.i = h__[i__5].i - sum.i;
1181 h__[i__4].r = q__1.r, h__[i__4].i = q__1.i;
1182 i__4 = j + (k + 1) * h_dim1;
1183 i__5 = j + (k + 1) * h_dim1;
1185 q__2.r = sum.r * q__3.r - sum.i * q__3.i, q__2.i = sum.r *
1186 q__3.i + sum.i * q__3.r;
1187 q__1.r = h__[i__5].r - q__2.r, q__1.i = h__[i__5].i - q__2.i;
1188 h__[i__4].r = q__1.r, h__[i__4].i = q__1.i;
1194 /* Accumulate transformations in the matrix Z */
1197 for (j = *iloz; j <= i__3; ++j) {
1198 i__4 = j + k * z_dim1;
1199 q__2.r = t1.r * z__[i__4].r - t1.i * z__[i__4].i, q__2.i =
1200 t1.r * z__[i__4].i + t1.i * z__[i__4].r;
1201 i__5 = j + (k + 1) * z_dim1;
1202 q__3.r = t2 * z__[i__5].r, q__3.i = t2 * z__[i__5].i;
1203 q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
1204 sum.r = q__1.r, sum.i = q__1.i;
1205 i__4 = j + k * z_dim1;
1206 i__5 = j + k * z_dim1;
1207 q__1.r = z__[i__5].r - sum.r, q__1.i = z__[i__5].i -
1209 z__[i__4].r = q__1.r, z__[i__4].i = q__1.i;
1210 i__4 = j + (k + 1) * z_dim1;
1211 i__5 = j + (k + 1) * z_dim1;
1213 q__2.r = sum.r * q__3.r - sum.i * q__3.i, q__2.i = sum.r *
1214 q__3.i + sum.i * q__3.r;
1215 q__1.r = z__[i__5].r - q__2.r, q__1.i = z__[i__5].i -
1217 z__[i__4].r = q__1.r, z__[i__4].i = q__1.i;
1222 if (k == m && m > l) {
1224 /* If the QR step was started at row M > L because two */
1225 /* consecutive small subdiagonals were found, then extra */
1226 /* scaling must be performed to ensure that H(M,M-1) remains */
1229 q__1.r = 1.f - t1.r, q__1.i = 0.f - t1.i;
1230 temp.r = q__1.r, temp.i = q__1.i;
1231 r__1 = c_abs(&temp);
1232 q__1.r = temp.r / r__1, q__1.i = temp.i / r__1;
1233 temp.r = q__1.r, temp.i = q__1.i;
1234 i__3 = m + 1 + m * h_dim1;
1235 i__4 = m + 1 + m * h_dim1;
1236 r_cnjg(&q__2, &temp);
1237 q__1.r = h__[i__4].r * q__2.r - h__[i__4].i * q__2.i, q__1.i =
1238 h__[i__4].r * q__2.i + h__[i__4].i * q__2.r;
1239 h__[i__3].r = q__1.r, h__[i__3].i = q__1.i;
1241 i__3 = m + 2 + (m + 1) * h_dim1;
1242 i__4 = m + 2 + (m + 1) * h_dim1;
1243 q__1.r = h__[i__4].r * temp.r - h__[i__4].i * temp.i,
1244 q__1.i = h__[i__4].r * temp.i + h__[i__4].i *
1246 h__[i__3].r = q__1.r, h__[i__3].i = q__1.i;
1249 for (j = m; j <= i__3; ++j) {
1253 cscal_(&i__4, &temp, &h__[j + (j + 1) * h_dim1],
1257 r_cnjg(&q__1, &temp);
1258 cscal_(&i__4, &q__1, &h__[i1 + j * h_dim1], &c__1);
1260 r_cnjg(&q__1, &temp);
1261 cscal_(&nz, &q__1, &z__[*iloz + j * z_dim1], &
1271 /* Ensure that H(I,I-1) is real. */
1273 i__2 = i__ + (i__ - 1) * h_dim1;
1274 temp.r = h__[i__2].r, temp.i = h__[i__2].i;
1275 if (r_imag(&temp) != 0.f) {
1276 rtemp = c_abs(&temp);
1277 i__2 = i__ + (i__ - 1) * h_dim1;
1278 h__[i__2].r = rtemp, h__[i__2].i = 0.f;
1279 q__1.r = temp.r / rtemp, q__1.i = temp.i / rtemp;
1280 temp.r = q__1.r, temp.i = q__1.i;
1283 r_cnjg(&q__1, &temp);
1284 cscal_(&i__2, &q__1, &h__[i__ + (i__ + 1) * h_dim1], ldh);
1287 cscal_(&i__2, &temp, &h__[i1 + i__ * h_dim1], &c__1);
1289 cscal_(&nz, &temp, &z__[*iloz + i__ * z_dim1], &c__1);
1296 /* Failure to converge in remaining number of iterations */
1303 /* H(I,I-1) is negligible: one eigenvalue has converged. */
1306 i__2 = i__ + i__ * h_dim1;
1307 w[i__1].r = h__[i__2].r, w[i__1].i = h__[i__2].i;
1309 /* return to start of the main loop with new value of I. */