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