C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / strevc3.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 integer c__1 = 1;
516 static integer c_n1 = -1;
517 static integer c__2 = 2;
518 static real c_b17 = 0.f;
519 static logical c_false = FALSE_;
520 static real c_b29 = 1.f;
521 static logical c_true = TRUE_;
522
523 /* > \brief \b STREVC3 */
524
525 /*  =========== DOCUMENTATION =========== */
526
527 /* Online html documentation available at */
528 /*            http://www.netlib.org/lapack/explore-html/ */
529
530 /* > \htmlonly */
531 /* > Download STREVC3 + dependencies */
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/strevc3
533 .f"> */
534 /* > [TGZ]</a> */
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/strevc3
536 .f"> */
537 /* > [ZIP]</a> */
538 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/strevc3
539 .f"> */
540 /* > [TXT]</a> */
541 /* > \endhtmlonly */
542
543 /*  Definition: */
544 /*  =========== */
545
546 /*       SUBROUTINE STREVC3( SIDE, HOWMNY, SELECT, N, T, LDT, VL, LDVL, */
547 /*                           VR, LDVR, MM, M, WORK, LWORK, INFO ) */
548
549 /*       CHARACTER          HOWMNY, SIDE */
550 /*       INTEGER            INFO, LDT, LDVL, LDVR, LWORK, M, MM, N */
551 /*       LOGICAL            SELECT( * ) */
552 /*       REAL               T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ), */
553 /*      $                   WORK( * ) */
554
555
556 /* > \par Purpose: */
557 /*  ============= */
558 /* > */
559 /* > \verbatim */
560 /* > */
561 /* > STREVC3 computes some or all of the right and/or left eigenvectors of */
562 /* > a real upper quasi-triangular matrix T. */
563 /* > Matrices of this type are produced by the Schur factorization of */
564 /* > a real general matrix:  A = Q*T*Q**T, as computed by SHSEQR. */
565 /* > */
566 /* > The right eigenvector x and the left eigenvector y of T corresponding */
567 /* > to an eigenvalue w are defined by: */
568 /* > */
569 /* >    T*x = w*x,     (y**T)*T = w*(y**T) */
570 /* > */
571 /* > where y**T denotes the transpose of the vector y. */
572 /* > The eigenvalues are not input to this routine, but are read directly */
573 /* > from the diagonal blocks of T. */
574 /* > */
575 /* > This routine returns the matrices X and/or Y of right and left */
576 /* > eigenvectors of T, or the products Q*X and/or Q*Y, where Q is an */
577 /* > input matrix. If Q is the orthogonal factor that reduces a matrix */
578 /* > A to Schur form T, then Q*X and Q*Y are the matrices of right and */
579 /* > left eigenvectors of A. */
580 /* > */
581 /* > This uses a Level 3 BLAS version of the back transformation. */
582 /* > \endverbatim */
583
584 /*  Arguments: */
585 /*  ========== */
586
587 /* > \param[in] SIDE */
588 /* > \verbatim */
589 /* >          SIDE is CHARACTER*1 */
590 /* >          = 'R':  compute right eigenvectors only; */
591 /* >          = 'L':  compute left eigenvectors only; */
592 /* >          = 'B':  compute both right and left eigenvectors. */
593 /* > \endverbatim */
594 /* > */
595 /* > \param[in] HOWMNY */
596 /* > \verbatim */
597 /* >          HOWMNY is CHARACTER*1 */
598 /* >          = 'A':  compute all right and/or left eigenvectors; */
599 /* >          = 'B':  compute all right and/or left eigenvectors, */
600 /* >                  backtransformed by the matrices in VR and/or VL; */
601 /* >          = 'S':  compute selected right and/or left eigenvectors, */
602 /* >                  as indicated by the logical array SELECT. */
603 /* > \endverbatim */
604 /* > */
605 /* > \param[in,out] SELECT */
606 /* > \verbatim */
607 /* >          SELECT is LOGICAL array, dimension (N) */
608 /* >          If HOWMNY = 'S', SELECT specifies the eigenvectors to be */
609 /* >          computed. */
610 /* >          If w(j) is a real eigenvalue, the corresponding real */
611 /* >          eigenvector is computed if SELECT(j) is .TRUE.. */
612 /* >          If w(j) and w(j+1) are the real and imaginary parts of a */
613 /* >          complex eigenvalue, the corresponding complex eigenvector is */
614 /* >          computed if either SELECT(j) or SELECT(j+1) is .TRUE., and */
615 /* >          on exit SELECT(j) is set to .TRUE. and SELECT(j+1) is set to */
616 /* >          .FALSE.. */
617 /* >          Not referenced if HOWMNY = 'A' or 'B'. */
618 /* > \endverbatim */
619 /* > */
620 /* > \param[in] N */
621 /* > \verbatim */
622 /* >          N is INTEGER */
623 /* >          The order of the matrix T. N >= 0. */
624 /* > \endverbatim */
625 /* > */
626 /* > \param[in] T */
627 /* > \verbatim */
628 /* >          T is REAL array, dimension (LDT,N) */
629 /* >          The upper quasi-triangular matrix T in Schur canonical form. */
630 /* > \endverbatim */
631 /* > */
632 /* > \param[in] LDT */
633 /* > \verbatim */
634 /* >          LDT is INTEGER */
635 /* >          The leading dimension of the array T. LDT >= f2cmax(1,N). */
636 /* > \endverbatim */
637 /* > */
638 /* > \param[in,out] VL */
639 /* > \verbatim */
640 /* >          VL is REAL array, dimension (LDVL,MM) */
641 /* >          On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must */
642 /* >          contain an N-by-N matrix Q (usually the orthogonal matrix Q */
643 /* >          of Schur vectors returned by SHSEQR). */
644 /* >          On exit, if SIDE = 'L' or 'B', VL contains: */
645 /* >          if HOWMNY = 'A', the matrix Y of left eigenvectors of T; */
646 /* >          if HOWMNY = 'B', the matrix Q*Y; */
647 /* >          if HOWMNY = 'S', the left eigenvectors of T specified by */
648 /* >                           SELECT, stored consecutively in the columns */
649 /* >                           of VL, in the same order as their */
650 /* >                           eigenvalues. */
651 /* >          A complex eigenvector corresponding to a complex eigenvalue */
652 /* >          is stored in two consecutive columns, the first holding the */
653 /* >          real part, and the second the imaginary part. */
654 /* >          Not referenced if SIDE = 'R'. */
655 /* > \endverbatim */
656 /* > */
657 /* > \param[in] LDVL */
658 /* > \verbatim */
659 /* >          LDVL is INTEGER */
660 /* >          The leading dimension of the array VL. */
661 /* >          LDVL >= 1, and if SIDE = 'L' or 'B', LDVL >= N. */
662 /* > \endverbatim */
663 /* > */
664 /* > \param[in,out] VR */
665 /* > \verbatim */
666 /* >          VR is REAL array, dimension (LDVR,MM) */
667 /* >          On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must */
668 /* >          contain an N-by-N matrix Q (usually the orthogonal matrix Q */
669 /* >          of Schur vectors returned by SHSEQR). */
670 /* >          On exit, if SIDE = 'R' or 'B', VR contains: */
671 /* >          if HOWMNY = 'A', the matrix X of right eigenvectors of T; */
672 /* >          if HOWMNY = 'B', the matrix Q*X; */
673 /* >          if HOWMNY = 'S', the right eigenvectors of T specified by */
674 /* >                           SELECT, stored consecutively in the columns */
675 /* >                           of VR, in the same order as their */
676 /* >                           eigenvalues. */
677 /* >          A complex eigenvector corresponding to a complex eigenvalue */
678 /* >          is stored in two consecutive columns, the first holding the */
679 /* >          real part and the second the imaginary part. */
680 /* >          Not referenced if SIDE = 'L'. */
681 /* > \endverbatim */
682 /* > */
683 /* > \param[in] LDVR */
684 /* > \verbatim */
685 /* >          LDVR is INTEGER */
686 /* >          The leading dimension of the array VR. */
687 /* >          LDVR >= 1, and if SIDE = 'R' or 'B', LDVR >= N. */
688 /* > \endverbatim */
689 /* > */
690 /* > \param[in] MM */
691 /* > \verbatim */
692 /* >          MM is INTEGER */
693 /* >          The number of columns in the arrays VL and/or VR. MM >= M. */
694 /* > \endverbatim */
695 /* > */
696 /* > \param[out] M */
697 /* > \verbatim */
698 /* >          M is INTEGER */
699 /* >          The number of columns in the arrays VL and/or VR actually */
700 /* >          used to store the eigenvectors. */
701 /* >          If HOWMNY = 'A' or 'B', M is set to N. */
702 /* >          Each selected real eigenvector occupies one column and each */
703 /* >          selected complex eigenvector occupies two columns. */
704 /* > \endverbatim */
705 /* > */
706 /* > \param[out] WORK */
707 /* > \verbatim */
708 /* >          WORK is REAL array, dimension (MAX(1,LWORK)) */
709 /* > \endverbatim */
710 /* > */
711 /* > \param[in] LWORK */
712 /* > \verbatim */
713 /* >          LWORK is INTEGER */
714 /* >          The dimension of array WORK. LWORK >= f2cmax(1,3*N). */
715 /* >          For optimum performance, LWORK >= N + 2*N*NB, where NB is */
716 /* >          the optimal blocksize. */
717 /* > */
718 /* >          If LWORK = -1, then a workspace query is assumed; the routine */
719 /* >          only calculates the optimal size of the WORK array, returns */
720 /* >          this value as the first entry of the WORK array, and no error */
721 /* >          message related to LWORK is issued by XERBLA. */
722 /* > \endverbatim */
723 /* > */
724 /* > \param[out] INFO */
725 /* > \verbatim */
726 /* >          INFO is INTEGER */
727 /* >          = 0:  successful exit */
728 /* >          < 0:  if INFO = -i, the i-th argument had an illegal value */
729 /* > \endverbatim */
730
731 /*  Authors: */
732 /*  ======== */
733
734 /* > \author Univ. of Tennessee */
735 /* > \author Univ. of California Berkeley */
736 /* > \author Univ. of Colorado Denver */
737 /* > \author NAG Ltd. */
738
739 /* > \date November 2017 */
740
741 /*  @generated from dtrevc3.f, fortran d -> s, Tue Apr 19 01:47:44 2016 */
742
743 /* > \ingroup realOTHERcomputational */
744
745 /* > \par Further Details: */
746 /*  ===================== */
747 /* > */
748 /* > \verbatim */
749 /* > */
750 /* >  The algorithm used in this program is basically backward (forward) */
751 /* >  substitution, with scaling to make the the code robust against */
752 /* >  possible overflow. */
753 /* > */
754 /* >  Each eigenvector is normalized so that the element of largest */
755 /* >  magnitude has magnitude 1; here the magnitude of a complex number */
756 /* >  (x,y) is taken to be |x| + |y|. */
757 /* > \endverbatim */
758 /* > */
759 /*  ===================================================================== */
760 /* Subroutine */ int strevc3_(char *side, char *howmny, logical *select, 
761         integer *n, real *t, integer *ldt, real *vl, integer *ldvl, real *vr, 
762         integer *ldvr, integer *mm, integer *m, real *work, integer *lwork, 
763         integer *info)
764 {
765     /* System generated locals */
766     address a__1[2];
767     integer t_dim1, t_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1[2],
768              i__2, i__3, i__4;
769     real r__1, r__2, r__3, r__4;
770     char ch__1[2];
771
772     /* Local variables */
773     real beta, emax;
774     logical pair, allv;
775     integer ierr;
776     real unfl, ovfl, smin;
777     extern real sdot_(integer *, real *, integer *, real *, integer *);
778     logical over;
779     real vmax;
780     integer jnxt, i__, j, k;
781     real scale, x[4]    /* was [2][2] */;
782     extern logical lsame_(char *, char *);
783     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *), 
784             sgemm_(char *, char *, integer *, integer *, integer *, real *, 
785             real *, integer *, real *, integer *, real *, real *, integer *);
786     real remax;
787     logical leftv;
788     extern /* Subroutine */ int sgemv_(char *, integer *, integer *, real *, 
789             real *, integer *, real *, integer *, real *, real *, integer *);
790     logical bothv;
791     real vcrit;
792     logical somev;
793     integer j1, j2;
794     extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 
795             integer *);
796     real xnorm;
797     extern /* Subroutine */ int saxpy_(integer *, real *, real *, integer *, 
798             real *, integer *);
799     integer iscomplex[128];
800     extern /* Subroutine */ int slaln2_(logical *, integer *, integer *, real 
801             *, real *, real *, integer *, real *, real *, real *, integer *, 
802             real *, real *, real *, integer *, real *, real *, integer *);
803     integer nb, ii, ki;
804     extern /* Subroutine */ int slabad_(real *, real *);
805     integer ip, is, iv;
806     real wi;
807     extern real slamch_(char *);
808     real wr;
809     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
810     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
811             integer *, integer *, ftnlen, ftnlen);
812     real bignum;
813     extern integer isamax_(integer *, real *, integer *);
814     extern /* Subroutine */ int slacpy_(char *, integer *, integer *, real *, 
815             integer *, real *, integer *), slaset_(char *, integer *, 
816             integer *, real *, real *, real *, integer *);
817     logical rightv;
818     integer ki2, maxwrk;
819     real smlnum;
820     logical lquery;
821     real rec, ulp;
822
823
824 /*  -- LAPACK computational routine (version 3.8.0) -- */
825 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
826 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
827 /*     November 2017 */
828
829
830 /*  ===================================================================== */
831
832
833 /*     Decode and test the input parameters */
834
835     /* Parameter adjustments */
836     --select;
837     t_dim1 = *ldt;
838     t_offset = 1 + t_dim1 * 1;
839     t -= t_offset;
840     vl_dim1 = *ldvl;
841     vl_offset = 1 + vl_dim1 * 1;
842     vl -= vl_offset;
843     vr_dim1 = *ldvr;
844     vr_offset = 1 + vr_dim1 * 1;
845     vr -= vr_offset;
846     --work;
847
848     /* Function Body */
849     bothv = lsame_(side, "B");
850     rightv = lsame_(side, "R") || bothv;
851     leftv = lsame_(side, "L") || bothv;
852
853     allv = lsame_(howmny, "A");
854     over = lsame_(howmny, "B");
855     somev = lsame_(howmny, "S");
856
857     *info = 0;
858 /* Writing concatenation */
859     i__1[0] = 1, a__1[0] = side;
860     i__1[1] = 1, a__1[1] = howmny;
861     s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)2);
862     nb = ilaenv_(&c__1, "STREVC", ch__1, n, &c_n1, &c_n1, &c_n1, (ftnlen)6, (
863             ftnlen)2);
864     maxwrk = *n + (*n << 1) * nb;
865     work[1] = (real) maxwrk;
866     lquery = *lwork == -1;
867     if (! rightv && ! leftv) {
868         *info = -1;
869     } else if (! allv && ! over && ! somev) {
870         *info = -2;
871     } else if (*n < 0) {
872         *info = -4;
873     } else if (*ldt < f2cmax(1,*n)) {
874         *info = -6;
875     } else if (*ldvl < 1 || leftv && *ldvl < *n) {
876         *info = -8;
877     } else if (*ldvr < 1 || rightv && *ldvr < *n) {
878         *info = -10;
879     } else /* if(complicated condition) */ {
880 /* Computing MAX */
881         i__2 = 1, i__3 = *n * 3;
882         if (*lwork < f2cmax(i__2,i__3) && ! lquery) {
883             *info = -14;
884         } else {
885
886 /*        Set M to the number of columns required to store the selected */
887 /*        eigenvectors, standardize the array SELECT if necessary, and */
888 /*        test MM. */
889
890             if (somev) {
891                 *m = 0;
892                 pair = FALSE_;
893                 i__2 = *n;
894                 for (j = 1; j <= i__2; ++j) {
895                     if (pair) {
896                         pair = FALSE_;
897                         select[j] = FALSE_;
898                     } else {
899                         if (j < *n) {
900                             if (t[j + 1 + j * t_dim1] == 0.f) {
901                                 if (select[j]) {
902                                     ++(*m);
903                                 }
904                             } else {
905                                 pair = TRUE_;
906                                 if (select[j] || select[j + 1]) {
907                                     select[j] = TRUE_;
908                                     *m += 2;
909                                 }
910                             }
911                         } else {
912                             if (select[*n]) {
913                                 ++(*m);
914                             }
915                         }
916                     }
917 /* L10: */
918                 }
919             } else {
920                 *m = *n;
921             }
922
923             if (*mm < *m) {
924                 *info = -11;
925             }
926         }
927     }
928     if (*info != 0) {
929         i__2 = -(*info);
930         xerbla_("STREVC3", &i__2, (ftnlen)7);
931         return 0;
932     } else if (lquery) {
933         return 0;
934     }
935
936 /*     Quick return if possible. */
937
938     if (*n == 0) {
939         return 0;
940     }
941
942 /*     Use blocked version of back-transformation if sufficient workspace. */
943 /*     Zero-out the workspace to avoid potential NaN propagation. */
944
945     if (over && *lwork >= *n + (*n << 4)) {
946         nb = (*lwork - *n) / (*n << 1);
947         nb = f2cmin(nb,128);
948         i__2 = (nb << 1) + 1;
949         slaset_("F", n, &i__2, &c_b17, &c_b17, &work[1], n);
950     } else {
951         nb = 1;
952     }
953
954 /*     Set the constants to control overflow. */
955
956     unfl = slamch_("Safe minimum");
957     ovfl = 1.f / unfl;
958     slabad_(&unfl, &ovfl);
959     ulp = slamch_("Precision");
960     smlnum = unfl * (*n / ulp);
961     bignum = (1.f - ulp) / smlnum;
962
963 /*     Compute 1-norm of each column of strictly upper triangular */
964 /*     part of T to control overflow in triangular solver. */
965
966     work[1] = 0.f;
967     i__2 = *n;
968     for (j = 2; j <= i__2; ++j) {
969         work[j] = 0.f;
970         i__3 = j - 1;
971         for (i__ = 1; i__ <= i__3; ++i__) {
972             work[j] += (r__1 = t[i__ + j * t_dim1], abs(r__1));
973 /* L20: */
974         }
975 /* L30: */
976     }
977
978 /*     Index IP is used to specify the real or complex eigenvalue: */
979 /*       IP = 0, real eigenvalue, */
980 /*            1, first  of conjugate complex pair: (wr,wi) */
981 /*           -1, second of conjugate complex pair: (wr,wi) */
982 /*       ISCOMPLEX array stores IP for each column in current block. */
983
984     if (rightv) {
985
986 /*        ============================================================ */
987 /*        Compute right eigenvectors. */
988
989 /*        IV is index of column in current block. */
990 /*        For complex right vector, uses IV-1 for real part and IV for complex part. */
991 /*        Non-blocked version always uses IV=2; */
992 /*        blocked     version starts with IV=NB, goes down to 1 or 2. */
993 /*        (Note the "0-th" column is used for 1-norms computed above.) */
994         iv = 2;
995         if (nb > 2) {
996             iv = nb;
997         }
998         ip = 0;
999         is = *m;
1000         for (ki = *n; ki >= 1; --ki) {
1001             if (ip == -1) {
1002 /*              previous iteration (ki+1) was second of conjugate pair, */
1003 /*              so this ki is first of conjugate pair; skip to end of loop */
1004                 ip = 1;
1005                 goto L140;
1006             } else if (ki == 1) {
1007 /*              last column, so this ki must be real eigenvalue */
1008                 ip = 0;
1009             } else if (t[ki + (ki - 1) * t_dim1] == 0.f) {
1010 /*              zero on sub-diagonal, so this ki is real eigenvalue */
1011                 ip = 0;
1012             } else {
1013 /*              non-zero on sub-diagonal, so this ki is second of conjugate pair */
1014                 ip = -1;
1015             }
1016             if (somev) {
1017                 if (ip == 0) {
1018                     if (! select[ki]) {
1019                         goto L140;
1020                     }
1021                 } else {
1022                     if (! select[ki - 1]) {
1023                         goto L140;
1024                     }
1025                 }
1026             }
1027
1028 /*           Compute the KI-th eigenvalue (WR,WI). */
1029
1030             wr = t[ki + ki * t_dim1];
1031             wi = 0.f;
1032             if (ip != 0) {
1033                 wi = sqrt((r__1 = t[ki + (ki - 1) * t_dim1], abs(r__1))) * 
1034                         sqrt((r__2 = t[ki - 1 + ki * t_dim1], abs(r__2)));
1035             }
1036 /* Computing MAX */
1037             r__1 = ulp * (abs(wr) + abs(wi));
1038             smin = f2cmax(r__1,smlnum);
1039
1040             if (ip == 0) {
1041
1042 /*              -------------------------------------------------------- */
1043 /*              Real right eigenvector */
1044
1045                 work[ki + iv * *n] = 1.f;
1046
1047 /*              Form right-hand side. */
1048
1049                 i__2 = ki - 1;
1050                 for (k = 1; k <= i__2; ++k) {
1051                     work[k + iv * *n] = -t[k + ki * t_dim1];
1052 /* L50: */
1053                 }
1054
1055 /*              Solve upper quasi-triangular system: */
1056 /*              [ T(1:KI-1,1:KI-1) - WR ]*X = SCALE*WORK. */
1057
1058                 jnxt = ki - 1;
1059                 for (j = ki - 1; j >= 1; --j) {
1060                     if (j > jnxt) {
1061                         goto L60;
1062                     }
1063                     j1 = j;
1064                     j2 = j;
1065                     jnxt = j - 1;
1066                     if (j > 1) {
1067                         if (t[j + (j - 1) * t_dim1] != 0.f) {
1068                             j1 = j - 1;
1069                             jnxt = j - 2;
1070                         }
1071                     }
1072
1073                     if (j1 == j2) {
1074
1075 /*                    1-by-1 diagonal block */
1076
1077                         slaln2_(&c_false, &c__1, &c__1, &smin, &c_b29, &t[j + 
1078                                 j * t_dim1], ldt, &c_b29, &c_b29, &work[j + 
1079                                 iv * *n], n, &wr, &c_b17, x, &c__2, &scale, &
1080                                 xnorm, &ierr);
1081
1082 /*                    Scale X(1,1) to avoid overflow when updating */
1083 /*                    the right-hand side. */
1084
1085                         if (xnorm > 1.f) {
1086                             if (work[j] > bignum / xnorm) {
1087                                 x[0] /= xnorm;
1088                                 scale /= xnorm;
1089                             }
1090                         }
1091
1092 /*                    Scale if necessary */
1093
1094                         if (scale != 1.f) {
1095                             sscal_(&ki, &scale, &work[iv * *n + 1], &c__1);
1096                         }
1097                         work[j + iv * *n] = x[0];
1098
1099 /*                    Update right-hand side */
1100
1101                         i__2 = j - 1;
1102                         r__1 = -x[0];
1103                         saxpy_(&i__2, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
1104                                 iv * *n + 1], &c__1);
1105
1106                     } else {
1107
1108 /*                    2-by-2 diagonal block */
1109
1110                         slaln2_(&c_false, &c__2, &c__1, &smin, &c_b29, &t[j - 
1111                                 1 + (j - 1) * t_dim1], ldt, &c_b29, &c_b29, &
1112                                 work[j - 1 + iv * *n], n, &wr, &c_b17, x, &
1113                                 c__2, &scale, &xnorm, &ierr);
1114
1115 /*                    Scale X(1,1) and X(2,1) to avoid overflow when */
1116 /*                    updating the right-hand side. */
1117
1118                         if (xnorm > 1.f) {
1119 /* Computing MAX */
1120                             r__1 = work[j - 1], r__2 = work[j];
1121                             beta = f2cmax(r__1,r__2);
1122                             if (beta > bignum / xnorm) {
1123                                 x[0] /= xnorm;
1124                                 x[1] /= xnorm;
1125                                 scale /= xnorm;
1126                             }
1127                         }
1128
1129 /*                    Scale if necessary */
1130
1131                         if (scale != 1.f) {
1132                             sscal_(&ki, &scale, &work[iv * *n + 1], &c__1);
1133                         }
1134                         work[j - 1 + iv * *n] = x[0];
1135                         work[j + iv * *n] = x[1];
1136
1137 /*                    Update right-hand side */
1138
1139                         i__2 = j - 2;
1140                         r__1 = -x[0];
1141                         saxpy_(&i__2, &r__1, &t[(j - 1) * t_dim1 + 1], &c__1, 
1142                                 &work[iv * *n + 1], &c__1);
1143                         i__2 = j - 2;
1144                         r__1 = -x[1];
1145                         saxpy_(&i__2, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
1146                                 iv * *n + 1], &c__1);
1147                     }
1148 L60:
1149                     ;
1150                 }
1151
1152 /*              Copy the vector x or Q*x to VR and normalize. */
1153
1154                 if (! over) {
1155 /*                 ------------------------------ */
1156 /*                 no back-transform: copy x to VR and normalize. */
1157                     scopy_(&ki, &work[iv * *n + 1], &c__1, &vr[is * vr_dim1 + 
1158                             1], &c__1);
1159
1160                     ii = isamax_(&ki, &vr[is * vr_dim1 + 1], &c__1);
1161                     remax = 1.f / (r__1 = vr[ii + is * vr_dim1], abs(r__1));
1162                     sscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
1163
1164                     i__2 = *n;
1165                     for (k = ki + 1; k <= i__2; ++k) {
1166                         vr[k + is * vr_dim1] = 0.f;
1167 /* L70: */
1168                     }
1169
1170                 } else if (nb == 1) {
1171 /*                 ------------------------------ */
1172 /*                 version 1: back-transform each vector with GEMV, Q*x. */
1173                     if (ki > 1) {
1174                         i__2 = ki - 1;
1175                         sgemv_("N", n, &i__2, &c_b29, &vr[vr_offset], ldvr, &
1176                                 work[iv * *n + 1], &c__1, &work[ki + iv * *n],
1177                                  &vr[ki * vr_dim1 + 1], &c__1);
1178                     }
1179
1180                     ii = isamax_(n, &vr[ki * vr_dim1 + 1], &c__1);
1181                     remax = 1.f / (r__1 = vr[ii + ki * vr_dim1], abs(r__1));
1182                     sscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
1183
1184                 } else {
1185 /*                 ------------------------------ */
1186 /*                 version 2: back-transform block of vectors with GEMM */
1187 /*                 zero out below vector */
1188                     i__2 = *n;
1189                     for (k = ki + 1; k <= i__2; ++k) {
1190                         work[k + iv * *n] = 0.f;
1191                     }
1192                     iscomplex[iv - 1] = ip;
1193 /*                 back-transform and normalization is done below */
1194                 }
1195             } else {
1196
1197 /*              -------------------------------------------------------- */
1198 /*              Complex right eigenvector. */
1199
1200 /*              Initial solve */
1201 /*              [ ( T(KI-1,KI-1) T(KI-1,KI) ) - (WR + I*WI) ]*X = 0. */
1202 /*              [ ( T(KI,  KI-1) T(KI,  KI) )               ] */
1203
1204                 if ((r__1 = t[ki - 1 + ki * t_dim1], abs(r__1)) >= (r__2 = t[
1205                         ki + (ki - 1) * t_dim1], abs(r__2))) {
1206                     work[ki - 1 + (iv - 1) * *n] = 1.f;
1207                     work[ki + iv * *n] = wi / t[ki - 1 + ki * t_dim1];
1208                 } else {
1209                     work[ki - 1 + (iv - 1) * *n] = -wi / t[ki + (ki - 1) * 
1210                             t_dim1];
1211                     work[ki + iv * *n] = 1.f;
1212                 }
1213                 work[ki + (iv - 1) * *n] = 0.f;
1214                 work[ki - 1 + iv * *n] = 0.f;
1215
1216 /*              Form right-hand side. */
1217
1218                 i__2 = ki - 2;
1219                 for (k = 1; k <= i__2; ++k) {
1220                     work[k + (iv - 1) * *n] = -work[ki - 1 + (iv - 1) * *n] * 
1221                             t[k + (ki - 1) * t_dim1];
1222                     work[k + iv * *n] = -work[ki + iv * *n] * t[k + ki * 
1223                             t_dim1];
1224 /* L80: */
1225                 }
1226
1227 /*              Solve upper quasi-triangular system: */
1228 /*              [ T(1:KI-2,1:KI-2) - (WR+i*WI) ]*X = SCALE*(WORK+i*WORK2) */
1229
1230                 jnxt = ki - 2;
1231                 for (j = ki - 2; j >= 1; --j) {
1232                     if (j > jnxt) {
1233                         goto L90;
1234                     }
1235                     j1 = j;
1236                     j2 = j;
1237                     jnxt = j - 1;
1238                     if (j > 1) {
1239                         if (t[j + (j - 1) * t_dim1] != 0.f) {
1240                             j1 = j - 1;
1241                             jnxt = j - 2;
1242                         }
1243                     }
1244
1245                     if (j1 == j2) {
1246
1247 /*                    1-by-1 diagonal block */
1248
1249                         slaln2_(&c_false, &c__1, &c__2, &smin, &c_b29, &t[j + 
1250                                 j * t_dim1], ldt, &c_b29, &c_b29, &work[j + (
1251                                 iv - 1) * *n], n, &wr, &wi, x, &c__2, &scale, 
1252                                 &xnorm, &ierr);
1253
1254 /*                    Scale X(1,1) and X(1,2) to avoid overflow when */
1255 /*                    updating the right-hand side. */
1256
1257                         if (xnorm > 1.f) {
1258                             if (work[j] > bignum / xnorm) {
1259                                 x[0] /= xnorm;
1260                                 x[2] /= xnorm;
1261                                 scale /= xnorm;
1262                             }
1263                         }
1264
1265 /*                    Scale if necessary */
1266
1267                         if (scale != 1.f) {
1268                             sscal_(&ki, &scale, &work[(iv - 1) * *n + 1], &
1269                                     c__1);
1270                             sscal_(&ki, &scale, &work[iv * *n + 1], &c__1);
1271                         }
1272                         work[j + (iv - 1) * *n] = x[0];
1273                         work[j + iv * *n] = x[2];
1274
1275 /*                    Update the right-hand side */
1276
1277                         i__2 = j - 1;
1278                         r__1 = -x[0];
1279                         saxpy_(&i__2, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
1280                                 (iv - 1) * *n + 1], &c__1);
1281                         i__2 = j - 1;
1282                         r__1 = -x[2];
1283                         saxpy_(&i__2, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
1284                                 iv * *n + 1], &c__1);
1285
1286                     } else {
1287
1288 /*                    2-by-2 diagonal block */
1289
1290                         slaln2_(&c_false, &c__2, &c__2, &smin, &c_b29, &t[j - 
1291                                 1 + (j - 1) * t_dim1], ldt, &c_b29, &c_b29, &
1292                                 work[j - 1 + (iv - 1) * *n], n, &wr, &wi, x, &
1293                                 c__2, &scale, &xnorm, &ierr);
1294
1295 /*                    Scale X to avoid overflow when updating */
1296 /*                    the right-hand side. */
1297
1298                         if (xnorm > 1.f) {
1299 /* Computing MAX */
1300                             r__1 = work[j - 1], r__2 = work[j];
1301                             beta = f2cmax(r__1,r__2);
1302                             if (beta > bignum / xnorm) {
1303                                 rec = 1.f / xnorm;
1304                                 x[0] *= rec;
1305                                 x[2] *= rec;
1306                                 x[1] *= rec;
1307                                 x[3] *= rec;
1308                                 scale *= rec;
1309                             }
1310                         }
1311
1312 /*                    Scale if necessary */
1313
1314                         if (scale != 1.f) {
1315                             sscal_(&ki, &scale, &work[(iv - 1) * *n + 1], &
1316                                     c__1);
1317                             sscal_(&ki, &scale, &work[iv * *n + 1], &c__1);
1318                         }
1319                         work[j - 1 + (iv - 1) * *n] = x[0];
1320                         work[j + (iv - 1) * *n] = x[1];
1321                         work[j - 1 + iv * *n] = x[2];
1322                         work[j + iv * *n] = x[3];
1323
1324 /*                    Update the right-hand side */
1325
1326                         i__2 = j - 2;
1327                         r__1 = -x[0];
1328                         saxpy_(&i__2, &r__1, &t[(j - 1) * t_dim1 + 1], &c__1, 
1329                                 &work[(iv - 1) * *n + 1], &c__1);
1330                         i__2 = j - 2;
1331                         r__1 = -x[1];
1332                         saxpy_(&i__2, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
1333                                 (iv - 1) * *n + 1], &c__1);
1334                         i__2 = j - 2;
1335                         r__1 = -x[2];
1336                         saxpy_(&i__2, &r__1, &t[(j - 1) * t_dim1 + 1], &c__1, 
1337                                 &work[iv * *n + 1], &c__1);
1338                         i__2 = j - 2;
1339                         r__1 = -x[3];
1340                         saxpy_(&i__2, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
1341                                 iv * *n + 1], &c__1);
1342                     }
1343 L90:
1344                     ;
1345                 }
1346
1347 /*              Copy the vector x or Q*x to VR and normalize. */
1348
1349                 if (! over) {
1350 /*                 ------------------------------ */
1351 /*                 no back-transform: copy x to VR and normalize. */
1352                     scopy_(&ki, &work[(iv - 1) * *n + 1], &c__1, &vr[(is - 1) 
1353                             * vr_dim1 + 1], &c__1);
1354                     scopy_(&ki, &work[iv * *n + 1], &c__1, &vr[is * vr_dim1 + 
1355                             1], &c__1);
1356
1357                     emax = 0.f;
1358                     i__2 = ki;
1359                     for (k = 1; k <= i__2; ++k) {
1360 /* Computing MAX */
1361                         r__3 = emax, r__4 = (r__1 = vr[k + (is - 1) * vr_dim1]
1362                                 , abs(r__1)) + (r__2 = vr[k + is * vr_dim1], 
1363                                 abs(r__2));
1364                         emax = f2cmax(r__3,r__4);
1365 /* L100: */
1366                     }
1367                     remax = 1.f / emax;
1368                     sscal_(&ki, &remax, &vr[(is - 1) * vr_dim1 + 1], &c__1);
1369                     sscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
1370
1371                     i__2 = *n;
1372                     for (k = ki + 1; k <= i__2; ++k) {
1373                         vr[k + (is - 1) * vr_dim1] = 0.f;
1374                         vr[k + is * vr_dim1] = 0.f;
1375 /* L110: */
1376                     }
1377
1378                 } else if (nb == 1) {
1379 /*                 ------------------------------ */
1380 /*                 version 1: back-transform each vector with GEMV, Q*x. */
1381                     if (ki > 2) {
1382                         i__2 = ki - 2;
1383                         sgemv_("N", n, &i__2, &c_b29, &vr[vr_offset], ldvr, &
1384                                 work[(iv - 1) * *n + 1], &c__1, &work[ki - 1 
1385                                 + (iv - 1) * *n], &vr[(ki - 1) * vr_dim1 + 1],
1386                                  &c__1);
1387                         i__2 = ki - 2;
1388                         sgemv_("N", n, &i__2, &c_b29, &vr[vr_offset], ldvr, &
1389                                 work[iv * *n + 1], &c__1, &work[ki + iv * *n],
1390                                  &vr[ki * vr_dim1 + 1], &c__1);
1391                     } else {
1392                         sscal_(n, &work[ki - 1 + (iv - 1) * *n], &vr[(ki - 1) 
1393                                 * vr_dim1 + 1], &c__1);
1394                         sscal_(n, &work[ki + iv * *n], &vr[ki * vr_dim1 + 1], 
1395                                 &c__1);
1396                     }
1397
1398                     emax = 0.f;
1399                     i__2 = *n;
1400                     for (k = 1; k <= i__2; ++k) {
1401 /* Computing MAX */
1402                         r__3 = emax, r__4 = (r__1 = vr[k + (ki - 1) * vr_dim1]
1403                                 , abs(r__1)) + (r__2 = vr[k + ki * vr_dim1], 
1404                                 abs(r__2));
1405                         emax = f2cmax(r__3,r__4);
1406 /* L120: */
1407                     }
1408                     remax = 1.f / emax;
1409                     sscal_(n, &remax, &vr[(ki - 1) * vr_dim1 + 1], &c__1);
1410                     sscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
1411
1412                 } else {
1413 /*                 ------------------------------ */
1414 /*                 version 2: back-transform block of vectors with GEMM */
1415 /*                 zero out below vector */
1416                     i__2 = *n;
1417                     for (k = ki + 1; k <= i__2; ++k) {
1418                         work[k + (iv - 1) * *n] = 0.f;
1419                         work[k + iv * *n] = 0.f;
1420                     }
1421                     iscomplex[iv - 2] = -ip;
1422                     iscomplex[iv - 1] = ip;
1423                     --iv;
1424 /*                 back-transform and normalization is done below */
1425                 }
1426             }
1427             if (nb > 1) {
1428 /*              -------------------------------------------------------- */
1429 /*              Blocked version of back-transform */
1430 /*              For complex case, KI2 includes both vectors (KI-1 and KI) */
1431                 if (ip == 0) {
1432                     ki2 = ki;
1433                 } else {
1434                     ki2 = ki - 1;
1435                 }
1436 /*              Columns IV:NB of work are valid vectors. */
1437 /*              When the number of vectors stored reaches NB-1 or NB, */
1438 /*              or if this was last vector, do the GEMM */
1439                 if (iv <= 2 || ki2 == 1) {
1440                     i__2 = nb - iv + 1;
1441                     i__3 = ki2 + nb - iv;
1442                     sgemm_("N", "N", n, &i__2, &i__3, &c_b29, &vr[vr_offset], 
1443                             ldvr, &work[iv * *n + 1], n, &c_b17, &work[(nb + 
1444                             iv) * *n + 1], n);
1445 /*                 normalize vectors */
1446                     i__2 = nb;
1447                     for (k = iv; k <= i__2; ++k) {
1448                         if (iscomplex[k - 1] == 0) {
1449 /*                       real eigenvector */
1450                             ii = isamax_(n, &work[(nb + k) * *n + 1], &c__1);
1451                             remax = 1.f / (r__1 = work[ii + (nb + k) * *n], 
1452                                     abs(r__1));
1453                         } else if (iscomplex[k - 1] == 1) {
1454 /*                       first eigenvector of conjugate pair */
1455                             emax = 0.f;
1456                             i__3 = *n;
1457                             for (ii = 1; ii <= i__3; ++ii) {
1458 /* Computing MAX */
1459                                 r__3 = emax, r__4 = (r__1 = work[ii + (nb + k)
1460                                          * *n], abs(r__1)) + (r__2 = work[ii 
1461                                         + (nb + k + 1) * *n], abs(r__2));
1462                                 emax = f2cmax(r__3,r__4);
1463                             }
1464                             remax = 1.f / emax;
1465 /*                    else if ISCOMPLEX(K).EQ.-1 */
1466 /*                       second eigenvector of conjugate pair */
1467 /*                       reuse same REMAX as previous K */
1468                         }
1469                         sscal_(n, &remax, &work[(nb + k) * *n + 1], &c__1);
1470                     }
1471                     i__2 = nb - iv + 1;
1472                     slacpy_("F", n, &i__2, &work[(nb + iv) * *n + 1], n, &vr[
1473                             ki2 * vr_dim1 + 1], ldvr);
1474                     iv = nb;
1475                 } else {
1476                     --iv;
1477                 }
1478             }
1479
1480 /* blocked back-transform */
1481             --is;
1482             if (ip != 0) {
1483                 --is;
1484             }
1485 L140:
1486             ;
1487         }
1488     }
1489     if (leftv) {
1490
1491 /*        ============================================================ */
1492 /*        Compute left eigenvectors. */
1493
1494 /*        IV is index of column in current block. */
1495 /*        For complex left vector, uses IV for real part and IV+1 for complex part. */
1496 /*        Non-blocked version always uses IV=1; */
1497 /*        blocked     version starts with IV=1, goes up to NB-1 or NB. */
1498 /*        (Note the "0-th" column is used for 1-norms computed above.) */
1499         iv = 1;
1500         ip = 0;
1501         is = 1;
1502         i__2 = *n;
1503         for (ki = 1; ki <= i__2; ++ki) {
1504             if (ip == 1) {
1505 /*              previous iteration (ki-1) was first of conjugate pair, */
1506 /*              so this ki is second of conjugate pair; skip to end of loop */
1507                 ip = -1;
1508                 goto L260;
1509             } else if (ki == *n) {
1510 /*              last column, so this ki must be real eigenvalue */
1511                 ip = 0;
1512             } else if (t[ki + 1 + ki * t_dim1] == 0.f) {
1513 /*              zero on sub-diagonal, so this ki is real eigenvalue */
1514                 ip = 0;
1515             } else {
1516 /*              non-zero on sub-diagonal, so this ki is first of conjugate pair */
1517                 ip = 1;
1518             }
1519
1520             if (somev) {
1521                 if (! select[ki]) {
1522                     goto L260;
1523                 }
1524             }
1525
1526 /*           Compute the KI-th eigenvalue (WR,WI). */
1527
1528             wr = t[ki + ki * t_dim1];
1529             wi = 0.f;
1530             if (ip != 0) {
1531                 wi = sqrt((r__1 = t[ki + (ki + 1) * t_dim1], abs(r__1))) * 
1532                         sqrt((r__2 = t[ki + 1 + ki * t_dim1], abs(r__2)));
1533             }
1534 /* Computing MAX */
1535             r__1 = ulp * (abs(wr) + abs(wi));
1536             smin = f2cmax(r__1,smlnum);
1537
1538             if (ip == 0) {
1539
1540 /*              -------------------------------------------------------- */
1541 /*              Real left eigenvector */
1542
1543                 work[ki + iv * *n] = 1.f;
1544
1545 /*              Form right-hand side. */
1546
1547                 i__3 = *n;
1548                 for (k = ki + 1; k <= i__3; ++k) {
1549                     work[k + iv * *n] = -t[ki + k * t_dim1];
1550 /* L160: */
1551                 }
1552
1553 /*              Solve transposed quasi-triangular system: */
1554 /*              [ T(KI+1:N,KI+1:N) - WR ]**T * X = SCALE*WORK */
1555
1556                 vmax = 1.f;
1557                 vcrit = bignum;
1558
1559                 jnxt = ki + 1;
1560                 i__3 = *n;
1561                 for (j = ki + 1; j <= i__3; ++j) {
1562                     if (j < jnxt) {
1563                         goto L170;
1564                     }
1565                     j1 = j;
1566                     j2 = j;
1567                     jnxt = j + 1;
1568                     if (j < *n) {
1569                         if (t[j + 1 + j * t_dim1] != 0.f) {
1570                             j2 = j + 1;
1571                             jnxt = j + 2;
1572                         }
1573                     }
1574
1575                     if (j1 == j2) {
1576
1577 /*                    1-by-1 diagonal block */
1578
1579 /*                    Scale if necessary to avoid overflow when forming */
1580 /*                    the right-hand side. */
1581
1582                         if (work[j] > vcrit) {
1583                             rec = 1.f / vmax;
1584                             i__4 = *n - ki + 1;
1585                             sscal_(&i__4, &rec, &work[ki + iv * *n], &c__1);
1586                             vmax = 1.f;
1587                             vcrit = bignum;
1588                         }
1589
1590                         i__4 = j - ki - 1;
1591                         work[j + iv * *n] -= sdot_(&i__4, &t[ki + 1 + j * 
1592                                 t_dim1], &c__1, &work[ki + 1 + iv * *n], &
1593                                 c__1);
1594
1595 /*                    Solve [ T(J,J) - WR ]**T * X = WORK */
1596
1597                         slaln2_(&c_false, &c__1, &c__1, &smin, &c_b29, &t[j + 
1598                                 j * t_dim1], ldt, &c_b29, &c_b29, &work[j + 
1599                                 iv * *n], n, &wr, &c_b17, x, &c__2, &scale, &
1600                                 xnorm, &ierr);
1601
1602 /*                    Scale if necessary */
1603
1604                         if (scale != 1.f) {
1605                             i__4 = *n - ki + 1;
1606                             sscal_(&i__4, &scale, &work[ki + iv * *n], &c__1);
1607                         }
1608                         work[j + iv * *n] = x[0];
1609 /* Computing MAX */
1610                         r__2 = (r__1 = work[j + iv * *n], abs(r__1));
1611                         vmax = f2cmax(r__2,vmax);
1612                         vcrit = bignum / vmax;
1613
1614                     } else {
1615
1616 /*                    2-by-2 diagonal block */
1617
1618 /*                    Scale if necessary to avoid overflow when forming */
1619 /*                    the right-hand side. */
1620
1621 /* Computing MAX */
1622                         r__1 = work[j], r__2 = work[j + 1];
1623                         beta = f2cmax(r__1,r__2);
1624                         if (beta > vcrit) {
1625                             rec = 1.f / vmax;
1626                             i__4 = *n - ki + 1;
1627                             sscal_(&i__4, &rec, &work[ki + iv * *n], &c__1);
1628                             vmax = 1.f;
1629                             vcrit = bignum;
1630                         }
1631
1632                         i__4 = j - ki - 1;
1633                         work[j + iv * *n] -= sdot_(&i__4, &t[ki + 1 + j * 
1634                                 t_dim1], &c__1, &work[ki + 1 + iv * *n], &
1635                                 c__1);
1636
1637                         i__4 = j - ki - 1;
1638                         work[j + 1 + iv * *n] -= sdot_(&i__4, &t[ki + 1 + (j 
1639                                 + 1) * t_dim1], &c__1, &work[ki + 1 + iv * *n]
1640                                 , &c__1);
1641
1642 /*                    Solve */
1643 /*                    [ T(J,J)-WR   T(J,J+1)      ]**T * X = SCALE*( WORK1 ) */
1644 /*                    [ T(J+1,J)    T(J+1,J+1)-WR ]                ( WORK2 ) */
1645
1646                         slaln2_(&c_true, &c__2, &c__1, &smin, &c_b29, &t[j + 
1647                                 j * t_dim1], ldt, &c_b29, &c_b29, &work[j + 
1648                                 iv * *n], n, &wr, &c_b17, x, &c__2, &scale, &
1649                                 xnorm, &ierr);
1650
1651 /*                    Scale if necessary */
1652
1653                         if (scale != 1.f) {
1654                             i__4 = *n - ki + 1;
1655                             sscal_(&i__4, &scale, &work[ki + iv * *n], &c__1);
1656                         }
1657                         work[j + iv * *n] = x[0];
1658                         work[j + 1 + iv * *n] = x[1];
1659
1660 /* Computing MAX */
1661                         r__3 = (r__1 = work[j + iv * *n], abs(r__1)), r__4 = (
1662                                 r__2 = work[j + 1 + iv * *n], abs(r__2)), 
1663                                 r__3 = f2cmax(r__3,r__4);
1664                         vmax = f2cmax(r__3,vmax);
1665                         vcrit = bignum / vmax;
1666
1667                     }
1668 L170:
1669                     ;
1670                 }
1671
1672 /*              Copy the vector x or Q*x to VL and normalize. */
1673
1674                 if (! over) {
1675 /*                 ------------------------------ */
1676 /*                 no back-transform: copy x to VL and normalize. */
1677                     i__3 = *n - ki + 1;
1678                     scopy_(&i__3, &work[ki + iv * *n], &c__1, &vl[ki + is * 
1679                             vl_dim1], &c__1);
1680
1681                     i__3 = *n - ki + 1;
1682                     ii = isamax_(&i__3, &vl[ki + is * vl_dim1], &c__1) + ki - 
1683                             1;
1684                     remax = 1.f / (r__1 = vl[ii + is * vl_dim1], abs(r__1));
1685                     i__3 = *n - ki + 1;
1686                     sscal_(&i__3, &remax, &vl[ki + is * vl_dim1], &c__1);
1687
1688                     i__3 = ki - 1;
1689                     for (k = 1; k <= i__3; ++k) {
1690                         vl[k + is * vl_dim1] = 0.f;
1691 /* L180: */
1692                     }
1693
1694                 } else if (nb == 1) {
1695 /*                 ------------------------------ */
1696 /*                 version 1: back-transform each vector with GEMV, Q*x. */
1697                     if (ki < *n) {
1698                         i__3 = *n - ki;
1699                         sgemv_("N", n, &i__3, &c_b29, &vl[(ki + 1) * vl_dim1 
1700                                 + 1], ldvl, &work[ki + 1 + iv * *n], &c__1, &
1701                                 work[ki + iv * *n], &vl[ki * vl_dim1 + 1], &
1702                                 c__1);
1703                     }
1704
1705                     ii = isamax_(n, &vl[ki * vl_dim1 + 1], &c__1);
1706                     remax = 1.f / (r__1 = vl[ii + ki * vl_dim1], abs(r__1));
1707                     sscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
1708
1709                 } else {
1710 /*                 ------------------------------ */
1711 /*                 version 2: back-transform block of vectors with GEMM */
1712 /*                 zero out above vector */
1713 /*                 could go from KI-NV+1 to KI-1 */
1714                     i__3 = ki - 1;
1715                     for (k = 1; k <= i__3; ++k) {
1716                         work[k + iv * *n] = 0.f;
1717                     }
1718                     iscomplex[iv - 1] = ip;
1719 /*                 back-transform and normalization is done below */
1720                 }
1721             } else {
1722
1723 /*              -------------------------------------------------------- */
1724 /*              Complex left eigenvector. */
1725
1726 /*              Initial solve: */
1727 /*              [ ( T(KI,KI)    T(KI,KI+1)  )**T - (WR - I* WI) ]*X = 0. */
1728 /*              [ ( T(KI+1,KI) T(KI+1,KI+1) )                   ] */
1729
1730                 if ((r__1 = t[ki + (ki + 1) * t_dim1], abs(r__1)) >= (r__2 = 
1731                         t[ki + 1 + ki * t_dim1], abs(r__2))) {
1732                     work[ki + iv * *n] = wi / t[ki + (ki + 1) * t_dim1];
1733                     work[ki + 1 + (iv + 1) * *n] = 1.f;
1734                 } else {
1735                     work[ki + iv * *n] = 1.f;
1736                     work[ki + 1 + (iv + 1) * *n] = -wi / t[ki + 1 + ki * 
1737                             t_dim1];
1738                 }
1739                 work[ki + 1 + iv * *n] = 0.f;
1740                 work[ki + (iv + 1) * *n] = 0.f;
1741
1742 /*              Form right-hand side. */
1743
1744                 i__3 = *n;
1745                 for (k = ki + 2; k <= i__3; ++k) {
1746                     work[k + iv * *n] = -work[ki + iv * *n] * t[ki + k * 
1747                             t_dim1];
1748                     work[k + (iv + 1) * *n] = -work[ki + 1 + (iv + 1) * *n] * 
1749                             t[ki + 1 + k * t_dim1];
1750 /* L190: */
1751                 }
1752
1753 /*              Solve transposed quasi-triangular system: */
1754 /*              [ T(KI+2:N,KI+2:N)**T - (WR-i*WI) ]*X = WORK1+i*WORK2 */
1755
1756                 vmax = 1.f;
1757                 vcrit = bignum;
1758
1759                 jnxt = ki + 2;
1760                 i__3 = *n;
1761                 for (j = ki + 2; j <= i__3; ++j) {
1762                     if (j < jnxt) {
1763                         goto L200;
1764                     }
1765                     j1 = j;
1766                     j2 = j;
1767                     jnxt = j + 1;
1768                     if (j < *n) {
1769                         if (t[j + 1 + j * t_dim1] != 0.f) {
1770                             j2 = j + 1;
1771                             jnxt = j + 2;
1772                         }
1773                     }
1774
1775                     if (j1 == j2) {
1776
1777 /*                    1-by-1 diagonal block */
1778
1779 /*                    Scale if necessary to avoid overflow when */
1780 /*                    forming the right-hand side elements. */
1781
1782                         if (work[j] > vcrit) {
1783                             rec = 1.f / vmax;
1784                             i__4 = *n - ki + 1;
1785                             sscal_(&i__4, &rec, &work[ki + iv * *n], &c__1);
1786                             i__4 = *n - ki + 1;
1787                             sscal_(&i__4, &rec, &work[ki + (iv + 1) * *n], &
1788                                     c__1);
1789                             vmax = 1.f;
1790                             vcrit = bignum;
1791                         }
1792
1793                         i__4 = j - ki - 2;
1794                         work[j + iv * *n] -= sdot_(&i__4, &t[ki + 2 + j * 
1795                                 t_dim1], &c__1, &work[ki + 2 + iv * *n], &
1796                                 c__1);
1797                         i__4 = j - ki - 2;
1798                         work[j + (iv + 1) * *n] -= sdot_(&i__4, &t[ki + 2 + j 
1799                                 * t_dim1], &c__1, &work[ki + 2 + (iv + 1) * *
1800                                 n], &c__1);
1801
1802 /*                    Solve [ T(J,J)-(WR-i*WI) ]*(X11+i*X12)= WK+I*WK2 */
1803
1804                         r__1 = -wi;
1805                         slaln2_(&c_false, &c__1, &c__2, &smin, &c_b29, &t[j + 
1806                                 j * t_dim1], ldt, &c_b29, &c_b29, &work[j + 
1807                                 iv * *n], n, &wr, &r__1, x, &c__2, &scale, &
1808                                 xnorm, &ierr);
1809
1810 /*                    Scale if necessary */
1811
1812                         if (scale != 1.f) {
1813                             i__4 = *n - ki + 1;
1814                             sscal_(&i__4, &scale, &work[ki + iv * *n], &c__1);
1815                             i__4 = *n - ki + 1;
1816                             sscal_(&i__4, &scale, &work[ki + (iv + 1) * *n], &
1817                                     c__1);
1818                         }
1819                         work[j + iv * *n] = x[0];
1820                         work[j + (iv + 1) * *n] = x[2];
1821 /* Computing MAX */
1822                         r__3 = (r__1 = work[j + iv * *n], abs(r__1)), r__4 = (
1823                                 r__2 = work[j + (iv + 1) * *n], abs(r__2)), 
1824                                 r__3 = f2cmax(r__3,r__4);
1825                         vmax = f2cmax(r__3,vmax);
1826                         vcrit = bignum / vmax;
1827
1828                     } else {
1829
1830 /*                    2-by-2 diagonal block */
1831
1832 /*                    Scale if necessary to avoid overflow when forming */
1833 /*                    the right-hand side elements. */
1834
1835 /* Computing MAX */
1836                         r__1 = work[j], r__2 = work[j + 1];
1837                         beta = f2cmax(r__1,r__2);
1838                         if (beta > vcrit) {
1839                             rec = 1.f / vmax;
1840                             i__4 = *n - ki + 1;
1841                             sscal_(&i__4, &rec, &work[ki + iv * *n], &c__1);
1842                             i__4 = *n - ki + 1;
1843                             sscal_(&i__4, &rec, &work[ki + (iv + 1) * *n], &
1844                                     c__1);
1845                             vmax = 1.f;
1846                             vcrit = bignum;
1847                         }
1848
1849                         i__4 = j - ki - 2;
1850                         work[j + iv * *n] -= sdot_(&i__4, &t[ki + 2 + j * 
1851                                 t_dim1], &c__1, &work[ki + 2 + iv * *n], &
1852                                 c__1);
1853
1854                         i__4 = j - ki - 2;
1855                         work[j + (iv + 1) * *n] -= sdot_(&i__4, &t[ki + 2 + j 
1856                                 * t_dim1], &c__1, &work[ki + 2 + (iv + 1) * *
1857                                 n], &c__1);
1858
1859                         i__4 = j - ki - 2;
1860                         work[j + 1 + iv * *n] -= sdot_(&i__4, &t[ki + 2 + (j 
1861                                 + 1) * t_dim1], &c__1, &work[ki + 2 + iv * *n]
1862                                 , &c__1);
1863
1864                         i__4 = j - ki - 2;
1865                         work[j + 1 + (iv + 1) * *n] -= sdot_(&i__4, &t[ki + 2 
1866                                 + (j + 1) * t_dim1], &c__1, &work[ki + 2 + (
1867                                 iv + 1) * *n], &c__1);
1868
1869 /*                    Solve 2-by-2 complex linear equation */
1870 /*                    [ (T(j,j)   T(j,j+1)  )**T - (wr-i*wi)*I ]*X = SCALE*B */
1871 /*                    [ (T(j+1,j) T(j+1,j+1))                  ] */
1872
1873                         r__1 = -wi;
1874                         slaln2_(&c_true, &c__2, &c__2, &smin, &c_b29, &t[j + 
1875                                 j * t_dim1], ldt, &c_b29, &c_b29, &work[j + 
1876                                 iv * *n], n, &wr, &r__1, x, &c__2, &scale, &
1877                                 xnorm, &ierr);
1878
1879 /*                    Scale if necessary */
1880
1881                         if (scale != 1.f) {
1882                             i__4 = *n - ki + 1;
1883                             sscal_(&i__4, &scale, &work[ki + iv * *n], &c__1);
1884                             i__4 = *n - ki + 1;
1885                             sscal_(&i__4, &scale, &work[ki + (iv + 1) * *n], &
1886                                     c__1);
1887                         }
1888                         work[j + iv * *n] = x[0];
1889                         work[j + (iv + 1) * *n] = x[2];
1890                         work[j + 1 + iv * *n] = x[1];
1891                         work[j + 1 + (iv + 1) * *n] = x[3];
1892 /* Computing MAX */
1893                         r__1 = abs(x[0]), r__2 = abs(x[2]), r__1 = f2cmax(r__1,
1894                                 r__2), r__2 = abs(x[1]), r__1 = f2cmax(r__1,r__2)
1895                                 , r__2 = abs(x[3]), r__1 = f2cmax(r__1,r__2);
1896                         vmax = f2cmax(r__1,vmax);
1897                         vcrit = bignum / vmax;
1898
1899                     }
1900 L200:
1901                     ;
1902                 }
1903
1904 /*              Copy the vector x or Q*x to VL and normalize. */
1905
1906                 if (! over) {
1907 /*                 ------------------------------ */
1908 /*                 no back-transform: copy x to VL and normalize. */
1909                     i__3 = *n - ki + 1;
1910                     scopy_(&i__3, &work[ki + iv * *n], &c__1, &vl[ki + is * 
1911                             vl_dim1], &c__1);
1912                     i__3 = *n - ki + 1;
1913                     scopy_(&i__3, &work[ki + (iv + 1) * *n], &c__1, &vl[ki + (
1914                             is + 1) * vl_dim1], &c__1);
1915
1916                     emax = 0.f;
1917                     i__3 = *n;
1918                     for (k = ki; k <= i__3; ++k) {
1919 /* Computing MAX */
1920                         r__3 = emax, r__4 = (r__1 = vl[k + is * vl_dim1], abs(
1921                                 r__1)) + (r__2 = vl[k + (is + 1) * vl_dim1], 
1922                                 abs(r__2));
1923                         emax = f2cmax(r__3,r__4);
1924 /* L220: */
1925                     }
1926                     remax = 1.f / emax;
1927                     i__3 = *n - ki + 1;
1928                     sscal_(&i__3, &remax, &vl[ki + is * vl_dim1], &c__1);
1929                     i__3 = *n - ki + 1;
1930                     sscal_(&i__3, &remax, &vl[ki + (is + 1) * vl_dim1], &c__1)
1931                             ;
1932
1933                     i__3 = ki - 1;
1934                     for (k = 1; k <= i__3; ++k) {
1935                         vl[k + is * vl_dim1] = 0.f;
1936                         vl[k + (is + 1) * vl_dim1] = 0.f;
1937 /* L230: */
1938                     }
1939
1940                 } else if (nb == 1) {
1941 /*                 ------------------------------ */
1942 /*                 version 1: back-transform each vector with GEMV, Q*x. */
1943                     if (ki < *n - 1) {
1944                         i__3 = *n - ki - 1;
1945                         sgemv_("N", n, &i__3, &c_b29, &vl[(ki + 2) * vl_dim1 
1946                                 + 1], ldvl, &work[ki + 2 + iv * *n], &c__1, &
1947                                 work[ki + iv * *n], &vl[ki * vl_dim1 + 1], &
1948                                 c__1);
1949                         i__3 = *n - ki - 1;
1950                         sgemv_("N", n, &i__3, &c_b29, &vl[(ki + 2) * vl_dim1 
1951                                 + 1], ldvl, &work[ki + 2 + (iv + 1) * *n], &
1952                                 c__1, &work[ki + 1 + (iv + 1) * *n], &vl[(ki 
1953                                 + 1) * vl_dim1 + 1], &c__1);
1954                     } else {
1955                         sscal_(n, &work[ki + iv * *n], &vl[ki * vl_dim1 + 1], 
1956                                 &c__1);
1957                         sscal_(n, &work[ki + 1 + (iv + 1) * *n], &vl[(ki + 1) 
1958                                 * vl_dim1 + 1], &c__1);
1959                     }
1960
1961                     emax = 0.f;
1962                     i__3 = *n;
1963                     for (k = 1; k <= i__3; ++k) {
1964 /* Computing MAX */
1965                         r__3 = emax, r__4 = (r__1 = vl[k + ki * vl_dim1], abs(
1966                                 r__1)) + (r__2 = vl[k + (ki + 1) * vl_dim1], 
1967                                 abs(r__2));
1968                         emax = f2cmax(r__3,r__4);
1969 /* L240: */
1970                     }
1971                     remax = 1.f / emax;
1972                     sscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
1973                     sscal_(n, &remax, &vl[(ki + 1) * vl_dim1 + 1], &c__1);
1974
1975                 } else {
1976 /*                 ------------------------------ */
1977 /*                 version 2: back-transform block of vectors with GEMM */
1978 /*                 zero out above vector */
1979 /*                 could go from KI-NV+1 to KI-1 */
1980                     i__3 = ki - 1;
1981                     for (k = 1; k <= i__3; ++k) {
1982                         work[k + iv * *n] = 0.f;
1983                         work[k + (iv + 1) * *n] = 0.f;
1984                     }
1985                     iscomplex[iv - 1] = ip;
1986                     iscomplex[iv] = -ip;
1987                     ++iv;
1988 /*                 back-transform and normalization is done below */
1989                 }
1990             }
1991             if (nb > 1) {
1992 /*              -------------------------------------------------------- */
1993 /*              Blocked version of back-transform */
1994 /*              For complex case, KI2 includes both vectors (KI and KI+1) */
1995                 if (ip == 0) {
1996                     ki2 = ki;
1997                 } else {
1998                     ki2 = ki + 1;
1999                 }
2000 /*              Columns 1:IV of work are valid vectors. */
2001 /*              When the number of vectors stored reaches NB-1 or NB, */
2002 /*              or if this was last vector, do the GEMM */
2003                 if (iv >= nb - 1 || ki2 == *n) {
2004                     i__3 = *n - ki2 + iv;
2005                     sgemm_("N", "N", n, &iv, &i__3, &c_b29, &vl[(ki2 - iv + 1)
2006                              * vl_dim1 + 1], ldvl, &work[ki2 - iv + 1 + *n], 
2007                             n, &c_b17, &work[(nb + 1) * *n + 1], n);
2008 /*                 normalize vectors */
2009                     i__3 = iv;
2010                     for (k = 1; k <= i__3; ++k) {
2011                         if (iscomplex[k - 1] == 0) {
2012 /*                       real eigenvector */
2013                             ii = isamax_(n, &work[(nb + k) * *n + 1], &c__1);
2014                             remax = 1.f / (r__1 = work[ii + (nb + k) * *n], 
2015                                     abs(r__1));
2016                         } else if (iscomplex[k - 1] == 1) {
2017 /*                       first eigenvector of conjugate pair */
2018                             emax = 0.f;
2019                             i__4 = *n;
2020                             for (ii = 1; ii <= i__4; ++ii) {
2021 /* Computing MAX */
2022                                 r__3 = emax, r__4 = (r__1 = work[ii + (nb + k)
2023                                          * *n], abs(r__1)) + (r__2 = work[ii 
2024                                         + (nb + k + 1) * *n], abs(r__2));
2025                                 emax = f2cmax(r__3,r__4);
2026                             }
2027                             remax = 1.f / emax;
2028 /*                    else if ISCOMPLEX(K).EQ.-1 */
2029 /*                       second eigenvector of conjugate pair */
2030 /*                       reuse same REMAX as previous K */
2031                         }
2032                         sscal_(n, &remax, &work[(nb + k) * *n + 1], &c__1);
2033                     }
2034                     slacpy_("F", n, &iv, &work[(nb + 1) * *n + 1], n, &vl[(
2035                             ki2 - iv + 1) * vl_dim1 + 1], ldvl);
2036                     iv = 1;
2037                 } else {
2038                     ++iv;
2039                 }
2040             }
2041
2042 /* blocked back-transform */
2043             ++is;
2044             if (ip != 0) {
2045                 ++is;
2046             }
2047 L260:
2048             ;
2049         }
2050     }
2051
2052     return 0;
2053
2054 /*     End of STREVC3 */
2055
2056 } /* strevc3_ */
2057