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


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