C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / dtgevc.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 logical c_true = TRUE_;
516 static integer c__2 = 2;
517 static doublereal c_b34 = 1.;
518 static integer c__1 = 1;
519 static doublereal c_b36 = 0.;
520 static logical c_false = FALSE_;
521
522 /* > \brief \b DTGEVC */
523
524 /*  =========== DOCUMENTATION =========== */
525
526 /* Online html documentation available at */
527 /*            http://www.netlib.org/lapack/explore-html/ */
528
529 /* > \htmlonly */
530 /* > Download DTGEVC + dependencies */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtgevc.
532 f"> */
533 /* > [TGZ]</a> */
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtgevc.
535 f"> */
536 /* > [ZIP]</a> */
537 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtgevc.
538 f"> */
539 /* > [TXT]</a> */
540 /* > \endhtmlonly */
541
542 /*  Definition: */
543 /*  =========== */
544
545 /*       SUBROUTINE DTGEVC( SIDE, HOWMNY, SELECT, N, S, LDS, P, LDP, VL, */
546 /*                          LDVL, VR, LDVR, MM, M, WORK, INFO ) */
547
548 /*       CHARACTER          HOWMNY, SIDE */
549 /*       INTEGER            INFO, LDP, LDS, LDVL, LDVR, M, MM, N */
550 /*       LOGICAL            SELECT( * ) */
551 /*       DOUBLE PRECISION   P( LDP, * ), S( LDS, * ), VL( LDVL, * ), */
552 /*      $                   VR( LDVR, * ), WORK( * ) */
553
554
555
556 /* > \par Purpose: */
557 /*  ============= */
558 /* > */
559 /* > \verbatim */
560 /* > */
561 /* > DTGEVC computes some or all of the right and/or left eigenvectors of */
562 /* > a pair of real matrices (S,P), where S is a quasi-triangular matrix */
563 /* > and P is upper triangular.  Matrix pairs of this type are produced by */
564 /* > the generalized Schur factorization of a matrix pair (A,B): */
565 /* > */
566 /* >    A = Q*S*Z**T,  B = Q*P*Z**T */
567 /* > */
568 /* > as computed by DGGHRD + DHGEQZ. */
569 /* > */
570 /* > The right eigenvector x and the left eigenvector y of (S,P) */
571 /* > corresponding to an eigenvalue w are defined by: */
572 /* > */
573 /* >    S*x = w*P*x,  (y**H)*S = w*(y**H)*P, */
574 /* > */
575 /* > where y**H denotes the conjugate tranpose of y. */
576 /* > The eigenvalues are not input to this routine, but are computed */
577 /* > directly from the diagonal blocks of S and P. */
578 /* > */
579 /* > This routine returns the matrices X and/or Y of right and left */
580 /* > eigenvectors of (S,P), or the products Z*X and/or Q*Y, */
581 /* > where Z and Q are input matrices. */
582 /* > If Q and Z are the orthogonal factors from the generalized Schur */
583 /* > factorization of a matrix pair (A,B), then Z*X and Q*Y */
584 /* > are the matrices of right and left eigenvectors of (A,B). */
585 /* > */
586 /* > \endverbatim */
587
588 /*  Arguments: */
589 /*  ========== */
590
591 /* > \param[in] SIDE */
592 /* > \verbatim */
593 /* >          SIDE is CHARACTER*1 */
594 /* >          = 'R': compute right eigenvectors only; */
595 /* >          = 'L': compute left eigenvectors only; */
596 /* >          = 'B': compute both right and left eigenvectors. */
597 /* > \endverbatim */
598 /* > */
599 /* > \param[in] HOWMNY */
600 /* > \verbatim */
601 /* >          HOWMNY is CHARACTER*1 */
602 /* >          = 'A': compute all right and/or left eigenvectors; */
603 /* >          = 'B': compute all right and/or left eigenvectors, */
604 /* >                 backtransformed by the matrices in VR and/or VL; */
605 /* >          = 'S': compute selected right and/or left eigenvectors, */
606 /* >                 specified by the logical array SELECT. */
607 /* > \endverbatim */
608 /* > */
609 /* > \param[in] SELECT */
610 /* > \verbatim */
611 /* >          SELECT is LOGICAL array, dimension (N) */
612 /* >          If HOWMNY='S', SELECT specifies the eigenvectors to be */
613 /* >          computed.  If w(j) is a real eigenvalue, the corresponding */
614 /* >          real eigenvector is computed if SELECT(j) is .TRUE.. */
615 /* >          If w(j) and w(j+1) are the real and imaginary parts of a */
616 /* >          complex eigenvalue, the corresponding complex eigenvector */
617 /* >          is computed if either SELECT(j) or SELECT(j+1) is .TRUE., */
618 /* >          and on exit SELECT(j) is set to .TRUE. and SELECT(j+1) is */
619 /* >          set to .FALSE.. */
620 /* >          Not referenced if HOWMNY = 'A' or 'B'. */
621 /* > \endverbatim */
622 /* > */
623 /* > \param[in] N */
624 /* > \verbatim */
625 /* >          N is INTEGER */
626 /* >          The order of the matrices S and P.  N >= 0. */
627 /* > \endverbatim */
628 /* > */
629 /* > \param[in] S */
630 /* > \verbatim */
631 /* >          S is DOUBLE PRECISION array, dimension (LDS,N) */
632 /* >          The upper quasi-triangular matrix S from a generalized Schur */
633 /* >          factorization, as computed by DHGEQZ. */
634 /* > \endverbatim */
635 /* > */
636 /* > \param[in] LDS */
637 /* > \verbatim */
638 /* >          LDS is INTEGER */
639 /* >          The leading dimension of array S.  LDS >= f2cmax(1,N). */
640 /* > \endverbatim */
641 /* > */
642 /* > \param[in] P */
643 /* > \verbatim */
644 /* >          P is DOUBLE PRECISION array, dimension (LDP,N) */
645 /* >          The upper triangular matrix P from a generalized Schur */
646 /* >          factorization, as computed by DHGEQZ. */
647 /* >          2-by-2 diagonal blocks of P corresponding to 2-by-2 blocks */
648 /* >          of S must be in positive diagonal form. */
649 /* > \endverbatim */
650 /* > */
651 /* > \param[in] LDP */
652 /* > \verbatim */
653 /* >          LDP is INTEGER */
654 /* >          The leading dimension of array P.  LDP >= f2cmax(1,N). */
655 /* > \endverbatim */
656 /* > */
657 /* > \param[in,out] VL */
658 /* > \verbatim */
659 /* >          VL is DOUBLE PRECISION array, dimension (LDVL,MM) */
660 /* >          On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must */
661 /* >          contain an N-by-N matrix Q (usually the orthogonal matrix Q */
662 /* >          of left Schur vectors returned by DHGEQZ). */
663 /* >          On exit, if SIDE = 'L' or 'B', VL contains: */
664 /* >          if HOWMNY = 'A', the matrix Y of left eigenvectors of (S,P); */
665 /* >          if HOWMNY = 'B', the matrix Q*Y; */
666 /* >          if HOWMNY = 'S', the left eigenvectors of (S,P) specified by */
667 /* >                      SELECT, stored consecutively in the columns of */
668 /* >                      VL, in the same order as their eigenvalues. */
669 /* > */
670 /* >          A complex eigenvector corresponding to a complex eigenvalue */
671 /* >          is stored in two consecutive columns, the first holding the */
672 /* >          real part, and the second the imaginary part. */
673 /* > */
674 /* >          Not referenced if SIDE = 'R'. */
675 /* > \endverbatim */
676 /* > */
677 /* > \param[in] LDVL */
678 /* > \verbatim */
679 /* >          LDVL is INTEGER */
680 /* >          The leading dimension of array VL.  LDVL >= 1, and if */
681 /* >          SIDE = 'L' or 'B', LDVL >= N. */
682 /* > \endverbatim */
683 /* > */
684 /* > \param[in,out] VR */
685 /* > \verbatim */
686 /* >          VR is DOUBLE PRECISION array, dimension (LDVR,MM) */
687 /* >          On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must */
688 /* >          contain an N-by-N matrix Z (usually the orthogonal matrix Z */
689 /* >          of right Schur vectors returned by DHGEQZ). */
690 /* > */
691 /* >          On exit, if SIDE = 'R' or 'B', VR contains: */
692 /* >          if HOWMNY = 'A', the matrix X of right eigenvectors of (S,P); */
693 /* >          if HOWMNY = 'B' or 'b', the matrix Z*X; */
694 /* >          if HOWMNY = 'S' or 's', the right eigenvectors of (S,P) */
695 /* >                      specified by SELECT, stored consecutively in the */
696 /* >                      columns of VR, in the same order as their */
697 /* >                      eigenvalues. */
698 /* > */
699 /* >          A complex eigenvector corresponding to a complex eigenvalue */
700 /* >          is stored in two consecutive columns, the first holding the */
701 /* >          real part and the second the imaginary part. */
702 /* > */
703 /* >          Not referenced if SIDE = 'L'. */
704 /* > \endverbatim */
705 /* > */
706 /* > \param[in] LDVR */
707 /* > \verbatim */
708 /* >          LDVR is INTEGER */
709 /* >          The leading dimension of the array VR.  LDVR >= 1, and if */
710 /* >          SIDE = 'R' or 'B', LDVR >= N. */
711 /* > \endverbatim */
712 /* > */
713 /* > \param[in] MM */
714 /* > \verbatim */
715 /* >          MM is INTEGER */
716 /* >          The number of columns in the arrays VL and/or VR. MM >= M. */
717 /* > \endverbatim */
718 /* > */
719 /* > \param[out] M */
720 /* > \verbatim */
721 /* >          M is INTEGER */
722 /* >          The number of columns in the arrays VL and/or VR actually */
723 /* >          used to store the eigenvectors.  If HOWMNY = 'A' or 'B', M */
724 /* >          is set to N.  Each selected real eigenvector occupies one */
725 /* >          column and each selected complex eigenvector occupies two */
726 /* >          columns. */
727 /* > \endverbatim */
728 /* > */
729 /* > \param[out] WORK */
730 /* > \verbatim */
731 /* >          WORK is DOUBLE PRECISION array, dimension (6*N) */
732 /* > \endverbatim */
733 /* > */
734 /* > \param[out] INFO */
735 /* > \verbatim */
736 /* >          INFO is INTEGER */
737 /* >          = 0:  successful exit. */
738 /* >          < 0:  if INFO = -i, the i-th argument had an illegal value. */
739 /* >          > 0:  the 2-by-2 block (INFO:INFO+1) does not have a complex */
740 /* >                eigenvalue. */
741 /* > \endverbatim */
742
743 /*  Authors: */
744 /*  ======== */
745
746 /* > \author Univ. of Tennessee */
747 /* > \author Univ. of California Berkeley */
748 /* > \author Univ. of Colorado Denver */
749 /* > \author NAG Ltd. */
750
751 /* > \date December 2016 */
752
753 /* > \ingroup doubleGEcomputational */
754
755 /* > \par Further Details: */
756 /*  ===================== */
757 /* > */
758 /* > \verbatim */
759 /* > */
760 /* >  Allocation of workspace: */
761 /* >  ---------- -- --------- */
762 /* > */
763 /* >     WORK( j ) = 1-norm of j-th column of A, above the diagonal */
764 /* >     WORK( N+j ) = 1-norm of j-th column of B, above the diagonal */
765 /* >     WORK( 2*N+1:3*N ) = real part of eigenvector */
766 /* >     WORK( 3*N+1:4*N ) = imaginary part of eigenvector */
767 /* >     WORK( 4*N+1:5*N ) = real part of back-transformed eigenvector */
768 /* >     WORK( 5*N+1:6*N ) = imaginary part of back-transformed eigenvector */
769 /* > */
770 /* >  Rowwise vs. columnwise solution methods: */
771 /* >  ------- --  ---------- -------- ------- */
772 /* > */
773 /* >  Finding a generalized eigenvector consists basically of solving the */
774 /* >  singular triangular system */
775 /* > */
776 /* >   (A - w B) x = 0     (for right) or:   (A - w B)**H y = 0  (for left) */
777 /* > */
778 /* >  Consider finding the i-th right eigenvector (assume all eigenvalues */
779 /* >  are real). The equation to be solved is: */
780 /* >       n                   i */
781 /* >  0 = sum  C(j,k) v(k)  = sum  C(j,k) v(k)     for j = i,. . .,1 */
782 /* >      k=j                 k=j */
783 /* > */
784 /* >  where  C = (A - w B)  (The components v(i+1:n) are 0.) */
785 /* > */
786 /* >  The "rowwise" method is: */
787 /* > */
788 /* >  (1)  v(i) := 1 */
789 /* >  for j = i-1,. . .,1: */
790 /* >                          i */
791 /* >      (2) compute  s = - sum C(j,k) v(k)   and */
792 /* >                        k=j+1 */
793 /* > */
794 /* >      (3) v(j) := s / C(j,j) */
795 /* > */
796 /* >  Step 2 is sometimes called the "dot product" step, since it is an */
797 /* >  inner product between the j-th row and the portion of the eigenvector */
798 /* >  that has been computed so far. */
799 /* > */
800 /* >  The "columnwise" method consists basically in doing the sums */
801 /* >  for all the rows in parallel.  As each v(j) is computed, the */
802 /* >  contribution of v(j) times the j-th column of C is added to the */
803 /* >  partial sums.  Since FORTRAN arrays are stored columnwise, this has */
804 /* >  the advantage that at each step, the elements of C that are accessed */
805 /* >  are adjacent to one another, whereas with the rowwise method, the */
806 /* >  elements accessed at a step are spaced LDS (and LDP) words apart. */
807 /* > */
808 /* >  When finding left eigenvectors, the matrix in question is the */
809 /* >  transpose of the one in storage, so the rowwise method then */
810 /* >  actually accesses columns of A and B at each step, and so is the */
811 /* >  preferred method. */
812 /* > \endverbatim */
813 /* > */
814 /*  ===================================================================== */
815 /* Subroutine */ int dtgevc_(char *side, char *howmny, logical *select, 
816         integer *n, doublereal *s, integer *lds, doublereal *p, integer *ldp, 
817         doublereal *vl, integer *ldvl, doublereal *vr, integer *ldvr, integer 
818         *mm, integer *m, doublereal *work, integer *info)
819 {
820     /* System generated locals */
821     integer p_dim1, p_offset, s_dim1, s_offset, vl_dim1, vl_offset, vr_dim1, 
822             vr_offset, i__1, i__2, i__3, i__4, i__5;
823     doublereal d__1, d__2, d__3, d__4, d__5, d__6;
824
825     /* Local variables */
826     integer ibeg, ieig, iend;
827     doublereal dmin__, temp, xmax, sump[4]      /* was [2][2] */, sums[4]       
828             /* was [2][2] */;
829     extern /* Subroutine */ int dlag2_(doublereal *, integer *, doublereal *, 
830             integer *, doublereal *, doublereal *, doublereal *, doublereal *,
831              doublereal *, doublereal *);
832     doublereal cim2a, cim2b, cre2a, cre2b, temp2, bdiag[2];
833     integer i__, j;
834     doublereal acoef, scale;
835     logical ilall;
836     integer iside;
837     doublereal sbeta;
838     extern logical lsame_(char *, char *);
839     extern /* Subroutine */ int dgemv_(char *, integer *, integer *, 
840             doublereal *, doublereal *, integer *, doublereal *, integer *, 
841             doublereal *, doublereal *, integer *);
842     logical il2by2;
843     integer iinfo;
844     doublereal small;
845     logical compl;
846     doublereal anorm, bnorm;
847     logical compr;
848     extern /* Subroutine */ int dlaln2_(logical *, integer *, integer *, 
849             doublereal *, doublereal *, doublereal *, integer *, doublereal *,
850              doublereal *, doublereal *, integer *, doublereal *, doublereal *
851             , doublereal *, integer *, doublereal *, doublereal *, integer *);
852     doublereal temp2i;
853     extern /* Subroutine */ int dlabad_(doublereal *, doublereal *);
854     doublereal temp2r;
855     integer ja;
856     logical ilabad, ilbbad;
857     integer jc, je, na;
858     doublereal acoefa, bcoefa, cimaga, cimagb;
859     logical ilback;
860     integer im;
861     doublereal bcoefi, ascale, bscale, creala;
862     integer jr;
863     doublereal crealb;
864     extern doublereal dlamch_(char *);
865     doublereal bcoefr;
866     integer jw, nw;
867     doublereal salfar, safmin;
868     extern /* Subroutine */ int dlacpy_(char *, integer *, integer *, 
869             doublereal *, integer *, doublereal *, integer *);
870     doublereal xscale, bignum;
871     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
872     logical ilcomp, ilcplx;
873     integer ihwmny;
874     doublereal big;
875     logical lsa, lsb;
876     doublereal ulp, sum[4]      /* was [2][2] */;
877
878
879 /*  -- LAPACK computational routine (version 3.7.0) -- */
880 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
881 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
882 /*     December 2016 */
883
884
885
886 /*  ===================================================================== */
887
888
889 /*     Decode and Test the input parameters */
890
891     /* Parameter adjustments */
892     --select;
893     s_dim1 = *lds;
894     s_offset = 1 + s_dim1 * 1;
895     s -= s_offset;
896     p_dim1 = *ldp;
897     p_offset = 1 + p_dim1 * 1;
898     p -= p_offset;
899     vl_dim1 = *ldvl;
900     vl_offset = 1 + vl_dim1 * 1;
901     vl -= vl_offset;
902     vr_dim1 = *ldvr;
903     vr_offset = 1 + vr_dim1 * 1;
904     vr -= vr_offset;
905     --work;
906
907     /* Function Body */
908     if (lsame_(howmny, "A")) {
909         ihwmny = 1;
910         ilall = TRUE_;
911         ilback = FALSE_;
912     } else if (lsame_(howmny, "S")) {
913         ihwmny = 2;
914         ilall = FALSE_;
915         ilback = FALSE_;
916     } else if (lsame_(howmny, "B")) {
917         ihwmny = 3;
918         ilall = TRUE_;
919         ilback = TRUE_;
920     } else {
921         ihwmny = -1;
922         ilall = TRUE_;
923     }
924
925     if (lsame_(side, "R")) {
926         iside = 1;
927         compl = FALSE_;
928         compr = TRUE_;
929     } else if (lsame_(side, "L")) {
930         iside = 2;
931         compl = TRUE_;
932         compr = FALSE_;
933     } else if (lsame_(side, "B")) {
934         iside = 3;
935         compl = TRUE_;
936         compr = TRUE_;
937     } else {
938         iside = -1;
939     }
940
941     *info = 0;
942     if (iside < 0) {
943         *info = -1;
944     } else if (ihwmny < 0) {
945         *info = -2;
946     } else if (*n < 0) {
947         *info = -4;
948     } else if (*lds < f2cmax(1,*n)) {
949         *info = -6;
950     } else if (*ldp < f2cmax(1,*n)) {
951         *info = -8;
952     }
953     if (*info != 0) {
954         i__1 = -(*info);
955         xerbla_("DTGEVC", &i__1, (ftnlen)6);
956         return 0;
957     }
958
959 /*     Count the number of eigenvectors to be computed */
960
961     if (! ilall) {
962         im = 0;
963         ilcplx = FALSE_;
964         i__1 = *n;
965         for (j = 1; j <= i__1; ++j) {
966             if (ilcplx) {
967                 ilcplx = FALSE_;
968                 goto L10;
969             }
970             if (j < *n) {
971                 if (s[j + 1 + j * s_dim1] != 0.) {
972                     ilcplx = TRUE_;
973                 }
974             }
975             if (ilcplx) {
976                 if (select[j] || select[j + 1]) {
977                     im += 2;
978                 }
979             } else {
980                 if (select[j]) {
981                     ++im;
982                 }
983             }
984 L10:
985             ;
986         }
987     } else {
988         im = *n;
989     }
990
991 /*     Check 2-by-2 diagonal blocks of A, B */
992
993     ilabad = FALSE_;
994     ilbbad = FALSE_;
995     i__1 = *n - 1;
996     for (j = 1; j <= i__1; ++j) {
997         if (s[j + 1 + j * s_dim1] != 0.) {
998             if (p[j + j * p_dim1] == 0. || p[j + 1 + (j + 1) * p_dim1] == 0. 
999                     || p[j + (j + 1) * p_dim1] != 0.) {
1000                 ilbbad = TRUE_;
1001             }
1002             if (j < *n - 1) {
1003                 if (s[j + 2 + (j + 1) * s_dim1] != 0.) {
1004                     ilabad = TRUE_;
1005                 }
1006             }
1007         }
1008 /* L20: */
1009     }
1010
1011     if (ilabad) {
1012         *info = -5;
1013     } else if (ilbbad) {
1014         *info = -7;
1015     } else if (compl && *ldvl < *n || *ldvl < 1) {
1016         *info = -10;
1017     } else if (compr && *ldvr < *n || *ldvr < 1) {
1018         *info = -12;
1019     } else if (*mm < im) {
1020         *info = -13;
1021     }
1022     if (*info != 0) {
1023         i__1 = -(*info);
1024         xerbla_("DTGEVC", &i__1, (ftnlen)6);
1025         return 0;
1026     }
1027
1028 /*     Quick return if possible */
1029
1030     *m = im;
1031     if (*n == 0) {
1032         return 0;
1033     }
1034
1035 /*     Machine Constants */
1036
1037     safmin = dlamch_("Safe minimum");
1038     big = 1. / safmin;
1039     dlabad_(&safmin, &big);
1040     ulp = dlamch_("Epsilon") * dlamch_("Base");
1041     small = safmin * *n / ulp;
1042     big = 1. / small;
1043     bignum = 1. / (safmin * *n);
1044
1045 /*     Compute the 1-norm of each column of the strictly upper triangular */
1046 /*     part (i.e., excluding all elements belonging to the diagonal */
1047 /*     blocks) of A and B to check for possible overflow in the */
1048 /*     triangular solver. */
1049
1050     anorm = (d__1 = s[s_dim1 + 1], abs(d__1));
1051     if (*n > 1) {
1052         anorm += (d__1 = s[s_dim1 + 2], abs(d__1));
1053     }
1054     bnorm = (d__1 = p[p_dim1 + 1], abs(d__1));
1055     work[1] = 0.;
1056     work[*n + 1] = 0.;
1057
1058     i__1 = *n;
1059     for (j = 2; j <= i__1; ++j) {
1060         temp = 0.;
1061         temp2 = 0.;
1062         if (s[j + (j - 1) * s_dim1] == 0.) {
1063             iend = j - 1;
1064         } else {
1065             iend = j - 2;
1066         }
1067         i__2 = iend;
1068         for (i__ = 1; i__ <= i__2; ++i__) {
1069             temp += (d__1 = s[i__ + j * s_dim1], abs(d__1));
1070             temp2 += (d__1 = p[i__ + j * p_dim1], abs(d__1));
1071 /* L30: */
1072         }
1073         work[j] = temp;
1074         work[*n + j] = temp2;
1075 /* Computing MIN */
1076         i__3 = j + 1;
1077         i__2 = f2cmin(i__3,*n);
1078         for (i__ = iend + 1; i__ <= i__2; ++i__) {
1079             temp += (d__1 = s[i__ + j * s_dim1], abs(d__1));
1080             temp2 += (d__1 = p[i__ + j * p_dim1], abs(d__1));
1081 /* L40: */
1082         }
1083         anorm = f2cmax(anorm,temp);
1084         bnorm = f2cmax(bnorm,temp2);
1085 /* L50: */
1086     }
1087
1088     ascale = 1. / f2cmax(anorm,safmin);
1089     bscale = 1. / f2cmax(bnorm,safmin);
1090
1091 /*     Left eigenvectors */
1092
1093     if (compl) {
1094         ieig = 0;
1095
1096 /*        Main loop over eigenvalues */
1097
1098         ilcplx = FALSE_;
1099         i__1 = *n;
1100         for (je = 1; je <= i__1; ++je) {
1101
1102 /*           Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or */
1103 /*           (b) this would be the second of a complex pair. */
1104 /*           Check for complex eigenvalue, so as to be sure of which */
1105 /*           entry(-ies) of SELECT to look at. */
1106
1107             if (ilcplx) {
1108                 ilcplx = FALSE_;
1109                 goto L220;
1110             }
1111             nw = 1;
1112             if (je < *n) {
1113                 if (s[je + 1 + je * s_dim1] != 0.) {
1114                     ilcplx = TRUE_;
1115                     nw = 2;
1116                 }
1117             }
1118             if (ilall) {
1119                 ilcomp = TRUE_;
1120             } else if (ilcplx) {
1121                 ilcomp = select[je] || select[je + 1];
1122             } else {
1123                 ilcomp = select[je];
1124             }
1125             if (! ilcomp) {
1126                 goto L220;
1127             }
1128
1129 /*           Decide if (a) singular pencil, (b) real eigenvalue, or */
1130 /*           (c) complex eigenvalue. */
1131
1132             if (! ilcplx) {
1133                 if ((d__1 = s[je + je * s_dim1], abs(d__1)) <= safmin && (
1134                         d__2 = p[je + je * p_dim1], abs(d__2)) <= safmin) {
1135
1136 /*                 Singular matrix pencil -- return unit eigenvector */
1137
1138                     ++ieig;
1139                     i__2 = *n;
1140                     for (jr = 1; jr <= i__2; ++jr) {
1141                         vl[jr + ieig * vl_dim1] = 0.;
1142 /* L60: */
1143                     }
1144                     vl[ieig + ieig * vl_dim1] = 1.;
1145                     goto L220;
1146                 }
1147             }
1148
1149 /*           Clear vector */
1150
1151             i__2 = nw * *n;
1152             for (jr = 1; jr <= i__2; ++jr) {
1153                 work[(*n << 1) + jr] = 0.;
1154 /* L70: */
1155             }
1156 /*                                                 T */
1157 /*           Compute coefficients in  ( a A - b B )  y = 0 */
1158 /*              a  is  ACOEF */
1159 /*              b  is  BCOEFR + i*BCOEFI */
1160
1161             if (! ilcplx) {
1162
1163 /*              Real eigenvalue */
1164
1165 /* Computing MAX */
1166                 d__3 = (d__1 = s[je + je * s_dim1], abs(d__1)) * ascale, d__4 
1167                         = (d__2 = p[je + je * p_dim1], abs(d__2)) * bscale, 
1168                         d__3 = f2cmax(d__3,d__4);
1169                 temp = 1. / f2cmax(d__3,safmin);
1170                 salfar = temp * s[je + je * s_dim1] * ascale;
1171                 sbeta = temp * p[je + je * p_dim1] * bscale;
1172                 acoef = sbeta * ascale;
1173                 bcoefr = salfar * bscale;
1174                 bcoefi = 0.;
1175
1176 /*              Scale to avoid underflow */
1177
1178                 scale = 1.;
1179                 lsa = abs(sbeta) >= safmin && abs(acoef) < small;
1180                 lsb = abs(salfar) >= safmin && abs(bcoefr) < small;
1181                 if (lsa) {
1182                     scale = small / abs(sbeta) * f2cmin(anorm,big);
1183                 }
1184                 if (lsb) {
1185 /* Computing MAX */
1186                     d__1 = scale, d__2 = small / abs(salfar) * f2cmin(bnorm,big);
1187                     scale = f2cmax(d__1,d__2);
1188                 }
1189                 if (lsa || lsb) {
1190 /* Computing MIN */
1191 /* Computing MAX */
1192                     d__3 = 1., d__4 = abs(acoef), d__3 = f2cmax(d__3,d__4), d__4 
1193                             = abs(bcoefr);
1194                     d__1 = scale, d__2 = 1. / (safmin * f2cmax(d__3,d__4));
1195                     scale = f2cmin(d__1,d__2);
1196                     if (lsa) {
1197                         acoef = ascale * (scale * sbeta);
1198                     } else {
1199                         acoef = scale * acoef;
1200                     }
1201                     if (lsb) {
1202                         bcoefr = bscale * (scale * salfar);
1203                     } else {
1204                         bcoefr = scale * bcoefr;
1205                     }
1206                 }
1207                 acoefa = abs(acoef);
1208                 bcoefa = abs(bcoefr);
1209
1210 /*              First component is 1 */
1211
1212                 work[(*n << 1) + je] = 1.;
1213                 xmax = 1.;
1214             } else {
1215
1216 /*              Complex eigenvalue */
1217
1218                 d__1 = safmin * 100.;
1219                 dlag2_(&s[je + je * s_dim1], lds, &p[je + je * p_dim1], ldp, &
1220                         d__1, &acoef, &temp, &bcoefr, &temp2, &bcoefi);
1221                 bcoefi = -bcoefi;
1222                 if (bcoefi == 0.) {
1223                     *info = je;
1224                     return 0;
1225                 }
1226
1227 /*              Scale to avoid over/underflow */
1228
1229                 acoefa = abs(acoef);
1230                 bcoefa = abs(bcoefr) + abs(bcoefi);
1231                 scale = 1.;
1232                 if (acoefa * ulp < safmin && acoefa >= safmin) {
1233                     scale = safmin / ulp / acoefa;
1234                 }
1235                 if (bcoefa * ulp < safmin && bcoefa >= safmin) {
1236 /* Computing MAX */
1237                     d__1 = scale, d__2 = safmin / ulp / bcoefa;
1238                     scale = f2cmax(d__1,d__2);
1239                 }
1240                 if (safmin * acoefa > ascale) {
1241                     scale = ascale / (safmin * acoefa);
1242                 }
1243                 if (safmin * bcoefa > bscale) {
1244 /* Computing MIN */
1245                     d__1 = scale, d__2 = bscale / (safmin * bcoefa);
1246                     scale = f2cmin(d__1,d__2);
1247                 }
1248                 if (scale != 1.) {
1249                     acoef = scale * acoef;
1250                     acoefa = abs(acoef);
1251                     bcoefr = scale * bcoefr;
1252                     bcoefi = scale * bcoefi;
1253                     bcoefa = abs(bcoefr) + abs(bcoefi);
1254                 }
1255
1256 /*              Compute first two components of eigenvector */
1257
1258                 temp = acoef * s[je + 1 + je * s_dim1];
1259                 temp2r = acoef * s[je + je * s_dim1] - bcoefr * p[je + je * 
1260                         p_dim1];
1261                 temp2i = -bcoefi * p[je + je * p_dim1];
1262                 if (abs(temp) > abs(temp2r) + abs(temp2i)) {
1263                     work[(*n << 1) + je] = 1.;
1264                     work[*n * 3 + je] = 0.;
1265                     work[(*n << 1) + je + 1] = -temp2r / temp;
1266                     work[*n * 3 + je + 1] = -temp2i / temp;
1267                 } else {
1268                     work[(*n << 1) + je + 1] = 1.;
1269                     work[*n * 3 + je + 1] = 0.;
1270                     temp = acoef * s[je + (je + 1) * s_dim1];
1271                     work[(*n << 1) + je] = (bcoefr * p[je + 1 + (je + 1) * 
1272                             p_dim1] - acoef * s[je + 1 + (je + 1) * s_dim1]) /
1273                              temp;
1274                     work[*n * 3 + je] = bcoefi * p[je + 1 + (je + 1) * p_dim1]
1275                              / temp;
1276                 }
1277 /* Computing MAX */
1278                 d__5 = (d__1 = work[(*n << 1) + je], abs(d__1)) + (d__2 = 
1279                         work[*n * 3 + je], abs(d__2)), d__6 = (d__3 = work[(*
1280                         n << 1) + je + 1], abs(d__3)) + (d__4 = work[*n * 3 + 
1281                         je + 1], abs(d__4));
1282                 xmax = f2cmax(d__5,d__6);
1283             }
1284
1285 /* Computing MAX */
1286             d__1 = ulp * acoefa * anorm, d__2 = ulp * bcoefa * bnorm, d__1 = 
1287                     f2cmax(d__1,d__2);
1288             dmin__ = f2cmax(d__1,safmin);
1289
1290 /*                                           T */
1291 /*           Triangular solve of  (a A - b B)  y = 0 */
1292
1293 /*                                   T */
1294 /*           (rowwise in  (a A - b B) , or columnwise in (a A - b B) ) */
1295
1296             il2by2 = FALSE_;
1297
1298             i__2 = *n;
1299             for (j = je + nw; j <= i__2; ++j) {
1300                 if (il2by2) {
1301                     il2by2 = FALSE_;
1302                     goto L160;
1303                 }
1304
1305                 na = 1;
1306                 bdiag[0] = p[j + j * p_dim1];
1307                 if (j < *n) {
1308                     if (s[j + 1 + j * s_dim1] != 0.) {
1309                         il2by2 = TRUE_;
1310                         bdiag[1] = p[j + 1 + (j + 1) * p_dim1];
1311                         na = 2;
1312                     }
1313                 }
1314
1315 /*              Check whether scaling is necessary for dot products */
1316
1317                 xscale = 1. / f2cmax(1.,xmax);
1318 /* Computing MAX */
1319                 d__1 = work[j], d__2 = work[*n + j], d__1 = f2cmax(d__1,d__2), 
1320                         d__2 = acoefa * work[j] + bcoefa * work[*n + j];
1321                 temp = f2cmax(d__1,d__2);
1322                 if (il2by2) {
1323 /* Computing MAX */
1324                     d__1 = temp, d__2 = work[j + 1], d__1 = f2cmax(d__1,d__2), 
1325                             d__2 = work[*n + j + 1], d__1 = f2cmax(d__1,d__2), 
1326                             d__2 = acoefa * work[j + 1] + bcoefa * work[*n + 
1327                             j + 1];
1328                     temp = f2cmax(d__1,d__2);
1329                 }
1330                 if (temp > bignum * xscale) {
1331                     i__3 = nw - 1;
1332                     for (jw = 0; jw <= i__3; ++jw) {
1333                         i__4 = j - 1;
1334                         for (jr = je; jr <= i__4; ++jr) {
1335                             work[(jw + 2) * *n + jr] = xscale * work[(jw + 2) 
1336                                     * *n + jr];
1337 /* L80: */
1338                         }
1339 /* L90: */
1340                     }
1341                     xmax *= xscale;
1342                 }
1343
1344 /*              Compute dot products */
1345
1346 /*                    j-1 */
1347 /*              SUM = sum  conjg( a*S(k,j) - b*P(k,j) )*x(k) */
1348 /*                    k=je */
1349
1350 /*              To reduce the op count, this is done as */
1351
1352 /*              _        j-1                  _        j-1 */
1353 /*              a*conjg( sum  S(k,j)*x(k) ) - b*conjg( sum  P(k,j)*x(k) ) */
1354 /*                       k=je                          k=je */
1355
1356 /*              which may cause underflow problems if A or B are close */
1357 /*              to underflow.  (E.g., less than SMALL.) */
1358
1359
1360                 i__3 = nw;
1361                 for (jw = 1; jw <= i__3; ++jw) {
1362                     i__4 = na;
1363                     for (ja = 1; ja <= i__4; ++ja) {
1364                         sums[ja + (jw << 1) - 3] = 0.;
1365                         sump[ja + (jw << 1) - 3] = 0.;
1366
1367                         i__5 = j - 1;
1368                         for (jr = je; jr <= i__5; ++jr) {
1369                             sums[ja + (jw << 1) - 3] += s[jr + (j + ja - 1) * 
1370                                     s_dim1] * work[(jw + 1) * *n + jr];
1371                             sump[ja + (jw << 1) - 3] += p[jr + (j + ja - 1) * 
1372                                     p_dim1] * work[(jw + 1) * *n + jr];
1373 /* L100: */
1374                         }
1375 /* L110: */
1376                     }
1377 /* L120: */
1378                 }
1379
1380                 i__3 = na;
1381                 for (ja = 1; ja <= i__3; ++ja) {
1382                     if (ilcplx) {
1383                         sum[ja - 1] = -acoef * sums[ja - 1] + bcoefr * sump[
1384                                 ja - 1] - bcoefi * sump[ja + 1];
1385                         sum[ja + 1] = -acoef * sums[ja + 1] + bcoefr * sump[
1386                                 ja + 1] + bcoefi * sump[ja - 1];
1387                     } else {
1388                         sum[ja - 1] = -acoef * sums[ja - 1] + bcoefr * sump[
1389                                 ja - 1];
1390                     }
1391 /* L130: */
1392                 }
1393
1394 /*                                  T */
1395 /*              Solve  ( a A - b B )  y = SUM(,) */
1396 /*              with scaling and perturbation of the denominator */
1397
1398                 dlaln2_(&c_true, &na, &nw, &dmin__, &acoef, &s[j + j * s_dim1]
1399                         , lds, bdiag, &bdiag[1], sum, &c__2, &bcoefr, &bcoefi,
1400                          &work[(*n << 1) + j], n, &scale, &temp, &iinfo);
1401                 if (scale < 1.) {
1402                     i__3 = nw - 1;
1403                     for (jw = 0; jw <= i__3; ++jw) {
1404                         i__4 = j - 1;
1405                         for (jr = je; jr <= i__4; ++jr) {
1406                             work[(jw + 2) * *n + jr] = scale * work[(jw + 2) *
1407                                      *n + jr];
1408 /* L140: */
1409                         }
1410 /* L150: */
1411                     }
1412                     xmax = scale * xmax;
1413                 }
1414                 xmax = f2cmax(xmax,temp);
1415 L160:
1416                 ;
1417             }
1418
1419 /*           Copy eigenvector to VL, back transforming if */
1420 /*           HOWMNY='B'. */
1421
1422             ++ieig;
1423             if (ilback) {
1424                 i__2 = nw - 1;
1425                 for (jw = 0; jw <= i__2; ++jw) {
1426                     i__3 = *n + 1 - je;
1427                     dgemv_("N", n, &i__3, &c_b34, &vl[je * vl_dim1 + 1], ldvl,
1428                              &work[(jw + 2) * *n + je], &c__1, &c_b36, &work[(
1429                             jw + 4) * *n + 1], &c__1);
1430 /* L170: */
1431                 }
1432                 dlacpy_(" ", n, &nw, &work[(*n << 2) + 1], n, &vl[je * 
1433                         vl_dim1 + 1], ldvl);
1434                 ibeg = 1;
1435             } else {
1436                 dlacpy_(" ", n, &nw, &work[(*n << 1) + 1], n, &vl[ieig * 
1437                         vl_dim1 + 1], ldvl);
1438                 ibeg = je;
1439             }
1440
1441 /*           Scale eigenvector */
1442
1443             xmax = 0.;
1444             if (ilcplx) {
1445                 i__2 = *n;
1446                 for (j = ibeg; j <= i__2; ++j) {
1447 /* Computing MAX */
1448                     d__3 = xmax, d__4 = (d__1 = vl[j + ieig * vl_dim1], abs(
1449                             d__1)) + (d__2 = vl[j + (ieig + 1) * vl_dim1], 
1450                             abs(d__2));
1451                     xmax = f2cmax(d__3,d__4);
1452 /* L180: */
1453                 }
1454             } else {
1455                 i__2 = *n;
1456                 for (j = ibeg; j <= i__2; ++j) {
1457 /* Computing MAX */
1458                     d__2 = xmax, d__3 = (d__1 = vl[j + ieig * vl_dim1], abs(
1459                             d__1));
1460                     xmax = f2cmax(d__2,d__3);
1461 /* L190: */
1462                 }
1463             }
1464
1465             if (xmax > safmin) {
1466                 xscale = 1. / xmax;
1467
1468                 i__2 = nw - 1;
1469                 for (jw = 0; jw <= i__2; ++jw) {
1470                     i__3 = *n;
1471                     for (jr = ibeg; jr <= i__3; ++jr) {
1472                         vl[jr + (ieig + jw) * vl_dim1] = xscale * vl[jr + (
1473                                 ieig + jw) * vl_dim1];
1474 /* L200: */
1475                     }
1476 /* L210: */
1477                 }
1478             }
1479             ieig = ieig + nw - 1;
1480
1481 L220:
1482             ;
1483         }
1484     }
1485
1486 /*     Right eigenvectors */
1487
1488     if (compr) {
1489         ieig = im + 1;
1490
1491 /*        Main loop over eigenvalues */
1492
1493         ilcplx = FALSE_;
1494         for (je = *n; je >= 1; --je) {
1495
1496 /*           Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or */
1497 /*           (b) this would be the second of a complex pair. */
1498 /*           Check for complex eigenvalue, so as to be sure of which */
1499 /*           entry(-ies) of SELECT to look at -- if complex, SELECT(JE) */
1500 /*           or SELECT(JE-1). */
1501 /*           If this is a complex pair, the 2-by-2 diagonal block */
1502 /*           corresponding to the eigenvalue is in rows/columns JE-1:JE */
1503
1504             if (ilcplx) {
1505                 ilcplx = FALSE_;
1506                 goto L500;
1507             }
1508             nw = 1;
1509             if (je > 1) {
1510                 if (s[je + (je - 1) * s_dim1] != 0.) {
1511                     ilcplx = TRUE_;
1512                     nw = 2;
1513                 }
1514             }
1515             if (ilall) {
1516                 ilcomp = TRUE_;
1517             } else if (ilcplx) {
1518                 ilcomp = select[je] || select[je - 1];
1519             } else {
1520                 ilcomp = select[je];
1521             }
1522             if (! ilcomp) {
1523                 goto L500;
1524             }
1525
1526 /*           Decide if (a) singular pencil, (b) real eigenvalue, or */
1527 /*           (c) complex eigenvalue. */
1528
1529             if (! ilcplx) {
1530                 if ((d__1 = s[je + je * s_dim1], abs(d__1)) <= safmin && (
1531                         d__2 = p[je + je * p_dim1], abs(d__2)) <= safmin) {
1532
1533 /*                 Singular matrix pencil -- unit eigenvector */
1534
1535                     --ieig;
1536                     i__1 = *n;
1537                     for (jr = 1; jr <= i__1; ++jr) {
1538                         vr[jr + ieig * vr_dim1] = 0.;
1539 /* L230: */
1540                     }
1541                     vr[ieig + ieig * vr_dim1] = 1.;
1542                     goto L500;
1543                 }
1544             }
1545
1546 /*           Clear vector */
1547
1548             i__1 = nw - 1;
1549             for (jw = 0; jw <= i__1; ++jw) {
1550                 i__2 = *n;
1551                 for (jr = 1; jr <= i__2; ++jr) {
1552                     work[(jw + 2) * *n + jr] = 0.;
1553 /* L240: */
1554                 }
1555 /* L250: */
1556             }
1557
1558 /*           Compute coefficients in  ( a A - b B ) x = 0 */
1559 /*              a  is  ACOEF */
1560 /*              b  is  BCOEFR + i*BCOEFI */
1561
1562             if (! ilcplx) {
1563
1564 /*              Real eigenvalue */
1565
1566 /* Computing MAX */
1567                 d__3 = (d__1 = s[je + je * s_dim1], abs(d__1)) * ascale, d__4 
1568                         = (d__2 = p[je + je * p_dim1], abs(d__2)) * bscale, 
1569                         d__3 = f2cmax(d__3,d__4);
1570                 temp = 1. / f2cmax(d__3,safmin);
1571                 salfar = temp * s[je + je * s_dim1] * ascale;
1572                 sbeta = temp * p[je + je * p_dim1] * bscale;
1573                 acoef = sbeta * ascale;
1574                 bcoefr = salfar * bscale;
1575                 bcoefi = 0.;
1576
1577 /*              Scale to avoid underflow */
1578
1579                 scale = 1.;
1580                 lsa = abs(sbeta) >= safmin && abs(acoef) < small;
1581                 lsb = abs(salfar) >= safmin && abs(bcoefr) < small;
1582                 if (lsa) {
1583                     scale = small / abs(sbeta) * f2cmin(anorm,big);
1584                 }
1585                 if (lsb) {
1586 /* Computing MAX */
1587                     d__1 = scale, d__2 = small / abs(salfar) * f2cmin(bnorm,big);
1588                     scale = f2cmax(d__1,d__2);
1589                 }
1590                 if (lsa || lsb) {
1591 /* Computing MIN */
1592 /* Computing MAX */
1593                     d__3 = 1., d__4 = abs(acoef), d__3 = f2cmax(d__3,d__4), d__4 
1594                             = abs(bcoefr);
1595                     d__1 = scale, d__2 = 1. / (safmin * f2cmax(d__3,d__4));
1596                     scale = f2cmin(d__1,d__2);
1597                     if (lsa) {
1598                         acoef = ascale * (scale * sbeta);
1599                     } else {
1600                         acoef = scale * acoef;
1601                     }
1602                     if (lsb) {
1603                         bcoefr = bscale * (scale * salfar);
1604                     } else {
1605                         bcoefr = scale * bcoefr;
1606                     }
1607                 }
1608                 acoefa = abs(acoef);
1609                 bcoefa = abs(bcoefr);
1610
1611 /*              First component is 1 */
1612
1613                 work[(*n << 1) + je] = 1.;
1614                 xmax = 1.;
1615
1616 /*              Compute contribution from column JE of A and B to sum */
1617 /*              (See "Further Details", above.) */
1618
1619                 i__1 = je - 1;
1620                 for (jr = 1; jr <= i__1; ++jr) {
1621                     work[(*n << 1) + jr] = bcoefr * p[jr + je * p_dim1] - 
1622                             acoef * s[jr + je * s_dim1];
1623 /* L260: */
1624                 }
1625             } else {
1626
1627 /*              Complex eigenvalue */
1628
1629                 d__1 = safmin * 100.;
1630                 dlag2_(&s[je - 1 + (je - 1) * s_dim1], lds, &p[je - 1 + (je - 
1631                         1) * p_dim1], ldp, &d__1, &acoef, &temp, &bcoefr, &
1632                         temp2, &bcoefi);
1633                 if (bcoefi == 0.) {
1634                     *info = je - 1;
1635                     return 0;
1636                 }
1637
1638 /*              Scale to avoid over/underflow */
1639
1640                 acoefa = abs(acoef);
1641                 bcoefa = abs(bcoefr) + abs(bcoefi);
1642                 scale = 1.;
1643                 if (acoefa * ulp < safmin && acoefa >= safmin) {
1644                     scale = safmin / ulp / acoefa;
1645                 }
1646                 if (bcoefa * ulp < safmin && bcoefa >= safmin) {
1647 /* Computing MAX */
1648                     d__1 = scale, d__2 = safmin / ulp / bcoefa;
1649                     scale = f2cmax(d__1,d__2);
1650                 }
1651                 if (safmin * acoefa > ascale) {
1652                     scale = ascale / (safmin * acoefa);
1653                 }
1654                 if (safmin * bcoefa > bscale) {
1655 /* Computing MIN */
1656                     d__1 = scale, d__2 = bscale / (safmin * bcoefa);
1657                     scale = f2cmin(d__1,d__2);
1658                 }
1659                 if (scale != 1.) {
1660                     acoef = scale * acoef;
1661                     acoefa = abs(acoef);
1662                     bcoefr = scale * bcoefr;
1663                     bcoefi = scale * bcoefi;
1664                     bcoefa = abs(bcoefr) + abs(bcoefi);
1665                 }
1666
1667 /*              Compute first two components of eigenvector */
1668 /*              and contribution to sums */
1669
1670                 temp = acoef * s[je + (je - 1) * s_dim1];
1671                 temp2r = acoef * s[je + je * s_dim1] - bcoefr * p[je + je * 
1672                         p_dim1];
1673                 temp2i = -bcoefi * p[je + je * p_dim1];
1674                 if (abs(temp) >= abs(temp2r) + abs(temp2i)) {
1675                     work[(*n << 1) + je] = 1.;
1676                     work[*n * 3 + je] = 0.;
1677                     work[(*n << 1) + je - 1] = -temp2r / temp;
1678                     work[*n * 3 + je - 1] = -temp2i / temp;
1679                 } else {
1680                     work[(*n << 1) + je - 1] = 1.;
1681                     work[*n * 3 + je - 1] = 0.;
1682                     temp = acoef * s[je - 1 + je * s_dim1];
1683                     work[(*n << 1) + je] = (bcoefr * p[je - 1 + (je - 1) * 
1684                             p_dim1] - acoef * s[je - 1 + (je - 1) * s_dim1]) /
1685                              temp;
1686                     work[*n * 3 + je] = bcoefi * p[je - 1 + (je - 1) * p_dim1]
1687                              / temp;
1688                 }
1689
1690 /* Computing MAX */
1691                 d__5 = (d__1 = work[(*n << 1) + je], abs(d__1)) + (d__2 = 
1692                         work[*n * 3 + je], abs(d__2)), d__6 = (d__3 = work[(*
1693                         n << 1) + je - 1], abs(d__3)) + (d__4 = work[*n * 3 + 
1694                         je - 1], abs(d__4));
1695                 xmax = f2cmax(d__5,d__6);
1696
1697 /*              Compute contribution from columns JE and JE-1 */
1698 /*              of A and B to the sums. */
1699
1700                 creala = acoef * work[(*n << 1) + je - 1];
1701                 cimaga = acoef * work[*n * 3 + je - 1];
1702                 crealb = bcoefr * work[(*n << 1) + je - 1] - bcoefi * work[*n 
1703                         * 3 + je - 1];
1704                 cimagb = bcoefi * work[(*n << 1) + je - 1] + bcoefr * work[*n 
1705                         * 3 + je - 1];
1706                 cre2a = acoef * work[(*n << 1) + je];
1707                 cim2a = acoef * work[*n * 3 + je];
1708                 cre2b = bcoefr * work[(*n << 1) + je] - bcoefi * work[*n * 3 
1709                         + je];
1710                 cim2b = bcoefi * work[(*n << 1) + je] + bcoefr * work[*n * 3 
1711                         + je];
1712                 i__1 = je - 2;
1713                 for (jr = 1; jr <= i__1; ++jr) {
1714                     work[(*n << 1) + jr] = -creala * s[jr + (je - 1) * s_dim1]
1715                              + crealb * p[jr + (je - 1) * p_dim1] - cre2a * s[
1716                             jr + je * s_dim1] + cre2b * p[jr + je * p_dim1];
1717                     work[*n * 3 + jr] = -cimaga * s[jr + (je - 1) * s_dim1] + 
1718                             cimagb * p[jr + (je - 1) * p_dim1] - cim2a * s[jr 
1719                             + je * s_dim1] + cim2b * p[jr + je * p_dim1];
1720 /* L270: */
1721                 }
1722             }
1723
1724 /* Computing MAX */
1725             d__1 = ulp * acoefa * anorm, d__2 = ulp * bcoefa * bnorm, d__1 = 
1726                     f2cmax(d__1,d__2);
1727             dmin__ = f2cmax(d__1,safmin);
1728
1729 /*           Columnwise triangular solve of  (a A - b B)  x = 0 */
1730
1731             il2by2 = FALSE_;
1732             for (j = je - nw; j >= 1; --j) {
1733
1734 /*              If a 2-by-2 block, is in position j-1:j, wait until */
1735 /*              next iteration to process it (when it will be j:j+1) */
1736
1737                 if (! il2by2 && j > 1) {
1738                     if (s[j + (j - 1) * s_dim1] != 0.) {
1739                         il2by2 = TRUE_;
1740                         goto L370;
1741                     }
1742                 }
1743                 bdiag[0] = p[j + j * p_dim1];
1744                 if (il2by2) {
1745                     na = 2;
1746                     bdiag[1] = p[j + 1 + (j + 1) * p_dim1];
1747                 } else {
1748                     na = 1;
1749                 }
1750
1751 /*              Compute x(j) (and x(j+1), if 2-by-2 block) */
1752
1753                 dlaln2_(&c_false, &na, &nw, &dmin__, &acoef, &s[j + j * 
1754                         s_dim1], lds, bdiag, &bdiag[1], &work[(*n << 1) + j], 
1755                         n, &bcoefr, &bcoefi, sum, &c__2, &scale, &temp, &
1756                         iinfo);
1757                 if (scale < 1.) {
1758
1759                     i__1 = nw - 1;
1760                     for (jw = 0; jw <= i__1; ++jw) {
1761                         i__2 = je;
1762                         for (jr = 1; jr <= i__2; ++jr) {
1763                             work[(jw + 2) * *n + jr] = scale * work[(jw + 2) *
1764                                      *n + jr];
1765 /* L280: */
1766                         }
1767 /* L290: */
1768                     }
1769                 }
1770 /* Computing MAX */
1771                 d__1 = scale * xmax;
1772                 xmax = f2cmax(d__1,temp);
1773
1774                 i__1 = nw;
1775                 for (jw = 1; jw <= i__1; ++jw) {
1776                     i__2 = na;
1777                     for (ja = 1; ja <= i__2; ++ja) {
1778                         work[(jw + 1) * *n + j + ja - 1] = sum[ja + (jw << 1) 
1779                                 - 3];
1780 /* L300: */
1781                     }
1782 /* L310: */
1783                 }
1784
1785 /*              w = w + x(j)*(a S(*,j) - b P(*,j) ) with scaling */
1786
1787                 if (j > 1) {
1788
1789 /*                 Check whether scaling is necessary for sum. */
1790
1791                     xscale = 1. / f2cmax(1.,xmax);
1792                     temp = acoefa * work[j] + bcoefa * work[*n + j];
1793                     if (il2by2) {
1794 /* Computing MAX */
1795                         d__1 = temp, d__2 = acoefa * work[j + 1] + bcoefa * 
1796                                 work[*n + j + 1];
1797                         temp = f2cmax(d__1,d__2);
1798                     }
1799 /* Computing MAX */
1800                     d__1 = f2cmax(temp,acoefa);
1801                     temp = f2cmax(d__1,bcoefa);
1802                     if (temp > bignum * xscale) {
1803
1804                         i__1 = nw - 1;
1805                         for (jw = 0; jw <= i__1; ++jw) {
1806                             i__2 = je;
1807                             for (jr = 1; jr <= i__2; ++jr) {
1808                                 work[(jw + 2) * *n + jr] = xscale * work[(jw 
1809                                         + 2) * *n + jr];
1810 /* L320: */
1811                             }
1812 /* L330: */
1813                         }
1814                         xmax *= xscale;
1815                     }
1816
1817 /*                 Compute the contributions of the off-diagonals of */
1818 /*                 column j (and j+1, if 2-by-2 block) of A and B to the */
1819 /*                 sums. */
1820
1821
1822                     i__1 = na;
1823                     for (ja = 1; ja <= i__1; ++ja) {
1824                         if (ilcplx) {
1825                             creala = acoef * work[(*n << 1) + j + ja - 1];
1826                             cimaga = acoef * work[*n * 3 + j + ja - 1];
1827                             crealb = bcoefr * work[(*n << 1) + j + ja - 1] - 
1828                                     bcoefi * work[*n * 3 + j + ja - 1];
1829                             cimagb = bcoefi * work[(*n << 1) + j + ja - 1] + 
1830                                     bcoefr * work[*n * 3 + j + ja - 1];
1831                             i__2 = j - 1;
1832                             for (jr = 1; jr <= i__2; ++jr) {
1833                                 work[(*n << 1) + jr] = work[(*n << 1) + jr] - 
1834                                         creala * s[jr + (j + ja - 1) * s_dim1]
1835                                          + crealb * p[jr + (j + ja - 1) * 
1836                                         p_dim1];
1837                                 work[*n * 3 + jr] = work[*n * 3 + jr] - 
1838                                         cimaga * s[jr + (j + ja - 1) * s_dim1]
1839                                          + cimagb * p[jr + (j + ja - 1) * 
1840                                         p_dim1];
1841 /* L340: */
1842                             }
1843                         } else {
1844                             creala = acoef * work[(*n << 1) + j + ja - 1];
1845                             crealb = bcoefr * work[(*n << 1) + j + ja - 1];
1846                             i__2 = j - 1;
1847                             for (jr = 1; jr <= i__2; ++jr) {
1848                                 work[(*n << 1) + jr] = work[(*n << 1) + jr] - 
1849                                         creala * s[jr + (j + ja - 1) * s_dim1]
1850                                          + crealb * p[jr + (j + ja - 1) * 
1851                                         p_dim1];
1852 /* L350: */
1853                             }
1854                         }
1855 /* L360: */
1856                     }
1857                 }
1858
1859                 il2by2 = FALSE_;
1860 L370:
1861                 ;
1862             }
1863
1864 /*           Copy eigenvector to VR, back transforming if */
1865 /*           HOWMNY='B'. */
1866
1867             ieig -= nw;
1868             if (ilback) {
1869
1870                 i__1 = nw - 1;
1871                 for (jw = 0; jw <= i__1; ++jw) {
1872                     i__2 = *n;
1873                     for (jr = 1; jr <= i__2; ++jr) {
1874                         work[(jw + 4) * *n + jr] = work[(jw + 2) * *n + 1] * 
1875                                 vr[jr + vr_dim1];
1876 /* L380: */
1877                     }
1878
1879 /*                 A series of compiler directives to defeat */
1880 /*                 vectorization for the next loop */
1881
1882
1883                     i__2 = je;
1884                     for (jc = 2; jc <= i__2; ++jc) {
1885                         i__3 = *n;
1886                         for (jr = 1; jr <= i__3; ++jr) {
1887                             work[(jw + 4) * *n + jr] += work[(jw + 2) * *n + 
1888                                     jc] * vr[jr + jc * vr_dim1];
1889 /* L390: */
1890                         }
1891 /* L400: */
1892                     }
1893 /* L410: */
1894                 }
1895
1896                 i__1 = nw - 1;
1897                 for (jw = 0; jw <= i__1; ++jw) {
1898                     i__2 = *n;
1899                     for (jr = 1; jr <= i__2; ++jr) {
1900                         vr[jr + (ieig + jw) * vr_dim1] = work[(jw + 4) * *n + 
1901                                 jr];
1902 /* L420: */
1903                     }
1904 /* L430: */
1905                 }
1906
1907                 iend = *n;
1908             } else {
1909                 i__1 = nw - 1;
1910                 for (jw = 0; jw <= i__1; ++jw) {
1911                     i__2 = *n;
1912                     for (jr = 1; jr <= i__2; ++jr) {
1913                         vr[jr + (ieig + jw) * vr_dim1] = work[(jw + 2) * *n + 
1914                                 jr];
1915 /* L440: */
1916                     }
1917 /* L450: */
1918                 }
1919
1920                 iend = je;
1921             }
1922
1923 /*           Scale eigenvector */
1924
1925             xmax = 0.;
1926             if (ilcplx) {
1927                 i__1 = iend;
1928                 for (j = 1; j <= i__1; ++j) {
1929 /* Computing MAX */
1930                     d__3 = xmax, d__4 = (d__1 = vr[j + ieig * vr_dim1], abs(
1931                             d__1)) + (d__2 = vr[j + (ieig + 1) * vr_dim1], 
1932                             abs(d__2));
1933                     xmax = f2cmax(d__3,d__4);
1934 /* L460: */
1935                 }
1936             } else {
1937                 i__1 = iend;
1938                 for (j = 1; j <= i__1; ++j) {
1939 /* Computing MAX */
1940                     d__2 = xmax, d__3 = (d__1 = vr[j + ieig * vr_dim1], abs(
1941                             d__1));
1942                     xmax = f2cmax(d__2,d__3);
1943 /* L470: */
1944                 }
1945             }
1946
1947             if (xmax > safmin) {
1948                 xscale = 1. / xmax;
1949                 i__1 = nw - 1;
1950                 for (jw = 0; jw <= i__1; ++jw) {
1951                     i__2 = iend;
1952                     for (jr = 1; jr <= i__2; ++jr) {
1953                         vr[jr + (ieig + jw) * vr_dim1] = xscale * vr[jr + (
1954                                 ieig + jw) * vr_dim1];
1955 /* L480: */
1956                     }
1957 /* L490: */
1958                 }
1959             }
1960 L500:
1961             ;
1962         }
1963     }
1964
1965     return 0;
1966
1967 /*     End of DTGEVC */
1968
1969 } /* dtgevc_ */
1970