cheevr.c
Go to the documentation of this file.
00001 /* cheevr.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__10 = 10;
00019 static integer c__1 = 1;
00020 static integer c__2 = 2;
00021 static integer c__3 = 3;
00022 static integer c__4 = 4;
00023 static integer c_n1 = -1;
00024 
00025 /* Subroutine */ int cheevr_(char *jobz, char *range, char *uplo, integer *n, 
00026         complex *a, integer *lda, real *vl, real *vu, integer *il, integer *
00027         iu, real *abstol, integer *m, real *w, complex *z__, integer *ldz, 
00028         integer *isuppz, complex *work, integer *lwork, real *rwork, integer *
00029         lrwork, integer *iwork, integer *liwork, integer *info)
00030 {
00031     /* System generated locals */
00032     integer a_dim1, a_offset, z_dim1, z_offset, i__1, i__2;
00033     real r__1, r__2;
00034 
00035     /* Builtin functions */
00036     double sqrt(doublereal);
00037 
00038     /* Local variables */
00039     integer i__, j, nb, jj;
00040     real eps, vll, vuu, tmp1, anrm;
00041     integer imax;
00042     real rmin, rmax;
00043     logical test;
00044     integer itmp1, indrd, indre;
00045     real sigma;
00046     extern logical lsame_(char *, char *);
00047     integer iinfo;
00048     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
00049     char order[1];
00050     integer indwk;
00051     extern /* Subroutine */ int cswap_(integer *, complex *, integer *, 
00052             complex *, integer *);
00053     integer lwmin;
00054     logical lower;
00055     extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 
00056             integer *);
00057     logical wantz, alleig, indeig;
00058     integer iscale, ieeeok, indibl, indrdd, indifl, indree;
00059     logical valeig;
00060     extern doublereal slamch_(char *);
00061     extern /* Subroutine */ int chetrd_(char *, integer *, complex *, integer 
00062             *, real *, real *, complex *, complex *, integer *, integer *), csscal_(integer *, real *, complex *, integer *);
00063     real safmin;
00064     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00065             integer *, integer *);
00066     extern /* Subroutine */ int xerbla_(char *, integer *);
00067     real abstll, bignum;
00068     integer indtau, indisp;
00069     extern /* Subroutine */ int cstein_(integer *, real *, real *, integer *, 
00070             real *, integer *, integer *, complex *, integer *, real *, 
00071             integer *, integer *, integer *);
00072     integer indiwo, indwkn;
00073     extern doublereal clansy_(char *, char *, integer *, complex *, integer *, 
00074              real *);
00075     extern /* Subroutine */ int cstemr_(char *, char *, integer *, real *, 
00076             real *, real *, real *, integer *, integer *, integer *, real *, 
00077             complex *, integer *, integer *, integer *, logical *, real *, 
00078             integer *, integer *, integer *, integer *);
00079     integer indrwk, liwmin;
00080     logical tryrac;
00081     extern /* Subroutine */ int ssterf_(integer *, real *, real *, integer *);
00082     integer lrwmin, llwrkn, llwork, nsplit;
00083     real smlnum;
00084     extern /* Subroutine */ int cunmtr_(char *, char *, char *, integer *, 
00085             integer *, complex *, integer *, complex *, complex *, integer *, 
00086             complex *, integer *, integer *), sstebz_(
00087             char *, char *, integer *, real *, real *, integer *, integer *, 
00088             real *, real *, real *, integer *, integer *, real *, integer *, 
00089             integer *, real *, integer *, integer *);
00090     logical lquery;
00091     integer lwkopt, llrwork;
00092 
00093 
00094 /*  -- LAPACK driver routine (version 3.2) -- */
00095 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00096 /*     November 2006 */
00097 
00098 /*     .. Scalar Arguments .. */
00099 /*     .. */
00100 /*     .. Array Arguments .. */
00101 /*     .. */
00102 
00103 /*  Purpose */
00104 /*  ======= */
00105 
00106 /*  CHEEVR computes selected eigenvalues and, optionally, eigenvectors */
00107 /*  of a complex Hermitian matrix A.  Eigenvalues and eigenvectors can */
00108 /*  be selected by specifying either a range of values or a range of */
00109 /*  indices for the desired eigenvalues. */
00110 
00111 /*  CHEEVR first reduces the matrix A to tridiagonal form T with a call */
00112 /*  to CHETRD.  Then, whenever possible, CHEEVR calls CSTEMR to compute */
00113 /*  the eigenspectrum using Relatively Robust Representations.  CSTEMR */
00114 /*  computes eigenvalues by the dqds algorithm, while orthogonal */
00115 /*  eigenvectors are computed from various "good" L D L^T representations */
00116 /*  (also known as Relatively Robust Representations). Gram-Schmidt */
00117 /*  orthogonalization is avoided as far as possible. More specifically, */
00118 /*  the various steps of the algorithm are as follows. */
00119 
00120 /*  For each unreduced block (submatrix) of T, */
00121 /*     (a) Compute T - sigma I  = L D L^T, so that L and D */
00122 /*         define all the wanted eigenvalues to high relative accuracy. */
00123 /*         This means that small relative changes in the entries of D and L */
00124 /*         cause only small relative changes in the eigenvalues and */
00125 /*         eigenvectors. The standard (unfactored) representation of the */
00126 /*         tridiagonal matrix T does not have this property in general. */
00127 /*     (b) Compute the eigenvalues to suitable accuracy. */
00128 /*         If the eigenvectors are desired, the algorithm attains full */
00129 /*         accuracy of the computed eigenvalues only right before */
00130 /*         the corresponding vectors have to be computed, see steps c) and d). */
00131 /*     (c) For each cluster of close eigenvalues, select a new */
00132 /*         shift close to the cluster, find a new factorization, and refine */
00133 /*         the shifted eigenvalues to suitable accuracy. */
00134 /*     (d) For each eigenvalue with a large enough relative separation compute */
00135 /*         the corresponding eigenvector by forming a rank revealing twisted */
00136 /*         factorization. Go back to (c) for any clusters that remain. */
00137 
00138 /*  The desired accuracy of the output can be specified by the input */
00139 /*  parameter ABSTOL. */
00140 
00141 /*  For more details, see DSTEMR's documentation and: */
00142 /*  - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations */
00143 /*    to compute orthogonal eigenvectors of symmetric tridiagonal matrices," */
00144 /*    Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. */
00145 /*  - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and */
00146 /*    Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, */
00147 /*    2004.  Also LAPACK Working Note 154. */
00148 /*  - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric */
00149 /*    tridiagonal eigenvalue/eigenvector problem", */
00150 /*    Computer Science Division Technical Report No. UCB/CSD-97-971, */
00151 /*    UC Berkeley, May 1997. */
00152 
00153 
00154 /*  Note 1 : CHEEVR calls CSTEMR when the full spectrum is requested */
00155 /*  on machines which conform to the ieee-754 floating point standard. */
00156 /*  CHEEVR calls SSTEBZ and CSTEIN on non-ieee machines and */
00157 /*  when partial spectrum requests are made. */
00158 
00159 /*  Normal execution of CSTEMR may create NaNs and infinities and */
00160 /*  hence may abort due to a floating point exception in environments */
00161 /*  which do not handle NaNs and infinities in the ieee standard default */
00162 /*  manner. */
00163 
00164 /*  Arguments */
00165 /*  ========= */
00166 
00167 /*  JOBZ    (input) CHARACTER*1 */
00168 /*          = 'N':  Compute eigenvalues only; */
00169 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00170 
00171 /*  RANGE   (input) CHARACTER*1 */
00172 /*          = 'A': all eigenvalues will be found. */
00173 /*          = 'V': all eigenvalues in the half-open interval (VL,VU] */
00174 /*                 will be found. */
00175 /*          = 'I': the IL-th through IU-th eigenvalues will be found. */
00176 /* ********* For RANGE = 'V' or 'I' and IU - IL < N - 1, SSTEBZ and */
00177 /* ********* CSTEIN are called */
00178 
00179 /*  UPLO    (input) CHARACTER*1 */
00180 /*          = 'U':  Upper triangle of A is stored; */
00181 /*          = 'L':  Lower triangle of A is stored. */
00182 
00183 /*  N       (input) INTEGER */
00184 /*          The order of the matrix A.  N >= 0. */
00185 
00186 /*  A       (input/output) COMPLEX array, dimension (LDA, N) */
00187 /*          On entry, the Hermitian matrix A.  If UPLO = 'U', the */
00188 /*          leading N-by-N upper triangular part of A contains the */
00189 /*          upper triangular part of the matrix A.  If UPLO = 'L', */
00190 /*          the leading N-by-N lower triangular part of A contains */
00191 /*          the lower triangular part of the matrix A. */
00192 /*          On exit, the lower triangle (if UPLO='L') or the upper */
00193 /*          triangle (if UPLO='U') of A, including the diagonal, is */
00194 /*          destroyed. */
00195 
00196 /*  LDA     (input) INTEGER */
00197 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00198 
00199 /*  VL      (input) REAL */
00200 /*  VU      (input) REAL */
00201 /*          If RANGE='V', the lower and upper bounds of the interval to */
00202 /*          be searched for eigenvalues. VL < VU. */
00203 /*          Not referenced if RANGE = 'A' or 'I'. */
00204 
00205 /*  IL      (input) INTEGER */
00206 /*  IU      (input) INTEGER */
00207 /*          If RANGE='I', the indices (in ascending order) of the */
00208 /*          smallest and largest eigenvalues to be returned. */
00209 /*          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
00210 /*          Not referenced if RANGE = 'A' or 'V'. */
00211 
00212 /*  ABSTOL  (input) REAL */
00213 /*          The absolute error tolerance for the eigenvalues. */
00214 /*          An approximate eigenvalue is accepted as converged */
00215 /*          when it is determined to lie in an interval [a,b] */
00216 /*          of width less than or equal to */
00217 
00218 /*                  ABSTOL + EPS *   max( |a|,|b| ) , */
00219 
00220 /*          where EPS is the machine precision.  If ABSTOL is less than */
00221 /*          or equal to zero, then  EPS*|T|  will be used in its place, */
00222 /*          where |T| is the 1-norm of the tridiagonal matrix obtained */
00223 /*          by reducing A to tridiagonal form. */
00224 
00225 /*          See "Computing Small Singular Values of Bidiagonal Matrices */
00226 /*          with Guaranteed High Relative Accuracy," by Demmel and */
00227 /*          Kahan, LAPACK Working Note #3. */
00228 
00229 /*          If high relative accuracy is important, set ABSTOL to */
00230 /*          SLAMCH( 'Safe minimum' ).  Doing so will guarantee that */
00231 /*          eigenvalues are computed to high relative accuracy when */
00232 /*          possible in future releases.  The current code does not */
00233 /*          make any guarantees about high relative accuracy, but */
00234 /*          furutre releases will. See J. Barlow and J. Demmel, */
00235 /*          "Computing Accurate Eigensystems of Scaled Diagonally */
00236 /*          Dominant Matrices", LAPACK Working Note #7, for a discussion */
00237 /*          of which matrices define their eigenvalues to high relative */
00238 /*          accuracy. */
00239 
00240 /*  M       (output) INTEGER */
00241 /*          The total number of eigenvalues found.  0 <= M <= N. */
00242 /*          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
00243 
00244 /*  W       (output) REAL array, dimension (N) */
00245 /*          The first M elements contain the selected eigenvalues in */
00246 /*          ascending order. */
00247 
00248 /*  Z       (output) COMPLEX array, dimension (LDZ, max(1,M)) */
00249 /*          If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
00250 /*          contain the orthonormal eigenvectors of the matrix A */
00251 /*          corresponding to the selected eigenvalues, with the i-th */
00252 /*          column of Z holding the eigenvector associated with W(i). */
00253 /*          If JOBZ = 'N', then Z is not referenced. */
00254 /*          Note: the user must ensure that at least max(1,M) columns are */
00255 /*          supplied in the array Z; if RANGE = 'V', the exact value of M */
00256 /*          is not known in advance and an upper bound must be used. */
00257 
00258 /*  LDZ     (input) INTEGER */
00259 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00260 /*          JOBZ = 'V', LDZ >= max(1,N). */
00261 
00262 /*  ISUPPZ  (output) INTEGER array, dimension ( 2*max(1,M) ) */
00263 /*          The support of the eigenvectors in Z, i.e., the indices */
00264 /*          indicating the nonzero elements in Z. The i-th eigenvector */
00265 /*          is nonzero only in elements ISUPPZ( 2*i-1 ) through */
00266 /*          ISUPPZ( 2*i ). */
00267 /* ********* Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1 */
00268 
00269 /*  WORK    (workspace/output) COMPLEX array, dimension (MAX(1,LWORK)) */
00270 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00271 
00272 /*  LWORK   (input) INTEGER */
00273 /*          The length of the array WORK.  LWORK >= max(1,2*N). */
00274 /*          For optimal efficiency, LWORK >= (NB+1)*N, */
00275 /*          where NB is the max of the blocksize for CHETRD and for */
00276 /*          CUNMTR as returned by ILAENV. */
00277 
00278 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00279 /*          only calculates the optimal sizes of the WORK, RWORK and */
00280 /*          IWORK arrays, returns these values as the first entries of */
00281 /*          the WORK, RWORK and IWORK arrays, and no error message */
00282 /*          related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
00283 
00284 /*  RWORK   (workspace/output) REAL array, dimension (MAX(1,LRWORK)) */
00285 /*          On exit, if INFO = 0, RWORK(1) returns the optimal */
00286 /*          (and minimal) LRWORK. */
00287 
00288 /* LRWORK   (input) INTEGER */
00289 /*          The length of the array RWORK.  LRWORK >= max(1,24*N). */
00290 
00291 /*          If LRWORK = -1, then a workspace query is assumed; the */
00292 /*          routine only calculates the optimal sizes of the WORK, RWORK */
00293 /*          and IWORK arrays, returns these values as the first entries */
00294 /*          of the WORK, RWORK and IWORK arrays, and no error message */
00295 /*          related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
00296 
00297 /*  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
00298 /*          On exit, if INFO = 0, IWORK(1) returns the optimal */
00299 /*          (and minimal) LIWORK. */
00300 
00301 /* LIWORK   (input) INTEGER */
00302 /*          The dimension of the array IWORK.  LIWORK >= max(1,10*N). */
00303 
00304 /*          If LIWORK = -1, then a workspace query is assumed; the */
00305 /*          routine only calculates the optimal sizes of the WORK, RWORK */
00306 /*          and IWORK arrays, returns these values as the first entries */
00307 /*          of the WORK, RWORK and IWORK arrays, and no error message */
00308 /*          related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
00309 
00310 /*  INFO    (output) INTEGER */
00311 /*          = 0:  successful exit */
00312 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00313 /*          > 0:  Internal error */
00314 
00315 /*  Further Details */
00316 /*  =============== */
00317 
00318 /*  Based on contributions by */
00319 /*     Inderjit Dhillon, IBM Almaden, USA */
00320 /*     Osni Marques, LBNL/NERSC, USA */
00321 /*     Ken Stanley, Computer Science Division, University of */
00322 /*       California at Berkeley, USA */
00323 /*     Jason Riedy, Computer Science Division, University of */
00324 /*       California at Berkeley, USA */
00325 
00326 /* ===================================================================== */
00327 
00328 /*     .. Parameters .. */
00329 /*     .. */
00330 /*     .. Local Scalars .. */
00331 /*     .. */
00332 /*     .. External Functions .. */
00333 /*     .. */
00334 /*     .. External Subroutines .. */
00335 /*     .. */
00336 /*     .. Intrinsic Functions .. */
00337 /*     .. */
00338 /*     .. Executable Statements .. */
00339 
00340 /*     Test the input parameters. */
00341 
00342     /* Parameter adjustments */
00343     a_dim1 = *lda;
00344     a_offset = 1 + a_dim1;
00345     a -= a_offset;
00346     --w;
00347     z_dim1 = *ldz;
00348     z_offset = 1 + z_dim1;
00349     z__ -= z_offset;
00350     --isuppz;
00351     --work;
00352     --rwork;
00353     --iwork;
00354 
00355     /* Function Body */
00356     ieeeok = ilaenv_(&c__10, "CHEEVR", "N", &c__1, &c__2, &c__3, &c__4);
00357 
00358     lower = lsame_(uplo, "L");
00359     wantz = lsame_(jobz, "V");
00360     alleig = lsame_(range, "A");
00361     valeig = lsame_(range, "V");
00362     indeig = lsame_(range, "I");
00363 
00364     lquery = *lwork == -1 || *lrwork == -1 || *liwork == -1;
00365 
00366 /* Computing MAX */
00367     i__1 = 1, i__2 = *n * 24;
00368     lrwmin = max(i__1,i__2);
00369 /* Computing MAX */
00370     i__1 = 1, i__2 = *n * 10;
00371     liwmin = max(i__1,i__2);
00372 /* Computing MAX */
00373     i__1 = 1, i__2 = *n << 1;
00374     lwmin = max(i__1,i__2);
00375 
00376     *info = 0;
00377     if (! (wantz || lsame_(jobz, "N"))) {
00378         *info = -1;
00379     } else if (! (alleig || valeig || indeig)) {
00380         *info = -2;
00381     } else if (! (lower || lsame_(uplo, "U"))) {
00382         *info = -3;
00383     } else if (*n < 0) {
00384         *info = -4;
00385     } else if (*lda < max(1,*n)) {
00386         *info = -6;
00387     } else {
00388         if (valeig) {
00389             if (*n > 0 && *vu <= *vl) {
00390                 *info = -8;
00391             }
00392         } else if (indeig) {
00393             if (*il < 1 || *il > max(1,*n)) {
00394                 *info = -9;
00395             } else if (*iu < min(*n,*il) || *iu > *n) {
00396                 *info = -10;
00397             }
00398         }
00399     }
00400     if (*info == 0) {
00401         if (*ldz < 1 || wantz && *ldz < *n) {
00402             *info = -15;
00403         }
00404     }
00405 
00406     if (*info == 0) {
00407         nb = ilaenv_(&c__1, "CHETRD", uplo, n, &c_n1, &c_n1, &c_n1);
00408 /* Computing MAX */
00409         i__1 = nb, i__2 = ilaenv_(&c__1, "CUNMTR", uplo, n, &c_n1, &c_n1, &
00410                 c_n1);
00411         nb = max(i__1,i__2);
00412 /* Computing MAX */
00413         i__1 = (nb + 1) * *n;
00414         lwkopt = max(i__1,lwmin);
00415         work[1].r = (real) lwkopt, work[1].i = 0.f;
00416         rwork[1] = (real) lrwmin;
00417         iwork[1] = liwmin;
00418 
00419         if (*lwork < lwmin && ! lquery) {
00420             *info = -18;
00421         } else if (*lrwork < lrwmin && ! lquery) {
00422             *info = -20;
00423         } else if (*liwork < liwmin && ! lquery) {
00424             *info = -22;
00425         }
00426     }
00427 
00428     if (*info != 0) {
00429         i__1 = -(*info);
00430         xerbla_("CHEEVR", &i__1);
00431         return 0;
00432     } else if (lquery) {
00433         return 0;
00434     }
00435 
00436 /*     Quick return if possible */
00437 
00438     *m = 0;
00439     if (*n == 0) {
00440         work[1].r = 1.f, work[1].i = 0.f;
00441         return 0;
00442     }
00443 
00444     if (*n == 1) {
00445         work[1].r = 2.f, work[1].i = 0.f;
00446         if (alleig || indeig) {
00447             *m = 1;
00448             i__1 = a_dim1 + 1;
00449             w[1] = a[i__1].r;
00450         } else {
00451             i__1 = a_dim1 + 1;
00452             i__2 = a_dim1 + 1;
00453             if (*vl < a[i__1].r && *vu >= a[i__2].r) {
00454                 *m = 1;
00455                 i__1 = a_dim1 + 1;
00456                 w[1] = a[i__1].r;
00457             }
00458         }
00459         if (wantz) {
00460             i__1 = z_dim1 + 1;
00461             z__[i__1].r = 1.f, z__[i__1].i = 0.f;
00462         }
00463         return 0;
00464     }
00465 
00466 /*     Get machine constants. */
00467 
00468     safmin = slamch_("Safe minimum");
00469     eps = slamch_("Precision");
00470     smlnum = safmin / eps;
00471     bignum = 1.f / smlnum;
00472     rmin = sqrt(smlnum);
00473 /* Computing MIN */
00474     r__1 = sqrt(bignum), r__2 = 1.f / sqrt(sqrt(safmin));
00475     rmax = dmin(r__1,r__2);
00476 
00477 /*     Scale matrix to allowable range, if necessary. */
00478 
00479     iscale = 0;
00480     abstll = *abstol;
00481     if (valeig) {
00482         vll = *vl;
00483         vuu = *vu;
00484     }
00485     anrm = clansy_("M", uplo, n, &a[a_offset], lda, &rwork[1]);
00486     if (anrm > 0.f && anrm < rmin) {
00487         iscale = 1;
00488         sigma = rmin / anrm;
00489     } else if (anrm > rmax) {
00490         iscale = 1;
00491         sigma = rmax / anrm;
00492     }
00493     if (iscale == 1) {
00494         if (lower) {
00495             i__1 = *n;
00496             for (j = 1; j <= i__1; ++j) {
00497                 i__2 = *n - j + 1;
00498                 csscal_(&i__2, &sigma, &a[j + j * a_dim1], &c__1);
00499 /* L10: */
00500             }
00501         } else {
00502             i__1 = *n;
00503             for (j = 1; j <= i__1; ++j) {
00504                 csscal_(&j, &sigma, &a[j * a_dim1 + 1], &c__1);
00505 /* L20: */
00506             }
00507         }
00508         if (*abstol > 0.f) {
00509             abstll = *abstol * sigma;
00510         }
00511         if (valeig) {
00512             vll = *vl * sigma;
00513             vuu = *vu * sigma;
00514         }
00515     }
00516 /*     Initialize indices into workspaces.  Note: The IWORK indices are */
00517 /*     used only if SSTERF or CSTEMR fail. */
00518 /*     WORK(INDTAU:INDTAU+N-1) stores the complex scalar factors of the */
00519 /*     elementary reflectors used in CHETRD. */
00520     indtau = 1;
00521 /*     INDWK is the starting offset of the remaining complex workspace, */
00522 /*     and LLWORK is the remaining complex workspace size. */
00523     indwk = indtau + *n;
00524     llwork = *lwork - indwk + 1;
00525 /*     RWORK(INDRD:INDRD+N-1) stores the real tridiagonal's diagonal */
00526 /*     entries. */
00527     indrd = 1;
00528 /*     RWORK(INDRE:INDRE+N-1) stores the off-diagonal entries of the */
00529 /*     tridiagonal matrix from CHETRD. */
00530     indre = indrd + *n;
00531 /*     RWORK(INDRDD:INDRDD+N-1) is a copy of the diagonal entries over */
00532 /*     -written by CSTEMR (the SSTERF path copies the diagonal to W). */
00533     indrdd = indre + *n;
00534 /*     RWORK(INDREE:INDREE+N-1) is a copy of the off-diagonal entries over */
00535 /*     -written while computing the eigenvalues in SSTERF and CSTEMR. */
00536     indree = indrdd + *n;
00537 /*     INDRWK is the starting offset of the left-over real workspace, and */
00538 /*     LLRWORK is the remaining workspace size. */
00539     indrwk = indree + *n;
00540     llrwork = *lrwork - indrwk + 1;
00541 /*     IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in SSTEBZ and */
00542 /*     stores the block indices of each of the M<=N eigenvalues. */
00543     indibl = 1;
00544 /*     IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in SSTEBZ and */
00545 /*     stores the starting and finishing indices of each block. */
00546     indisp = indibl + *n;
00547 /*     IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors */
00548 /*     that corresponding to eigenvectors that fail to converge in */
00549 /*     SSTEIN.  This information is discarded; if any fail, the driver */
00550 /*     returns INFO > 0. */
00551     indifl = indisp + *n;
00552 /*     INDIWO is the offset of the remaining integer workspace. */
00553     indiwo = indisp + *n;
00554 
00555 /*     Call CHETRD to reduce Hermitian matrix to tridiagonal form. */
00556 
00557     chetrd_(uplo, n, &a[a_offset], lda, &rwork[indrd], &rwork[indre], &work[
00558             indtau], &work[indwk], &llwork, &iinfo);
00559 
00560 /*     If all eigenvalues are desired */
00561 /*     then call SSTERF or CSTEMR and CUNMTR. */
00562 
00563     test = FALSE_;
00564     if (indeig) {
00565         if (*il == 1 && *iu == *n) {
00566             test = TRUE_;
00567         }
00568     }
00569     if ((alleig || test) && ieeeok == 1) {
00570         if (! wantz) {
00571             scopy_(n, &rwork[indrd], &c__1, &w[1], &c__1);
00572             i__1 = *n - 1;
00573             scopy_(&i__1, &rwork[indre], &c__1, &rwork[indree], &c__1);
00574             ssterf_(n, &w[1], &rwork[indree], info);
00575         } else {
00576             i__1 = *n - 1;
00577             scopy_(&i__1, &rwork[indre], &c__1, &rwork[indree], &c__1);
00578             scopy_(n, &rwork[indrd], &c__1, &rwork[indrdd], &c__1);
00579 
00580             if (*abstol <= *n * 2.f * eps) {
00581                 tryrac = TRUE_;
00582             } else {
00583                 tryrac = FALSE_;
00584             }
00585             cstemr_(jobz, "A", n, &rwork[indrdd], &rwork[indree], vl, vu, il, 
00586                     iu, m, &w[1], &z__[z_offset], ldz, n, &isuppz[1], &tryrac, 
00587                      &rwork[indrwk], &llrwork, &iwork[1], liwork, info);
00588 
00589 /*           Apply unitary matrix used in reduction to tridiagonal */
00590 /*           form to eigenvectors returned by CSTEIN. */
00591 
00592             if (wantz && *info == 0) {
00593                 indwkn = indwk;
00594                 llwrkn = *lwork - indwkn + 1;
00595                 cunmtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau]
00596 , &z__[z_offset], ldz, &work[indwkn], &llwrkn, &iinfo);
00597             }
00598         }
00599 
00600 
00601         if (*info == 0) {
00602             *m = *n;
00603             goto L30;
00604         }
00605         *info = 0;
00606     }
00607 
00608 /*     Otherwise, call SSTEBZ and, if eigenvectors are desired, CSTEIN. */
00609 /*     Also call SSTEBZ and CSTEIN if CSTEMR fails. */
00610 
00611     if (wantz) {
00612         *(unsigned char *)order = 'B';
00613     } else {
00614         *(unsigned char *)order = 'E';
00615     }
00616     sstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &rwork[indrd], &
00617             rwork[indre], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &
00618             rwork[indrwk], &iwork[indiwo], info);
00619 
00620     if (wantz) {
00621         cstein_(n, &rwork[indrd], &rwork[indre], m, &w[1], &iwork[indibl], &
00622                 iwork[indisp], &z__[z_offset], ldz, &rwork[indrwk], &iwork[
00623                 indiwo], &iwork[indifl], info);
00624 
00625 /*        Apply unitary matrix used in reduction to tridiagonal */
00626 /*        form to eigenvectors returned by CSTEIN. */
00627 
00628         indwkn = indwk;
00629         llwrkn = *lwork - indwkn + 1;
00630         cunmtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau], &z__[
00631                 z_offset], ldz, &work[indwkn], &llwrkn, &iinfo);
00632     }
00633 
00634 /*     If matrix was scaled, then rescale eigenvalues appropriately. */
00635 
00636 L30:
00637     if (iscale == 1) {
00638         if (*info == 0) {
00639             imax = *m;
00640         } else {
00641             imax = *info - 1;
00642         }
00643         r__1 = 1.f / sigma;
00644         sscal_(&imax, &r__1, &w[1], &c__1);
00645     }
00646 
00647 /*     If eigenvalues are not in order, then sort them, along with */
00648 /*     eigenvectors. */
00649 
00650     if (wantz) {
00651         i__1 = *m - 1;
00652         for (j = 1; j <= i__1; ++j) {
00653             i__ = 0;
00654             tmp1 = w[j];
00655             i__2 = *m;
00656             for (jj = j + 1; jj <= i__2; ++jj) {
00657                 if (w[jj] < tmp1) {
00658                     i__ = jj;
00659                     tmp1 = w[jj];
00660                 }
00661 /* L40: */
00662             }
00663 
00664             if (i__ != 0) {
00665                 itmp1 = iwork[indibl + i__ - 1];
00666                 w[i__] = w[j];
00667                 iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
00668                 w[j] = tmp1;
00669                 iwork[indibl + j - 1] = itmp1;
00670                 cswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], 
00671                          &c__1);
00672             }
00673 /* L50: */
00674         }
00675     }
00676 
00677 /*     Set WORK(1) to optimal workspace size. */
00678 
00679     work[1].r = (real) lwkopt, work[1].i = 0.f;
00680     rwork[1] = (real) lrwmin;
00681     iwork[1] = liwmin;
00682 
00683     return 0;
00684 
00685 /*     End of CHEEVR */
00686 
00687 } /* cheevr_ */


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