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