14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
22 typedef BLASLONG blasint;
24 #define blasabs(x) llabs(x)
26 #define blasabs(x) labs(x)
30 #define blasabs(x) abs(x)
33 typedef blasint integer;
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
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;}
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;}
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
63 /* Extern is for use with -E */
74 /*external read, write*/
83 /*internal read, write*/
113 /*rewind, backspace, endfile*/
125 ftnint *inex; /*parameters in standard's order*/
151 union Multitype { /* for multiple entry points */
162 typedef union Multitype Multitype;
164 struct Vardesc { /* for Namelist */
170 typedef struct Vardesc Vardesc;
177 typedef struct Namelist Namelist;
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)))
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)); }
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]);}
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);}
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)}
261 /* procedure parameter types for -A and -C++ */
263 #define F2C_proc_par_types 1
265 typedef logical (*L_fp)(...);
267 typedef logical (*L_fp)();
270 static float spow_ui(float x, integer n) {
271 float pow=1.0; unsigned long int u;
273 if(n < 0) n = -n, x = 1/x;
282 static double dpow_ui(double x, integer n) {
283 double pow=1.0; unsigned long int u;
285 if(n < 0) n = -n, x = 1/x;
295 static _Fcomplex cpow_ui(complex x, integer n) {
296 complex pow={1.0,0.0}; unsigned long int u;
298 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
300 if(u & 01) pow.r *= x.r, pow.i *= x.i;
301 if(u >>= 1) x.r *= x.r, x.i *= x.i;
305 _Fcomplex p={pow.r, pow.i};
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310 _Complex float pow=1.0; unsigned long int u;
312 if(n < 0) n = -n, x = 1/x;
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324 _Dcomplex pow={1.0,0.0}; unsigned long int u;
326 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
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];
333 _Dcomplex p = {pow._Val[0], pow._Val[1]};
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338 _Complex double pow=1.0; unsigned long int u;
340 if(n < 0) n = -n, x = 1/x;
350 static integer pow_ii(integer x, integer n) {
351 integer pow; unsigned long int u;
353 if (n == 0 || x == 1) pow = 1;
354 else if (x != -1) pow = x == 0 ? 1/x : 0;
357 if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
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];
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
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];
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;
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];
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];
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]);
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]);
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;
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];
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];
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]);
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]);
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;
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];
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];
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]);
467 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468 zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
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;
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];
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];
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]);
498 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499 zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
505 /* -- translated by f2c (version 20000121).
506 You must link the resulting object file with the libraries:
507 -lf2c -lm (in that order)
513 /* Table of constant values */
515 static integer c__1 = 1;
516 static integer c__0 = 0;
517 static integer c_n1 = -1;
519 /* > \brief <b> SGEESX computes the eigenvalues, the Schur form, and, optionally, the matrix of Schur vectors
520 for GE matrices</b> */
522 /* =========== DOCUMENTATION =========== */
524 /* Online html documentation available at */
525 /* http://www.netlib.org/lapack/explore-html/ */
528 /* > Download SGEESX + dependencies */
529 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgeesx.
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgeesx.
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgeesx.
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 ) */
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( * ), */
555 /* EXTERNAL SELECT */
558 /* > \par Purpose: */
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). */
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. */
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). */
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 */
585 /* > where b*c < 0. The eigenvalues of such a block are a +- sqrt(bc). */
591 /* > \param[in] JOBVS */
593 /* > JOBVS is CHARACTER*1 */
594 /* > = 'N': Schur vectors are not computed; */
595 /* > = 'V': Schur vectors are computed. */
598 /* > \param[in] SORT */
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). */
607 /* > \param[in] SELECT */
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). */
624 /* > \param[in] SENSE */
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'. */
638 /* > The order of the matrix A. N >= 0. */
641 /* > \param[in,out] A */
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. */
648 /* > \param[in] LDA */
650 /* > LDA is INTEGER */
651 /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
654 /* > \param[out] SDIM */
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.) */
664 /* > \param[out] WR */
666 /* > WR is REAL array, dimension (N) */
669 /* > \param[out] WI */
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. */
679 /* > \param[out] VS */
681 /* > VS is REAL array, dimension (LDVS,N) */
682 /* > If JOBVS = 'V', VS contains the orthogonal matrix Z of Schur */
684 /* > If JOBVS = 'N', VS is not referenced. */
687 /* > \param[in] LDVS */
689 /* > LDVS is INTEGER */
690 /* > The leading dimension of the array VS. LDVS >= 1, and if */
691 /* > JOBVS = 'V', LDVS >= N. */
694 /* > \param[out] RCONDE */
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'. */
702 /* > \param[out] RCONDV */
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'. */
710 /* > \param[out] WORK */
712 /* > WORK is REAL array, dimension (MAX(1,LWORK)) */
713 /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
716 /* > \param[in] LWORK */
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. */
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. */
735 /* > \param[out] IWORK */
737 /* > IWORK is INTEGER array, dimension (MAX(1,LIWORK)) */
738 /* > On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
741 /* > \param[in] LIWORK */
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. */
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. */
757 /* > \param[out] BWORK */
759 /* > BWORK is LOGICAL array, dimension (N) */
760 /* > Not referenced if SORT = 'N'. */
763 /* > \param[out] INFO */
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. */
786 /* > \author Univ. of Tennessee */
787 /* > \author Univ. of California Berkeley */
788 /* > \author Univ. of Colorado Denver */
789 /* > \author NAG Ltd. */
791 /* > \date June 2016 */
793 /* > \ingroup realGEeigen */
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,
802 /* System generated locals */
803 integer a_dim1, a_offset, vs_dim1, vs_offset, i__1, i__2, i__3;
805 /* Local variables */
808 integer ierr, itau, iwrk, lwrk, inxt, i__, icond, ieval;
809 extern logical lsame_(char *, char *);
811 integer liwrk, i1, i2;
812 extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
813 integer *), sswap_(integer *, real *, integer *, real *, integer *
816 extern /* Subroutine */ int slabad_(real *, real *);
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
832 extern /* Subroutine */ int slascl_(char *, integer *, integer *, real *,
833 real *, integer *, integer *, real *, integer *, integer *), slacpy_(char *, integer *, integer *, 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;
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 *
848 logical wantst, lquery, wantsv, wantvs;
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..-- */
859 /* ===================================================================== */
862 /* Test the input arguments */
864 /* Parameter adjustments */
866 a_offset = 1 + a_dim1 * 1;
871 vs_offset = 1 + vs_dim1 * 1;
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;
887 if (! wantvs && ! lsame_(jobvs, "N")) {
889 } else if (! wantst && ! lsame_(sort, "N")) {
891 } else if (! (wantsn || wantse || wantsv || wantsb) || ! wantst && !
896 } else if (*lda < f2cmax(1,*n)) {
898 } else if (*ldvs < 1 || wantvs && *ldvs < *n) {
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 */
922 maxwrk = (*n << 1) + *n * ilaenv_(&c__1, "SGEHRD", " ", n, &c__1,
923 n, &c__0, (ftnlen)6, (ftnlen)1);
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);
932 i__1 = maxwrk, i__2 = *n + hswork;
933 maxwrk = f2cmax(i__1,i__2);
936 i__1 = maxwrk, i__2 = (*n << 1) + (*n - 1) * ilaenv_(&c__1,
937 "SORGHR", " ", n, &c__1, n, &c_n1, (ftnlen)6, (ftnlen)
939 maxwrk = f2cmax(i__1,i__2);
941 i__1 = maxwrk, i__2 = *n + hswork;
942 maxwrk = f2cmax(i__1,i__2);
947 i__1 = lwrk, i__2 = *n + *n * *n / 2;
948 lwrk = f2cmax(i__1,i__2);
950 if (wantsv || wantsb) {
955 work[1] = (real) lwrk;
957 if (*lwork < minwrk && ! lquery) {
959 } else if (*liwork < 1 && ! lquery) {
966 xerbla_("SGEESX", &i__1, (ftnlen)6);
972 /* Quick return if possible */
979 /* Get machine constants */
982 smlnum = slamch_("S");
983 bignum = 1.f / smlnum;
984 slabad_(&smlnum, &bignum);
985 smlnum = sqrt(smlnum) / eps;
986 bignum = 1.f / smlnum;
988 /* Scale A if f2cmax element outside range [SMLNUM,BIGNUM] */
990 anrm = slange_("M", n, n, &a[a_offset], lda, dum);
992 if (anrm > 0.f && anrm < smlnum) {
995 } else if (anrm > bignum) {
1000 slascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
1004 /* Permute the matrix to make it more nearly triangular */
1005 /* (RWorkspace: need N) */
1008 sgebal_("P", n, &a[a_offset], lda, &ilo, &ihi, &work[ibal], &ierr);
1010 /* Reduce to upper Hessenberg form */
1011 /* (RWorkspace: need 3*N, prefer 2*N+N*NB) */
1015 i__1 = *lwork - iwrk + 1;
1016 sgehrd_(n, &ilo, &ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1,
1021 /* Copy Householder vectors to VS */
1023 slacpy_("L", n, n, &a[a_offset], lda, &vs[vs_offset], ldvs)
1026 /* Generate orthogonal matrix in VS */
1027 /* (RWorkspace: need 3*N-1, prefer 2*N+(N-1)*NB) */
1029 i__1 = *lwork - iwrk + 1;
1030 sorghr_(n, &ilo, &ihi, &vs[vs_offset], ldvs, &work[itau], &work[iwrk],
1036 /* Perform QR iteration, accumulating Schur vectors in VS if desired */
1037 /* (RWorkspace: need N+1, prefer N+HSWORK (see comments) ) */
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);
1047 /* Sort eigenvalues if desired */
1049 if (wantst && *info == 0) {
1051 slascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &wr[1], n, &
1053 slascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &wi[1], n, &
1057 for (i__ = 1; i__ <= i__1; ++i__) {
1058 bwork[i__] = (*select)(&wr[i__], &wi[i__]);
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 ) */
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);
1075 i__1 = maxwrk, i__2 = *n + (*sdim << 1) * (*n - *sdim);
1076 maxwrk = f2cmax(i__1,i__2);
1080 /* Not enough real workspace */
1083 } else if (icond == -17) {
1085 /* Not enough integer workspace */
1088 } else if (icond > 0) {
1090 /* STRSEN failed to reorder or to restore standard Schur form */
1098 /* Undo balancing */
1099 /* (RWorkspace: need N) */
1101 sgebak_("P", "R", n, &ilo, &ihi, &work[ibal], n, &vs[vs_offset], ldvs,
1107 /* Undo scaling for the Schur form of A */
1109 slascl_("H", &c__0, &c__0, &cscale, &anrm, n, n, &a[a_offset], lda, &
1112 scopy_(n, &a[a_offset], &i__1, &wr[1], &c__1);
1113 if ((wantsv || wantsb) && *info == 0) {
1115 slascl_("G", &c__0, &c__0, &cscale, &anrm, &c__1, &c__1, dum, &
1119 if (cscale == smlnum) {
1121 /* If scaling back towards underflow, adjust WI if an */
1122 /* offdiagonal element of a 2-by-2 block in the Schur form */
1129 slascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[
1131 } else if (wantst) {
1140 for (i__ = i1; i__ <= i__1; ++i__) {
1144 if (wi[i__] == 0.f) {
1147 if (a[i__ + 1 + i__ * a_dim1] == 0.f) {
1150 } else if (a[i__ + 1 + i__ * a_dim1] != 0.f && a[i__ + (
1151 i__ + 1) * a_dim1] == 0.f) {
1156 sswap_(&i__2, &a[i__ * a_dim1 + 1], &c__1, &a[(
1157 i__ + 1) * a_dim1 + 1], &c__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);
1165 sswap_(n, &vs[i__ * vs_dim1 + 1], &c__1, &vs[(i__
1166 + 1) * vs_dim1 + 1], &c__1);
1168 a[i__ + (i__ + 1) * a_dim1] = a[i__ + 1 + i__ *
1170 a[i__ + 1 + i__ * a_dim1] = 0.f;
1181 i__2 = f2cmax(i__3,1);
1182 slascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[ieval +
1186 if (wantst && *info == 0) {
1188 /* Check if reordering successful */
1195 for (i__ = 1; i__ <= i__1; ++i__) {
1196 cursl = (*select)(&wr[i__], &wi[i__]);
1197 if (wi[i__] == 0.f) {
1202 if (cursl && ! lastsl) {
1208 /* Last eigenvalue of conjugate pair */
1210 cursl = cursl || lastsl;
1216 if (cursl && ! lst2sl) {
1221 /* First eigenvalue of conjugate pair */
1232 work[1] = (real) maxwrk;
1233 if (wantsv || wantsb) {
1234 iwork[1] = *sdim * (*n - *sdim);