C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / zlahqr.c
1 #include <math.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <complex.h>
6 #ifdef complex
7 #undef complex
8 #endif
9 #ifdef I
10 #undef I
11 #endif
12
13 #if defined(_WIN64)
14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
16 #else
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
19 #endif
20
21 #ifdef LAPACK_ILP64
22 typedef BLASLONG blasint;
23 #if defined(_WIN64)
24 #define blasabs(x) llabs(x)
25 #else
26 #define blasabs(x) labs(x)
27 #endif
28 #else
29 typedef int blasint;
30 #define blasabs(x) abs(x)
31 #endif
32
33 typedef blasint integer;
34
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
38 typedef float real;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
42 #ifdef _MSC_VER
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;}
47 #else
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;}
52 #endif
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
55 typedef int logical;
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
59
60 #define TRUE_ (1)
61 #define FALSE_ (0)
62
63 /* Extern is for use with -E */
64 #ifndef Extern
65 #define Extern extern
66 #endif
67
68 /* I/O stuff */
69
70 typedef int flag;
71 typedef int ftnlen;
72 typedef int ftnint;
73
74 /*external read, write*/
75 typedef struct
76 {       flag cierr;
77         ftnint ciunit;
78         flag ciend;
79         char *cifmt;
80         ftnint cirec;
81 } cilist;
82
83 /*internal read, write*/
84 typedef struct
85 {       flag icierr;
86         char *iciunit;
87         flag iciend;
88         char *icifmt;
89         ftnint icirlen;
90         ftnint icirnum;
91 } icilist;
92
93 /*open*/
94 typedef struct
95 {       flag oerr;
96         ftnint ounit;
97         char *ofnm;
98         ftnlen ofnmlen;
99         char *osta;
100         char *oacc;
101         char *ofm;
102         ftnint orl;
103         char *oblnk;
104 } olist;
105
106 /*close*/
107 typedef struct
108 {       flag cerr;
109         ftnint cunit;
110         char *csta;
111 } cllist;
112
113 /*rewind, backspace, endfile*/
114 typedef struct
115 {       flag aerr;
116         ftnint aunit;
117 } alist;
118
119 /* inquire */
120 typedef struct
121 {       flag inerr;
122         ftnint inunit;
123         char *infile;
124         ftnlen infilen;
125         ftnint  *inex;  /*parameters in standard's order*/
126         ftnint  *inopen;
127         ftnint  *innum;
128         ftnint  *innamed;
129         char    *inname;
130         ftnlen  innamlen;
131         char    *inacc;
132         ftnlen  inacclen;
133         char    *inseq;
134         ftnlen  inseqlen;
135         char    *indir;
136         ftnlen  indirlen;
137         char    *infmt;
138         ftnlen  infmtlen;
139         char    *inform;
140         ftnint  informlen;
141         char    *inunf;
142         ftnlen  inunflen;
143         ftnint  *inrecl;
144         ftnint  *innrec;
145         char    *inblank;
146         ftnlen  inblanklen;
147 } inlist;
148
149 #define VOID void
150
151 union Multitype {       /* for multiple entry points */
152         integer1 g;
153         shortint h;
154         integer i;
155         /* longint j; */
156         real r;
157         doublereal d;
158         complex c;
159         doublecomplex z;
160         };
161
162 typedef union Multitype Multitype;
163
164 struct Vardesc {        /* for Namelist */
165         char *name;
166         char *addr;
167         ftnlen *dims;
168         int  type;
169         };
170 typedef struct Vardesc Vardesc;
171
172 struct Namelist {
173         char *name;
174         Vardesc **vars;
175         int nvars;
176         };
177 typedef struct Namelist Namelist;
178
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)))
188
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)); }
192 #ifdef _MSC_VER
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]);}
195 #else
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);}
198 #endif
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)}
260
261 /* procedure parameter types for -A and -C++ */
262
263 #define F2C_proc_par_types 1
264 #ifdef __cplusplus
265 typedef logical (*L_fp)(...);
266 #else
267 typedef logical (*L_fp)();
268 #endif
269
270 static float spow_ui(float x, integer n) {
271         float pow=1.0; unsigned long int u;
272         if(n != 0) {
273                 if(n < 0) n = -n, x = 1/x;
274                 for(u = n; ; ) {
275                         if(u & 01) pow *= x;
276                         if(u >>= 1) x *= x;
277                         else break;
278                 }
279         }
280         return pow;
281 }
282 static double dpow_ui(double x, integer n) {
283         double pow=1.0; unsigned long int u;
284         if(n != 0) {
285                 if(n < 0) n = -n, x = 1/x;
286                 for(u = n; ; ) {
287                         if(u & 01) pow *= x;
288                         if(u >>= 1) x *= x;
289                         else break;
290                 }
291         }
292         return pow;
293 }
294 #ifdef _MSC_VER
295 static _Fcomplex cpow_ui(complex x, integer n) {
296         complex pow={1.0,0.0}; unsigned long int u;
297                 if(n != 0) {
298                 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
299                 for(u = n; ; ) {
300                         if(u & 01) pow.r *= x.r, pow.i *= x.i;
301                         if(u >>= 1) x.r *= x.r, x.i *= x.i;
302                         else break;
303                 }
304         }
305         _Fcomplex p={pow.r, pow.i};
306         return p;
307 }
308 #else
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310         _Complex float pow=1.0; unsigned long int u;
311         if(n != 0) {
312                 if(n < 0) n = -n, x = 1/x;
313                 for(u = n; ; ) {
314                         if(u & 01) pow *= x;
315                         if(u >>= 1) x *= x;
316                         else break;
317                 }
318         }
319         return pow;
320 }
321 #endif
322 #ifdef _MSC_VER
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324         _Dcomplex pow={1.0,0.0}; unsigned long int u;
325         if(n != 0) {
326                 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
327                 for(u = n; ; ) {
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];
330                         else break;
331                 }
332         }
333         _Dcomplex p = {pow._Val[0], pow._Val[1]};
334         return p;
335 }
336 #else
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338         _Complex double pow=1.0; unsigned long int u;
339         if(n != 0) {
340                 if(n < 0) n = -n, x = 1/x;
341                 for(u = n; ; ) {
342                         if(u & 01) pow *= x;
343                         if(u >>= 1) x *= x;
344                         else break;
345                 }
346         }
347         return pow;
348 }
349 #endif
350 static integer pow_ii(integer x, integer n) {
351         integer pow; unsigned long int u;
352         if (n <= 0) {
353                 if (n == 0 || x == 1) pow = 1;
354                 else if (x != -1) pow = x == 0 ? 1/x : 0;
355                 else n = -n;
356         }
357         if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
358                 u = n;
359                 for(pow = 1; ; ) {
360                         if(u & 01) pow *= x;
361                         if(u >>= 1) x *= x;
362                         else break;
363                 }
364         }
365         return pow;
366 }
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
368 {
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];
372         return mi-s+1;
373 }
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
375 {
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];
379         return mi-s+1;
380 }
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;
383 #ifdef _MSC_VER
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];
389                 }
390         } else {
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];
394                 }
395         }
396         pCf(z) = zdotc;
397 }
398 #else
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]);
403                 }
404         } else {
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]);
407                 }
408         }
409         pCf(z) = zdotc;
410 }
411 #endif
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;
414 #ifdef _MSC_VER
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];
420                 }
421         } else {
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];
425                 }
426         }
427         pCd(z) = zdotc;
428 }
429 #else
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]);
434                 }
435         } else {
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]);
438                 }
439         }
440         pCd(z) = zdotc;
441 }
442 #endif  
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;
445 #ifdef _MSC_VER
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];
451                 }
452         } else {
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];
456                 }
457         }
458         pCf(z) = zdotc;
459 }
460 #else
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]);
465                 }
466         } else {
467                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468                         zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
469                 }
470         }
471         pCf(z) = zdotc;
472 }
473 #endif
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;
476 #ifdef _MSC_VER
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];
482                 }
483         } else {
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];
487                 }
488         }
489         pCd(z) = zdotc;
490 }
491 #else
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]);
496                 }
497         } else {
498                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499                         zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
500                 }
501         }
502         pCd(z) = zdotc;
503 }
504 #endif
505 /*  -- translated by f2c (version 20000121).
506    You must link the resulting object file with the libraries:
507         -lf2c -lm   (in that order)
508 */
509
510
511
512
513 /* Table of constant values */
514
515 static integer c__1 = 1;
516 static integer c__2 = 2;
517
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. */
520
521 /*  =========== DOCUMENTATION =========== */
522
523 /* Online html documentation available at */
524 /*            http://www.netlib.org/lapack/explore-html/ */
525
526 /* > \htmlonly */
527 /* > Download ZLAHQR + dependencies */
528 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlahqr.
529 f"> */
530 /* > [TGZ]</a> */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlahqr.
532 f"> */
533 /* > [ZIP]</a> */
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlahqr.
535 f"> */
536 /* > [TXT]</a> */
537 /* > \endhtmlonly */
538
539 /*  Definition: */
540 /*  =========== */
541
542 /*       SUBROUTINE ZLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ, */
543 /*                          IHIZ, Z, LDZ, INFO ) */
544
545 /*       INTEGER            IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, N */
546 /*       LOGICAL            WANTT, WANTZ */
547 /*       COMPLEX*16         H( LDH, * ), W( * ), Z( LDZ, * ) */
548
549
550 /* > \par Purpose: */
551 /*  ============= */
552 /* > */
553 /* > \verbatim */
554 /* > */
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 */
558 /* >    IHI. */
559 /* > \endverbatim */
560
561 /*  Arguments: */
562 /*  ========== */
563
564 /* > \param[in] WANTT */
565 /* > \verbatim */
566 /* >          WANTT is LOGICAL */
567 /* >          = .TRUE. : the full Schur form T is required; */
568 /* >          = .FALSE.: only eigenvalues are required. */
569 /* > \endverbatim */
570 /* > */
571 /* > \param[in] WANTZ */
572 /* > \verbatim */
573 /* >          WANTZ is LOGICAL */
574 /* >          = .TRUE. : the matrix of Schur vectors Z is required; */
575 /* >          = .FALSE.: Schur vectors are not required. */
576 /* > \endverbatim */
577 /* > */
578 /* > \param[in] N */
579 /* > \verbatim */
580 /* >          N is INTEGER */
581 /* >          The order of the matrix H.  N >= 0. */
582 /* > \endverbatim */
583 /* > */
584 /* > \param[in] ILO */
585 /* > \verbatim */
586 /* >          ILO is INTEGER */
587 /* > \endverbatim */
588 /* > */
589 /* > \param[in] IHI */
590 /* > \verbatim */
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. */
598 /* > \endverbatim */
599 /* > */
600 /* > \param[in,out] H */
601 /* > \verbatim */
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. */
609 /* > \endverbatim */
610 /* > */
611 /* > \param[in] LDH */
612 /* > \verbatim */
613 /* >          LDH is INTEGER */
614 /* >          The leading dimension of the array H. LDH >= f2cmax(1,N). */
615 /* > \endverbatim */
616 /* > */
617 /* > \param[out] W */
618 /* > \verbatim */
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). */
624 /* > \endverbatim */
625 /* > */
626 /* > \param[in] ILOZ */
627 /* > \verbatim */
628 /* >          ILOZ is INTEGER */
629 /* > \endverbatim */
630 /* > */
631 /* > \param[in] IHIZ */
632 /* > \verbatim */
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. */
637 /* > \endverbatim */
638 /* > */
639 /* > \param[in,out] Z */
640 /* > \verbatim */
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. */
647 /* > \endverbatim */
648 /* > */
649 /* > \param[in] LDZ */
650 /* > \verbatim */
651 /* >          LDZ is INTEGER */
652 /* >          The leading dimension of the array Z. LDZ >= f2cmax(1,N). */
653 /* > \endverbatim */
654 /* > */
655 /* > \param[out] INFO */
656 /* > \verbatim */
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 */
663 /* >                  computed. */
664 /* > */
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. */
670 /* > */
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. */
676 /* > */
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.) */
681 /* > \endverbatim */
682
683 /*  Authors: */
684 /*  ======== */
685
686 /* > \author Univ. of Tennessee */
687 /* > \author Univ. of California Berkeley */
688 /* > \author Univ. of Colorado Denver */
689 /* > \author NAG Ltd. */
690
691 /* > \date December 2016 */
692
693 /* > \ingroup complex16OTHERauxiliary */
694
695 /* > \par Contributors: */
696 /*  ================== */
697 /* > */
698 /* > \verbatim */
699 /* > */
700 /* >     02-96 Based on modifications by */
701 /* >     David Day, Sandia National Laboratory, USA */
702 /* > */
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). */
709 /* > \endverbatim */
710 /* > */
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)
716 {
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;
721
722     /* Local variables */
723     doublecomplex temp;
724     integer i__, j, k, l, m;
725     doublereal s;
726     doublecomplex t, u, v[2], x, y;
727     extern /* Subroutine */ int zscal_(integer *, doublecomplex *, 
728             doublecomplex *, integer *);
729     integer itmax;
730     doublereal rtemp;
731     integer i1, i2;
732     extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *, 
733             doublecomplex *, integer *);
734     doublecomplex t1;
735     doublereal t2;
736     doublecomplex v2;
737     doublereal aa, ab, ba, bb;
738     extern /* Subroutine */ int dlabad_(doublereal *, doublereal *);
739     doublereal h10;
740     doublecomplex h11;
741     doublereal h21;
742     doublecomplex h22, sc;
743     integer nh;
744     extern doublereal dlamch_(char *);
745     integer nz;
746     doublereal sx, safmin, safmax;
747     extern /* Subroutine */ int zlarfg_(integer *, doublecomplex *, 
748             doublecomplex *, integer *, doublecomplex *);
749     extern /* Double Complex */ VOID zladiv_(doublecomplex *, doublecomplex *,
750              doublecomplex *);
751     doublereal smlnum;
752     integer jhi;
753     doublecomplex h11s;
754     integer jlo, its;
755     doublereal ulp;
756     doublecomplex sum;
757     doublereal tst;
758
759
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..-- */
763 /*     December 2016 */
764
765
766 /*  ========================================================= */
767
768
769     /* Parameter adjustments */
770     h_dim1 = *ldh;
771     h_offset = 1 + h_dim1 * 1;
772     h__ -= h_offset;
773     --w;
774     z_dim1 = *ldz;
775     z_offset = 1 + z_dim1 * 1;
776     z__ -= z_offset;
777
778     /* Function Body */
779     *info = 0;
780
781 /*     Quick return if possible */
782
783     if (*n == 0) {
784         return 0;
785     }
786     if (*ilo == *ihi) {
787         i__1 = *ilo;
788         i__2 = *ilo + *ilo * h_dim1;
789         w[i__1].r = h__[i__2].r, w[i__1].i = h__[i__2].i;
790         return 0;
791     }
792
793 /*     ==== clear out the trash ==== */
794     i__1 = *ihi - 3;
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.;
800 /* L10: */
801     }
802     if (*ilo <= *ihi - 2) {
803         i__1 = *ihi + (*ihi - 2) * h_dim1;
804         h__[i__1].r = 0., h__[i__1].i = 0.;
805     }
806 /*     ==== ensure that subdiagonal entries are real ==== */
807     if (*wantt) {
808         jlo = 1;
809         jhi = *n;
810     } else {
811         jlo = *ilo;
812         jhi = *ihi;
813     }
814     i__1 = *ihi;
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;
826             d_cnjg(&z__2, &sc);
827             d__1 = z_abs(&sc);
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);
835 /* Computing MIN */
836             i__3 = jhi, i__4 = i__ + 1;
837             i__2 = f2cmin(i__3,i__4) - jlo + 1;
838             d_cnjg(&z__1, &sc);
839             zscal_(&i__2, &z__1, &h__[jlo + i__ * h_dim1], &c__1);
840             if (*wantz) {
841                 i__2 = *ihiz - *iloz + 1;
842                 d_cnjg(&z__1, &sc);
843                 zscal_(&i__2, &z__1, &z__[*iloz + i__ * z_dim1], &c__1);
844             }
845         }
846 /* L20: */
847     }
848
849     nh = *ihi - *ilo + 1;
850     nz = *ihiz - *iloz + 1;
851
852 /*     Set machine-dependent constants for the stopping criterion. */
853
854     safmin = dlamch_("SAFE MINIMUM");
855     safmax = 1. / safmin;
856     dlabad_(&safmin, &safmax);
857     ulp = dlamch_("PRECISION");
858     smlnum = safmin * ((doublereal) nh / ulp);
859
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. */
863
864     if (*wantt) {
865         i1 = 1;
866         i2 = *n;
867     }
868
869 /*     ITMAX is the total number of QR iterations allowed. */
870
871     itmax = f2cmax(10,nh) * 30;
872
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. */
878
879     i__ = *ihi;
880 L30:
881     if (i__ < *ilo) {
882         goto L150;
883     }
884
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. */
888
889     l = *ilo;
890     i__1 = itmax;
891     for (its = 0; its <= i__1; ++its) {
892
893 /*        Look for a single small subdiagonal element. */
894
895         i__2 = l + 1;
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) {
900                 goto L50;
901             }
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(
907                     d__4)));
908             if (tst == 0.) {
909                 if (k - 2 >= *ilo) {
910                     i__3 = k - 1 + (k - 2) * h_dim1;
911                     tst += (d__1 = h__[i__3].r, abs(d__1));
912                 }
913                 if (k + 1 <= *ihi) {
914                     i__3 = k + 1 + k * h_dim1;
915                     tst += (d__1 = h__[i__3].r, abs(d__1));
916                 }
917             }
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) {
924 /* Computing MAX */
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);
932 /* Computing MIN */
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 - 
943                         h__[i__4].i;
944                 z__1.r = z__2.r, z__1.i = z__2.i;
945 /* Computing MAX */
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 - 
954                         h__[i__4].i;
955                 z__1.r = z__2.r, z__1.i = z__2.i;
956 /* Computing MIN */
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);
962                 s = aa + ab;
963 /* Computing MAX */
964                 d__1 = smlnum, d__2 = ulp * (bb * (aa / s));
965                 if (ba * (ab / s) <= f2cmax(d__1,d__2)) {
966                     goto L50;
967                 }
968             }
969 /* L40: */
970         }
971 L50:
972         l = k;
973         if (l > *ilo) {
974
975 /*           H(L,L-1) is negligible */
976
977             i__2 = l + (l - 1) * h_dim1;
978             h__[i__2].r = 0., h__[i__2].i = 0.;
979         }
980
981 /*        Exit from loop if a submatrix of order 1 has split off. */
982
983         if (l >= i__) {
984             goto L140;
985         }
986
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. */
990
991         if (! (*wantt)) {
992             i1 = l;
993             i2 = i__;
994         }
995
996         if (its == 10) {
997
998 /*           Exceptional shift. */
999
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) {
1006
1007 /*           Exceptional shift. */
1008
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;
1014         } else {
1015
1016 /*           Wilkinson's shift. */
1017
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));
1026             if (s != 0.) {
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));
1032 /* Computing MAX */
1033                 d__3 = s, d__4 = (d__1 = x.r, abs(d__1)) + (d__2 = d_imag(&x),
1034                          abs(d__2));
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;
1044                 if (sx > 0.) {
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;
1050                     }
1051                 }
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 + 
1055                         u.i * z__3.r;
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;
1058             }
1059         }
1060
1061 /*        Look for two consecutive small subdiagonal elements. */
1062
1063         i__2 = l + 1;
1064         for (m = i__ - 1; m >= i__2; --m) {
1065
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) */
1068 /*           negligible. */
1069
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;
1077             h21 = h__[i__3].r;
1078             s = (d__1 = h11s.r, abs(d__1)) + (d__2 = d_imag(&h11s), abs(d__2))
1079                      + abs(h21);
1080             z__1.r = h11s.r / s, z__1.i = h11s.i / s;
1081             h11s.r = z__1.r, h11s.i = z__1.i;
1082             h21 /= s;
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;
1086             h10 = h__[i__3].r;
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)))))) {
1091                 goto L70;
1092             }
1093 /* L60: */
1094         }
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;
1102         h21 = h__[i__2].r;
1103         s = (d__1 = h11s.r, abs(d__1)) + (d__2 = d_imag(&h11s), abs(d__2)) + 
1104                 abs(h21);
1105         z__1.r = h11s.r / s, z__1.i = h11s.i / s;
1106         h11s.r = z__1.r, h11s.i = z__1.i;
1107         h21 /= s;
1108         v[0].r = h11s.r, v[0].i = h11s.i;
1109         v[1].r = h21, v[1].i = 0.;
1110 L70:
1111
1112 /*        Single-shift QR step */
1113
1114         i__2 = i__ - 1;
1115         for (k = m; k <= i__2; ++k) {
1116
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. */
1120
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 */
1124 /*           submatrix. */
1125
1126 /*           V(2) is always real before the call to ZLARFG, and hence */
1127 /*           after the call T2 ( = T1*V(2) ) is also real. */
1128
1129             if (k > m) {
1130                 zcopy_(&c__2, &h__[k + (k - 1) * h_dim1], &c__1, v, &c__1);
1131             }
1132             zlarfg_(&c__2, v, &v[1], &c__1, &t1);
1133             if (k > m) {
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.;
1138             }
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 * 
1141                     v2.r;
1142             t2 = z__1.r;
1143
1144 /*           Apply G from the left to transform the rows of the matrix */
1145 /*           in columns K to I2. */
1146
1147             i__3 = i2;
1148             for (j = k; j <= i__3; ++j) {
1149                 d_cnjg(&z__3, &t1);
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 + 
1164                         sum.i * v2.r;
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;
1167 /* L80: */
1168             }
1169
1170 /*           Apply G from the right to transform the columns of the */
1171 /*           matrix in rows I1 to f2cmin(K+2,I). */
1172
1173 /* Computing MIN */
1174             i__4 = k + 2;
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;
1190                 d_cnjg(&z__3, &v2);
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;
1195 /* L90: */
1196             }
1197
1198             if (*wantz) {
1199
1200 /*              Accumulate transformations in the matrix Z */
1201
1202                 i__3 = *ihiz;
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 - 
1214                             sum.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;
1218                     d_cnjg(&z__3, &v2);
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 - 
1222                             z__2.i;
1223                     z__[i__4].r = z__1.r, z__[i__4].i = z__1.i;
1224 /* L100: */
1225                 }
1226             }
1227
1228             if (k == m && m > l) {
1229
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 */
1233 /*              real. */
1234
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;
1246                 if (m + 2 <= 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 * 
1251                             temp.r;
1252                     h__[i__3].r = z__1.r, h__[i__3].i = z__1.i;
1253                 }
1254                 i__3 = i__;
1255                 for (j = m; j <= i__3; ++j) {
1256                     if (j != m + 1) {
1257                         if (i2 > j) {
1258                             i__4 = i2 - j;
1259                             zscal_(&i__4, &temp, &h__[j + (j + 1) * h_dim1], 
1260                                     ldh);
1261                         }
1262                         i__4 = j - i1;
1263                         d_cnjg(&z__1, &temp);
1264                         zscal_(&i__4, &z__1, &h__[i1 + j * h_dim1], &c__1);
1265                         if (*wantz) {
1266                             d_cnjg(&z__1, &temp);
1267                             zscal_(&nz, &z__1, &z__[*iloz + j * z_dim1], &
1268                                     c__1);
1269                         }
1270                     }
1271 /* L110: */
1272                 }
1273             }
1274 /* L120: */
1275         }
1276
1277 /*        Ensure that H(I,I-1) is real. */
1278
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;
1287             if (i2 > i__) {
1288                 i__2 = i2 - i__;
1289                 d_cnjg(&z__1, &temp);
1290                 zscal_(&i__2, &z__1, &h__[i__ + (i__ + 1) * h_dim1], ldh);
1291             }
1292             i__2 = i__ - i1;
1293             zscal_(&i__2, &temp, &h__[i1 + i__ * h_dim1], &c__1);
1294             if (*wantz) {
1295                 zscal_(&nz, &temp, &z__[*iloz + i__ * z_dim1], &c__1);
1296             }
1297         }
1298
1299 /* L130: */
1300     }
1301
1302 /*     Failure to converge in remaining number of iterations */
1303
1304     *info = i__;
1305     return 0;
1306
1307 L140:
1308
1309 /*     H(I,I-1) is negligible: one eigenvalue has converged. */
1310
1311     i__1 = i__;
1312     i__2 = i__ + i__ * h_dim1;
1313     w[i__1].r = h__[i__2].r, w[i__1].i = h__[i__2].i;
1314
1315 /*     return to start of the main loop with new value of I. */
1316
1317     i__ = l - 1;
1318     goto L30;
1319
1320 L150:
1321     return 0;
1322
1323 /*     End of ZLAHQR */
1324
1325 } /* zlahqr_ */
1326