sgeevx.c
Go to the documentation of this file.
00001 /* sgeevx.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__0 = 0;
00020 static integer c_n1 = -1;
00021 
00022 /* Subroutine */ int sgeevx_(char *balanc, char *jobvl, char *jobvr, char *
00023         sense, integer *n, real *a, integer *lda, real *wr, real *wi, real *
00024         vl, integer *ldvl, real *vr, integer *ldvr, integer *ilo, integer *
00025         ihi, real *scale, real *abnrm, real *rconde, real *rcondv, real *work, 
00026          integer *lwork, integer *iwork, integer *info)
00027 {
00028     /* System generated locals */
00029     integer a_dim1, a_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1, 
00030             i__2, i__3;
00031     real r__1, r__2;
00032 
00033     /* Builtin functions */
00034     double sqrt(doublereal);
00035 
00036     /* Local variables */
00037     integer i__, k;
00038     real r__, cs, sn;
00039     char job[1];
00040     real scl, dum[1], eps;
00041     char side[1];
00042     real anrm;
00043     integer ierr, itau, iwrk, nout;
00044     extern /* Subroutine */ int srot_(integer *, real *, integer *, real *, 
00045             integer *, real *, real *);
00046     extern doublereal snrm2_(integer *, real *, integer *);
00047     integer icond;
00048     extern logical lsame_(char *, char *);
00049     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
00050     extern doublereal slapy2_(real *, real *);
00051     extern /* Subroutine */ int slabad_(real *, real *);
00052     logical scalea;
00053     real cscale;
00054     extern /* Subroutine */ int sgebak_(char *, char *, integer *, integer *, 
00055             integer *, real *, integer *, real *, integer *, integer *), sgebal_(char *, integer *, real *, integer *, 
00056             integer *, integer *, real *, integer *);
00057     extern doublereal slamch_(char *), slange_(char *, integer *, 
00058             integer *, real *, integer *, real *);
00059     extern /* Subroutine */ int sgehrd_(integer *, integer *, integer *, real 
00060             *, integer *, real *, real *, integer *, integer *), xerbla_(char 
00061             *, integer *);
00062     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00063             integer *, integer *);
00064     logical select[1];
00065     real bignum;
00066     extern /* Subroutine */ int slascl_(char *, integer *, integer *, real *, 
00067             real *, integer *, integer *, real *, integer *, integer *);
00068     extern integer isamax_(integer *, real *, integer *);
00069     extern /* Subroutine */ int slacpy_(char *, integer *, integer *, real *, 
00070             integer *, real *, integer *), slartg_(real *, real *, 
00071             real *, real *, real *), sorghr_(integer *, integer *, integer *, 
00072             real *, integer *, real *, real *, integer *, integer *), shseqr_(
00073             char *, char *, integer *, integer *, integer *, real *, integer *
00074 , real *, real *, real *, integer *, real *, integer *, integer *), strevc_(char *, char *, logical *, integer *, 
00075             real *, integer *, real *, integer *, real *, integer *, integer *
00076 , integer *, real *, integer *);
00077     integer minwrk, maxwrk;
00078     extern /* Subroutine */ int strsna_(char *, char *, logical *, integer *, 
00079             real *, integer *, real *, integer *, real *, integer *, real *, 
00080             real *, integer *, integer *, real *, integer *, integer *, 
00081             integer *);
00082     logical wantvl, wntsnb;
00083     integer hswork;
00084     logical wntsne;
00085     real smlnum;
00086     logical lquery, wantvr, wntsnn, wntsnv;
00087 
00088 
00089 /*  -- LAPACK driver routine (version 3.2) -- */
00090 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00091 /*     November 2006 */
00092 
00093 /*     .. Scalar Arguments .. */
00094 /*     .. */
00095 /*     .. Array Arguments .. */
00096 /*     .. */
00097 
00098 /*  Purpose */
00099 /*  ======= */
00100 
00101 /*  SGEEVX computes for an N-by-N real nonsymmetric matrix A, the */
00102 /*  eigenvalues and, optionally, the left and/or right eigenvectors. */
00103 
00104 /*  Optionally also, it computes a balancing transformation to improve */
00105 /*  the conditioning of the eigenvalues and eigenvectors (ILO, IHI, */
00106 /*  SCALE, and ABNRM), reciprocal condition numbers for the eigenvalues */
00107 /*  (RCONDE), and reciprocal condition numbers for the right */
00108 /*  eigenvectors (RCONDV). */
00109 
00110 /*  The right eigenvector v(j) of A satisfies */
00111 /*                   A * v(j) = lambda(j) * v(j) */
00112 /*  where lambda(j) is its eigenvalue. */
00113 /*  The left eigenvector u(j) of A satisfies */
00114 /*                u(j)**H * A = lambda(j) * u(j)**H */
00115 /*  where u(j)**H denotes the conjugate transpose of u(j). */
00116 
00117 /*  The computed eigenvectors are normalized to have Euclidean norm */
00118 /*  equal to 1 and largest component real. */
00119 
00120 /*  Balancing a matrix means permuting the rows and columns to make it */
00121 /*  more nearly upper triangular, and applying a diagonal similarity */
00122 /*  transformation D * A * D**(-1), where D is a diagonal matrix, to */
00123 /*  make its rows and columns closer in norm and the condition numbers */
00124 /*  of its eigenvalues and eigenvectors smaller.  The computed */
00125 /*  reciprocal condition numbers correspond to the balanced matrix. */
00126 /*  Permuting rows and columns will not change the condition numbers */
00127 /*  (in exact arithmetic) but diagonal scaling will.  For further */
00128 /*  explanation of balancing, see section 4.10.2 of the LAPACK */
00129 /*  Users' Guide. */
00130 
00131 /*  Arguments */
00132 /*  ========= */
00133 
00134 /*  BALANC  (input) CHARACTER*1 */
00135 /*          Indicates how the input matrix should be diagonally scaled */
00136 /*          and/or permuted to improve the conditioning of its */
00137 /*          eigenvalues. */
00138 /*          = 'N': Do not diagonally scale or permute; */
00139 /*          = 'P': Perform permutations to make the matrix more nearly */
00140 /*                 upper triangular. Do not diagonally scale; */
00141 /*          = 'S': Diagonally scale the matrix, i.e. replace A by */
00142 /*                 D*A*D**(-1), where D is a diagonal matrix chosen */
00143 /*                 to make the rows and columns of A more equal in */
00144 /*                 norm. Do not permute; */
00145 /*          = 'B': Both diagonally scale and permute A. */
00146 
00147 /*          Computed reciprocal condition numbers will be for the matrix */
00148 /*          after balancing and/or permuting. Permuting does not change */
00149 /*          condition numbers (in exact arithmetic), but balancing does. */
00150 
00151 /*  JOBVL   (input) CHARACTER*1 */
00152 /*          = 'N': left eigenvectors of A are not computed; */
00153 /*          = 'V': left eigenvectors of A are computed. */
00154 /*          If SENSE = 'E' or 'B', JOBVL must = 'V'. */
00155 
00156 /*  JOBVR   (input) CHARACTER*1 */
00157 /*          = 'N': right eigenvectors of A are not computed; */
00158 /*          = 'V': right eigenvectors of A are computed. */
00159 /*          If SENSE = 'E' or 'B', JOBVR must = 'V'. */
00160 
00161 /*  SENSE   (input) CHARACTER*1 */
00162 /*          Determines which reciprocal condition numbers are computed. */
00163 /*          = 'N': None are computed; */
00164 /*          = 'E': Computed for eigenvalues only; */
00165 /*          = 'V': Computed for right eigenvectors only; */
00166 /*          = 'B': Computed for eigenvalues and right eigenvectors. */
00167 
00168 /*          If SENSE = 'E' or 'B', both left and right eigenvectors */
00169 /*          must also be computed (JOBVL = 'V' and JOBVR = 'V'). */
00170 
00171 /*  N       (input) INTEGER */
00172 /*          The order of the matrix A. N >= 0. */
00173 
00174 /*  A       (input/output) REAL array, dimension (LDA,N) */
00175 /*          On entry, the N-by-N matrix A. */
00176 /*          On exit, A has been overwritten.  If JOBVL = 'V' or */
00177 /*          JOBVR = 'V', A contains the real Schur form of the balanced */
00178 /*          version of the input matrix A. */
00179 
00180 /*  LDA     (input) INTEGER */
00181 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00182 
00183 /*  WR      (output) REAL array, dimension (N) */
00184 /*  WI      (output) REAL array, dimension (N) */
00185 /*          WR and WI contain the real and imaginary parts, */
00186 /*          respectively, of the computed eigenvalues.  Complex */
00187 /*          conjugate pairs of eigenvalues will appear consecutively */
00188 /*          with the eigenvalue having the positive imaginary part */
00189 /*          first. */
00190 
00191 /*  VL      (output) REAL array, dimension (LDVL,N) */
00192 /*          If JOBVL = 'V', the left eigenvectors u(j) are stored one */
00193 /*          after another in the columns of VL, in the same order */
00194 /*          as their eigenvalues. */
00195 /*          If JOBVL = 'N', VL is not referenced. */
00196 /*          If the j-th eigenvalue is real, then u(j) = VL(:,j), */
00197 /*          the j-th column of VL. */
00198 /*          If the j-th and (j+1)-st eigenvalues form a complex */
00199 /*          conjugate pair, then u(j) = VL(:,j) + i*VL(:,j+1) and */
00200 /*          u(j+1) = VL(:,j) - i*VL(:,j+1). */
00201 
00202 /*  LDVL    (input) INTEGER */
00203 /*          The leading dimension of the array VL.  LDVL >= 1; if */
00204 /*          JOBVL = 'V', LDVL >= N. */
00205 
00206 /*  VR      (output) REAL array, dimension (LDVR,N) */
00207 /*          If JOBVR = 'V', the right eigenvectors v(j) are stored one */
00208 /*          after another in the columns of VR, in the same order */
00209 /*          as their eigenvalues. */
00210 /*          If JOBVR = 'N', VR is not referenced. */
00211 /*          If the j-th eigenvalue is real, then v(j) = VR(:,j), */
00212 /*          the j-th column of VR. */
00213 /*          If the j-th and (j+1)-st eigenvalues form a complex */
00214 /*          conjugate pair, then v(j) = VR(:,j) + i*VR(:,j+1) and */
00215 /*          v(j+1) = VR(:,j) - i*VR(:,j+1). */
00216 
00217 /*  LDVR    (input) INTEGER */
00218 /*          The leading dimension of the array VR.  LDVR >= 1, and if */
00219 /*          JOBVR = 'V', LDVR >= N. */
00220 
00221 /*  ILO     (output) INTEGER */
00222 /*  IHI     (output) INTEGER */
00223 /*          ILO and IHI are integer values determined when A was */
00224 /*          balanced.  The balanced A(i,j) = 0 if I > J and */
00225 /*          J = 1,...,ILO-1 or I = IHI+1,...,N. */
00226 
00227 /*  SCALE   (output) REAL array, dimension (N) */
00228 /*          Details of the permutations and scaling factors applied */
00229 /*          when balancing A.  If P(j) is the index of the row and column */
00230 /*          interchanged with row and column j, and D(j) is the scaling */
00231 /*          factor applied to row and column j, then */
00232 /*          SCALE(J) = P(J),    for J = 1,...,ILO-1 */
00233 /*                   = D(J),    for J = ILO,...,IHI */
00234 /*                   = P(J)     for J = IHI+1,...,N. */
00235 /*          The order in which the interchanges are made is N to IHI+1, */
00236 /*          then 1 to ILO-1. */
00237 
00238 /*  ABNRM   (output) REAL */
00239 /*          The one-norm of the balanced matrix (the maximum */
00240 /*          of the sum of absolute values of elements of any column). */
00241 
00242 /*  RCONDE  (output) REAL array, dimension (N) */
00243 /*          RCONDE(j) is the reciprocal condition number of the j-th */
00244 /*          eigenvalue. */
00245 
00246 /*  RCONDV  (output) REAL array, dimension (N) */
00247 /*          RCONDV(j) is the reciprocal condition number of the j-th */
00248 /*          right eigenvector. */
00249 
00250 /*  WORK    (workspace/output) REAL array, dimension (MAX(1,LWORK)) */
00251 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00252 
00253 /*  LWORK   (input) INTEGER */
00254 /*          The dimension of the array WORK.   If SENSE = 'N' or 'E', */
00255 /*          LWORK >= max(1,2*N), and if JOBVL = 'V' or JOBVR = 'V', */
00256 /*          LWORK >= 3*N.  If SENSE = 'V' or 'B', LWORK >= N*(N+6). */
00257 /*          For good performance, LWORK must generally be larger. */
00258 
00259 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00260 /*          only calculates the optimal size of the WORK array, returns */
00261 /*          this value as the first entry of the WORK array, and no error */
00262 /*          message related to LWORK is issued by XERBLA. */
00263 
00264 /*  IWORK   (workspace) INTEGER array, dimension (2*N-2) */
00265 /*          If SENSE = 'N' or 'E', not referenced. */
00266 
00267 /*  INFO    (output) INTEGER */
00268 /*          = 0:  successful exit */
00269 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00270 /*          > 0:  if INFO = i, the QR algorithm failed to compute all the */
00271 /*                eigenvalues, and no eigenvectors or condition numbers */
00272 /*                have been computed; elements 1:ILO-1 and i+1:N of WR */
00273 /*                and WI contain eigenvalues which have converged. */
00274 
00275 /*  ===================================================================== */
00276 
00277 /*     .. Parameters .. */
00278 /*     .. */
00279 /*     .. Local Scalars .. */
00280 /*     .. */
00281 /*     .. Local Arrays .. */
00282 /*     .. */
00283 /*     .. External Subroutines .. */
00284 /*     .. */
00285 /*     .. External Functions .. */
00286 /*     .. */
00287 /*     .. Intrinsic Functions .. */
00288 /*     .. */
00289 /*     .. Executable Statements .. */
00290 
00291 /*     Test the input arguments */
00292 
00293     /* Parameter adjustments */
00294     a_dim1 = *lda;
00295     a_offset = 1 + a_dim1;
00296     a -= a_offset;
00297     --wr;
00298     --wi;
00299     vl_dim1 = *ldvl;
00300     vl_offset = 1 + vl_dim1;
00301     vl -= vl_offset;
00302     vr_dim1 = *ldvr;
00303     vr_offset = 1 + vr_dim1;
00304     vr -= vr_offset;
00305     --scale;
00306     --rconde;
00307     --rcondv;
00308     --work;
00309     --iwork;
00310 
00311     /* Function Body */
00312     *info = 0;
00313     lquery = *lwork == -1;
00314     wantvl = lsame_(jobvl, "V");
00315     wantvr = lsame_(jobvr, "V");
00316     wntsnn = lsame_(sense, "N");
00317     wntsne = lsame_(sense, "E");
00318     wntsnv = lsame_(sense, "V");
00319     wntsnb = lsame_(sense, "B");
00320     if (! (lsame_(balanc, "N") || lsame_(balanc, "S") || lsame_(balanc, "P") 
00321             || lsame_(balanc, "B"))) {
00322         *info = -1;
00323     } else if (! wantvl && ! lsame_(jobvl, "N")) {
00324         *info = -2;
00325     } else if (! wantvr && ! lsame_(jobvr, "N")) {
00326         *info = -3;
00327     } else if (! (wntsnn || wntsne || wntsnb || wntsnv) || (wntsne || wntsnb) 
00328             && ! (wantvl && wantvr)) {
00329         *info = -4;
00330     } else if (*n < 0) {
00331         *info = -5;
00332     } else if (*lda < max(1,*n)) {
00333         *info = -7;
00334     } else if (*ldvl < 1 || wantvl && *ldvl < *n) {
00335         *info = -11;
00336     } else if (*ldvr < 1 || wantvr && *ldvr < *n) {
00337         *info = -13;
00338     }
00339 
00340 /*     Compute workspace */
00341 /*      (Note: Comments in the code beginning "Workspace:" describe the */
00342 /*       minimal amount of workspace needed at that point in the code, */
00343 /*       as well as the preferred amount for good performance. */
00344 /*       NB refers to the optimal block size for the immediately */
00345 /*       following subroutine, as returned by ILAENV. */
00346 /*       HSWORK refers to the workspace preferred by SHSEQR, as */
00347 /*       calculated below. HSWORK is computed assuming ILO=1 and IHI=N, */
00348 /*       the worst case.) */
00349 
00350     if (*info == 0) {
00351         if (*n == 0) {
00352             minwrk = 1;
00353             maxwrk = 1;
00354         } else {
00355             maxwrk = *n + *n * ilaenv_(&c__1, "SGEHRD", " ", n, &c__1, n, &
00356                     c__0);
00357 
00358             if (wantvl) {
00359                 shseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[
00360                         1], &vl[vl_offset], ldvl, &work[1], &c_n1, info);
00361             } else if (wantvr) {
00362                 shseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[
00363                         1], &vr[vr_offset], ldvr, &work[1], &c_n1, info);
00364             } else {
00365                 if (wntsnn) {
00366                     shseqr_("E", "N", n, &c__1, n, &a[a_offset], lda, &wr[1], 
00367                             &wi[1], &vr[vr_offset], ldvr, &work[1], &c_n1, 
00368                             info);
00369                 } else {
00370                     shseqr_("S", "N", n, &c__1, n, &a[a_offset], lda, &wr[1], 
00371                             &wi[1], &vr[vr_offset], ldvr, &work[1], &c_n1, 
00372                             info);
00373                 }
00374             }
00375             hswork = work[1];
00376 
00377             if (! wantvl && ! wantvr) {
00378                 minwrk = *n << 1;
00379                 if (! wntsnn) {
00380 /* Computing MAX */
00381                     i__1 = minwrk, i__2 = *n * *n + *n * 6;
00382                     minwrk = max(i__1,i__2);
00383                 }
00384                 maxwrk = max(maxwrk,hswork);
00385                 if (! wntsnn) {
00386 /* Computing MAX */
00387                     i__1 = maxwrk, i__2 = *n * *n + *n * 6;
00388                     maxwrk = max(i__1,i__2);
00389                 }
00390             } else {
00391                 minwrk = *n * 3;
00392                 if (! wntsnn && ! wntsne) {
00393 /* Computing MAX */
00394                     i__1 = minwrk, i__2 = *n * *n + *n * 6;
00395                     minwrk = max(i__1,i__2);
00396                 }
00397                 maxwrk = max(maxwrk,hswork);
00398 /* Computing MAX */
00399                 i__1 = maxwrk, i__2 = *n + (*n - 1) * ilaenv_(&c__1, "SORGHR", 
00400                          " ", n, &c__1, n, &c_n1);
00401                 maxwrk = max(i__1,i__2);
00402                 if (! wntsnn && ! wntsne) {
00403 /* Computing MAX */
00404                     i__1 = maxwrk, i__2 = *n * *n + *n * 6;
00405                     maxwrk = max(i__1,i__2);
00406                 }
00407 /* Computing MAX */
00408                 i__1 = maxwrk, i__2 = *n * 3;
00409                 maxwrk = max(i__1,i__2);
00410             }
00411             maxwrk = max(maxwrk,minwrk);
00412         }
00413         work[1] = (real) maxwrk;
00414 
00415         if (*lwork < minwrk && ! lquery) {
00416             *info = -21;
00417         }
00418     }
00419 
00420     if (*info != 0) {
00421         i__1 = -(*info);
00422         xerbla_("SGEEVX", &i__1);
00423         return 0;
00424     } else if (lquery) {
00425         return 0;
00426     }
00427 
00428 /*     Quick return if possible */
00429 
00430     if (*n == 0) {
00431         return 0;
00432     }
00433 
00434 /*     Get machine constants */
00435 
00436     eps = slamch_("P");
00437     smlnum = slamch_("S");
00438     bignum = 1.f / smlnum;
00439     slabad_(&smlnum, &bignum);
00440     smlnum = sqrt(smlnum) / eps;
00441     bignum = 1.f / smlnum;
00442 
00443 /*     Scale A if max element outside range [SMLNUM,BIGNUM] */
00444 
00445     icond = 0;
00446     anrm = slange_("M", n, n, &a[a_offset], lda, dum);
00447     scalea = FALSE_;
00448     if (anrm > 0.f && anrm < smlnum) {
00449         scalea = TRUE_;
00450         cscale = smlnum;
00451     } else if (anrm > bignum) {
00452         scalea = TRUE_;
00453         cscale = bignum;
00454     }
00455     if (scalea) {
00456         slascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
00457                 ierr);
00458     }
00459 
00460 /*     Balance the matrix and compute ABNRM */
00461 
00462     sgebal_(balanc, n, &a[a_offset], lda, ilo, ihi, &scale[1], &ierr);
00463     *abnrm = slange_("1", n, n, &a[a_offset], lda, dum);
00464     if (scalea) {
00465         dum[0] = *abnrm;
00466         slascl_("G", &c__0, &c__0, &cscale, &anrm, &c__1, &c__1, dum, &c__1, &
00467                 ierr);
00468         *abnrm = dum[0];
00469     }
00470 
00471 /*     Reduce to upper Hessenberg form */
00472 /*     (Workspace: need 2*N, prefer N+N*NB) */
00473 
00474     itau = 1;
00475     iwrk = itau + *n;
00476     i__1 = *lwork - iwrk + 1;
00477     sgehrd_(n, ilo, ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1, &
00478             ierr);
00479 
00480     if (wantvl) {
00481 
00482 /*        Want left eigenvectors */
00483 /*        Copy Householder vectors to VL */
00484 
00485         *(unsigned char *)side = 'L';
00486         slacpy_("L", n, n, &a[a_offset], lda, &vl[vl_offset], ldvl)
00487                 ;
00488 
00489 /*        Generate orthogonal matrix in VL */
00490 /*        (Workspace: need 2*N-1, prefer N+(N-1)*NB) */
00491 
00492         i__1 = *lwork - iwrk + 1;
00493         sorghr_(n, ilo, ihi, &vl[vl_offset], ldvl, &work[itau], &work[iwrk], &
00494                 i__1, &ierr);
00495 
00496 /*        Perform QR iteration, accumulating Schur vectors in VL */
00497 /*        (Workspace: need 1, prefer HSWORK (see comments) ) */
00498 
00499         iwrk = itau;
00500         i__1 = *lwork - iwrk + 1;
00501         shseqr_("S", "V", n, ilo, ihi, &a[a_offset], lda, &wr[1], &wi[1], &vl[
00502                 vl_offset], ldvl, &work[iwrk], &i__1, info);
00503 
00504         if (wantvr) {
00505 
00506 /*           Want left and right eigenvectors */
00507 /*           Copy Schur vectors to VR */
00508 
00509             *(unsigned char *)side = 'B';
00510             slacpy_("F", n, n, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr);
00511         }
00512 
00513     } else if (wantvr) {
00514 
00515 /*        Want right eigenvectors */
00516 /*        Copy Householder vectors to VR */
00517 
00518         *(unsigned char *)side = 'R';
00519         slacpy_("L", n, n, &a[a_offset], lda, &vr[vr_offset], ldvr)
00520                 ;
00521 
00522 /*        Generate orthogonal matrix in VR */
00523 /*        (Workspace: need 2*N-1, prefer N+(N-1)*NB) */
00524 
00525         i__1 = *lwork - iwrk + 1;
00526         sorghr_(n, ilo, ihi, &vr[vr_offset], ldvr, &work[itau], &work[iwrk], &
00527                 i__1, &ierr);
00528 
00529 /*        Perform QR iteration, accumulating Schur vectors in VR */
00530 /*        (Workspace: need 1, prefer HSWORK (see comments) ) */
00531 
00532         iwrk = itau;
00533         i__1 = *lwork - iwrk + 1;
00534         shseqr_("S", "V", n, ilo, ihi, &a[a_offset], lda, &wr[1], &wi[1], &vr[
00535                 vr_offset], ldvr, &work[iwrk], &i__1, info);
00536 
00537     } else {
00538 
00539 /*        Compute eigenvalues only */
00540 /*        If condition numbers desired, compute Schur form */
00541 
00542         if (wntsnn) {
00543             *(unsigned char *)job = 'E';
00544         } else {
00545             *(unsigned char *)job = 'S';
00546         }
00547 
00548 /*        (Workspace: need 1, prefer HSWORK (see comments) ) */
00549 
00550         iwrk = itau;
00551         i__1 = *lwork - iwrk + 1;
00552         shseqr_(job, "N", n, ilo, ihi, &a[a_offset], lda, &wr[1], &wi[1], &vr[
00553                 vr_offset], ldvr, &work[iwrk], &i__1, info);
00554     }
00555 
00556 /*     If INFO > 0 from SHSEQR, then quit */
00557 
00558     if (*info > 0) {
00559         goto L50;
00560     }
00561 
00562     if (wantvl || wantvr) {
00563 
00564 /*        Compute left and/or right eigenvectors */
00565 /*        (Workspace: need 3*N) */
00566 
00567         strevc_(side, "B", select, n, &a[a_offset], lda, &vl[vl_offset], ldvl, 
00568                  &vr[vr_offset], ldvr, n, &nout, &work[iwrk], &ierr);
00569     }
00570 
00571 /*     Compute condition numbers if desired */
00572 /*     (Workspace: need N*N+6*N unless SENSE = 'E') */
00573 
00574     if (! wntsnn) {
00575         strsna_(sense, "A", select, n, &a[a_offset], lda, &vl[vl_offset], 
00576                 ldvl, &vr[vr_offset], ldvr, &rconde[1], &rcondv[1], n, &nout, 
00577                 &work[iwrk], n, &iwork[1], &icond);
00578     }
00579 
00580     if (wantvl) {
00581 
00582 /*        Undo balancing of left eigenvectors */
00583 
00584         sgebak_(balanc, "L", n, ilo, ihi, &scale[1], n, &vl[vl_offset], ldvl, 
00585                 &ierr);
00586 
00587 /*        Normalize left eigenvectors and make largest component real */
00588 
00589         i__1 = *n;
00590         for (i__ = 1; i__ <= i__1; ++i__) {
00591             if (wi[i__] == 0.f) {
00592                 scl = 1.f / snrm2_(n, &vl[i__ * vl_dim1 + 1], &c__1);
00593                 sscal_(n, &scl, &vl[i__ * vl_dim1 + 1], &c__1);
00594             } else if (wi[i__] > 0.f) {
00595                 r__1 = snrm2_(n, &vl[i__ * vl_dim1 + 1], &c__1);
00596                 r__2 = snrm2_(n, &vl[(i__ + 1) * vl_dim1 + 1], &c__1);
00597                 scl = 1.f / slapy2_(&r__1, &r__2);
00598                 sscal_(n, &scl, &vl[i__ * vl_dim1 + 1], &c__1);
00599                 sscal_(n, &scl, &vl[(i__ + 1) * vl_dim1 + 1], &c__1);
00600                 i__2 = *n;
00601                 for (k = 1; k <= i__2; ++k) {
00602 /* Computing 2nd power */
00603                     r__1 = vl[k + i__ * vl_dim1];
00604 /* Computing 2nd power */
00605                     r__2 = vl[k + (i__ + 1) * vl_dim1];
00606                     work[k] = r__1 * r__1 + r__2 * r__2;
00607 /* L10: */
00608                 }
00609                 k = isamax_(n, &work[1], &c__1);
00610                 slartg_(&vl[k + i__ * vl_dim1], &vl[k + (i__ + 1) * vl_dim1], 
00611                         &cs, &sn, &r__);
00612                 srot_(n, &vl[i__ * vl_dim1 + 1], &c__1, &vl[(i__ + 1) * 
00613                         vl_dim1 + 1], &c__1, &cs, &sn);
00614                 vl[k + (i__ + 1) * vl_dim1] = 0.f;
00615             }
00616 /* L20: */
00617         }
00618     }
00619 
00620     if (wantvr) {
00621 
00622 /*        Undo balancing of right eigenvectors */
00623 
00624         sgebak_(balanc, "R", n, ilo, ihi, &scale[1], n, &vr[vr_offset], ldvr, 
00625                 &ierr);
00626 
00627 /*        Normalize right eigenvectors and make largest component real */
00628 
00629         i__1 = *n;
00630         for (i__ = 1; i__ <= i__1; ++i__) {
00631             if (wi[i__] == 0.f) {
00632                 scl = 1.f / snrm2_(n, &vr[i__ * vr_dim1 + 1], &c__1);
00633                 sscal_(n, &scl, &vr[i__ * vr_dim1 + 1], &c__1);
00634             } else if (wi[i__] > 0.f) {
00635                 r__1 = snrm2_(n, &vr[i__ * vr_dim1 + 1], &c__1);
00636                 r__2 = snrm2_(n, &vr[(i__ + 1) * vr_dim1 + 1], &c__1);
00637                 scl = 1.f / slapy2_(&r__1, &r__2);
00638                 sscal_(n, &scl, &vr[i__ * vr_dim1 + 1], &c__1);
00639                 sscal_(n, &scl, &vr[(i__ + 1) * vr_dim1 + 1], &c__1);
00640                 i__2 = *n;
00641                 for (k = 1; k <= i__2; ++k) {
00642 /* Computing 2nd power */
00643                     r__1 = vr[k + i__ * vr_dim1];
00644 /* Computing 2nd power */
00645                     r__2 = vr[k + (i__ + 1) * vr_dim1];
00646                     work[k] = r__1 * r__1 + r__2 * r__2;
00647 /* L30: */
00648                 }
00649                 k = isamax_(n, &work[1], &c__1);
00650                 slartg_(&vr[k + i__ * vr_dim1], &vr[k + (i__ + 1) * vr_dim1], 
00651                         &cs, &sn, &r__);
00652                 srot_(n, &vr[i__ * vr_dim1 + 1], &c__1, &vr[(i__ + 1) * 
00653                         vr_dim1 + 1], &c__1, &cs, &sn);
00654                 vr[k + (i__ + 1) * vr_dim1] = 0.f;
00655             }
00656 /* L40: */
00657         }
00658     }
00659 
00660 /*     Undo scaling if necessary */
00661 
00662 L50:
00663     if (scalea) {
00664         i__1 = *n - *info;
00665 /* Computing MAX */
00666         i__3 = *n - *info;
00667         i__2 = max(i__3,1);
00668         slascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wr[*info + 
00669                 1], &i__2, &ierr);
00670         i__1 = *n - *info;
00671 /* Computing MAX */
00672         i__3 = *n - *info;
00673         i__2 = max(i__3,1);
00674         slascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[*info + 
00675                 1], &i__2, &ierr);
00676         if (*info == 0) {
00677             if ((wntsnv || wntsnb) && icond == 0) {
00678                 slascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &rcondv[
00679                         1], n, &ierr);
00680             }
00681         } else {
00682             i__1 = *ilo - 1;
00683             slascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wr[1], 
00684                     n, &ierr);
00685             i__1 = *ilo - 1;
00686             slascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[1], 
00687                     n, &ierr);
00688         }
00689     }
00690 
00691     work[1] = (real) maxwrk;
00692     return 0;
00693 
00694 /*     End of SGEEVX */
00695 
00696 } /* sgeevx_ */


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