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


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