C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / sgeesx.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__0 = 0;
517 static integer c_n1 = -1;
518
519 /* > \brief <b> SGEESX computes the eigenvalues, the Schur form, and, optionally, the matrix of Schur vectors 
520 for GE matrices</b> */
521
522 /*  =========== DOCUMENTATION =========== */
523
524 /* Online html documentation available at */
525 /*            http://www.netlib.org/lapack/explore-html/ */
526
527 /* > \htmlonly */
528 /* > Download SGEESX + dependencies */
529 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgeesx.
530 f"> */
531 /* > [TGZ]</a> */
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgeesx.
533 f"> */
534 /* > [ZIP]</a> */
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgeesx.
536 f"> */
537 /* > [TXT]</a> */
538 /* > \endhtmlonly */
539
540 /*  Definition: */
541 /*  =========== */
542
543 /*       SUBROUTINE SGEESX( JOBVS, SORT, SELECT, SENSE, N, A, LDA, SDIM, */
544 /*                          WR, WI, VS, LDVS, RCONDE, RCONDV, WORK, LWORK, */
545 /*                          IWORK, LIWORK, BWORK, INFO ) */
546
547 /*       CHARACTER          JOBVS, SENSE, SORT */
548 /*       INTEGER            INFO, LDA, LDVS, LIWORK, LWORK, N, SDIM */
549 /*       REAL               RCONDE, RCONDV */
550 /*       LOGICAL            BWORK( * ) */
551 /*       INTEGER            IWORK( * ) */
552 /*       REAL               A( LDA, * ), VS( LDVS, * ), WI( * ), WORK( * ), */
553 /*      $                   WR( * ) */
554 /*       LOGICAL            SELECT */
555 /*       EXTERNAL           SELECT */
556
557
558 /* > \par Purpose: */
559 /*  ============= */
560 /* > */
561 /* > \verbatim */
562 /* > */
563 /* > SGEESX computes for an N-by-N real nonsymmetric matrix A, the */
564 /* > eigenvalues, the real Schur form T, and, optionally, the matrix of */
565 /* > Schur vectors Z.  This gives the Schur factorization A = Z*T*(Z**T). */
566 /* > */
567 /* > Optionally, it also orders the eigenvalues on the diagonal of the */
568 /* > real Schur form so that selected eigenvalues are at the top left; */
569 /* > computes a reciprocal condition number for the average of the */
570 /* > selected eigenvalues (RCONDE); and computes a reciprocal condition */
571 /* > number for the right invariant subspace corresponding to the */
572 /* > selected eigenvalues (RCONDV).  The leading columns of Z form an */
573 /* > orthonormal basis for this invariant subspace. */
574 /* > */
575 /* > For further explanation of the reciprocal condition numbers RCONDE */
576 /* > and RCONDV, see Section 4.10 of the LAPACK Users' Guide (where */
577 /* > these quantities are called s and sep respectively). */
578 /* > */
579 /* > A real matrix is in real Schur form if it is upper quasi-triangular */
580 /* > with 1-by-1 and 2-by-2 blocks. 2-by-2 blocks will be standardized in */
581 /* > the form */
582 /* >           [  a  b  ] */
583 /* >           [  c  a  ] */
584 /* > */
585 /* > where b*c < 0. The eigenvalues of such a block are a +- sqrt(bc). */
586 /* > \endverbatim */
587
588 /*  Arguments: */
589 /*  ========== */
590
591 /* > \param[in] JOBVS */
592 /* > \verbatim */
593 /* >          JOBVS is CHARACTER*1 */
594 /* >          = 'N': Schur vectors are not computed; */
595 /* >          = 'V': Schur vectors are computed. */
596 /* > \endverbatim */
597 /* > */
598 /* > \param[in] SORT */
599 /* > \verbatim */
600 /* >          SORT is CHARACTER*1 */
601 /* >          Specifies whether or not to order the eigenvalues on the */
602 /* >          diagonal of the Schur form. */
603 /* >          = 'N': Eigenvalues are not ordered; */
604 /* >          = 'S': Eigenvalues are ordered (see SELECT). */
605 /* > \endverbatim */
606 /* > */
607 /* > \param[in] SELECT */
608 /* > \verbatim */
609 /* >          SELECT is a LOGICAL FUNCTION of two REAL arguments */
610 /* >          SELECT must be declared EXTERNAL in the calling subroutine. */
611 /* >          If SORT = 'S', SELECT is used to select eigenvalues to sort */
612 /* >          to the top left of the Schur form. */
613 /* >          If SORT = 'N', SELECT is not referenced. */
614 /* >          An eigenvalue WR(j)+sqrt(-1)*WI(j) is selected if */
615 /* >          SELECT(WR(j),WI(j)) is true; i.e., if either one of a */
616 /* >          complex conjugate pair of eigenvalues is selected, then both */
617 /* >          are.  Note that a selected complex eigenvalue may no longer */
618 /* >          satisfy SELECT(WR(j),WI(j)) = .TRUE. after ordering, since */
619 /* >          ordering may change the value of complex eigenvalues */
620 /* >          (especially if the eigenvalue is ill-conditioned); in this */
621 /* >          case INFO may be set to N+3 (see INFO below). */
622 /* > \endverbatim */
623 /* > */
624 /* > \param[in] SENSE */
625 /* > \verbatim */
626 /* >          SENSE is CHARACTER*1 */
627 /* >          Determines which reciprocal condition numbers are computed. */
628 /* >          = 'N': None are computed; */
629 /* >          = 'E': Computed for average of selected eigenvalues only; */
630 /* >          = 'V': Computed for selected right invariant subspace only; */
631 /* >          = 'B': Computed for both. */
632 /* >          If SENSE = 'E', 'V' or 'B', SORT must equal 'S'. */
633 /* > \endverbatim */
634 /* > */
635 /* > \param[in] N */
636 /* > \verbatim */
637 /* >          N is INTEGER */
638 /* >          The order of the matrix A. N >= 0. */
639 /* > \endverbatim */
640 /* > */
641 /* > \param[in,out] A */
642 /* > \verbatim */
643 /* >          A is REAL array, dimension (LDA, N) */
644 /* >          On entry, the N-by-N matrix A. */
645 /* >          On exit, A is overwritten by its real Schur form T. */
646 /* > \endverbatim */
647 /* > */
648 /* > \param[in] LDA */
649 /* > \verbatim */
650 /* >          LDA is INTEGER */
651 /* >          The leading dimension of the array A.  LDA >= f2cmax(1,N). */
652 /* > \endverbatim */
653 /* > */
654 /* > \param[out] SDIM */
655 /* > \verbatim */
656 /* >          SDIM is INTEGER */
657 /* >          If SORT = 'N', SDIM = 0. */
658 /* >          If SORT = 'S', SDIM = number of eigenvalues (after sorting) */
659 /* >                         for which SELECT is true. (Complex conjugate */
660 /* >                         pairs for which SELECT is true for either */
661 /* >                         eigenvalue count as 2.) */
662 /* > \endverbatim */
663 /* > */
664 /* > \param[out] WR */
665 /* > \verbatim */
666 /* >          WR is REAL array, dimension (N) */
667 /* > \endverbatim */
668 /* > */
669 /* > \param[out] WI */
670 /* > \verbatim */
671 /* >          WI is REAL array, dimension (N) */
672 /* >          WR and WI contain the real and imaginary parts, respectively, */
673 /* >          of the computed eigenvalues, in the same order that they */
674 /* >          appear on the diagonal of the output Schur form T.  Complex */
675 /* >          conjugate pairs of eigenvalues appear consecutively with the */
676 /* >          eigenvalue having the positive imaginary part first. */
677 /* > \endverbatim */
678 /* > */
679 /* > \param[out] VS */
680 /* > \verbatim */
681 /* >          VS is REAL array, dimension (LDVS,N) */
682 /* >          If JOBVS = 'V', VS contains the orthogonal matrix Z of Schur */
683 /* >          vectors. */
684 /* >          If JOBVS = 'N', VS is not referenced. */
685 /* > \endverbatim */
686 /* > */
687 /* > \param[in] LDVS */
688 /* > \verbatim */
689 /* >          LDVS is INTEGER */
690 /* >          The leading dimension of the array VS.  LDVS >= 1, and if */
691 /* >          JOBVS = 'V', LDVS >= N. */
692 /* > \endverbatim */
693 /* > */
694 /* > \param[out] RCONDE */
695 /* > \verbatim */
696 /* >          RCONDE is REAL */
697 /* >          If SENSE = 'E' or 'B', RCONDE contains the reciprocal */
698 /* >          condition number for the average of the selected eigenvalues. */
699 /* >          Not referenced if SENSE = 'N' or 'V'. */
700 /* > \endverbatim */
701 /* > */
702 /* > \param[out] RCONDV */
703 /* > \verbatim */
704 /* >          RCONDV is REAL */
705 /* >          If SENSE = 'V' or 'B', RCONDV contains the reciprocal */
706 /* >          condition number for the selected right invariant subspace. */
707 /* >          Not referenced if SENSE = 'N' or 'E'. */
708 /* > \endverbatim */
709 /* > */
710 /* > \param[out] WORK */
711 /* > \verbatim */
712 /* >          WORK is REAL array, dimension (MAX(1,LWORK)) */
713 /* >          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
714 /* > \endverbatim */
715 /* > */
716 /* > \param[in] LWORK */
717 /* > \verbatim */
718 /* >          LWORK is INTEGER */
719 /* >          The dimension of the array WORK.  LWORK >= f2cmax(1,3*N). */
720 /* >          Also, if SENSE = 'E' or 'V' or 'B', */
721 /* >          LWORK >= N+2*SDIM*(N-SDIM), where SDIM is the number of */
722 /* >          selected eigenvalues computed by this routine.  Note that */
723 /* >          N+2*SDIM*(N-SDIM) <= N+N*N/2. Note also that an error is only */
724 /* >          returned if LWORK < f2cmax(1,3*N), but if SENSE = 'E' or 'V' or */
725 /* >          'B' this may not be large enough. */
726 /* >          For good performance, LWORK must generally be larger. */
727 /* > */
728 /* >          If LWORK = -1, then a workspace query is assumed; the routine */
729 /* >          only calculates upper bounds on the optimal sizes of the */
730 /* >          arrays WORK and IWORK, returns these values as the first */
731 /* >          entries of the WORK and IWORK arrays, and no error messages */
732 /* >          related to LWORK or LIWORK are issued by XERBLA. */
733 /* > \endverbatim */
734 /* > */
735 /* > \param[out] IWORK */
736 /* > \verbatim */
737 /* >          IWORK is INTEGER array, dimension (MAX(1,LIWORK)) */
738 /* >          On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
739 /* > \endverbatim */
740 /* > */
741 /* > \param[in] LIWORK */
742 /* > \verbatim */
743 /* >          LIWORK is INTEGER */
744 /* >          The dimension of the array IWORK. */
745 /* >          LIWORK >= 1; if SENSE = 'V' or 'B', LIWORK >= SDIM*(N-SDIM). */
746 /* >          Note that SDIM*(N-SDIM) <= N*N/4. Note also that an error is */
747 /* >          only returned if LIWORK < 1, but if SENSE = 'V' or 'B' this */
748 /* >          may not be large enough. */
749 /* > */
750 /* >          If LIWORK = -1, then a workspace query is assumed; the */
751 /* >          routine only calculates upper bounds on the optimal sizes of */
752 /* >          the arrays WORK and IWORK, returns these values as the first */
753 /* >          entries of the WORK and IWORK arrays, and no error messages */
754 /* >          related to LWORK or LIWORK are issued by XERBLA. */
755 /* > \endverbatim */
756 /* > */
757 /* > \param[out] BWORK */
758 /* > \verbatim */
759 /* >          BWORK is LOGICAL array, dimension (N) */
760 /* >          Not referenced if SORT = 'N'. */
761 /* > \endverbatim */
762 /* > */
763 /* > \param[out] INFO */
764 /* > \verbatim */
765 /* >          INFO is INTEGER */
766 /* >          = 0: successful exit */
767 /* >          < 0: if INFO = -i, the i-th argument had an illegal value. */
768 /* >          > 0: if INFO = i, and i is */
769 /* >             <= N: the QR algorithm failed to compute all the */
770 /* >                   eigenvalues; elements 1:ILO-1 and i+1:N of WR and WI */
771 /* >                   contain those eigenvalues which have converged; if */
772 /* >                   JOBVS = 'V', VS contains the transformation which */
773 /* >                   reduces A to its partially converged Schur form. */
774 /* >             = N+1: the eigenvalues could not be reordered because some */
775 /* >                   eigenvalues were too close to separate (the problem */
776 /* >                   is very ill-conditioned); */
777 /* >             = N+2: after reordering, roundoff changed values of some */
778 /* >                   complex eigenvalues so that leading eigenvalues in */
779 /* >                   the Schur form no longer satisfy SELECT=.TRUE.  This */
780 /* >                   could also be caused by underflow due to scaling. */
781 /* > \endverbatim */
782
783 /*  Authors: */
784 /*  ======== */
785
786 /* > \author Univ. of Tennessee */
787 /* > \author Univ. of California Berkeley */
788 /* > \author Univ. of Colorado Denver */
789 /* > \author NAG Ltd. */
790
791 /* > \date June 2016 */
792
793 /* > \ingroup realGEeigen */
794
795 /*  ===================================================================== */
796 /* Subroutine */ int sgeesx_(char *jobvs, char *sort, L_fp select, char *
797         sense, integer *n, real *a, integer *lda, integer *sdim, real *wr, 
798         real *wi, real *vs, integer *ldvs, real *rconde, real *rcondv, real *
799         work, integer *lwork, integer *iwork, integer *liwork, logical *bwork,
800          integer *info)
801 {
802     /* System generated locals */
803     integer a_dim1, a_offset, vs_dim1, vs_offset, i__1, i__2, i__3;
804
805     /* Local variables */
806     integer ibal;
807     real anrm;
808     integer ierr, itau, iwrk, lwrk, inxt, i__, icond, ieval;
809     extern logical lsame_(char *, char *);
810     logical cursl;
811     integer liwrk, i1, i2;
812     extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 
813             integer *), sswap_(integer *, real *, integer *, real *, integer *
814             );
815     logical lst2sl;
816     extern /* Subroutine */ int slabad_(real *, real *);
817     logical scalea;
818     integer ip;
819     real cscale;
820     extern /* Subroutine */ int sgebak_(char *, char *, integer *, integer *, 
821             integer *, real *, integer *, real *, integer *, integer *), sgebal_(char *, integer *, real *, integer *, 
822             integer *, integer *, real *, integer *);
823     extern real slamch_(char *);
824     extern /* Subroutine */ int sgehrd_(integer *, integer *, integer *, real 
825             *, integer *, real *, real *, integer *, integer *), xerbla_(char 
826             *, integer *, ftnlen);
827     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
828             integer *, integer *, ftnlen, ftnlen);
829     extern real slange_(char *, integer *, integer *, real *, integer *, real 
830             *);
831     real bignum;
832     extern /* Subroutine */ int slascl_(char *, integer *, integer *, real *, 
833             real *, integer *, integer *, real *, integer *, integer *), slacpy_(char *, integer *, integer *, real *, integer *, 
834             real *, integer *);
835     logical wantsb, wantse, lastsl;
836     extern /* Subroutine */ int sorghr_(integer *, integer *, integer *, real 
837             *, integer *, real *, real *, integer *, integer *), shseqr_(char 
838             *, char *, integer *, integer *, integer *, real *, integer *, 
839             real *, real *, real *, integer *, real *, integer *, integer *);
840     integer minwrk, maxwrk;
841     logical wantsn;
842     real smlnum;
843     integer hswork;
844     extern /* Subroutine */ int strsen_(char *, char *, logical *, integer *, 
845             real *, integer *, real *, integer *, real *, real *, integer *, 
846             real *, real *, real *, integer *, integer *, integer *, integer *
847             );
848     logical wantst, lquery, wantsv, wantvs;
849     integer ihi, ilo;
850     real dum[1], eps;
851
852
853 /*  -- LAPACK driver routine (version 3.7.0) -- */
854 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
855 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
856 /*     June 2016 */
857
858
859 /*  ===================================================================== */
860
861
862 /*     Test the input arguments */
863
864     /* Parameter adjustments */
865     a_dim1 = *lda;
866     a_offset = 1 + a_dim1 * 1;
867     a -= a_offset;
868     --wr;
869     --wi;
870     vs_dim1 = *ldvs;
871     vs_offset = 1 + vs_dim1 * 1;
872     vs -= vs_offset;
873     --work;
874     --iwork;
875     --bwork;
876
877     /* Function Body */
878     *info = 0;
879     wantvs = lsame_(jobvs, "V");
880     wantst = lsame_(sort, "S");
881     wantsn = lsame_(sense, "N");
882     wantse = lsame_(sense, "E");
883     wantsv = lsame_(sense, "V");
884     wantsb = lsame_(sense, "B");
885     lquery = *lwork == -1 || *liwork == -1;
886
887     if (! wantvs && ! lsame_(jobvs, "N")) {
888         *info = -1;
889     } else if (! wantst && ! lsame_(sort, "N")) {
890         *info = -2;
891     } else if (! (wantsn || wantse || wantsv || wantsb) || ! wantst && ! 
892             wantsn) {
893         *info = -4;
894     } else if (*n < 0) {
895         *info = -5;
896     } else if (*lda < f2cmax(1,*n)) {
897         *info = -7;
898     } else if (*ldvs < 1 || wantvs && *ldvs < *n) {
899         *info = -12;
900     }
901
902 /*     Compute workspace */
903 /*      (Note: Comments in the code beginning "RWorkspace:" describe the */
904 /*       minimal amount of real workspace needed at that point in the */
905 /*       code, as well as the preferred amount for good performance. */
906 /*       IWorkspace refers to integer workspace. */
907 /*       NB refers to the optimal block size for the immediately */
908 /*       following subroutine, as returned by ILAENV. */
909 /*       HSWORK refers to the workspace preferred by SHSEQR, as */
910 /*       calculated below. HSWORK is computed assuming ILO=1 and IHI=N, */
911 /*       the worst case. */
912 /*       If SENSE = 'E', 'V' or 'B', then the amount of workspace needed */
913 /*       depends on SDIM, which is computed by the routine STRSEN later */
914 /*       in the code.) */
915
916     if (*info == 0) {
917         liwrk = 1;
918         if (*n == 0) {
919             minwrk = 1;
920             lwrk = 1;
921         } else {
922             maxwrk = (*n << 1) + *n * ilaenv_(&c__1, "SGEHRD", " ", n, &c__1, 
923                     n, &c__0, (ftnlen)6, (ftnlen)1);
924             minwrk = *n * 3;
925
926             shseqr_("S", jobvs, n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[1]
927                     , &vs[vs_offset], ldvs, &work[1], &c_n1, &ieval);
928             hswork = work[1];
929
930             if (! wantvs) {
931 /* Computing MAX */
932                 i__1 = maxwrk, i__2 = *n + hswork;
933                 maxwrk = f2cmax(i__1,i__2);
934             } else {
935 /* Computing MAX */
936                 i__1 = maxwrk, i__2 = (*n << 1) + (*n - 1) * ilaenv_(&c__1, 
937                         "SORGHR", " ", n, &c__1, n, &c_n1, (ftnlen)6, (ftnlen)
938                         1);
939                 maxwrk = f2cmax(i__1,i__2);
940 /* Computing MAX */
941                 i__1 = maxwrk, i__2 = *n + hswork;
942                 maxwrk = f2cmax(i__1,i__2);
943             }
944             lwrk = maxwrk;
945             if (! wantsn) {
946 /* Computing MAX */
947                 i__1 = lwrk, i__2 = *n + *n * *n / 2;
948                 lwrk = f2cmax(i__1,i__2);
949             }
950             if (wantsv || wantsb) {
951                 liwrk = *n * *n / 4;
952             }
953         }
954         iwork[1] = liwrk;
955         work[1] = (real) lwrk;
956
957         if (*lwork < minwrk && ! lquery) {
958             *info = -16;
959         } else if (*liwork < 1 && ! lquery) {
960             *info = -18;
961         }
962     }
963
964     if (*info != 0) {
965         i__1 = -(*info);
966         xerbla_("SGEESX", &i__1, (ftnlen)6);
967         return 0;
968     } else if (lquery) {
969         return 0;
970     }
971
972 /*     Quick return if possible */
973
974     if (*n == 0) {
975         *sdim = 0;
976         return 0;
977     }
978
979 /*     Get machine constants */
980
981     eps = slamch_("P");
982     smlnum = slamch_("S");
983     bignum = 1.f / smlnum;
984     slabad_(&smlnum, &bignum);
985     smlnum = sqrt(smlnum) / eps;
986     bignum = 1.f / smlnum;
987
988 /*     Scale A if f2cmax element outside range [SMLNUM,BIGNUM] */
989
990     anrm = slange_("M", n, n, &a[a_offset], lda, dum);
991     scalea = FALSE_;
992     if (anrm > 0.f && anrm < smlnum) {
993         scalea = TRUE_;
994         cscale = smlnum;
995     } else if (anrm > bignum) {
996         scalea = TRUE_;
997         cscale = bignum;
998     }
999     if (scalea) {
1000         slascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
1001                 ierr);
1002     }
1003
1004 /*     Permute the matrix to make it more nearly triangular */
1005 /*     (RWorkspace: need N) */
1006
1007     ibal = 1;
1008     sgebal_("P", n, &a[a_offset], lda, &ilo, &ihi, &work[ibal], &ierr);
1009
1010 /*     Reduce to upper Hessenberg form */
1011 /*     (RWorkspace: need 3*N, prefer 2*N+N*NB) */
1012
1013     itau = *n + ibal;
1014     iwrk = *n + itau;
1015     i__1 = *lwork - iwrk + 1;
1016     sgehrd_(n, &ilo, &ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1,
1017              &ierr);
1018
1019     if (wantvs) {
1020
1021 /*        Copy Householder vectors to VS */
1022
1023         slacpy_("L", n, n, &a[a_offset], lda, &vs[vs_offset], ldvs)
1024                 ;
1025
1026 /*        Generate orthogonal matrix in VS */
1027 /*        (RWorkspace: need 3*N-1, prefer 2*N+(N-1)*NB) */
1028
1029         i__1 = *lwork - iwrk + 1;
1030         sorghr_(n, &ilo, &ihi, &vs[vs_offset], ldvs, &work[itau], &work[iwrk],
1031                  &i__1, &ierr);
1032     }
1033
1034     *sdim = 0;
1035
1036 /*     Perform QR iteration, accumulating Schur vectors in VS if desired */
1037 /*     (RWorkspace: need N+1, prefer N+HSWORK (see comments) ) */
1038
1039     iwrk = itau;
1040     i__1 = *lwork - iwrk + 1;
1041     shseqr_("S", jobvs, n, &ilo, &ihi, &a[a_offset], lda, &wr[1], &wi[1], &vs[
1042             vs_offset], ldvs, &work[iwrk], &i__1, &ieval);
1043     if (ieval > 0) {
1044         *info = ieval;
1045     }
1046
1047 /*     Sort eigenvalues if desired */
1048
1049     if (wantst && *info == 0) {
1050         if (scalea) {
1051             slascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &wr[1], n, &
1052                     ierr);
1053             slascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &wi[1], n, &
1054                     ierr);
1055         }
1056         i__1 = *n;
1057         for (i__ = 1; i__ <= i__1; ++i__) {
1058             bwork[i__] = (*select)(&wr[i__], &wi[i__]);
1059 /* L10: */
1060         }
1061
1062 /*        Reorder eigenvalues, transform Schur vectors, and compute */
1063 /*        reciprocal condition numbers */
1064 /*        (RWorkspace: if SENSE is not 'N', need N+2*SDIM*(N-SDIM) */
1065 /*                     otherwise, need N ) */
1066 /*        (IWorkspace: if SENSE is 'V' or 'B', need SDIM*(N-SDIM) */
1067 /*                     otherwise, need 0 ) */
1068
1069         i__1 = *lwork - iwrk + 1;
1070         strsen_(sense, jobvs, &bwork[1], n, &a[a_offset], lda, &vs[vs_offset],
1071                  ldvs, &wr[1], &wi[1], sdim, rconde, rcondv, &work[iwrk], &
1072                 i__1, &iwork[1], liwork, &icond);
1073         if (! wantsn) {
1074 /* Computing MAX */
1075             i__1 = maxwrk, i__2 = *n + (*sdim << 1) * (*n - *sdim);
1076             maxwrk = f2cmax(i__1,i__2);
1077         }
1078         if (icond == -15) {
1079
1080 /*           Not enough real workspace */
1081
1082             *info = -16;
1083         } else if (icond == -17) {
1084
1085 /*           Not enough integer workspace */
1086
1087             *info = -18;
1088         } else if (icond > 0) {
1089
1090 /*           STRSEN failed to reorder or to restore standard Schur form */
1091
1092             *info = icond + *n;
1093         }
1094     }
1095
1096     if (wantvs) {
1097
1098 /*        Undo balancing */
1099 /*        (RWorkspace: need N) */
1100
1101         sgebak_("P", "R", n, &ilo, &ihi, &work[ibal], n, &vs[vs_offset], ldvs,
1102                  &ierr);
1103     }
1104
1105     if (scalea) {
1106
1107 /*        Undo scaling for the Schur form of A */
1108
1109         slascl_("H", &c__0, &c__0, &cscale, &anrm, n, n, &a[a_offset], lda, &
1110                 ierr);
1111         i__1 = *lda + 1;
1112         scopy_(n, &a[a_offset], &i__1, &wr[1], &c__1);
1113         if ((wantsv || wantsb) && *info == 0) {
1114             dum[0] = *rcondv;
1115             slascl_("G", &c__0, &c__0, &cscale, &anrm, &c__1, &c__1, dum, &
1116                     c__1, &ierr);
1117             *rcondv = dum[0];
1118         }
1119         if (cscale == smlnum) {
1120
1121 /*           If scaling back towards underflow, adjust WI if an */
1122 /*           offdiagonal element of a 2-by-2 block in the Schur form */
1123 /*           underflows. */
1124
1125             if (ieval > 0) {
1126                 i1 = ieval + 1;
1127                 i2 = ihi - 1;
1128                 i__1 = ilo - 1;
1129                 slascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[
1130                         1], n, &ierr);
1131             } else if (wantst) {
1132                 i1 = 1;
1133                 i2 = *n - 1;
1134             } else {
1135                 i1 = ilo;
1136                 i2 = ihi - 1;
1137             }
1138             inxt = i1 - 1;
1139             i__1 = i2;
1140             for (i__ = i1; i__ <= i__1; ++i__) {
1141                 if (i__ < inxt) {
1142                     goto L20;
1143                 }
1144                 if (wi[i__] == 0.f) {
1145                     inxt = i__ + 1;
1146                 } else {
1147                     if (a[i__ + 1 + i__ * a_dim1] == 0.f) {
1148                         wi[i__] = 0.f;
1149                         wi[i__ + 1] = 0.f;
1150                     } else if (a[i__ + 1 + i__ * a_dim1] != 0.f && a[i__ + (
1151                             i__ + 1) * a_dim1] == 0.f) {
1152                         wi[i__] = 0.f;
1153                         wi[i__ + 1] = 0.f;
1154                         if (i__ > 1) {
1155                             i__2 = i__ - 1;
1156                             sswap_(&i__2, &a[i__ * a_dim1 + 1], &c__1, &a[(
1157                                     i__ + 1) * a_dim1 + 1], &c__1);
1158                         }
1159                         if (*n > i__ + 1) {
1160                             i__2 = *n - i__ - 1;
1161                             sswap_(&i__2, &a[i__ + (i__ + 2) * a_dim1], lda, &
1162                                     a[i__ + 1 + (i__ + 2) * a_dim1], lda);
1163                         }
1164                         if (wantvs) {
1165                             sswap_(n, &vs[i__ * vs_dim1 + 1], &c__1, &vs[(i__ 
1166                                     + 1) * vs_dim1 + 1], &c__1);
1167                         }
1168                         a[i__ + (i__ + 1) * a_dim1] = a[i__ + 1 + i__ * 
1169                                 a_dim1];
1170                         a[i__ + 1 + i__ * a_dim1] = 0.f;
1171                     }
1172                     inxt = i__ + 2;
1173                 }
1174 L20:
1175                 ;
1176             }
1177         }
1178         i__1 = *n - ieval;
1179 /* Computing MAX */
1180         i__3 = *n - ieval;
1181         i__2 = f2cmax(i__3,1);
1182         slascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[ieval + 
1183                 1], &i__2, &ierr);
1184     }
1185
1186     if (wantst && *info == 0) {
1187
1188 /*        Check if reordering successful */
1189
1190         lastsl = TRUE_;
1191         lst2sl = TRUE_;
1192         *sdim = 0;
1193         ip = 0;
1194         i__1 = *n;
1195         for (i__ = 1; i__ <= i__1; ++i__) {
1196             cursl = (*select)(&wr[i__], &wi[i__]);
1197             if (wi[i__] == 0.f) {
1198                 if (cursl) {
1199                     ++(*sdim);
1200                 }
1201                 ip = 0;
1202                 if (cursl && ! lastsl) {
1203                     *info = *n + 2;
1204                 }
1205             } else {
1206                 if (ip == 1) {
1207
1208 /*                 Last eigenvalue of conjugate pair */
1209
1210                     cursl = cursl || lastsl;
1211                     lastsl = cursl;
1212                     if (cursl) {
1213                         *sdim += 2;
1214                     }
1215                     ip = -1;
1216                     if (cursl && ! lst2sl) {
1217                         *info = *n + 2;
1218                     }
1219                 } else {
1220
1221 /*                 First eigenvalue of conjugate pair */
1222
1223                     ip = 1;
1224                 }
1225             }
1226             lst2sl = lastsl;
1227             lastsl = cursl;
1228 /* L30: */
1229         }
1230     }
1231
1232     work[1] = (real) maxwrk;
1233     if (wantsv || wantsb) {
1234         iwork[1] = *sdim * (*n - *sdim);
1235     } else {
1236         iwork[1] = 1;
1237     }
1238
1239     return 0;
1240
1241 /*     End of SGEESX */
1242
1243 } /* sgeesx_ */
1244