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 logical c_true = TRUE_;
516 static integer c__2 = 2;
517 static real c_b34 = 1.f;
518 static integer c__1 = 1;
519 static real c_b36 = 0.f;
520 static logical c_false = FALSE_;
522 /* > \brief \b STGEVC */
524 /* =========== DOCUMENTATION =========== */
526 /* Online html documentation available at */
527 /* http://www.netlib.org/lapack/explore-html/ */
530 /* > Download STGEVC + dependencies */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/stgevc.
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/stgevc.
537 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/stgevc.
545 /* SUBROUTINE STGEVC( SIDE, HOWMNY, SELECT, N, S, LDS, P, LDP, VL, */
546 /* LDVL, VR, LDVR, MM, M, WORK, INFO ) */
548 /* CHARACTER HOWMNY, SIDE */
549 /* INTEGER INFO, LDP, LDS, LDVL, LDVR, M, MM, N */
550 /* LOGICAL SELECT( * ) */
551 /* REAL P( LDP, * ), S( LDS, * ), VL( LDVL, * ), */
552 /* $ VR( LDVR, * ), WORK( * ) */
556 /* > \par Purpose: */
561 /* > STGEVC computes some or all of the right and/or left eigenvectors of */
562 /* > a pair of real matrices (S,P), where S is a quasi-triangular matrix */
563 /* > and P is upper triangular. Matrix pairs of this type are produced by */
564 /* > the generalized Schur factorization of a matrix pair (A,B): */
566 /* > A = Q*S*Z**T, B = Q*P*Z**T */
568 /* > as computed by SGGHRD + SHGEQZ. */
570 /* > The right eigenvector x and the left eigenvector y of (S,P) */
571 /* > corresponding to an eigenvalue w are defined by: */
573 /* > S*x = w*P*x, (y**H)*S = w*(y**H)*P, */
575 /* > where y**H denotes the conjugate tranpose of y. */
576 /* > The eigenvalues are not input to this routine, but are computed */
577 /* > directly from the diagonal blocks of S and P. */
579 /* > This routine returns the matrices X and/or Y of right and left */
580 /* > eigenvectors of (S,P), or the products Z*X and/or Q*Y, */
581 /* > where Z and Q are input matrices. */
582 /* > If Q and Z are the orthogonal factors from the generalized Schur */
583 /* > factorization of a matrix pair (A,B), then Z*X and Q*Y */
584 /* > are the matrices of right and left eigenvectors of (A,B). */
591 /* > \param[in] SIDE */
593 /* > SIDE is CHARACTER*1 */
594 /* > = 'R': compute right eigenvectors only; */
595 /* > = 'L': compute left eigenvectors only; */
596 /* > = 'B': compute both right and left eigenvectors. */
599 /* > \param[in] HOWMNY */
601 /* > HOWMNY is CHARACTER*1 */
602 /* > = 'A': compute all right and/or left eigenvectors; */
603 /* > = 'B': compute all right and/or left eigenvectors, */
604 /* > backtransformed by the matrices in VR and/or VL; */
605 /* > = 'S': compute selected right and/or left eigenvectors, */
606 /* > specified by the logical array SELECT. */
609 /* > \param[in] SELECT */
611 /* > SELECT is LOGICAL array, dimension (N) */
612 /* > If HOWMNY='S', SELECT specifies the eigenvectors to be */
613 /* > computed. If w(j) is a real eigenvalue, the corresponding */
614 /* > real eigenvector is computed if SELECT(j) is .TRUE.. */
615 /* > If w(j) and w(j+1) are the real and imaginary parts of a */
616 /* > complex eigenvalue, the corresponding complex eigenvector */
617 /* > is computed if either SELECT(j) or SELECT(j+1) is .TRUE., */
618 /* > and on exit SELECT(j) is set to .TRUE. and SELECT(j+1) is */
619 /* > set to .FALSE.. */
620 /* > Not referenced if HOWMNY = 'A' or 'B'. */
626 /* > The order of the matrices S and P. N >= 0. */
631 /* > S is REAL array, dimension (LDS,N) */
632 /* > The upper quasi-triangular matrix S from a generalized Schur */
633 /* > factorization, as computed by SHGEQZ. */
636 /* > \param[in] LDS */
638 /* > LDS is INTEGER */
639 /* > The leading dimension of array S. LDS >= f2cmax(1,N). */
644 /* > P is REAL array, dimension (LDP,N) */
645 /* > The upper triangular matrix P from a generalized Schur */
646 /* > factorization, as computed by SHGEQZ. */
647 /* > 2-by-2 diagonal blocks of P corresponding to 2-by-2 blocks */
648 /* > of S must be in positive diagonal form. */
651 /* > \param[in] LDP */
653 /* > LDP is INTEGER */
654 /* > The leading dimension of array P. LDP >= f2cmax(1,N). */
657 /* > \param[in,out] VL */
659 /* > VL is REAL array, dimension (LDVL,MM) */
660 /* > On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must */
661 /* > contain an N-by-N matrix Q (usually the orthogonal matrix Q */
662 /* > of left Schur vectors returned by SHGEQZ). */
663 /* > On exit, if SIDE = 'L' or 'B', VL contains: */
664 /* > if HOWMNY = 'A', the matrix Y of left eigenvectors of (S,P); */
665 /* > if HOWMNY = 'B', the matrix Q*Y; */
666 /* > if HOWMNY = 'S', the left eigenvectors of (S,P) specified by */
667 /* > SELECT, stored consecutively in the columns of */
668 /* > VL, in the same order as their eigenvalues. */
670 /* > A complex eigenvector corresponding to a complex eigenvalue */
671 /* > is stored in two consecutive columns, the first holding the */
672 /* > real part, and the second the imaginary part. */
674 /* > Not referenced if SIDE = 'R'. */
677 /* > \param[in] LDVL */
679 /* > LDVL is INTEGER */
680 /* > The leading dimension of array VL. LDVL >= 1, and if */
681 /* > SIDE = 'L' or 'B', LDVL >= N. */
684 /* > \param[in,out] VR */
686 /* > VR is REAL array, dimension (LDVR,MM) */
687 /* > On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must */
688 /* > contain an N-by-N matrix Z (usually the orthogonal matrix Z */
689 /* > of right Schur vectors returned by SHGEQZ). */
691 /* > On exit, if SIDE = 'R' or 'B', VR contains: */
692 /* > if HOWMNY = 'A', the matrix X of right eigenvectors of (S,P); */
693 /* > if HOWMNY = 'B' or 'b', the matrix Z*X; */
694 /* > if HOWMNY = 'S' or 's', the right eigenvectors of (S,P) */
695 /* > specified by SELECT, stored consecutively in the */
696 /* > columns of VR, in the same order as their */
699 /* > A complex eigenvector corresponding to a complex eigenvalue */
700 /* > is stored in two consecutive columns, the first holding the */
701 /* > real part and the second the imaginary part. */
703 /* > Not referenced if SIDE = 'L'. */
706 /* > \param[in] LDVR */
708 /* > LDVR is INTEGER */
709 /* > The leading dimension of the array VR. LDVR >= 1, and if */
710 /* > SIDE = 'R' or 'B', LDVR >= N. */
713 /* > \param[in] MM */
715 /* > MM is INTEGER */
716 /* > The number of columns in the arrays VL and/or VR. MM >= M. */
719 /* > \param[out] M */
722 /* > The number of columns in the arrays VL and/or VR actually */
723 /* > used to store the eigenvectors. If HOWMNY = 'A' or 'B', M */
724 /* > is set to N. Each selected real eigenvector occupies one */
725 /* > column and each selected complex eigenvector occupies two */
729 /* > \param[out] WORK */
731 /* > WORK is REAL array, dimension (6*N) */
734 /* > \param[out] INFO */
736 /* > INFO is INTEGER */
737 /* > = 0: successful exit. */
738 /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
739 /* > > 0: the 2-by-2 block (INFO:INFO+1) does not have a complex */
746 /* > \author Univ. of Tennessee */
747 /* > \author Univ. of California Berkeley */
748 /* > \author Univ. of Colorado Denver */
749 /* > \author NAG Ltd. */
751 /* > \date December 2016 */
753 /* > \ingroup realGEcomputational */
755 /* > \par Further Details: */
756 /* ===================== */
760 /* > Allocation of workspace: */
761 /* > ---------- -- --------- */
763 /* > WORK( j ) = 1-norm of j-th column of A, above the diagonal */
764 /* > WORK( N+j ) = 1-norm of j-th column of B, above the diagonal */
765 /* > WORK( 2*N+1:3*N ) = real part of eigenvector */
766 /* > WORK( 3*N+1:4*N ) = imaginary part of eigenvector */
767 /* > WORK( 4*N+1:5*N ) = real part of back-transformed eigenvector */
768 /* > WORK( 5*N+1:6*N ) = imaginary part of back-transformed eigenvector */
770 /* > Rowwise vs. columnwise solution methods: */
771 /* > ------- -- ---------- -------- ------- */
773 /* > Finding a generalized eigenvector consists basically of solving the */
774 /* > singular triangular system */
776 /* > (A - w B) x = 0 (for right) or: (A - w B)**H y = 0 (for left) */
778 /* > Consider finding the i-th right eigenvector (assume all eigenvalues */
779 /* > are real). The equation to be solved is: */
781 /* > 0 = sum C(j,k) v(k) = sum C(j,k) v(k) for j = i,. . .,1 */
784 /* > where C = (A - w B) (The components v(i+1:n) are 0.) */
786 /* > The "rowwise" method is: */
788 /* > (1) v(i) := 1 */
789 /* > for j = i-1,. . .,1: */
791 /* > (2) compute s = - sum C(j,k) v(k) and */
794 /* > (3) v(j) := s / C(j,j) */
796 /* > Step 2 is sometimes called the "dot product" step, since it is an */
797 /* > inner product between the j-th row and the portion of the eigenvector */
798 /* > that has been computed so far. */
800 /* > The "columnwise" method consists basically in doing the sums */
801 /* > for all the rows in parallel. As each v(j) is computed, the */
802 /* > contribution of v(j) times the j-th column of C is added to the */
803 /* > partial sums. Since FORTRAN arrays are stored columnwise, this has */
804 /* > the advantage that at each step, the elements of C that are accessed */
805 /* > are adjacent to one another, whereas with the rowwise method, the */
806 /* > elements accessed at a step are spaced LDS (and LDP) words apart. */
808 /* > When finding left eigenvectors, the matrix in question is the */
809 /* > transpose of the one in storage, so the rowwise method then */
810 /* > actually accesses columns of A and B at each step, and so is the */
811 /* > preferred method. */
814 /* ===================================================================== */
815 /* Subroutine */ int stgevc_(char *side, char *howmny, logical *select,
816 integer *n, real *s, integer *lds, real *p, integer *ldp, real *vl,
817 integer *ldvl, real *vr, integer *ldvr, integer *mm, integer *m, real
818 *work, integer *info)
820 /* System generated locals */
821 integer p_dim1, p_offset, s_dim1, s_offset, vl_dim1, vl_offset, vr_dim1,
822 vr_offset, i__1, i__2, i__3, i__4, i__5;
823 real r__1, r__2, r__3, r__4, r__5, r__6;
825 /* Local variables */
826 integer ibeg, ieig, iend;
827 real dmin__, temp, xmax, sump[4] /* was [2][2] */, sums[4] /*
828 was [2][2] */, cim2a, cim2b, cre2a, cre2b;
829 extern /* Subroutine */ int slag2_(real *, integer *, real *, integer *,
830 real *, real *, real *, real *, real *, real *);
831 real temp2, bdiag[2];
837 extern logical lsame_(char *, char *);
844 extern /* Subroutine */ int sgemv_(char *, integer *, integer *, real *,
845 real *, integer *, real *, integer *, real *, real *, integer *), slaln2_(logical *, integer *, integer *, real *, real *,
846 real *, integer *, real *, real *, real *, integer *, real *,
847 real *, real *, integer *, real *, real *, integer *);
850 logical ilabad, ilbbad;
852 real acoefa, bcoefa, cimaga, cimagb;
855 real bcoefi, ascale, bscale, creala;
858 extern /* Subroutine */ int slabad_(real *, real *);
861 extern real slamch_(char *);
863 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
865 logical ilcomp, ilcplx;
866 extern /* Subroutine */ int slacpy_(char *, integer *, integer *, real *,
867 integer *, real *, integer *);
871 real ulp, sum[4] /* was [2][2] */;
874 /* -- LAPACK computational routine (version 3.7.0) -- */
875 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
876 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
881 /* ===================================================================== */
884 /* Decode and Test the input parameters */
886 /* Parameter adjustments */
889 s_offset = 1 + s_dim1 * 1;
892 p_offset = 1 + p_dim1 * 1;
895 vl_offset = 1 + vl_dim1 * 1;
898 vr_offset = 1 + vr_dim1 * 1;
903 if (lsame_(howmny, "A")) {
907 } else if (lsame_(howmny, "S")) {
911 } else if (lsame_(howmny, "B")) {
920 if (lsame_(side, "R")) {
924 } else if (lsame_(side, "L")) {
928 } else if (lsame_(side, "B")) {
939 } else if (ihwmny < 0) {
943 } else if (*lds < f2cmax(1,*n)) {
945 } else if (*ldp < f2cmax(1,*n)) {
950 xerbla_("STGEVC", &i__1, (ftnlen)6);
954 /* Count the number of eigenvectors to be computed */
960 for (j = 1; j <= i__1; ++j) {
966 if (s[j + 1 + j * s_dim1] != 0.f) {
971 if (select[j] || select[j + 1]) {
986 /* Check 2-by-2 diagonal blocks of A, B */
991 for (j = 1; j <= i__1; ++j) {
992 if (s[j + 1 + j * s_dim1] != 0.f) {
993 if (p[j + j * p_dim1] == 0.f || p[j + 1 + (j + 1) * p_dim1] ==
994 0.f || p[j + (j + 1) * p_dim1] != 0.f) {
998 if (s[j + 2 + (j + 1) * s_dim1] != 0.f) {
1008 } else if (ilbbad) {
1010 } else if (compl && *ldvl < *n || *ldvl < 1) {
1012 } else if (compr && *ldvr < *n || *ldvr < 1) {
1014 } else if (*mm < im) {
1019 xerbla_("STGEVC", &i__1, (ftnlen)6);
1023 /* Quick return if possible */
1030 /* Machine Constants */
1032 safmin = slamch_("Safe minimum");
1034 slabad_(&safmin, &big);
1035 ulp = slamch_("Epsilon") * slamch_("Base");
1036 small = safmin * *n / ulp;
1038 bignum = 1.f / (safmin * *n);
1040 /* Compute the 1-norm of each column of the strictly upper triangular */
1041 /* part (i.e., excluding all elements belonging to the diagonal */
1042 /* blocks) of A and B to check for possible overflow in the */
1043 /* triangular solver. */
1045 anorm = (r__1 = s[s_dim1 + 1], abs(r__1));
1047 anorm += (r__1 = s[s_dim1 + 2], abs(r__1));
1049 bnorm = (r__1 = p[p_dim1 + 1], abs(r__1));
1054 for (j = 2; j <= i__1; ++j) {
1057 if (s[j + (j - 1) * s_dim1] == 0.f) {
1063 for (i__ = 1; i__ <= i__2; ++i__) {
1064 temp += (r__1 = s[i__ + j * s_dim1], abs(r__1));
1065 temp2 += (r__1 = p[i__ + j * p_dim1], abs(r__1));
1069 work[*n + j] = temp2;
1072 i__2 = f2cmin(i__3,*n);
1073 for (i__ = iend + 1; i__ <= i__2; ++i__) {
1074 temp += (r__1 = s[i__ + j * s_dim1], abs(r__1));
1075 temp2 += (r__1 = p[i__ + j * p_dim1], abs(r__1));
1078 anorm = f2cmax(anorm,temp);
1079 bnorm = f2cmax(bnorm,temp2);
1083 ascale = 1.f / f2cmax(anorm,safmin);
1084 bscale = 1.f / f2cmax(bnorm,safmin);
1086 /* Left eigenvectors */
1091 /* Main loop over eigenvalues */
1095 for (je = 1; je <= i__1; ++je) {
1097 /* Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or */
1098 /* (b) this would be the second of a complex pair. */
1099 /* Check for complex eigenvalue, so as to be sure of which */
1100 /* entry(-ies) of SELECT to look at. */
1108 if (s[je + 1 + je * s_dim1] != 0.f) {
1115 } else if (ilcplx) {
1116 ilcomp = select[je] || select[je + 1];
1118 ilcomp = select[je];
1124 /* Decide if (a) singular pencil, (b) real eigenvalue, or */
1125 /* (c) complex eigenvalue. */
1128 if ((r__1 = s[je + je * s_dim1], abs(r__1)) <= safmin && (
1129 r__2 = p[je + je * p_dim1], abs(r__2)) <= safmin) {
1131 /* Singular matrix pencil -- return unit eigenvector */
1135 for (jr = 1; jr <= i__2; ++jr) {
1136 vl[jr + ieig * vl_dim1] = 0.f;
1139 vl[ieig + ieig * vl_dim1] = 1.f;
1147 for (jr = 1; jr <= i__2; ++jr) {
1148 work[(*n << 1) + jr] = 0.f;
1152 /* Compute coefficients in ( a A - b B ) y = 0 */
1154 /* b is BCOEFR + i*BCOEFI */
1158 /* Real eigenvalue */
1161 r__3 = (r__1 = s[je + je * s_dim1], abs(r__1)) * ascale, r__4
1162 = (r__2 = p[je + je * p_dim1], abs(r__2)) * bscale,
1163 r__3 = f2cmax(r__3,r__4);
1164 temp = 1.f / f2cmax(r__3,safmin);
1165 salfar = temp * s[je + je * s_dim1] * ascale;
1166 sbeta = temp * p[je + je * p_dim1] * bscale;
1167 acoef = sbeta * ascale;
1168 bcoefr = salfar * bscale;
1171 /* Scale to avoid underflow */
1174 lsa = abs(sbeta) >= safmin && abs(acoef) < small;
1175 lsb = abs(salfar) >= safmin && abs(bcoefr) < small;
1177 scale = small / abs(sbeta) * f2cmin(anorm,big);
1181 r__1 = scale, r__2 = small / abs(salfar) * f2cmin(bnorm,big);
1182 scale = f2cmax(r__1,r__2);
1187 r__3 = 1.f, r__4 = abs(acoef), r__3 = f2cmax(r__3,r__4),
1189 r__1 = scale, r__2 = 1.f / (safmin * f2cmax(r__3,r__4));
1190 scale = f2cmin(r__1,r__2);
1192 acoef = ascale * (scale * sbeta);
1194 acoef = scale * acoef;
1197 bcoefr = bscale * (scale * salfar);
1199 bcoefr = scale * bcoefr;
1202 acoefa = abs(acoef);
1203 bcoefa = abs(bcoefr);
1205 /* First component is 1 */
1207 work[(*n << 1) + je] = 1.f;
1211 /* Complex eigenvalue */
1213 r__1 = safmin * 100.f;
1214 slag2_(&s[je + je * s_dim1], lds, &p[je + je * p_dim1], ldp, &
1215 r__1, &acoef, &temp, &bcoefr, &temp2, &bcoefi);
1217 if (bcoefi == 0.f) {
1222 /* Scale to avoid over/underflow */
1224 acoefa = abs(acoef);
1225 bcoefa = abs(bcoefr) + abs(bcoefi);
1227 if (acoefa * ulp < safmin && acoefa >= safmin) {
1228 scale = safmin / ulp / acoefa;
1230 if (bcoefa * ulp < safmin && bcoefa >= safmin) {
1232 r__1 = scale, r__2 = safmin / ulp / bcoefa;
1233 scale = f2cmax(r__1,r__2);
1235 if (safmin * acoefa > ascale) {
1236 scale = ascale / (safmin * acoefa);
1238 if (safmin * bcoefa > bscale) {
1240 r__1 = scale, r__2 = bscale / (safmin * bcoefa);
1241 scale = f2cmin(r__1,r__2);
1244 acoef = scale * acoef;
1245 acoefa = abs(acoef);
1246 bcoefr = scale * bcoefr;
1247 bcoefi = scale * bcoefi;
1248 bcoefa = abs(bcoefr) + abs(bcoefi);
1251 /* Compute first two components of eigenvector */
1253 temp = acoef * s[je + 1 + je * s_dim1];
1254 temp2r = acoef * s[je + je * s_dim1] - bcoefr * p[je + je *
1256 temp2i = -bcoefi * p[je + je * p_dim1];
1257 if (abs(temp) > abs(temp2r) + abs(temp2i)) {
1258 work[(*n << 1) + je] = 1.f;
1259 work[*n * 3 + je] = 0.f;
1260 work[(*n << 1) + je + 1] = -temp2r / temp;
1261 work[*n * 3 + je + 1] = -temp2i / temp;
1263 work[(*n << 1) + je + 1] = 1.f;
1264 work[*n * 3 + je + 1] = 0.f;
1265 temp = acoef * s[je + (je + 1) * s_dim1];
1266 work[(*n << 1) + je] = (bcoefr * p[je + 1 + (je + 1) *
1267 p_dim1] - acoef * s[je + 1 + (je + 1) * s_dim1]) /
1269 work[*n * 3 + je] = bcoefi * p[je + 1 + (je + 1) * p_dim1]
1273 r__5 = (r__1 = work[(*n << 1) + je], abs(r__1)) + (r__2 =
1274 work[*n * 3 + je], abs(r__2)), r__6 = (r__3 = work[(*
1275 n << 1) + je + 1], abs(r__3)) + (r__4 = work[*n * 3 +
1276 je + 1], abs(r__4));
1277 xmax = f2cmax(r__5,r__6);
1281 r__1 = ulp * acoefa * anorm, r__2 = ulp * bcoefa * bnorm, r__1 =
1283 dmin__ = f2cmax(r__1,safmin);
1286 /* Triangular solve of (a A - b B) y = 0 */
1289 /* (rowwise in (a A - b B) , or columnwise in (a A - b B) ) */
1294 for (j = je + nw; j <= i__2; ++j) {
1301 bdiag[0] = p[j + j * p_dim1];
1303 if (s[j + 1 + j * s_dim1] != 0.f) {
1305 bdiag[1] = p[j + 1 + (j + 1) * p_dim1];
1310 /* Check whether scaling is necessary for dot products */
1312 xscale = 1.f / f2cmax(1.f,xmax);
1314 r__1 = work[j], r__2 = work[*n + j], r__1 = f2cmax(r__1,r__2),
1315 r__2 = acoefa * work[j] + bcoefa * work[*n + j];
1316 temp = f2cmax(r__1,r__2);
1319 r__1 = temp, r__2 = work[j + 1], r__1 = f2cmax(r__1,r__2),
1320 r__2 = work[*n + j + 1], r__1 = f2cmax(r__1,r__2),
1321 r__2 = acoefa * work[j + 1] + bcoefa * work[*n +
1323 temp = f2cmax(r__1,r__2);
1325 if (temp > bignum * xscale) {
1327 for (jw = 0; jw <= i__3; ++jw) {
1329 for (jr = je; jr <= i__4; ++jr) {
1330 work[(jw + 2) * *n + jr] = xscale * work[(jw + 2)
1339 /* Compute dot products */
1342 /* SUM = sum conjg( a*S(k,j) - b*P(k,j) )*x(k) */
1345 /* To reduce the op count, this is done as */
1348 /* a*conjg( sum S(k,j)*x(k) ) - b*conjg( sum P(k,j)*x(k) ) */
1351 /* which may cause underflow problems if A or B are close */
1352 /* to underflow. (E.g., less than SMALL.) */
1356 for (jw = 1; jw <= i__3; ++jw) {
1358 for (ja = 1; ja <= i__4; ++ja) {
1359 sums[ja + (jw << 1) - 3] = 0.f;
1360 sump[ja + (jw << 1) - 3] = 0.f;
1363 for (jr = je; jr <= i__5; ++jr) {
1364 sums[ja + (jw << 1) - 3] += s[jr + (j + ja - 1) *
1365 s_dim1] * work[(jw + 1) * *n + jr];
1366 sump[ja + (jw << 1) - 3] += p[jr + (j + ja - 1) *
1367 p_dim1] * work[(jw + 1) * *n + jr];
1376 for (ja = 1; ja <= i__3; ++ja) {
1378 sum[ja - 1] = -acoef * sums[ja - 1] + bcoefr * sump[
1379 ja - 1] - bcoefi * sump[ja + 1];
1380 sum[ja + 1] = -acoef * sums[ja + 1] + bcoefr * sump[
1381 ja + 1] + bcoefi * sump[ja - 1];
1383 sum[ja - 1] = -acoef * sums[ja - 1] + bcoefr * sump[
1390 /* Solve ( a A - b B ) y = SUM(,) */
1391 /* with scaling and perturbation of the denominator */
1393 slaln2_(&c_true, &na, &nw, &dmin__, &acoef, &s[j + j * s_dim1]
1394 , lds, bdiag, &bdiag[1], sum, &c__2, &bcoefr, &bcoefi,
1395 &work[(*n << 1) + j], n, &scale, &temp, &iinfo);
1398 for (jw = 0; jw <= i__3; ++jw) {
1400 for (jr = je; jr <= i__4; ++jr) {
1401 work[(jw + 2) * *n + jr] = scale * work[(jw + 2) *
1407 xmax = scale * xmax;
1409 xmax = f2cmax(xmax,temp);
1414 /* Copy eigenvector to VL, back transforming if */
1420 for (jw = 0; jw <= i__2; ++jw) {
1422 sgemv_("N", n, &i__3, &c_b34, &vl[je * vl_dim1 + 1], ldvl,
1423 &work[(jw + 2) * *n + je], &c__1, &c_b36, &work[(
1424 jw + 4) * *n + 1], &c__1);
1427 slacpy_(" ", n, &nw, &work[(*n << 2) + 1], n, &vl[je *
1428 vl_dim1 + 1], ldvl);
1431 slacpy_(" ", n, &nw, &work[(*n << 1) + 1], n, &vl[ieig *
1432 vl_dim1 + 1], ldvl);
1436 /* Scale eigenvector */
1441 for (j = ibeg; j <= i__2; ++j) {
1443 r__3 = xmax, r__4 = (r__1 = vl[j + ieig * vl_dim1], abs(
1444 r__1)) + (r__2 = vl[j + (ieig + 1) * vl_dim1],
1446 xmax = f2cmax(r__3,r__4);
1451 for (j = ibeg; j <= i__2; ++j) {
1453 r__2 = xmax, r__3 = (r__1 = vl[j + ieig * vl_dim1], abs(
1455 xmax = f2cmax(r__2,r__3);
1460 if (xmax > safmin) {
1461 xscale = 1.f / xmax;
1464 for (jw = 0; jw <= i__2; ++jw) {
1466 for (jr = ibeg; jr <= i__3; ++jr) {
1467 vl[jr + (ieig + jw) * vl_dim1] = xscale * vl[jr + (
1468 ieig + jw) * vl_dim1];
1474 ieig = ieig + nw - 1;
1481 /* Right eigenvectors */
1486 /* Main loop over eigenvalues */
1489 for (je = *n; je >= 1; --je) {
1491 /* Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or */
1492 /* (b) this would be the second of a complex pair. */
1493 /* Check for complex eigenvalue, so as to be sure of which */
1494 /* entry(-ies) of SELECT to look at -- if complex, SELECT(JE) */
1495 /* or SELECT(JE-1). */
1496 /* If this is a complex pair, the 2-by-2 diagonal block */
1497 /* corresponding to the eigenvalue is in rows/columns JE-1:JE */
1505 if (s[je + (je - 1) * s_dim1] != 0.f) {
1512 } else if (ilcplx) {
1513 ilcomp = select[je] || select[je - 1];
1515 ilcomp = select[je];
1521 /* Decide if (a) singular pencil, (b) real eigenvalue, or */
1522 /* (c) complex eigenvalue. */
1525 if ((r__1 = s[je + je * s_dim1], abs(r__1)) <= safmin && (
1526 r__2 = p[je + je * p_dim1], abs(r__2)) <= safmin) {
1528 /* Singular matrix pencil -- unit eigenvector */
1532 for (jr = 1; jr <= i__1; ++jr) {
1533 vr[jr + ieig * vr_dim1] = 0.f;
1536 vr[ieig + ieig * vr_dim1] = 1.f;
1544 for (jw = 0; jw <= i__1; ++jw) {
1546 for (jr = 1; jr <= i__2; ++jr) {
1547 work[(jw + 2) * *n + jr] = 0.f;
1553 /* Compute coefficients in ( a A - b B ) x = 0 */
1555 /* b is BCOEFR + i*BCOEFI */
1559 /* Real eigenvalue */
1562 r__3 = (r__1 = s[je + je * s_dim1], abs(r__1)) * ascale, r__4
1563 = (r__2 = p[je + je * p_dim1], abs(r__2)) * bscale,
1564 r__3 = f2cmax(r__3,r__4);
1565 temp = 1.f / f2cmax(r__3,safmin);
1566 salfar = temp * s[je + je * s_dim1] * ascale;
1567 sbeta = temp * p[je + je * p_dim1] * bscale;
1568 acoef = sbeta * ascale;
1569 bcoefr = salfar * bscale;
1572 /* Scale to avoid underflow */
1575 lsa = abs(sbeta) >= safmin && abs(acoef) < small;
1576 lsb = abs(salfar) >= safmin && abs(bcoefr) < small;
1578 scale = small / abs(sbeta) * f2cmin(anorm,big);
1582 r__1 = scale, r__2 = small / abs(salfar) * f2cmin(bnorm,big);
1583 scale = f2cmax(r__1,r__2);
1588 r__3 = 1.f, r__4 = abs(acoef), r__3 = f2cmax(r__3,r__4),
1590 r__1 = scale, r__2 = 1.f / (safmin * f2cmax(r__3,r__4));
1591 scale = f2cmin(r__1,r__2);
1593 acoef = ascale * (scale * sbeta);
1595 acoef = scale * acoef;
1598 bcoefr = bscale * (scale * salfar);
1600 bcoefr = scale * bcoefr;
1603 acoefa = abs(acoef);
1604 bcoefa = abs(bcoefr);
1606 /* First component is 1 */
1608 work[(*n << 1) + je] = 1.f;
1611 /* Compute contribution from column JE of A and B to sum */
1612 /* (See "Further Details", above.) */
1615 for (jr = 1; jr <= i__1; ++jr) {
1616 work[(*n << 1) + jr] = bcoefr * p[jr + je * p_dim1] -
1617 acoef * s[jr + je * s_dim1];
1622 /* Complex eigenvalue */
1624 r__1 = safmin * 100.f;
1625 slag2_(&s[je - 1 + (je - 1) * s_dim1], lds, &p[je - 1 + (je -
1626 1) * p_dim1], ldp, &r__1, &acoef, &temp, &bcoefr, &
1628 if (bcoefi == 0.f) {
1633 /* Scale to avoid over/underflow */
1635 acoefa = abs(acoef);
1636 bcoefa = abs(bcoefr) + abs(bcoefi);
1638 if (acoefa * ulp < safmin && acoefa >= safmin) {
1639 scale = safmin / ulp / acoefa;
1641 if (bcoefa * ulp < safmin && bcoefa >= safmin) {
1643 r__1 = scale, r__2 = safmin / ulp / bcoefa;
1644 scale = f2cmax(r__1,r__2);
1646 if (safmin * acoefa > ascale) {
1647 scale = ascale / (safmin * acoefa);
1649 if (safmin * bcoefa > bscale) {
1651 r__1 = scale, r__2 = bscale / (safmin * bcoefa);
1652 scale = f2cmin(r__1,r__2);
1655 acoef = scale * acoef;
1656 acoefa = abs(acoef);
1657 bcoefr = scale * bcoefr;
1658 bcoefi = scale * bcoefi;
1659 bcoefa = abs(bcoefr) + abs(bcoefi);
1662 /* Compute first two components of eigenvector */
1663 /* and contribution to sums */
1665 temp = acoef * s[je + (je - 1) * s_dim1];
1666 temp2r = acoef * s[je + je * s_dim1] - bcoefr * p[je + je *
1668 temp2i = -bcoefi * p[je + je * p_dim1];
1669 if (abs(temp) >= abs(temp2r) + abs(temp2i)) {
1670 work[(*n << 1) + je] = 1.f;
1671 work[*n * 3 + je] = 0.f;
1672 work[(*n << 1) + je - 1] = -temp2r / temp;
1673 work[*n * 3 + je - 1] = -temp2i / temp;
1675 work[(*n << 1) + je - 1] = 1.f;
1676 work[*n * 3 + je - 1] = 0.f;
1677 temp = acoef * s[je - 1 + je * s_dim1];
1678 work[(*n << 1) + je] = (bcoefr * p[je - 1 + (je - 1) *
1679 p_dim1] - acoef * s[je - 1 + (je - 1) * s_dim1]) /
1681 work[*n * 3 + je] = bcoefi * p[je - 1 + (je - 1) * p_dim1]
1686 r__5 = (r__1 = work[(*n << 1) + je], abs(r__1)) + (r__2 =
1687 work[*n * 3 + je], abs(r__2)), r__6 = (r__3 = work[(*
1688 n << 1) + je - 1], abs(r__3)) + (r__4 = work[*n * 3 +
1689 je - 1], abs(r__4));
1690 xmax = f2cmax(r__5,r__6);
1692 /* Compute contribution from columns JE and JE-1 */
1693 /* of A and B to the sums. */
1695 creala = acoef * work[(*n << 1) + je - 1];
1696 cimaga = acoef * work[*n * 3 + je - 1];
1697 crealb = bcoefr * work[(*n << 1) + je - 1] - bcoefi * work[*n
1699 cimagb = bcoefi * work[(*n << 1) + je - 1] + bcoefr * work[*n
1701 cre2a = acoef * work[(*n << 1) + je];
1702 cim2a = acoef * work[*n * 3 + je];
1703 cre2b = bcoefr * work[(*n << 1) + je] - bcoefi * work[*n * 3
1705 cim2b = bcoefi * work[(*n << 1) + je] + bcoefr * work[*n * 3
1708 for (jr = 1; jr <= i__1; ++jr) {
1709 work[(*n << 1) + jr] = -creala * s[jr + (je - 1) * s_dim1]
1710 + crealb * p[jr + (je - 1) * p_dim1] - cre2a * s[
1711 jr + je * s_dim1] + cre2b * p[jr + je * p_dim1];
1712 work[*n * 3 + jr] = -cimaga * s[jr + (je - 1) * s_dim1] +
1713 cimagb * p[jr + (je - 1) * p_dim1] - cim2a * s[jr
1714 + je * s_dim1] + cim2b * p[jr + je * p_dim1];
1720 r__1 = ulp * acoefa * anorm, r__2 = ulp * bcoefa * bnorm, r__1 =
1722 dmin__ = f2cmax(r__1,safmin);
1724 /* Columnwise triangular solve of (a A - b B) x = 0 */
1727 for (j = je - nw; j >= 1; --j) {
1729 /* If a 2-by-2 block, is in position j-1:j, wait until */
1730 /* next iteration to process it (when it will be j:j+1) */
1732 if (! il2by2 && j > 1) {
1733 if (s[j + (j - 1) * s_dim1] != 0.f) {
1738 bdiag[0] = p[j + j * p_dim1];
1741 bdiag[1] = p[j + 1 + (j + 1) * p_dim1];
1746 /* Compute x(j) (and x(j+1), if 2-by-2 block) */
1748 slaln2_(&c_false, &na, &nw, &dmin__, &acoef, &s[j + j *
1749 s_dim1], lds, bdiag, &bdiag[1], &work[(*n << 1) + j],
1750 n, &bcoefr, &bcoefi, sum, &c__2, &scale, &temp, &
1755 for (jw = 0; jw <= i__1; ++jw) {
1757 for (jr = 1; jr <= i__2; ++jr) {
1758 work[(jw + 2) * *n + jr] = scale * work[(jw + 2) *
1766 r__1 = scale * xmax;
1767 xmax = f2cmax(r__1,temp);
1770 for (jw = 1; jw <= i__1; ++jw) {
1772 for (ja = 1; ja <= i__2; ++ja) {
1773 work[(jw + 1) * *n + j + ja - 1] = sum[ja + (jw << 1)
1780 /* w = w + x(j)*(a S(*,j) - b P(*,j) ) with scaling */
1784 /* Check whether scaling is necessary for sum. */
1786 xscale = 1.f / f2cmax(1.f,xmax);
1787 temp = acoefa * work[j] + bcoefa * work[*n + j];
1790 r__1 = temp, r__2 = acoefa * work[j + 1] + bcoefa *
1792 temp = f2cmax(r__1,r__2);
1795 r__1 = f2cmax(temp,acoefa);
1796 temp = f2cmax(r__1,bcoefa);
1797 if (temp > bignum * xscale) {
1800 for (jw = 0; jw <= i__1; ++jw) {
1802 for (jr = 1; jr <= i__2; ++jr) {
1803 work[(jw + 2) * *n + jr] = xscale * work[(jw
1812 /* Compute the contributions of the off-diagonals of */
1813 /* column j (and j+1, if 2-by-2 block) of A and B to the */
1818 for (ja = 1; ja <= i__1; ++ja) {
1820 creala = acoef * work[(*n << 1) + j + ja - 1];
1821 cimaga = acoef * work[*n * 3 + j + ja - 1];
1822 crealb = bcoefr * work[(*n << 1) + j + ja - 1] -
1823 bcoefi * work[*n * 3 + j + ja - 1];
1824 cimagb = bcoefi * work[(*n << 1) + j + ja - 1] +
1825 bcoefr * work[*n * 3 + j + ja - 1];
1827 for (jr = 1; jr <= i__2; ++jr) {
1828 work[(*n << 1) + jr] = work[(*n << 1) + jr] -
1829 creala * s[jr + (j + ja - 1) * s_dim1]
1830 + crealb * p[jr + (j + ja - 1) *
1832 work[*n * 3 + jr] = work[*n * 3 + jr] -
1833 cimaga * s[jr + (j + ja - 1) * s_dim1]
1834 + cimagb * p[jr + (j + ja - 1) *
1839 creala = acoef * work[(*n << 1) + j + ja - 1];
1840 crealb = bcoefr * work[(*n << 1) + j + ja - 1];
1842 for (jr = 1; jr <= i__2; ++jr) {
1843 work[(*n << 1) + jr] = work[(*n << 1) + jr] -
1844 creala * s[jr + (j + ja - 1) * s_dim1]
1845 + crealb * p[jr + (j + ja - 1) *
1859 /* Copy eigenvector to VR, back transforming if */
1866 for (jw = 0; jw <= i__1; ++jw) {
1868 for (jr = 1; jr <= i__2; ++jr) {
1869 work[(jw + 4) * *n + jr] = work[(jw + 2) * *n + 1] *
1874 /* A series of compiler directives to defeat */
1875 /* vectorization for the next loop */
1879 for (jc = 2; jc <= i__2; ++jc) {
1881 for (jr = 1; jr <= i__3; ++jr) {
1882 work[(jw + 4) * *n + jr] += work[(jw + 2) * *n +
1883 jc] * vr[jr + jc * vr_dim1];
1892 for (jw = 0; jw <= i__1; ++jw) {
1894 for (jr = 1; jr <= i__2; ++jr) {
1895 vr[jr + (ieig + jw) * vr_dim1] = work[(jw + 4) * *n +
1905 for (jw = 0; jw <= i__1; ++jw) {
1907 for (jr = 1; jr <= i__2; ++jr) {
1908 vr[jr + (ieig + jw) * vr_dim1] = work[(jw + 2) * *n +
1918 /* Scale eigenvector */
1923 for (j = 1; j <= i__1; ++j) {
1925 r__3 = xmax, r__4 = (r__1 = vr[j + ieig * vr_dim1], abs(
1926 r__1)) + (r__2 = vr[j + (ieig + 1) * vr_dim1],
1928 xmax = f2cmax(r__3,r__4);
1933 for (j = 1; j <= i__1; ++j) {
1935 r__2 = xmax, r__3 = (r__1 = vr[j + ieig * vr_dim1], abs(
1937 xmax = f2cmax(r__2,r__3);
1942 if (xmax > safmin) {
1943 xscale = 1.f / xmax;
1945 for (jw = 0; jw <= i__1; ++jw) {
1947 for (jr = 1; jr <= i__2; ++jr) {
1948 vr[jr + (ieig + jw) * vr_dim1] = xscale * vr[jr + (
1949 ieig + jw) * vr_dim1];