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 complex c_b1 = {0.f,0.f};
516 static complex c_b2 = {1.f,0.f};
517 static integer c__1 = 1;
518 static integer c__0 = 0;
519 static integer c_n1 = -1;
521 /* > \brief <b> CGGESX 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 CGGESX + dependencies */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cggesx.
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cggesx.
537 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cggesx.
545 /* SUBROUTINE CGGESX( JOBVSL, JOBVSR, SORT, SELCTG, SENSE, N, A, LDA, */
546 /* B, LDB, SDIM, ALPHA, BETA, VSL, LDVSL, VSR, */
547 /* LDVSR, RCONDE, RCONDV, WORK, LWORK, RWORK, */
548 /* IWORK, 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 RCONDE( 2 ), RCONDV( 2 ), RWORK( * ) */
556 /* COMPLEX A( LDA, * ), ALPHA( * ), B( LDB, * ), */
557 /* $ BETA( * ), VSL( LDVSL, * ), VSR( LDVSR, * ), */
560 /* EXTERNAL SELCTG */
563 /* > \par Purpose: */
568 /* > CGGESX computes for a pair of N-by-N complex nonsymmetric matrices */
569 /* > (A,B), the generalized eigenvalues, the complex Schur form (S,T), */
570 /* > and, optionally, the left and/or right matrices of Schur vectors (VSL */
571 /* > and VSR). This gives the generalized Schur factorization */
573 /* > (A,B) = ( (VSL) S (VSR)**H, (VSL) T (VSR)**H ) */
575 /* > where (VSR)**H is the conjugate-transpose of VSR. */
577 /* > Optionally, it also orders the eigenvalues so that a selected cluster */
578 /* > of eigenvalues appears in the leading diagonal blocks of the upper */
579 /* > triangular matrix S and the upper triangular matrix T; computes */
580 /* > a reciprocal condition number for the average of the selected */
581 /* > eigenvalues (RCONDE); and computes a reciprocal condition number for */
582 /* > the right and left deflating subspaces corresponding to the selected */
583 /* > eigenvalues (RCONDV). The leading columns of VSL and VSR then form */
584 /* > an orthonormal basis for the corresponding left and right eigenspaces */
585 /* > (deflating subspaces). */
587 /* > A generalized eigenvalue for a pair of matrices (A,B) is a scalar w */
588 /* > or a ratio alpha/beta = w, such that A - w*B is singular. It is */
589 /* > usually represented as the pair (alpha,beta), as there is a */
590 /* > reasonable interpretation for beta=0 or for both being zero. */
592 /* > A pair of matrices (S,T) is in generalized complex Schur form if T is */
593 /* > upper triangular with non-negative diagonal and S is upper */
600 /* > \param[in] JOBVSL */
602 /* > JOBVSL is CHARACTER*1 */
603 /* > = 'N': do not compute the left Schur vectors; */
604 /* > = 'V': compute the left Schur vectors. */
607 /* > \param[in] JOBVSR */
609 /* > JOBVSR is CHARACTER*1 */
610 /* > = 'N': do not compute the right Schur vectors; */
611 /* > = 'V': compute the right Schur vectors. */
614 /* > \param[in] SORT */
616 /* > SORT is CHARACTER*1 */
617 /* > Specifies whether or not to order the eigenvalues on the */
618 /* > diagonal of the generalized Schur form. */
619 /* > = 'N': Eigenvalues are not ordered; */
620 /* > = 'S': Eigenvalues are ordered (see SELCTG). */
623 /* > \param[in] SELCTG */
625 /* > SELCTG is a LOGICAL FUNCTION of two COMPLEX arguments */
626 /* > SELCTG must be declared EXTERNAL in the calling subroutine. */
627 /* > If SORT = 'N', SELCTG is not referenced. */
628 /* > If SORT = 'S', SELCTG is used to select eigenvalues to sort */
629 /* > to the top left of the Schur form. */
630 /* > Note that a selected complex eigenvalue may no longer satisfy */
631 /* > SELCTG(ALPHA(j),BETA(j)) = .TRUE. after ordering, since */
632 /* > ordering may change the value of complex eigenvalues */
633 /* > (especially if the eigenvalue is ill-conditioned), in this */
634 /* > case INFO is set to N+3 see INFO below). */
637 /* > \param[in] SENSE */
639 /* > SENSE is CHARACTER*1 */
640 /* > Determines which reciprocal condition numbers are computed. */
641 /* > = 'N': None are computed; */
642 /* > = 'E': Computed for average of selected eigenvalues only; */
643 /* > = 'V': Computed for selected deflating subspaces only; */
644 /* > = 'B': Computed for both. */
645 /* > If SENSE = 'E', 'V', or 'B', SORT must equal 'S'. */
651 /* > The order of the matrices A, B, VSL, and VSR. N >= 0. */
654 /* > \param[in,out] A */
656 /* > A is COMPLEX array, dimension (LDA, N) */
657 /* > On entry, the first of the pair of matrices. */
658 /* > On exit, A has been overwritten by its generalized Schur */
662 /* > \param[in] LDA */
664 /* > LDA is INTEGER */
665 /* > The leading dimension of A. LDA >= f2cmax(1,N). */
668 /* > \param[in,out] B */
670 /* > B is COMPLEX array, dimension (LDB, N) */
671 /* > On entry, the second of the pair of matrices. */
672 /* > On exit, B has been overwritten by its generalized Schur */
676 /* > \param[in] LDB */
678 /* > LDB is INTEGER */
679 /* > The leading dimension of B. LDB >= f2cmax(1,N). */
682 /* > \param[out] SDIM */
684 /* > SDIM is INTEGER */
685 /* > If SORT = 'N', SDIM = 0. */
686 /* > If SORT = 'S', SDIM = number of eigenvalues (after sorting) */
687 /* > for which SELCTG is true. */
690 /* > \param[out] ALPHA */
692 /* > ALPHA is COMPLEX array, dimension (N) */
695 /* > \param[out] BETA */
697 /* > BETA is COMPLEX array, dimension (N) */
698 /* > On exit, ALPHA(j)/BETA(j), j=1,...,N, will be the */
699 /* > generalized eigenvalues. ALPHA(j) and BETA(j),j=1,...,N are */
700 /* > the diagonals of the complex Schur form (S,T). BETA(j) will */
701 /* > be non-negative real. */
703 /* > Note: the quotients ALPHA(j)/BETA(j) may easily over- or */
704 /* > underflow, and BETA(j) may even be zero. Thus, the user */
705 /* > should avoid naively computing the ratio alpha/beta. */
706 /* > However, ALPHA will be always less than and usually */
707 /* > comparable with norm(A) in magnitude, and BETA always less */
708 /* > than and usually comparable with norm(B). */
711 /* > \param[out] VSL */
713 /* > VSL is COMPLEX array, dimension (LDVSL,N) */
714 /* > If JOBVSL = 'V', VSL will contain the left Schur vectors. */
715 /* > Not referenced if JOBVSL = 'N'. */
718 /* > \param[in] LDVSL */
720 /* > LDVSL is INTEGER */
721 /* > The leading dimension of the matrix VSL. LDVSL >=1, and */
722 /* > if JOBVSL = 'V', LDVSL >= N. */
725 /* > \param[out] VSR */
727 /* > VSR is COMPLEX array, dimension (LDVSR,N) */
728 /* > If JOBVSR = 'V', VSR will contain the right Schur vectors. */
729 /* > Not referenced if JOBVSR = 'N'. */
732 /* > \param[in] LDVSR */
734 /* > LDVSR is INTEGER */
735 /* > The leading dimension of the matrix VSR. LDVSR >= 1, and */
736 /* > if JOBVSR = 'V', LDVSR >= N. */
739 /* > \param[out] RCONDE */
741 /* > RCONDE is REAL array, dimension ( 2 ) */
742 /* > If SENSE = 'E' or 'B', RCONDE(1) and RCONDE(2) contain the */
743 /* > reciprocal condition numbers for the average of the selected */
745 /* > Not referenced if SENSE = 'N' or 'V'. */
748 /* > \param[out] RCONDV */
750 /* > RCONDV is REAL array, dimension ( 2 ) */
751 /* > If SENSE = 'V' or 'B', RCONDV(1) and RCONDV(2) contain the */
752 /* > reciprocal condition number for the selected deflating */
754 /* > Not referenced if SENSE = 'N' or 'E'. */
757 /* > \param[out] WORK */
759 /* > WORK is COMPLEX array, dimension (MAX(1,LWORK)) */
760 /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
763 /* > \param[in] LWORK */
765 /* > LWORK is INTEGER */
766 /* > The dimension of the array WORK. */
767 /* > If N = 0, LWORK >= 1, else if SENSE = 'E', 'V', or 'B', */
768 /* > LWORK >= MAX(1,2*N,2*SDIM*(N-SDIM)), else */
769 /* > LWORK >= MAX(1,2*N). Note that 2*SDIM*(N-SDIM) <= N*N/2. */
770 /* > Note also that an error is only returned if */
771 /* > LWORK < MAX(1,2*N), but if SENSE = 'E' or 'V' or 'B' this may */
772 /* > not be large enough. */
774 /* > If LWORK = -1, then a workspace query is assumed; the routine */
775 /* > only calculates the bound on the optimal size of the WORK */
776 /* > array and the minimum size of the IWORK array, returns these */
777 /* > values as the first entries of the WORK and IWORK arrays, and */
778 /* > no error message related to LWORK or LIWORK is issued by */
782 /* > \param[out] RWORK */
784 /* > RWORK is REAL array, dimension ( 8*N ) */
785 /* > Real workspace. */
788 /* > \param[out] IWORK */
790 /* > IWORK is INTEGER array, dimension (MAX(1,LIWORK)) */
791 /* > On exit, if INFO = 0, IWORK(1) returns the minimum LIWORK. */
794 /* > \param[in] LIWORK */
796 /* > LIWORK is INTEGER */
797 /* > The dimension of the array WORK. */
798 /* > If SENSE = 'N' or N = 0, LIWORK >= 1, otherwise */
799 /* > LIWORK >= N+2. */
801 /* > If LIWORK = -1, then a workspace query is assumed; the */
802 /* > routine only calculates the bound on the optimal size of the */
803 /* > WORK array and the minimum size of the IWORK array, returns */
804 /* > these values as the first entries of the WORK and IWORK */
805 /* > arrays, and no error message related to LWORK or LIWORK is */
806 /* > issued by XERBLA. */
809 /* > \param[out] BWORK */
811 /* > BWORK is LOGICAL array, dimension (N) */
812 /* > Not referenced if SORT = 'N'. */
815 /* > \param[out] INFO */
817 /* > INFO is INTEGER */
818 /* > = 0: successful exit */
819 /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
821 /* > The QZ iteration failed. (A,B) are not in Schur */
822 /* > form, but ALPHA(j) and BETA(j) should be correct for */
823 /* > j=INFO+1,...,N. */
824 /* > > N: =N+1: other than QZ iteration failed in CHGEQZ */
825 /* > =N+2: after reordering, roundoff changed values of */
826 /* > some complex eigenvalues so that leading */
827 /* > eigenvalues in the Generalized Schur form no */
828 /* > longer satisfy SELCTG=.TRUE. This could also */
829 /* > be caused due to scaling. */
830 /* > =N+3: reordering failed in CTGSEN. */
836 /* > \author Univ. of Tennessee */
837 /* > \author Univ. of California Berkeley */
838 /* > \author Univ. of Colorado Denver */
839 /* > \author NAG Ltd. */
841 /* > \date June 2017 */
843 /* > \ingroup complexGEeigen */
845 /* ===================================================================== */
846 /* Subroutine */ int cggesx_(char *jobvsl, char *jobvsr, char *sort, L_fp
847 selctg, char *sense, integer *n, complex *a, integer *lda, complex *b,
848 integer *ldb, integer *sdim, complex *alpha, complex *beta, complex *
849 vsl, integer *ldvsl, complex *vsr, integer *ldvsr, real *rconde, real
850 *rcondv, complex *work, integer *lwork, real *rwork, integer *iwork,
851 integer *liwork, logical *bwork, integer *info)
853 /* System generated locals */
854 integer a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset,
855 vsr_dim1, vsr_offset, i__1, i__2;
857 /* Local variables */
860 integer ierr, itau, iwrk, lwrk, i__;
861 extern logical lsame_(char *, char *);
862 integer ileft, icols;
863 logical cursl, ilvsl, ilvsr;
864 integer irwrk, irows;
865 extern /* Subroutine */ int cggbak_(char *, char *, integer *, integer *,
866 integer *, real *, real *, integer *, complex *, integer *,
867 integer *), cggbal_(char *, integer *, complex *,
868 integer *, complex *, integer *, integer *, integer *, real *,
869 real *, real *, integer *), slabad_(real *, real *);
870 extern real clange_(char *, integer *, integer *, complex *, integer *,
873 extern /* Subroutine */ int cgghrd_(char *, char *, integer *, integer *,
874 integer *, complex *, integer *, complex *, integer *, complex *,
875 integer *, complex *, integer *, integer *),
876 clascl_(char *, integer *, integer *, real *, real *, integer *,
877 integer *, complex *, integer *, integer *);
879 logical ilascl, ilbscl;
880 extern /* Subroutine */ int cgeqrf_(integer *, integer *, complex *,
881 integer *, complex *, complex *, integer *, integer *), clacpy_(
882 char *, integer *, integer *, complex *, integer *, complex *,
883 integer *), claset_(char *, integer *, integer *, complex
884 *, complex *, complex *, integer *), xerbla_(char *,
886 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
887 integer *, integer *, ftnlen, ftnlen);
888 extern real slamch_(char *);
890 extern /* Subroutine */ int chgeqz_(char *, char *, char *, integer *,
891 integer *, integer *, complex *, integer *, complex *, integer *,
892 complex *, complex *, complex *, integer *, complex *, integer *,
893 complex *, integer *, real *, integer *),
894 ctgsen_(integer *, logical *, logical *, logical *, integer *,
895 complex *, integer *, complex *, integer *, complex *, complex *,
896 complex *, integer *, complex *, integer *, integer *, real *,
897 real *, real *, complex *, integer *, integer *, integer *,
899 integer ijobvl, iright, ijobvr;
902 logical wantse, lastsl;
904 extern /* Subroutine */ int cungqr_(integer *, integer *, integer *,
905 complex *, integer *, complex *, complex *, integer *, integer *);
906 integer minwrk, maxwrk;
909 extern /* Subroutine */ int cunmqr_(char *, char *, integer *, integer *,
910 integer *, complex *, integer *, complex *, complex *, integer *,
911 complex *, integer *, integer *);
912 logical wantst, lquery, wantsv;
918 /* -- LAPACK driver routine (version 3.7.1) -- */
919 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
920 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
924 /* ===================================================================== */
927 /* Decode the input arguments */
929 /* Parameter adjustments */
931 a_offset = 1 + a_dim1 * 1;
934 b_offset = 1 + b_dim1 * 1;
939 vsl_offset = 1 + vsl_dim1 * 1;
942 vsr_offset = 1 + vsr_dim1 * 1;
952 if (lsame_(jobvsl, "N")) {
955 } else if (lsame_(jobvsl, "V")) {
963 if (lsame_(jobvsr, "N")) {
966 } else if (lsame_(jobvsr, "V")) {
974 wantst = lsame_(sort, "S");
975 wantsn = lsame_(sense, "N");
976 wantse = lsame_(sense, "E");
977 wantsv = lsame_(sense, "V");
978 wantsb = lsame_(sense, "B");
979 lquery = *lwork == -1 || *liwork == -1;
990 /* Test the input arguments */
995 } else if (ijobvr <= 0) {
997 } else if (! wantst && ! lsame_(sort, "N")) {
999 } else if (! (wantsn || wantse || wantsv || wantsb) || ! wantst && !
1002 } else if (*n < 0) {
1004 } else if (*lda < f2cmax(1,*n)) {
1006 } else if (*ldb < f2cmax(1,*n)) {
1008 } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) {
1010 } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) {
1014 /* Compute workspace */
1015 /* (Note: Comments in the code beginning "Workspace:" describe the */
1016 /* minimal amount of workspace needed at that point in the code, */
1017 /* as well as the preferred amount for good performance. */
1018 /* NB refers to the optimal block size for the immediately */
1019 /* following subroutine, as returned by ILAENV.) */
1024 maxwrk = *n * (ilaenv_(&c__1, "CGEQRF", " ", n, &c__1, n, &c__0, (
1025 ftnlen)6, (ftnlen)1) + 1);
1027 i__1 = maxwrk, i__2 = *n * (ilaenv_(&c__1, "CUNMQR", " ", n, &
1028 c__1, n, &c_n1, (ftnlen)6, (ftnlen)1) + 1);
1029 maxwrk = f2cmax(i__1,i__2);
1032 i__1 = maxwrk, i__2 = *n * (ilaenv_(&c__1, "CUNGQR", " ", n, &
1033 c__1, n, &c_n1, (ftnlen)6, (ftnlen)1) + 1);
1034 maxwrk = f2cmax(i__1,i__2);
1039 i__1 = lwrk, i__2 = *n * *n / 2;
1040 lwrk = f2cmax(i__1,i__2);
1047 work[1].r = (real) lwrk, work[1].i = 0.f;
1048 if (wantsn || *n == 0) {
1055 if (*lwork < minwrk && ! lquery) {
1057 } else if (*liwork < liwmin && ! lquery) {
1064 xerbla_("CGGESX", &i__1, (ftnlen)6);
1066 } else if (lquery) {
1070 /* Quick return if possible */
1077 /* Get machine constants */
1080 smlnum = slamch_("S");
1081 bignum = 1.f / smlnum;
1082 slabad_(&smlnum, &bignum);
1083 smlnum = sqrt(smlnum) / eps;
1084 bignum = 1.f / smlnum;
1086 /* Scale A if f2cmax element outside range [SMLNUM,BIGNUM] */
1088 anrm = clange_("M", n, n, &a[a_offset], lda, &rwork[1]);
1090 if (anrm > 0.f && anrm < smlnum) {
1093 } else if (anrm > bignum) {
1098 clascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
1102 /* Scale B if f2cmax element outside range [SMLNUM,BIGNUM] */
1104 bnrm = clange_("M", n, n, &b[b_offset], ldb, &rwork[1]);
1106 if (bnrm > 0.f && bnrm < smlnum) {
1109 } else if (bnrm > bignum) {
1114 clascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
1118 /* Permute the matrix to make it more nearly triangular */
1119 /* (Real Workspace: need 6*N) */
1123 irwrk = iright + *n;
1124 cggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &rwork[
1125 ileft], &rwork[iright], &rwork[irwrk], &ierr);
1127 /* Reduce B to triangular form (QR decomposition of B) */
1128 /* (Complex Workspace: need N, prefer N*NB) */
1130 irows = ihi + 1 - ilo;
1131 icols = *n + 1 - ilo;
1133 iwrk = itau + irows;
1134 i__1 = *lwork + 1 - iwrk;
1135 cgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
1136 iwrk], &i__1, &ierr);
1138 /* Apply the unitary transformation to matrix A */
1139 /* (Complex Workspace: need N, prefer N*NB) */
1141 i__1 = *lwork + 1 - iwrk;
1142 cunmqr_("L", "C", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
1143 work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, &
1146 /* Initialize VSL */
1147 /* (Complex Workspace: need N, prefer N*NB) */
1150 claset_("Full", n, n, &c_b1, &c_b2, &vsl[vsl_offset], ldvsl);
1154 clacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vsl[
1155 ilo + 1 + ilo * vsl_dim1], ldvsl);
1157 i__1 = *lwork + 1 - iwrk;
1158 cungqr_(&irows, &irows, &irows, &vsl[ilo + ilo * vsl_dim1], ldvsl, &
1159 work[itau], &work[iwrk], &i__1, &ierr);
1162 /* Initialize VSR */
1165 claset_("Full", n, n, &c_b1, &c_b2, &vsr[vsr_offset], ldvsr);
1168 /* Reduce to generalized Hessenberg form */
1169 /* (Workspace: none needed) */
1171 cgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
1172 ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &ierr);
1176 /* Perform QZ algorithm, computing Schur vectors if desired */
1177 /* (Complex Workspace: need N) */
1178 /* (Real Workspace: need N) */
1181 i__1 = *lwork + 1 - iwrk;
1182 chgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[
1183 b_offset], ldb, &alpha[1], &beta[1], &vsl[vsl_offset], ldvsl, &
1184 vsr[vsr_offset], ldvsr, &work[iwrk], &i__1, &rwork[irwrk], &ierr);
1186 if (ierr > 0 && ierr <= *n) {
1188 } else if (ierr > *n && ierr <= *n << 1) {
1196 /* Sort eigenvalues ALPHA/BETA and compute the reciprocal of */
1197 /* condition number(s) */
1201 /* Undo scaling on eigenvalues before SELCTGing */
1204 clascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alpha[1], n,
1208 clascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n,
1212 /* Select eigenvalues */
1215 for (i__ = 1; i__ <= i__1; ++i__) {
1216 bwork[i__] = (*selctg)(&alpha[i__], &beta[i__]);
1220 /* Reorder eigenvalues, transform Generalized Schur vectors, and */
1221 /* compute reciprocal condition numbers */
1222 /* (Complex Workspace: If IJOB >= 1, need MAX(1, 2*SDIM*(N-SDIM)) */
1223 /* otherwise, need 1 ) */
1225 i__1 = *lwork - iwrk + 1;
1226 ctgsen_(&ijob, &ilvsl, &ilvsr, &bwork[1], n, &a[a_offset], lda, &b[
1227 b_offset], ldb, &alpha[1], &beta[1], &vsl[vsl_offset], ldvsl,
1228 &vsr[vsr_offset], ldvsr, sdim, &pl, &pr, dif, &work[iwrk], &
1229 i__1, &iwork[1], liwork, &ierr);
1233 i__1 = maxwrk, i__2 = (*sdim << 1) * (*n - *sdim);
1234 maxwrk = f2cmax(i__1,i__2);
1238 /* not enough complex workspace */
1242 if (ijob == 1 || ijob == 4) {
1246 if (ijob == 2 || ijob == 4) {
1257 /* Apply permutation to VSL and VSR */
1258 /* (Workspace: none needed) */
1261 cggbak_("P", "L", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, &
1262 vsl[vsl_offset], ldvsl, &ierr);
1266 cggbak_("P", "R", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, &
1267 vsr[vsr_offset], ldvsr, &ierr);
1273 clascl_("U", &c__0, &c__0, &anrmto, &anrm, n, n, &a[a_offset], lda, &
1275 clascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alpha[1], n, &
1280 clascl_("U", &c__0, &c__0, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, &
1282 clascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
1288 /* Check if reordering is correct */
1293 for (i__ = 1; i__ <= i__1; ++i__) {
1294 cursl = (*selctg)(&alpha[i__], &beta[i__]);
1298 if (cursl && ! lastsl) {
1309 work[1].r = (real) maxwrk, work[1].i = 0.f;