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 doublecomplex c_b1 = {0.,0.};
516 static doublecomplex c_b2 = {1.,0.};
517 static integer c__1 = 1;
518 static integer c__0 = 0;
519 static integer c_n1 = -1;
521 /* > \brief <b> ZGGESX 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 ZGGESX + dependencies */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zggesx.
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zggesx.
537 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zggesx.
545 /* SUBROUTINE ZGGESX( 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 /* DOUBLE PRECISION RCONDE( 2 ), RCONDV( 2 ), RWORK( * ) */
556 /* COMPLEX*16 A( LDA, * ), ALPHA( * ), B( LDB, * ), */
557 /* $ BETA( * ), VSL( LDVSL, * ), VSR( LDVSR, * ), */
560 /* EXTERNAL SELCTG */
563 /* > \par Purpose: */
568 /* > ZGGESX 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*16 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*16 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*16 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*16 array, dimension (N) */
695 /* > \param[out] BETA */
697 /* > BETA is COMPLEX*16 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*16 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*16 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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*16 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 DOUBLE PRECISION 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 IWORK. */
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 ZHGEQZ */
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 ZTGSEN. */
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 complex16GEeigen */
845 /* ===================================================================== */
846 /* Subroutine */ int zggesx_(char *jobvsl, char *jobvsr, char *sort, L_fp
847 selctg, char *sense, integer *n, doublecomplex *a, integer *lda,
848 doublecomplex *b, integer *ldb, integer *sdim, doublecomplex *alpha,
849 doublecomplex *beta, doublecomplex *vsl, integer *ldvsl,
850 doublecomplex *vsr, integer *ldvsr, doublereal *rconde, doublereal *
851 rcondv, doublecomplex *work, integer *lwork, doublereal *rwork,
852 integer *iwork, integer *liwork, logical *bwork, integer *info)
854 /* System generated locals */
855 integer a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset,
856 vsr_dim1, vsr_offset, i__1, i__2;
858 /* Local variables */
860 doublereal anrm, bnrm;
861 integer ierr, itau, iwrk, lwrk, i__;
862 extern logical lsame_(char *, char *);
863 integer ileft, icols;
864 logical cursl, ilvsl, ilvsr;
865 integer irwrk, irows;
866 extern /* Subroutine */ int dlabad_(doublereal *, doublereal *);
867 extern doublereal dlamch_(char *);
869 extern /* Subroutine */ int zggbak_(char *, char *, integer *, integer *,
870 integer *, doublereal *, doublereal *, integer *, doublecomplex *,
871 integer *, integer *), zggbal_(char *, integer *,
872 doublecomplex *, integer *, doublecomplex *, integer *, integer *
873 , integer *, doublereal *, doublereal *, doublereal *, integer *);
874 logical ilascl, ilbscl;
875 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
876 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
877 integer *, integer *, ftnlen, ftnlen);
878 extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
879 integer *, doublereal *);
881 integer ijobvl, iright;
882 extern /* Subroutine */ int zgghrd_(char *, char *, integer *, integer *,
883 integer *, doublecomplex *, integer *, doublecomplex *, integer *,
884 doublecomplex *, integer *, doublecomplex *, integer *, integer *
885 ), zlascl_(char *, integer *, integer *,
886 doublereal *, doublereal *, integer *, integer *, doublecomplex *,
887 integer *, integer *);
891 logical wantse, lastsl;
892 doublereal anrmto, bnrmto;
893 extern /* Subroutine */ int zgeqrf_(integer *, integer *, doublecomplex *,
894 integer *, doublecomplex *, doublecomplex *, integer *, integer *
900 extern /* Subroutine */ int zhgeqz_(char *, char *, char *, integer *,
901 integer *, integer *, doublecomplex *, integer *, doublecomplex *,
902 integer *, doublecomplex *, doublecomplex *, doublecomplex *,
903 integer *, doublecomplex *, integer *, doublecomplex *, integer *,
904 doublereal *, integer *), zlacpy_(char *,
905 integer *, integer *, doublecomplex *, integer *, doublecomplex *
906 , integer *), zlaset_(char *, integer *, integer *,
907 doublecomplex *, doublecomplex *, doublecomplex *, integer *);
908 logical wantst, lquery, wantsv;
909 extern /* Subroutine */ int ztgsen_(integer *, logical *, logical *,
910 logical *, integer *, doublecomplex *, integer *, doublecomplex *,
911 integer *, doublecomplex *, doublecomplex *, doublecomplex *,
912 integer *, doublecomplex *, integer *, integer *, doublereal *,
913 doublereal *, doublereal *, doublecomplex *, integer *, integer *,
914 integer *, integer *), zungqr_(integer *, integer *, integer *,
915 doublecomplex *, integer *, doublecomplex *, doublecomplex *,
916 integer *, integer *), zunmqr_(char *, char *, integer *, integer
917 *, integer *, doublecomplex *, integer *, doublecomplex *,
918 doublecomplex *, integer *, doublecomplex *, integer *, integer *);
924 /* -- LAPACK driver routine (version 3.7.1) -- */
925 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
926 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
930 /* ===================================================================== */
933 /* Decode the input arguments */
935 /* Parameter adjustments */
937 a_offset = 1 + a_dim1 * 1;
940 b_offset = 1 + b_dim1 * 1;
945 vsl_offset = 1 + vsl_dim1 * 1;
948 vsr_offset = 1 + vsr_dim1 * 1;
958 if (lsame_(jobvsl, "N")) {
961 } else if (lsame_(jobvsl, "V")) {
969 if (lsame_(jobvsr, "N")) {
972 } else if (lsame_(jobvsr, "V")) {
980 wantst = lsame_(sort, "S");
981 wantsn = lsame_(sense, "N");
982 wantse = lsame_(sense, "E");
983 wantsv = lsame_(sense, "V");
984 wantsb = lsame_(sense, "B");
985 lquery = *lwork == -1 || *liwork == -1;
996 /* Test the input arguments */
1001 } else if (ijobvr <= 0) {
1003 } else if (! wantst && ! lsame_(sort, "N")) {
1005 } else if (! (wantsn || wantse || wantsv || wantsb) || ! wantst && !
1008 } else if (*n < 0) {
1010 } else if (*lda < f2cmax(1,*n)) {
1012 } else if (*ldb < f2cmax(1,*n)) {
1014 } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) {
1016 } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) {
1020 /* Compute workspace */
1021 /* (Note: Comments in the code beginning "Workspace:" describe the */
1022 /* minimal amount of workspace needed at that point in the code, */
1023 /* as well as the preferred amount for good performance. */
1024 /* NB refers to the optimal block size for the immediately */
1025 /* following subroutine, as returned by ILAENV.) */
1030 maxwrk = *n * (ilaenv_(&c__1, "ZGEQRF", " ", n, &c__1, n, &c__0, (
1031 ftnlen)6, (ftnlen)1) + 1);
1033 i__1 = maxwrk, i__2 = *n * (ilaenv_(&c__1, "ZUNMQR", " ", n, &
1034 c__1, n, &c_n1, (ftnlen)6, (ftnlen)1) + 1);
1035 maxwrk = f2cmax(i__1,i__2);
1038 i__1 = maxwrk, i__2 = *n * (ilaenv_(&c__1, "ZUNGQR", " ", n, &
1039 c__1, n, &c_n1, (ftnlen)6, (ftnlen)1) + 1);
1040 maxwrk = f2cmax(i__1,i__2);
1045 i__1 = lwrk, i__2 = *n * *n / 2;
1046 lwrk = f2cmax(i__1,i__2);
1053 work[1].r = (doublereal) lwrk, work[1].i = 0.;
1054 if (wantsn || *n == 0) {
1061 if (*lwork < minwrk && ! lquery) {
1063 } else if (*liwork < liwmin && ! lquery) {
1070 xerbla_("ZGGESX", &i__1, (ftnlen)6);
1072 } else if (lquery) {
1076 /* Quick return if possible */
1083 /* Get machine constants */
1086 smlnum = dlamch_("S");
1087 bignum = 1. / smlnum;
1088 dlabad_(&smlnum, &bignum);
1089 smlnum = sqrt(smlnum) / eps;
1090 bignum = 1. / smlnum;
1092 /* Scale A if f2cmax element outside range [SMLNUM,BIGNUM] */
1094 anrm = zlange_("M", n, n, &a[a_offset], lda, &rwork[1]);
1096 if (anrm > 0. && anrm < smlnum) {
1099 } else if (anrm > bignum) {
1104 zlascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
1108 /* Scale B if f2cmax element outside range [SMLNUM,BIGNUM] */
1110 bnrm = zlange_("M", n, n, &b[b_offset], ldb, &rwork[1]);
1112 if (bnrm > 0. && bnrm < smlnum) {
1115 } else if (bnrm > bignum) {
1120 zlascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
1124 /* Permute the matrix to make it more nearly triangular */
1125 /* (Real Workspace: need 6*N) */
1129 irwrk = iright + *n;
1130 zggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &rwork[
1131 ileft], &rwork[iright], &rwork[irwrk], &ierr);
1133 /* Reduce B to triangular form (QR decomposition of B) */
1134 /* (Complex Workspace: need N, prefer N*NB) */
1136 irows = ihi + 1 - ilo;
1137 icols = *n + 1 - ilo;
1139 iwrk = itau + irows;
1140 i__1 = *lwork + 1 - iwrk;
1141 zgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
1142 iwrk], &i__1, &ierr);
1144 /* Apply the unitary transformation to matrix A */
1145 /* (Complex Workspace: need N, prefer N*NB) */
1147 i__1 = *lwork + 1 - iwrk;
1148 zunmqr_("L", "C", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
1149 work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, &
1152 /* Initialize VSL */
1153 /* (Complex Workspace: need N, prefer N*NB) */
1156 zlaset_("Full", n, n, &c_b1, &c_b2, &vsl[vsl_offset], ldvsl);
1160 zlacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vsl[
1161 ilo + 1 + ilo * vsl_dim1], ldvsl);
1163 i__1 = *lwork + 1 - iwrk;
1164 zungqr_(&irows, &irows, &irows, &vsl[ilo + ilo * vsl_dim1], ldvsl, &
1165 work[itau], &work[iwrk], &i__1, &ierr);
1168 /* Initialize VSR */
1171 zlaset_("Full", n, n, &c_b1, &c_b2, &vsr[vsr_offset], ldvsr);
1174 /* Reduce to generalized Hessenberg form */
1175 /* (Workspace: none needed) */
1177 zgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
1178 ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &ierr);
1182 /* Perform QZ algorithm, computing Schur vectors if desired */
1183 /* (Complex Workspace: need N) */
1184 /* (Real Workspace: need N) */
1187 i__1 = *lwork + 1 - iwrk;
1188 zhgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[
1189 b_offset], ldb, &alpha[1], &beta[1], &vsl[vsl_offset], ldvsl, &
1190 vsr[vsr_offset], ldvsr, &work[iwrk], &i__1, &rwork[irwrk], &ierr);
1192 if (ierr > 0 && ierr <= *n) {
1194 } else if (ierr > *n && ierr <= *n << 1) {
1202 /* Sort eigenvalues ALPHA/BETA and compute the reciprocal of */
1203 /* condition number(s) */
1207 /* Undo scaling on eigenvalues before SELCTGing */
1210 zlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alpha[1], n,
1214 zlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n,
1218 /* Select eigenvalues */
1221 for (i__ = 1; i__ <= i__1; ++i__) {
1222 bwork[i__] = (*selctg)(&alpha[i__], &beta[i__]);
1226 /* Reorder eigenvalues, transform Generalized Schur vectors, and */
1227 /* compute reciprocal condition numbers */
1228 /* (Complex Workspace: If IJOB >= 1, need MAX(1, 2*SDIM*(N-SDIM)) */
1229 /* otherwise, need 1 ) */
1231 i__1 = *lwork - iwrk + 1;
1232 ztgsen_(&ijob, &ilvsl, &ilvsr, &bwork[1], n, &a[a_offset], lda, &b[
1233 b_offset], ldb, &alpha[1], &beta[1], &vsl[vsl_offset], ldvsl,
1234 &vsr[vsr_offset], ldvsr, sdim, &pl, &pr, dif, &work[iwrk], &
1235 i__1, &iwork[1], liwork, &ierr);
1239 i__1 = maxwrk, i__2 = (*sdim << 1) * (*n - *sdim);
1240 maxwrk = f2cmax(i__1,i__2);
1244 /* not enough complex workspace */
1248 if (ijob == 1 || ijob == 4) {
1252 if (ijob == 2 || ijob == 4) {
1263 /* Apply permutation to VSL and VSR */
1264 /* (Workspace: none needed) */
1267 zggbak_("P", "L", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, &
1268 vsl[vsl_offset], ldvsl, &ierr);
1272 zggbak_("P", "R", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, &
1273 vsr[vsr_offset], ldvsr, &ierr);
1279 zlascl_("U", &c__0, &c__0, &anrmto, &anrm, n, n, &a[a_offset], lda, &
1281 zlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alpha[1], n, &
1286 zlascl_("U", &c__0, &c__0, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, &
1288 zlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
1294 /* Check if reordering is correct */
1299 for (i__ = 1; i__ <= i__1; ++i__) {
1300 cursl = (*selctg)(&alpha[i__], &beta[i__]);
1304 if (cursl && ! lastsl) {
1315 work[1].r = (doublereal) maxwrk, work[1].i = 0.;