C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / zgghd3.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(complex x, integer n) {
296         complex pow={1.0,0.0}; unsigned long int u;
297                 if(n != 0) {
298                 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
299                 for(u = n; ; ) {
300                         if(u & 01) pow.r *= x.r, pow.i *= x.i;
301                         if(u >>= 1) x.r *= x.r, x.i *= x.i;
302                         else break;
303                 }
304         }
305         _Fcomplex p={pow.r, pow.i};
306         return p;
307 }
308 #else
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310         _Complex float pow=1.0; unsigned long int u;
311         if(n != 0) {
312                 if(n < 0) n = -n, x = 1/x;
313                 for(u = n; ; ) {
314                         if(u & 01) pow *= x;
315                         if(u >>= 1) x *= x;
316                         else break;
317                 }
318         }
319         return pow;
320 }
321 #endif
322 #ifdef _MSC_VER
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324         _Dcomplex pow={1.0,0.0}; unsigned long int u;
325         if(n != 0) {
326                 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
327                 for(u = n; ; ) {
328                         if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329                         if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
330                         else break;
331                 }
332         }
333         _Dcomplex p = {pow._Val[0], pow._Val[1]};
334         return p;
335 }
336 #else
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338         _Complex double pow=1.0; unsigned long int u;
339         if(n != 0) {
340                 if(n < 0) n = -n, x = 1/x;
341                 for(u = n; ; ) {
342                         if(u & 01) pow *= x;
343                         if(u >>= 1) x *= x;
344                         else break;
345                 }
346         }
347         return pow;
348 }
349 #endif
350 static integer pow_ii(integer x, integer n) {
351         integer pow; unsigned long int u;
352         if (n <= 0) {
353                 if (n == 0 || x == 1) pow = 1;
354                 else if (x != -1) pow = x == 0 ? 1/x : 0;
355                 else n = -n;
356         }
357         if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
358                 u = n;
359                 for(pow = 1; ; ) {
360                         if(u & 01) pow *= x;
361                         if(u >>= 1) x *= x;
362                         else break;
363                 }
364         }
365         return pow;
366 }
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
368 {
369         double m; integer i, mi;
370         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371                 if (w[i-1]>m) mi=i ,m=w[i-1];
372         return mi-s+1;
373 }
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
375 {
376         float m; integer i, mi;
377         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378                 if (w[i-1]>m) mi=i ,m=w[i-1];
379         return mi-s+1;
380 }
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382         integer n = *n_, incx = *incx_, incy = *incy_, i;
383 #ifdef _MSC_VER
384         _Fcomplex zdotc = {0.0, 0.0};
385         if (incx == 1 && incy == 1) {
386                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387                         zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388                         zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
389                 }
390         } else {
391                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392                         zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393                         zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
394                 }
395         }
396         pCf(z) = zdotc;
397 }
398 #else
399         _Complex float zdotc = 0.0;
400         if (incx == 1 && incy == 1) {
401                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402                         zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
403                 }
404         } else {
405                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406                         zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
407                 }
408         }
409         pCf(z) = zdotc;
410 }
411 #endif
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413         integer n = *n_, incx = *incx_, incy = *incy_, i;
414 #ifdef _MSC_VER
415         _Dcomplex zdotc = {0.0, 0.0};
416         if (incx == 1 && incy == 1) {
417                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418                         zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419                         zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
420                 }
421         } else {
422                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423                         zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424                         zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
425                 }
426         }
427         pCd(z) = zdotc;
428 }
429 #else
430         _Complex double zdotc = 0.0;
431         if (incx == 1 && incy == 1) {
432                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433                         zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
434                 }
435         } else {
436                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437                         zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
438                 }
439         }
440         pCd(z) = zdotc;
441 }
442 #endif  
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444         integer n = *n_, incx = *incx_, incy = *incy_, i;
445 #ifdef _MSC_VER
446         _Fcomplex zdotc = {0.0, 0.0};
447         if (incx == 1 && incy == 1) {
448                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449                         zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450                         zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
451                 }
452         } else {
453                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454                         zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455                         zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
456                 }
457         }
458         pCf(z) = zdotc;
459 }
460 #else
461         _Complex float zdotc = 0.0;
462         if (incx == 1 && incy == 1) {
463                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464                         zdotc += Cf(&x[i]) * Cf(&y[i]);
465                 }
466         } else {
467                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468                         zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
469                 }
470         }
471         pCf(z) = zdotc;
472 }
473 #endif
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475         integer n = *n_, incx = *incx_, incy = *incy_, i;
476 #ifdef _MSC_VER
477         _Dcomplex zdotc = {0.0, 0.0};
478         if (incx == 1 && incy == 1) {
479                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480                         zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481                         zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
482                 }
483         } else {
484                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485                         zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486                         zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
487                 }
488         }
489         pCd(z) = zdotc;
490 }
491 #else
492         _Complex double zdotc = 0.0;
493         if (incx == 1 && incy == 1) {
494                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495                         zdotc += Cd(&x[i]) * Cd(&y[i]);
496                 }
497         } else {
498                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499                         zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
500                 }
501         }
502         pCd(z) = zdotc;
503 }
504 #endif
505 /*  -- translated by f2c (version 20000121).
506    You must link the resulting object file with the libraries:
507         -lf2c -lm   (in that order)
508 */
509
510
511
512
513 /* Table of constant values */
514
515 static doublecomplex c_b1 = {1.,0.};
516 static doublecomplex c_b2 = {0.,0.};
517 static integer c__1 = 1;
518 static integer c_n1 = -1;
519 static integer c__2 = 2;
520 static integer c__3 = 3;
521 static integer c__16 = 16;
522
523 /* > \brief \b ZGGHD3 */
524
525 /*  =========== DOCUMENTATION =========== */
526
527 /* Online html documentation available at */
528 /*            http://www.netlib.org/lapack/explore-html/ */
529
530 /* > \htmlonly */
531 /* > Download ZGGHD3 + dependencies */
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgghd3.
533 f"> */
534 /* > [TGZ]</a> */
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgghd3.
536 f"> */
537 /* > [ZIP]</a> */
538 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgghd3.
539 f"> */
540 /* > [TXT]</a> */
541 /* > \endhtmlonly */
542
543 /*  Definition: */
544 /*  =========== */
545
546 /*       SUBROUTINE ZGGHD3( COMPQ, COMPZ, N, ILO, IHI, A, LDA, B, LDB, Q, */
547 /*                          LDQ, Z, LDZ, WORK, LWORK, INFO ) */
548
549 /*       CHARACTER          COMPQ, COMPZ */
550 /*       INTEGER            IHI, ILO, INFO, LDA, LDB, LDQ, LDZ, N, LWORK */
551 /*       COMPLEX*16         A( LDA, * ), B( LDB, * ), Q( LDQ, * ), */
552 /*      $                   Z( LDZ, * ), WORK( * ) */
553
554
555 /* > \par Purpose: */
556 /*  ============= */
557 /* > */
558 /* > \verbatim */
559 /* > */
560 /* > ZGGHD3 reduces a pair of complex matrices (A,B) to generalized upper */
561 /* > Hessenberg form using unitary transformations, where A is a */
562 /* > general matrix and B is upper triangular.  The form of the */
563 /* > generalized eigenvalue problem is */
564 /* >    A*x = lambda*B*x, */
565 /* > and B is typically made upper triangular by computing its QR */
566 /* > factorization and moving the unitary matrix Q to the left side */
567 /* > of the equation. */
568 /* > */
569 /* > This subroutine simultaneously reduces A to a Hessenberg matrix H: */
570 /* >    Q**H*A*Z = H */
571 /* > and transforms B to another upper triangular matrix T: */
572 /* >    Q**H*B*Z = T */
573 /* > in order to reduce the problem to its standard form */
574 /* >    H*y = lambda*T*y */
575 /* > where y = Z**H*x. */
576 /* > */
577 /* > The unitary matrices Q and Z are determined as products of Givens */
578 /* > rotations.  They may either be formed explicitly, or they may be */
579 /* > postmultiplied into input matrices Q1 and Z1, so that */
580 /* >      Q1 * A * Z1**H = (Q1*Q) * H * (Z1*Z)**H */
581 /* >      Q1 * B * Z1**H = (Q1*Q) * T * (Z1*Z)**H */
582 /* > If Q1 is the unitary matrix from the QR factorization of B in the */
583 /* > original equation A*x = lambda*B*x, then ZGGHD3 reduces the original */
584 /* > problem to generalized Hessenberg form. */
585 /* > */
586 /* > This is a blocked variant of CGGHRD, using matrix-matrix */
587 /* > multiplications for parts of the computation to enhance performance. */
588 /* > \endverbatim */
589
590 /*  Arguments: */
591 /*  ========== */
592
593 /* > \param[in] COMPQ */
594 /* > \verbatim */
595 /* >          COMPQ is CHARACTER*1 */
596 /* >          = 'N': do not compute Q; */
597 /* >          = 'I': Q is initialized to the unit matrix, and the */
598 /* >                 unitary matrix Q is returned; */
599 /* >          = 'V': Q must contain a unitary matrix Q1 on entry, */
600 /* >                 and the product Q1*Q is returned. */
601 /* > \endverbatim */
602 /* > */
603 /* > \param[in] COMPZ */
604 /* > \verbatim */
605 /* >          COMPZ is CHARACTER*1 */
606 /* >          = 'N': do not compute Z; */
607 /* >          = 'I': Z is initialized to the unit matrix, and the */
608 /* >                 unitary matrix Z is returned; */
609 /* >          = 'V': Z must contain a unitary matrix Z1 on entry, */
610 /* >                 and the product Z1*Z is returned. */
611 /* > \endverbatim */
612 /* > */
613 /* > \param[in] N */
614 /* > \verbatim */
615 /* >          N is INTEGER */
616 /* >          The order of the matrices A and B.  N >= 0. */
617 /* > \endverbatim */
618 /* > */
619 /* > \param[in] ILO */
620 /* > \verbatim */
621 /* >          ILO is INTEGER */
622 /* > \endverbatim */
623 /* > */
624 /* > \param[in] IHI */
625 /* > \verbatim */
626 /* >          IHI is INTEGER */
627 /* > */
628 /* >          ILO and IHI mark the rows and columns of A which are to be */
629 /* >          reduced.  It is assumed that A is already upper triangular */
630 /* >          in rows and columns 1:ILO-1 and IHI+1:N.  ILO and IHI are */
631 /* >          normally set by a previous call to ZGGBAL; otherwise they */
632 /* >          should be set to 1 and N respectively. */
633 /* >          1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0. */
634 /* > \endverbatim */
635 /* > */
636 /* > \param[in,out] A */
637 /* > \verbatim */
638 /* >          A is COMPLEX*16 array, dimension (LDA, N) */
639 /* >          On entry, the N-by-N general matrix to be reduced. */
640 /* >          On exit, the upper triangle and the first subdiagonal of A */
641 /* >          are overwritten with the upper Hessenberg matrix H, and the */
642 /* >          rest is set to zero. */
643 /* > \endverbatim */
644 /* > */
645 /* > \param[in] LDA */
646 /* > \verbatim */
647 /* >          LDA is INTEGER */
648 /* >          The leading dimension of the array A.  LDA >= f2cmax(1,N). */
649 /* > \endverbatim */
650 /* > */
651 /* > \param[in,out] B */
652 /* > \verbatim */
653 /* >          B is COMPLEX*16 array, dimension (LDB, N) */
654 /* >          On entry, the N-by-N upper triangular matrix B. */
655 /* >          On exit, the upper triangular matrix T = Q**H B Z.  The */
656 /* >          elements below the diagonal are set to zero. */
657 /* > \endverbatim */
658 /* > */
659 /* > \param[in] LDB */
660 /* > \verbatim */
661 /* >          LDB is INTEGER */
662 /* >          The leading dimension of the array B.  LDB >= f2cmax(1,N). */
663 /* > \endverbatim */
664 /* > */
665 /* > \param[in,out] Q */
666 /* > \verbatim */
667 /* >          Q is COMPLEX*16 array, dimension (LDQ, N) */
668 /* >          On entry, if COMPQ = 'V', the unitary matrix Q1, typically */
669 /* >          from the QR factorization of B. */
670 /* >          On exit, if COMPQ='I', the unitary matrix Q, and if */
671 /* >          COMPQ = 'V', the product Q1*Q. */
672 /* >          Not referenced if COMPQ='N'. */
673 /* > \endverbatim */
674 /* > */
675 /* > \param[in] LDQ */
676 /* > \verbatim */
677 /* >          LDQ is INTEGER */
678 /* >          The leading dimension of the array Q. */
679 /* >          LDQ >= N if COMPQ='V' or 'I'; LDQ >= 1 otherwise. */
680 /* > \endverbatim */
681 /* > */
682 /* > \param[in,out] Z */
683 /* > \verbatim */
684 /* >          Z is COMPLEX*16 array, dimension (LDZ, N) */
685 /* >          On entry, if COMPZ = 'V', the unitary matrix Z1. */
686 /* >          On exit, if COMPZ='I', the unitary matrix Z, and if */
687 /* >          COMPZ = 'V', the product Z1*Z. */
688 /* >          Not referenced if COMPZ='N'. */
689 /* > \endverbatim */
690 /* > */
691 /* > \param[in] LDZ */
692 /* > \verbatim */
693 /* >          LDZ is INTEGER */
694 /* >          The leading dimension of the array Z. */
695 /* >          LDZ >= N if COMPZ='V' or 'I'; LDZ >= 1 otherwise. */
696 /* > \endverbatim */
697 /* > */
698 /* > \param[out] WORK */
699 /* > \verbatim */
700 /* >          WORK is COMPLEX*16 array, dimension (LWORK) */
701 /* >          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
702 /* > \endverbatim */
703 /* > */
704 /* > \param[in]  LWORK */
705 /* > \verbatim */
706 /* >          LWORK is INTEGER */
707 /* >          The length of the array WORK.  LWORK >= 1. */
708 /* >          For optimum performance LWORK >= 6*N*NB, where NB is the */
709 /* >          optimal blocksize. */
710 /* > */
711 /* >          If LWORK = -1, then a workspace query is assumed; the routine */
712 /* >          only calculates the optimal size of the WORK array, returns */
713 /* >          this value as the first entry of the WORK array, and no error */
714 /* >          message related to LWORK is issued by XERBLA. */
715 /* > \endverbatim */
716 /* > */
717 /* > \param[out] INFO */
718 /* > \verbatim */
719 /* >          INFO is INTEGER */
720 /* >          = 0:  successful exit. */
721 /* >          < 0:  if INFO = -i, the i-th argument had an illegal value. */
722 /* > \endverbatim */
723
724 /*  Authors: */
725 /*  ======== */
726
727 /* > \author Univ. of Tennessee */
728 /* > \author Univ. of California Berkeley */
729 /* > \author Univ. of Colorado Denver */
730 /* > \author NAG Ltd. */
731
732 /* > \date January 2015 */
733
734 /* > \ingroup complex16OTHERcomputational */
735
736 /* > \par Further Details: */
737 /*  ===================== */
738 /* > */
739 /* > \verbatim */
740 /* > */
741 /* >  This routine reduces A to Hessenberg form and maintains B in */
742 /* >  using a blocked variant of Moler and Stewart's original algorithm, */
743 /* >  as described by Kagstrom, Kressner, Quintana-Orti, and Quintana-Orti */
744 /* >  (BIT 2008). */
745 /* > \endverbatim */
746 /* > */
747 /*  ===================================================================== */
748 /* Subroutine */ int zgghd3_(char *compq, char *compz, integer *n, integer *
749         ilo, integer *ihi, doublecomplex *a, integer *lda, doublecomplex *b, 
750         integer *ldb, doublecomplex *q, integer *ldq, doublecomplex *z__, 
751         integer *ldz, doublecomplex *work, integer *lwork, integer *info)
752 {
753     /* System generated locals */
754     integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1, 
755             z_offset, i__1, i__2, i__3, i__4, i__5, i__6, i__7, i__8, i__9;
756     doublecomplex z__1, z__2, z__3, z__4;
757
758     /* Local variables */
759     logical blk22;
760     integer cola, jcol, ierr;
761     doublecomplex temp;
762     integer jrow, topq, ppwo;
763     extern /* Subroutine */ int zrot_(integer *, doublecomplex *, integer *, 
764             doublecomplex *, integer *, doublereal *, doublecomplex *);
765     doublecomplex temp1, temp2, temp3;
766     doublereal c__;
767     integer kacc22, i__, j, k;
768     doublecomplex s;
769     extern logical lsame_(char *, char *);
770     integer nbmin;
771     doublecomplex ctemp;
772     extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *, 
773             integer *, doublecomplex *, doublecomplex *, integer *, 
774             doublecomplex *, integer *, doublecomplex *, doublecomplex *, 
775             integer *);
776     integer nblst;
777     logical initq;
778     doublecomplex c1, c2;
779     extern /* Subroutine */ int zgemv_(char *, integer *, integer *, 
780             doublecomplex *, doublecomplex *, integer *, doublecomplex *, 
781             integer *, doublecomplex *, doublecomplex *, integer *);
782     logical wantq;
783     integer j0;
784     logical initz;
785     extern /* Subroutine */ int zunm22_(char *, char *, integer *, integer *, 
786             integer *, integer *, doublecomplex *, integer *, doublecomplex *,
787              integer *, doublecomplex *, integer *, integer *)
788             ;
789     logical wantz;
790     doublecomplex s1, s2;
791     extern /* Subroutine */ int ztrmv_(char *, char *, char *, integer *, 
792             doublecomplex *, integer *, doublecomplex *, integer *);
793     char compq2[1], compz2[1];
794     integer nb, jj, nh, nx, pw;
795     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
796     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
797             integer *, integer *, ftnlen, ftnlen);
798     extern /* Subroutine */ int zgghrd_(char *, char *, integer *, integer *, 
799             integer *, doublecomplex *, integer *, doublecomplex *, integer *,
800              doublecomplex *, integer *, doublecomplex *, integer *, integer *
801             ), zlaset_(char *, integer *, integer *, 
802             doublecomplex *, doublecomplex *, doublecomplex *, integer *), zlartg_(doublecomplex *, doublecomplex *, doublereal *, 
803             doublecomplex *, doublecomplex *), zlacpy_(char *, integer *, 
804             integer *, doublecomplex *, integer *, doublecomplex *, integer *);
805     integer lwkopt;
806     logical lquery;
807     integer nnb, len, top, ppw, n2nb;
808
809
810 /*  -- LAPACK computational routine (version 3.8.0) -- */
811 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
812 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
813 /*     January 2015 */
814
815
816
817 /*  ===================================================================== */
818
819
820 /*     Decode and test the input parameters. */
821
822     /* Parameter adjustments */
823     a_dim1 = *lda;
824     a_offset = 1 + a_dim1 * 1;
825     a -= a_offset;
826     b_dim1 = *ldb;
827     b_offset = 1 + b_dim1 * 1;
828     b -= b_offset;
829     q_dim1 = *ldq;
830     q_offset = 1 + q_dim1 * 1;
831     q -= q_offset;
832     z_dim1 = *ldz;
833     z_offset = 1 + z_dim1 * 1;
834     z__ -= z_offset;
835     --work;
836
837     /* Function Body */
838     *info = 0;
839     nb = ilaenv_(&c__1, "ZGGHD3", " ", n, ilo, ihi, &c_n1, (ftnlen)6, (ftnlen)
840             1);
841 /* Computing MAX */
842     i__1 = *n * 6 * nb;
843     lwkopt = f2cmax(i__1,1);
844     z__1.r = (doublereal) lwkopt, z__1.i = 0.;
845     work[1].r = z__1.r, work[1].i = z__1.i;
846     initq = lsame_(compq, "I");
847     wantq = initq || lsame_(compq, "V");
848     initz = lsame_(compz, "I");
849     wantz = initz || lsame_(compz, "V");
850     lquery = *lwork == -1;
851
852     if (! lsame_(compq, "N") && ! wantq) {
853         *info = -1;
854     } else if (! lsame_(compz, "N") && ! wantz) {
855         *info = -2;
856     } else if (*n < 0) {
857         *info = -3;
858     } else if (*ilo < 1) {
859         *info = -4;
860     } else if (*ihi > *n || *ihi < *ilo - 1) {
861         *info = -5;
862     } else if (*lda < f2cmax(1,*n)) {
863         *info = -7;
864     } else if (*ldb < f2cmax(1,*n)) {
865         *info = -9;
866     } else if (wantq && *ldq < *n || *ldq < 1) {
867         *info = -11;
868     } else if (wantz && *ldz < *n || *ldz < 1) {
869         *info = -13;
870     } else if (*lwork < 1 && ! lquery) {
871         *info = -15;
872     }
873     if (*info != 0) {
874         i__1 = -(*info);
875         xerbla_("ZGGHD3", &i__1, (ftnlen)6);
876         return 0;
877     } else if (lquery) {
878         return 0;
879     }
880
881 /*     Initialize Q and Z if desired. */
882
883     if (initq) {
884         zlaset_("All", n, n, &c_b2, &c_b1, &q[q_offset], ldq);
885     }
886     if (initz) {
887         zlaset_("All", n, n, &c_b2, &c_b1, &z__[z_offset], ldz);
888     }
889
890 /*     Zero out lower triangle of B. */
891
892     if (*n > 1) {
893         i__1 = *n - 1;
894         i__2 = *n - 1;
895         zlaset_("Lower", &i__1, &i__2, &c_b2, &c_b2, &b[b_dim1 + 2], ldb);
896     }
897
898 /*     Quick return if possible */
899
900     nh = *ihi - *ilo + 1;
901     if (nh <= 1) {
902         work[1].r = 1., work[1].i = 0.;
903         return 0;
904     }
905
906 /*     Determine the blocksize. */
907
908     nbmin = ilaenv_(&c__2, "ZGGHD3", " ", n, ilo, ihi, &c_n1, (ftnlen)6, (
909             ftnlen)1);
910     if (nb > 1 && nb < nh) {
911
912 /*        Determine when to use unblocked instead of blocked code. */
913
914 /* Computing MAX */
915         i__1 = nb, i__2 = ilaenv_(&c__3, "ZGGHD3", " ", n, ilo, ihi, &c_n1, (
916                 ftnlen)6, (ftnlen)1);
917         nx = f2cmax(i__1,i__2);
918         if (nx < nh) {
919
920 /*           Determine if workspace is large enough for blocked code. */
921
922             if (*lwork < lwkopt) {
923
924 /*              Not enough workspace to use optimal NB:  determine the */
925 /*              minimum value of NB, and reduce NB or force use of */
926 /*              unblocked code. */
927
928 /* Computing MAX */
929                 i__1 = 2, i__2 = ilaenv_(&c__2, "ZGGHD3", " ", n, ilo, ihi, &
930                         c_n1, (ftnlen)6, (ftnlen)1);
931                 nbmin = f2cmax(i__1,i__2);
932                 if (*lwork >= *n * 6 * nbmin) {
933                     nb = *lwork / (*n * 6);
934                 } else {
935                     nb = 1;
936                 }
937             }
938         }
939     }
940
941     if (nb < nbmin || nb >= nh) {
942
943 /*        Use unblocked code below */
944
945         jcol = *ilo;
946
947     } else {
948
949 /*        Use blocked code */
950
951         kacc22 = ilaenv_(&c__16, "ZGGHD3", " ", n, ilo, ihi, &c_n1, (ftnlen)6,
952                  (ftnlen)1);
953         blk22 = kacc22 == 2;
954         i__1 = *ihi - 2;
955         i__2 = nb;
956         for (jcol = *ilo; i__2 < 0 ? jcol >= i__1 : jcol <= i__1; jcol += 
957                 i__2) {
958 /* Computing MIN */
959             i__3 = nb, i__4 = *ihi - jcol - 1;
960             nnb = f2cmin(i__3,i__4);
961
962 /*           Initialize small unitary factors that will hold the */
963 /*           accumulated Givens rotations in workspace. */
964 /*           N2NB   denotes the number of 2*NNB-by-2*NNB factors */
965 /*           NBLST  denotes the (possibly smaller) order of the last */
966 /*                  factor. */
967
968             n2nb = (*ihi - jcol - 1) / nnb - 1;
969             nblst = *ihi - jcol - n2nb * nnb;
970             zlaset_("All", &nblst, &nblst, &c_b2, &c_b1, &work[1], &nblst);
971             pw = nblst * nblst + 1;
972             i__3 = n2nb;
973             for (i__ = 1; i__ <= i__3; ++i__) {
974                 i__4 = nnb << 1;
975                 i__5 = nnb << 1;
976                 i__6 = nnb << 1;
977                 zlaset_("All", &i__4, &i__5, &c_b2, &c_b1, &work[pw], &i__6);
978                 pw += (nnb << 2) * nnb;
979             }
980
981 /*           Reduce columns JCOL:JCOL+NNB-1 of A to Hessenberg form. */
982
983             i__3 = jcol + nnb - 1;
984             for (j = jcol; j <= i__3; ++j) {
985
986 /*              Reduce Jth column of A. Store cosines and sines in Jth */
987 /*              column of A and B, respectively. */
988
989                 i__4 = j + 2;
990                 for (i__ = *ihi; i__ >= i__4; --i__) {
991                     i__5 = i__ - 1 + j * a_dim1;
992                     temp.r = a[i__5].r, temp.i = a[i__5].i;
993                     zlartg_(&temp, &a[i__ + j * a_dim1], &c__, &s, &a[i__ - 1 
994                             + j * a_dim1]);
995                     i__5 = i__ + j * a_dim1;
996                     z__1.r = c__, z__1.i = 0.;
997                     a[i__5].r = z__1.r, a[i__5].i = z__1.i;
998                     i__5 = i__ + j * b_dim1;
999                     b[i__5].r = s.r, b[i__5].i = s.i;
1000                 }
1001
1002 /*              Accumulate Givens rotations into workspace array. */
1003
1004                 ppw = (nblst + 1) * (nblst - 2) - j + jcol + 1;
1005                 len = j + 2 - jcol;
1006                 jrow = j + n2nb * nnb + 2;
1007                 i__4 = jrow;
1008                 for (i__ = *ihi; i__ >= i__4; --i__) {
1009                     i__5 = i__ + j * a_dim1;
1010                     ctemp.r = a[i__5].r, ctemp.i = a[i__5].i;
1011                     i__5 = i__ + j * b_dim1;
1012                     s.r = b[i__5].r, s.i = b[i__5].i;
1013                     i__5 = ppw + len - 1;
1014                     for (jj = ppw; jj <= i__5; ++jj) {
1015                         i__6 = jj + nblst;
1016                         temp.r = work[i__6].r, temp.i = work[i__6].i;
1017                         i__6 = jj + nblst;
1018                         z__2.r = ctemp.r * temp.r - ctemp.i * temp.i, z__2.i =
1019                                  ctemp.r * temp.i + ctemp.i * temp.r;
1020                         i__7 = jj;
1021                         z__3.r = s.r * work[i__7].r - s.i * work[i__7].i, 
1022                                 z__3.i = s.r * work[i__7].i + s.i * work[i__7]
1023                                 .r;
1024                         z__1.r = z__2.r - z__3.r, z__1.i = z__2.i - z__3.i;
1025                         work[i__6].r = z__1.r, work[i__6].i = z__1.i;
1026                         i__6 = jj;
1027                         d_cnjg(&z__3, &s);
1028                         z__2.r = z__3.r * temp.r - z__3.i * temp.i, z__2.i = 
1029                                 z__3.r * temp.i + z__3.i * temp.r;
1030                         i__7 = jj;
1031                         z__4.r = ctemp.r * work[i__7].r - ctemp.i * work[i__7]
1032                                 .i, z__4.i = ctemp.r * work[i__7].i + ctemp.i 
1033                                 * work[i__7].r;
1034                         z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
1035                         work[i__6].r = z__1.r, work[i__6].i = z__1.i;
1036                     }
1037                     ++len;
1038                     ppw = ppw - nblst - 1;
1039                 }
1040
1041                 ppwo = nblst * nblst + (nnb + j - jcol - 1 << 1) * nnb + nnb;
1042                 j0 = jrow - nnb;
1043                 i__4 = j + 2;
1044                 i__5 = -nnb;
1045                 for (jrow = j0; i__5 < 0 ? jrow >= i__4 : jrow <= i__4; jrow 
1046                         += i__5) {
1047                     ppw = ppwo;
1048                     len = j + 2 - jcol;
1049                     i__6 = jrow;
1050                     for (i__ = jrow + nnb - 1; i__ >= i__6; --i__) {
1051                         i__7 = i__ + j * a_dim1;
1052                         ctemp.r = a[i__7].r, ctemp.i = a[i__7].i;
1053                         i__7 = i__ + j * b_dim1;
1054                         s.r = b[i__7].r, s.i = b[i__7].i;
1055                         i__7 = ppw + len - 1;
1056                         for (jj = ppw; jj <= i__7; ++jj) {
1057                             i__8 = jj + (nnb << 1);
1058                             temp.r = work[i__8].r, temp.i = work[i__8].i;
1059                             i__8 = jj + (nnb << 1);
1060                             z__2.r = ctemp.r * temp.r - ctemp.i * temp.i, 
1061                                     z__2.i = ctemp.r * temp.i + ctemp.i * 
1062                                     temp.r;
1063                             i__9 = jj;
1064                             z__3.r = s.r * work[i__9].r - s.i * work[i__9].i, 
1065                                     z__3.i = s.r * work[i__9].i + s.i * work[
1066                                     i__9].r;
1067                             z__1.r = z__2.r - z__3.r, z__1.i = z__2.i - 
1068                                     z__3.i;
1069                             work[i__8].r = z__1.r, work[i__8].i = z__1.i;
1070                             i__8 = jj;
1071                             d_cnjg(&z__3, &s);
1072                             z__2.r = z__3.r * temp.r - z__3.i * temp.i, 
1073                                     z__2.i = z__3.r * temp.i + z__3.i * 
1074                                     temp.r;
1075                             i__9 = jj;
1076                             z__4.r = ctemp.r * work[i__9].r - ctemp.i * work[
1077                                     i__9].i, z__4.i = ctemp.r * work[i__9].i 
1078                                     + ctemp.i * work[i__9].r;
1079                             z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + 
1080                                     z__4.i;
1081                             work[i__8].r = z__1.r, work[i__8].i = z__1.i;
1082                         }
1083                         ++len;
1084                         ppw = ppw - (nnb << 1) - 1;
1085                     }
1086                     ppwo += (nnb << 2) * nnb;
1087                 }
1088
1089 /*              TOP denotes the number of top rows in A and B that will */
1090 /*              not be updated during the next steps. */
1091
1092                 if (jcol <= 2) {
1093                     top = 0;
1094                 } else {
1095                     top = jcol;
1096                 }
1097
1098 /*              Propagate transformations through B and replace stored */
1099 /*              left sines/cosines by right sines/cosines. */
1100
1101                 i__5 = j + 1;
1102                 for (jj = *n; jj >= i__5; --jj) {
1103
1104 /*                 Update JJth column of B. */
1105
1106 /* Computing MIN */
1107                     i__4 = jj + 1;
1108                     i__6 = j + 2;
1109                     for (i__ = f2cmin(i__4,*ihi); i__ >= i__6; --i__) {
1110                         i__4 = i__ + j * a_dim1;
1111                         ctemp.r = a[i__4].r, ctemp.i = a[i__4].i;
1112                         i__4 = i__ + j * b_dim1;
1113                         s.r = b[i__4].r, s.i = b[i__4].i;
1114                         i__4 = i__ + jj * b_dim1;
1115                         temp.r = b[i__4].r, temp.i = b[i__4].i;
1116                         i__4 = i__ + jj * b_dim1;
1117                         z__2.r = ctemp.r * temp.r - ctemp.i * temp.i, z__2.i =
1118                                  ctemp.r * temp.i + ctemp.i * temp.r;
1119                         d_cnjg(&z__4, &s);
1120                         i__7 = i__ - 1 + jj * b_dim1;
1121                         z__3.r = z__4.r * b[i__7].r - z__4.i * b[i__7].i, 
1122                                 z__3.i = z__4.r * b[i__7].i + z__4.i * b[i__7]
1123                                 .r;
1124                         z__1.r = z__2.r - z__3.r, z__1.i = z__2.i - z__3.i;
1125                         b[i__4].r = z__1.r, b[i__4].i = z__1.i;
1126                         i__4 = i__ - 1 + jj * b_dim1;
1127                         z__2.r = s.r * temp.r - s.i * temp.i, z__2.i = s.r * 
1128                                 temp.i + s.i * temp.r;
1129                         i__7 = i__ - 1 + jj * b_dim1;
1130                         z__3.r = ctemp.r * b[i__7].r - ctemp.i * b[i__7].i, 
1131                                 z__3.i = ctemp.r * b[i__7].i + ctemp.i * b[
1132                                 i__7].r;
1133                         z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1134                         b[i__4].r = z__1.r, b[i__4].i = z__1.i;
1135                     }
1136
1137 /*                 Annihilate B( JJ+1, JJ ). */
1138
1139                     if (jj < *ihi) {
1140                         i__6 = jj + 1 + (jj + 1) * b_dim1;
1141                         temp.r = b[i__6].r, temp.i = b[i__6].i;
1142                         zlartg_(&temp, &b[jj + 1 + jj * b_dim1], &c__, &s, &b[
1143                                 jj + 1 + (jj + 1) * b_dim1]);
1144                         i__6 = jj + 1 + jj * b_dim1;
1145                         b[i__6].r = 0., b[i__6].i = 0.;
1146                         i__6 = jj - top;
1147                         zrot_(&i__6, &b[top + 1 + (jj + 1) * b_dim1], &c__1, &
1148                                 b[top + 1 + jj * b_dim1], &c__1, &c__, &s);
1149                         i__6 = jj + 1 + j * a_dim1;
1150                         z__1.r = c__, z__1.i = 0.;
1151                         a[i__6].r = z__1.r, a[i__6].i = z__1.i;
1152                         i__6 = jj + 1 + j * b_dim1;
1153                         d_cnjg(&z__2, &s);
1154                         z__1.r = -z__2.r, z__1.i = -z__2.i;
1155                         b[i__6].r = z__1.r, b[i__6].i = z__1.i;
1156                     }
1157                 }
1158
1159 /*              Update A by transformations from right. */
1160
1161                 jj = (*ihi - j - 1) % 3;
1162                 i__5 = jj + 1;
1163                 for (i__ = *ihi - j - 3; i__ >= i__5; i__ += -3) {
1164                     i__6 = j + 1 + i__ + j * a_dim1;
1165                     ctemp.r = a[i__6].r, ctemp.i = a[i__6].i;
1166                     i__6 = j + 1 + i__ + j * b_dim1;
1167                     z__1.r = -b[i__6].r, z__1.i = -b[i__6].i;
1168                     s.r = z__1.r, s.i = z__1.i;
1169                     i__6 = j + 2 + i__ + j * a_dim1;
1170                     c1.r = a[i__6].r, c1.i = a[i__6].i;
1171                     i__6 = j + 2 + i__ + j * b_dim1;
1172                     z__1.r = -b[i__6].r, z__1.i = -b[i__6].i;
1173                     s1.r = z__1.r, s1.i = z__1.i;
1174                     i__6 = j + 3 + i__ + j * a_dim1;
1175                     c2.r = a[i__6].r, c2.i = a[i__6].i;
1176                     i__6 = j + 3 + i__ + j * b_dim1;
1177                     z__1.r = -b[i__6].r, z__1.i = -b[i__6].i;
1178                     s2.r = z__1.r, s2.i = z__1.i;
1179
1180                     i__6 = *ihi;
1181                     for (k = top + 1; k <= i__6; ++k) {
1182                         i__4 = k + (j + i__) * a_dim1;
1183                         temp.r = a[i__4].r, temp.i = a[i__4].i;
1184                         i__4 = k + (j + i__ + 1) * a_dim1;
1185                         temp1.r = a[i__4].r, temp1.i = a[i__4].i;
1186                         i__4 = k + (j + i__ + 2) * a_dim1;
1187                         temp2.r = a[i__4].r, temp2.i = a[i__4].i;
1188                         i__4 = k + (j + i__ + 3) * a_dim1;
1189                         temp3.r = a[i__4].r, temp3.i = a[i__4].i;
1190                         i__4 = k + (j + i__ + 3) * a_dim1;
1191                         z__2.r = c2.r * temp3.r - c2.i * temp3.i, z__2.i = 
1192                                 c2.r * temp3.i + c2.i * temp3.r;
1193                         d_cnjg(&z__4, &s2);
1194                         z__3.r = z__4.r * temp2.r - z__4.i * temp2.i, z__3.i =
1195                                  z__4.r * temp2.i + z__4.i * temp2.r;
1196                         z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1197                         a[i__4].r = z__1.r, a[i__4].i = z__1.i;
1198                         z__3.r = -s2.r, z__3.i = -s2.i;
1199                         z__2.r = z__3.r * temp3.r - z__3.i * temp3.i, z__2.i =
1200                                  z__3.r * temp3.i + z__3.i * temp3.r;
1201                         z__4.r = c2.r * temp2.r - c2.i * temp2.i, z__4.i = 
1202                                 c2.r * temp2.i + c2.i * temp2.r;
1203                         z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
1204                         temp2.r = z__1.r, temp2.i = z__1.i;
1205                         i__4 = k + (j + i__ + 2) * a_dim1;
1206                         z__2.r = c1.r * temp2.r - c1.i * temp2.i, z__2.i = 
1207                                 c1.r * temp2.i + c1.i * temp2.r;
1208                         d_cnjg(&z__4, &s1);
1209                         z__3.r = z__4.r * temp1.r - z__4.i * temp1.i, z__3.i =
1210                                  z__4.r * temp1.i + z__4.i * temp1.r;
1211                         z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1212                         a[i__4].r = z__1.r, a[i__4].i = z__1.i;
1213                         z__3.r = -s1.r, z__3.i = -s1.i;
1214                         z__2.r = z__3.r * temp2.r - z__3.i * temp2.i, z__2.i =
1215                                  z__3.r * temp2.i + z__3.i * temp2.r;
1216                         z__4.r = c1.r * temp1.r - c1.i * temp1.i, z__4.i = 
1217                                 c1.r * temp1.i + c1.i * temp1.r;
1218                         z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
1219                         temp1.r = z__1.r, temp1.i = z__1.i;
1220                         i__4 = k + (j + i__ + 1) * a_dim1;
1221                         z__2.r = ctemp.r * temp1.r - ctemp.i * temp1.i, 
1222                                 z__2.i = ctemp.r * temp1.i + ctemp.i * 
1223                                 temp1.r;
1224                         d_cnjg(&z__4, &s);
1225                         z__3.r = z__4.r * temp.r - z__4.i * temp.i, z__3.i = 
1226                                 z__4.r * temp.i + z__4.i * temp.r;
1227                         z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
1228                         a[i__4].r = z__1.r, a[i__4].i = z__1.i;
1229                         i__4 = k + (j + i__) * a_dim1;
1230                         z__3.r = -s.r, z__3.i = -s.i;
1231                         z__2.r = z__3.r * temp1.r - z__3.i * temp1.i, z__2.i =
1232                                  z__3.r * temp1.i + z__3.i * temp1.r;
1233                         z__4.r = ctemp.r * temp.r - ctemp.i * temp.i, z__4.i =
1234                                  ctemp.r * temp.i + ctemp.i * temp.r;
1235                         z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
1236                         a[i__4].r = z__1.r, a[i__4].i = z__1.i;
1237                     }
1238                 }
1239
1240                 if (jj > 0) {
1241                     for (i__ = jj; i__ >= 1; --i__) {
1242                         i__5 = j + 1 + i__ + j * a_dim1;
1243                         c__ = a[i__5].r;
1244                         i__5 = *ihi - top;
1245                         d_cnjg(&z__2, &b[j + 1 + i__ + j * b_dim1]);
1246                         z__1.r = -z__2.r, z__1.i = -z__2.i;
1247                         zrot_(&i__5, &a[top + 1 + (j + i__ + 1) * a_dim1], &
1248                                 c__1, &a[top + 1 + (j + i__) * a_dim1], &c__1,
1249                                  &c__, &z__1);
1250                     }
1251                 }
1252
1253 /*              Update (J+1)th column of A by transformations from left. */
1254
1255                 if (j < jcol + nnb - 1) {
1256                     len = j + 1 - jcol;
1257
1258 /*                 Multiply with the trailing accumulated unitary */
1259 /*                 matrix, which takes the form */
1260
1261 /*                        [  U11  U12  ] */
1262 /*                    U = [            ], */
1263 /*                        [  U21  U22  ] */
1264
1265 /*                 where U21 is a LEN-by-LEN matrix and U12 is lower */
1266 /*                 triangular. */
1267
1268                     jrow = *ihi - nblst + 1;
1269                     zgemv_("Conjugate", &nblst, &len, &c_b1, &work[1], &nblst,
1270                              &a[jrow + (j + 1) * a_dim1], &c__1, &c_b2, &work[
1271                             pw], &c__1);
1272                     ppw = pw + len;
1273                     i__5 = jrow + nblst - len - 1;
1274                     for (i__ = jrow; i__ <= i__5; ++i__) {
1275                         i__6 = ppw;
1276                         i__4 = i__ + (j + 1) * a_dim1;
1277                         work[i__6].r = a[i__4].r, work[i__6].i = a[i__4].i;
1278                         ++ppw;
1279                     }
1280                     i__5 = nblst - len;
1281                     ztrmv_("Lower", "Conjugate", "Non-unit", &i__5, &work[len 
1282                             * nblst + 1], &nblst, &work[pw + len], &c__1);
1283                     i__5 = nblst - len;
1284                     zgemv_("Conjugate", &len, &i__5, &c_b1, &work[(len + 1) * 
1285                             nblst - len + 1], &nblst, &a[jrow + nblst - len + 
1286                             (j + 1) * a_dim1], &c__1, &c_b1, &work[pw + len], 
1287                             &c__1);
1288                     ppw = pw;
1289                     i__5 = jrow + nblst - 1;
1290                     for (i__ = jrow; i__ <= i__5; ++i__) {
1291                         i__6 = i__ + (j + 1) * a_dim1;
1292                         i__4 = ppw;
1293                         a[i__6].r = work[i__4].r, a[i__6].i = work[i__4].i;
1294                         ++ppw;
1295                     }
1296
1297 /*                 Multiply with the other accumulated unitary */
1298 /*                 matrices, which take the form */
1299
1300 /*                        [  U11  U12   0  ] */
1301 /*                        [                ] */
1302 /*                    U = [  U21  U22   0  ], */
1303 /*                        [                ] */
1304 /*                        [   0    0    I  ] */
1305
1306 /*                 where I denotes the (NNB-LEN)-by-(NNB-LEN) identity */
1307 /*                 matrix, U21 is a LEN-by-LEN upper triangular matrix */
1308 /*                 and U12 is an NNB-by-NNB lower triangular matrix. */
1309
1310                     ppwo = nblst * nblst + 1;
1311                     j0 = jrow - nnb;
1312                     i__5 = jcol + 1;
1313                     i__6 = -nnb;
1314                     for (jrow = j0; i__6 < 0 ? jrow >= i__5 : jrow <= i__5; 
1315                             jrow += i__6) {
1316                         ppw = pw + len;
1317                         i__4 = jrow + nnb - 1;
1318                         for (i__ = jrow; i__ <= i__4; ++i__) {
1319                             i__7 = ppw;
1320                             i__8 = i__ + (j + 1) * a_dim1;
1321                             work[i__7].r = a[i__8].r, work[i__7].i = a[i__8]
1322                                     .i;
1323                             ++ppw;
1324                         }
1325                         ppw = pw;
1326                         i__4 = jrow + nnb + len - 1;
1327                         for (i__ = jrow + nnb; i__ <= i__4; ++i__) {
1328                             i__7 = ppw;
1329                             i__8 = i__ + (j + 1) * a_dim1;
1330                             work[i__7].r = a[i__8].r, work[i__7].i = a[i__8]
1331                                     .i;
1332                             ++ppw;
1333                         }
1334                         i__4 = nnb << 1;
1335                         ztrmv_("Upper", "Conjugate", "Non-unit", &len, &work[
1336                                 ppwo + nnb], &i__4, &work[pw], &c__1);
1337                         i__4 = nnb << 1;
1338                         ztrmv_("Lower", "Conjugate", "Non-unit", &nnb, &work[
1339                                 ppwo + (len << 1) * nnb], &i__4, &work[pw + 
1340                                 len], &c__1);
1341                         i__4 = nnb << 1;
1342                         zgemv_("Conjugate", &nnb, &len, &c_b1, &work[ppwo], &
1343                                 i__4, &a[jrow + (j + 1) * a_dim1], &c__1, &
1344                                 c_b1, &work[pw], &c__1);
1345                         i__4 = nnb << 1;
1346                         zgemv_("Conjugate", &len, &nnb, &c_b1, &work[ppwo + (
1347                                 len << 1) * nnb + nnb], &i__4, &a[jrow + nnb 
1348                                 + (j + 1) * a_dim1], &c__1, &c_b1, &work[pw + 
1349                                 len], &c__1);
1350                         ppw = pw;
1351                         i__4 = jrow + len + nnb - 1;
1352                         for (i__ = jrow; i__ <= i__4; ++i__) {
1353                             i__7 = i__ + (j + 1) * a_dim1;
1354                             i__8 = ppw;
1355                             a[i__7].r = work[i__8].r, a[i__7].i = work[i__8]
1356                                     .i;
1357                             ++ppw;
1358                         }
1359                         ppwo += (nnb << 2) * nnb;
1360                     }
1361                 }
1362             }
1363
1364 /*           Apply accumulated unitary matrices to A. */
1365
1366             cola = *n - jcol - nnb + 1;
1367             j = *ihi - nblst + 1;
1368             zgemm_("Conjugate", "No Transpose", &nblst, &cola, &nblst, &c_b1, 
1369                     &work[1], &nblst, &a[j + (jcol + nnb) * a_dim1], lda, &
1370                     c_b2, &work[pw], &nblst);
1371             zlacpy_("All", &nblst, &cola, &work[pw], &nblst, &a[j + (jcol + 
1372                     nnb) * a_dim1], lda);
1373             ppwo = nblst * nblst + 1;
1374             j0 = j - nnb;
1375             i__3 = jcol + 1;
1376             i__6 = -nnb;
1377             for (j = j0; i__6 < 0 ? j >= i__3 : j <= i__3; j += i__6) {
1378                 if (blk22) {
1379
1380 /*                 Exploit the structure of */
1381
1382 /*                        [  U11  U12  ] */
1383 /*                    U = [            ] */
1384 /*                        [  U21  U22  ], */
1385
1386 /*                 where all blocks are NNB-by-NNB, U21 is upper */
1387 /*                 triangular and U12 is lower triangular. */
1388
1389                     i__5 = nnb << 1;
1390                     i__4 = nnb << 1;
1391                     i__7 = *lwork - pw + 1;
1392                     zunm22_("Left", "Conjugate", &i__5, &cola, &nnb, &nnb, &
1393                             work[ppwo], &i__4, &a[j + (jcol + nnb) * a_dim1], 
1394                             lda, &work[pw], &i__7, &ierr);
1395                 } else {
1396
1397 /*                 Ignore the structure of U. */
1398
1399                     i__5 = nnb << 1;
1400                     i__4 = nnb << 1;
1401                     i__7 = nnb << 1;
1402                     i__8 = nnb << 1;
1403                     zgemm_("Conjugate", "No Transpose", &i__5, &cola, &i__4, &
1404                             c_b1, &work[ppwo], &i__7, &a[j + (jcol + nnb) * 
1405                             a_dim1], lda, &c_b2, &work[pw], &i__8);
1406                     i__5 = nnb << 1;
1407                     i__4 = nnb << 1;
1408                     zlacpy_("All", &i__5, &cola, &work[pw], &i__4, &a[j + (
1409                             jcol + nnb) * a_dim1], lda);
1410                 }
1411                 ppwo += (nnb << 2) * nnb;
1412             }
1413
1414 /*           Apply accumulated unitary matrices to Q. */
1415
1416             if (wantq) {
1417                 j = *ihi - nblst + 1;
1418                 if (initq) {
1419 /* Computing MAX */
1420                     i__6 = 2, i__3 = j - jcol + 1;
1421                     topq = f2cmax(i__6,i__3);
1422                     nh = *ihi - topq + 1;
1423                 } else {
1424                     topq = 1;
1425                     nh = *n;
1426                 }
1427                 zgemm_("No Transpose", "No Transpose", &nh, &nblst, &nblst, &
1428                         c_b1, &q[topq + j * q_dim1], ldq, &work[1], &nblst, &
1429                         c_b2, &work[pw], &nh);
1430                 zlacpy_("All", &nh, &nblst, &work[pw], &nh, &q[topq + j * 
1431                         q_dim1], ldq);
1432                 ppwo = nblst * nblst + 1;
1433                 j0 = j - nnb;
1434                 i__6 = jcol + 1;
1435                 i__3 = -nnb;
1436                 for (j = j0; i__3 < 0 ? j >= i__6 : j <= i__6; j += i__3) {
1437                     if (initq) {
1438 /* Computing MAX */
1439                         i__5 = 2, i__4 = j - jcol + 1;
1440                         topq = f2cmax(i__5,i__4);
1441                         nh = *ihi - topq + 1;
1442                     }
1443                     if (blk22) {
1444
1445 /*                    Exploit the structure of U. */
1446
1447                         i__5 = nnb << 1;
1448                         i__4 = nnb << 1;
1449                         i__7 = *lwork - pw + 1;
1450                         zunm22_("Right", "No Transpose", &nh, &i__5, &nnb, &
1451                                 nnb, &work[ppwo], &i__4, &q[topq + j * q_dim1]
1452                                 , ldq, &work[pw], &i__7, &ierr);
1453                     } else {
1454
1455 /*                    Ignore the structure of U. */
1456
1457                         i__5 = nnb << 1;
1458                         i__4 = nnb << 1;
1459                         i__7 = nnb << 1;
1460                         zgemm_("No Transpose", "No Transpose", &nh, &i__5, &
1461                                 i__4, &c_b1, &q[topq + j * q_dim1], ldq, &
1462                                 work[ppwo], &i__7, &c_b2, &work[pw], &nh);
1463                         i__5 = nnb << 1;
1464                         zlacpy_("All", &nh, &i__5, &work[pw], &nh, &q[topq + 
1465                                 j * q_dim1], ldq);
1466                     }
1467                     ppwo += (nnb << 2) * nnb;
1468                 }
1469             }
1470
1471 /*           Accumulate right Givens rotations if required. */
1472
1473             if (wantz || top > 0) {
1474
1475 /*              Initialize small unitary factors that will hold the */
1476 /*              accumulated Givens rotations in workspace. */
1477
1478                 zlaset_("All", &nblst, &nblst, &c_b2, &c_b1, &work[1], &nblst);
1479                 pw = nblst * nblst + 1;
1480                 i__3 = n2nb;
1481                 for (i__ = 1; i__ <= i__3; ++i__) {
1482                     i__6 = nnb << 1;
1483                     i__5 = nnb << 1;
1484                     i__4 = nnb << 1;
1485                     zlaset_("All", &i__6, &i__5, &c_b2, &c_b1, &work[pw], &
1486                             i__4);
1487                     pw += (nnb << 2) * nnb;
1488                 }
1489
1490 /*              Accumulate Givens rotations into workspace array. */
1491
1492                 i__3 = jcol + nnb - 1;
1493                 for (j = jcol; j <= i__3; ++j) {
1494                     ppw = (nblst + 1) * (nblst - 2) - j + jcol + 1;
1495                     len = j + 2 - jcol;
1496                     jrow = j + n2nb * nnb + 2;
1497                     i__6 = jrow;
1498                     for (i__ = *ihi; i__ >= i__6; --i__) {
1499                         i__5 = i__ + j * a_dim1;
1500                         ctemp.r = a[i__5].r, ctemp.i = a[i__5].i;
1501                         i__5 = i__ + j * a_dim1;
1502                         a[i__5].r = 0., a[i__5].i = 0.;
1503                         i__5 = i__ + j * b_dim1;
1504                         s.r = b[i__5].r, s.i = b[i__5].i;
1505                         i__5 = i__ + j * b_dim1;
1506                         b[i__5].r = 0., b[i__5].i = 0.;
1507                         i__5 = ppw + len - 1;
1508                         for (jj = ppw; jj <= i__5; ++jj) {
1509                             i__4 = jj + nblst;
1510                             temp.r = work[i__4].r, temp.i = work[i__4].i;
1511                             i__4 = jj + nblst;
1512                             z__2.r = ctemp.r * temp.r - ctemp.i * temp.i, 
1513                                     z__2.i = ctemp.r * temp.i + ctemp.i * 
1514                                     temp.r;
1515                             d_cnjg(&z__4, &s);
1516                             i__7 = jj;
1517                             z__3.r = z__4.r * work[i__7].r - z__4.i * work[
1518                                     i__7].i, z__3.i = z__4.r * work[i__7].i + 
1519                                     z__4.i * work[i__7].r;
1520                             z__1.r = z__2.r - z__3.r, z__1.i = z__2.i - 
1521                                     z__3.i;
1522                             work[i__4].r = z__1.r, work[i__4].i = z__1.i;
1523                             i__4 = jj;
1524                             z__2.r = s.r * temp.r - s.i * temp.i, z__2.i = 
1525                                     s.r * temp.i + s.i * temp.r;
1526                             i__7 = jj;
1527                             z__3.r = ctemp.r * work[i__7].r - ctemp.i * work[
1528                                     i__7].i, z__3.i = ctemp.r * work[i__7].i 
1529                                     + ctemp.i * work[i__7].r;
1530                             z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + 
1531                                     z__3.i;
1532                             work[i__4].r = z__1.r, work[i__4].i = z__1.i;
1533                         }
1534                         ++len;
1535                         ppw = ppw - nblst - 1;
1536                     }
1537
1538                     ppwo = nblst * nblst + (nnb + j - jcol - 1 << 1) * nnb + 
1539                             nnb;
1540                     j0 = jrow - nnb;
1541                     i__6 = j + 2;
1542                     i__5 = -nnb;
1543                     for (jrow = j0; i__5 < 0 ? jrow >= i__6 : jrow <= i__6; 
1544                             jrow += i__5) {
1545                         ppw = ppwo;
1546                         len = j + 2 - jcol;
1547                         i__4 = jrow;
1548                         for (i__ = jrow + nnb - 1; i__ >= i__4; --i__) {
1549                             i__7 = i__ + j * a_dim1;
1550                             ctemp.r = a[i__7].r, ctemp.i = a[i__7].i;
1551                             i__7 = i__ + j * a_dim1;
1552                             a[i__7].r = 0., a[i__7].i = 0.;
1553                             i__7 = i__ + j * b_dim1;
1554                             s.r = b[i__7].r, s.i = b[i__7].i;
1555                             i__7 = i__ + j * b_dim1;
1556                             b[i__7].r = 0., b[i__7].i = 0.;
1557                             i__7 = ppw + len - 1;
1558                             for (jj = ppw; jj <= i__7; ++jj) {
1559                                 i__8 = jj + (nnb << 1);
1560                                 temp.r = work[i__8].r, temp.i = work[i__8].i;
1561                                 i__8 = jj + (nnb << 1);
1562                                 z__2.r = ctemp.r * temp.r - ctemp.i * temp.i, 
1563                                         z__2.i = ctemp.r * temp.i + ctemp.i * 
1564                                         temp.r;
1565                                 d_cnjg(&z__4, &s);
1566                                 i__9 = jj;
1567                                 z__3.r = z__4.r * work[i__9].r - z__4.i * 
1568                                         work[i__9].i, z__3.i = z__4.r * work[
1569                                         i__9].i + z__4.i * work[i__9].r;
1570                                 z__1.r = z__2.r - z__3.r, z__1.i = z__2.i - 
1571                                         z__3.i;
1572                                 work[i__8].r = z__1.r, work[i__8].i = z__1.i;
1573                                 i__8 = jj;
1574                                 z__2.r = s.r * temp.r - s.i * temp.i, z__2.i =
1575                                          s.r * temp.i + s.i * temp.r;
1576                                 i__9 = jj;
1577                                 z__3.r = ctemp.r * work[i__9].r - ctemp.i * 
1578                                         work[i__9].i, z__3.i = ctemp.r * work[
1579                                         i__9].i + ctemp.i * work[i__9].r;
1580                                 z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + 
1581                                         z__3.i;
1582                                 work[i__8].r = z__1.r, work[i__8].i = z__1.i;
1583                             }
1584                             ++len;
1585                             ppw = ppw - (nnb << 1) - 1;
1586                         }
1587                         ppwo += (nnb << 2) * nnb;
1588                     }
1589                 }
1590             } else {
1591
1592                 i__3 = *ihi - jcol - 1;
1593                 zlaset_("Lower", &i__3, &nnb, &c_b2, &c_b2, &a[jcol + 2 + 
1594                         jcol * a_dim1], lda);
1595                 i__3 = *ihi - jcol - 1;
1596                 zlaset_("Lower", &i__3, &nnb, &c_b2, &c_b2, &b[jcol + 2 + 
1597                         jcol * b_dim1], ldb);
1598             }
1599
1600 /*           Apply accumulated unitary matrices to A and B. */
1601
1602             if (top > 0) {
1603                 j = *ihi - nblst + 1;
1604                 zgemm_("No Transpose", "No Transpose", &top, &nblst, &nblst, &
1605                         c_b1, &a[j * a_dim1 + 1], lda, &work[1], &nblst, &
1606                         c_b2, &work[pw], &top);
1607                 zlacpy_("All", &top, &nblst, &work[pw], &top, &a[j * a_dim1 + 
1608                         1], lda);
1609                 ppwo = nblst * nblst + 1;
1610                 j0 = j - nnb;
1611                 i__3 = jcol + 1;
1612                 i__5 = -nnb;
1613                 for (j = j0; i__5 < 0 ? j >= i__3 : j <= i__3; j += i__5) {
1614                     if (blk22) {
1615
1616 /*                    Exploit the structure of U. */
1617
1618                         i__6 = nnb << 1;
1619                         i__4 = nnb << 1;
1620                         i__7 = *lwork - pw + 1;
1621                         zunm22_("Right", "No Transpose", &top, &i__6, &nnb, &
1622                                 nnb, &work[ppwo], &i__4, &a[j * a_dim1 + 1], 
1623                                 lda, &work[pw], &i__7, &ierr);
1624                     } else {
1625
1626 /*                    Ignore the structure of U. */
1627
1628                         i__6 = nnb << 1;
1629                         i__4 = nnb << 1;
1630                         i__7 = nnb << 1;
1631                         zgemm_("No Transpose", "No Transpose", &top, &i__6, &
1632                                 i__4, &c_b1, &a[j * a_dim1 + 1], lda, &work[
1633                                 ppwo], &i__7, &c_b2, &work[pw], &top);
1634                         i__6 = nnb << 1;
1635                         zlacpy_("All", &top, &i__6, &work[pw], &top, &a[j * 
1636                                 a_dim1 + 1], lda);
1637                     }
1638                     ppwo += (nnb << 2) * nnb;
1639                 }
1640
1641                 j = *ihi - nblst + 1;
1642                 zgemm_("No Transpose", "No Transpose", &top, &nblst, &nblst, &
1643                         c_b1, &b[j * b_dim1 + 1], ldb, &work[1], &nblst, &
1644                         c_b2, &work[pw], &top);
1645                 zlacpy_("All", &top, &nblst, &work[pw], &top, &b[j * b_dim1 + 
1646                         1], ldb);
1647                 ppwo = nblst * nblst + 1;
1648                 j0 = j - nnb;
1649                 i__5 = jcol + 1;
1650                 i__3 = -nnb;
1651                 for (j = j0; i__3 < 0 ? j >= i__5 : j <= i__5; j += i__3) {
1652                     if (blk22) {
1653
1654 /*                    Exploit the structure of U. */
1655
1656                         i__6 = nnb << 1;
1657                         i__4 = nnb << 1;
1658                         i__7 = *lwork - pw + 1;
1659                         zunm22_("Right", "No Transpose", &top, &i__6, &nnb, &
1660                                 nnb, &work[ppwo], &i__4, &b[j * b_dim1 + 1], 
1661                                 ldb, &work[pw], &i__7, &ierr);
1662                     } else {
1663
1664 /*                    Ignore the structure of U. */
1665
1666                         i__6 = nnb << 1;
1667                         i__4 = nnb << 1;
1668                         i__7 = nnb << 1;
1669                         zgemm_("No Transpose", "No Transpose", &top, &i__6, &
1670                                 i__4, &c_b1, &b[j * b_dim1 + 1], ldb, &work[
1671                                 ppwo], &i__7, &c_b2, &work[pw], &top);
1672                         i__6 = nnb << 1;
1673                         zlacpy_("All", &top, &i__6, &work[pw], &top, &b[j * 
1674                                 b_dim1 + 1], ldb);
1675                     }
1676                     ppwo += (nnb << 2) * nnb;
1677                 }
1678             }
1679
1680 /*           Apply accumulated unitary matrices to Z. */
1681
1682             if (wantz) {
1683                 j = *ihi - nblst + 1;
1684                 if (initq) {
1685 /* Computing MAX */
1686                     i__3 = 2, i__5 = j - jcol + 1;
1687                     topq = f2cmax(i__3,i__5);
1688                     nh = *ihi - topq + 1;
1689                 } else {
1690                     topq = 1;
1691                     nh = *n;
1692                 }
1693                 zgemm_("No Transpose", "No Transpose", &nh, &nblst, &nblst, &
1694                         c_b1, &z__[topq + j * z_dim1], ldz, &work[1], &nblst, 
1695                         &c_b2, &work[pw], &nh);
1696                 zlacpy_("All", &nh, &nblst, &work[pw], &nh, &z__[topq + j * 
1697                         z_dim1], ldz);
1698                 ppwo = nblst * nblst + 1;
1699                 j0 = j - nnb;
1700                 i__3 = jcol + 1;
1701                 i__5 = -nnb;
1702                 for (j = j0; i__5 < 0 ? j >= i__3 : j <= i__3; j += i__5) {
1703                     if (initq) {
1704 /* Computing MAX */
1705                         i__6 = 2, i__4 = j - jcol + 1;
1706                         topq = f2cmax(i__6,i__4);
1707                         nh = *ihi - topq + 1;
1708                     }
1709                     if (blk22) {
1710
1711 /*                    Exploit the structure of U. */
1712
1713                         i__6 = nnb << 1;
1714                         i__4 = nnb << 1;
1715                         i__7 = *lwork - pw + 1;
1716                         zunm22_("Right", "No Transpose", &nh, &i__6, &nnb, &
1717                                 nnb, &work[ppwo], &i__4, &z__[topq + j * 
1718                                 z_dim1], ldz, &work[pw], &i__7, &ierr);
1719                     } else {
1720
1721 /*                    Ignore the structure of U. */
1722
1723                         i__6 = nnb << 1;
1724                         i__4 = nnb << 1;
1725                         i__7 = nnb << 1;
1726                         zgemm_("No Transpose", "No Transpose", &nh, &i__6, &
1727                                 i__4, &c_b1, &z__[topq + j * z_dim1], ldz, &
1728                                 work[ppwo], &i__7, &c_b2, &work[pw], &nh);
1729                         i__6 = nnb << 1;
1730                         zlacpy_("All", &nh, &i__6, &work[pw], &nh, &z__[topq 
1731                                 + j * z_dim1], ldz);
1732                     }
1733                     ppwo += (nnb << 2) * nnb;
1734                 }
1735             }
1736         }
1737     }
1738
1739 /*     Use unblocked code to reduce the rest of the matrix */
1740 /*     Avoid re-initialization of modified Q and Z. */
1741
1742     *(unsigned char *)compq2 = *(unsigned char *)compq;
1743     *(unsigned char *)compz2 = *(unsigned char *)compz;
1744     if (jcol != *ilo) {
1745         if (wantq) {
1746             *(unsigned char *)compq2 = 'V';
1747         }
1748         if (wantz) {
1749             *(unsigned char *)compz2 = 'V';
1750         }
1751     }
1752
1753     if (jcol < *ihi) {
1754         zgghrd_(compq2, compz2, n, &jcol, ihi, &a[a_offset], lda, &b[b_offset]
1755                 , ldb, &q[q_offset], ldq, &z__[z_offset], ldz, &ierr);
1756     }
1757     z__1.r = (doublereal) lwkopt, z__1.i = 0.;
1758     work[1].r = z__1.r, work[1].i = z__1.i;
1759
1760     return 0;
1761
1762 /*     End of ZGGHD3 */
1763
1764 } /* zgghd3_ */
1765