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


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