C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / zhgeqz.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
514 /* Table of constant values */
515
516 static doublecomplex c_b1 = {0.,0.};
517 static doublecomplex c_b2 = {1.,0.};
518 static integer c__1 = 1;
519 static integer c__2 = 2;
520
521 /* > \brief \b ZHGEQZ */
522
523 /*  =========== DOCUMENTATION =========== */
524
525 /* Online html documentation available at */
526 /*            http://www.netlib.org/lapack/explore-html/ */
527
528 /* > \htmlonly */
529 /* > Download ZHGEQZ + dependencies */
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhgeqz.
531 f"> */
532 /* > [TGZ]</a> */
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhgeqz.
534 f"> */
535 /* > [ZIP]</a> */
536 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhgeqz.
537 f"> */
538 /* > [TXT]</a> */
539 /* > \endhtmlonly */
540
541 /*  Definition: */
542 /*  =========== */
543
544 /*       SUBROUTINE ZHGEQZ( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT, */
545 /*                          ALPHA, BETA, Q, LDQ, Z, LDZ, WORK, LWORK, */
546 /*                          RWORK, INFO ) */
547
548 /*       CHARACTER          COMPQ, COMPZ, JOB */
549 /*       INTEGER            IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N */
550 /*       DOUBLE PRECISION   RWORK( * ) */
551 /*       COMPLEX*16         ALPHA( * ), BETA( * ), H( LDH, * ), */
552 /*      $                   Q( LDQ, * ), T( LDT, * ), WORK( * ), */
553 /*      $                   Z( LDZ, * ) */
554
555
556 /* > \par Purpose: */
557 /*  ============= */
558 /* > */
559 /* > \verbatim */
560 /* > */
561 /* > ZHGEQZ computes the eigenvalues of a complex matrix pair (H,T), */
562 /* > where H is an upper Hessenberg matrix and T is upper triangular, */
563 /* > using the single-shift QZ method. */
564 /* > Matrix pairs of this type are produced by the reduction to */
565 /* > generalized upper Hessenberg form of a complex matrix pair (A,B): */
566 /* > */
567 /* >    A = Q1*H*Z1**H,  B = Q1*T*Z1**H, */
568 /* > */
569 /* > as computed by ZGGHRD. */
570 /* > */
571 /* > If JOB='S', then the Hessenberg-triangular pair (H,T) is */
572 /* > also reduced to generalized Schur form, */
573 /* > */
574 /* >    H = Q*S*Z**H,  T = Q*P*Z**H, */
575 /* > */
576 /* > where Q and Z are unitary matrices and S and P are upper triangular. */
577 /* > */
578 /* > Optionally, the unitary matrix Q from the generalized Schur */
579 /* > factorization may be postmultiplied into an input matrix Q1, and the */
580 /* > unitary matrix Z may be postmultiplied into an input matrix Z1. */
581 /* > If Q1 and Z1 are the unitary matrices from ZGGHRD that reduced */
582 /* > the matrix pair (A,B) to generalized Hessenberg form, then the output */
583 /* > matrices Q1*Q and Z1*Z are the unitary factors from the generalized */
584 /* > Schur factorization of (A,B): */
585 /* > */
586 /* >    A = (Q1*Q)*S*(Z1*Z)**H,  B = (Q1*Q)*P*(Z1*Z)**H. */
587 /* > */
588 /* > To avoid overflow, eigenvalues of the matrix pair (H,T) */
589 /* > (equivalently, of (A,B)) are computed as a pair of complex values */
590 /* > (alpha,beta).  If beta is nonzero, lambda = alpha / beta is an */
591 /* > eigenvalue of the generalized nonsymmetric eigenvalue problem (GNEP) */
592 /* >    A*x = lambda*B*x */
593 /* > and if alpha is nonzero, mu = beta / alpha is an eigenvalue of the */
594 /* > alternate form of the GNEP */
595 /* >    mu*A*y = B*y. */
596 /* > The values of alpha and beta for the i-th eigenvalue can be read */
597 /* > directly from the generalized Schur form:  alpha = S(i,i), */
598 /* > beta = P(i,i). */
599 /* > */
600 /* > Ref: C.B. Moler & G.W. Stewart, "An Algorithm for Generalized Matrix */
601 /* >      Eigenvalue Problems", SIAM J. Numer. Anal., 10(1973), */
602 /* >      pp. 241--256. */
603 /* > \endverbatim */
604
605 /*  Arguments: */
606 /*  ========== */
607
608 /* > \param[in] JOB */
609 /* > \verbatim */
610 /* >          JOB is CHARACTER*1 */
611 /* >          = 'E': Compute eigenvalues only; */
612 /* >          = 'S': Computer eigenvalues and the Schur form. */
613 /* > \endverbatim */
614 /* > */
615 /* > \param[in] COMPQ */
616 /* > \verbatim */
617 /* >          COMPQ is CHARACTER*1 */
618 /* >          = 'N': Left Schur vectors (Q) are not computed; */
619 /* >          = 'I': Q is initialized to the unit matrix and the matrix Q */
620 /* >                 of left Schur vectors of (H,T) is returned; */
621 /* >          = 'V': Q must contain a unitary matrix Q1 on entry and */
622 /* >                 the product Q1*Q is returned. */
623 /* > \endverbatim */
624 /* > */
625 /* > \param[in] COMPZ */
626 /* > \verbatim */
627 /* >          COMPZ is CHARACTER*1 */
628 /* >          = 'N': Right Schur vectors (Z) are not computed; */
629 /* >          = 'I': Q is initialized to the unit matrix and the matrix Z */
630 /* >                 of right Schur vectors of (H,T) is returned; */
631 /* >          = 'V': Z must contain a unitary matrix Z1 on entry and */
632 /* >                 the product Z1*Z is returned. */
633 /* > \endverbatim */
634 /* > */
635 /* > \param[in] N */
636 /* > \verbatim */
637 /* >          N is INTEGER */
638 /* >          The order of the matrices H, T, Q, and Z.  N >= 0. */
639 /* > \endverbatim */
640 /* > */
641 /* > \param[in] ILO */
642 /* > \verbatim */
643 /* >          ILO is INTEGER */
644 /* > \endverbatim */
645 /* > */
646 /* > \param[in] IHI */
647 /* > \verbatim */
648 /* >          IHI is INTEGER */
649 /* >          ILO and IHI mark the rows and columns of H which are in */
650 /* >          Hessenberg form.  It is assumed that A is already upper */
651 /* >          triangular in rows and columns 1:ILO-1 and IHI+1:N. */
652 /* >          If N > 0, 1 <= ILO <= IHI <= N; if N = 0, ILO=1 and IHI=0. */
653 /* > \endverbatim */
654 /* > */
655 /* > \param[in,out] H */
656 /* > \verbatim */
657 /* >          H is COMPLEX*16 array, dimension (LDH, N) */
658 /* >          On entry, the N-by-N upper Hessenberg matrix H. */
659 /* >          On exit, if JOB = 'S', H contains the upper triangular */
660 /* >          matrix S from the generalized Schur factorization. */
661 /* >          If JOB = 'E', the diagonal of H matches that of S, but */
662 /* >          the rest of H is unspecified. */
663 /* > \endverbatim */
664 /* > */
665 /* > \param[in] LDH */
666 /* > \verbatim */
667 /* >          LDH is INTEGER */
668 /* >          The leading dimension of the array H.  LDH >= f2cmax( 1, N ). */
669 /* > \endverbatim */
670 /* > */
671 /* > \param[in,out] T */
672 /* > \verbatim */
673 /* >          T is COMPLEX*16 array, dimension (LDT, N) */
674 /* >          On entry, the N-by-N upper triangular matrix T. */
675 /* >          On exit, if JOB = 'S', T contains the upper triangular */
676 /* >          matrix P from the generalized Schur factorization. */
677 /* >          If JOB = 'E', the diagonal of T matches that of P, but */
678 /* >          the rest of T is unspecified. */
679 /* > \endverbatim */
680 /* > */
681 /* > \param[in] LDT */
682 /* > \verbatim */
683 /* >          LDT is INTEGER */
684 /* >          The leading dimension of the array T.  LDT >= f2cmax( 1, N ). */
685 /* > \endverbatim */
686 /* > */
687 /* > \param[out] ALPHA */
688 /* > \verbatim */
689 /* >          ALPHA is COMPLEX*16 array, dimension (N) */
690 /* >          The complex scalars alpha that define the eigenvalues of */
691 /* >          GNEP.  ALPHA(i) = S(i,i) in the generalized Schur */
692 /* >          factorization. */
693 /* > \endverbatim */
694 /* > */
695 /* > \param[out] BETA */
696 /* > \verbatim */
697 /* >          BETA is COMPLEX*16 array, dimension (N) */
698 /* >          The real non-negative scalars beta that define the */
699 /* >          eigenvalues of GNEP.  BETA(i) = P(i,i) in the generalized */
700 /* >          Schur factorization. */
701 /* > */
702 /* >          Together, the quantities alpha = ALPHA(j) and beta = BETA(j) */
703 /* >          represent the j-th eigenvalue of the matrix pair (A,B), in */
704 /* >          one of the forms lambda = alpha/beta or mu = beta/alpha. */
705 /* >          Since either lambda or mu may overflow, they should not, */
706 /* >          in general, be computed. */
707 /* > \endverbatim */
708 /* > */
709 /* > \param[in,out] Q */
710 /* > \verbatim */
711 /* >          Q is COMPLEX*16 array, dimension (LDQ, N) */
712 /* >          On entry, if COMPQ = 'V', the unitary matrix Q1 used in the */
713 /* >          reduction of (A,B) to generalized Hessenberg form. */
714 /* >          On exit, if COMPQ = 'I', the unitary matrix of left Schur */
715 /* >          vectors of (H,T), and if COMPQ = 'V', the unitary matrix of */
716 /* >          left Schur vectors of (A,B). */
717 /* >          Not referenced if COMPQ = 'N'. */
718 /* > \endverbatim */
719 /* > */
720 /* > \param[in] LDQ */
721 /* > \verbatim */
722 /* >          LDQ is INTEGER */
723 /* >          The leading dimension of the array Q.  LDQ >= 1. */
724 /* >          If COMPQ='V' or 'I', then LDQ >= N. */
725 /* > \endverbatim */
726 /* > */
727 /* > \param[in,out] Z */
728 /* > \verbatim */
729 /* >          Z is COMPLEX*16 array, dimension (LDZ, N) */
730 /* >          On entry, if COMPZ = 'V', the unitary matrix Z1 used in the */
731 /* >          reduction of (A,B) to generalized Hessenberg form. */
732 /* >          On exit, if COMPZ = 'I', the unitary matrix of right Schur */
733 /* >          vectors of (H,T), and if COMPZ = 'V', the unitary matrix of */
734 /* >          right Schur vectors of (A,B). */
735 /* >          Not referenced if COMPZ = 'N'. */
736 /* > \endverbatim */
737 /* > */
738 /* > \param[in] LDZ */
739 /* > \verbatim */
740 /* >          LDZ is INTEGER */
741 /* >          The leading dimension of the array Z.  LDZ >= 1. */
742 /* >          If COMPZ='V' or 'I', then LDZ >= N. */
743 /* > \endverbatim */
744 /* > */
745 /* > \param[out] WORK */
746 /* > \verbatim */
747 /* >          WORK is COMPLEX*16 array, dimension (MAX(1,LWORK)) */
748 /* >          On exit, if INFO >= 0, WORK(1) returns the optimal LWORK. */
749 /* > \endverbatim */
750 /* > */
751 /* > \param[in] LWORK */
752 /* > \verbatim */
753 /* >          LWORK is INTEGER */
754 /* >          The dimension of the array WORK.  LWORK >= f2cmax(1,N). */
755 /* > */
756 /* >          If LWORK = -1, then a workspace query is assumed; the routine */
757 /* >          only calculates the optimal size of the WORK array, returns */
758 /* >          this value as the first entry of the WORK array, and no error */
759 /* >          message related to LWORK is issued by XERBLA. */
760 /* > \endverbatim */
761 /* > */
762 /* > \param[out] RWORK */
763 /* > \verbatim */
764 /* >          RWORK is DOUBLE PRECISION array, dimension (N) */
765 /* > \endverbatim */
766 /* > */
767 /* > \param[out] INFO */
768 /* > \verbatim */
769 /* >          INFO is INTEGER */
770 /* >          = 0: successful exit */
771 /* >          < 0: if INFO = -i, the i-th argument had an illegal value */
772 /* >          = 1,...,N: the QZ iteration did not converge.  (H,T) is not */
773 /* >                     in Schur form, but ALPHA(i) and BETA(i), */
774 /* >                     i=INFO+1,...,N should be correct. */
775 /* >          = N+1,...,2*N: the shift calculation failed.  (H,T) is not */
776 /* >                     in Schur form, but ALPHA(i) and BETA(i), */
777 /* >                     i=INFO-N+1,...,N should be correct. */
778 /* > \endverbatim */
779
780 /*  Authors: */
781 /*  ======== */
782
783 /* > \author Univ. of Tennessee */
784 /* > \author Univ. of California Berkeley */
785 /* > \author Univ. of Colorado Denver */
786 /* > \author NAG Ltd. */
787
788 /* > \date April 2012 */
789
790 /* > \ingroup complex16GEcomputational */
791
792 /* > \par Further Details: */
793 /*  ===================== */
794 /* > */
795 /* > \verbatim */
796 /* > */
797 /* >  We assume that complex ABS works as long as its value is less than */
798 /* >  overflow. */
799 /* > \endverbatim */
800 /* > */
801 /*  ===================================================================== */
802 /* Subroutine */ int zhgeqz_(char *job, char *compq, char *compz, integer *n, 
803         integer *ilo, integer *ihi, doublecomplex *h__, integer *ldh, 
804         doublecomplex *t, integer *ldt, doublecomplex *alpha, doublecomplex *
805         beta, doublecomplex *q, integer *ldq, doublecomplex *z__, integer *
806         ldz, doublecomplex *work, integer *lwork, doublereal *rwork, integer *
807         info)
808 {
809     /* System generated locals */
810     integer h_dim1, h_offset, q_dim1, q_offset, t_dim1, t_offset, z_dim1, 
811             z_offset, i__1, i__2, i__3, i__4, i__5, i__6;
812     doublereal d__1, d__2, d__3, d__4, d__5, d__6;
813     doublecomplex z__1, z__2, z__3, z__4, z__5, z__6, z__7;
814
815     /* Local variables */
816     doublereal absb, atol, btol, temp;
817     extern /* Subroutine */ int zrot_(integer *, doublecomplex *, integer *, 
818             doublecomplex *, integer *, doublereal *, doublecomplex *);
819     doublereal temp2, c__;
820     integer j;
821     doublecomplex s, x, y;
822     extern logical lsame_(char *, char *);
823     doublecomplex ctemp;
824     integer iiter, ilast, jiter;
825     doublereal anorm, bnorm;
826     integer maxit;
827     doublecomplex shift;
828     extern /* Subroutine */ int zscal_(integer *, doublecomplex *, 
829             doublecomplex *, integer *);
830     doublereal tempr;
831     doublecomplex ctemp2, ctemp3;
832     logical ilazr2;
833     integer jc, in;
834     doublereal ascale, bscale;
835     doublecomplex u12;
836     extern doublereal dlamch_(char *);
837     integer jr;
838     doublecomplex signbc;
839     doublereal safmin;
840     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
841     doublecomplex eshift;
842     logical ilschr;
843     integer icompq, ilastm;
844     extern /* Double Complex */ VOID zladiv_(doublecomplex *, doublecomplex *,
845              doublecomplex *);
846     integer ischur;
847     extern doublereal zlanhs_(char *, integer *, doublecomplex *, integer *, 
848             doublereal *);
849     logical ilazro;
850     integer icompz, ifirst;
851     extern /* Subroutine */ int zlartg_(doublecomplex *, doublecomplex *, 
852             doublereal *, doublecomplex *, doublecomplex *);
853     integer ifrstm;
854     extern /* Subroutine */ int zlaset_(char *, integer *, integer *, 
855             doublecomplex *, doublecomplex *, doublecomplex *, integer *);
856     integer istart;
857     logical lquery;
858     doublecomplex ad11, ad12, ad21, ad22;
859     integer jch;
860     logical ilq, ilz;
861     doublereal ulp;
862     doublecomplex abi12, abi22;
863
864
865 /*  -- LAPACK computational routine (version 3.7.0) -- */
866 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
867 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
868 /*     April 2012 */
869
870
871 /*  ===================================================================== */
872
873
874 /*     Decode JOB, COMPQ, COMPZ */
875
876     /* Parameter adjustments */
877     h_dim1 = *ldh;
878     h_offset = 1 + h_dim1 * 1;
879     h__ -= h_offset;
880     t_dim1 = *ldt;
881     t_offset = 1 + t_dim1 * 1;
882     t -= t_offset;
883     --alpha;
884     --beta;
885     q_dim1 = *ldq;
886     q_offset = 1 + q_dim1 * 1;
887     q -= q_offset;
888     z_dim1 = *ldz;
889     z_offset = 1 + z_dim1 * 1;
890     z__ -= z_offset;
891     --work;
892     --rwork;
893
894     /* Function Body */
895     if (lsame_(job, "E")) {
896         ilschr = FALSE_;
897         ischur = 1;
898     } else if (lsame_(job, "S")) {
899         ilschr = TRUE_;
900         ischur = 2;
901     } else {
902         ilschr = TRUE_;
903         ischur = 0;
904     }
905
906     if (lsame_(compq, "N")) {
907         ilq = FALSE_;
908         icompq = 1;
909     } else if (lsame_(compq, "V")) {
910         ilq = TRUE_;
911         icompq = 2;
912     } else if (lsame_(compq, "I")) {
913         ilq = TRUE_;
914         icompq = 3;
915     } else {
916         ilq = TRUE_;
917         icompq = 0;
918     }
919
920     if (lsame_(compz, "N")) {
921         ilz = FALSE_;
922         icompz = 1;
923     } else if (lsame_(compz, "V")) {
924         ilz = TRUE_;
925         icompz = 2;
926     } else if (lsame_(compz, "I")) {
927         ilz = TRUE_;
928         icompz = 3;
929     } else {
930         ilz = TRUE_;
931         icompz = 0;
932     }
933
934 /*     Check Argument Values */
935
936     *info = 0;
937     i__1 = f2cmax(1,*n);
938     work[1].r = (doublereal) i__1, work[1].i = 0.;
939     lquery = *lwork == -1;
940     if (ischur == 0) {
941         *info = -1;
942     } else if (icompq == 0) {
943         *info = -2;
944     } else if (icompz == 0) {
945         *info = -3;
946     } else if (*n < 0) {
947         *info = -4;
948     } else if (*ilo < 1) {
949         *info = -5;
950     } else if (*ihi > *n || *ihi < *ilo - 1) {
951         *info = -6;
952     } else if (*ldh < *n) {
953         *info = -8;
954     } else if (*ldt < *n) {
955         *info = -10;
956     } else if (*ldq < 1 || ilq && *ldq < *n) {
957         *info = -14;
958     } else if (*ldz < 1 || ilz && *ldz < *n) {
959         *info = -16;
960     } else if (*lwork < f2cmax(1,*n) && ! lquery) {
961         *info = -18;
962     }
963     if (*info != 0) {
964         i__1 = -(*info);
965         xerbla_("ZHGEQZ", &i__1, (ftnlen)6);
966         return 0;
967     } else if (lquery) {
968         return 0;
969     }
970
971 /*     Quick return if possible */
972
973 /*     WORK( 1 ) = CMPLX( 1 ) */
974     if (*n <= 0) {
975         work[1].r = 1., work[1].i = 0.;
976         return 0;
977     }
978
979 /*     Initialize Q and Z */
980
981     if (icompq == 3) {
982         zlaset_("Full", n, n, &c_b1, &c_b2, &q[q_offset], ldq);
983     }
984     if (icompz == 3) {
985         zlaset_("Full", n, n, &c_b1, &c_b2, &z__[z_offset], ldz);
986     }
987
988 /*     Machine Constants */
989
990     in = *ihi + 1 - *ilo;
991     safmin = dlamch_("S");
992     ulp = dlamch_("E") * dlamch_("B");
993     anorm = zlanhs_("F", &in, &h__[*ilo + *ilo * h_dim1], ldh, &rwork[1]);
994     bnorm = zlanhs_("F", &in, &t[*ilo + *ilo * t_dim1], ldt, &rwork[1]);
995 /* Computing MAX */
996     d__1 = safmin, d__2 = ulp * anorm;
997     atol = f2cmax(d__1,d__2);
998 /* Computing MAX */
999     d__1 = safmin, d__2 = ulp * bnorm;
1000     btol = f2cmax(d__1,d__2);
1001     ascale = 1. / f2cmax(safmin,anorm);
1002     bscale = 1. / f2cmax(safmin,bnorm);
1003
1004
1005 /*     Set Eigenvalues IHI+1:N */
1006
1007     i__1 = *n;
1008     for (j = *ihi + 1; j <= i__1; ++j) {
1009         absb = z_abs(&t[j + j * t_dim1]);
1010         if (absb > safmin) {
1011             i__2 = j + j * t_dim1;
1012             z__2.r = t[i__2].r / absb, z__2.i = t[i__2].i / absb;
1013             d_cnjg(&z__1, &z__2);
1014             signbc.r = z__1.r, signbc.i = z__1.i;
1015             i__2 = j + j * t_dim1;
1016             t[i__2].r = absb, t[i__2].i = 0.;
1017             if (ilschr) {
1018                 i__2 = j - 1;
1019                 zscal_(&i__2, &signbc, &t[j * t_dim1 + 1], &c__1);
1020                 zscal_(&j, &signbc, &h__[j * h_dim1 + 1], &c__1);
1021             } else {
1022                 zscal_(&c__1, &signbc, &h__[j + j * h_dim1], &c__1);
1023             }
1024             if (ilz) {
1025                 zscal_(n, &signbc, &z__[j * z_dim1 + 1], &c__1);
1026             }
1027         } else {
1028             i__2 = j + j * t_dim1;
1029             t[i__2].r = 0., t[i__2].i = 0.;
1030         }
1031         i__2 = j;
1032         i__3 = j + j * h_dim1;
1033         alpha[i__2].r = h__[i__3].r, alpha[i__2].i = h__[i__3].i;
1034         i__2 = j;
1035         i__3 = j + j * t_dim1;
1036         beta[i__2].r = t[i__3].r, beta[i__2].i = t[i__3].i;
1037 /* L10: */
1038     }
1039
1040 /*     If IHI < ILO, skip QZ steps */
1041
1042     if (*ihi < *ilo) {
1043         goto L190;
1044     }
1045
1046 /*     MAIN QZ ITERATION LOOP */
1047
1048 /*     Initialize dynamic indices */
1049
1050 /*     Eigenvalues ILAST+1:N have been found. */
1051 /*        Column operations modify rows IFRSTM:whatever */
1052 /*        Row operations modify columns whatever:ILASTM */
1053
1054 /*     If only eigenvalues are being computed, then */
1055 /*        IFRSTM is the row of the last splitting row above row ILAST; */
1056 /*        this is always at least ILO. */
1057 /*     IITER counts iterations since the last eigenvalue was found, */
1058 /*        to tell when to use an extraordinary shift. */
1059 /*     MAXIT is the maximum number of QZ sweeps allowed. */
1060
1061     ilast = *ihi;
1062     if (ilschr) {
1063         ifrstm = 1;
1064         ilastm = *n;
1065     } else {
1066         ifrstm = *ilo;
1067         ilastm = *ihi;
1068     }
1069     iiter = 0;
1070     eshift.r = 0., eshift.i = 0.;
1071     maxit = (*ihi - *ilo + 1) * 30;
1072
1073     i__1 = maxit;
1074     for (jiter = 1; jiter <= i__1; ++jiter) {
1075
1076 /*        Check for too many iterations. */
1077
1078         if (jiter > maxit) {
1079             goto L180;
1080         }
1081
1082 /*        Split the matrix if possible. */
1083
1084 /*        Two tests: */
1085 /*           1: H(j,j-1)=0  or  j=ILO */
1086 /*           2: T(j,j)=0 */
1087
1088 /*        Special case: j=ILAST */
1089
1090         if (ilast == *ilo) {
1091             goto L60;
1092         } else {
1093             i__2 = ilast + (ilast - 1) * h_dim1;
1094             if ((d__1 = h__[i__2].r, abs(d__1)) + (d__2 = d_imag(&h__[ilast + 
1095                     (ilast - 1) * h_dim1]), abs(d__2)) <= atol) {
1096                 i__2 = ilast + (ilast - 1) * h_dim1;
1097                 h__[i__2].r = 0., h__[i__2].i = 0.;
1098                 goto L60;
1099             }
1100         }
1101
1102         if (z_abs(&t[ilast + ilast * t_dim1]) <= btol) {
1103             i__2 = ilast + ilast * t_dim1;
1104             t[i__2].r = 0., t[i__2].i = 0.;
1105             goto L50;
1106         }
1107
1108 /*        General case: j<ILAST */
1109
1110         i__2 = *ilo;
1111         for (j = ilast - 1; j >= i__2; --j) {
1112
1113 /*           Test 1: for H(j,j-1)=0 or j=ILO */
1114
1115             if (j == *ilo) {
1116                 ilazro = TRUE_;
1117             } else {
1118                 i__3 = j + (j - 1) * h_dim1;
1119                 if ((d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&h__[j + 
1120                         (j - 1) * h_dim1]), abs(d__2)) <= atol) {
1121                     i__3 = j + (j - 1) * h_dim1;
1122                     h__[i__3].r = 0., h__[i__3].i = 0.;
1123                     ilazro = TRUE_;
1124                 } else {
1125                     ilazro = FALSE_;
1126                 }
1127             }
1128
1129 /*           Test 2: for T(j,j)=0 */
1130
1131             if (z_abs(&t[j + j * t_dim1]) < btol) {
1132                 i__3 = j + j * t_dim1;
1133                 t[i__3].r = 0., t[i__3].i = 0.;
1134
1135 /*              Test 1a: Check for 2 consecutive small subdiagonals in A */
1136
1137                 ilazr2 = FALSE_;
1138                 if (! ilazro) {
1139                     i__3 = j + (j - 1) * h_dim1;
1140                     i__4 = j + 1 + j * h_dim1;
1141                     i__5 = j + j * h_dim1;
1142                     if (((d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&
1143                             h__[j + (j - 1) * h_dim1]), abs(d__2))) * (ascale 
1144                             * ((d__3 = h__[i__4].r, abs(d__3)) + (d__4 = 
1145                             d_imag(&h__[j + 1 + j * h_dim1]), abs(d__4)))) <= 
1146                             ((d__5 = h__[i__5].r, abs(d__5)) + (d__6 = d_imag(
1147                             &h__[j + j * h_dim1]), abs(d__6))) * (ascale * 
1148                             atol)) {
1149                         ilazr2 = TRUE_;
1150                     }
1151                 }
1152
1153 /*              If both tests pass (1 & 2), i.e., the leading diagonal */
1154 /*              element of B in the block is zero, split a 1x1 block off */
1155 /*              at the top. (I.e., at the J-th row/column) The leading */
1156 /*              diagonal element of the remainder can also be zero, so */
1157 /*              this may have to be done repeatedly. */
1158
1159                 if (ilazro || ilazr2) {
1160                     i__3 = ilast - 1;
1161                     for (jch = j; jch <= i__3; ++jch) {
1162                         i__4 = jch + jch * h_dim1;
1163                         ctemp.r = h__[i__4].r, ctemp.i = h__[i__4].i;
1164                         zlartg_(&ctemp, &h__[jch + 1 + jch * h_dim1], &c__, &
1165                                 s, &h__[jch + jch * h_dim1]);
1166                         i__4 = jch + 1 + jch * h_dim1;
1167                         h__[i__4].r = 0., h__[i__4].i = 0.;
1168                         i__4 = ilastm - jch;
1169                         zrot_(&i__4, &h__[jch + (jch + 1) * h_dim1], ldh, &
1170                                 h__[jch + 1 + (jch + 1) * h_dim1], ldh, &c__, 
1171                                 &s);
1172                         i__4 = ilastm - jch;
1173                         zrot_(&i__4, &t[jch + (jch + 1) * t_dim1], ldt, &t[
1174                                 jch + 1 + (jch + 1) * t_dim1], ldt, &c__, &s);
1175                         if (ilq) {
1176                             d_cnjg(&z__1, &s);
1177                             zrot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
1178                                      * q_dim1 + 1], &c__1, &c__, &z__1);
1179                         }
1180                         if (ilazr2) {
1181                             i__4 = jch + (jch - 1) * h_dim1;
1182                             i__5 = jch + (jch - 1) * h_dim1;
1183                             z__1.r = c__ * h__[i__5].r, z__1.i = c__ * h__[
1184                                     i__5].i;
1185                             h__[i__4].r = z__1.r, h__[i__4].i = z__1.i;
1186                         }
1187                         ilazr2 = FALSE_;
1188                         i__4 = jch + 1 + (jch + 1) * t_dim1;
1189                         if ((d__1 = t[i__4].r, abs(d__1)) + (d__2 = d_imag(&t[
1190                                 jch + 1 + (jch + 1) * t_dim1]), abs(d__2)) >= 
1191                                 btol) {
1192                             if (jch + 1 >= ilast) {
1193                                 goto L60;
1194                             } else {
1195                                 ifirst = jch + 1;
1196                                 goto L70;
1197                             }
1198                         }
1199                         i__4 = jch + 1 + (jch + 1) * t_dim1;
1200                         t[i__4].r = 0., t[i__4].i = 0.;
1201 /* L20: */
1202                     }
1203                     goto L50;
1204                 } else {
1205
1206 /*                 Only test 2 passed -- chase the zero to T(ILAST,ILAST) */
1207 /*                 Then process as in the case T(ILAST,ILAST)=0 */
1208
1209                     i__3 = ilast - 1;
1210                     for (jch = j; jch <= i__3; ++jch) {
1211                         i__4 = jch + (jch + 1) * t_dim1;
1212                         ctemp.r = t[i__4].r, ctemp.i = t[i__4].i;
1213                         zlartg_(&ctemp, &t[jch + 1 + (jch + 1) * t_dim1], &
1214                                 c__, &s, &t[jch + (jch + 1) * t_dim1]);
1215                         i__4 = jch + 1 + (jch + 1) * t_dim1;
1216                         t[i__4].r = 0., t[i__4].i = 0.;
1217                         if (jch < ilastm - 1) {
1218                             i__4 = ilastm - jch - 1;
1219                             zrot_(&i__4, &t[jch + (jch + 2) * t_dim1], ldt, &
1220                                     t[jch + 1 + (jch + 2) * t_dim1], ldt, &
1221                                     c__, &s);
1222                         }
1223                         i__4 = ilastm - jch + 2;
1224                         zrot_(&i__4, &h__[jch + (jch - 1) * h_dim1], ldh, &
1225                                 h__[jch + 1 + (jch - 1) * h_dim1], ldh, &c__, 
1226                                 &s);
1227                         if (ilq) {
1228                             d_cnjg(&z__1, &s);
1229                             zrot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
1230                                      * q_dim1 + 1], &c__1, &c__, &z__1);
1231                         }
1232                         i__4 = jch + 1 + jch * h_dim1;
1233                         ctemp.r = h__[i__4].r, ctemp.i = h__[i__4].i;
1234                         zlartg_(&ctemp, &h__[jch + 1 + (jch - 1) * h_dim1], &
1235                                 c__, &s, &h__[jch + 1 + jch * h_dim1]);
1236                         i__4 = jch + 1 + (jch - 1) * h_dim1;
1237                         h__[i__4].r = 0., h__[i__4].i = 0.;
1238                         i__4 = jch + 1 - ifrstm;
1239                         zrot_(&i__4, &h__[ifrstm + jch * h_dim1], &c__1, &h__[
1240                                 ifrstm + (jch - 1) * h_dim1], &c__1, &c__, &s)
1241                                 ;
1242                         i__4 = jch - ifrstm;
1243                         zrot_(&i__4, &t[ifrstm + jch * t_dim1], &c__1, &t[
1244                                 ifrstm + (jch - 1) * t_dim1], &c__1, &c__, &s)
1245                                 ;
1246                         if (ilz) {
1247                             zrot_(n, &z__[jch * z_dim1 + 1], &c__1, &z__[(jch 
1248                                     - 1) * z_dim1 + 1], &c__1, &c__, &s);
1249                         }
1250 /* L30: */
1251                     }
1252                     goto L50;
1253                 }
1254             } else if (ilazro) {
1255
1256 /*              Only test 1 passed -- work on J:ILAST */
1257
1258                 ifirst = j;
1259                 goto L70;
1260             }
1261
1262 /*           Neither test passed -- try next J */
1263
1264 /* L40: */
1265         }
1266
1267 /*        (Drop-through is "impossible") */
1268
1269         *info = (*n << 1) + 1;
1270         goto L210;
1271
1272 /*        T(ILAST,ILAST)=0 -- clear H(ILAST,ILAST-1) to split off a */
1273 /*        1x1 block. */
1274
1275 L50:
1276         i__2 = ilast + ilast * h_dim1;
1277         ctemp.r = h__[i__2].r, ctemp.i = h__[i__2].i;
1278         zlartg_(&ctemp, &h__[ilast + (ilast - 1) * h_dim1], &c__, &s, &h__[
1279                 ilast + ilast * h_dim1]);
1280         i__2 = ilast + (ilast - 1) * h_dim1;
1281         h__[i__2].r = 0., h__[i__2].i = 0.;
1282         i__2 = ilast - ifrstm;
1283         zrot_(&i__2, &h__[ifrstm + ilast * h_dim1], &c__1, &h__[ifrstm + (
1284                 ilast - 1) * h_dim1], &c__1, &c__, &s);
1285         i__2 = ilast - ifrstm;
1286         zrot_(&i__2, &t[ifrstm + ilast * t_dim1], &c__1, &t[ifrstm + (ilast - 
1287                 1) * t_dim1], &c__1, &c__, &s);
1288         if (ilz) {
1289             zrot_(n, &z__[ilast * z_dim1 + 1], &c__1, &z__[(ilast - 1) * 
1290                     z_dim1 + 1], &c__1, &c__, &s);
1291         }
1292
1293 /*        H(ILAST,ILAST-1)=0 -- Standardize B, set ALPHA and BETA */
1294
1295 L60:
1296         absb = z_abs(&t[ilast + ilast * t_dim1]);
1297         if (absb > safmin) {
1298             i__2 = ilast + ilast * t_dim1;
1299             z__2.r = t[i__2].r / absb, z__2.i = t[i__2].i / absb;
1300             d_cnjg(&z__1, &z__2);
1301             signbc.r = z__1.r, signbc.i = z__1.i;
1302             i__2 = ilast + ilast * t_dim1;
1303             t[i__2].r = absb, t[i__2].i = 0.;
1304             if (ilschr) {
1305                 i__2 = ilast - ifrstm;
1306                 zscal_(&i__2, &signbc, &t[ifrstm + ilast * t_dim1], &c__1);
1307                 i__2 = ilast + 1 - ifrstm;
1308                 zscal_(&i__2, &signbc, &h__[ifrstm + ilast * h_dim1], &c__1);
1309             } else {
1310                 zscal_(&c__1, &signbc, &h__[ilast + ilast * h_dim1], &c__1);
1311             }
1312             if (ilz) {
1313                 zscal_(n, &signbc, &z__[ilast * z_dim1 + 1], &c__1);
1314             }
1315         } else {
1316             i__2 = ilast + ilast * t_dim1;
1317             t[i__2].r = 0., t[i__2].i = 0.;
1318         }
1319         i__2 = ilast;
1320         i__3 = ilast + ilast * h_dim1;
1321         alpha[i__2].r = h__[i__3].r, alpha[i__2].i = h__[i__3].i;
1322         i__2 = ilast;
1323         i__3 = ilast + ilast * t_dim1;
1324         beta[i__2].r = t[i__3].r, beta[i__2].i = t[i__3].i;
1325
1326 /*        Go to next block -- exit if finished. */
1327
1328         --ilast;
1329         if (ilast < *ilo) {
1330             goto L190;
1331         }
1332
1333 /*        Reset counters */
1334
1335         iiter = 0;
1336         eshift.r = 0., eshift.i = 0.;
1337         if (! ilschr) {
1338             ilastm = ilast;
1339             if (ifrstm > ilast) {
1340                 ifrstm = *ilo;
1341             }
1342         }
1343         goto L160;
1344
1345 /*        QZ step */
1346
1347 /*        This iteration only involves rows/columns IFIRST:ILAST.  We */
1348 /*        assume IFIRST < ILAST, and that the diagonal of B is non-zero. */
1349
1350 L70:
1351         ++iiter;
1352         if (! ilschr) {
1353             ifrstm = ifirst;
1354         }
1355
1356 /*        Compute the Shift. */
1357
1358 /*        At this point, IFIRST < ILAST, and the diagonal elements of */
1359 /*        T(IFIRST:ILAST,IFIRST,ILAST) are larger than BTOL (in */
1360 /*        magnitude) */
1361
1362         if (iiter / 10 * 10 != iiter) {
1363
1364 /*           The Wilkinson shift (AEP p.512), i.e., the eigenvalue of */
1365 /*           the bottom-right 2x2 block of A inv(B) which is nearest to */
1366 /*           the bottom-right element. */
1367
1368 /*           We factor B as U*D, where U has unit diagonals, and */
1369 /*           compute (A*inv(D))*inv(U). */
1370
1371             i__2 = ilast - 1 + ilast * t_dim1;
1372             z__2.r = bscale * t[i__2].r, z__2.i = bscale * t[i__2].i;
1373             i__3 = ilast + ilast * t_dim1;
1374             z__3.r = bscale * t[i__3].r, z__3.i = bscale * t[i__3].i;
1375             z_div(&z__1, &z__2, &z__3);
1376             u12.r = z__1.r, u12.i = z__1.i;
1377             i__2 = ilast - 1 + (ilast - 1) * h_dim1;
1378             z__2.r = ascale * h__[i__2].r, z__2.i = ascale * h__[i__2].i;
1379             i__3 = ilast - 1 + (ilast - 1) * t_dim1;
1380             z__3.r = bscale * t[i__3].r, z__3.i = bscale * t[i__3].i;
1381             z_div(&z__1, &z__2, &z__3);
1382             ad11.r = z__1.r, ad11.i = z__1.i;
1383             i__2 = ilast + (ilast - 1) * h_dim1;
1384             z__2.r = ascale * h__[i__2].r, z__2.i = ascale * h__[i__2].i;
1385             i__3 = ilast - 1 + (ilast - 1) * t_dim1;
1386             z__3.r = bscale * t[i__3].r, z__3.i = bscale * t[i__3].i;
1387             z_div(&z__1, &z__2, &z__3);
1388             ad21.r = z__1.r, ad21.i = z__1.i;
1389             i__2 = ilast - 1 + ilast * h_dim1;
1390             z__2.r = ascale * h__[i__2].r, z__2.i = ascale * h__[i__2].i;
1391             i__3 = ilast + ilast * t_dim1;
1392             z__3.r = bscale * t[i__3].r, z__3.i = bscale * t[i__3].i;
1393             z_div(&z__1, &z__2, &z__3);
1394             ad12.r = z__1.r, ad12.i = z__1.i;
1395             i__2 = ilast + ilast * h_dim1;
1396             z__2.r = ascale * h__[i__2].r, z__2.i = ascale * h__[i__2].i;
1397             i__3 = ilast + ilast * t_dim1;
1398             z__3.r = bscale * t[i__3].r, z__3.i = bscale * t[i__3].i;
1399             z_div(&z__1, &z__2, &z__3);
1400             ad22.r = z__1.r, ad22.i = z__1.i;
1401             z__2.r = u12.r * ad21.r - u12.i * ad21.i, z__2.i = u12.r * ad21.i 
1402                     + u12.i * ad21.r;
1403             z__1.r = ad22.r - z__2.r, z__1.i = ad22.i - z__2.i;
1404             abi22.r = z__1.r, abi22.i = z__1.i;
1405             z__2.r = u12.r * ad11.r - u12.i * ad11.i, z__2.i = u12.r * ad11.i 
1406                     + u12.i * ad11.r;
1407             z__1.r = ad12.r - z__2.r, z__1.i = ad12.i - z__2.i;
1408             abi12.r = z__1.r, abi12.i = z__1.i;
1409
1410             shift.r = abi22.r, shift.i = abi22.i;
1411             z_sqrt(&z__2, &abi12);
1412             z_sqrt(&z__3, &ad21);
1413             z__1.r = z__2.r * z__3.r - z__2.i * z__3.i, z__1.i = z__2.r * 
1414                     z__3.i + z__2.i * z__3.r;
1415             ctemp.r = z__1.r, ctemp.i = z__1.i;
1416             temp = (d__1 = ctemp.r, abs(d__1)) + (d__2 = d_imag(&ctemp), abs(
1417                     d__2));
1418             if (ctemp.r != 0. || ctemp.i != 0.) {
1419                 z__2.r = ad11.r - shift.r, z__2.i = ad11.i - shift.i;
1420                 z__1.r = z__2.r * .5, z__1.i = z__2.i * .5;
1421                 x.r = z__1.r, x.i = z__1.i;
1422                 temp2 = (d__1 = x.r, abs(d__1)) + (d__2 = d_imag(&x), abs(
1423                         d__2));
1424 /* Computing MAX */
1425                 d__3 = temp, d__4 = (d__1 = x.r, abs(d__1)) + (d__2 = d_imag(&
1426                         x), abs(d__2));
1427                 temp = f2cmax(d__3,d__4);
1428                 z__5.r = x.r / temp, z__5.i = x.i / temp;
1429                 pow_zi(&z__4, &z__5, &c__2);
1430                 z__7.r = ctemp.r / temp, z__7.i = ctemp.i / temp;
1431                 pow_zi(&z__6, &z__7, &c__2);
1432                 z__3.r = z__4.r + z__6.r, z__3.i = z__4.i + z__6.i;
1433                 z_sqrt(&z__2, &z__3);
1434                 z__1.r = temp * z__2.r, z__1.i = temp * z__2.i;
1435                 y.r = z__1.r, y.i = z__1.i;
1436                 if (temp2 > 0.) {
1437                     z__1.r = x.r / temp2, z__1.i = x.i / temp2;
1438                     z__2.r = x.r / temp2, z__2.i = x.i / temp2;
1439                     if (z__1.r * y.r + d_imag(&z__2) * d_imag(&y) < 0.) {
1440                         z__3.r = -y.r, z__3.i = -y.i;
1441                         y.r = z__3.r, y.i = z__3.i;
1442                     }
1443                 }
1444                 z__4.r = x.r + y.r, z__4.i = x.i + y.i;
1445                 zladiv_(&z__3, &ctemp, &z__4);
1446                 z__2.r = ctemp.r * z__3.r - ctemp.i * z__3.i, z__2.i = 
1447                         ctemp.r * z__3.i + ctemp.i * z__3.r;
1448                 z__1.r = shift.r - z__2.r, z__1.i = shift.i - z__2.i;
1449                 shift.r = z__1.r, shift.i = z__1.i;
1450             }
1451         } else {
1452
1453 /*           Exceptional shift.  Chosen for no particularly good reason. */
1454
1455             i__2 = ilast + ilast * t_dim1;
1456             if (iiter / 20 * 20 == iiter && bscale * ((d__1 = t[i__2].r, abs(
1457                     d__1)) + (d__2 = d_imag(&t[ilast + ilast * t_dim1]), abs(
1458                     d__2))) > safmin) {
1459                 i__2 = ilast + ilast * h_dim1;
1460                 z__3.r = ascale * h__[i__2].r, z__3.i = ascale * h__[i__2].i;
1461                 i__3 = ilast + ilast * t_dim1;
1462                 z__4.r = bscale * t[i__3].r, z__4.i = bscale * t[i__3].i;
1463                 z_div(&z__2, &z__3, &z__4);
1464                 z__1.r = eshift.r + z__2.r, z__1.i = eshift.i + z__2.i;
1465                 eshift.r = z__1.r, eshift.i = z__1.i;
1466             } else {
1467                 i__2 = ilast + (ilast - 1) * h_dim1;
1468                 z__3.r = ascale * h__[i__2].r, z__3.i = ascale * h__[i__2].i;
1469                 i__3 = ilast - 1 + (ilast - 1) * t_dim1;
1470                 z__4.r = bscale * t[i__3].r, z__4.i = bscale * t[i__3].i;
1471                 z_div(&z__2, &z__3, &z__4);
1472                 z__1.r = eshift.r + z__2.r, z__1.i = eshift.i + z__2.i;
1473                 eshift.r = z__1.r, eshift.i = z__1.i;
1474             }
1475             shift.r = eshift.r, shift.i = eshift.i;
1476         }
1477
1478 /*        Now check for two consecutive small subdiagonals. */
1479
1480         i__2 = ifirst + 1;
1481         for (j = ilast - 1; j >= i__2; --j) {
1482             istart = j;
1483             i__3 = j + j * h_dim1;
1484             z__2.r = ascale * h__[i__3].r, z__2.i = ascale * h__[i__3].i;
1485             i__4 = j + j * t_dim1;
1486             z__4.r = bscale * t[i__4].r, z__4.i = bscale * t[i__4].i;
1487             z__3.r = shift.r * z__4.r - shift.i * z__4.i, z__3.i = shift.r * 
1488                     z__4.i + shift.i * z__4.r;
1489             z__1.r = z__2.r - z__3.r, z__1.i = z__2.i - z__3.i;
1490             ctemp.r = z__1.r, ctemp.i = z__1.i;
1491             temp = (d__1 = ctemp.r, abs(d__1)) + (d__2 = d_imag(&ctemp), abs(
1492                     d__2));
1493             i__3 = j + 1 + j * h_dim1;
1494             temp2 = ascale * ((d__1 = h__[i__3].r, abs(d__1)) + (d__2 = 
1495                     d_imag(&h__[j + 1 + j * h_dim1]), abs(d__2)));
1496             tempr = f2cmax(temp,temp2);
1497             if (tempr < 1. && tempr != 0.) {
1498                 temp /= tempr;
1499                 temp2 /= tempr;
1500             }
1501             i__3 = j + (j - 1) * h_dim1;
1502             if (((d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&h__[j + (j 
1503                     - 1) * h_dim1]), abs(d__2))) * temp2 <= temp * atol) {
1504                 goto L90;
1505             }
1506 /* L80: */
1507         }
1508
1509         istart = ifirst;
1510         i__2 = ifirst + ifirst * h_dim1;
1511         z__2.r = ascale * h__[i__2].r, z__2.i = ascale * h__[i__2].i;
1512         i__3 = ifirst + ifirst * t_dim1;
1513         z__4.r = bscale * t[i__3].r, z__4.i = bscale * t[i__3].i;
1514         z__3.r = shift.r * z__4.r - shift.i * z__4.i, z__3.i = shift.r * 
1515                 z__4.i + shift.i * z__4.r;
1516         z__1.r = z__2.r - z__3.r, z__1.i = z__2.i - z__3.i;
1517         ctemp.r = z__1.r, ctemp.i = z__1.i;
1518 L90:
1519
1520 /*        Do an implicit-shift QZ sweep. */
1521
1522 /*        Initial Q */
1523
1524         i__2 = istart + 1 + istart * h_dim1;
1525         z__1.r = ascale * h__[i__2].r, z__1.i = ascale * h__[i__2].i;
1526         ctemp2.r = z__1.r, ctemp2.i = z__1.i;
1527         zlartg_(&ctemp, &ctemp2, &c__, &s, &ctemp3);
1528
1529 /*        Sweep */
1530
1531         i__2 = ilast - 1;
1532         for (j = istart; j <= i__2; ++j) {
1533             if (j > istart) {
1534                 i__3 = j + (j - 1) * h_dim1;
1535                 ctemp.r = h__[i__3].r, ctemp.i = h__[i__3].i;
1536                 zlartg_(&ctemp, &h__[j + 1 + (j - 1) * h_dim1], &c__, &s, &
1537                         h__[j + (j - 1) * h_dim1]);
1538                 i__3 = j + 1 + (j - 1) * h_dim1;
1539                 h__[i__3].r = 0., h__[i__3].i = 0.;
1540             }
1541
1542             i__3 = ilastm;
1543             for (jc = j; jc <= i__3; ++jc) {
1544                 i__4 = j + jc * h_dim1;
1545                 z__2.r = c__ * h__[i__4].r, z__2.i = c__ * h__[i__4].i;
1546                 i__5 = j + 1 + jc * h_dim1;
1547                 z__3.r = s.r * h__[i__5].r - s.i * h__[i__5].i, z__3.i = s.r *
1548                          h__[i__5].i + s.i * h__[i__5].r;
1549                 z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1550                 ctemp.r = z__1.r, ctemp.i = z__1.i;
1551                 i__4 = j + 1 + jc * h_dim1;
1552                 d_cnjg(&z__4, &s);
1553                 z__3.r = -z__4.r, z__3.i = -z__4.i;
1554                 i__5 = j + jc * h_dim1;
1555                 z__2.r = z__3.r * h__[i__5].r - z__3.i * h__[i__5].i, z__2.i =
1556                          z__3.r * h__[i__5].i + z__3.i * h__[i__5].r;
1557                 i__6 = j + 1 + jc * h_dim1;
1558                 z__5.r = c__ * h__[i__6].r, z__5.i = c__ * h__[i__6].i;
1559                 z__1.r = z__2.r + z__5.r, z__1.i = z__2.i + z__5.i;
1560                 h__[i__4].r = z__1.r, h__[i__4].i = z__1.i;
1561                 i__4 = j + jc * h_dim1;
1562                 h__[i__4].r = ctemp.r, h__[i__4].i = ctemp.i;
1563                 i__4 = j + jc * t_dim1;
1564                 z__2.r = c__ * t[i__4].r, z__2.i = c__ * t[i__4].i;
1565                 i__5 = j + 1 + jc * t_dim1;
1566                 z__3.r = s.r * t[i__5].r - s.i * t[i__5].i, z__3.i = s.r * t[
1567                         i__5].i + s.i * t[i__5].r;
1568                 z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1569                 ctemp2.r = z__1.r, ctemp2.i = z__1.i;
1570                 i__4 = j + 1 + jc * t_dim1;
1571                 d_cnjg(&z__4, &s);
1572                 z__3.r = -z__4.r, z__3.i = -z__4.i;
1573                 i__5 = j + jc * t_dim1;
1574                 z__2.r = z__3.r * t[i__5].r - z__3.i * t[i__5].i, z__2.i = 
1575                         z__3.r * t[i__5].i + z__3.i * t[i__5].r;
1576                 i__6 = j + 1 + jc * t_dim1;
1577                 z__5.r = c__ * t[i__6].r, z__5.i = c__ * t[i__6].i;
1578                 z__1.r = z__2.r + z__5.r, z__1.i = z__2.i + z__5.i;
1579                 t[i__4].r = z__1.r, t[i__4].i = z__1.i;
1580                 i__4 = j + jc * t_dim1;
1581                 t[i__4].r = ctemp2.r, t[i__4].i = ctemp2.i;
1582 /* L100: */
1583             }
1584             if (ilq) {
1585                 i__3 = *n;
1586                 for (jr = 1; jr <= i__3; ++jr) {
1587                     i__4 = jr + j * q_dim1;
1588                     z__2.r = c__ * q[i__4].r, z__2.i = c__ * q[i__4].i;
1589                     d_cnjg(&z__4, &s);
1590                     i__5 = jr + (j + 1) * q_dim1;
1591                     z__3.r = z__4.r * q[i__5].r - z__4.i * q[i__5].i, z__3.i =
1592                              z__4.r * q[i__5].i + z__4.i * q[i__5].r;
1593                     z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1594                     ctemp.r = z__1.r, ctemp.i = z__1.i;
1595                     i__4 = jr + (j + 1) * q_dim1;
1596                     z__3.r = -s.r, z__3.i = -s.i;
1597                     i__5 = jr + j * q_dim1;
1598                     z__2.r = z__3.r * q[i__5].r - z__3.i * q[i__5].i, z__2.i =
1599                              z__3.r * q[i__5].i + z__3.i * q[i__5].r;
1600                     i__6 = jr + (j + 1) * q_dim1;
1601                     z__4.r = c__ * q[i__6].r, z__4.i = c__ * q[i__6].i;
1602                     z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
1603                     q[i__4].r = z__1.r, q[i__4].i = z__1.i;
1604                     i__4 = jr + j * q_dim1;
1605                     q[i__4].r = ctemp.r, q[i__4].i = ctemp.i;
1606 /* L110: */
1607                 }
1608             }
1609
1610             i__3 = j + 1 + (j + 1) * t_dim1;
1611             ctemp.r = t[i__3].r, ctemp.i = t[i__3].i;
1612             zlartg_(&ctemp, &t[j + 1 + j * t_dim1], &c__, &s, &t[j + 1 + (j + 
1613                     1) * t_dim1]);
1614             i__3 = j + 1 + j * t_dim1;
1615             t[i__3].r = 0., t[i__3].i = 0.;
1616
1617 /* Computing MIN */
1618             i__4 = j + 2;
1619             i__3 = f2cmin(i__4,ilast);
1620             for (jr = ifrstm; jr <= i__3; ++jr) {
1621                 i__4 = jr + (j + 1) * h_dim1;
1622                 z__2.r = c__ * h__[i__4].r, z__2.i = c__ * h__[i__4].i;
1623                 i__5 = jr + j * h_dim1;
1624                 z__3.r = s.r * h__[i__5].r - s.i * h__[i__5].i, z__3.i = s.r *
1625                          h__[i__5].i + s.i * h__[i__5].r;
1626                 z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1627                 ctemp.r = z__1.r, ctemp.i = z__1.i;
1628                 i__4 = jr + j * h_dim1;
1629                 d_cnjg(&z__4, &s);
1630                 z__3.r = -z__4.r, z__3.i = -z__4.i;
1631                 i__5 = jr + (j + 1) * h_dim1;
1632                 z__2.r = z__3.r * h__[i__5].r - z__3.i * h__[i__5].i, z__2.i =
1633                          z__3.r * h__[i__5].i + z__3.i * h__[i__5].r;
1634                 i__6 = jr + j * h_dim1;
1635                 z__5.r = c__ * h__[i__6].r, z__5.i = c__ * h__[i__6].i;
1636                 z__1.r = z__2.r + z__5.r, z__1.i = z__2.i + z__5.i;
1637                 h__[i__4].r = z__1.r, h__[i__4].i = z__1.i;
1638                 i__4 = jr + (j + 1) * h_dim1;
1639                 h__[i__4].r = ctemp.r, h__[i__4].i = ctemp.i;
1640 /* L120: */
1641             }
1642             i__3 = j;
1643             for (jr = ifrstm; jr <= i__3; ++jr) {
1644                 i__4 = jr + (j + 1) * t_dim1;
1645                 z__2.r = c__ * t[i__4].r, z__2.i = c__ * t[i__4].i;
1646                 i__5 = jr + j * t_dim1;
1647                 z__3.r = s.r * t[i__5].r - s.i * t[i__5].i, z__3.i = s.r * t[
1648                         i__5].i + s.i * t[i__5].r;
1649                 z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1650                 ctemp.r = z__1.r, ctemp.i = z__1.i;
1651                 i__4 = jr + j * t_dim1;
1652                 d_cnjg(&z__4, &s);
1653                 z__3.r = -z__4.r, z__3.i = -z__4.i;
1654                 i__5 = jr + (j + 1) * t_dim1;
1655                 z__2.r = z__3.r * t[i__5].r - z__3.i * t[i__5].i, z__2.i = 
1656                         z__3.r * t[i__5].i + z__3.i * t[i__5].r;
1657                 i__6 = jr + j * t_dim1;
1658                 z__5.r = c__ * t[i__6].r, z__5.i = c__ * t[i__6].i;
1659                 z__1.r = z__2.r + z__5.r, z__1.i = z__2.i + z__5.i;
1660                 t[i__4].r = z__1.r, t[i__4].i = z__1.i;
1661                 i__4 = jr + (j + 1) * t_dim1;
1662                 t[i__4].r = ctemp.r, t[i__4].i = ctemp.i;
1663 /* L130: */
1664             }
1665             if (ilz) {
1666                 i__3 = *n;
1667                 for (jr = 1; jr <= i__3; ++jr) {
1668                     i__4 = jr + (j + 1) * z_dim1;
1669                     z__2.r = c__ * z__[i__4].r, z__2.i = c__ * z__[i__4].i;
1670                     i__5 = jr + j * z_dim1;
1671                     z__3.r = s.r * z__[i__5].r - s.i * z__[i__5].i, z__3.i = 
1672                             s.r * z__[i__5].i + s.i * z__[i__5].r;
1673                     z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1674                     ctemp.r = z__1.r, ctemp.i = z__1.i;
1675                     i__4 = jr + j * z_dim1;
1676                     d_cnjg(&z__4, &s);
1677                     z__3.r = -z__4.r, z__3.i = -z__4.i;
1678                     i__5 = jr + (j + 1) * z_dim1;
1679                     z__2.r = z__3.r * z__[i__5].r - z__3.i * z__[i__5].i, 
1680                             z__2.i = z__3.r * z__[i__5].i + z__3.i * z__[i__5]
1681                             .r;
1682                     i__6 = jr + j * z_dim1;
1683                     z__5.r = c__ * z__[i__6].r, z__5.i = c__ * z__[i__6].i;
1684                     z__1.r = z__2.r + z__5.r, z__1.i = z__2.i + z__5.i;
1685                     z__[i__4].r = z__1.r, z__[i__4].i = z__1.i;
1686                     i__4 = jr + (j + 1) * z_dim1;
1687                     z__[i__4].r = ctemp.r, z__[i__4].i = ctemp.i;
1688 /* L140: */
1689                 }
1690             }
1691 /* L150: */
1692         }
1693
1694 L160:
1695
1696 /* L170: */
1697         ;
1698     }
1699
1700 /*     Drop-through = non-convergence */
1701
1702 L180:
1703     *info = ilast;
1704     goto L210;
1705
1706 /*     Successful completion of all QZ steps */
1707
1708 L190:
1709
1710 /*     Set Eigenvalues 1:ILO-1 */
1711
1712     i__1 = *ilo - 1;
1713     for (j = 1; j <= i__1; ++j) {
1714         absb = z_abs(&t[j + j * t_dim1]);
1715         if (absb > safmin) {
1716             i__2 = j + j * t_dim1;
1717             z__2.r = t[i__2].r / absb, z__2.i = t[i__2].i / absb;
1718             d_cnjg(&z__1, &z__2);
1719             signbc.r = z__1.r, signbc.i = z__1.i;
1720             i__2 = j + j * t_dim1;
1721             t[i__2].r = absb, t[i__2].i = 0.;
1722             if (ilschr) {
1723                 i__2 = j - 1;
1724                 zscal_(&i__2, &signbc, &t[j * t_dim1 + 1], &c__1);
1725                 zscal_(&j, &signbc, &h__[j * h_dim1 + 1], &c__1);
1726             } else {
1727                 zscal_(&c__1, &signbc, &h__[j + j * h_dim1], &c__1);
1728             }
1729             if (ilz) {
1730                 zscal_(n, &signbc, &z__[j * z_dim1 + 1], &c__1);
1731             }
1732         } else {
1733             i__2 = j + j * t_dim1;
1734             t[i__2].r = 0., t[i__2].i = 0.;
1735         }
1736         i__2 = j;
1737         i__3 = j + j * h_dim1;
1738         alpha[i__2].r = h__[i__3].r, alpha[i__2].i = h__[i__3].i;
1739         i__2 = j;
1740         i__3 = j + j * t_dim1;
1741         beta[i__2].r = t[i__3].r, beta[i__2].i = t[i__3].i;
1742 /* L200: */
1743     }
1744
1745 /*     Normal Termination */
1746
1747     *info = 0;
1748
1749 /*     Exit (other than argument error) -- return optimal workspace size */
1750
1751 L210:
1752     z__1.r = (doublereal) (*n), z__1.i = 0.;
1753     work[1].r = z__1.r, work[1].i = z__1.i;
1754     return 0;
1755
1756 /*     End of ZHGEQZ */
1757
1758 } /* zhgeqz_ */
1759