C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / stgevc.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 real c_b34 = 1.f;
518 static integer c__1 = 1;
519 static real c_b36 = 0.f;
520 static logical c_false = FALSE_;
521
522 /* > \brief \b STGEVC */
523
524 /*  =========== DOCUMENTATION =========== */
525
526 /* Online html documentation available at */
527 /*            http://www.netlib.org/lapack/explore-html/ */
528
529 /* > \htmlonly */
530 /* > Download STGEVC + dependencies */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/stgevc.
532 f"> */
533 /* > [TGZ]</a> */
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/stgevc.
535 f"> */
536 /* > [ZIP]</a> */
537 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/stgevc.
538 f"> */
539 /* > [TXT]</a> */
540 /* > \endhtmlonly */
541
542 /*  Definition: */
543 /*  =========== */
544
545 /*       SUBROUTINE STGEVC( 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 /*       REAL               P( LDP, * ), S( LDS, * ), VL( LDVL, * ), */
552 /*      $                   VR( LDVR, * ), WORK( * ) */
553
554
555
556 /* > \par Purpose: */
557 /*  ============= */
558 /* > */
559 /* > \verbatim */
560 /* > */
561 /* > STGEVC 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 SGGHRD + SHGEQZ. */
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 REAL array, dimension (LDS,N) */
632 /* >          The upper quasi-triangular matrix S from a generalized Schur */
633 /* >          factorization, as computed by SHGEQZ. */
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 REAL array, dimension (LDP,N) */
645 /* >          The upper triangular matrix P from a generalized Schur */
646 /* >          factorization, as computed by SHGEQZ. */
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 REAL 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 SHGEQZ). */
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 REAL 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 SHGEQZ). */
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 REAL 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 realGEcomputational */
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 stgevc_(char *side, char *howmny, logical *select, 
816         integer *n, real *s, integer *lds, real *p, integer *ldp, real *vl, 
817         integer *ldvl, real *vr, integer *ldvr, integer *mm, integer *m, real 
818         *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     real r__1, r__2, r__3, r__4, r__5, r__6;
824
825     /* Local variables */
826     integer ibeg, ieig, iend;
827     real dmin__, temp, xmax, sump[4]    /* was [2][2] */, sums[4]       /* 
828             was [2][2] */, cim2a, cim2b, cre2a, cre2b;
829     extern /* Subroutine */ int slag2_(real *, integer *, real *, integer *, 
830             real *, real *, real *, real *, real *, real *);
831     real temp2, bdiag[2];
832     integer i__, j;
833     real acoef, scale;
834     logical ilall;
835     integer iside;
836     real sbeta;
837     extern logical lsame_(char *, char *);
838     logical il2by2;
839     integer iinfo;
840     real small;
841     logical compl;
842     real anorm, bnorm;
843     logical compr;
844     extern /* Subroutine */ int sgemv_(char *, integer *, integer *, real *, 
845             real *, integer *, real *, integer *, real *, real *, integer *), slaln2_(logical *, integer *, integer *, real *, real *, 
846             real *, integer *, real *, real *, real *, integer *, real *, 
847             real *, real *, integer *, real *, real *, integer *);
848     real temp2i, temp2r;
849     integer ja;
850     logical ilabad, ilbbad;
851     integer jc, je, na;
852     real acoefa, bcoefa, cimaga, cimagb;
853     logical ilback;
854     integer im;
855     real bcoefi, ascale, bscale, creala;
856     integer jr;
857     real crealb;
858     extern /* Subroutine */ int slabad_(real *, real *);
859     real bcoefr;
860     integer jw, nw;
861     extern real slamch_(char *);
862     real salfar, safmin;
863     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
864     real xscale, bignum;
865     logical ilcomp, ilcplx;
866     extern /* Subroutine */ int slacpy_(char *, integer *, integer *, real *, 
867             integer *, real *, integer *);
868     integer ihwmny;
869     real big;
870     logical lsa, lsb;
871     real ulp, sum[4]    /* was [2][2] */;
872
873
874 /*  -- LAPACK computational routine (version 3.7.0) -- */
875 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
876 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
877 /*     December 2016 */
878
879
880
881 /*  ===================================================================== */
882
883
884 /*     Decode and Test the input parameters */
885
886     /* Parameter adjustments */
887     --select;
888     s_dim1 = *lds;
889     s_offset = 1 + s_dim1 * 1;
890     s -= s_offset;
891     p_dim1 = *ldp;
892     p_offset = 1 + p_dim1 * 1;
893     p -= p_offset;
894     vl_dim1 = *ldvl;
895     vl_offset = 1 + vl_dim1 * 1;
896     vl -= vl_offset;
897     vr_dim1 = *ldvr;
898     vr_offset = 1 + vr_dim1 * 1;
899     vr -= vr_offset;
900     --work;
901
902     /* Function Body */
903     if (lsame_(howmny, "A")) {
904         ihwmny = 1;
905         ilall = TRUE_;
906         ilback = FALSE_;
907     } else if (lsame_(howmny, "S")) {
908         ihwmny = 2;
909         ilall = FALSE_;
910         ilback = FALSE_;
911     } else if (lsame_(howmny, "B")) {
912         ihwmny = 3;
913         ilall = TRUE_;
914         ilback = TRUE_;
915     } else {
916         ihwmny = -1;
917         ilall = TRUE_;
918     }
919
920     if (lsame_(side, "R")) {
921         iside = 1;
922         compl = FALSE_;
923         compr = TRUE_;
924     } else if (lsame_(side, "L")) {
925         iside = 2;
926         compl = TRUE_;
927         compr = FALSE_;
928     } else if (lsame_(side, "B")) {
929         iside = 3;
930         compl = TRUE_;
931         compr = TRUE_;
932     } else {
933         iside = -1;
934     }
935
936     *info = 0;
937     if (iside < 0) {
938         *info = -1;
939     } else if (ihwmny < 0) {
940         *info = -2;
941     } else if (*n < 0) {
942         *info = -4;
943     } else if (*lds < f2cmax(1,*n)) {
944         *info = -6;
945     } else if (*ldp < f2cmax(1,*n)) {
946         *info = -8;
947     }
948     if (*info != 0) {
949         i__1 = -(*info);
950         xerbla_("STGEVC", &i__1, (ftnlen)6);
951         return 0;
952     }
953
954 /*     Count the number of eigenvectors to be computed */
955
956     if (! ilall) {
957         im = 0;
958         ilcplx = FALSE_;
959         i__1 = *n;
960         for (j = 1; j <= i__1; ++j) {
961             if (ilcplx) {
962                 ilcplx = FALSE_;
963                 goto L10;
964             }
965             if (j < *n) {
966                 if (s[j + 1 + j * s_dim1] != 0.f) {
967                     ilcplx = TRUE_;
968                 }
969             }
970             if (ilcplx) {
971                 if (select[j] || select[j + 1]) {
972                     im += 2;
973                 }
974             } else {
975                 if (select[j]) {
976                     ++im;
977                 }
978             }
979 L10:
980             ;
981         }
982     } else {
983         im = *n;
984     }
985
986 /*     Check 2-by-2 diagonal blocks of A, B */
987
988     ilabad = FALSE_;
989     ilbbad = FALSE_;
990     i__1 = *n - 1;
991     for (j = 1; j <= i__1; ++j) {
992         if (s[j + 1 + j * s_dim1] != 0.f) {
993             if (p[j + j * p_dim1] == 0.f || p[j + 1 + (j + 1) * p_dim1] == 
994                     0.f || p[j + (j + 1) * p_dim1] != 0.f) {
995                 ilbbad = TRUE_;
996             }
997             if (j < *n - 1) {
998                 if (s[j + 2 + (j + 1) * s_dim1] != 0.f) {
999                     ilabad = TRUE_;
1000                 }
1001             }
1002         }
1003 /* L20: */
1004     }
1005
1006     if (ilabad) {
1007         *info = -5;
1008     } else if (ilbbad) {
1009         *info = -7;
1010     } else if (compl && *ldvl < *n || *ldvl < 1) {
1011         *info = -10;
1012     } else if (compr && *ldvr < *n || *ldvr < 1) {
1013         *info = -12;
1014     } else if (*mm < im) {
1015         *info = -13;
1016     }
1017     if (*info != 0) {
1018         i__1 = -(*info);
1019         xerbla_("STGEVC", &i__1, (ftnlen)6);
1020         return 0;
1021     }
1022
1023 /*     Quick return if possible */
1024
1025     *m = im;
1026     if (*n == 0) {
1027         return 0;
1028     }
1029
1030 /*     Machine Constants */
1031
1032     safmin = slamch_("Safe minimum");
1033     big = 1.f / safmin;
1034     slabad_(&safmin, &big);
1035     ulp = slamch_("Epsilon") * slamch_("Base");
1036     small = safmin * *n / ulp;
1037     big = 1.f / small;
1038     bignum = 1.f / (safmin * *n);
1039
1040 /*     Compute the 1-norm of each column of the strictly upper triangular */
1041 /*     part (i.e., excluding all elements belonging to the diagonal */
1042 /*     blocks) of A and B to check for possible overflow in the */
1043 /*     triangular solver. */
1044
1045     anorm = (r__1 = s[s_dim1 + 1], abs(r__1));
1046     if (*n > 1) {
1047         anorm += (r__1 = s[s_dim1 + 2], abs(r__1));
1048     }
1049     bnorm = (r__1 = p[p_dim1 + 1], abs(r__1));
1050     work[1] = 0.f;
1051     work[*n + 1] = 0.f;
1052
1053     i__1 = *n;
1054     for (j = 2; j <= i__1; ++j) {
1055         temp = 0.f;
1056         temp2 = 0.f;
1057         if (s[j + (j - 1) * s_dim1] == 0.f) {
1058             iend = j - 1;
1059         } else {
1060             iend = j - 2;
1061         }
1062         i__2 = iend;
1063         for (i__ = 1; i__ <= i__2; ++i__) {
1064             temp += (r__1 = s[i__ + j * s_dim1], abs(r__1));
1065             temp2 += (r__1 = p[i__ + j * p_dim1], abs(r__1));
1066 /* L30: */
1067         }
1068         work[j] = temp;
1069         work[*n + j] = temp2;
1070 /* Computing MIN */
1071         i__3 = j + 1;
1072         i__2 = f2cmin(i__3,*n);
1073         for (i__ = iend + 1; i__ <= i__2; ++i__) {
1074             temp += (r__1 = s[i__ + j * s_dim1], abs(r__1));
1075             temp2 += (r__1 = p[i__ + j * p_dim1], abs(r__1));
1076 /* L40: */
1077         }
1078         anorm = f2cmax(anorm,temp);
1079         bnorm = f2cmax(bnorm,temp2);
1080 /* L50: */
1081     }
1082
1083     ascale = 1.f / f2cmax(anorm,safmin);
1084     bscale = 1.f / f2cmax(bnorm,safmin);
1085
1086 /*     Left eigenvectors */
1087
1088     if (compl) {
1089         ieig = 0;
1090
1091 /*        Main loop over eigenvalues */
1092
1093         ilcplx = FALSE_;
1094         i__1 = *n;
1095         for (je = 1; je <= i__1; ++je) {
1096
1097 /*           Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or */
1098 /*           (b) this would be the second of a complex pair. */
1099 /*           Check for complex eigenvalue, so as to be sure of which */
1100 /*           entry(-ies) of SELECT to look at. */
1101
1102             if (ilcplx) {
1103                 ilcplx = FALSE_;
1104                 goto L220;
1105             }
1106             nw = 1;
1107             if (je < *n) {
1108                 if (s[je + 1 + je * s_dim1] != 0.f) {
1109                     ilcplx = TRUE_;
1110                     nw = 2;
1111                 }
1112             }
1113             if (ilall) {
1114                 ilcomp = TRUE_;
1115             } else if (ilcplx) {
1116                 ilcomp = select[je] || select[je + 1];
1117             } else {
1118                 ilcomp = select[je];
1119             }
1120             if (! ilcomp) {
1121                 goto L220;
1122             }
1123
1124 /*           Decide if (a) singular pencil, (b) real eigenvalue, or */
1125 /*           (c) complex eigenvalue. */
1126
1127             if (! ilcplx) {
1128                 if ((r__1 = s[je + je * s_dim1], abs(r__1)) <= safmin && (
1129                         r__2 = p[je + je * p_dim1], abs(r__2)) <= safmin) {
1130
1131 /*                 Singular matrix pencil -- return unit eigenvector */
1132
1133                     ++ieig;
1134                     i__2 = *n;
1135                     for (jr = 1; jr <= i__2; ++jr) {
1136                         vl[jr + ieig * vl_dim1] = 0.f;
1137 /* L60: */
1138                     }
1139                     vl[ieig + ieig * vl_dim1] = 1.f;
1140                     goto L220;
1141                 }
1142             }
1143
1144 /*           Clear vector */
1145
1146             i__2 = nw * *n;
1147             for (jr = 1; jr <= i__2; ++jr) {
1148                 work[(*n << 1) + jr] = 0.f;
1149 /* L70: */
1150             }
1151 /*                                                 T */
1152 /*           Compute coefficients in  ( a A - b B )  y = 0 */
1153 /*              a  is  ACOEF */
1154 /*              b  is  BCOEFR + i*BCOEFI */
1155
1156             if (! ilcplx) {
1157
1158 /*              Real eigenvalue */
1159
1160 /* Computing MAX */
1161                 r__3 = (r__1 = s[je + je * s_dim1], abs(r__1)) * ascale, r__4 
1162                         = (r__2 = p[je + je * p_dim1], abs(r__2)) * bscale, 
1163                         r__3 = f2cmax(r__3,r__4);
1164                 temp = 1.f / f2cmax(r__3,safmin);
1165                 salfar = temp * s[je + je * s_dim1] * ascale;
1166                 sbeta = temp * p[je + je * p_dim1] * bscale;
1167                 acoef = sbeta * ascale;
1168                 bcoefr = salfar * bscale;
1169                 bcoefi = 0.f;
1170
1171 /*              Scale to avoid underflow */
1172
1173                 scale = 1.f;
1174                 lsa = abs(sbeta) >= safmin && abs(acoef) < small;
1175                 lsb = abs(salfar) >= safmin && abs(bcoefr) < small;
1176                 if (lsa) {
1177                     scale = small / abs(sbeta) * f2cmin(anorm,big);
1178                 }
1179                 if (lsb) {
1180 /* Computing MAX */
1181                     r__1 = scale, r__2 = small / abs(salfar) * f2cmin(bnorm,big);
1182                     scale = f2cmax(r__1,r__2);
1183                 }
1184                 if (lsa || lsb) {
1185 /* Computing MIN */
1186 /* Computing MAX */
1187                     r__3 = 1.f, r__4 = abs(acoef), r__3 = f2cmax(r__3,r__4), 
1188                             r__4 = abs(bcoefr);
1189                     r__1 = scale, r__2 = 1.f / (safmin * f2cmax(r__3,r__4));
1190                     scale = f2cmin(r__1,r__2);
1191                     if (lsa) {
1192                         acoef = ascale * (scale * sbeta);
1193                     } else {
1194                         acoef = scale * acoef;
1195                     }
1196                     if (lsb) {
1197                         bcoefr = bscale * (scale * salfar);
1198                     } else {
1199                         bcoefr = scale * bcoefr;
1200                     }
1201                 }
1202                 acoefa = abs(acoef);
1203                 bcoefa = abs(bcoefr);
1204
1205 /*              First component is 1 */
1206
1207                 work[(*n << 1) + je] = 1.f;
1208                 xmax = 1.f;
1209             } else {
1210
1211 /*              Complex eigenvalue */
1212
1213                 r__1 = safmin * 100.f;
1214                 slag2_(&s[je + je * s_dim1], lds, &p[je + je * p_dim1], ldp, &
1215                         r__1, &acoef, &temp, &bcoefr, &temp2, &bcoefi);
1216                 bcoefi = -bcoefi;
1217                 if (bcoefi == 0.f) {
1218                     *info = je;
1219                     return 0;
1220                 }
1221
1222 /*              Scale to avoid over/underflow */
1223
1224                 acoefa = abs(acoef);
1225                 bcoefa = abs(bcoefr) + abs(bcoefi);
1226                 scale = 1.f;
1227                 if (acoefa * ulp < safmin && acoefa >= safmin) {
1228                     scale = safmin / ulp / acoefa;
1229                 }
1230                 if (bcoefa * ulp < safmin && bcoefa >= safmin) {
1231 /* Computing MAX */
1232                     r__1 = scale, r__2 = safmin / ulp / bcoefa;
1233                     scale = f2cmax(r__1,r__2);
1234                 }
1235                 if (safmin * acoefa > ascale) {
1236                     scale = ascale / (safmin * acoefa);
1237                 }
1238                 if (safmin * bcoefa > bscale) {
1239 /* Computing MIN */
1240                     r__1 = scale, r__2 = bscale / (safmin * bcoefa);
1241                     scale = f2cmin(r__1,r__2);
1242                 }
1243                 if (scale != 1.f) {
1244                     acoef = scale * acoef;
1245                     acoefa = abs(acoef);
1246                     bcoefr = scale * bcoefr;
1247                     bcoefi = scale * bcoefi;
1248                     bcoefa = abs(bcoefr) + abs(bcoefi);
1249                 }
1250
1251 /*              Compute first two components of eigenvector */
1252
1253                 temp = acoef * s[je + 1 + je * s_dim1];
1254                 temp2r = acoef * s[je + je * s_dim1] - bcoefr * p[je + je * 
1255                         p_dim1];
1256                 temp2i = -bcoefi * p[je + je * p_dim1];
1257                 if (abs(temp) > abs(temp2r) + abs(temp2i)) {
1258                     work[(*n << 1) + je] = 1.f;
1259                     work[*n * 3 + je] = 0.f;
1260                     work[(*n << 1) + je + 1] = -temp2r / temp;
1261                     work[*n * 3 + je + 1] = -temp2i / temp;
1262                 } else {
1263                     work[(*n << 1) + je + 1] = 1.f;
1264                     work[*n * 3 + je + 1] = 0.f;
1265                     temp = acoef * s[je + (je + 1) * s_dim1];
1266                     work[(*n << 1) + je] = (bcoefr * p[je + 1 + (je + 1) * 
1267                             p_dim1] - acoef * s[je + 1 + (je + 1) * s_dim1]) /
1268                              temp;
1269                     work[*n * 3 + je] = bcoefi * p[je + 1 + (je + 1) * p_dim1]
1270                              / temp;
1271                 }
1272 /* Computing MAX */
1273                 r__5 = (r__1 = work[(*n << 1) + je], abs(r__1)) + (r__2 = 
1274                         work[*n * 3 + je], abs(r__2)), r__6 = (r__3 = work[(*
1275                         n << 1) + je + 1], abs(r__3)) + (r__4 = work[*n * 3 + 
1276                         je + 1], abs(r__4));
1277                 xmax = f2cmax(r__5,r__6);
1278             }
1279
1280 /* Computing MAX */
1281             r__1 = ulp * acoefa * anorm, r__2 = ulp * bcoefa * bnorm, r__1 = 
1282                     f2cmax(r__1,r__2);
1283             dmin__ = f2cmax(r__1,safmin);
1284
1285 /*                                           T */
1286 /*           Triangular solve of  (a A - b B)  y = 0 */
1287
1288 /*                                   T */
1289 /*           (rowwise in  (a A - b B) , or columnwise in (a A - b B) ) */
1290
1291             il2by2 = FALSE_;
1292
1293             i__2 = *n;
1294             for (j = je + nw; j <= i__2; ++j) {
1295                 if (il2by2) {
1296                     il2by2 = FALSE_;
1297                     goto L160;
1298                 }
1299
1300                 na = 1;
1301                 bdiag[0] = p[j + j * p_dim1];
1302                 if (j < *n) {
1303                     if (s[j + 1 + j * s_dim1] != 0.f) {
1304                         il2by2 = TRUE_;
1305                         bdiag[1] = p[j + 1 + (j + 1) * p_dim1];
1306                         na = 2;
1307                     }
1308                 }
1309
1310 /*              Check whether scaling is necessary for dot products */
1311
1312                 xscale = 1.f / f2cmax(1.f,xmax);
1313 /* Computing MAX */
1314                 r__1 = work[j], r__2 = work[*n + j], r__1 = f2cmax(r__1,r__2), 
1315                         r__2 = acoefa * work[j] + bcoefa * work[*n + j];
1316                 temp = f2cmax(r__1,r__2);
1317                 if (il2by2) {
1318 /* Computing MAX */
1319                     r__1 = temp, r__2 = work[j + 1], r__1 = f2cmax(r__1,r__2), 
1320                             r__2 = work[*n + j + 1], r__1 = f2cmax(r__1,r__2), 
1321                             r__2 = acoefa * work[j + 1] + bcoefa * work[*n + 
1322                             j + 1];
1323                     temp = f2cmax(r__1,r__2);
1324                 }
1325                 if (temp > bignum * xscale) {
1326                     i__3 = nw - 1;
1327                     for (jw = 0; jw <= i__3; ++jw) {
1328                         i__4 = j - 1;
1329                         for (jr = je; jr <= i__4; ++jr) {
1330                             work[(jw + 2) * *n + jr] = xscale * work[(jw + 2) 
1331                                     * *n + jr];
1332 /* L80: */
1333                         }
1334 /* L90: */
1335                     }
1336                     xmax *= xscale;
1337                 }
1338
1339 /*              Compute dot products */
1340
1341 /*                    j-1 */
1342 /*              SUM = sum  conjg( a*S(k,j) - b*P(k,j) )*x(k) */
1343 /*                    k=je */
1344
1345 /*              To reduce the op count, this is done as */
1346
1347 /*              _        j-1                  _        j-1 */
1348 /*              a*conjg( sum  S(k,j)*x(k) ) - b*conjg( sum  P(k,j)*x(k) ) */
1349 /*                       k=je                          k=je */
1350
1351 /*              which may cause underflow problems if A or B are close */
1352 /*              to underflow.  (E.g., less than SMALL.) */
1353
1354
1355                 i__3 = nw;
1356                 for (jw = 1; jw <= i__3; ++jw) {
1357                     i__4 = na;
1358                     for (ja = 1; ja <= i__4; ++ja) {
1359                         sums[ja + (jw << 1) - 3] = 0.f;
1360                         sump[ja + (jw << 1) - 3] = 0.f;
1361
1362                         i__5 = j - 1;
1363                         for (jr = je; jr <= i__5; ++jr) {
1364                             sums[ja + (jw << 1) - 3] += s[jr + (j + ja - 1) * 
1365                                     s_dim1] * work[(jw + 1) * *n + jr];
1366                             sump[ja + (jw << 1) - 3] += p[jr + (j + ja - 1) * 
1367                                     p_dim1] * work[(jw + 1) * *n + jr];
1368 /* L100: */
1369                         }
1370 /* L110: */
1371                     }
1372 /* L120: */
1373                 }
1374
1375                 i__3 = na;
1376                 for (ja = 1; ja <= i__3; ++ja) {
1377                     if (ilcplx) {
1378                         sum[ja - 1] = -acoef * sums[ja - 1] + bcoefr * sump[
1379                                 ja - 1] - bcoefi * sump[ja + 1];
1380                         sum[ja + 1] = -acoef * sums[ja + 1] + bcoefr * sump[
1381                                 ja + 1] + bcoefi * sump[ja - 1];
1382                     } else {
1383                         sum[ja - 1] = -acoef * sums[ja - 1] + bcoefr * sump[
1384                                 ja - 1];
1385                     }
1386 /* L130: */
1387                 }
1388
1389 /*                                  T */
1390 /*              Solve  ( a A - b B )  y = SUM(,) */
1391 /*              with scaling and perturbation of the denominator */
1392
1393                 slaln2_(&c_true, &na, &nw, &dmin__, &acoef, &s[j + j * s_dim1]
1394                         , lds, bdiag, &bdiag[1], sum, &c__2, &bcoefr, &bcoefi,
1395                          &work[(*n << 1) + j], n, &scale, &temp, &iinfo);
1396                 if (scale < 1.f) {
1397                     i__3 = nw - 1;
1398                     for (jw = 0; jw <= i__3; ++jw) {
1399                         i__4 = j - 1;
1400                         for (jr = je; jr <= i__4; ++jr) {
1401                             work[(jw + 2) * *n + jr] = scale * work[(jw + 2) *
1402                                      *n + jr];
1403 /* L140: */
1404                         }
1405 /* L150: */
1406                     }
1407                     xmax = scale * xmax;
1408                 }
1409                 xmax = f2cmax(xmax,temp);
1410 L160:
1411                 ;
1412             }
1413
1414 /*           Copy eigenvector to VL, back transforming if */
1415 /*           HOWMNY='B'. */
1416
1417             ++ieig;
1418             if (ilback) {
1419                 i__2 = nw - 1;
1420                 for (jw = 0; jw <= i__2; ++jw) {
1421                     i__3 = *n + 1 - je;
1422                     sgemv_("N", n, &i__3, &c_b34, &vl[je * vl_dim1 + 1], ldvl,
1423                              &work[(jw + 2) * *n + je], &c__1, &c_b36, &work[(
1424                             jw + 4) * *n + 1], &c__1);
1425 /* L170: */
1426                 }
1427                 slacpy_(" ", n, &nw, &work[(*n << 2) + 1], n, &vl[je * 
1428                         vl_dim1 + 1], ldvl);
1429                 ibeg = 1;
1430             } else {
1431                 slacpy_(" ", n, &nw, &work[(*n << 1) + 1], n, &vl[ieig * 
1432                         vl_dim1 + 1], ldvl);
1433                 ibeg = je;
1434             }
1435
1436 /*           Scale eigenvector */
1437
1438             xmax = 0.f;
1439             if (ilcplx) {
1440                 i__2 = *n;
1441                 for (j = ibeg; j <= i__2; ++j) {
1442 /* Computing MAX */
1443                     r__3 = xmax, r__4 = (r__1 = vl[j + ieig * vl_dim1], abs(
1444                             r__1)) + (r__2 = vl[j + (ieig + 1) * vl_dim1], 
1445                             abs(r__2));
1446                     xmax = f2cmax(r__3,r__4);
1447 /* L180: */
1448                 }
1449             } else {
1450                 i__2 = *n;
1451                 for (j = ibeg; j <= i__2; ++j) {
1452 /* Computing MAX */
1453                     r__2 = xmax, r__3 = (r__1 = vl[j + ieig * vl_dim1], abs(
1454                             r__1));
1455                     xmax = f2cmax(r__2,r__3);
1456 /* L190: */
1457                 }
1458             }
1459
1460             if (xmax > safmin) {
1461                 xscale = 1.f / xmax;
1462
1463                 i__2 = nw - 1;
1464                 for (jw = 0; jw <= i__2; ++jw) {
1465                     i__3 = *n;
1466                     for (jr = ibeg; jr <= i__3; ++jr) {
1467                         vl[jr + (ieig + jw) * vl_dim1] = xscale * vl[jr + (
1468                                 ieig + jw) * vl_dim1];
1469 /* L200: */
1470                     }
1471 /* L210: */
1472                 }
1473             }
1474             ieig = ieig + nw - 1;
1475
1476 L220:
1477             ;
1478         }
1479     }
1480
1481 /*     Right eigenvectors */
1482
1483     if (compr) {
1484         ieig = im + 1;
1485
1486 /*        Main loop over eigenvalues */
1487
1488         ilcplx = FALSE_;
1489         for (je = *n; je >= 1; --je) {
1490
1491 /*           Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or */
1492 /*           (b) this would be the second of a complex pair. */
1493 /*           Check for complex eigenvalue, so as to be sure of which */
1494 /*           entry(-ies) of SELECT to look at -- if complex, SELECT(JE) */
1495 /*           or SELECT(JE-1). */
1496 /*           If this is a complex pair, the 2-by-2 diagonal block */
1497 /*           corresponding to the eigenvalue is in rows/columns JE-1:JE */
1498
1499             if (ilcplx) {
1500                 ilcplx = FALSE_;
1501                 goto L500;
1502             }
1503             nw = 1;
1504             if (je > 1) {
1505                 if (s[je + (je - 1) * s_dim1] != 0.f) {
1506                     ilcplx = TRUE_;
1507                     nw = 2;
1508                 }
1509             }
1510             if (ilall) {
1511                 ilcomp = TRUE_;
1512             } else if (ilcplx) {
1513                 ilcomp = select[je] || select[je - 1];
1514             } else {
1515                 ilcomp = select[je];
1516             }
1517             if (! ilcomp) {
1518                 goto L500;
1519             }
1520
1521 /*           Decide if (a) singular pencil, (b) real eigenvalue, or */
1522 /*           (c) complex eigenvalue. */
1523
1524             if (! ilcplx) {
1525                 if ((r__1 = s[je + je * s_dim1], abs(r__1)) <= safmin && (
1526                         r__2 = p[je + je * p_dim1], abs(r__2)) <= safmin) {
1527
1528 /*                 Singular matrix pencil -- unit eigenvector */
1529
1530                     --ieig;
1531                     i__1 = *n;
1532                     for (jr = 1; jr <= i__1; ++jr) {
1533                         vr[jr + ieig * vr_dim1] = 0.f;
1534 /* L230: */
1535                     }
1536                     vr[ieig + ieig * vr_dim1] = 1.f;
1537                     goto L500;
1538                 }
1539             }
1540
1541 /*           Clear vector */
1542
1543             i__1 = nw - 1;
1544             for (jw = 0; jw <= i__1; ++jw) {
1545                 i__2 = *n;
1546                 for (jr = 1; jr <= i__2; ++jr) {
1547                     work[(jw + 2) * *n + jr] = 0.f;
1548 /* L240: */
1549                 }
1550 /* L250: */
1551             }
1552
1553 /*           Compute coefficients in  ( a A - b B ) x = 0 */
1554 /*              a  is  ACOEF */
1555 /*              b  is  BCOEFR + i*BCOEFI */
1556
1557             if (! ilcplx) {
1558
1559 /*              Real eigenvalue */
1560
1561 /* Computing MAX */
1562                 r__3 = (r__1 = s[je + je * s_dim1], abs(r__1)) * ascale, r__4 
1563                         = (r__2 = p[je + je * p_dim1], abs(r__2)) * bscale, 
1564                         r__3 = f2cmax(r__3,r__4);
1565                 temp = 1.f / f2cmax(r__3,safmin);
1566                 salfar = temp * s[je + je * s_dim1] * ascale;
1567                 sbeta = temp * p[je + je * p_dim1] * bscale;
1568                 acoef = sbeta * ascale;
1569                 bcoefr = salfar * bscale;
1570                 bcoefi = 0.f;
1571
1572 /*              Scale to avoid underflow */
1573
1574                 scale = 1.f;
1575                 lsa = abs(sbeta) >= safmin && abs(acoef) < small;
1576                 lsb = abs(salfar) >= safmin && abs(bcoefr) < small;
1577                 if (lsa) {
1578                     scale = small / abs(sbeta) * f2cmin(anorm,big);
1579                 }
1580                 if (lsb) {
1581 /* Computing MAX */
1582                     r__1 = scale, r__2 = small / abs(salfar) * f2cmin(bnorm,big);
1583                     scale = f2cmax(r__1,r__2);
1584                 }
1585                 if (lsa || lsb) {
1586 /* Computing MIN */
1587 /* Computing MAX */
1588                     r__3 = 1.f, r__4 = abs(acoef), r__3 = f2cmax(r__3,r__4), 
1589                             r__4 = abs(bcoefr);
1590                     r__1 = scale, r__2 = 1.f / (safmin * f2cmax(r__3,r__4));
1591                     scale = f2cmin(r__1,r__2);
1592                     if (lsa) {
1593                         acoef = ascale * (scale * sbeta);
1594                     } else {
1595                         acoef = scale * acoef;
1596                     }
1597                     if (lsb) {
1598                         bcoefr = bscale * (scale * salfar);
1599                     } else {
1600                         bcoefr = scale * bcoefr;
1601                     }
1602                 }
1603                 acoefa = abs(acoef);
1604                 bcoefa = abs(bcoefr);
1605
1606 /*              First component is 1 */
1607
1608                 work[(*n << 1) + je] = 1.f;
1609                 xmax = 1.f;
1610
1611 /*              Compute contribution from column JE of A and B to sum */
1612 /*              (See "Further Details", above.) */
1613
1614                 i__1 = je - 1;
1615                 for (jr = 1; jr <= i__1; ++jr) {
1616                     work[(*n << 1) + jr] = bcoefr * p[jr + je * p_dim1] - 
1617                             acoef * s[jr + je * s_dim1];
1618 /* L260: */
1619                 }
1620             } else {
1621
1622 /*              Complex eigenvalue */
1623
1624                 r__1 = safmin * 100.f;
1625                 slag2_(&s[je - 1 + (je - 1) * s_dim1], lds, &p[je - 1 + (je - 
1626                         1) * p_dim1], ldp, &r__1, &acoef, &temp, &bcoefr, &
1627                         temp2, &bcoefi);
1628                 if (bcoefi == 0.f) {
1629                     *info = je - 1;
1630                     return 0;
1631                 }
1632
1633 /*              Scale to avoid over/underflow */
1634
1635                 acoefa = abs(acoef);
1636                 bcoefa = abs(bcoefr) + abs(bcoefi);
1637                 scale = 1.f;
1638                 if (acoefa * ulp < safmin && acoefa >= safmin) {
1639                     scale = safmin / ulp / acoefa;
1640                 }
1641                 if (bcoefa * ulp < safmin && bcoefa >= safmin) {
1642 /* Computing MAX */
1643                     r__1 = scale, r__2 = safmin / ulp / bcoefa;
1644                     scale = f2cmax(r__1,r__2);
1645                 }
1646                 if (safmin * acoefa > ascale) {
1647                     scale = ascale / (safmin * acoefa);
1648                 }
1649                 if (safmin * bcoefa > bscale) {
1650 /* Computing MIN */
1651                     r__1 = scale, r__2 = bscale / (safmin * bcoefa);
1652                     scale = f2cmin(r__1,r__2);
1653                 }
1654                 if (scale != 1.f) {
1655                     acoef = scale * acoef;
1656                     acoefa = abs(acoef);
1657                     bcoefr = scale * bcoefr;
1658                     bcoefi = scale * bcoefi;
1659                     bcoefa = abs(bcoefr) + abs(bcoefi);
1660                 }
1661
1662 /*              Compute first two components of eigenvector */
1663 /*              and contribution to sums */
1664
1665                 temp = acoef * s[je + (je - 1) * s_dim1];
1666                 temp2r = acoef * s[je + je * s_dim1] - bcoefr * p[je + je * 
1667                         p_dim1];
1668                 temp2i = -bcoefi * p[je + je * p_dim1];
1669                 if (abs(temp) >= abs(temp2r) + abs(temp2i)) {
1670                     work[(*n << 1) + je] = 1.f;
1671                     work[*n * 3 + je] = 0.f;
1672                     work[(*n << 1) + je - 1] = -temp2r / temp;
1673                     work[*n * 3 + je - 1] = -temp2i / temp;
1674                 } else {
1675                     work[(*n << 1) + je - 1] = 1.f;
1676                     work[*n * 3 + je - 1] = 0.f;
1677                     temp = acoef * s[je - 1 + je * s_dim1];
1678                     work[(*n << 1) + je] = (bcoefr * p[je - 1 + (je - 1) * 
1679                             p_dim1] - acoef * s[je - 1 + (je - 1) * s_dim1]) /
1680                              temp;
1681                     work[*n * 3 + je] = bcoefi * p[je - 1 + (je - 1) * p_dim1]
1682                              / temp;
1683                 }
1684
1685 /* Computing MAX */
1686                 r__5 = (r__1 = work[(*n << 1) + je], abs(r__1)) + (r__2 = 
1687                         work[*n * 3 + je], abs(r__2)), r__6 = (r__3 = work[(*
1688                         n << 1) + je - 1], abs(r__3)) + (r__4 = work[*n * 3 + 
1689                         je - 1], abs(r__4));
1690                 xmax = f2cmax(r__5,r__6);
1691
1692 /*              Compute contribution from columns JE and JE-1 */
1693 /*              of A and B to the sums. */
1694
1695                 creala = acoef * work[(*n << 1) + je - 1];
1696                 cimaga = acoef * work[*n * 3 + je - 1];
1697                 crealb = bcoefr * work[(*n << 1) + je - 1] - bcoefi * work[*n 
1698                         * 3 + je - 1];
1699                 cimagb = bcoefi * work[(*n << 1) + je - 1] + bcoefr * work[*n 
1700                         * 3 + je - 1];
1701                 cre2a = acoef * work[(*n << 1) + je];
1702                 cim2a = acoef * work[*n * 3 + je];
1703                 cre2b = bcoefr * work[(*n << 1) + je] - bcoefi * work[*n * 3 
1704                         + je];
1705                 cim2b = bcoefi * work[(*n << 1) + je] + bcoefr * work[*n * 3 
1706                         + je];
1707                 i__1 = je - 2;
1708                 for (jr = 1; jr <= i__1; ++jr) {
1709                     work[(*n << 1) + jr] = -creala * s[jr + (je - 1) * s_dim1]
1710                              + crealb * p[jr + (je - 1) * p_dim1] - cre2a * s[
1711                             jr + je * s_dim1] + cre2b * p[jr + je * p_dim1];
1712                     work[*n * 3 + jr] = -cimaga * s[jr + (je - 1) * s_dim1] + 
1713                             cimagb * p[jr + (je - 1) * p_dim1] - cim2a * s[jr 
1714                             + je * s_dim1] + cim2b * p[jr + je * p_dim1];
1715 /* L270: */
1716                 }
1717             }
1718
1719 /* Computing MAX */
1720             r__1 = ulp * acoefa * anorm, r__2 = ulp * bcoefa * bnorm, r__1 = 
1721                     f2cmax(r__1,r__2);
1722             dmin__ = f2cmax(r__1,safmin);
1723
1724 /*           Columnwise triangular solve of  (a A - b B)  x = 0 */
1725
1726             il2by2 = FALSE_;
1727             for (j = je - nw; j >= 1; --j) {
1728
1729 /*              If a 2-by-2 block, is in position j-1:j, wait until */
1730 /*              next iteration to process it (when it will be j:j+1) */
1731
1732                 if (! il2by2 && j > 1) {
1733                     if (s[j + (j - 1) * s_dim1] != 0.f) {
1734                         il2by2 = TRUE_;
1735                         goto L370;
1736                     }
1737                 }
1738                 bdiag[0] = p[j + j * p_dim1];
1739                 if (il2by2) {
1740                     na = 2;
1741                     bdiag[1] = p[j + 1 + (j + 1) * p_dim1];
1742                 } else {
1743                     na = 1;
1744                 }
1745
1746 /*              Compute x(j) (and x(j+1), if 2-by-2 block) */
1747
1748                 slaln2_(&c_false, &na, &nw, &dmin__, &acoef, &s[j + j * 
1749                         s_dim1], lds, bdiag, &bdiag[1], &work[(*n << 1) + j], 
1750                         n, &bcoefr, &bcoefi, sum, &c__2, &scale, &temp, &
1751                         iinfo);
1752                 if (scale < 1.f) {
1753
1754                     i__1 = nw - 1;
1755                     for (jw = 0; jw <= i__1; ++jw) {
1756                         i__2 = je;
1757                         for (jr = 1; jr <= i__2; ++jr) {
1758                             work[(jw + 2) * *n + jr] = scale * work[(jw + 2) *
1759                                      *n + jr];
1760 /* L280: */
1761                         }
1762 /* L290: */
1763                     }
1764                 }
1765 /* Computing MAX */
1766                 r__1 = scale * xmax;
1767                 xmax = f2cmax(r__1,temp);
1768
1769                 i__1 = nw;
1770                 for (jw = 1; jw <= i__1; ++jw) {
1771                     i__2 = na;
1772                     for (ja = 1; ja <= i__2; ++ja) {
1773                         work[(jw + 1) * *n + j + ja - 1] = sum[ja + (jw << 1) 
1774                                 - 3];
1775 /* L300: */
1776                     }
1777 /* L310: */
1778                 }
1779
1780 /*              w = w + x(j)*(a S(*,j) - b P(*,j) ) with scaling */
1781
1782                 if (j > 1) {
1783
1784 /*                 Check whether scaling is necessary for sum. */
1785
1786                     xscale = 1.f / f2cmax(1.f,xmax);
1787                     temp = acoefa * work[j] + bcoefa * work[*n + j];
1788                     if (il2by2) {
1789 /* Computing MAX */
1790                         r__1 = temp, r__2 = acoefa * work[j + 1] + bcoefa * 
1791                                 work[*n + j + 1];
1792                         temp = f2cmax(r__1,r__2);
1793                     }
1794 /* Computing MAX */
1795                     r__1 = f2cmax(temp,acoefa);
1796                     temp = f2cmax(r__1,bcoefa);
1797                     if (temp > bignum * xscale) {
1798
1799                         i__1 = nw - 1;
1800                         for (jw = 0; jw <= i__1; ++jw) {
1801                             i__2 = je;
1802                             for (jr = 1; jr <= i__2; ++jr) {
1803                                 work[(jw + 2) * *n + jr] = xscale * work[(jw 
1804                                         + 2) * *n + jr];
1805 /* L320: */
1806                             }
1807 /* L330: */
1808                         }
1809                         xmax *= xscale;
1810                     }
1811
1812 /*                 Compute the contributions of the off-diagonals of */
1813 /*                 column j (and j+1, if 2-by-2 block) of A and B to the */
1814 /*                 sums. */
1815
1816
1817                     i__1 = na;
1818                     for (ja = 1; ja <= i__1; ++ja) {
1819                         if (ilcplx) {
1820                             creala = acoef * work[(*n << 1) + j + ja - 1];
1821                             cimaga = acoef * work[*n * 3 + j + ja - 1];
1822                             crealb = bcoefr * work[(*n << 1) + j + ja - 1] - 
1823                                     bcoefi * work[*n * 3 + j + ja - 1];
1824                             cimagb = bcoefi * work[(*n << 1) + j + ja - 1] + 
1825                                     bcoefr * work[*n * 3 + j + ja - 1];
1826                             i__2 = j - 1;
1827                             for (jr = 1; jr <= i__2; ++jr) {
1828                                 work[(*n << 1) + jr] = work[(*n << 1) + jr] - 
1829                                         creala * s[jr + (j + ja - 1) * s_dim1]
1830                                          + crealb * p[jr + (j + ja - 1) * 
1831                                         p_dim1];
1832                                 work[*n * 3 + jr] = work[*n * 3 + jr] - 
1833                                         cimaga * s[jr + (j + ja - 1) * s_dim1]
1834                                          + cimagb * p[jr + (j + ja - 1) * 
1835                                         p_dim1];
1836 /* L340: */
1837                             }
1838                         } else {
1839                             creala = acoef * work[(*n << 1) + j + ja - 1];
1840                             crealb = bcoefr * work[(*n << 1) + j + ja - 1];
1841                             i__2 = j - 1;
1842                             for (jr = 1; jr <= i__2; ++jr) {
1843                                 work[(*n << 1) + jr] = work[(*n << 1) + jr] - 
1844                                         creala * s[jr + (j + ja - 1) * s_dim1]
1845                                          + crealb * p[jr + (j + ja - 1) * 
1846                                         p_dim1];
1847 /* L350: */
1848                             }
1849                         }
1850 /* L360: */
1851                     }
1852                 }
1853
1854                 il2by2 = FALSE_;
1855 L370:
1856                 ;
1857             }
1858
1859 /*           Copy eigenvector to VR, back transforming if */
1860 /*           HOWMNY='B'. */
1861
1862             ieig -= nw;
1863             if (ilback) {
1864
1865                 i__1 = nw - 1;
1866                 for (jw = 0; jw <= i__1; ++jw) {
1867                     i__2 = *n;
1868                     for (jr = 1; jr <= i__2; ++jr) {
1869                         work[(jw + 4) * *n + jr] = work[(jw + 2) * *n + 1] * 
1870                                 vr[jr + vr_dim1];
1871 /* L380: */
1872                     }
1873
1874 /*                 A series of compiler directives to defeat */
1875 /*                 vectorization for the next loop */
1876
1877
1878                     i__2 = je;
1879                     for (jc = 2; jc <= i__2; ++jc) {
1880                         i__3 = *n;
1881                         for (jr = 1; jr <= i__3; ++jr) {
1882                             work[(jw + 4) * *n + jr] += work[(jw + 2) * *n + 
1883                                     jc] * vr[jr + jc * vr_dim1];
1884 /* L390: */
1885                         }
1886 /* L400: */
1887                     }
1888 /* L410: */
1889                 }
1890
1891                 i__1 = nw - 1;
1892                 for (jw = 0; jw <= i__1; ++jw) {
1893                     i__2 = *n;
1894                     for (jr = 1; jr <= i__2; ++jr) {
1895                         vr[jr + (ieig + jw) * vr_dim1] = work[(jw + 4) * *n + 
1896                                 jr];
1897 /* L420: */
1898                     }
1899 /* L430: */
1900                 }
1901
1902                 iend = *n;
1903             } else {
1904                 i__1 = nw - 1;
1905                 for (jw = 0; jw <= i__1; ++jw) {
1906                     i__2 = *n;
1907                     for (jr = 1; jr <= i__2; ++jr) {
1908                         vr[jr + (ieig + jw) * vr_dim1] = work[(jw + 2) * *n + 
1909                                 jr];
1910 /* L440: */
1911                     }
1912 /* L450: */
1913                 }
1914
1915                 iend = je;
1916             }
1917
1918 /*           Scale eigenvector */
1919
1920             xmax = 0.f;
1921             if (ilcplx) {
1922                 i__1 = iend;
1923                 for (j = 1; j <= i__1; ++j) {
1924 /* Computing MAX */
1925                     r__3 = xmax, r__4 = (r__1 = vr[j + ieig * vr_dim1], abs(
1926                             r__1)) + (r__2 = vr[j + (ieig + 1) * vr_dim1], 
1927                             abs(r__2));
1928                     xmax = f2cmax(r__3,r__4);
1929 /* L460: */
1930                 }
1931             } else {
1932                 i__1 = iend;
1933                 for (j = 1; j <= i__1; ++j) {
1934 /* Computing MAX */
1935                     r__2 = xmax, r__3 = (r__1 = vr[j + ieig * vr_dim1], abs(
1936                             r__1));
1937                     xmax = f2cmax(r__2,r__3);
1938 /* L470: */
1939                 }
1940             }
1941
1942             if (xmax > safmin) {
1943                 xscale = 1.f / xmax;
1944                 i__1 = nw - 1;
1945                 for (jw = 0; jw <= i__1; ++jw) {
1946                     i__2 = iend;
1947                     for (jr = 1; jr <= i__2; ++jr) {
1948                         vr[jr + (ieig + jw) * vr_dim1] = xscale * vr[jr + (
1949                                 ieig + jw) * vr_dim1];
1950 /* L480: */
1951                     }
1952 /* L490: */
1953                 }
1954             }
1955 L500:
1956             ;
1957         }
1958     }
1959
1960     return 0;
1961
1962 /*     End of STGEVC */
1963
1964 } /* stgevc_ */
1965