C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / ctgevc.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 = {0.f,0.f};
516 static complex c_b2 = {1.f,0.f};
517 static integer c__1 = 1;
518
519 /* > \brief \b CTGEVC */
520
521 /*  =========== DOCUMENTATION =========== */
522
523 /* Online html documentation available at */
524 /*            http://www.netlib.org/lapack/explore-html/ */
525
526 /* > \htmlonly */
527 /* > Download CTGEVC + dependencies */
528 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ctgevc.
529 f"> */
530 /* > [TGZ]</a> */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ctgevc.
532 f"> */
533 /* > [ZIP]</a> */
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ctgevc.
535 f"> */
536 /* > [TXT]</a> */
537 /* > \endhtmlonly */
538
539 /*  Definition: */
540 /*  =========== */
541
542 /*       SUBROUTINE CTGEVC( SIDE, HOWMNY, SELECT, N, S, LDS, P, LDP, VL, */
543 /*                          LDVL, VR, LDVR, MM, M, WORK, RWORK, INFO ) */
544
545 /*       CHARACTER          HOWMNY, SIDE */
546 /*       INTEGER            INFO, LDP, LDS, LDVL, LDVR, M, MM, N */
547 /*       LOGICAL            SELECT( * ) */
548 /*       REAL               RWORK( * ) */
549 /*       COMPLEX            P( LDP, * ), S( LDS, * ), VL( LDVL, * ), */
550 /*      $                   VR( LDVR, * ), WORK( * ) */
551
552
553
554 /* > \par Purpose: */
555 /*  ============= */
556 /* > */
557 /* > \verbatim */
558 /* > */
559 /* > CTGEVC computes some or all of the right and/or left eigenvectors of */
560 /* > a pair of complex matrices (S,P), where S and P are upper triangular. */
561 /* > Matrix pairs of this type are produced by the generalized Schur */
562 /* > factorization of a complex matrix pair (A,B): */
563 /* > */
564 /* >    A = Q*S*Z**H,  B = Q*P*Z**H */
565 /* > */
566 /* > as computed by CGGHRD + CHGEQZ. */
567 /* > */
568 /* > The right eigenvector x and the left eigenvector y of (S,P) */
569 /* > corresponding to an eigenvalue w are defined by: */
570 /* > */
571 /* >    S*x = w*P*x,  (y**H)*S = w*(y**H)*P, */
572 /* > */
573 /* > where y**H denotes the conjugate tranpose of y. */
574 /* > The eigenvalues are not input to this routine, but are computed */
575 /* > directly from the diagonal elements of S and P. */
576 /* > */
577 /* > This routine returns the matrices X and/or Y of right and left */
578 /* > eigenvectors of (S,P), or the products Z*X and/or Q*Y, */
579 /* > where Z and Q are input matrices. */
580 /* > If Q and Z are the unitary factors from the generalized Schur */
581 /* > factorization of a matrix pair (A,B), then Z*X and Q*Y */
582 /* > are the matrices of right and left eigenvectors of (A,B). */
583 /* > \endverbatim */
584
585 /*  Arguments: */
586 /*  ========== */
587
588 /* > \param[in] SIDE */
589 /* > \verbatim */
590 /* >          SIDE is CHARACTER*1 */
591 /* >          = 'R': compute right eigenvectors only; */
592 /* >          = 'L': compute left eigenvectors only; */
593 /* >          = 'B': compute both right and left eigenvectors. */
594 /* > \endverbatim */
595 /* > */
596 /* > \param[in] HOWMNY */
597 /* > \verbatim */
598 /* >          HOWMNY is CHARACTER*1 */
599 /* >          = 'A': compute all right and/or left eigenvectors; */
600 /* >          = 'B': compute all right and/or left eigenvectors, */
601 /* >                 backtransformed by the matrices in VR and/or VL; */
602 /* >          = 'S': compute selected right and/or left eigenvectors, */
603 /* >                 specified by the logical array SELECT. */
604 /* > \endverbatim */
605 /* > */
606 /* > \param[in] SELECT */
607 /* > \verbatim */
608 /* >          SELECT is LOGICAL array, dimension (N) */
609 /* >          If HOWMNY='S', SELECT specifies the eigenvectors to be */
610 /* >          computed.  The eigenvector corresponding to the j-th */
611 /* >          eigenvalue is computed if SELECT(j) = .TRUE.. */
612 /* >          Not referenced if HOWMNY = 'A' or 'B'. */
613 /* > \endverbatim */
614 /* > */
615 /* > \param[in] N */
616 /* > \verbatim */
617 /* >          N is INTEGER */
618 /* >          The order of the matrices S and P.  N >= 0. */
619 /* > \endverbatim */
620 /* > */
621 /* > \param[in] S */
622 /* > \verbatim */
623 /* >          S is COMPLEX array, dimension (LDS,N) */
624 /* >          The upper triangular matrix S from a generalized Schur */
625 /* >          factorization, as computed by CHGEQZ. */
626 /* > \endverbatim */
627 /* > */
628 /* > \param[in] LDS */
629 /* > \verbatim */
630 /* >          LDS is INTEGER */
631 /* >          The leading dimension of array S.  LDS >= f2cmax(1,N). */
632 /* > \endverbatim */
633 /* > */
634 /* > \param[in] P */
635 /* > \verbatim */
636 /* >          P is COMPLEX array, dimension (LDP,N) */
637 /* >          The upper triangular matrix P from a generalized Schur */
638 /* >          factorization, as computed by CHGEQZ.  P must have real */
639 /* >          diagonal elements. */
640 /* > \endverbatim */
641 /* > */
642 /* > \param[in] LDP */
643 /* > \verbatim */
644 /* >          LDP is INTEGER */
645 /* >          The leading dimension of array P.  LDP >= f2cmax(1,N). */
646 /* > \endverbatim */
647 /* > */
648 /* > \param[in,out] VL */
649 /* > \verbatim */
650 /* >          VL is COMPLEX array, dimension (LDVL,MM) */
651 /* >          On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must */
652 /* >          contain an N-by-N matrix Q (usually the unitary matrix Q */
653 /* >          of left Schur vectors returned by CHGEQZ). */
654 /* >          On exit, if SIDE = 'L' or 'B', VL contains: */
655 /* >          if HOWMNY = 'A', the matrix Y of left eigenvectors of (S,P); */
656 /* >          if HOWMNY = 'B', the matrix Q*Y; */
657 /* >          if HOWMNY = 'S', the left eigenvectors of (S,P) specified by */
658 /* >                      SELECT, stored consecutively in the columns of */
659 /* >                      VL, in the same order as their eigenvalues. */
660 /* >          Not referenced if SIDE = 'R'. */
661 /* > \endverbatim */
662 /* > */
663 /* > \param[in] LDVL */
664 /* > \verbatim */
665 /* >          LDVL is INTEGER */
666 /* >          The leading dimension of array VL.  LDVL >= 1, and if */
667 /* >          SIDE = 'L' or 'l' or 'B' or 'b', LDVL >= N. */
668 /* > \endverbatim */
669 /* > */
670 /* > \param[in,out] VR */
671 /* > \verbatim */
672 /* >          VR is COMPLEX array, dimension (LDVR,MM) */
673 /* >          On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must */
674 /* >          contain an N-by-N matrix Q (usually the unitary matrix Z */
675 /* >          of right Schur vectors returned by CHGEQZ). */
676 /* >          On exit, if SIDE = 'R' or 'B', VR contains: */
677 /* >          if HOWMNY = 'A', the matrix X of right eigenvectors of (S,P); */
678 /* >          if HOWMNY = 'B', the matrix Z*X; */
679 /* >          if HOWMNY = 'S', the right eigenvectors of (S,P) specified by */
680 /* >                      SELECT, stored consecutively in the columns of */
681 /* >                      VR, in the same order as their eigenvalues. */
682 /* >          Not referenced if SIDE = 'L'. */
683 /* > \endverbatim */
684 /* > */
685 /* > \param[in] LDVR */
686 /* > \verbatim */
687 /* >          LDVR is INTEGER */
688 /* >          The leading dimension of the array VR.  LDVR >= 1, and if */
689 /* >          SIDE = 'R' or 'B', LDVR >= N. */
690 /* > \endverbatim */
691 /* > */
692 /* > \param[in] MM */
693 /* > \verbatim */
694 /* >          MM is INTEGER */
695 /* >          The number of columns in the arrays VL and/or VR. MM >= M. */
696 /* > \endverbatim */
697 /* > */
698 /* > \param[out] M */
699 /* > \verbatim */
700 /* >          M is INTEGER */
701 /* >          The number of columns in the arrays VL and/or VR actually */
702 /* >          used to store the eigenvectors.  If HOWMNY = 'A' or 'B', M */
703 /* >          is set to N.  Each selected eigenvector occupies one column. */
704 /* > \endverbatim */
705 /* > */
706 /* > \param[out] WORK */
707 /* > \verbatim */
708 /* >          WORK is COMPLEX array, dimension (2*N) */
709 /* > \endverbatim */
710 /* > */
711 /* > \param[out] RWORK */
712 /* > \verbatim */
713 /* >          RWORK is REAL array, dimension (2*N) */
714 /* > \endverbatim */
715 /* > */
716 /* > \param[out] INFO */
717 /* > \verbatim */
718 /* >          INFO is INTEGER */
719 /* >          = 0:  successful exit. */
720 /* >          < 0:  if INFO = -i, the i-th argument had an illegal value. */
721 /* > \endverbatim */
722
723 /*  Authors: */
724 /*  ======== */
725
726 /* > \author Univ. of Tennessee */
727 /* > \author Univ. of California Berkeley */
728 /* > \author Univ. of Colorado Denver */
729 /* > \author NAG Ltd. */
730
731 /* > \date December 2016 */
732
733 /* > \ingroup complexGEcomputational */
734
735 /*  ===================================================================== */
736 /* Subroutine */ int ctgevc_(char *side, char *howmny, logical *select, 
737         integer *n, complex *s, integer *lds, complex *p, integer *ldp, 
738         complex *vl, integer *ldvl, complex *vr, integer *ldvr, integer *mm, 
739         integer *m, complex *work, real *rwork, integer *info)
740 {
741     /* System generated locals */
742     integer p_dim1, p_offset, s_dim1, s_offset, vl_dim1, vl_offset, vr_dim1, 
743             vr_offset, i__1, i__2, i__3, i__4, i__5;
744     real r__1, r__2, r__3, r__4, r__5, r__6;
745     complex q__1, q__2, q__3, q__4;
746
747     /* Local variables */
748     integer ibeg, ieig, iend;
749     real dmin__;
750     integer isrc;
751     real temp;
752     complex suma, sumb;
753     real xmax;
754     complex d__;
755     integer i__, j;
756     real scale;
757     logical ilall;
758     integer iside;
759     real sbeta;
760     extern logical lsame_(char *, char *);
761     extern /* Subroutine */ int cgemv_(char *, integer *, integer *, complex *
762             , complex *, integer *, complex *, integer *, complex *, complex *
763             , integer *);
764     real small;
765     logical compl;
766     real anorm, bnorm;
767     logical compr;
768     complex ca, cb;
769     logical ilbbad;
770     real acoefa;
771     integer je;
772     real bcoefa, acoeff;
773     complex bcoeff;
774     logical ilback;
775     integer im;
776     extern /* Subroutine */ int slabad_(real *, real *);
777     real ascale, bscale;
778     integer jr;
779     extern /* Complex */ VOID cladiv_(complex *, complex *, complex *);
780     extern real slamch_(char *);
781     complex salpha;
782     real safmin;
783     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
784     real bignum;
785     logical ilcomp;
786     integer ihwmny;
787     real big;
788     logical lsa, lsb;
789     real ulp;
790     complex sum;
791
792
793 /*  -- LAPACK computational routine (version 3.7.0) -- */
794 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
795 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
796 /*     December 2016 */
797
798
799
800 /*  ===================================================================== */
801
802
803 /*     Decode and Test the input parameters */
804
805     /* Parameter adjustments */
806     --select;
807     s_dim1 = *lds;
808     s_offset = 1 + s_dim1 * 1;
809     s -= s_offset;
810     p_dim1 = *ldp;
811     p_offset = 1 + p_dim1 * 1;
812     p -= p_offset;
813     vl_dim1 = *ldvl;
814     vl_offset = 1 + vl_dim1 * 1;
815     vl -= vl_offset;
816     vr_dim1 = *ldvr;
817     vr_offset = 1 + vr_dim1 * 1;
818     vr -= vr_offset;
819     --work;
820     --rwork;
821
822     /* Function Body */
823     if (lsame_(howmny, "A")) {
824         ihwmny = 1;
825         ilall = TRUE_;
826         ilback = FALSE_;
827     } else if (lsame_(howmny, "S")) {
828         ihwmny = 2;
829         ilall = FALSE_;
830         ilback = FALSE_;
831     } else if (lsame_(howmny, "B")) {
832         ihwmny = 3;
833         ilall = TRUE_;
834         ilback = TRUE_;
835     } else {
836         ihwmny = -1;
837     }
838
839     if (lsame_(side, "R")) {
840         iside = 1;
841         compl = FALSE_;
842         compr = TRUE_;
843     } else if (lsame_(side, "L")) {
844         iside = 2;
845         compl = TRUE_;
846         compr = FALSE_;
847     } else if (lsame_(side, "B")) {
848         iside = 3;
849         compl = TRUE_;
850         compr = TRUE_;
851     } else {
852         iside = -1;
853     }
854
855     *info = 0;
856     if (iside < 0) {
857         *info = -1;
858     } else if (ihwmny < 0) {
859         *info = -2;
860     } else if (*n < 0) {
861         *info = -4;
862     } else if (*lds < f2cmax(1,*n)) {
863         *info = -6;
864     } else if (*ldp < f2cmax(1,*n)) {
865         *info = -8;
866     }
867     if (*info != 0) {
868         i__1 = -(*info);
869         xerbla_("CTGEVC", &i__1, (ftnlen)6);
870         return 0;
871     }
872
873 /*     Count the number of eigenvectors */
874
875     if (! ilall) {
876         im = 0;
877         i__1 = *n;
878         for (j = 1; j <= i__1; ++j) {
879             if (select[j]) {
880                 ++im;
881             }
882 /* L10: */
883         }
884     } else {
885         im = *n;
886     }
887
888 /*     Check diagonal of B */
889
890     ilbbad = FALSE_;
891     i__1 = *n;
892     for (j = 1; j <= i__1; ++j) {
893         if (r_imag(&p[j + j * p_dim1]) != 0.f) {
894             ilbbad = TRUE_;
895         }
896 /* L20: */
897     }
898
899     if (ilbbad) {
900         *info = -7;
901     } else if (compl && *ldvl < *n || *ldvl < 1) {
902         *info = -10;
903     } else if (compr && *ldvr < *n || *ldvr < 1) {
904         *info = -12;
905     } else if (*mm < im) {
906         *info = -13;
907     }
908     if (*info != 0) {
909         i__1 = -(*info);
910         xerbla_("CTGEVC", &i__1, (ftnlen)6);
911         return 0;
912     }
913
914 /*     Quick return if possible */
915
916     *m = im;
917     if (*n == 0) {
918         return 0;
919     }
920
921 /*     Machine Constants */
922
923     safmin = slamch_("Safe minimum");
924     big = 1.f / safmin;
925     slabad_(&safmin, &big);
926     ulp = slamch_("Epsilon") * slamch_("Base");
927     small = safmin * *n / ulp;
928     big = 1.f / small;
929     bignum = 1.f / (safmin * *n);
930
931 /*     Compute the 1-norm of each column of the strictly upper triangular */
932 /*     part of A and B to check for possible overflow in the triangular */
933 /*     solver. */
934
935     i__1 = s_dim1 + 1;
936     anorm = (r__1 = s[i__1].r, abs(r__1)) + (r__2 = r_imag(&s[s_dim1 + 1]), 
937             abs(r__2));
938     i__1 = p_dim1 + 1;
939     bnorm = (r__1 = p[i__1].r, abs(r__1)) + (r__2 = r_imag(&p[p_dim1 + 1]), 
940             abs(r__2));
941     rwork[1] = 0.f;
942     rwork[*n + 1] = 0.f;
943     i__1 = *n;
944     for (j = 2; j <= i__1; ++j) {
945         rwork[j] = 0.f;
946         rwork[*n + j] = 0.f;
947         i__2 = j - 1;
948         for (i__ = 1; i__ <= i__2; ++i__) {
949             i__3 = i__ + j * s_dim1;
950             rwork[j] += (r__1 = s[i__3].r, abs(r__1)) + (r__2 = r_imag(&s[i__ 
951                     + j * s_dim1]), abs(r__2));
952             i__3 = i__ + j * p_dim1;
953             rwork[*n + j] += (r__1 = p[i__3].r, abs(r__1)) + (r__2 = r_imag(&
954                     p[i__ + j * p_dim1]), abs(r__2));
955 /* L30: */
956         }
957 /* Computing MAX */
958         i__2 = j + j * s_dim1;
959         r__3 = anorm, r__4 = rwork[j] + ((r__1 = s[i__2].r, abs(r__1)) + (
960                 r__2 = r_imag(&s[j + j * s_dim1]), abs(r__2)));
961         anorm = f2cmax(r__3,r__4);
962 /* Computing MAX */
963         i__2 = j + j * p_dim1;
964         r__3 = bnorm, r__4 = rwork[*n + j] + ((r__1 = p[i__2].r, abs(r__1)) + 
965                 (r__2 = r_imag(&p[j + j * p_dim1]), abs(r__2)));
966         bnorm = f2cmax(r__3,r__4);
967 /* L40: */
968     }
969
970     ascale = 1.f / f2cmax(anorm,safmin);
971     bscale = 1.f / f2cmax(bnorm,safmin);
972
973 /*     Left eigenvectors */
974
975     if (compl) {
976         ieig = 0;
977
978 /*        Main loop over eigenvalues */
979
980         i__1 = *n;
981         for (je = 1; je <= i__1; ++je) {
982             if (ilall) {
983                 ilcomp = TRUE_;
984             } else {
985                 ilcomp = select[je];
986             }
987             if (ilcomp) {
988                 ++ieig;
989
990                 i__2 = je + je * s_dim1;
991                 i__3 = je + je * p_dim1;
992                 if ((r__2 = s[i__2].r, abs(r__2)) + (r__3 = r_imag(&s[je + je 
993                         * s_dim1]), abs(r__3)) <= safmin && (r__1 = p[i__3].r,
994                          abs(r__1)) <= safmin) {
995
996 /*                 Singular matrix pencil -- return unit eigenvector */
997
998                     i__2 = *n;
999                     for (jr = 1; jr <= i__2; ++jr) {
1000                         i__3 = jr + ieig * vl_dim1;
1001                         vl[i__3].r = 0.f, vl[i__3].i = 0.f;
1002 /* L50: */
1003                     }
1004                     i__2 = ieig + ieig * vl_dim1;
1005                     vl[i__2].r = 1.f, vl[i__2].i = 0.f;
1006                     goto L140;
1007                 }
1008
1009 /*              Non-singular eigenvalue: */
1010 /*              Compute coefficients  a  and  b  in */
1011 /*                   H */
1012 /*                 y  ( a A - b B ) = 0 */
1013
1014 /* Computing MAX */
1015                 i__2 = je + je * s_dim1;
1016                 i__3 = je + je * p_dim1;
1017                 r__4 = ((r__2 = s[i__2].r, abs(r__2)) + (r__3 = r_imag(&s[je 
1018                         + je * s_dim1]), abs(r__3))) * ascale, r__5 = (r__1 = 
1019                         p[i__3].r, abs(r__1)) * bscale, r__4 = f2cmax(r__4,r__5);
1020                 temp = 1.f / f2cmax(r__4,safmin);
1021                 i__2 = je + je * s_dim1;
1022                 q__2.r = temp * s[i__2].r, q__2.i = temp * s[i__2].i;
1023                 q__1.r = ascale * q__2.r, q__1.i = ascale * q__2.i;
1024                 salpha.r = q__1.r, salpha.i = q__1.i;
1025                 i__2 = je + je * p_dim1;
1026                 sbeta = temp * p[i__2].r * bscale;
1027                 acoeff = sbeta * ascale;
1028                 q__1.r = bscale * salpha.r, q__1.i = bscale * salpha.i;
1029                 bcoeff.r = q__1.r, bcoeff.i = q__1.i;
1030
1031 /*              Scale to avoid underflow */
1032
1033                 lsa = abs(sbeta) >= safmin && abs(acoeff) < small;
1034                 lsb = (r__1 = salpha.r, abs(r__1)) + (r__2 = r_imag(&salpha), 
1035                         abs(r__2)) >= safmin && (r__3 = bcoeff.r, abs(r__3)) 
1036                         + (r__4 = r_imag(&bcoeff), abs(r__4)) < small;
1037
1038                 scale = 1.f;
1039                 if (lsa) {
1040                     scale = small / abs(sbeta) * f2cmin(anorm,big);
1041                 }
1042                 if (lsb) {
1043 /* Computing MAX */
1044                     r__3 = scale, r__4 = small / ((r__1 = salpha.r, abs(r__1))
1045                              + (r__2 = r_imag(&salpha), abs(r__2))) * f2cmin(
1046                             bnorm,big);
1047                     scale = f2cmax(r__3,r__4);
1048                 }
1049                 if (lsa || lsb) {
1050 /* Computing MIN */
1051 /* Computing MAX */
1052                     r__5 = 1.f, r__6 = abs(acoeff), r__5 = f2cmax(r__5,r__6), 
1053                             r__6 = (r__1 = bcoeff.r, abs(r__1)) + (r__2 = 
1054                             r_imag(&bcoeff), abs(r__2));
1055                     r__3 = scale, r__4 = 1.f / (safmin * f2cmax(r__5,r__6));
1056                     scale = f2cmin(r__3,r__4);
1057                     if (lsa) {
1058                         acoeff = ascale * (scale * sbeta);
1059                     } else {
1060                         acoeff = scale * acoeff;
1061                     }
1062                     if (lsb) {
1063                         q__2.r = scale * salpha.r, q__2.i = scale * salpha.i;
1064                         q__1.r = bscale * q__2.r, q__1.i = bscale * q__2.i;
1065                         bcoeff.r = q__1.r, bcoeff.i = q__1.i;
1066                     } else {
1067                         q__1.r = scale * bcoeff.r, q__1.i = scale * bcoeff.i;
1068                         bcoeff.r = q__1.r, bcoeff.i = q__1.i;
1069                     }
1070                 }
1071
1072                 acoefa = abs(acoeff);
1073                 bcoefa = (r__1 = bcoeff.r, abs(r__1)) + (r__2 = r_imag(&
1074                         bcoeff), abs(r__2));
1075                 xmax = 1.f;
1076                 i__2 = *n;
1077                 for (jr = 1; jr <= i__2; ++jr) {
1078                     i__3 = jr;
1079                     work[i__3].r = 0.f, work[i__3].i = 0.f;
1080 /* L60: */
1081                 }
1082                 i__2 = je;
1083                 work[i__2].r = 1.f, work[i__2].i = 0.f;
1084 /* Computing MAX */
1085                 r__1 = ulp * acoefa * anorm, r__2 = ulp * bcoefa * bnorm, 
1086                         r__1 = f2cmax(r__1,r__2);
1087                 dmin__ = f2cmax(r__1,safmin);
1088
1089 /*                                              H */
1090 /*              Triangular solve of  (a A - b B)  y = 0 */
1091
1092 /*                                      H */
1093 /*              (rowwise in  (a A - b B) , or columnwise in a A - b B) */
1094
1095                 i__2 = *n;
1096                 for (j = je + 1; j <= i__2; ++j) {
1097
1098 /*                 Compute */
1099 /*                       j-1 */
1100 /*                 SUM = sum  conjg( a*S(k,j) - b*P(k,j) )*x(k) */
1101 /*                       k=je */
1102 /*                 (Scale if necessary) */
1103
1104                     temp = 1.f / xmax;
1105                     if (acoefa * rwork[j] + bcoefa * rwork[*n + j] > bignum * 
1106                             temp) {
1107                         i__3 = j - 1;
1108                         for (jr = je; jr <= i__3; ++jr) {
1109                             i__4 = jr;
1110                             i__5 = jr;
1111                             q__1.r = temp * work[i__5].r, q__1.i = temp * 
1112                                     work[i__5].i;
1113                             work[i__4].r = q__1.r, work[i__4].i = q__1.i;
1114 /* L70: */
1115                         }
1116                         xmax = 1.f;
1117                     }
1118                     suma.r = 0.f, suma.i = 0.f;
1119                     sumb.r = 0.f, sumb.i = 0.f;
1120
1121                     i__3 = j - 1;
1122                     for (jr = je; jr <= i__3; ++jr) {
1123                         r_cnjg(&q__3, &s[jr + j * s_dim1]);
1124                         i__4 = jr;
1125                         q__2.r = q__3.r * work[i__4].r - q__3.i * work[i__4]
1126                                 .i, q__2.i = q__3.r * work[i__4].i + q__3.i * 
1127                                 work[i__4].r;
1128                         q__1.r = suma.r + q__2.r, q__1.i = suma.i + q__2.i;
1129                         suma.r = q__1.r, suma.i = q__1.i;
1130                         r_cnjg(&q__3, &p[jr + j * p_dim1]);
1131                         i__4 = jr;
1132                         q__2.r = q__3.r * work[i__4].r - q__3.i * work[i__4]
1133                                 .i, q__2.i = q__3.r * work[i__4].i + q__3.i * 
1134                                 work[i__4].r;
1135                         q__1.r = sumb.r + q__2.r, q__1.i = sumb.i + q__2.i;
1136                         sumb.r = q__1.r, sumb.i = q__1.i;
1137 /* L80: */
1138                     }
1139                     q__2.r = acoeff * suma.r, q__2.i = acoeff * suma.i;
1140                     r_cnjg(&q__4, &bcoeff);
1141                     q__3.r = q__4.r * sumb.r - q__4.i * sumb.i, q__3.i = 
1142                             q__4.r * sumb.i + q__4.i * sumb.r;
1143                     q__1.r = q__2.r - q__3.r, q__1.i = q__2.i - q__3.i;
1144                     sum.r = q__1.r, sum.i = q__1.i;
1145
1146 /*                 Form x(j) = - SUM / conjg( a*S(j,j) - b*P(j,j) ) */
1147
1148 /*                 with scaling and perturbation of the denominator */
1149
1150                     i__3 = j + j * s_dim1;
1151                     q__3.r = acoeff * s[i__3].r, q__3.i = acoeff * s[i__3].i;
1152                     i__4 = j + j * p_dim1;
1153                     q__4.r = bcoeff.r * p[i__4].r - bcoeff.i * p[i__4].i, 
1154                             q__4.i = bcoeff.r * p[i__4].i + bcoeff.i * p[i__4]
1155                             .r;
1156                     q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
1157                     r_cnjg(&q__1, &q__2);
1158                     d__.r = q__1.r, d__.i = q__1.i;
1159                     if ((r__1 = d__.r, abs(r__1)) + (r__2 = r_imag(&d__), abs(
1160                             r__2)) <= dmin__) {
1161                         q__1.r = dmin__, q__1.i = 0.f;
1162                         d__.r = q__1.r, d__.i = q__1.i;
1163                     }
1164
1165                     if ((r__1 = d__.r, abs(r__1)) + (r__2 = r_imag(&d__), abs(
1166                             r__2)) < 1.f) {
1167                         if ((r__1 = sum.r, abs(r__1)) + (r__2 = r_imag(&sum), 
1168                                 abs(r__2)) >= bignum * ((r__3 = d__.r, abs(
1169                                 r__3)) + (r__4 = r_imag(&d__), abs(r__4)))) {
1170                             temp = 1.f / ((r__1 = sum.r, abs(r__1)) + (r__2 = 
1171                                     r_imag(&sum), abs(r__2)));
1172                             i__3 = j - 1;
1173                             for (jr = je; jr <= i__3; ++jr) {
1174                                 i__4 = jr;
1175                                 i__5 = jr;
1176                                 q__1.r = temp * work[i__5].r, q__1.i = temp * 
1177                                         work[i__5].i;
1178                                 work[i__4].r = q__1.r, work[i__4].i = q__1.i;
1179 /* L90: */
1180                             }
1181                             xmax = temp * xmax;
1182                             q__1.r = temp * sum.r, q__1.i = temp * sum.i;
1183                             sum.r = q__1.r, sum.i = q__1.i;
1184                         }
1185                     }
1186                     i__3 = j;
1187                     q__2.r = -sum.r, q__2.i = -sum.i;
1188                     cladiv_(&q__1, &q__2, &d__);
1189                     work[i__3].r = q__1.r, work[i__3].i = q__1.i;
1190 /* Computing MAX */
1191                     i__3 = j;
1192                     r__3 = xmax, r__4 = (r__1 = work[i__3].r, abs(r__1)) + (
1193                             r__2 = r_imag(&work[j]), abs(r__2));
1194                     xmax = f2cmax(r__3,r__4);
1195 /* L100: */
1196                 }
1197
1198 /*              Back transform eigenvector if HOWMNY='B'. */
1199
1200                 if (ilback) {
1201                     i__2 = *n + 1 - je;
1202                     cgemv_("N", n, &i__2, &c_b2, &vl[je * vl_dim1 + 1], ldvl, 
1203                             &work[je], &c__1, &c_b1, &work[*n + 1], &c__1);
1204                     isrc = 2;
1205                     ibeg = 1;
1206                 } else {
1207                     isrc = 1;
1208                     ibeg = je;
1209                 }
1210
1211 /*              Copy and scale eigenvector into column of VL */
1212
1213                 xmax = 0.f;
1214                 i__2 = *n;
1215                 for (jr = ibeg; jr <= i__2; ++jr) {
1216 /* Computing MAX */
1217                     i__3 = (isrc - 1) * *n + jr;
1218                     r__3 = xmax, r__4 = (r__1 = work[i__3].r, abs(r__1)) + (
1219                             r__2 = r_imag(&work[(isrc - 1) * *n + jr]), abs(
1220                             r__2));
1221                     xmax = f2cmax(r__3,r__4);
1222 /* L110: */
1223                 }
1224
1225                 if (xmax > safmin) {
1226                     temp = 1.f / xmax;
1227                     i__2 = *n;
1228                     for (jr = ibeg; jr <= i__2; ++jr) {
1229                         i__3 = jr + ieig * vl_dim1;
1230                         i__4 = (isrc - 1) * *n + jr;
1231                         q__1.r = temp * work[i__4].r, q__1.i = temp * work[
1232                                 i__4].i;
1233                         vl[i__3].r = q__1.r, vl[i__3].i = q__1.i;
1234 /* L120: */
1235                     }
1236                 } else {
1237                     ibeg = *n + 1;
1238                 }
1239
1240                 i__2 = ibeg - 1;
1241                 for (jr = 1; jr <= i__2; ++jr) {
1242                     i__3 = jr + ieig * vl_dim1;
1243                     vl[i__3].r = 0.f, vl[i__3].i = 0.f;
1244 /* L130: */
1245                 }
1246
1247             }
1248 L140:
1249             ;
1250         }
1251     }
1252
1253 /*     Right eigenvectors */
1254
1255     if (compr) {
1256         ieig = im + 1;
1257
1258 /*        Main loop over eigenvalues */
1259
1260         for (je = *n; je >= 1; --je) {
1261             if (ilall) {
1262                 ilcomp = TRUE_;
1263             } else {
1264                 ilcomp = select[je];
1265             }
1266             if (ilcomp) {
1267                 --ieig;
1268
1269                 i__1 = je + je * s_dim1;
1270                 i__2 = je + je * p_dim1;
1271                 if ((r__2 = s[i__1].r, abs(r__2)) + (r__3 = r_imag(&s[je + je 
1272                         * s_dim1]), abs(r__3)) <= safmin && (r__1 = p[i__2].r,
1273                          abs(r__1)) <= safmin) {
1274
1275 /*                 Singular matrix pencil -- return unit eigenvector */
1276
1277                     i__1 = *n;
1278                     for (jr = 1; jr <= i__1; ++jr) {
1279                         i__2 = jr + ieig * vr_dim1;
1280                         vr[i__2].r = 0.f, vr[i__2].i = 0.f;
1281 /* L150: */
1282                     }
1283                     i__1 = ieig + ieig * vr_dim1;
1284                     vr[i__1].r = 1.f, vr[i__1].i = 0.f;
1285                     goto L250;
1286                 }
1287
1288 /*              Non-singular eigenvalue: */
1289 /*              Compute coefficients  a  and  b  in */
1290
1291 /*              ( a A - b B ) x  = 0 */
1292
1293 /* Computing MAX */
1294                 i__1 = je + je * s_dim1;
1295                 i__2 = je + je * p_dim1;
1296                 r__4 = ((r__2 = s[i__1].r, abs(r__2)) + (r__3 = r_imag(&s[je 
1297                         + je * s_dim1]), abs(r__3))) * ascale, r__5 = (r__1 = 
1298                         p[i__2].r, abs(r__1)) * bscale, r__4 = f2cmax(r__4,r__5);
1299                 temp = 1.f / f2cmax(r__4,safmin);
1300                 i__1 = je + je * s_dim1;
1301                 q__2.r = temp * s[i__1].r, q__2.i = temp * s[i__1].i;
1302                 q__1.r = ascale * q__2.r, q__1.i = ascale * q__2.i;
1303                 salpha.r = q__1.r, salpha.i = q__1.i;
1304                 i__1 = je + je * p_dim1;
1305                 sbeta = temp * p[i__1].r * bscale;
1306                 acoeff = sbeta * ascale;
1307                 q__1.r = bscale * salpha.r, q__1.i = bscale * salpha.i;
1308                 bcoeff.r = q__1.r, bcoeff.i = q__1.i;
1309
1310 /*              Scale to avoid underflow */
1311
1312                 lsa = abs(sbeta) >= safmin && abs(acoeff) < small;
1313                 lsb = (r__1 = salpha.r, abs(r__1)) + (r__2 = r_imag(&salpha), 
1314                         abs(r__2)) >= safmin && (r__3 = bcoeff.r, abs(r__3)) 
1315                         + (r__4 = r_imag(&bcoeff), abs(r__4)) < small;
1316
1317                 scale = 1.f;
1318                 if (lsa) {
1319                     scale = small / abs(sbeta) * f2cmin(anorm,big);
1320                 }
1321                 if (lsb) {
1322 /* Computing MAX */
1323                     r__3 = scale, r__4 = small / ((r__1 = salpha.r, abs(r__1))
1324                              + (r__2 = r_imag(&salpha), abs(r__2))) * f2cmin(
1325                             bnorm,big);
1326                     scale = f2cmax(r__3,r__4);
1327                 }
1328                 if (lsa || lsb) {
1329 /* Computing MIN */
1330 /* Computing MAX */
1331                     r__5 = 1.f, r__6 = abs(acoeff), r__5 = f2cmax(r__5,r__6), 
1332                             r__6 = (r__1 = bcoeff.r, abs(r__1)) + (r__2 = 
1333                             r_imag(&bcoeff), abs(r__2));
1334                     r__3 = scale, r__4 = 1.f / (safmin * f2cmax(r__5,r__6));
1335                     scale = f2cmin(r__3,r__4);
1336                     if (lsa) {
1337                         acoeff = ascale * (scale * sbeta);
1338                     } else {
1339                         acoeff = scale * acoeff;
1340                     }
1341                     if (lsb) {
1342                         q__2.r = scale * salpha.r, q__2.i = scale * salpha.i;
1343                         q__1.r = bscale * q__2.r, q__1.i = bscale * q__2.i;
1344                         bcoeff.r = q__1.r, bcoeff.i = q__1.i;
1345                     } else {
1346                         q__1.r = scale * bcoeff.r, q__1.i = scale * bcoeff.i;
1347                         bcoeff.r = q__1.r, bcoeff.i = q__1.i;
1348                     }
1349                 }
1350
1351                 acoefa = abs(acoeff);
1352                 bcoefa = (r__1 = bcoeff.r, abs(r__1)) + (r__2 = r_imag(&
1353                         bcoeff), abs(r__2));
1354                 xmax = 1.f;
1355                 i__1 = *n;
1356                 for (jr = 1; jr <= i__1; ++jr) {
1357                     i__2 = jr;
1358                     work[i__2].r = 0.f, work[i__2].i = 0.f;
1359 /* L160: */
1360                 }
1361                 i__1 = je;
1362                 work[i__1].r = 1.f, work[i__1].i = 0.f;
1363 /* Computing MAX */
1364                 r__1 = ulp * acoefa * anorm, r__2 = ulp * bcoefa * bnorm, 
1365                         r__1 = f2cmax(r__1,r__2);
1366                 dmin__ = f2cmax(r__1,safmin);
1367
1368 /*              Triangular solve of  (a A - b B) x = 0  (columnwise) */
1369
1370 /*              WORK(1:j-1) contains sums w, */
1371 /*              WORK(j+1:JE) contains x */
1372
1373                 i__1 = je - 1;
1374                 for (jr = 1; jr <= i__1; ++jr) {
1375                     i__2 = jr;
1376                     i__3 = jr + je * s_dim1;
1377                     q__2.r = acoeff * s[i__3].r, q__2.i = acoeff * s[i__3].i;
1378                     i__4 = jr + je * p_dim1;
1379                     q__3.r = bcoeff.r * p[i__4].r - bcoeff.i * p[i__4].i, 
1380                             q__3.i = bcoeff.r * p[i__4].i + bcoeff.i * p[i__4]
1381                             .r;
1382                     q__1.r = q__2.r - q__3.r, q__1.i = q__2.i - q__3.i;
1383                     work[i__2].r = q__1.r, work[i__2].i = q__1.i;
1384 /* L170: */
1385                 }
1386                 i__1 = je;
1387                 work[i__1].r = 1.f, work[i__1].i = 0.f;
1388
1389                 for (j = je - 1; j >= 1; --j) {
1390
1391 /*                 Form x(j) := - w(j) / d */
1392 /*                 with scaling and perturbation of the denominator */
1393
1394                     i__1 = j + j * s_dim1;
1395                     q__2.r = acoeff * s[i__1].r, q__2.i = acoeff * s[i__1].i;
1396                     i__2 = j + j * p_dim1;
1397                     q__3.r = bcoeff.r * p[i__2].r - bcoeff.i * p[i__2].i, 
1398                             q__3.i = bcoeff.r * p[i__2].i + bcoeff.i * p[i__2]
1399                             .r;
1400                     q__1.r = q__2.r - q__3.r, q__1.i = q__2.i - q__3.i;
1401                     d__.r = q__1.r, d__.i = q__1.i;
1402                     if ((r__1 = d__.r, abs(r__1)) + (r__2 = r_imag(&d__), abs(
1403                             r__2)) <= dmin__) {
1404                         q__1.r = dmin__, q__1.i = 0.f;
1405                         d__.r = q__1.r, d__.i = q__1.i;
1406                     }
1407
1408                     if ((r__1 = d__.r, abs(r__1)) + (r__2 = r_imag(&d__), abs(
1409                             r__2)) < 1.f) {
1410                         i__1 = j;
1411                         if ((r__1 = work[i__1].r, abs(r__1)) + (r__2 = r_imag(
1412                                 &work[j]), abs(r__2)) >= bignum * ((r__3 = 
1413                                 d__.r, abs(r__3)) + (r__4 = r_imag(&d__), abs(
1414                                 r__4)))) {
1415                             i__1 = j;
1416                             temp = 1.f / ((r__1 = work[i__1].r, abs(r__1)) + (
1417                                     r__2 = r_imag(&work[j]), abs(r__2)));
1418                             i__1 = je;
1419                             for (jr = 1; jr <= i__1; ++jr) {
1420                                 i__2 = jr;
1421                                 i__3 = jr;
1422                                 q__1.r = temp * work[i__3].r, q__1.i = temp * 
1423                                         work[i__3].i;
1424                                 work[i__2].r = q__1.r, work[i__2].i = q__1.i;
1425 /* L180: */
1426                             }
1427                         }
1428                     }
1429
1430                     i__1 = j;
1431                     i__2 = j;
1432                     q__2.r = -work[i__2].r, q__2.i = -work[i__2].i;
1433                     cladiv_(&q__1, &q__2, &d__);
1434                     work[i__1].r = q__1.r, work[i__1].i = q__1.i;
1435
1436                     if (j > 1) {
1437
1438 /*                    w = w + x(j)*(a S(*,j) - b P(*,j) ) with scaling */
1439
1440                         i__1 = j;
1441                         if ((r__1 = work[i__1].r, abs(r__1)) + (r__2 = r_imag(
1442                                 &work[j]), abs(r__2)) > 1.f) {
1443                             i__1 = j;
1444                             temp = 1.f / ((r__1 = work[i__1].r, abs(r__1)) + (
1445                                     r__2 = r_imag(&work[j]), abs(r__2)));
1446                             if (acoefa * rwork[j] + bcoefa * rwork[*n + j] >= 
1447                                     bignum * temp) {
1448                                 i__1 = je;
1449                                 for (jr = 1; jr <= i__1; ++jr) {
1450                                     i__2 = jr;
1451                                     i__3 = jr;
1452                                     q__1.r = temp * work[i__3].r, q__1.i = 
1453                                             temp * work[i__3].i;
1454                                     work[i__2].r = q__1.r, work[i__2].i = 
1455                                             q__1.i;
1456 /* L190: */
1457                                 }
1458                             }
1459                         }
1460
1461                         i__1 = j;
1462                         q__1.r = acoeff * work[i__1].r, q__1.i = acoeff * 
1463                                 work[i__1].i;
1464                         ca.r = q__1.r, ca.i = q__1.i;
1465                         i__1 = j;
1466                         q__1.r = bcoeff.r * work[i__1].r - bcoeff.i * work[
1467                                 i__1].i, q__1.i = bcoeff.r * work[i__1].i + 
1468                                 bcoeff.i * work[i__1].r;
1469                         cb.r = q__1.r, cb.i = q__1.i;
1470                         i__1 = j - 1;
1471                         for (jr = 1; jr <= i__1; ++jr) {
1472                             i__2 = jr;
1473                             i__3 = jr;
1474                             i__4 = jr + j * s_dim1;
1475                             q__3.r = ca.r * s[i__4].r - ca.i * s[i__4].i, 
1476                                     q__3.i = ca.r * s[i__4].i + ca.i * s[i__4]
1477                                     .r;
1478                             q__2.r = work[i__3].r + q__3.r, q__2.i = work[
1479                                     i__3].i + q__3.i;
1480                             i__5 = jr + j * p_dim1;
1481                             q__4.r = cb.r * p[i__5].r - cb.i * p[i__5].i, 
1482                                     q__4.i = cb.r * p[i__5].i + cb.i * p[i__5]
1483                                     .r;
1484                             q__1.r = q__2.r - q__4.r, q__1.i = q__2.i - 
1485                                     q__4.i;
1486                             work[i__2].r = q__1.r, work[i__2].i = q__1.i;
1487 /* L200: */
1488                         }
1489                     }
1490 /* L210: */
1491                 }
1492
1493 /*              Back transform eigenvector if HOWMNY='B'. */
1494
1495                 if (ilback) {
1496                     cgemv_("N", n, &je, &c_b2, &vr[vr_offset], ldvr, &work[1],
1497                              &c__1, &c_b1, &work[*n + 1], &c__1);
1498                     isrc = 2;
1499                     iend = *n;
1500                 } else {
1501                     isrc = 1;
1502                     iend = je;
1503                 }
1504
1505 /*              Copy and scale eigenvector into column of VR */
1506
1507                 xmax = 0.f;
1508                 i__1 = iend;
1509                 for (jr = 1; jr <= i__1; ++jr) {
1510 /* Computing MAX */
1511                     i__2 = (isrc - 1) * *n + jr;
1512                     r__3 = xmax, r__4 = (r__1 = work[i__2].r, abs(r__1)) + (
1513                             r__2 = r_imag(&work[(isrc - 1) * *n + jr]), abs(
1514                             r__2));
1515                     xmax = f2cmax(r__3,r__4);
1516 /* L220: */
1517                 }
1518
1519                 if (xmax > safmin) {
1520                     temp = 1.f / xmax;
1521                     i__1 = iend;
1522                     for (jr = 1; jr <= i__1; ++jr) {
1523                         i__2 = jr + ieig * vr_dim1;
1524                         i__3 = (isrc - 1) * *n + jr;
1525                         q__1.r = temp * work[i__3].r, q__1.i = temp * work[
1526                                 i__3].i;
1527                         vr[i__2].r = q__1.r, vr[i__2].i = q__1.i;
1528 /* L230: */
1529                     }
1530                 } else {
1531                     iend = 0;
1532                 }
1533
1534                 i__1 = *n;
1535                 for (jr = iend + 1; jr <= i__1; ++jr) {
1536                     i__2 = jr + ieig * vr_dim1;
1537                     vr[i__2].r = 0.f, vr[i__2].i = 0.f;
1538 /* L240: */
1539                 }
1540
1541             }
1542 L250:
1543             ;
1544         }
1545     }
1546
1547     return 0;
1548
1549 /*     End of CTGEVC */
1550
1551 } /* ctgevc_ */
1552