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 doublereal c_b34 = 1.;
518 static integer c__1 = 1;
519 static doublereal c_b36 = 0.;
520 static logical c_false = FALSE_;
522 /* > \brief \b DTGEVC */
524 /* =========== DOCUMENTATION =========== */
526 /* Online html documentation available at */
527 /* http://www.netlib.org/lapack/explore-html/ */
530 /* > Download DTGEVC + dependencies */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtgevc.
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtgevc.
537 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtgevc.
545 /* SUBROUTINE DTGEVC( 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 /* DOUBLE PRECISION P( LDP, * ), S( LDS, * ), VL( LDVL, * ), */
552 /* $ VR( LDVR, * ), WORK( * ) */
556 /* > \par Purpose: */
561 /* > DTGEVC 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 DGGHRD + DHGEQZ. */
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 DOUBLE PRECISION array, dimension (LDS,N) */
632 /* > The upper quasi-triangular matrix S from a generalized Schur */
633 /* > factorization, as computed by DHGEQZ. */
636 /* > \param[in] LDS */
638 /* > LDS is INTEGER */
639 /* > The leading dimension of array S. LDS >= f2cmax(1,N). */
644 /* > P is DOUBLE PRECISION array, dimension (LDP,N) */
645 /* > The upper triangular matrix P from a generalized Schur */
646 /* > factorization, as computed by DHGEQZ. */
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 DOUBLE PRECISION 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 DHGEQZ). */
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 DOUBLE PRECISION 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 DHGEQZ). */
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 DOUBLE PRECISION 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 doubleGEcomputational */
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 dtgevc_(char *side, char *howmny, logical *select,
816 integer *n, doublereal *s, integer *lds, doublereal *p, integer *ldp,
817 doublereal *vl, integer *ldvl, doublereal *vr, integer *ldvr, integer
818 *mm, integer *m, doublereal *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 doublereal d__1, d__2, d__3, d__4, d__5, d__6;
825 /* Local variables */
826 integer ibeg, ieig, iend;
827 doublereal dmin__, temp, xmax, sump[4] /* was [2][2] */, sums[4]
829 extern /* Subroutine */ int dlag2_(doublereal *, integer *, doublereal *,
830 integer *, doublereal *, doublereal *, doublereal *, doublereal *,
831 doublereal *, doublereal *);
832 doublereal cim2a, cim2b, cre2a, cre2b, temp2, bdiag[2];
834 doublereal acoef, scale;
838 extern logical lsame_(char *, char *);
839 extern /* Subroutine */ int dgemv_(char *, integer *, integer *,
840 doublereal *, doublereal *, integer *, doublereal *, integer *,
841 doublereal *, doublereal *, integer *);
846 doublereal anorm, bnorm;
848 extern /* Subroutine */ int dlaln2_(logical *, integer *, integer *,
849 doublereal *, doublereal *, doublereal *, integer *, doublereal *,
850 doublereal *, doublereal *, integer *, doublereal *, doublereal *
851 , doublereal *, integer *, doublereal *, doublereal *, integer *);
853 extern /* Subroutine */ int dlabad_(doublereal *, doublereal *);
856 logical ilabad, ilbbad;
858 doublereal acoefa, bcoefa, cimaga, cimagb;
861 doublereal bcoefi, ascale, bscale, creala;
864 extern doublereal dlamch_(char *);
867 doublereal salfar, safmin;
868 extern /* Subroutine */ int dlacpy_(char *, integer *, integer *,
869 doublereal *, integer *, doublereal *, integer *);
870 doublereal xscale, bignum;
871 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
872 logical ilcomp, ilcplx;
876 doublereal ulp, sum[4] /* was [2][2] */;
879 /* -- LAPACK computational routine (version 3.7.0) -- */
880 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
881 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
886 /* ===================================================================== */
889 /* Decode and Test the input parameters */
891 /* Parameter adjustments */
894 s_offset = 1 + s_dim1 * 1;
897 p_offset = 1 + p_dim1 * 1;
900 vl_offset = 1 + vl_dim1 * 1;
903 vr_offset = 1 + vr_dim1 * 1;
908 if (lsame_(howmny, "A")) {
912 } else if (lsame_(howmny, "S")) {
916 } else if (lsame_(howmny, "B")) {
925 if (lsame_(side, "R")) {
929 } else if (lsame_(side, "L")) {
933 } else if (lsame_(side, "B")) {
944 } else if (ihwmny < 0) {
948 } else if (*lds < f2cmax(1,*n)) {
950 } else if (*ldp < f2cmax(1,*n)) {
955 xerbla_("DTGEVC", &i__1, (ftnlen)6);
959 /* Count the number of eigenvectors to be computed */
965 for (j = 1; j <= i__1; ++j) {
971 if (s[j + 1 + j * s_dim1] != 0.) {
976 if (select[j] || select[j + 1]) {
991 /* Check 2-by-2 diagonal blocks of A, B */
996 for (j = 1; j <= i__1; ++j) {
997 if (s[j + 1 + j * s_dim1] != 0.) {
998 if (p[j + j * p_dim1] == 0. || p[j + 1 + (j + 1) * p_dim1] == 0.
999 || p[j + (j + 1) * p_dim1] != 0.) {
1003 if (s[j + 2 + (j + 1) * s_dim1] != 0.) {
1013 } else if (ilbbad) {
1015 } else if (compl && *ldvl < *n || *ldvl < 1) {
1017 } else if (compr && *ldvr < *n || *ldvr < 1) {
1019 } else if (*mm < im) {
1024 xerbla_("DTGEVC", &i__1, (ftnlen)6);
1028 /* Quick return if possible */
1035 /* Machine Constants */
1037 safmin = dlamch_("Safe minimum");
1039 dlabad_(&safmin, &big);
1040 ulp = dlamch_("Epsilon") * dlamch_("Base");
1041 small = safmin * *n / ulp;
1043 bignum = 1. / (safmin * *n);
1045 /* Compute the 1-norm of each column of the strictly upper triangular */
1046 /* part (i.e., excluding all elements belonging to the diagonal */
1047 /* blocks) of A and B to check for possible overflow in the */
1048 /* triangular solver. */
1050 anorm = (d__1 = s[s_dim1 + 1], abs(d__1));
1052 anorm += (d__1 = s[s_dim1 + 2], abs(d__1));
1054 bnorm = (d__1 = p[p_dim1 + 1], abs(d__1));
1059 for (j = 2; j <= i__1; ++j) {
1062 if (s[j + (j - 1) * s_dim1] == 0.) {
1068 for (i__ = 1; i__ <= i__2; ++i__) {
1069 temp += (d__1 = s[i__ + j * s_dim1], abs(d__1));
1070 temp2 += (d__1 = p[i__ + j * p_dim1], abs(d__1));
1074 work[*n + j] = temp2;
1077 i__2 = f2cmin(i__3,*n);
1078 for (i__ = iend + 1; i__ <= i__2; ++i__) {
1079 temp += (d__1 = s[i__ + j * s_dim1], abs(d__1));
1080 temp2 += (d__1 = p[i__ + j * p_dim1], abs(d__1));
1083 anorm = f2cmax(anorm,temp);
1084 bnorm = f2cmax(bnorm,temp2);
1088 ascale = 1. / f2cmax(anorm,safmin);
1089 bscale = 1. / f2cmax(bnorm,safmin);
1091 /* Left eigenvectors */
1096 /* Main loop over eigenvalues */
1100 for (je = 1; je <= i__1; ++je) {
1102 /* Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or */
1103 /* (b) this would be the second of a complex pair. */
1104 /* Check for complex eigenvalue, so as to be sure of which */
1105 /* entry(-ies) of SELECT to look at. */
1113 if (s[je + 1 + je * s_dim1] != 0.) {
1120 } else if (ilcplx) {
1121 ilcomp = select[je] || select[je + 1];
1123 ilcomp = select[je];
1129 /* Decide if (a) singular pencil, (b) real eigenvalue, or */
1130 /* (c) complex eigenvalue. */
1133 if ((d__1 = s[je + je * s_dim1], abs(d__1)) <= safmin && (
1134 d__2 = p[je + je * p_dim1], abs(d__2)) <= safmin) {
1136 /* Singular matrix pencil -- return unit eigenvector */
1140 for (jr = 1; jr <= i__2; ++jr) {
1141 vl[jr + ieig * vl_dim1] = 0.;
1144 vl[ieig + ieig * vl_dim1] = 1.;
1152 for (jr = 1; jr <= i__2; ++jr) {
1153 work[(*n << 1) + jr] = 0.;
1157 /* Compute coefficients in ( a A - b B ) y = 0 */
1159 /* b is BCOEFR + i*BCOEFI */
1163 /* Real eigenvalue */
1166 d__3 = (d__1 = s[je + je * s_dim1], abs(d__1)) * ascale, d__4
1167 = (d__2 = p[je + je * p_dim1], abs(d__2)) * bscale,
1168 d__3 = f2cmax(d__3,d__4);
1169 temp = 1. / f2cmax(d__3,safmin);
1170 salfar = temp * s[je + je * s_dim1] * ascale;
1171 sbeta = temp * p[je + je * p_dim1] * bscale;
1172 acoef = sbeta * ascale;
1173 bcoefr = salfar * bscale;
1176 /* Scale to avoid underflow */
1179 lsa = abs(sbeta) >= safmin && abs(acoef) < small;
1180 lsb = abs(salfar) >= safmin && abs(bcoefr) < small;
1182 scale = small / abs(sbeta) * f2cmin(anorm,big);
1186 d__1 = scale, d__2 = small / abs(salfar) * f2cmin(bnorm,big);
1187 scale = f2cmax(d__1,d__2);
1192 d__3 = 1., d__4 = abs(acoef), d__3 = f2cmax(d__3,d__4), d__4
1194 d__1 = scale, d__2 = 1. / (safmin * f2cmax(d__3,d__4));
1195 scale = f2cmin(d__1,d__2);
1197 acoef = ascale * (scale * sbeta);
1199 acoef = scale * acoef;
1202 bcoefr = bscale * (scale * salfar);
1204 bcoefr = scale * bcoefr;
1207 acoefa = abs(acoef);
1208 bcoefa = abs(bcoefr);
1210 /* First component is 1 */
1212 work[(*n << 1) + je] = 1.;
1216 /* Complex eigenvalue */
1218 d__1 = safmin * 100.;
1219 dlag2_(&s[je + je * s_dim1], lds, &p[je + je * p_dim1], ldp, &
1220 d__1, &acoef, &temp, &bcoefr, &temp2, &bcoefi);
1227 /* Scale to avoid over/underflow */
1229 acoefa = abs(acoef);
1230 bcoefa = abs(bcoefr) + abs(bcoefi);
1232 if (acoefa * ulp < safmin && acoefa >= safmin) {
1233 scale = safmin / ulp / acoefa;
1235 if (bcoefa * ulp < safmin && bcoefa >= safmin) {
1237 d__1 = scale, d__2 = safmin / ulp / bcoefa;
1238 scale = f2cmax(d__1,d__2);
1240 if (safmin * acoefa > ascale) {
1241 scale = ascale / (safmin * acoefa);
1243 if (safmin * bcoefa > bscale) {
1245 d__1 = scale, d__2 = bscale / (safmin * bcoefa);
1246 scale = f2cmin(d__1,d__2);
1249 acoef = scale * acoef;
1250 acoefa = abs(acoef);
1251 bcoefr = scale * bcoefr;
1252 bcoefi = scale * bcoefi;
1253 bcoefa = abs(bcoefr) + abs(bcoefi);
1256 /* Compute first two components of eigenvector */
1258 temp = acoef * s[je + 1 + je * s_dim1];
1259 temp2r = acoef * s[je + je * s_dim1] - bcoefr * p[je + je *
1261 temp2i = -bcoefi * p[je + je * p_dim1];
1262 if (abs(temp) > abs(temp2r) + abs(temp2i)) {
1263 work[(*n << 1) + je] = 1.;
1264 work[*n * 3 + je] = 0.;
1265 work[(*n << 1) + je + 1] = -temp2r / temp;
1266 work[*n * 3 + je + 1] = -temp2i / temp;
1268 work[(*n << 1) + je + 1] = 1.;
1269 work[*n * 3 + je + 1] = 0.;
1270 temp = acoef * s[je + (je + 1) * s_dim1];
1271 work[(*n << 1) + je] = (bcoefr * p[je + 1 + (je + 1) *
1272 p_dim1] - acoef * s[je + 1 + (je + 1) * s_dim1]) /
1274 work[*n * 3 + je] = bcoefi * p[je + 1 + (je + 1) * p_dim1]
1278 d__5 = (d__1 = work[(*n << 1) + je], abs(d__1)) + (d__2 =
1279 work[*n * 3 + je], abs(d__2)), d__6 = (d__3 = work[(*
1280 n << 1) + je + 1], abs(d__3)) + (d__4 = work[*n * 3 +
1281 je + 1], abs(d__4));
1282 xmax = f2cmax(d__5,d__6);
1286 d__1 = ulp * acoefa * anorm, d__2 = ulp * bcoefa * bnorm, d__1 =
1288 dmin__ = f2cmax(d__1,safmin);
1291 /* Triangular solve of (a A - b B) y = 0 */
1294 /* (rowwise in (a A - b B) , or columnwise in (a A - b B) ) */
1299 for (j = je + nw; j <= i__2; ++j) {
1306 bdiag[0] = p[j + j * p_dim1];
1308 if (s[j + 1 + j * s_dim1] != 0.) {
1310 bdiag[1] = p[j + 1 + (j + 1) * p_dim1];
1315 /* Check whether scaling is necessary for dot products */
1317 xscale = 1. / f2cmax(1.,xmax);
1319 d__1 = work[j], d__2 = work[*n + j], d__1 = f2cmax(d__1,d__2),
1320 d__2 = acoefa * work[j] + bcoefa * work[*n + j];
1321 temp = f2cmax(d__1,d__2);
1324 d__1 = temp, d__2 = work[j + 1], d__1 = f2cmax(d__1,d__2),
1325 d__2 = work[*n + j + 1], d__1 = f2cmax(d__1,d__2),
1326 d__2 = acoefa * work[j + 1] + bcoefa * work[*n +
1328 temp = f2cmax(d__1,d__2);
1330 if (temp > bignum * xscale) {
1332 for (jw = 0; jw <= i__3; ++jw) {
1334 for (jr = je; jr <= i__4; ++jr) {
1335 work[(jw + 2) * *n + jr] = xscale * work[(jw + 2)
1344 /* Compute dot products */
1347 /* SUM = sum conjg( a*S(k,j) - b*P(k,j) )*x(k) */
1350 /* To reduce the op count, this is done as */
1353 /* a*conjg( sum S(k,j)*x(k) ) - b*conjg( sum P(k,j)*x(k) ) */
1356 /* which may cause underflow problems if A or B are close */
1357 /* to underflow. (E.g., less than SMALL.) */
1361 for (jw = 1; jw <= i__3; ++jw) {
1363 for (ja = 1; ja <= i__4; ++ja) {
1364 sums[ja + (jw << 1) - 3] = 0.;
1365 sump[ja + (jw << 1) - 3] = 0.;
1368 for (jr = je; jr <= i__5; ++jr) {
1369 sums[ja + (jw << 1) - 3] += s[jr + (j + ja - 1) *
1370 s_dim1] * work[(jw + 1) * *n + jr];
1371 sump[ja + (jw << 1) - 3] += p[jr + (j + ja - 1) *
1372 p_dim1] * work[(jw + 1) * *n + jr];
1381 for (ja = 1; ja <= i__3; ++ja) {
1383 sum[ja - 1] = -acoef * sums[ja - 1] + bcoefr * sump[
1384 ja - 1] - bcoefi * sump[ja + 1];
1385 sum[ja + 1] = -acoef * sums[ja + 1] + bcoefr * sump[
1386 ja + 1] + bcoefi * sump[ja - 1];
1388 sum[ja - 1] = -acoef * sums[ja - 1] + bcoefr * sump[
1395 /* Solve ( a A - b B ) y = SUM(,) */
1396 /* with scaling and perturbation of the denominator */
1398 dlaln2_(&c_true, &na, &nw, &dmin__, &acoef, &s[j + j * s_dim1]
1399 , lds, bdiag, &bdiag[1], sum, &c__2, &bcoefr, &bcoefi,
1400 &work[(*n << 1) + j], n, &scale, &temp, &iinfo);
1403 for (jw = 0; jw <= i__3; ++jw) {
1405 for (jr = je; jr <= i__4; ++jr) {
1406 work[(jw + 2) * *n + jr] = scale * work[(jw + 2) *
1412 xmax = scale * xmax;
1414 xmax = f2cmax(xmax,temp);
1419 /* Copy eigenvector to VL, back transforming if */
1425 for (jw = 0; jw <= i__2; ++jw) {
1427 dgemv_("N", n, &i__3, &c_b34, &vl[je * vl_dim1 + 1], ldvl,
1428 &work[(jw + 2) * *n + je], &c__1, &c_b36, &work[(
1429 jw + 4) * *n + 1], &c__1);
1432 dlacpy_(" ", n, &nw, &work[(*n << 2) + 1], n, &vl[je *
1433 vl_dim1 + 1], ldvl);
1436 dlacpy_(" ", n, &nw, &work[(*n << 1) + 1], n, &vl[ieig *
1437 vl_dim1 + 1], ldvl);
1441 /* Scale eigenvector */
1446 for (j = ibeg; j <= i__2; ++j) {
1448 d__3 = xmax, d__4 = (d__1 = vl[j + ieig * vl_dim1], abs(
1449 d__1)) + (d__2 = vl[j + (ieig + 1) * vl_dim1],
1451 xmax = f2cmax(d__3,d__4);
1456 for (j = ibeg; j <= i__2; ++j) {
1458 d__2 = xmax, d__3 = (d__1 = vl[j + ieig * vl_dim1], abs(
1460 xmax = f2cmax(d__2,d__3);
1465 if (xmax > safmin) {
1469 for (jw = 0; jw <= i__2; ++jw) {
1471 for (jr = ibeg; jr <= i__3; ++jr) {
1472 vl[jr + (ieig + jw) * vl_dim1] = xscale * vl[jr + (
1473 ieig + jw) * vl_dim1];
1479 ieig = ieig + nw - 1;
1486 /* Right eigenvectors */
1491 /* Main loop over eigenvalues */
1494 for (je = *n; je >= 1; --je) {
1496 /* Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or */
1497 /* (b) this would be the second of a complex pair. */
1498 /* Check for complex eigenvalue, so as to be sure of which */
1499 /* entry(-ies) of SELECT to look at -- if complex, SELECT(JE) */
1500 /* or SELECT(JE-1). */
1501 /* If this is a complex pair, the 2-by-2 diagonal block */
1502 /* corresponding to the eigenvalue is in rows/columns JE-1:JE */
1510 if (s[je + (je - 1) * s_dim1] != 0.) {
1517 } else if (ilcplx) {
1518 ilcomp = select[je] || select[je - 1];
1520 ilcomp = select[je];
1526 /* Decide if (a) singular pencil, (b) real eigenvalue, or */
1527 /* (c) complex eigenvalue. */
1530 if ((d__1 = s[je + je * s_dim1], abs(d__1)) <= safmin && (
1531 d__2 = p[je + je * p_dim1], abs(d__2)) <= safmin) {
1533 /* Singular matrix pencil -- unit eigenvector */
1537 for (jr = 1; jr <= i__1; ++jr) {
1538 vr[jr + ieig * vr_dim1] = 0.;
1541 vr[ieig + ieig * vr_dim1] = 1.;
1549 for (jw = 0; jw <= i__1; ++jw) {
1551 for (jr = 1; jr <= i__2; ++jr) {
1552 work[(jw + 2) * *n + jr] = 0.;
1558 /* Compute coefficients in ( a A - b B ) x = 0 */
1560 /* b is BCOEFR + i*BCOEFI */
1564 /* Real eigenvalue */
1567 d__3 = (d__1 = s[je + je * s_dim1], abs(d__1)) * ascale, d__4
1568 = (d__2 = p[je + je * p_dim1], abs(d__2)) * bscale,
1569 d__3 = f2cmax(d__3,d__4);
1570 temp = 1. / f2cmax(d__3,safmin);
1571 salfar = temp * s[je + je * s_dim1] * ascale;
1572 sbeta = temp * p[je + je * p_dim1] * bscale;
1573 acoef = sbeta * ascale;
1574 bcoefr = salfar * bscale;
1577 /* Scale to avoid underflow */
1580 lsa = abs(sbeta) >= safmin && abs(acoef) < small;
1581 lsb = abs(salfar) >= safmin && abs(bcoefr) < small;
1583 scale = small / abs(sbeta) * f2cmin(anorm,big);
1587 d__1 = scale, d__2 = small / abs(salfar) * f2cmin(bnorm,big);
1588 scale = f2cmax(d__1,d__2);
1593 d__3 = 1., d__4 = abs(acoef), d__3 = f2cmax(d__3,d__4), d__4
1595 d__1 = scale, d__2 = 1. / (safmin * f2cmax(d__3,d__4));
1596 scale = f2cmin(d__1,d__2);
1598 acoef = ascale * (scale * sbeta);
1600 acoef = scale * acoef;
1603 bcoefr = bscale * (scale * salfar);
1605 bcoefr = scale * bcoefr;
1608 acoefa = abs(acoef);
1609 bcoefa = abs(bcoefr);
1611 /* First component is 1 */
1613 work[(*n << 1) + je] = 1.;
1616 /* Compute contribution from column JE of A and B to sum */
1617 /* (See "Further Details", above.) */
1620 for (jr = 1; jr <= i__1; ++jr) {
1621 work[(*n << 1) + jr] = bcoefr * p[jr + je * p_dim1] -
1622 acoef * s[jr + je * s_dim1];
1627 /* Complex eigenvalue */
1629 d__1 = safmin * 100.;
1630 dlag2_(&s[je - 1 + (je - 1) * s_dim1], lds, &p[je - 1 + (je -
1631 1) * p_dim1], ldp, &d__1, &acoef, &temp, &bcoefr, &
1638 /* Scale to avoid over/underflow */
1640 acoefa = abs(acoef);
1641 bcoefa = abs(bcoefr) + abs(bcoefi);
1643 if (acoefa * ulp < safmin && acoefa >= safmin) {
1644 scale = safmin / ulp / acoefa;
1646 if (bcoefa * ulp < safmin && bcoefa >= safmin) {
1648 d__1 = scale, d__2 = safmin / ulp / bcoefa;
1649 scale = f2cmax(d__1,d__2);
1651 if (safmin * acoefa > ascale) {
1652 scale = ascale / (safmin * acoefa);
1654 if (safmin * bcoefa > bscale) {
1656 d__1 = scale, d__2 = bscale / (safmin * bcoefa);
1657 scale = f2cmin(d__1,d__2);
1660 acoef = scale * acoef;
1661 acoefa = abs(acoef);
1662 bcoefr = scale * bcoefr;
1663 bcoefi = scale * bcoefi;
1664 bcoefa = abs(bcoefr) + abs(bcoefi);
1667 /* Compute first two components of eigenvector */
1668 /* and contribution to sums */
1670 temp = acoef * s[je + (je - 1) * s_dim1];
1671 temp2r = acoef * s[je + je * s_dim1] - bcoefr * p[je + je *
1673 temp2i = -bcoefi * p[je + je * p_dim1];
1674 if (abs(temp) >= abs(temp2r) + abs(temp2i)) {
1675 work[(*n << 1) + je] = 1.;
1676 work[*n * 3 + je] = 0.;
1677 work[(*n << 1) + je - 1] = -temp2r / temp;
1678 work[*n * 3 + je - 1] = -temp2i / temp;
1680 work[(*n << 1) + je - 1] = 1.;
1681 work[*n * 3 + je - 1] = 0.;
1682 temp = acoef * s[je - 1 + je * s_dim1];
1683 work[(*n << 1) + je] = (bcoefr * p[je - 1 + (je - 1) *
1684 p_dim1] - acoef * s[je - 1 + (je - 1) * s_dim1]) /
1686 work[*n * 3 + je] = bcoefi * p[je - 1 + (je - 1) * p_dim1]
1691 d__5 = (d__1 = work[(*n << 1) + je], abs(d__1)) + (d__2 =
1692 work[*n * 3 + je], abs(d__2)), d__6 = (d__3 = work[(*
1693 n << 1) + je - 1], abs(d__3)) + (d__4 = work[*n * 3 +
1694 je - 1], abs(d__4));
1695 xmax = f2cmax(d__5,d__6);
1697 /* Compute contribution from columns JE and JE-1 */
1698 /* of A and B to the sums. */
1700 creala = acoef * work[(*n << 1) + je - 1];
1701 cimaga = acoef * work[*n * 3 + je - 1];
1702 crealb = bcoefr * work[(*n << 1) + je - 1] - bcoefi * work[*n
1704 cimagb = bcoefi * work[(*n << 1) + je - 1] + bcoefr * work[*n
1706 cre2a = acoef * work[(*n << 1) + je];
1707 cim2a = acoef * work[*n * 3 + je];
1708 cre2b = bcoefr * work[(*n << 1) + je] - bcoefi * work[*n * 3
1710 cim2b = bcoefi * work[(*n << 1) + je] + bcoefr * work[*n * 3
1713 for (jr = 1; jr <= i__1; ++jr) {
1714 work[(*n << 1) + jr] = -creala * s[jr + (je - 1) * s_dim1]
1715 + crealb * p[jr + (je - 1) * p_dim1] - cre2a * s[
1716 jr + je * s_dim1] + cre2b * p[jr + je * p_dim1];
1717 work[*n * 3 + jr] = -cimaga * s[jr + (je - 1) * s_dim1] +
1718 cimagb * p[jr + (je - 1) * p_dim1] - cim2a * s[jr
1719 + je * s_dim1] + cim2b * p[jr + je * p_dim1];
1725 d__1 = ulp * acoefa * anorm, d__2 = ulp * bcoefa * bnorm, d__1 =
1727 dmin__ = f2cmax(d__1,safmin);
1729 /* Columnwise triangular solve of (a A - b B) x = 0 */
1732 for (j = je - nw; j >= 1; --j) {
1734 /* If a 2-by-2 block, is in position j-1:j, wait until */
1735 /* next iteration to process it (when it will be j:j+1) */
1737 if (! il2by2 && j > 1) {
1738 if (s[j + (j - 1) * s_dim1] != 0.) {
1743 bdiag[0] = p[j + j * p_dim1];
1746 bdiag[1] = p[j + 1 + (j + 1) * p_dim1];
1751 /* Compute x(j) (and x(j+1), if 2-by-2 block) */
1753 dlaln2_(&c_false, &na, &nw, &dmin__, &acoef, &s[j + j *
1754 s_dim1], lds, bdiag, &bdiag[1], &work[(*n << 1) + j],
1755 n, &bcoefr, &bcoefi, sum, &c__2, &scale, &temp, &
1760 for (jw = 0; jw <= i__1; ++jw) {
1762 for (jr = 1; jr <= i__2; ++jr) {
1763 work[(jw + 2) * *n + jr] = scale * work[(jw + 2) *
1771 d__1 = scale * xmax;
1772 xmax = f2cmax(d__1,temp);
1775 for (jw = 1; jw <= i__1; ++jw) {
1777 for (ja = 1; ja <= i__2; ++ja) {
1778 work[(jw + 1) * *n + j + ja - 1] = sum[ja + (jw << 1)
1785 /* w = w + x(j)*(a S(*,j) - b P(*,j) ) with scaling */
1789 /* Check whether scaling is necessary for sum. */
1791 xscale = 1. / f2cmax(1.,xmax);
1792 temp = acoefa * work[j] + bcoefa * work[*n + j];
1795 d__1 = temp, d__2 = acoefa * work[j + 1] + bcoefa *
1797 temp = f2cmax(d__1,d__2);
1800 d__1 = f2cmax(temp,acoefa);
1801 temp = f2cmax(d__1,bcoefa);
1802 if (temp > bignum * xscale) {
1805 for (jw = 0; jw <= i__1; ++jw) {
1807 for (jr = 1; jr <= i__2; ++jr) {
1808 work[(jw + 2) * *n + jr] = xscale * work[(jw
1817 /* Compute the contributions of the off-diagonals of */
1818 /* column j (and j+1, if 2-by-2 block) of A and B to the */
1823 for (ja = 1; ja <= i__1; ++ja) {
1825 creala = acoef * work[(*n << 1) + j + ja - 1];
1826 cimaga = acoef * work[*n * 3 + j + ja - 1];
1827 crealb = bcoefr * work[(*n << 1) + j + ja - 1] -
1828 bcoefi * work[*n * 3 + j + ja - 1];
1829 cimagb = bcoefi * work[(*n << 1) + j + ja - 1] +
1830 bcoefr * work[*n * 3 + j + ja - 1];
1832 for (jr = 1; jr <= i__2; ++jr) {
1833 work[(*n << 1) + jr] = work[(*n << 1) + jr] -
1834 creala * s[jr + (j + ja - 1) * s_dim1]
1835 + crealb * p[jr + (j + ja - 1) *
1837 work[*n * 3 + jr] = work[*n * 3 + jr] -
1838 cimaga * s[jr + (j + ja - 1) * s_dim1]
1839 + cimagb * p[jr + (j + ja - 1) *
1844 creala = acoef * work[(*n << 1) + j + ja - 1];
1845 crealb = bcoefr * work[(*n << 1) + j + ja - 1];
1847 for (jr = 1; jr <= i__2; ++jr) {
1848 work[(*n << 1) + jr] = work[(*n << 1) + jr] -
1849 creala * s[jr + (j + ja - 1) * s_dim1]
1850 + crealb * p[jr + (j + ja - 1) *
1864 /* Copy eigenvector to VR, back transforming if */
1871 for (jw = 0; jw <= i__1; ++jw) {
1873 for (jr = 1; jr <= i__2; ++jr) {
1874 work[(jw + 4) * *n + jr] = work[(jw + 2) * *n + 1] *
1879 /* A series of compiler directives to defeat */
1880 /* vectorization for the next loop */
1884 for (jc = 2; jc <= i__2; ++jc) {
1886 for (jr = 1; jr <= i__3; ++jr) {
1887 work[(jw + 4) * *n + jr] += work[(jw + 2) * *n +
1888 jc] * vr[jr + jc * vr_dim1];
1897 for (jw = 0; jw <= i__1; ++jw) {
1899 for (jr = 1; jr <= i__2; ++jr) {
1900 vr[jr + (ieig + jw) * vr_dim1] = work[(jw + 4) * *n +
1910 for (jw = 0; jw <= i__1; ++jw) {
1912 for (jr = 1; jr <= i__2; ++jr) {
1913 vr[jr + (ieig + jw) * vr_dim1] = work[(jw + 2) * *n +
1923 /* Scale eigenvector */
1928 for (j = 1; j <= i__1; ++j) {
1930 d__3 = xmax, d__4 = (d__1 = vr[j + ieig * vr_dim1], abs(
1931 d__1)) + (d__2 = vr[j + (ieig + 1) * vr_dim1],
1933 xmax = f2cmax(d__3,d__4);
1938 for (j = 1; j <= i__1; ++j) {
1940 d__2 = xmax, d__3 = (d__1 = vr[j + ieig * vr_dim1], abs(
1942 xmax = f2cmax(d__2,d__3);
1947 if (xmax > safmin) {
1950 for (jw = 0; jw <= i__1; ++jw) {
1952 for (jr = 1; jr <= i__2; ++jr) {
1953 vr[jr + (ieig + jw) * vr_dim1] = xscale * vr[jr + (
1954 ieig + jw) * vr_dim1];