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


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