cgegv.c
Go to the documentation of this file.
00001 /* cgegv.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 static integer c_n1 = -1;
00022 static real c_b29 = 1.f;
00023 
00024 /* Subroutine */ int cgegv_(char *jobvl, char *jobvr, integer *n, complex *a, 
00025         integer *lda, complex *b, integer *ldb, complex *alpha, complex *beta, 
00026          complex *vl, integer *ldvl, complex *vr, integer *ldvr, complex *
00027         work, integer *lwork, real *rwork, integer *info)
00028 {
00029     /* System generated locals */
00030     integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1, 
00031             vr_offset, i__1, i__2, i__3, i__4;
00032     real r__1, r__2, r__3, r__4;
00033     complex q__1, q__2;
00034 
00035     /* Builtin functions */
00036     double r_imag(complex *);
00037 
00038     /* Local variables */
00039     integer jc, nb, in, jr, nb1, nb2, nb3, ihi, ilo;
00040     real eps;
00041     logical ilv;
00042     real absb, anrm, bnrm;
00043     integer itau;
00044     real temp;
00045     logical ilvl, ilvr;
00046     integer lopt;
00047     real anrm1, anrm2, bnrm1, bnrm2, absai, scale, absar, sbeta;
00048     extern logical lsame_(char *, char *);
00049     integer ileft, iinfo, icols, iwork, irows;
00050     extern /* Subroutine */ int cggbak_(char *, char *, integer *, integer *, 
00051             integer *, real *, real *, integer *, complex *, integer *, 
00052             integer *), cggbal_(char *, integer *, complex *, 
00053             integer *, complex *, integer *, integer *, integer *, real *, 
00054             real *, real *, integer *);
00055     extern doublereal clange_(char *, integer *, integer *, complex *, 
00056             integer *, real *);
00057     extern /* Subroutine */ int cgghrd_(char *, char *, integer *, integer *, 
00058             integer *, complex *, integer *, complex *, integer *, complex *, 
00059             integer *, complex *, integer *, integer *);
00060     real salfai;
00061     extern /* Subroutine */ int clascl_(char *, integer *, integer *, real *, 
00062             real *, integer *, integer *, complex *, integer *, integer *), cgeqrf_(integer *, integer *, complex *, integer *, 
00063             complex *, complex *, integer *, integer *);
00064     real salfar;
00065     extern doublereal slamch_(char *);
00066     extern /* Subroutine */ int clacpy_(char *, integer *, integer *, complex 
00067             *, integer *, complex *, integer *), claset_(char *, 
00068             integer *, integer *, complex *, complex *, complex *, integer *);
00069     real safmin;
00070     extern /* Subroutine */ int ctgevc_(char *, char *, logical *, integer *, 
00071             complex *, integer *, complex *, integer *, complex *, integer *, 
00072             complex *, integer *, integer *, integer *, complex *, real *, 
00073             integer *);
00074     real safmax;
00075     char chtemp[1];
00076     logical ldumma[1];
00077     extern /* Subroutine */ int chgeqz_(char *, char *, char *, integer *, 
00078             integer *, integer *, complex *, integer *, complex *, integer *, 
00079             complex *, complex *, complex *, integer *, complex *, integer *, 
00080             complex *, integer *, real *, integer *), 
00081             xerbla_(char *, integer *);
00082     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00083             integer *, integer *);
00084     integer ijobvl, iright;
00085     logical ilimit;
00086     integer ijobvr;
00087     extern /* Subroutine */ int cungqr_(integer *, integer *, integer *, 
00088             complex *, integer *, complex *, complex *, integer *, integer *);
00089     integer lwkmin;
00090     extern /* Subroutine */ int cunmqr_(char *, char *, integer *, integer *, 
00091             integer *, complex *, integer *, complex *, complex *, integer *, 
00092             complex *, integer *, integer *);
00093     integer irwork, lwkopt;
00094     logical lquery;
00095 
00096 
00097 /*  -- LAPACK driver routine (version 3.2) -- */
00098 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00099 /*     November 2006 */
00100 
00101 /*     .. Scalar Arguments .. */
00102 /*     .. */
00103 /*     .. Array Arguments .. */
00104 /*     .. */
00105 
00106 /*  Purpose */
00107 /*  ======= */
00108 
00109 /*  This routine is deprecated and has been replaced by routine CGGEV. */
00110 
00111 /*  CGEGV computes the eigenvalues and, optionally, the left and/or right */
00112 /*  eigenvectors of a complex matrix pair (A,B). */
00113 /*  Given two square matrices A and B, */
00114 /*  the generalized nonsymmetric eigenvalue problem (GNEP) is to find the */
00115 /*  eigenvalues lambda and corresponding (non-zero) eigenvectors x such */
00116 /*  that */
00117 /*     A*x = lambda*B*x. */
00118 
00119 /*  An alternate form is to find the eigenvalues mu and corresponding */
00120 /*  eigenvectors y such that */
00121 /*     mu*A*y = B*y. */
00122 
00123 /*  These two forms are equivalent with mu = 1/lambda and x = y if */
00124 /*  neither lambda nor mu is zero.  In order to deal with the case that */
00125 /*  lambda or mu is zero or small, two values alpha and beta are returned */
00126 /*  for each eigenvalue, such that lambda = alpha/beta and */
00127 /*  mu = beta/alpha. */
00128 
00129 /*  The vectors x and y in the above equations are right eigenvectors of */
00130 /*  the matrix pair (A,B).  Vectors u and v satisfying */
00131 /*     u**H*A = lambda*u**H*B  or  mu*v**H*A = v**H*B */
00132 /*  are left eigenvectors of (A,B). */
00133 
00134 /*  Note: this routine performs "full balancing" on A and B -- see */
00135 /*  "Further Details", below. */
00136 
00137 /*  Arguments */
00138 /*  ========= */
00139 
00140 /*  JOBVL   (input) CHARACTER*1 */
00141 /*          = 'N':  do not compute the left generalized eigenvectors; */
00142 /*          = 'V':  compute the left generalized eigenvectors (returned */
00143 /*                  in VL). */
00144 
00145 /*  JOBVR   (input) CHARACTER*1 */
00146 /*          = 'N':  do not compute the right generalized eigenvectors; */
00147 /*          = 'V':  compute the right generalized eigenvectors (returned */
00148 /*                  in VR). */
00149 
00150 /*  N       (input) INTEGER */
00151 /*          The order of the matrices A, B, VL, and VR.  N >= 0. */
00152 
00153 /*  A       (input/output) COMPLEX array, dimension (LDA, N) */
00154 /*          On entry, the matrix A. */
00155 /*          If JOBVL = 'V' or JOBVR = 'V', then on exit A */
00156 /*          contains the Schur form of A from the generalized Schur */
00157 /*          factorization of the pair (A,B) after balancing.  If no */
00158 /*          eigenvectors were computed, then only the diagonal elements */
00159 /*          of the Schur form will be correct.  See CGGHRD and CHGEQZ */
00160 /*          for details. */
00161 
00162 /*  LDA     (input) INTEGER */
00163 /*          The leading dimension of A.  LDA >= max(1,N). */
00164 
00165 /*  B       (input/output) COMPLEX array, dimension (LDB, N) */
00166 /*          On entry, the matrix B. */
00167 /*          If JOBVL = 'V' or JOBVR = 'V', then on exit B contains the */
00168 /*          upper triangular matrix obtained from B in the generalized */
00169 /*          Schur factorization of the pair (A,B) after balancing. */
00170 /*          If no eigenvectors were computed, then only the diagonal */
00171 /*          elements of B will be correct.  See CGGHRD and CHGEQZ for */
00172 /*          details. */
00173 
00174 /*  LDB     (input) INTEGER */
00175 /*          The leading dimension of B.  LDB >= max(1,N). */
00176 
00177 /*  ALPHA   (output) COMPLEX array, dimension (N) */
00178 /*          The complex scalars alpha that define the eigenvalues of */
00179 /*          GNEP. */
00180 
00181 /*  BETA    (output) COMPLEX array, dimension (N) */
00182 /*          The complex scalars beta that define the eigenvalues of GNEP. */
00183 
00184 /*          Together, the quantities alpha = ALPHA(j) and beta = BETA(j) */
00185 /*          represent the j-th eigenvalue of the matrix pair (A,B), in */
00186 /*          one of the forms lambda = alpha/beta or mu = beta/alpha. */
00187 /*          Since either lambda or mu may overflow, they should not, */
00188 /*          in general, be computed. */
00189 
00190 /*  VL      (output) COMPLEX array, dimension (LDVL,N) */
00191 /*          If JOBVL = 'V', the left eigenvectors u(j) are stored */
00192 /*          in the columns of VL, in the same order as their eigenvalues. */
00193 /*          Each eigenvector is scaled so that its largest component has */
00194 /*          abs(real part) + abs(imag. part) = 1, except for eigenvectors */
00195 /*          corresponding to an eigenvalue with alpha = beta = 0, which */
00196 /*          are set to zero. */
00197 /*          Not referenced if JOBVL = 'N'. */
00198 
00199 /*  LDVL    (input) INTEGER */
00200 /*          The leading dimension of the matrix VL. LDVL >= 1, and */
00201 /*          if JOBVL = 'V', LDVL >= N. */
00202 
00203 /*  VR      (output) COMPLEX array, dimension (LDVR,N) */
00204 /*          If JOBVR = 'V', the right eigenvectors x(j) are stored */
00205 /*          in the columns of VR, in the same order as their eigenvalues. */
00206 /*          Each eigenvector is scaled so that its largest component has */
00207 /*          abs(real part) + abs(imag. part) = 1, except for eigenvectors */
00208 /*          corresponding to an eigenvalue with alpha = beta = 0, which */
00209 /*          are set to zero. */
00210 /*          Not referenced if JOBVR = 'N'. */
00211 
00212 /*  LDVR    (input) INTEGER */
00213 /*          The leading dimension of the matrix VR. LDVR >= 1, and */
00214 /*          if JOBVR = 'V', LDVR >= N. */
00215 
00216 /*  WORK    (workspace/output) COMPLEX array, dimension (MAX(1,LWORK)) */
00217 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00218 
00219 /*  LWORK   (input) INTEGER */
00220 /*          The dimension of the array WORK.  LWORK >= max(1,2*N). */
00221 /*          For good performance, LWORK must generally be larger. */
00222 /*          To compute the optimal value of LWORK, call ILAENV to get */
00223 /*          blocksizes (for CGEQRF, CUNMQR, and CUNGQR.)  Then compute: */
00224 /*          NB  -- MAX of the blocksizes for CGEQRF, CUNMQR, and CUNGQR; */
00225 /*          The optimal LWORK is  MAX( 2*N, N*(NB+1) ). */
00226 
00227 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00228 /*          only calculates the optimal size of the WORK array, returns */
00229 /*          this value as the first entry of the WORK array, and no error */
00230 /*          message related to LWORK is issued by XERBLA. */
00231 
00232 /*  RWORK   (workspace/output) REAL array, dimension (8*N) */
00233 
00234 /*  INFO    (output) INTEGER */
00235 /*          = 0:  successful exit */
00236 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00237 /*          =1,...,N: */
00238 /*                The QZ iteration failed.  No eigenvectors have been */
00239 /*                calculated, but ALPHA(j) and BETA(j) should be */
00240 /*                correct for j=INFO+1,...,N. */
00241 /*          > N:  errors that usually indicate LAPACK problems: */
00242 /*                =N+1: error return from CGGBAL */
00243 /*                =N+2: error return from CGEQRF */
00244 /*                =N+3: error return from CUNMQR */
00245 /*                =N+4: error return from CUNGQR */
00246 /*                =N+5: error return from CGGHRD */
00247 /*                =N+6: error return from CHGEQZ (other than failed */
00248 /*                                               iteration) */
00249 /*                =N+7: error return from CTGEVC */
00250 /*                =N+8: error return from CGGBAK (computing VL) */
00251 /*                =N+9: error return from CGGBAK (computing VR) */
00252 /*                =N+10: error return from CLASCL (various calls) */
00253 
00254 /*  Further Details */
00255 /*  =============== */
00256 
00257 /*  Balancing */
00258 /*  --------- */
00259 
00260 /*  This driver calls CGGBAL to both permute and scale rows and columns */
00261 /*  of A and B.  The permutations PL and PR are chosen so that PL*A*PR */
00262 /*  and PL*B*R will be upper triangular except for the diagonal blocks */
00263 /*  A(i:j,i:j) and B(i:j,i:j), with i and j as close together as */
00264 /*  possible.  The diagonal scaling matrices DL and DR are chosen so */
00265 /*  that the pair  DL*PL*A*PR*DR, DL*PL*B*PR*DR have elements close to */
00266 /*  one (except for the elements that start out zero.) */
00267 
00268 /*  After the eigenvalues and eigenvectors of the balanced matrices */
00269 /*  have been computed, CGGBAK transforms the eigenvectors back to what */
00270 /*  they would have been (in perfect arithmetic) if they had not been */
00271 /*  balanced. */
00272 
00273 /*  Contents of A and B on Exit */
00274 /*  -------- -- - --- - -- ---- */
00275 
00276 /*  If any eigenvectors are computed (either JOBVL='V' or JOBVR='V' or */
00277 /*  both), then on exit the arrays A and B will contain the complex Schur */
00278 /*  form[*] of the "balanced" versions of A and B.  If no eigenvectors */
00279 /*  are computed, then only the diagonal blocks will be correct. */
00280 
00281 /*  [*] In other words, upper triangular form. */
00282 
00283 /*  ===================================================================== */
00284 
00285 /*     .. Parameters .. */
00286 /*     .. */
00287 /*     .. Local Scalars .. */
00288 /*     .. */
00289 /*     .. Local Arrays .. */
00290 /*     .. */
00291 /*     .. External Subroutines .. */
00292 /*     .. */
00293 /*     .. External Functions .. */
00294 /*     .. */
00295 /*     .. Intrinsic Functions .. */
00296 /*     .. */
00297 /*     .. Statement Functions .. */
00298 /*     .. */
00299 /*     .. Statement Function definitions .. */
00300 /*     .. */
00301 /*     .. Executable Statements .. */
00302 
00303 /*     Decode the input arguments */
00304 
00305     /* Parameter adjustments */
00306     a_dim1 = *lda;
00307     a_offset = 1 + a_dim1;
00308     a -= a_offset;
00309     b_dim1 = *ldb;
00310     b_offset = 1 + b_dim1;
00311     b -= b_offset;
00312     --alpha;
00313     --beta;
00314     vl_dim1 = *ldvl;
00315     vl_offset = 1 + vl_dim1;
00316     vl -= vl_offset;
00317     vr_dim1 = *ldvr;
00318     vr_offset = 1 + vr_dim1;
00319     vr -= vr_offset;
00320     --work;
00321     --rwork;
00322 
00323     /* Function Body */
00324     if (lsame_(jobvl, "N")) {
00325         ijobvl = 1;
00326         ilvl = FALSE_;
00327     } else if (lsame_(jobvl, "V")) {
00328         ijobvl = 2;
00329         ilvl = TRUE_;
00330     } else {
00331         ijobvl = -1;
00332         ilvl = FALSE_;
00333     }
00334 
00335     if (lsame_(jobvr, "N")) {
00336         ijobvr = 1;
00337         ilvr = FALSE_;
00338     } else if (lsame_(jobvr, "V")) {
00339         ijobvr = 2;
00340         ilvr = TRUE_;
00341     } else {
00342         ijobvr = -1;
00343         ilvr = FALSE_;
00344     }
00345     ilv = ilvl || ilvr;
00346 
00347 /*     Test the input arguments */
00348 
00349 /* Computing MAX */
00350     i__1 = *n << 1;
00351     lwkmin = max(i__1,1);
00352     lwkopt = lwkmin;
00353     work[1].r = (real) lwkopt, work[1].i = 0.f;
00354     lquery = *lwork == -1;
00355     *info = 0;
00356     if (ijobvl <= 0) {
00357         *info = -1;
00358     } else if (ijobvr <= 0) {
00359         *info = -2;
00360     } else if (*n < 0) {
00361         *info = -3;
00362     } else if (*lda < max(1,*n)) {
00363         *info = -5;
00364     } else if (*ldb < max(1,*n)) {
00365         *info = -7;
00366     } else if (*ldvl < 1 || ilvl && *ldvl < *n) {
00367         *info = -11;
00368     } else if (*ldvr < 1 || ilvr && *ldvr < *n) {
00369         *info = -13;
00370     } else if (*lwork < lwkmin && ! lquery) {
00371         *info = -15;
00372     }
00373 
00374     if (*info == 0) {
00375         nb1 = ilaenv_(&c__1, "CGEQRF", " ", n, n, &c_n1, &c_n1);
00376         nb2 = ilaenv_(&c__1, "CUNMQR", " ", n, n, n, &c_n1);
00377         nb3 = ilaenv_(&c__1, "CUNGQR", " ", n, n, n, &c_n1);
00378 /* Computing MAX */
00379         i__1 = max(nb1,nb2);
00380         nb = max(i__1,nb3);
00381 /* Computing MAX */
00382         i__1 = *n << 1, i__2 = *n * (nb + 1);
00383         lopt = max(i__1,i__2);
00384         work[1].r = (real) lopt, work[1].i = 0.f;
00385     }
00386 
00387     if (*info != 0) {
00388         i__1 = -(*info);
00389         xerbla_("CGEGV ", &i__1);
00390         return 0;
00391     } else if (lquery) {
00392         return 0;
00393     }
00394 
00395 /*     Quick return if possible */
00396 
00397     if (*n == 0) {
00398         return 0;
00399     }
00400 
00401 /*     Get machine constants */
00402 
00403     eps = slamch_("E") * slamch_("B");
00404     safmin = slamch_("S");
00405     safmin += safmin;
00406     safmax = 1.f / safmin;
00407 
00408 /*     Scale A */
00409 
00410     anrm = clange_("M", n, n, &a[a_offset], lda, &rwork[1]);
00411     anrm1 = anrm;
00412     anrm2 = 1.f;
00413     if (anrm < 1.f) {
00414         if (safmax * anrm < 1.f) {
00415             anrm1 = safmin;
00416             anrm2 = safmax * anrm;
00417         }
00418     }
00419 
00420     if (anrm > 0.f) {
00421         clascl_("G", &c_n1, &c_n1, &anrm, &c_b29, n, n, &a[a_offset], lda, &
00422                 iinfo);
00423         if (iinfo != 0) {
00424             *info = *n + 10;
00425             return 0;
00426         }
00427     }
00428 
00429 /*     Scale B */
00430 
00431     bnrm = clange_("M", n, n, &b[b_offset], ldb, &rwork[1]);
00432     bnrm1 = bnrm;
00433     bnrm2 = 1.f;
00434     if (bnrm < 1.f) {
00435         if (safmax * bnrm < 1.f) {
00436             bnrm1 = safmin;
00437             bnrm2 = safmax * bnrm;
00438         }
00439     }
00440 
00441     if (bnrm > 0.f) {
00442         clascl_("G", &c_n1, &c_n1, &bnrm, &c_b29, n, n, &b[b_offset], ldb, &
00443                 iinfo);
00444         if (iinfo != 0) {
00445             *info = *n + 10;
00446             return 0;
00447         }
00448     }
00449 
00450 /*     Permute the matrix to make it more nearly triangular */
00451 /*     Also "balance" the matrix. */
00452 
00453     ileft = 1;
00454     iright = *n + 1;
00455     irwork = iright + *n;
00456     cggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &rwork[
00457             ileft], &rwork[iright], &rwork[irwork], &iinfo);
00458     if (iinfo != 0) {
00459         *info = *n + 1;
00460         goto L80;
00461     }
00462 
00463 /*     Reduce B to triangular form, and initialize VL and/or VR */
00464 
00465     irows = ihi + 1 - ilo;
00466     if (ilv) {
00467         icols = *n + 1 - ilo;
00468     } else {
00469         icols = irows;
00470     }
00471     itau = 1;
00472     iwork = itau + irows;
00473     i__1 = *lwork + 1 - iwork;
00474     cgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
00475             iwork], &i__1, &iinfo);
00476     if (iinfo >= 0) {
00477 /* Computing MAX */
00478         i__3 = iwork;
00479         i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
00480         lwkopt = max(i__1,i__2);
00481     }
00482     if (iinfo != 0) {
00483         *info = *n + 2;
00484         goto L80;
00485     }
00486 
00487     i__1 = *lwork + 1 - iwork;
00488     cunmqr_("L", "C", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
00489             work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwork], &i__1, &
00490             iinfo);
00491     if (iinfo >= 0) {
00492 /* Computing MAX */
00493         i__3 = iwork;
00494         i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
00495         lwkopt = max(i__1,i__2);
00496     }
00497     if (iinfo != 0) {
00498         *info = *n + 3;
00499         goto L80;
00500     }
00501 
00502     if (ilvl) {
00503         claset_("Full", n, n, &c_b1, &c_b2, &vl[vl_offset], ldvl);
00504         i__1 = irows - 1;
00505         i__2 = irows - 1;
00506         clacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vl[ilo + 
00507                 1 + ilo * vl_dim1], ldvl);
00508         i__1 = *lwork + 1 - iwork;
00509         cungqr_(&irows, &irows, &irows, &vl[ilo + ilo * vl_dim1], ldvl, &work[
00510                 itau], &work[iwork], &i__1, &iinfo);
00511         if (iinfo >= 0) {
00512 /* Computing MAX */
00513             i__3 = iwork;
00514             i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
00515             lwkopt = max(i__1,i__2);
00516         }
00517         if (iinfo != 0) {
00518             *info = *n + 4;
00519             goto L80;
00520         }
00521     }
00522 
00523     if (ilvr) {
00524         claset_("Full", n, n, &c_b1, &c_b2, &vr[vr_offset], ldvr);
00525     }
00526 
00527 /*     Reduce to generalized Hessenberg form */
00528 
00529     if (ilv) {
00530 
00531 /*        Eigenvectors requested -- work on whole matrix. */
00532 
00533         cgghrd_(jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset], 
00534                 ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &iinfo);
00535     } else {
00536         cgghrd_("N", "N", &irows, &c__1, &irows, &a[ilo + ilo * a_dim1], lda, 
00537                 &b[ilo + ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[
00538                 vr_offset], ldvr, &iinfo);
00539     }
00540     if (iinfo != 0) {
00541         *info = *n + 5;
00542         goto L80;
00543     }
00544 
00545 /*     Perform QZ algorithm */
00546 
00547     iwork = itau;
00548     if (ilv) {
00549         *(unsigned char *)chtemp = 'S';
00550     } else {
00551         *(unsigned char *)chtemp = 'E';
00552     }
00553     i__1 = *lwork + 1 - iwork;
00554     chgeqz_(chtemp, jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[
00555             b_offset], ldb, &alpha[1], &beta[1], &vl[vl_offset], ldvl, &vr[
00556             vr_offset], ldvr, &work[iwork], &i__1, &rwork[irwork], &iinfo);
00557     if (iinfo >= 0) {
00558 /* Computing MAX */
00559         i__3 = iwork;
00560         i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
00561         lwkopt = max(i__1,i__2);
00562     }
00563     if (iinfo != 0) {
00564         if (iinfo > 0 && iinfo <= *n) {
00565             *info = iinfo;
00566         } else if (iinfo > *n && iinfo <= *n << 1) {
00567             *info = iinfo - *n;
00568         } else {
00569             *info = *n + 6;
00570         }
00571         goto L80;
00572     }
00573 
00574     if (ilv) {
00575 
00576 /*        Compute Eigenvectors */
00577 
00578         if (ilvl) {
00579             if (ilvr) {
00580                 *(unsigned char *)chtemp = 'B';
00581             } else {
00582                 *(unsigned char *)chtemp = 'L';
00583             }
00584         } else {
00585             *(unsigned char *)chtemp = 'R';
00586         }
00587 
00588         ctgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset], ldb, 
00589                 &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &work[
00590                 iwork], &rwork[irwork], &iinfo);
00591         if (iinfo != 0) {
00592             *info = *n + 7;
00593             goto L80;
00594         }
00595 
00596 /*        Undo balancing on VL and VR, rescale */
00597 
00598         if (ilvl) {
00599             cggbak_("P", "L", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, 
00600                      &vl[vl_offset], ldvl, &iinfo);
00601             if (iinfo != 0) {
00602                 *info = *n + 8;
00603                 goto L80;
00604             }
00605             i__1 = *n;
00606             for (jc = 1; jc <= i__1; ++jc) {
00607                 temp = 0.f;
00608                 i__2 = *n;
00609                 for (jr = 1; jr <= i__2; ++jr) {
00610 /* Computing MAX */
00611                     i__3 = jr + jc * vl_dim1;
00612                     r__3 = temp, r__4 = (r__1 = vl[i__3].r, dabs(r__1)) + (
00613                             r__2 = r_imag(&vl[jr + jc * vl_dim1]), dabs(r__2))
00614                             ;
00615                     temp = dmax(r__3,r__4);
00616 /* L10: */
00617                 }
00618                 if (temp < safmin) {
00619                     goto L30;
00620                 }
00621                 temp = 1.f / temp;
00622                 i__2 = *n;
00623                 for (jr = 1; jr <= i__2; ++jr) {
00624                     i__3 = jr + jc * vl_dim1;
00625                     i__4 = jr + jc * vl_dim1;
00626                     q__1.r = temp * vl[i__4].r, q__1.i = temp * vl[i__4].i;
00627                     vl[i__3].r = q__1.r, vl[i__3].i = q__1.i;
00628 /* L20: */
00629                 }
00630 L30:
00631                 ;
00632             }
00633         }
00634         if (ilvr) {
00635             cggbak_("P", "R", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, 
00636                      &vr[vr_offset], ldvr, &iinfo);
00637             if (iinfo != 0) {
00638                 *info = *n + 9;
00639                 goto L80;
00640             }
00641             i__1 = *n;
00642             for (jc = 1; jc <= i__1; ++jc) {
00643                 temp = 0.f;
00644                 i__2 = *n;
00645                 for (jr = 1; jr <= i__2; ++jr) {
00646 /* Computing MAX */
00647                     i__3 = jr + jc * vr_dim1;
00648                     r__3 = temp, r__4 = (r__1 = vr[i__3].r, dabs(r__1)) + (
00649                             r__2 = r_imag(&vr[jr + jc * vr_dim1]), dabs(r__2))
00650                             ;
00651                     temp = dmax(r__3,r__4);
00652 /* L40: */
00653                 }
00654                 if (temp < safmin) {
00655                     goto L60;
00656                 }
00657                 temp = 1.f / temp;
00658                 i__2 = *n;
00659                 for (jr = 1; jr <= i__2; ++jr) {
00660                     i__3 = jr + jc * vr_dim1;
00661                     i__4 = jr + jc * vr_dim1;
00662                     q__1.r = temp * vr[i__4].r, q__1.i = temp * vr[i__4].i;
00663                     vr[i__3].r = q__1.r, vr[i__3].i = q__1.i;
00664 /* L50: */
00665                 }
00666 L60:
00667                 ;
00668             }
00669         }
00670 
00671 /*        End of eigenvector calculation */
00672 
00673     }
00674 
00675 /*     Undo scaling in alpha, beta */
00676 
00677 /*     Note: this does not give the alpha and beta for the unscaled */
00678 /*     problem. */
00679 
00680 /*     Un-scaling is limited to avoid underflow in alpha and beta */
00681 /*     if they are significant. */
00682 
00683     i__1 = *n;
00684     for (jc = 1; jc <= i__1; ++jc) {
00685         i__2 = jc;
00686         absar = (r__1 = alpha[i__2].r, dabs(r__1));
00687         absai = (r__1 = r_imag(&alpha[jc]), dabs(r__1));
00688         i__2 = jc;
00689         absb = (r__1 = beta[i__2].r, dabs(r__1));
00690         i__2 = jc;
00691         salfar = anrm * alpha[i__2].r;
00692         salfai = anrm * r_imag(&alpha[jc]);
00693         i__2 = jc;
00694         sbeta = bnrm * beta[i__2].r;
00695         ilimit = FALSE_;
00696         scale = 1.f;
00697 
00698 /*        Check for significant underflow in imaginary part of ALPHA */
00699 
00700 /* Computing MAX */
00701         r__1 = safmin, r__2 = eps * absar, r__1 = max(r__1,r__2), r__2 = eps *
00702                  absb;
00703         if (dabs(salfai) < safmin && absai >= dmax(r__1,r__2)) {
00704             ilimit = TRUE_;
00705 /* Computing MAX */
00706             r__1 = safmin, r__2 = anrm2 * absai;
00707             scale = safmin / anrm1 / dmax(r__1,r__2);
00708         }
00709 
00710 /*        Check for significant underflow in real part of ALPHA */
00711 
00712 /* Computing MAX */
00713         r__1 = safmin, r__2 = eps * absai, r__1 = max(r__1,r__2), r__2 = eps *
00714                  absb;
00715         if (dabs(salfar) < safmin && absar >= dmax(r__1,r__2)) {
00716             ilimit = TRUE_;
00717 /* Computing MAX */
00718 /* Computing MAX */
00719             r__3 = safmin, r__4 = anrm2 * absar;
00720             r__1 = scale, r__2 = safmin / anrm1 / dmax(r__3,r__4);
00721             scale = dmax(r__1,r__2);
00722         }
00723 
00724 /*        Check for significant underflow in BETA */
00725 
00726 /* Computing MAX */
00727         r__1 = safmin, r__2 = eps * absar, r__1 = max(r__1,r__2), r__2 = eps *
00728                  absai;
00729         if (dabs(sbeta) < safmin && absb >= dmax(r__1,r__2)) {
00730             ilimit = TRUE_;
00731 /* Computing MAX */
00732 /* Computing MAX */
00733             r__3 = safmin, r__4 = bnrm2 * absb;
00734             r__1 = scale, r__2 = safmin / bnrm1 / dmax(r__3,r__4);
00735             scale = dmax(r__1,r__2);
00736         }
00737 
00738 /*        Check for possible overflow when limiting scaling */
00739 
00740         if (ilimit) {
00741 /* Computing MAX */
00742             r__1 = dabs(salfar), r__2 = dabs(salfai), r__1 = max(r__1,r__2), 
00743                     r__2 = dabs(sbeta);
00744             temp = scale * safmin * dmax(r__1,r__2);
00745             if (temp > 1.f) {
00746                 scale /= temp;
00747             }
00748             if (scale < 1.f) {
00749                 ilimit = FALSE_;
00750             }
00751         }
00752 
00753 /*        Recompute un-scaled ALPHA, BETA if necessary. */
00754 
00755         if (ilimit) {
00756             i__2 = jc;
00757             salfar = scale * alpha[i__2].r * anrm;
00758             salfai = scale * r_imag(&alpha[jc]) * anrm;
00759             i__2 = jc;
00760             q__2.r = scale * beta[i__2].r, q__2.i = scale * beta[i__2].i;
00761             q__1.r = bnrm * q__2.r, q__1.i = bnrm * q__2.i;
00762             sbeta = q__1.r;
00763         }
00764         i__2 = jc;
00765         q__1.r = salfar, q__1.i = salfai;
00766         alpha[i__2].r = q__1.r, alpha[i__2].i = q__1.i;
00767         i__2 = jc;
00768         beta[i__2].r = sbeta, beta[i__2].i = 0.f;
00769 /* L70: */
00770     }
00771 
00772 L80:
00773     work[1].r = (real) lwkopt, work[1].i = 0.f;
00774 
00775     return 0;
00776 
00777 /*     End of CGEGV */
00778 
00779 } /* cgegv_ */


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