C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / clahqr.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]/df(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(_Fcomplex x, integer n) {
296         _Fcomplex pow={1.0,0.0}; unsigned long int u;
297                 if(n != 0) {
298                 if(n < 0) n = -n, x._Val[0] = 1./x._Val[0], x._Val[1]=1./x._Val[1];
299                 for(u = n; ; ) {
300                         if(u & 01) pow = _FCmulcc (pow,x);
301                         if(u >>= 1) x = _FCmulcc (x,x);
302                         else break;
303                 }
304         }
305         return pow;
306 }
307 #else
308 static _Complex float cpow_ui(_Complex float x, integer n) {
309         _Complex float pow=1.0; unsigned long int u;
310         if(n != 0) {
311                 if(n < 0) n = -n, x = 1/x;
312                 for(u = n; ; ) {
313                         if(u & 01) pow *= x;
314                         if(u >>= 1) x *= x;
315                         else break;
316                 }
317         }
318         return pow;
319 }
320 #endif
321 #ifdef _MSC_VER
322 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
323         _Dcomplex pow={1.0,0.0}; unsigned long int u;
324         if(n != 0) {
325                 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
326                 for(u = n; ; ) {
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];
329                         else break;
330                 }
331         }
332         _Dcomplex p = {pow._Val[0], pow._Val[1]};
333         return p;
334 }
335 #else
336 static _Complex double zpow_ui(_Complex double x, integer n) {
337         _Complex double pow=1.0; unsigned long int u;
338         if(n != 0) {
339                 if(n < 0) n = -n, x = 1/x;
340                 for(u = n; ; ) {
341                         if(u & 01) pow *= x;
342                         if(u >>= 1) x *= x;
343                         else break;
344                 }
345         }
346         return pow;
347 }
348 #endif
349 static integer pow_ii(integer x, integer n) {
350         integer pow; unsigned long int u;
351         if (n <= 0) {
352                 if (n == 0 || x == 1) pow = 1;
353                 else if (x != -1) pow = x == 0 ? 1/x : 0;
354                 else n = -n;
355         }
356         if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
357                 u = n;
358                 for(pow = 1; ; ) {
359                         if(u & 01) pow *= x;
360                         if(u >>= 1) x *= x;
361                         else break;
362                 }
363         }
364         return pow;
365 }
366 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
367 {
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];
371         return mi-s+1;
372 }
373 static integer smaxloc_(float *w, integer s, integer e, integer *n)
374 {
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];
378         return mi-s+1;
379 }
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;
382 #ifdef _MSC_VER
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];
388                 }
389         } else {
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];
393                 }
394         }
395         pCf(z) = zdotc;
396 }
397 #else
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]);
402                 }
403         } else {
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]);
406                 }
407         }
408         pCf(z) = zdotc;
409 }
410 #endif
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;
413 #ifdef _MSC_VER
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];
419                 }
420         } else {
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];
424                 }
425         }
426         pCd(z) = zdotc;
427 }
428 #else
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]);
433                 }
434         } else {
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]);
437                 }
438         }
439         pCd(z) = zdotc;
440 }
441 #endif  
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;
444 #ifdef _MSC_VER
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];
450                 }
451         } else {
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];
455                 }
456         }
457         pCf(z) = zdotc;
458 }
459 #else
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]);
464                 }
465         } else {
466                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
467                         zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
468                 }
469         }
470         pCf(z) = zdotc;
471 }
472 #endif
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;
475 #ifdef _MSC_VER
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];
481                 }
482         } else {
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];
486                 }
487         }
488         pCd(z) = zdotc;
489 }
490 #else
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]);
495                 }
496         } else {
497                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
498                         zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
499                 }
500         }
501         pCd(z) = zdotc;
502 }
503 #endif
504 /*  -- translated by f2c (version 20000121).
505    You must link the resulting object file with the libraries:
506         -lf2c -lm   (in that order)
507 */
508
509
510
511
512 /* Table of constant values */
513
514 static integer c__1 = 1;
515 static integer c__2 = 2;
516
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. */
519
520 /*  =========== DOCUMENTATION =========== */
521
522 /* Online html documentation available at */
523 /*            http://www.netlib.org/lapack/explore-html/ */
524
525 /* > \htmlonly */
526 /* > Download CLAHQR + dependencies */
527 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clahqr.
528 f"> */
529 /* > [TGZ]</a> */
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clahqr.
531 f"> */
532 /* > [ZIP]</a> */
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clahqr.
534 f"> */
535 /* > [TXT]</a> */
536 /* > \endhtmlonly */
537
538 /*  Definition: */
539 /*  =========== */
540
541 /*       SUBROUTINE CLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ, */
542 /*                          IHIZ, Z, LDZ, INFO ) */
543
544 /*       INTEGER            IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, N */
545 /*       LOGICAL            WANTT, WANTZ */
546 /*       COMPLEX            H( LDH, * ), W( * ), Z( LDZ, * ) */
547
548
549 /* > \par Purpose: */
550 /*  ============= */
551 /* > */
552 /* > \verbatim */
553 /* > */
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 */
557 /* >    IHI. */
558 /* > \endverbatim */
559
560 /*  Arguments: */
561 /*  ========== */
562
563 /* > \param[in] WANTT */
564 /* > \verbatim */
565 /* >          WANTT is LOGICAL */
566 /* >          = .TRUE. : the full Schur form T is required; */
567 /* >          = .FALSE.: only eigenvalues are required. */
568 /* > \endverbatim */
569 /* > */
570 /* > \param[in] WANTZ */
571 /* > \verbatim */
572 /* >          WANTZ is LOGICAL */
573 /* >          = .TRUE. : the matrix of Schur vectors Z is required; */
574 /* >          = .FALSE.: Schur vectors are not required. */
575 /* > \endverbatim */
576 /* > */
577 /* > \param[in] N */
578 /* > \verbatim */
579 /* >          N is INTEGER */
580 /* >          The order of the matrix H.  N >= 0. */
581 /* > \endverbatim */
582 /* > */
583 /* > \param[in] ILO */
584 /* > \verbatim */
585 /* >          ILO is INTEGER */
586 /* > \endverbatim */
587 /* > */
588 /* > \param[in] IHI */
589 /* > \verbatim */
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. */
597 /* > \endverbatim */
598 /* > */
599 /* > \param[in,out] H */
600 /* > \verbatim */
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. */
608 /* > \endverbatim */
609 /* > */
610 /* > \param[in] LDH */
611 /* > \verbatim */
612 /* >          LDH is INTEGER */
613 /* >          The leading dimension of the array H. LDH >= f2cmax(1,N). */
614 /* > \endverbatim */
615 /* > */
616 /* > \param[out] W */
617 /* > \verbatim */
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). */
623 /* > \endverbatim */
624 /* > */
625 /* > \param[in] ILOZ */
626 /* > \verbatim */
627 /* >          ILOZ is INTEGER */
628 /* > \endverbatim */
629 /* > */
630 /* > \param[in] IHIZ */
631 /* > \verbatim */
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. */
636 /* > \endverbatim */
637 /* > */
638 /* > \param[in,out] Z */
639 /* > \verbatim */
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. */
646 /* > \endverbatim */
647 /* > */
648 /* > \param[in] LDZ */
649 /* > \verbatim */
650 /* >          LDZ is INTEGER */
651 /* >          The leading dimension of the array Z. LDZ >= f2cmax(1,N). */
652 /* > \endverbatim */
653 /* > */
654 /* > \param[out] INFO */
655 /* > \verbatim */
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 */
662 /* >                  computed. */
663 /* > */
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. */
669 /* > */
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. */
675 /* > */
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.) */
680 /* > \endverbatim */
681
682 /*  Authors: */
683 /*  ======== */
684
685 /* > \author Univ. of Tennessee */
686 /* > \author Univ. of California Berkeley */
687 /* > \author Univ. of Colorado Denver */
688 /* > \author NAG Ltd. */
689
690 /* > \date December 2016 */
691
692 /* > \ingroup complexOTHERauxiliary */
693
694 /* > \par Contributors: */
695 /*  ================== */
696 /* > */
697 /* > \verbatim */
698 /* > */
699 /* >     02-96 Based on modifications by */
700 /* >     David Day, Sandia National Laboratory, USA */
701 /* > */
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). */
708 /* > \endverbatim */
709 /* > */
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 *
714         info)
715 {
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;
720
721     /* Local variables */
722     complex temp;
723     integer i__, j, k, l, m;
724     real s;
725     complex t, u, v[2], x, y;
726     extern /* Subroutine */ int cscal_(integer *, complex *, complex *, 
727             integer *), ccopy_(integer *, complex *, integer *, complex *, 
728             integer *);
729     integer itmax;
730     real rtemp;
731     integer i1, i2;
732     complex t1;
733     real t2;
734     complex v2;
735     real aa, ab, ba, bb, h10;
736     complex h11;
737     real h21;
738     complex h22, sc;
739     integer nh;
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 *);
744     integer nz;
745     real sx, safmin, safmax, smlnum;
746     integer jhi;
747     complex h11s;
748     integer jlo, its;
749     real ulp;
750     complex sum;
751     real tst;
752
753
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..-- */
757 /*     December 2016 */
758
759
760 /*  ========================================================= */
761
762
763     /* Parameter adjustments */
764     h_dim1 = *ldh;
765     h_offset = 1 + h_dim1 * 1;
766     h__ -= h_offset;
767     --w;
768     z_dim1 = *ldz;
769     z_offset = 1 + z_dim1 * 1;
770     z__ -= z_offset;
771
772     /* Function Body */
773     *info = 0;
774
775 /*     Quick return if possible */
776
777     if (*n == 0) {
778         return 0;
779     }
780     if (*ilo == *ihi) {
781         i__1 = *ilo;
782         i__2 = *ilo + *ilo * h_dim1;
783         w[i__1].r = h__[i__2].r, w[i__1].i = h__[i__2].i;
784         return 0;
785     }
786
787 /*     ==== clear out the trash ==== */
788     i__1 = *ihi - 3;
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;
794 /* L10: */
795     }
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;
799     }
800 /*     ==== ensure that subdiagonal entries are real ==== */
801     if (*wantt) {
802         jlo = 1;
803         jhi = *n;
804     } else {
805         jlo = *ilo;
806         jhi = *ihi;
807     }
808     i__1 = *ihi;
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;
820             r_cnjg(&q__2, &sc);
821             r__1 = c_abs(&sc);
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);
829 /* Computing MIN */
830             i__3 = jhi, i__4 = i__ + 1;
831             i__2 = f2cmin(i__3,i__4) - jlo + 1;
832             r_cnjg(&q__1, &sc);
833             cscal_(&i__2, &q__1, &h__[jlo + i__ * h_dim1], &c__1);
834             if (*wantz) {
835                 i__2 = *ihiz - *iloz + 1;
836                 r_cnjg(&q__1, &sc);
837                 cscal_(&i__2, &q__1, &z__[*iloz + i__ * z_dim1], &c__1);
838             }
839         }
840 /* L20: */
841     }
842
843     nh = *ihi - *ilo + 1;
844     nz = *ihiz - *iloz + 1;
845
846 /*     Set machine-dependent constants for the stopping criterion. */
847
848     safmin = slamch_("SAFE MINIMUM");
849     safmax = 1.f / safmin;
850     slabad_(&safmin, &safmax);
851     ulp = slamch_("PRECISION");
852     smlnum = safmin * ((real) nh / ulp);
853
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. */
857
858     if (*wantt) {
859         i1 = 1;
860         i2 = *n;
861     }
862
863 /*     ITMAX is the total number of QR iterations allowed. */
864
865     itmax = f2cmax(10,nh) * 30;
866
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. */
872
873     i__ = *ihi;
874 L30:
875     if (i__ < *ilo) {
876         goto L150;
877     }
878
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. */
882
883     l = *ilo;
884     i__1 = itmax;
885     for (its = 0; its <= i__1; ++its) {
886
887 /*        Look for a single small subdiagonal element. */
888
889         i__2 = l + 1;
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) {
894                 goto L50;
895             }
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(
901                     r__4)));
902             if (tst == 0.f) {
903                 if (k - 2 >= *ilo) {
904                     i__3 = k - 1 + (k - 2) * h_dim1;
905                     tst += (r__1 = h__[i__3].r, abs(r__1));
906                 }
907                 if (k + 1 <= *ihi) {
908                     i__3 = k + 1 + k * h_dim1;
909                     tst += (r__1 = h__[i__3].r, abs(r__1));
910                 }
911             }
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) {
918 /* Computing MAX */
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);
926 /* Computing MIN */
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 - 
937                         h__[i__4].i;
938                 q__1.r = q__2.r, q__1.i = q__2.i;
939 /* Computing MAX */
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 - 
948                         h__[i__4].i;
949                 q__1.r = q__2.r, q__1.i = q__2.i;
950 /* Computing MIN */
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);
956                 s = aa + ab;
957 /* Computing MAX */
958                 r__1 = smlnum, r__2 = ulp * (bb * (aa / s));
959                 if (ba * (ab / s) <= f2cmax(r__1,r__2)) {
960                     goto L50;
961                 }
962             }
963 /* L40: */
964         }
965 L50:
966         l = k;
967         if (l > *ilo) {
968
969 /*           H(L,L-1) is negligible */
970
971             i__2 = l + (l - 1) * h_dim1;
972             h__[i__2].r = 0.f, h__[i__2].i = 0.f;
973         }
974
975 /*        Exit from loop if a submatrix of order 1 has split off. */
976
977         if (l >= i__) {
978             goto L140;
979         }
980
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. */
984
985         if (! (*wantt)) {
986             i1 = l;
987             i2 = i__;
988         }
989
990         if (its == 10) {
991
992 /*           Exceptional shift. */
993
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) {
1000
1001 /*           Exceptional shift. */
1002
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;
1008         } else {
1009
1010 /*           Wilkinson's shift. */
1011
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));
1020             if (s != 0.f) {
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));
1026 /* Computing MAX */
1027                 r__3 = s, r__4 = (r__1 = x.r, abs(r__1)) + (r__2 = r_imag(&x),
1028                          abs(r__2));
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;
1038                 if (sx > 0.f) {
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;
1044                     }
1045                 }
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 + 
1049                         u.i * q__3.r;
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;
1052             }
1053         }
1054
1055 /*        Look for two consecutive small subdiagonal elements. */
1056
1057         i__2 = l + 1;
1058         for (m = i__ - 1; m >= i__2; --m) {
1059
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) */
1062 /*           negligible. */
1063
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;
1071             h21 = h__[i__3].r;
1072             s = (r__1 = h11s.r, abs(r__1)) + (r__2 = r_imag(&h11s), abs(r__2))
1073                      + abs(h21);
1074             q__1.r = h11s.r / s, q__1.i = h11s.i / s;
1075             h11s.r = q__1.r, h11s.i = q__1.i;
1076             h21 /= s;
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;
1080             h10 = h__[i__3].r;
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)))))) {
1085                 goto L70;
1086             }
1087 /* L60: */
1088         }
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;
1096         h21 = h__[i__2].r;
1097         s = (r__1 = h11s.r, abs(r__1)) + (r__2 = r_imag(&h11s), abs(r__2)) + 
1098                 abs(h21);
1099         q__1.r = h11s.r / s, q__1.i = h11s.i / s;
1100         h11s.r = q__1.r, h11s.i = q__1.i;
1101         h21 /= s;
1102         v[0].r = h11s.r, v[0].i = h11s.i;
1103         v[1].r = h21, v[1].i = 0.f;
1104 L70:
1105
1106 /*        Single-shift QR step */
1107
1108         i__2 = i__ - 1;
1109         for (k = m; k <= i__2; ++k) {
1110
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. */
1114
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 */
1118 /*           submatrix. */
1119
1120 /*           V(2) is always real before the call to CLARFG, and hence */
1121 /*           after the call T2 ( = T1*V(2) ) is also real. */
1122
1123             if (k > m) {
1124                 ccopy_(&c__2, &h__[k + (k - 1) * h_dim1], &c__1, v, &c__1);
1125             }
1126             clarfg_(&c__2, v, &v[1], &c__1, &t1);
1127             if (k > m) {
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;
1132             }
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 * 
1135                     v2.r;
1136             t2 = q__1.r;
1137
1138 /*           Apply G from the left to transform the rows of the matrix */
1139 /*           in columns K to I2. */
1140
1141             i__3 = i2;
1142             for (j = k; j <= i__3; ++j) {
1143                 r_cnjg(&q__3, &t1);
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 + 
1158                         sum.i * v2.r;
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;
1161 /* L80: */
1162             }
1163
1164 /*           Apply G from the right to transform the columns of the */
1165 /*           matrix in rows I1 to f2cmin(K+2,I). */
1166
1167 /* Computing MIN */
1168             i__4 = k + 2;
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;
1184                 r_cnjg(&q__3, &v2);
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;
1189 /* L90: */
1190             }
1191
1192             if (*wantz) {
1193
1194 /*              Accumulate transformations in the matrix Z */
1195
1196                 i__3 = *ihiz;
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 - 
1208                             sum.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;
1212                     r_cnjg(&q__3, &v2);
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 - 
1216                             q__2.i;
1217                     z__[i__4].r = q__1.r, z__[i__4].i = q__1.i;
1218 /* L100: */
1219                 }
1220             }
1221
1222             if (k == m && m > l) {
1223
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 */
1227 /*              real. */
1228
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;
1240                 if (m + 2 <= 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 * 
1245                             temp.r;
1246                     h__[i__3].r = q__1.r, h__[i__3].i = q__1.i;
1247                 }
1248                 i__3 = i__;
1249                 for (j = m; j <= i__3; ++j) {
1250                     if (j != m + 1) {
1251                         if (i2 > j) {
1252                             i__4 = i2 - j;
1253                             cscal_(&i__4, &temp, &h__[j + (j + 1) * h_dim1], 
1254                                     ldh);
1255                         }
1256                         i__4 = j - i1;
1257                         r_cnjg(&q__1, &temp);
1258                         cscal_(&i__4, &q__1, &h__[i1 + j * h_dim1], &c__1);
1259                         if (*wantz) {
1260                             r_cnjg(&q__1, &temp);
1261                             cscal_(&nz, &q__1, &z__[*iloz + j * z_dim1], &
1262                                     c__1);
1263                         }
1264                     }
1265 /* L110: */
1266                 }
1267             }
1268 /* L120: */
1269         }
1270
1271 /*        Ensure that H(I,I-1) is real. */
1272
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;
1281             if (i2 > i__) {
1282                 i__2 = i2 - i__;
1283                 r_cnjg(&q__1, &temp);
1284                 cscal_(&i__2, &q__1, &h__[i__ + (i__ + 1) * h_dim1], ldh);
1285             }
1286             i__2 = i__ - i1;
1287             cscal_(&i__2, &temp, &h__[i1 + i__ * h_dim1], &c__1);
1288             if (*wantz) {
1289                 cscal_(&nz, &temp, &z__[*iloz + i__ * z_dim1], &c__1);
1290             }
1291         }
1292
1293 /* L130: */
1294     }
1295
1296 /*     Failure to converge in remaining number of iterations */
1297
1298     *info = i__;
1299     return 0;
1300
1301 L140:
1302
1303 /*     H(I,I-1) is negligible: one eigenvalue has converged. */
1304
1305     i__1 = i__;
1306     i__2 = i__ + i__ * h_dim1;
1307     w[i__1].r = h__[i__2].r, w[i__1].i = h__[i__2].i;
1308
1309 /*     return to start of the main loop with new value of I. */
1310
1311     i__ = l - 1;
1312     goto L30;
1313
1314 L150:
1315     return 0;
1316
1317 /*     End of CLAHQR */
1318
1319 } /* clahqr_ */
1320