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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:43