ctgevc.c
Go to the documentation of this file.
00001 /* ctgevc.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static complex c_b1 = {0.f,0.f};
00019 static complex c_b2 = {1.f,0.f};
00020 static integer c__1 = 1;
00021 
00022 /* Subroutine */ int ctgevc_(char *side, char *howmny, logical *select, 
00023         integer *n, complex *s, integer *lds, complex *p, integer *ldp, 
00024         complex *vl, integer *ldvl, complex *vr, integer *ldvr, integer *mm, 
00025         integer *m, complex *work, real *rwork, integer *info)
00026 {
00027     /* System generated locals */
00028     integer p_dim1, p_offset, s_dim1, s_offset, vl_dim1, vl_offset, vr_dim1, 
00029             vr_offset, i__1, i__2, i__3, i__4, i__5;
00030     real r__1, r__2, r__3, r__4, r__5, r__6;
00031     complex q__1, q__2, q__3, q__4;
00032 
00033     /* Builtin functions */
00034     double r_imag(complex *);
00035     void r_cnjg(complex *, complex *);
00036 
00037     /* Local variables */
00038     complex d__;
00039     integer i__, j;
00040     complex ca, cb;
00041     integer je, im, jr;
00042     real big;
00043     logical lsa, lsb;
00044     real ulp;
00045     complex sum;
00046     integer ibeg, ieig, iend;
00047     real dmin__;
00048     integer isrc;
00049     real temp;
00050     complex suma, sumb;
00051     real xmax, scale;
00052     logical ilall;
00053     integer iside;
00054     real sbeta;
00055     extern logical lsame_(char *, char *);
00056     extern /* Subroutine */ int cgemv_(char *, integer *, integer *, complex *
00057 , complex *, integer *, complex *, integer *, complex *, complex *
00058 , integer *);
00059     real small;
00060     logical compl;
00061     real anorm, bnorm;
00062     logical compr, ilbbad;
00063     real acoefa, bcoefa, acoeff;
00064     complex bcoeff;
00065     logical ilback;
00066     extern /* Subroutine */ int slabad_(real *, real *);
00067     real ascale, bscale;
00068     extern /* Complex */ VOID cladiv_(complex *, complex *, complex *);
00069     extern doublereal slamch_(char *);
00070     complex salpha;
00071     real safmin;
00072     extern /* Subroutine */ int xerbla_(char *, integer *);
00073     real bignum;
00074     logical ilcomp;
00075     integer ihwmny;
00076 
00077 
00078 /*  -- LAPACK routine (version 3.2) -- */
00079 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00080 /*     November 2006 */
00081 
00082 /*     .. Scalar Arguments .. */
00083 /*     .. */
00084 /*     .. Array Arguments .. */
00085 /*     .. */
00086 
00087 
00088 /*  Purpose */
00089 /*  ======= */
00090 
00091 /*  CTGEVC computes some or all of the right and/or left eigenvectors of */
00092 /*  a pair of complex matrices (S,P), where S and P are upper triangular. */
00093 /*  Matrix pairs of this type are produced by the generalized Schur */
00094 /*  factorization of a complex matrix pair (A,B): */
00095 
00096 /*     A = Q*S*Z**H,  B = Q*P*Z**H */
00097 
00098 /*  as computed by CGGHRD + CHGEQZ. */
00099 
00100 /*  The right eigenvector x and the left eigenvector y of (S,P) */
00101 /*  corresponding to an eigenvalue w are defined by: */
00102 
00103 /*     S*x = w*P*x,  (y**H)*S = w*(y**H)*P, */
00104 
00105 /*  where y**H denotes the conjugate tranpose of y. */
00106 /*  The eigenvalues are not input to this routine, but are computed */
00107 /*  directly from the diagonal elements of S and P. */
00108 
00109 /*  This routine returns the matrices X and/or Y of right and left */
00110 /*  eigenvectors of (S,P), or the products Z*X and/or Q*Y, */
00111 /*  where Z and Q are input matrices. */
00112 /*  If Q and Z are the unitary factors from the generalized Schur */
00113 /*  factorization of a matrix pair (A,B), then Z*X and Q*Y */
00114 /*  are the matrices of right and left eigenvectors of (A,B). */
00115 
00116 /*  Arguments */
00117 /*  ========= */
00118 
00119 /*  SIDE    (input) CHARACTER*1 */
00120 /*          = 'R': compute right eigenvectors only; */
00121 /*          = 'L': compute left eigenvectors only; */
00122 /*          = 'B': compute both right and left eigenvectors. */
00123 
00124 /*  HOWMNY  (input) CHARACTER*1 */
00125 /*          = 'A': compute all right and/or left eigenvectors; */
00126 /*          = 'B': compute all right and/or left eigenvectors, */
00127 /*                 backtransformed by the matrices in VR and/or VL; */
00128 /*          = 'S': compute selected right and/or left eigenvectors, */
00129 /*                 specified by the logical array SELECT. */
00130 
00131 /*  SELECT  (input) LOGICAL array, dimension (N) */
00132 /*          If HOWMNY='S', SELECT specifies the eigenvectors to be */
00133 /*          computed.  The eigenvector corresponding to the j-th */
00134 /*          eigenvalue is computed if SELECT(j) = .TRUE.. */
00135 /*          Not referenced if HOWMNY = 'A' or 'B'. */
00136 
00137 /*  N       (input) INTEGER */
00138 /*          The order of the matrices S and P.  N >= 0. */
00139 
00140 /*  S       (input) COMPLEX array, dimension (LDS,N) */
00141 /*          The upper triangular matrix S from a generalized Schur */
00142 /*          factorization, as computed by CHGEQZ. */
00143 
00144 /*  LDS     (input) INTEGER */
00145 /*          The leading dimension of array S.  LDS >= max(1,N). */
00146 
00147 /*  P       (input) COMPLEX array, dimension (LDP,N) */
00148 /*          The upper triangular matrix P from a generalized Schur */
00149 /*          factorization, as computed by CHGEQZ.  P must have real */
00150 /*          diagonal elements. */
00151 
00152 /*  LDP     (input) INTEGER */
00153 /*          The leading dimension of array P.  LDP >= max(1,N). */
00154 
00155 /*  VL      (input/output) COMPLEX array, dimension (LDVL,MM) */
00156 /*          On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must */
00157 /*          contain an N-by-N matrix Q (usually the unitary matrix Q */
00158 /*          of left Schur vectors returned by CHGEQZ). */
00159 /*          On exit, if SIDE = 'L' or 'B', VL contains: */
00160 /*          if HOWMNY = 'A', the matrix Y of left eigenvectors of (S,P); */
00161 /*          if HOWMNY = 'B', the matrix Q*Y; */
00162 /*          if HOWMNY = 'S', the left eigenvectors of (S,P) specified by */
00163 /*                      SELECT, stored consecutively in the columns of */
00164 /*                      VL, in the same order as their eigenvalues. */
00165 /*          Not referenced if SIDE = 'R'. */
00166 
00167 /*  LDVL    (input) INTEGER */
00168 /*          The leading dimension of array VL.  LDVL >= 1, and if */
00169 /*          SIDE = 'L' or 'l' or 'B' or 'b', LDVL >= N. */
00170 
00171 /*  VR      (input/output) COMPLEX array, dimension (LDVR,MM) */
00172 /*          On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must */
00173 /*          contain an N-by-N matrix Q (usually the unitary matrix Z */
00174 /*          of right Schur vectors returned by CHGEQZ). */
00175 /*          On exit, if SIDE = 'R' or 'B', VR contains: */
00176 /*          if HOWMNY = 'A', the matrix X of right eigenvectors of (S,P); */
00177 /*          if HOWMNY = 'B', the matrix Z*X; */
00178 /*          if HOWMNY = 'S', the right eigenvectors of (S,P) specified by */
00179 /*                      SELECT, stored consecutively in the columns of */
00180 /*                      VR, in the same order as their eigenvalues. */
00181 /*          Not referenced if SIDE = 'L'. */
00182 
00183 /*  LDVR    (input) INTEGER */
00184 /*          The leading dimension of the array VR.  LDVR >= 1, and if */
00185 /*          SIDE = 'R' or 'B', LDVR >= N. */
00186 
00187 /*  MM      (input) INTEGER */
00188 /*          The number of columns in the arrays VL and/or VR. MM >= M. */
00189 
00190 /*  M       (output) INTEGER */
00191 /*          The number of columns in the arrays VL and/or VR actually */
00192 /*          used to store the eigenvectors.  If HOWMNY = 'A' or 'B', M */
00193 /*          is set to N.  Each selected eigenvector occupies one column. */
00194 
00195 /*  WORK    (workspace) COMPLEX array, dimension (2*N) */
00196 
00197 /*  RWORK   (workspace) REAL array, dimension (2*N) */
00198 
00199 /*  INFO    (output) INTEGER */
00200 /*          = 0:  successful exit. */
00201 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00202 
00203 /*  ===================================================================== */
00204 
00205 /*     .. Parameters .. */
00206 /*     .. */
00207 /*     .. Local Scalars .. */
00208 /*     .. */
00209 /*     .. External Functions .. */
00210 /*     .. */
00211 /*     .. External Subroutines .. */
00212 /*     .. */
00213 /*     .. Intrinsic Functions .. */
00214 /*     .. */
00215 /*     .. Statement Functions .. */
00216 /*     .. */
00217 /*     .. Statement Function definitions .. */
00218 /*     .. */
00219 /*     .. Executable Statements .. */
00220 
00221 /*     Decode and Test the input parameters */
00222 
00223     /* Parameter adjustments */
00224     --select;
00225     s_dim1 = *lds;
00226     s_offset = 1 + s_dim1;
00227     s -= s_offset;
00228     p_dim1 = *ldp;
00229     p_offset = 1 + p_dim1;
00230     p -= p_offset;
00231     vl_dim1 = *ldvl;
00232     vl_offset = 1 + vl_dim1;
00233     vl -= vl_offset;
00234     vr_dim1 = *ldvr;
00235     vr_offset = 1 + vr_dim1;
00236     vr -= vr_offset;
00237     --work;
00238     --rwork;
00239 
00240     /* Function Body */
00241     if (lsame_(howmny, "A")) {
00242         ihwmny = 1;
00243         ilall = TRUE_;
00244         ilback = FALSE_;
00245     } else if (lsame_(howmny, "S")) {
00246         ihwmny = 2;
00247         ilall = FALSE_;
00248         ilback = FALSE_;
00249     } else if (lsame_(howmny, "B")) {
00250         ihwmny = 3;
00251         ilall = TRUE_;
00252         ilback = TRUE_;
00253     } else {
00254         ihwmny = -1;
00255     }
00256 
00257     if (lsame_(side, "R")) {
00258         iside = 1;
00259         compl = FALSE_;
00260         compr = TRUE_;
00261     } else if (lsame_(side, "L")) {
00262         iside = 2;
00263         compl = TRUE_;
00264         compr = FALSE_;
00265     } else if (lsame_(side, "B")) {
00266         iside = 3;
00267         compl = TRUE_;
00268         compr = TRUE_;
00269     } else {
00270         iside = -1;
00271     }
00272 
00273     *info = 0;
00274     if (iside < 0) {
00275         *info = -1;
00276     } else if (ihwmny < 0) {
00277         *info = -2;
00278     } else if (*n < 0) {
00279         *info = -4;
00280     } else if (*lds < max(1,*n)) {
00281         *info = -6;
00282     } else if (*ldp < max(1,*n)) {
00283         *info = -8;
00284     }
00285     if (*info != 0) {
00286         i__1 = -(*info);
00287         xerbla_("CTGEVC", &i__1);
00288         return 0;
00289     }
00290 
00291 /*     Count the number of eigenvectors */
00292 
00293     if (! ilall) {
00294         im = 0;
00295         i__1 = *n;
00296         for (j = 1; j <= i__1; ++j) {
00297             if (select[j]) {
00298                 ++im;
00299             }
00300 /* L10: */
00301         }
00302     } else {
00303         im = *n;
00304     }
00305 
00306 /*     Check diagonal of B */
00307 
00308     ilbbad = FALSE_;
00309     i__1 = *n;
00310     for (j = 1; j <= i__1; ++j) {
00311         if (r_imag(&p[j + j * p_dim1]) != 0.f) {
00312             ilbbad = TRUE_;
00313         }
00314 /* L20: */
00315     }
00316 
00317     if (ilbbad) {
00318         *info = -7;
00319     } else if (compl && *ldvl < *n || *ldvl < 1) {
00320         *info = -10;
00321     } else if (compr && *ldvr < *n || *ldvr < 1) {
00322         *info = -12;
00323     } else if (*mm < im) {
00324         *info = -13;
00325     }
00326     if (*info != 0) {
00327         i__1 = -(*info);
00328         xerbla_("CTGEVC", &i__1);
00329         return 0;
00330     }
00331 
00332 /*     Quick return if possible */
00333 
00334     *m = im;
00335     if (*n == 0) {
00336         return 0;
00337     }
00338 
00339 /*     Machine Constants */
00340 
00341     safmin = slamch_("Safe minimum");
00342     big = 1.f / safmin;
00343     slabad_(&safmin, &big);
00344     ulp = slamch_("Epsilon") * slamch_("Base");
00345     small = safmin * *n / ulp;
00346     big = 1.f / small;
00347     bignum = 1.f / (safmin * *n);
00348 
00349 /*     Compute the 1-norm of each column of the strictly upper triangular */
00350 /*     part of A and B to check for possible overflow in the triangular */
00351 /*     solver. */
00352 
00353     i__1 = s_dim1 + 1;
00354     anorm = (r__1 = s[i__1].r, dabs(r__1)) + (r__2 = r_imag(&s[s_dim1 + 1]), 
00355             dabs(r__2));
00356     i__1 = p_dim1 + 1;
00357     bnorm = (r__1 = p[i__1].r, dabs(r__1)) + (r__2 = r_imag(&p[p_dim1 + 1]), 
00358             dabs(r__2));
00359     rwork[1] = 0.f;
00360     rwork[*n + 1] = 0.f;
00361     i__1 = *n;
00362     for (j = 2; j <= i__1; ++j) {
00363         rwork[j] = 0.f;
00364         rwork[*n + j] = 0.f;
00365         i__2 = j - 1;
00366         for (i__ = 1; i__ <= i__2; ++i__) {
00367             i__3 = i__ + j * s_dim1;
00368             rwork[j] += (r__1 = s[i__3].r, dabs(r__1)) + (r__2 = r_imag(&s[
00369                     i__ + j * s_dim1]), dabs(r__2));
00370             i__3 = i__ + j * p_dim1;
00371             rwork[*n + j] += (r__1 = p[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
00372                     p[i__ + j * p_dim1]), dabs(r__2));
00373 /* L30: */
00374         }
00375 /* Computing MAX */
00376         i__2 = j + j * s_dim1;
00377         r__3 = anorm, r__4 = rwork[j] + ((r__1 = s[i__2].r, dabs(r__1)) + (
00378                 r__2 = r_imag(&s[j + j * s_dim1]), dabs(r__2)));
00379         anorm = dmax(r__3,r__4);
00380 /* Computing MAX */
00381         i__2 = j + j * p_dim1;
00382         r__3 = bnorm, r__4 = rwork[*n + j] + ((r__1 = p[i__2].r, dabs(r__1)) 
00383                 + (r__2 = r_imag(&p[j + j * p_dim1]), dabs(r__2)));
00384         bnorm = dmax(r__3,r__4);
00385 /* L40: */
00386     }
00387 
00388     ascale = 1.f / dmax(anorm,safmin);
00389     bscale = 1.f / dmax(bnorm,safmin);
00390 
00391 /*     Left eigenvectors */
00392 
00393     if (compl) {
00394         ieig = 0;
00395 
00396 /*        Main loop over eigenvalues */
00397 
00398         i__1 = *n;
00399         for (je = 1; je <= i__1; ++je) {
00400             if (ilall) {
00401                 ilcomp = TRUE_;
00402             } else {
00403                 ilcomp = select[je];
00404             }
00405             if (ilcomp) {
00406                 ++ieig;
00407 
00408                 i__2 = je + je * s_dim1;
00409                 i__3 = je + je * p_dim1;
00410                 if ((r__2 = s[i__2].r, dabs(r__2)) + (r__3 = r_imag(&s[je + 
00411                         je * s_dim1]), dabs(r__3)) <= safmin && (r__1 = p[
00412                         i__3].r, dabs(r__1)) <= safmin) {
00413 
00414 /*                 Singular matrix pencil -- return unit eigenvector */
00415 
00416                     i__2 = *n;
00417                     for (jr = 1; jr <= i__2; ++jr) {
00418                         i__3 = jr + ieig * vl_dim1;
00419                         vl[i__3].r = 0.f, vl[i__3].i = 0.f;
00420 /* L50: */
00421                     }
00422                     i__2 = ieig + ieig * vl_dim1;
00423                     vl[i__2].r = 1.f, vl[i__2].i = 0.f;
00424                     goto L140;
00425                 }
00426 
00427 /*              Non-singular eigenvalue: */
00428 /*              Compute coefficients  a  and  b  in */
00429 /*                   H */
00430 /*                 y  ( a A - b B ) = 0 */
00431 
00432 /* Computing MAX */
00433                 i__2 = je + je * s_dim1;
00434                 i__3 = je + je * p_dim1;
00435                 r__4 = ((r__2 = s[i__2].r, dabs(r__2)) + (r__3 = r_imag(&s[je 
00436                         + je * s_dim1]), dabs(r__3))) * ascale, r__5 = (r__1 =
00437                          p[i__3].r, dabs(r__1)) * bscale, r__4 = max(r__4,
00438                         r__5);
00439                 temp = 1.f / dmax(r__4,safmin);
00440                 i__2 = je + je * s_dim1;
00441                 q__2.r = temp * s[i__2].r, q__2.i = temp * s[i__2].i;
00442                 q__1.r = ascale * q__2.r, q__1.i = ascale * q__2.i;
00443                 salpha.r = q__1.r, salpha.i = q__1.i;
00444                 i__2 = je + je * p_dim1;
00445                 sbeta = temp * p[i__2].r * bscale;
00446                 acoeff = sbeta * ascale;
00447                 q__1.r = bscale * salpha.r, q__1.i = bscale * salpha.i;
00448                 bcoeff.r = q__1.r, bcoeff.i = q__1.i;
00449 
00450 /*              Scale to avoid underflow */
00451 
00452                 lsa = dabs(sbeta) >= safmin && dabs(acoeff) < small;
00453                 lsb = (r__1 = salpha.r, dabs(r__1)) + (r__2 = r_imag(&salpha),
00454                          dabs(r__2)) >= safmin && (r__3 = bcoeff.r, dabs(r__3)
00455                         ) + (r__4 = r_imag(&bcoeff), dabs(r__4)) < small;
00456 
00457                 scale = 1.f;
00458                 if (lsa) {
00459                     scale = small / dabs(sbeta) * dmin(anorm,big);
00460                 }
00461                 if (lsb) {
00462 /* Computing MAX */
00463                     r__3 = scale, r__4 = small / ((r__1 = salpha.r, dabs(r__1)
00464                             ) + (r__2 = r_imag(&salpha), dabs(r__2))) * dmin(
00465                             bnorm,big);
00466                     scale = dmax(r__3,r__4);
00467                 }
00468                 if (lsa || lsb) {
00469 /* Computing MIN */
00470 /* Computing MAX */
00471                     r__5 = 1.f, r__6 = dabs(acoeff), r__5 = max(r__5,r__6), 
00472                             r__6 = (r__1 = bcoeff.r, dabs(r__1)) + (r__2 = 
00473                             r_imag(&bcoeff), dabs(r__2));
00474                     r__3 = scale, r__4 = 1.f / (safmin * dmax(r__5,r__6));
00475                     scale = dmin(r__3,r__4);
00476                     if (lsa) {
00477                         acoeff = ascale * (scale * sbeta);
00478                     } else {
00479                         acoeff = scale * acoeff;
00480                     }
00481                     if (lsb) {
00482                         q__2.r = scale * salpha.r, q__2.i = scale * salpha.i;
00483                         q__1.r = bscale * q__2.r, q__1.i = bscale * q__2.i;
00484                         bcoeff.r = q__1.r, bcoeff.i = q__1.i;
00485                     } else {
00486                         q__1.r = scale * bcoeff.r, q__1.i = scale * bcoeff.i;
00487                         bcoeff.r = q__1.r, bcoeff.i = q__1.i;
00488                     }
00489                 }
00490 
00491                 acoefa = dabs(acoeff);
00492                 bcoefa = (r__1 = bcoeff.r, dabs(r__1)) + (r__2 = r_imag(&
00493                         bcoeff), dabs(r__2));
00494                 xmax = 1.f;
00495                 i__2 = *n;
00496                 for (jr = 1; jr <= i__2; ++jr) {
00497                     i__3 = jr;
00498                     work[i__3].r = 0.f, work[i__3].i = 0.f;
00499 /* L60: */
00500                 }
00501                 i__2 = je;
00502                 work[i__2].r = 1.f, work[i__2].i = 0.f;
00503 /* Computing MAX */
00504                 r__1 = ulp * acoefa * anorm, r__2 = ulp * bcoefa * bnorm, 
00505                         r__1 = max(r__1,r__2);
00506                 dmin__ = dmax(r__1,safmin);
00507 
00508 /*                                              H */
00509 /*              Triangular solve of  (a A - b B)  y = 0 */
00510 
00511 /*                                      H */
00512 /*              (rowwise in  (a A - b B) , or columnwise in a A - b B) */
00513 
00514                 i__2 = *n;
00515                 for (j = je + 1; j <= i__2; ++j) {
00516 
00517 /*                 Compute */
00518 /*                       j-1 */
00519 /*                 SUM = sum  conjg( a*S(k,j) - b*P(k,j) )*x(k) */
00520 /*                       k=je */
00521 /*                 (Scale if necessary) */
00522 
00523                     temp = 1.f / xmax;
00524                     if (acoefa * rwork[j] + bcoefa * rwork[*n + j] > bignum * 
00525                             temp) {
00526                         i__3 = j - 1;
00527                         for (jr = je; jr <= i__3; ++jr) {
00528                             i__4 = jr;
00529                             i__5 = jr;
00530                             q__1.r = temp * work[i__5].r, q__1.i = temp * 
00531                                     work[i__5].i;
00532                             work[i__4].r = q__1.r, work[i__4].i = q__1.i;
00533 /* L70: */
00534                         }
00535                         xmax = 1.f;
00536                     }
00537                     suma.r = 0.f, suma.i = 0.f;
00538                     sumb.r = 0.f, sumb.i = 0.f;
00539 
00540                     i__3 = j - 1;
00541                     for (jr = je; jr <= i__3; ++jr) {
00542                         r_cnjg(&q__3, &s[jr + j * s_dim1]);
00543                         i__4 = jr;
00544                         q__2.r = q__3.r * work[i__4].r - q__3.i * work[i__4]
00545                                 .i, q__2.i = q__3.r * work[i__4].i + q__3.i * 
00546                                 work[i__4].r;
00547                         q__1.r = suma.r + q__2.r, q__1.i = suma.i + q__2.i;
00548                         suma.r = q__1.r, suma.i = q__1.i;
00549                         r_cnjg(&q__3, &p[jr + j * p_dim1]);
00550                         i__4 = jr;
00551                         q__2.r = q__3.r * work[i__4].r - q__3.i * work[i__4]
00552                                 .i, q__2.i = q__3.r * work[i__4].i + q__3.i * 
00553                                 work[i__4].r;
00554                         q__1.r = sumb.r + q__2.r, q__1.i = sumb.i + q__2.i;
00555                         sumb.r = q__1.r, sumb.i = q__1.i;
00556 /* L80: */
00557                     }
00558                     q__2.r = acoeff * suma.r, q__2.i = acoeff * suma.i;
00559                     r_cnjg(&q__4, &bcoeff);
00560                     q__3.r = q__4.r * sumb.r - q__4.i * sumb.i, q__3.i = 
00561                             q__4.r * sumb.i + q__4.i * sumb.r;
00562                     q__1.r = q__2.r - q__3.r, q__1.i = q__2.i - q__3.i;
00563                     sum.r = q__1.r, sum.i = q__1.i;
00564 
00565 /*                 Form x(j) = - SUM / conjg( a*S(j,j) - b*P(j,j) ) */
00566 
00567 /*                 with scaling and perturbation of the denominator */
00568 
00569                     i__3 = j + j * s_dim1;
00570                     q__3.r = acoeff * s[i__3].r, q__3.i = acoeff * s[i__3].i;
00571                     i__4 = j + j * p_dim1;
00572                     q__4.r = bcoeff.r * p[i__4].r - bcoeff.i * p[i__4].i, 
00573                             q__4.i = bcoeff.r * p[i__4].i + bcoeff.i * p[i__4]
00574                             .r;
00575                     q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
00576                     r_cnjg(&q__1, &q__2);
00577                     d__.r = q__1.r, d__.i = q__1.i;
00578                     if ((r__1 = d__.r, dabs(r__1)) + (r__2 = r_imag(&d__), 
00579                             dabs(r__2)) <= dmin__) {
00580                         q__1.r = dmin__, q__1.i = 0.f;
00581                         d__.r = q__1.r, d__.i = q__1.i;
00582                     }
00583 
00584                     if ((r__1 = d__.r, dabs(r__1)) + (r__2 = r_imag(&d__), 
00585                             dabs(r__2)) < 1.f) {
00586                         if ((r__1 = sum.r, dabs(r__1)) + (r__2 = r_imag(&sum),
00587                                  dabs(r__2)) >= bignum * ((r__3 = d__.r, dabs(
00588                                 r__3)) + (r__4 = r_imag(&d__), dabs(r__4)))) {
00589                             temp = 1.f / ((r__1 = sum.r, dabs(r__1)) + (r__2 =
00590                                      r_imag(&sum), dabs(r__2)));
00591                             i__3 = j - 1;
00592                             for (jr = je; jr <= i__3; ++jr) {
00593                                 i__4 = jr;
00594                                 i__5 = jr;
00595                                 q__1.r = temp * work[i__5].r, q__1.i = temp * 
00596                                         work[i__5].i;
00597                                 work[i__4].r = q__1.r, work[i__4].i = q__1.i;
00598 /* L90: */
00599                             }
00600                             xmax = temp * xmax;
00601                             q__1.r = temp * sum.r, q__1.i = temp * sum.i;
00602                             sum.r = q__1.r, sum.i = q__1.i;
00603                         }
00604                     }
00605                     i__3 = j;
00606                     q__2.r = -sum.r, q__2.i = -sum.i;
00607                     cladiv_(&q__1, &q__2, &d__);
00608                     work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00609 /* Computing MAX */
00610                     i__3 = j;
00611                     r__3 = xmax, r__4 = (r__1 = work[i__3].r, dabs(r__1)) + (
00612                             r__2 = r_imag(&work[j]), dabs(r__2));
00613                     xmax = dmax(r__3,r__4);
00614 /* L100: */
00615                 }
00616 
00617 /*              Back transform eigenvector if HOWMNY='B'. */
00618 
00619                 if (ilback) {
00620                     i__2 = *n + 1 - je;
00621                     cgemv_("N", n, &i__2, &c_b2, &vl[je * vl_dim1 + 1], ldvl, 
00622                             &work[je], &c__1, &c_b1, &work[*n + 1], &c__1);
00623                     isrc = 2;
00624                     ibeg = 1;
00625                 } else {
00626                     isrc = 1;
00627                     ibeg = je;
00628                 }
00629 
00630 /*              Copy and scale eigenvector into column of VL */
00631 
00632                 xmax = 0.f;
00633                 i__2 = *n;
00634                 for (jr = ibeg; jr <= i__2; ++jr) {
00635 /* Computing MAX */
00636                     i__3 = (isrc - 1) * *n + jr;
00637                     r__3 = xmax, r__4 = (r__1 = work[i__3].r, dabs(r__1)) + (
00638                             r__2 = r_imag(&work[(isrc - 1) * *n + jr]), dabs(
00639                             r__2));
00640                     xmax = dmax(r__3,r__4);
00641 /* L110: */
00642                 }
00643 
00644                 if (xmax > safmin) {
00645                     temp = 1.f / xmax;
00646                     i__2 = *n;
00647                     for (jr = ibeg; jr <= i__2; ++jr) {
00648                         i__3 = jr + ieig * vl_dim1;
00649                         i__4 = (isrc - 1) * *n + jr;
00650                         q__1.r = temp * work[i__4].r, q__1.i = temp * work[
00651                                 i__4].i;
00652                         vl[i__3].r = q__1.r, vl[i__3].i = q__1.i;
00653 /* L120: */
00654                     }
00655                 } else {
00656                     ibeg = *n + 1;
00657                 }
00658 
00659                 i__2 = ibeg - 1;
00660                 for (jr = 1; jr <= i__2; ++jr) {
00661                     i__3 = jr + ieig * vl_dim1;
00662                     vl[i__3].r = 0.f, vl[i__3].i = 0.f;
00663 /* L130: */
00664                 }
00665 
00666             }
00667 L140:
00668             ;
00669         }
00670     }
00671 
00672 /*     Right eigenvectors */
00673 
00674     if (compr) {
00675         ieig = im + 1;
00676 
00677 /*        Main loop over eigenvalues */
00678 
00679         for (je = *n; je >= 1; --je) {
00680             if (ilall) {
00681                 ilcomp = TRUE_;
00682             } else {
00683                 ilcomp = select[je];
00684             }
00685             if (ilcomp) {
00686                 --ieig;
00687 
00688                 i__1 = je + je * s_dim1;
00689                 i__2 = je + je * p_dim1;
00690                 if ((r__2 = s[i__1].r, dabs(r__2)) + (r__3 = r_imag(&s[je + 
00691                         je * s_dim1]), dabs(r__3)) <= safmin && (r__1 = p[
00692                         i__2].r, dabs(r__1)) <= safmin) {
00693 
00694 /*                 Singular matrix pencil -- return unit eigenvector */
00695 
00696                     i__1 = *n;
00697                     for (jr = 1; jr <= i__1; ++jr) {
00698                         i__2 = jr + ieig * vr_dim1;
00699                         vr[i__2].r = 0.f, vr[i__2].i = 0.f;
00700 /* L150: */
00701                     }
00702                     i__1 = ieig + ieig * vr_dim1;
00703                     vr[i__1].r = 1.f, vr[i__1].i = 0.f;
00704                     goto L250;
00705                 }
00706 
00707 /*              Non-singular eigenvalue: */
00708 /*              Compute coefficients  a  and  b  in */
00709 
00710 /*              ( a A - b B ) x  = 0 */
00711 
00712 /* Computing MAX */
00713                 i__1 = je + je * s_dim1;
00714                 i__2 = je + je * p_dim1;
00715                 r__4 = ((r__2 = s[i__1].r, dabs(r__2)) + (r__3 = r_imag(&s[je 
00716                         + je * s_dim1]), dabs(r__3))) * ascale, r__5 = (r__1 =
00717                          p[i__2].r, dabs(r__1)) * bscale, r__4 = max(r__4,
00718                         r__5);
00719                 temp = 1.f / dmax(r__4,safmin);
00720                 i__1 = je + je * s_dim1;
00721                 q__2.r = temp * s[i__1].r, q__2.i = temp * s[i__1].i;
00722                 q__1.r = ascale * q__2.r, q__1.i = ascale * q__2.i;
00723                 salpha.r = q__1.r, salpha.i = q__1.i;
00724                 i__1 = je + je * p_dim1;
00725                 sbeta = temp * p[i__1].r * bscale;
00726                 acoeff = sbeta * ascale;
00727                 q__1.r = bscale * salpha.r, q__1.i = bscale * salpha.i;
00728                 bcoeff.r = q__1.r, bcoeff.i = q__1.i;
00729 
00730 /*              Scale to avoid underflow */
00731 
00732                 lsa = dabs(sbeta) >= safmin && dabs(acoeff) < small;
00733                 lsb = (r__1 = salpha.r, dabs(r__1)) + (r__2 = r_imag(&salpha),
00734                          dabs(r__2)) >= safmin && (r__3 = bcoeff.r, dabs(r__3)
00735                         ) + (r__4 = r_imag(&bcoeff), dabs(r__4)) < small;
00736 
00737                 scale = 1.f;
00738                 if (lsa) {
00739                     scale = small / dabs(sbeta) * dmin(anorm,big);
00740                 }
00741                 if (lsb) {
00742 /* Computing MAX */
00743                     r__3 = scale, r__4 = small / ((r__1 = salpha.r, dabs(r__1)
00744                             ) + (r__2 = r_imag(&salpha), dabs(r__2))) * dmin(
00745                             bnorm,big);
00746                     scale = dmax(r__3,r__4);
00747                 }
00748                 if (lsa || lsb) {
00749 /* Computing MIN */
00750 /* Computing MAX */
00751                     r__5 = 1.f, r__6 = dabs(acoeff), r__5 = max(r__5,r__6), 
00752                             r__6 = (r__1 = bcoeff.r, dabs(r__1)) + (r__2 = 
00753                             r_imag(&bcoeff), dabs(r__2));
00754                     r__3 = scale, r__4 = 1.f / (safmin * dmax(r__5,r__6));
00755                     scale = dmin(r__3,r__4);
00756                     if (lsa) {
00757                         acoeff = ascale * (scale * sbeta);
00758                     } else {
00759                         acoeff = scale * acoeff;
00760                     }
00761                     if (lsb) {
00762                         q__2.r = scale * salpha.r, q__2.i = scale * salpha.i;
00763                         q__1.r = bscale * q__2.r, q__1.i = bscale * q__2.i;
00764                         bcoeff.r = q__1.r, bcoeff.i = q__1.i;
00765                     } else {
00766                         q__1.r = scale * bcoeff.r, q__1.i = scale * bcoeff.i;
00767                         bcoeff.r = q__1.r, bcoeff.i = q__1.i;
00768                     }
00769                 }
00770 
00771                 acoefa = dabs(acoeff);
00772                 bcoefa = (r__1 = bcoeff.r, dabs(r__1)) + (r__2 = r_imag(&
00773                         bcoeff), dabs(r__2));
00774                 xmax = 1.f;
00775                 i__1 = *n;
00776                 for (jr = 1; jr <= i__1; ++jr) {
00777                     i__2 = jr;
00778                     work[i__2].r = 0.f, work[i__2].i = 0.f;
00779 /* L160: */
00780                 }
00781                 i__1 = je;
00782                 work[i__1].r = 1.f, work[i__1].i = 0.f;
00783 /* Computing MAX */
00784                 r__1 = ulp * acoefa * anorm, r__2 = ulp * bcoefa * bnorm, 
00785                         r__1 = max(r__1,r__2);
00786                 dmin__ = dmax(r__1,safmin);
00787 
00788 /*              Triangular solve of  (a A - b B) x = 0  (columnwise) */
00789 
00790 /*              WORK(1:j-1) contains sums w, */
00791 /*              WORK(j+1:JE) contains x */
00792 
00793                 i__1 = je - 1;
00794                 for (jr = 1; jr <= i__1; ++jr) {
00795                     i__2 = jr;
00796                     i__3 = jr + je * s_dim1;
00797                     q__2.r = acoeff * s[i__3].r, q__2.i = acoeff * s[i__3].i;
00798                     i__4 = jr + je * p_dim1;
00799                     q__3.r = bcoeff.r * p[i__4].r - bcoeff.i * p[i__4].i, 
00800                             q__3.i = bcoeff.r * p[i__4].i + bcoeff.i * p[i__4]
00801                             .r;
00802                     q__1.r = q__2.r - q__3.r, q__1.i = q__2.i - q__3.i;
00803                     work[i__2].r = q__1.r, work[i__2].i = q__1.i;
00804 /* L170: */
00805                 }
00806                 i__1 = je;
00807                 work[i__1].r = 1.f, work[i__1].i = 0.f;
00808 
00809                 for (j = je - 1; j >= 1; --j) {
00810 
00811 /*                 Form x(j) := - w(j) / d */
00812 /*                 with scaling and perturbation of the denominator */
00813 
00814                     i__1 = j + j * s_dim1;
00815                     q__2.r = acoeff * s[i__1].r, q__2.i = acoeff * s[i__1].i;
00816                     i__2 = j + j * p_dim1;
00817                     q__3.r = bcoeff.r * p[i__2].r - bcoeff.i * p[i__2].i, 
00818                             q__3.i = bcoeff.r * p[i__2].i + bcoeff.i * p[i__2]
00819                             .r;
00820                     q__1.r = q__2.r - q__3.r, q__1.i = q__2.i - q__3.i;
00821                     d__.r = q__1.r, d__.i = q__1.i;
00822                     if ((r__1 = d__.r, dabs(r__1)) + (r__2 = r_imag(&d__), 
00823                             dabs(r__2)) <= dmin__) {
00824                         q__1.r = dmin__, q__1.i = 0.f;
00825                         d__.r = q__1.r, d__.i = q__1.i;
00826                     }
00827 
00828                     if ((r__1 = d__.r, dabs(r__1)) + (r__2 = r_imag(&d__), 
00829                             dabs(r__2)) < 1.f) {
00830                         i__1 = j;
00831                         if ((r__1 = work[i__1].r, dabs(r__1)) + (r__2 = 
00832                                 r_imag(&work[j]), dabs(r__2)) >= bignum * ((
00833                                 r__3 = d__.r, dabs(r__3)) + (r__4 = r_imag(&
00834                                 d__), dabs(r__4)))) {
00835                             i__1 = j;
00836                             temp = 1.f / ((r__1 = work[i__1].r, dabs(r__1)) + 
00837                                     (r__2 = r_imag(&work[j]), dabs(r__2)));
00838                             i__1 = je;
00839                             for (jr = 1; jr <= i__1; ++jr) {
00840                                 i__2 = jr;
00841                                 i__3 = jr;
00842                                 q__1.r = temp * work[i__3].r, q__1.i = temp * 
00843                                         work[i__3].i;
00844                                 work[i__2].r = q__1.r, work[i__2].i = q__1.i;
00845 /* L180: */
00846                             }
00847                         }
00848                     }
00849 
00850                     i__1 = j;
00851                     i__2 = j;
00852                     q__2.r = -work[i__2].r, q__2.i = -work[i__2].i;
00853                     cladiv_(&q__1, &q__2, &d__);
00854                     work[i__1].r = q__1.r, work[i__1].i = q__1.i;
00855 
00856                     if (j > 1) {
00857 
00858 /*                    w = w + x(j)*(a S(*,j) - b P(*,j) ) with scaling */
00859 
00860                         i__1 = j;
00861                         if ((r__1 = work[i__1].r, dabs(r__1)) + (r__2 = 
00862                                 r_imag(&work[j]), dabs(r__2)) > 1.f) {
00863                             i__1 = j;
00864                             temp = 1.f / ((r__1 = work[i__1].r, dabs(r__1)) + 
00865                                     (r__2 = r_imag(&work[j]), dabs(r__2)));
00866                             if (acoefa * rwork[j] + bcoefa * rwork[*n + j] >= 
00867                                     bignum * temp) {
00868                                 i__1 = je;
00869                                 for (jr = 1; jr <= i__1; ++jr) {
00870                                     i__2 = jr;
00871                                     i__3 = jr;
00872                                     q__1.r = temp * work[i__3].r, q__1.i = 
00873                                             temp * work[i__3].i;
00874                                     work[i__2].r = q__1.r, work[i__2].i = 
00875                                             q__1.i;
00876 /* L190: */
00877                                 }
00878                             }
00879                         }
00880 
00881                         i__1 = j;
00882                         q__1.r = acoeff * work[i__1].r, q__1.i = acoeff * 
00883                                 work[i__1].i;
00884                         ca.r = q__1.r, ca.i = q__1.i;
00885                         i__1 = j;
00886                         q__1.r = bcoeff.r * work[i__1].r - bcoeff.i * work[
00887                                 i__1].i, q__1.i = bcoeff.r * work[i__1].i + 
00888                                 bcoeff.i * work[i__1].r;
00889                         cb.r = q__1.r, cb.i = q__1.i;
00890                         i__1 = j - 1;
00891                         for (jr = 1; jr <= i__1; ++jr) {
00892                             i__2 = jr;
00893                             i__3 = jr;
00894                             i__4 = jr + j * s_dim1;
00895                             q__3.r = ca.r * s[i__4].r - ca.i * s[i__4].i, 
00896                                     q__3.i = ca.r * s[i__4].i + ca.i * s[i__4]
00897                                     .r;
00898                             q__2.r = work[i__3].r + q__3.r, q__2.i = work[
00899                                     i__3].i + q__3.i;
00900                             i__5 = jr + j * p_dim1;
00901                             q__4.r = cb.r * p[i__5].r - cb.i * p[i__5].i, 
00902                                     q__4.i = cb.r * p[i__5].i + cb.i * p[i__5]
00903                                     .r;
00904                             q__1.r = q__2.r - q__4.r, q__1.i = q__2.i - 
00905                                     q__4.i;
00906                             work[i__2].r = q__1.r, work[i__2].i = q__1.i;
00907 /* L200: */
00908                         }
00909                     }
00910 /* L210: */
00911                 }
00912 
00913 /*              Back transform eigenvector if HOWMNY='B'. */
00914 
00915                 if (ilback) {
00916                     cgemv_("N", n, &je, &c_b2, &vr[vr_offset], ldvr, &work[1], 
00917                              &c__1, &c_b1, &work[*n + 1], &c__1);
00918                     isrc = 2;
00919                     iend = *n;
00920                 } else {
00921                     isrc = 1;
00922                     iend = je;
00923                 }
00924 
00925 /*              Copy and scale eigenvector into column of VR */
00926 
00927                 xmax = 0.f;
00928                 i__1 = iend;
00929                 for (jr = 1; jr <= i__1; ++jr) {
00930 /* Computing MAX */
00931                     i__2 = (isrc - 1) * *n + jr;
00932                     r__3 = xmax, r__4 = (r__1 = work[i__2].r, dabs(r__1)) + (
00933                             r__2 = r_imag(&work[(isrc - 1) * *n + jr]), dabs(
00934                             r__2));
00935                     xmax = dmax(r__3,r__4);
00936 /* L220: */
00937                 }
00938 
00939                 if (xmax > safmin) {
00940                     temp = 1.f / xmax;
00941                     i__1 = iend;
00942                     for (jr = 1; jr <= i__1; ++jr) {
00943                         i__2 = jr + ieig * vr_dim1;
00944                         i__3 = (isrc - 1) * *n + jr;
00945                         q__1.r = temp * work[i__3].r, q__1.i = temp * work[
00946                                 i__3].i;
00947                         vr[i__2].r = q__1.r, vr[i__2].i = q__1.i;
00948 /* L230: */
00949                     }
00950                 } else {
00951                     iend = 0;
00952                 }
00953 
00954                 i__1 = *n;
00955                 for (jr = iend + 1; jr <= i__1; ++jr) {
00956                     i__2 = jr + ieig * vr_dim1;
00957                     vr[i__2].r = 0.f, vr[i__2].i = 0.f;
00958 /* L240: */
00959                 }
00960 
00961             }
00962 L250:
00963             ;
00964         }
00965     }
00966 
00967     return 0;
00968 
00969 /*     End of CTGEVC */
00970 
00971 } /* ctgevc_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:34