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;
518 static real c_b42 = 0.f;
519 static real c_b43 = 1.f;
521 /* > \brief <b> SGGESX computes the eigenvalues, the Schur form, and, optionally, the matrix of Schur vectors
522 for GE matrices</b> */
524 /* =========== DOCUMENTATION =========== */
526 /* Online html documentation available at */
527 /* http://www.netlib.org/lapack/explore-html/ */
530 /* > Download SGGESX + dependencies */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sggesx.
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sggesx.
537 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sggesx.
545 /* SUBROUTINE SGGESX( JOBVSL, JOBVSR, SORT, SELCTG, SENSE, N, A, LDA, */
546 /* B, LDB, SDIM, ALPHAR, ALPHAI, BETA, VSL, LDVSL, */
547 /* VSR, LDVSR, RCONDE, RCONDV, WORK, LWORK, IWORK, */
548 /* LIWORK, BWORK, INFO ) */
550 /* CHARACTER JOBVSL, JOBVSR, SENSE, SORT */
551 /* INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LIWORK, LWORK, N, */
553 /* LOGICAL BWORK( * ) */
554 /* INTEGER IWORK( * ) */
555 /* REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ), */
556 /* $ B( LDB, * ), BETA( * ), RCONDE( 2 ), */
557 /* $ RCONDV( 2 ), VSL( LDVSL, * ), VSR( LDVSR, * ), */
560 /* EXTERNAL SELCTG */
563 /* > \par Purpose: */
568 /* > SGGESX computes for a pair of N-by-N real nonsymmetric matrices */
569 /* > (A,B), the generalized eigenvalues, the real Schur form (S,T), and, */
570 /* > optionally, the left and/or right matrices of Schur vectors (VSL and */
571 /* > VSR). This gives the generalized Schur factorization */
573 /* > (A,B) = ( (VSL) S (VSR)**T, (VSL) T (VSR)**T ) */
575 /* > Optionally, it also orders the eigenvalues so that a selected cluster */
576 /* > of eigenvalues appears in the leading diagonal blocks of the upper */
577 /* > quasi-triangular matrix S and the upper triangular matrix T; computes */
578 /* > a reciprocal condition number for the average of the selected */
579 /* > eigenvalues (RCONDE); and computes a reciprocal condition number for */
580 /* > the right and left deflating subspaces corresponding to the selected */
581 /* > eigenvalues (RCONDV). The leading columns of VSL and VSR then form */
582 /* > an orthonormal basis for the corresponding left and right eigenspaces */
583 /* > (deflating subspaces). */
585 /* > A generalized eigenvalue for a pair of matrices (A,B) is a scalar w */
586 /* > or a ratio alpha/beta = w, such that A - w*B is singular. It is */
587 /* > usually represented as the pair (alpha,beta), as there is a */
588 /* > reasonable interpretation for beta=0 or for both being zero. */
590 /* > A pair of matrices (S,T) is in generalized real Schur form if T is */
591 /* > upper triangular with non-negative diagonal and S is block upper */
592 /* > triangular with 1-by-1 and 2-by-2 blocks. 1-by-1 blocks correspond */
593 /* > to real generalized eigenvalues, while 2-by-2 blocks of S will be */
594 /* > "standardized" by making the corresponding elements of T have the */
599 /* > and the pair of corresponding 2-by-2 blocks in S and T will have a */
600 /* > complex conjugate pair of generalized eigenvalues. */
607 /* > \param[in] JOBVSL */
609 /* > JOBVSL is CHARACTER*1 */
610 /* > = 'N': do not compute the left Schur vectors; */
611 /* > = 'V': compute the left Schur vectors. */
614 /* > \param[in] JOBVSR */
616 /* > JOBVSR is CHARACTER*1 */
617 /* > = 'N': do not compute the right Schur vectors; */
618 /* > = 'V': compute the right Schur vectors. */
621 /* > \param[in] SORT */
623 /* > SORT is CHARACTER*1 */
624 /* > Specifies whether or not to order the eigenvalues on the */
625 /* > diagonal of the generalized Schur form. */
626 /* > = 'N': Eigenvalues are not ordered; */
627 /* > = 'S': Eigenvalues are ordered (see SELCTG). */
630 /* > \param[in] SELCTG */
632 /* > SELCTG is a LOGICAL FUNCTION of three REAL arguments */
633 /* > SELCTG must be declared EXTERNAL in the calling subroutine. */
634 /* > If SORT = 'N', SELCTG is not referenced. */
635 /* > If SORT = 'S', SELCTG is used to select eigenvalues to sort */
636 /* > to the top left of the Schur form. */
637 /* > An eigenvalue (ALPHAR(j)+ALPHAI(j))/BETA(j) is selected if */
638 /* > SELCTG(ALPHAR(j),ALPHAI(j),BETA(j)) is true; i.e. if either */
639 /* > one of a complex conjugate pair of eigenvalues is selected, */
640 /* > then both complex eigenvalues are selected. */
641 /* > Note that a selected complex eigenvalue may no longer satisfy */
642 /* > SELCTG(ALPHAR(j),ALPHAI(j),BETA(j)) = .TRUE. after ordering, */
643 /* > since ordering may change the value of complex eigenvalues */
644 /* > (especially if the eigenvalue is ill-conditioned), in this */
645 /* > case INFO is set to N+3. */
648 /* > \param[in] SENSE */
650 /* > SENSE is CHARACTER*1 */
651 /* > Determines which reciprocal condition numbers are computed. */
652 /* > = 'N': None are computed; */
653 /* > = 'E': Computed for average of selected eigenvalues only; */
654 /* > = 'V': Computed for selected deflating subspaces only; */
655 /* > = 'B': Computed for both. */
656 /* > If SENSE = 'E', 'V', or 'B', SORT must equal 'S'. */
662 /* > The order of the matrices A, B, VSL, and VSR. N >= 0. */
665 /* > \param[in,out] A */
667 /* > A is REAL array, dimension (LDA, N) */
668 /* > On entry, the first of the pair of matrices. */
669 /* > On exit, A has been overwritten by its generalized Schur */
673 /* > \param[in] LDA */
675 /* > LDA is INTEGER */
676 /* > The leading dimension of A. LDA >= f2cmax(1,N). */
679 /* > \param[in,out] B */
681 /* > B is REAL array, dimension (LDB, N) */
682 /* > On entry, the second of the pair of matrices. */
683 /* > On exit, B has been overwritten by its generalized Schur */
687 /* > \param[in] LDB */
689 /* > LDB is INTEGER */
690 /* > The leading dimension of B. LDB >= f2cmax(1,N). */
693 /* > \param[out] SDIM */
695 /* > SDIM is INTEGER */
696 /* > If SORT = 'N', SDIM = 0. */
697 /* > If SORT = 'S', SDIM = number of eigenvalues (after sorting) */
698 /* > for which SELCTG is true. (Complex conjugate pairs for which */
699 /* > SELCTG is true for either eigenvalue count as 2.) */
702 /* > \param[out] ALPHAR */
704 /* > ALPHAR is REAL array, dimension (N) */
707 /* > \param[out] ALPHAI */
709 /* > ALPHAI is REAL array, dimension (N) */
712 /* > \param[out] BETA */
714 /* > BETA is REAL array, dimension (N) */
715 /* > On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will */
716 /* > be the generalized eigenvalues. ALPHAR(j) + ALPHAI(j)*i */
717 /* > and BETA(j),j=1,...,N are the diagonals of the complex Schur */
718 /* > form (S,T) that would result if the 2-by-2 diagonal blocks of */
719 /* > the real Schur form of (A,B) were further reduced to */
720 /* > triangular form using 2-by-2 complex unitary transformations. */
721 /* > If ALPHAI(j) is zero, then the j-th eigenvalue is real; if */
722 /* > positive, then the j-th and (j+1)-st eigenvalues are a */
723 /* > complex conjugate pair, with ALPHAI(j+1) negative. */
725 /* > Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j) */
726 /* > may easily over- or underflow, and BETA(j) may even be zero. */
727 /* > Thus, the user should avoid naively computing the ratio. */
728 /* > However, ALPHAR and ALPHAI will be always less than and */
729 /* > usually comparable with norm(A) in magnitude, and BETA always */
730 /* > less than and usually comparable with norm(B). */
733 /* > \param[out] VSL */
735 /* > VSL is REAL array, dimension (LDVSL,N) */
736 /* > If JOBVSL = 'V', VSL will contain the left Schur vectors. */
737 /* > Not referenced if JOBVSL = 'N'. */
740 /* > \param[in] LDVSL */
742 /* > LDVSL is INTEGER */
743 /* > The leading dimension of the matrix VSL. LDVSL >=1, and */
744 /* > if JOBVSL = 'V', LDVSL >= N. */
747 /* > \param[out] VSR */
749 /* > VSR is REAL array, dimension (LDVSR,N) */
750 /* > If JOBVSR = 'V', VSR will contain the right Schur vectors. */
751 /* > Not referenced if JOBVSR = 'N'. */
754 /* > \param[in] LDVSR */
756 /* > LDVSR is INTEGER */
757 /* > The leading dimension of the matrix VSR. LDVSR >= 1, and */
758 /* > if JOBVSR = 'V', LDVSR >= N. */
761 /* > \param[out] RCONDE */
763 /* > RCONDE is REAL array, dimension ( 2 ) */
764 /* > If SENSE = 'E' or 'B', RCONDE(1) and RCONDE(2) contain the */
765 /* > reciprocal condition numbers for the average of the selected */
767 /* > Not referenced if SENSE = 'N' or 'V'. */
770 /* > \param[out] RCONDV */
772 /* > RCONDV is REAL array, dimension ( 2 ) */
773 /* > If SENSE = 'V' or 'B', RCONDV(1) and RCONDV(2) contain the */
774 /* > reciprocal condition numbers for the selected deflating */
776 /* > Not referenced if SENSE = 'N' or 'E'. */
779 /* > \param[out] WORK */
781 /* > WORK is REAL array, dimension (MAX(1,LWORK)) */
782 /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
785 /* > \param[in] LWORK */
787 /* > LWORK is INTEGER */
788 /* > The dimension of the array WORK. */
789 /* > If N = 0, LWORK >= 1, else if SENSE = 'E', 'V', or 'B', */
790 /* > LWORK >= f2cmax( 8*N, 6*N+16, 2*SDIM*(N-SDIM) ), else */
791 /* > LWORK >= f2cmax( 8*N, 6*N+16 ). */
792 /* > Note that 2*SDIM*(N-SDIM) <= N*N/2. */
793 /* > Note also that an error is only returned if */
794 /* > LWORK < f2cmax( 8*N, 6*N+16), but if SENSE = 'E' or 'V' or 'B' */
795 /* > this may not be large enough. */
797 /* > If LWORK = -1, then a workspace query is assumed; the routine */
798 /* > only calculates the bound on the optimal size of the WORK */
799 /* > array and the minimum size of the IWORK array, returns these */
800 /* > values as the first entries of the WORK and IWORK arrays, and */
801 /* > no error message related to LWORK or LIWORK is issued by */
805 /* > \param[out] IWORK */
807 /* > IWORK is INTEGER array, dimension (MAX(1,LIWORK)) */
808 /* > On exit, if INFO = 0, IWORK(1) returns the minimum LIWORK. */
811 /* > \param[in] LIWORK */
813 /* > LIWORK is INTEGER */
814 /* > The dimension of the array IWORK. */
815 /* > If SENSE = 'N' or N = 0, LIWORK >= 1, otherwise */
816 /* > LIWORK >= N+6. */
818 /* > If LIWORK = -1, then a workspace query is assumed; the */
819 /* > routine only calculates the bound on the optimal size of the */
820 /* > WORK array and the minimum size of the IWORK array, returns */
821 /* > these values as the first entries of the WORK and IWORK */
822 /* > arrays, and no error message related to LWORK or LIWORK is */
823 /* > issued by XERBLA. */
826 /* > \param[out] BWORK */
828 /* > BWORK is LOGICAL array, dimension (N) */
829 /* > Not referenced if SORT = 'N'. */
832 /* > \param[out] INFO */
834 /* > INFO is INTEGER */
835 /* > = 0: successful exit */
836 /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
838 /* > The QZ iteration failed. (A,B) are not in Schur */
839 /* > form, but ALPHAR(j), ALPHAI(j), and BETA(j) should */
840 /* > be correct for j=INFO+1,...,N. */
841 /* > > N: =N+1: other than QZ iteration failed in SHGEQZ */
842 /* > =N+2: after reordering, roundoff changed values of */
843 /* > some complex eigenvalues so that leading */
844 /* > eigenvalues in the Generalized Schur form no */
845 /* > longer satisfy SELCTG=.TRUE. This could also */
846 /* > be caused due to scaling. */
847 /* > =N+3: reordering failed in STGSEN. */
853 /* > \author Univ. of Tennessee */
854 /* > \author Univ. of California Berkeley */
855 /* > \author Univ. of Colorado Denver */
856 /* > \author NAG Ltd. */
858 /* > \date June 2017 */
860 /* > \ingroup realGEeigen */
862 /* > \par Further Details: */
863 /* ===================== */
867 /* > An approximate (asymptotic) bound on the average absolute error of */
868 /* > the selected eigenvalues is */
870 /* > EPS * norm((A, B)) / RCONDE( 1 ). */
872 /* > An approximate (asymptotic) bound on the maximum angular error in */
873 /* > the computed deflating subspaces is */
875 /* > EPS * norm((A, B)) / RCONDV( 2 ). */
877 /* > See LAPACK User's Guide, section 4.11 for more information. */
880 /* ===================================================================== */
881 /* Subroutine */ int sggesx_(char *jobvsl, char *jobvsr, char *sort, L_fp
882 selctg, char *sense, integer *n, real *a, integer *lda, real *b,
883 integer *ldb, integer *sdim, real *alphar, real *alphai, real *beta,
884 real *vsl, integer *ldvsl, real *vsr, integer *ldvsr, real *rconde,
885 real *rcondv, real *work, integer *lwork, integer *iwork, integer *
886 liwork, logical *bwork, integer *info)
888 /* System generated locals */
889 integer a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset,
890 vsr_dim1, vsr_offset, i__1, i__2;
893 /* Local variables */
896 integer ierr, itau, iwrk, lwrk, i__;
897 extern logical lsame_(char *, char *);
898 integer ileft, icols;
899 logical cursl, ilvsl, ilvsr;
902 extern /* Subroutine */ int slabad_(real *, real *);
905 extern /* Subroutine */ int sggbak_(char *, char *, integer *, integer *,
906 integer *, real *, real *, integer *, real *, integer *, integer *
907 ), sggbal_(char *, integer *, real *, integer *,
908 real *, integer *, integer *, integer *, real *, real *, real *,
911 logical ilascl, ilbscl;
912 extern real slamch_(char *), slange_(char *, integer *, integer *,
913 real *, integer *, real *);
915 extern /* Subroutine */ int sgghrd_(char *, char *, integer *, integer *,
916 integer *, real *, integer *, real *, integer *, real *, integer *
917 , real *, integer *, integer *);
919 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
921 extern /* Subroutine */ int slascl_(char *, integer *, integer *, real *,
922 real *, integer *, integer *, real *, integer *, integer *);
923 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
924 integer *, integer *, ftnlen, ftnlen);
925 integer ijobvl, iright;
926 extern /* Subroutine */ int sgeqrf_(integer *, integer *, real *, integer
927 *, real *, real *, integer *, integer *);
929 extern /* Subroutine */ int slacpy_(char *, integer *, integer *, real *,
930 integer *, real *, integer *);
931 logical wantsb, wantse, lastsl;
934 integer minwrk, maxwrk;
937 extern /* Subroutine */ int shgeqz_(char *, char *, char *, integer *,
938 integer *, integer *, real *, integer *, real *, integer *, real *
939 , real *, real *, real *, integer *, real *, integer *, real *,
940 integer *, integer *), slaset_(char *,
941 integer *, integer *, real *, real *, real *, integer *),
942 sorgqr_(integer *, integer *, integer *, real *, integer *, real *
943 , real *, integer *, integer *), stgsen_(integer *, logical *,
944 logical *, logical *, integer *, real *, integer *, real *,
945 integer *, real *, real *, real *, real *, integer *, real *,
946 integer *, integer *, real *, real *, real *, real *, integer *,
947 integer *, integer *, integer *);
948 logical wantst, lquery, wantsv;
949 extern /* Subroutine */ int sormqr_(char *, char *, integer *, integer *,
950 integer *, real *, integer *, real *, real *, integer *, real *,
951 integer *, integer *);
957 /* -- LAPACK driver routine (version 3.7.1) -- */
958 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
959 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
963 /* ===================================================================== */
966 /* Decode the input arguments */
968 /* Parameter adjustments */
970 a_offset = 1 + a_dim1 * 1;
973 b_offset = 1 + b_dim1 * 1;
979 vsl_offset = 1 + vsl_dim1 * 1;
982 vsr_offset = 1 + vsr_dim1 * 1;
991 if (lsame_(jobvsl, "N")) {
994 } else if (lsame_(jobvsl, "V")) {
1002 if (lsame_(jobvsr, "N")) {
1005 } else if (lsame_(jobvsr, "V")) {
1013 wantst = lsame_(sort, "S");
1014 wantsn = lsame_(sense, "N");
1015 wantse = lsame_(sense, "E");
1016 wantsv = lsame_(sense, "V");
1017 wantsb = lsame_(sense, "B");
1018 lquery = *lwork == -1 || *liwork == -1;
1021 } else if (wantse) {
1023 } else if (wantsv) {
1025 } else if (wantsb) {
1029 /* Test the input arguments */
1034 } else if (ijobvr <= 0) {
1036 } else if (! wantst && ! lsame_(sort, "N")) {
1038 } else if (! (wantsn || wantse || wantsv || wantsb) || ! wantst && !
1041 } else if (*n < 0) {
1043 } else if (*lda < f2cmax(1,*n)) {
1045 } else if (*ldb < f2cmax(1,*n)) {
1047 } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) {
1049 } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) {
1053 /* Compute workspace */
1054 /* (Note: Comments in the code beginning "Workspace:" describe the */
1055 /* minimal amount of workspace needed at that point in the code, */
1056 /* as well as the preferred amount for good performance. */
1057 /* NB refers to the optimal block size for the immediately */
1058 /* following subroutine, as returned by ILAENV.) */
1063 i__1 = *n << 3, i__2 = *n * 6 + 16;
1064 minwrk = f2cmax(i__1,i__2);
1065 maxwrk = minwrk - *n + *n * ilaenv_(&c__1, "SGEQRF", " ", n, &
1066 c__1, n, &c__0, (ftnlen)6, (ftnlen)1);
1068 i__1 = maxwrk, i__2 = minwrk - *n + *n * ilaenv_(&c__1, "SORMQR",
1069 " ", n, &c__1, n, &c_n1, (ftnlen)6, (ftnlen)1);
1070 maxwrk = f2cmax(i__1,i__2);
1073 i__1 = maxwrk, i__2 = minwrk - *n + *n * ilaenv_(&c__1, "SOR"
1074 "GQR", " ", n, &c__1, n, &c_n1, (ftnlen)6, (ftnlen)1);
1075 maxwrk = f2cmax(i__1,i__2);
1080 i__1 = lwrk, i__2 = *n * *n / 2;
1081 lwrk = f2cmax(i__1,i__2);
1088 work[1] = (real) lwrk;
1089 if (wantsn || *n == 0) {
1096 if (*lwork < minwrk && ! lquery) {
1098 } else if (*liwork < liwmin && ! lquery) {
1105 xerbla_("SGGESX", &i__1, (ftnlen)6);
1107 } else if (lquery) {
1111 /* Quick return if possible */
1118 /* Get machine constants */
1121 safmin = slamch_("S");
1122 safmax = 1.f / safmin;
1123 slabad_(&safmin, &safmax);
1124 smlnum = sqrt(safmin) / eps;
1125 bignum = 1.f / smlnum;
1127 /* Scale A if f2cmax element outside range [SMLNUM,BIGNUM] */
1129 anrm = slange_("M", n, n, &a[a_offset], lda, &work[1]);
1131 if (anrm > 0.f && anrm < smlnum) {
1134 } else if (anrm > bignum) {
1139 slascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
1143 /* Scale B if f2cmax element outside range [SMLNUM,BIGNUM] */
1145 bnrm = slange_("M", n, n, &b[b_offset], ldb, &work[1]);
1147 if (bnrm > 0.f && bnrm < smlnum) {
1150 } else if (bnrm > bignum) {
1155 slascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
1159 /* Permute the matrix to make it more nearly triangular */
1160 /* (Workspace: need 6*N + 2*N for permutation parameters) */
1165 sggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &work[
1166 ileft], &work[iright], &work[iwrk], &ierr);
1168 /* Reduce B to triangular form (QR decomposition of B) */
1169 /* (Workspace: need N, prefer N*NB) */
1171 irows = ihi + 1 - ilo;
1172 icols = *n + 1 - ilo;
1174 iwrk = itau + irows;
1175 i__1 = *lwork + 1 - iwrk;
1176 sgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
1177 iwrk], &i__1, &ierr);
1179 /* Apply the orthogonal transformation to matrix A */
1180 /* (Workspace: need N, prefer N*NB) */
1182 i__1 = *lwork + 1 - iwrk;
1183 sormqr_("L", "T", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
1184 work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, &
1187 /* Initialize VSL */
1188 /* (Workspace: need N, prefer N*NB) */
1191 slaset_("Full", n, n, &c_b42, &c_b43, &vsl[vsl_offset], ldvsl);
1195 slacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vsl[
1196 ilo + 1 + ilo * vsl_dim1], ldvsl);
1198 i__1 = *lwork + 1 - iwrk;
1199 sorgqr_(&irows, &irows, &irows, &vsl[ilo + ilo * vsl_dim1], ldvsl, &
1200 work[itau], &work[iwrk], &i__1, &ierr);
1203 /* Initialize VSR */
1206 slaset_("Full", n, n, &c_b42, &c_b43, &vsr[vsr_offset], ldvsr);
1209 /* Reduce to generalized Hessenberg form */
1210 /* (Workspace: none needed) */
1212 sgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
1213 ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &ierr);
1217 /* Perform QZ algorithm, computing Schur vectors if desired */
1218 /* (Workspace: need N) */
1221 i__1 = *lwork + 1 - iwrk;
1222 shgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[
1223 b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vsl[vsl_offset]
1224 , ldvsl, &vsr[vsr_offset], ldvsr, &work[iwrk], &i__1, &ierr);
1226 if (ierr > 0 && ierr <= *n) {
1228 } else if (ierr > *n && ierr <= *n << 1) {
1236 /* Sort eigenvalues ALPHA/BETA and compute the reciprocal of */
1237 /* condition number(s) */
1238 /* (Workspace: If IJOB >= 1, need MAX( 8*(N+1), 2*SDIM*(N-SDIM) ) */
1239 /* otherwise, need 8*(N+1) ) */
1243 /* Undo scaling on eigenvalues before SELCTGing */
1246 slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1],
1248 slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1],
1252 slascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n,
1256 /* Select eigenvalues */
1259 for (i__ = 1; i__ <= i__1; ++i__) {
1260 bwork[i__] = (*selctg)(&alphar[i__], &alphai[i__], &beta[i__]);
1264 /* Reorder eigenvalues, transform Generalized Schur vectors, and */
1265 /* compute reciprocal condition numbers */
1267 i__1 = *lwork - iwrk + 1;
1268 stgsen_(&ijob, &ilvsl, &ilvsr, &bwork[1], n, &a[a_offset], lda, &b[
1269 b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vsl[
1270 vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, sdim, &pl, &pr,
1271 dif, &work[iwrk], &i__1, &iwork[1], liwork, &ierr);
1275 i__1 = maxwrk, i__2 = (*sdim << 1) * (*n - *sdim);
1276 maxwrk = f2cmax(i__1,i__2);
1280 /* not enough real workspace */
1284 if (ijob == 1 || ijob == 4) {
1288 if (ijob == 2 || ijob == 4) {
1299 /* Apply permutation to VSL and VSR */
1300 /* (Workspace: none needed) */
1303 sggbak_("P", "L", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsl[
1304 vsl_offset], ldvsl, &ierr);
1308 sggbak_("P", "R", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsr[
1309 vsr_offset], ldvsr, &ierr);
1312 /* Check if unscaling would cause over/underflow, if so, rescale */
1313 /* (ALPHAR(I),ALPHAI(I),BETA(I)) so BETA(I) is on the order of */
1314 /* B(I,I) and ALPHAR(I) and ALPHAI(I) are on the order of A(I,I) */
1318 for (i__ = 1; i__ <= i__1; ++i__) {
1319 if (alphai[i__] != 0.f) {
1320 if (alphar[i__] / safmax > anrmto / anrm || safmin / alphar[
1321 i__] > anrm / anrmto) {
1322 work[1] = (r__1 = a[i__ + i__ * a_dim1] / alphar[i__],
1324 beta[i__] *= work[1];
1325 alphar[i__] *= work[1];
1326 alphai[i__] *= work[1];
1327 } else if (alphai[i__] / safmax > anrmto / anrm || safmin /
1328 alphai[i__] > anrm / anrmto) {
1329 work[1] = (r__1 = a[i__ + (i__ + 1) * a_dim1] / alphai[
1331 beta[i__] *= work[1];
1332 alphar[i__] *= work[1];
1333 alphai[i__] *= work[1];
1342 for (i__ = 1; i__ <= i__1; ++i__) {
1343 if (alphai[i__] != 0.f) {
1344 if (beta[i__] / safmax > bnrmto / bnrm || safmin / beta[i__]
1346 work[1] = (r__1 = b[i__ + i__ * b_dim1] / beta[i__], abs(
1348 beta[i__] *= work[1];
1349 alphar[i__] *= work[1];
1350 alphai[i__] *= work[1];
1360 slascl_("H", &c__0, &c__0, &anrmto, &anrm, n, n, &a[a_offset], lda, &
1362 slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1], n, &
1364 slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1], n, &
1369 slascl_("U", &c__0, &c__0, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, &
1371 slascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
1377 /* Check if reordering is correct */
1384 for (i__ = 1; i__ <= i__1; ++i__) {
1385 cursl = (*selctg)(&alphar[i__], &alphai[i__], &beta[i__]);
1386 if (alphai[i__] == 0.f) {
1391 if (cursl && ! lastsl) {
1397 /* Last eigenvalue of conjugate pair */
1399 cursl = cursl || lastsl;
1405 if (cursl && ! lst2sl) {
1410 /* First eigenvalue of conjugate pair */
1424 work[1] = (real) maxwrk;