zhpevx.c
Go to the documentation of this file.
00001 /* zhpevx.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 
00020 /* Subroutine */ int zhpevx_(char *jobz, char *range, char *uplo, integer *n, 
00021         doublecomplex *ap, doublereal *vl, doublereal *vu, integer *il, 
00022         integer *iu, doublereal *abstol, integer *m, doublereal *w, 
00023         doublecomplex *z__, integer *ldz, doublecomplex *work, doublereal *
00024         rwork, integer *iwork, integer *ifail, integer *info)
00025 {
00026     /* System generated locals */
00027     integer z_dim1, z_offset, i__1, i__2;
00028     doublereal d__1, d__2;
00029 
00030     /* Builtin functions */
00031     double sqrt(doublereal);
00032 
00033     /* Local variables */
00034     integer i__, j, jj;
00035     doublereal eps, vll, vuu, tmp1;
00036     integer indd, inde;
00037     doublereal anrm;
00038     integer imax;
00039     doublereal rmin, rmax;
00040     logical test;
00041     integer itmp1, indee;
00042     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00043             integer *);
00044     doublereal sigma;
00045     extern logical lsame_(char *, char *);
00046     integer iinfo;
00047     char order[1];
00048     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
00049             doublereal *, integer *);
00050     logical wantz;
00051     extern /* Subroutine */ int zswap_(integer *, doublecomplex *, integer *, 
00052             doublecomplex *, integer *);
00053     extern doublereal dlamch_(char *);
00054     logical alleig, indeig;
00055     integer iscale, indibl;
00056     logical valeig;
00057     doublereal safmin;
00058     extern /* Subroutine */ int xerbla_(char *, integer *), zdscal_(
00059             integer *, doublereal *, doublecomplex *, integer *);
00060     doublereal abstll, bignum;
00061     integer indiwk, indisp, indtau;
00062     extern /* Subroutine */ int dsterf_(integer *, doublereal *, doublereal *, 
00063              integer *), dstebz_(char *, char *, integer *, doublereal *, 
00064             doublereal *, integer *, integer *, doublereal *, doublereal *, 
00065             doublereal *, integer *, integer *, doublereal *, integer *, 
00066             integer *, doublereal *, integer *, integer *);
00067     extern doublereal zlanhp_(char *, char *, integer *, doublecomplex *, 
00068             doublereal *);
00069     integer indrwk, indwrk, nsplit;
00070     doublereal smlnum;
00071     extern /* Subroutine */ int zhptrd_(char *, integer *, doublecomplex *, 
00072             doublereal *, doublereal *, doublecomplex *, integer *), 
00073             zstein_(integer *, doublereal *, doublereal *, integer *, 
00074             doublereal *, integer *, integer *, doublecomplex *, integer *, 
00075             doublereal *, integer *, integer *, integer *), zsteqr_(char *, 
00076             integer *, doublereal *, doublereal *, doublecomplex *, integer *, 
00077              doublereal *, integer *), zupgtr_(char *, integer *, 
00078             doublecomplex *, doublecomplex *, doublecomplex *, integer *, 
00079             doublecomplex *, integer *), zupmtr_(char *, char *, char 
00080             *, integer *, integer *, doublecomplex *, doublecomplex *, 
00081             doublecomplex *, integer *, doublecomplex *, integer *);
00082 
00083 
00084 /*  -- LAPACK driver routine (version 3.2) -- */
00085 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00086 /*     November 2006 */
00087 
00088 /*     .. Scalar Arguments .. */
00089 /*     .. */
00090 /*     .. Array Arguments .. */
00091 /*     .. */
00092 
00093 /*  Purpose */
00094 /*  ======= */
00095 
00096 /*  ZHPEVX computes selected eigenvalues and, optionally, eigenvectors */
00097 /*  of a complex Hermitian matrix A in packed storage. */
00098 /*  Eigenvalues/vectors can be selected by specifying either a range of */
00099 /*  values or a range of indices for the desired eigenvalues. */
00100 
00101 /*  Arguments */
00102 /*  ========= */
00103 
00104 /*  JOBZ    (input) CHARACTER*1 */
00105 /*          = 'N':  Compute eigenvalues only; */
00106 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00107 
00108 /*  RANGE   (input) CHARACTER*1 */
00109 /*          = 'A': all eigenvalues will be found; */
00110 /*          = 'V': all eigenvalues in the half-open interval (VL,VU] */
00111 /*                 will be found; */
00112 /*          = 'I': the IL-th through IU-th eigenvalues will be found. */
00113 
00114 /*  UPLO    (input) CHARACTER*1 */
00115 /*          = 'U':  Upper triangle of A is stored; */
00116 /*          = 'L':  Lower triangle of A is stored. */
00117 
00118 /*  N       (input) INTEGER */
00119 /*          The order of the matrix A.  N >= 0. */
00120 
00121 /*  AP      (input/output) COMPLEX*16 array, dimension (N*(N+1)/2) */
00122 /*          On entry, the upper or lower triangle of the Hermitian matrix */
00123 /*          A, packed columnwise in a linear array.  The j-th column of A */
00124 /*          is stored in the array AP as follows: */
00125 /*          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
00126 /*          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */
00127 
00128 /*          On exit, AP is overwritten by values generated during the */
00129 /*          reduction to tridiagonal form.  If UPLO = 'U', the diagonal */
00130 /*          and first superdiagonal of the tridiagonal matrix T overwrite */
00131 /*          the corresponding elements of A, and if UPLO = 'L', the */
00132 /*          diagonal and first subdiagonal of T overwrite the */
00133 /*          corresponding elements of A. */
00134 
00135 /*  VL      (input) DOUBLE PRECISION */
00136 /*  VU      (input) DOUBLE PRECISION */
00137 /*          If RANGE='V', the lower and upper bounds of the interval to */
00138 /*          be searched for eigenvalues. VL < VU. */
00139 /*          Not referenced if RANGE = 'A' or 'I'. */
00140 
00141 /*  IL      (input) INTEGER */
00142 /*  IU      (input) INTEGER */
00143 /*          If RANGE='I', the indices (in ascending order) of the */
00144 /*          smallest and largest eigenvalues to be returned. */
00145 /*          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
00146 /*          Not referenced if RANGE = 'A' or 'V'. */
00147 
00148 /*  ABSTOL  (input) DOUBLE PRECISION */
00149 /*          The absolute error tolerance for the eigenvalues. */
00150 /*          An approximate eigenvalue is accepted as converged */
00151 /*          when it is determined to lie in an interval [a,b] */
00152 /*          of width less than or equal to */
00153 
00154 /*                  ABSTOL + EPS *   max( |a|,|b| ) , */
00155 
00156 /*          where EPS is the machine precision.  If ABSTOL is less than */
00157 /*          or equal to zero, then  EPS*|T|  will be used in its place, */
00158 /*          where |T| is the 1-norm of the tridiagonal matrix obtained */
00159 /*          by reducing AP to tridiagonal form. */
00160 
00161 /*          Eigenvalues will be computed most accurately when ABSTOL is */
00162 /*          set to twice the underflow threshold 2*DLAMCH('S'), not zero. */
00163 /*          If this routine returns with INFO>0, indicating that some */
00164 /*          eigenvectors did not converge, try setting ABSTOL to */
00165 /*          2*DLAMCH('S'). */
00166 
00167 /*          See "Computing Small Singular Values of Bidiagonal Matrices */
00168 /*          with Guaranteed High Relative Accuracy," by Demmel and */
00169 /*          Kahan, LAPACK Working Note #3. */
00170 
00171 /*  M       (output) INTEGER */
00172 /*          The total number of eigenvalues found.  0 <= M <= N. */
00173 /*          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
00174 
00175 /*  W       (output) DOUBLE PRECISION array, dimension (N) */
00176 /*          If INFO = 0, the selected eigenvalues in ascending order. */
00177 
00178 /*  Z       (output) COMPLEX*16 array, dimension (LDZ, max(1,M)) */
00179 /*          If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
00180 /*          contain the orthonormal eigenvectors of the matrix A */
00181 /*          corresponding to the selected eigenvalues, with the i-th */
00182 /*          column of Z holding the eigenvector associated with W(i). */
00183 /*          If an eigenvector fails to converge, then that column of Z */
00184 /*          contains the latest approximation to the eigenvector, and */
00185 /*          the index of the eigenvector is returned in IFAIL. */
00186 /*          If JOBZ = 'N', then Z is not referenced. */
00187 /*          Note: the user must ensure that at least max(1,M) columns are */
00188 /*          supplied in the array Z; if RANGE = 'V', the exact value of M */
00189 /*          is not known in advance and an upper bound must be used. */
00190 
00191 /*  LDZ     (input) INTEGER */
00192 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00193 /*          JOBZ = 'V', LDZ >= max(1,N). */
00194 
00195 /*  WORK    (workspace) COMPLEX*16 array, dimension (2*N) */
00196 
00197 /*  RWORK   (workspace) DOUBLE PRECISION array, dimension (7*N) */
00198 
00199 /*  IWORK   (workspace) INTEGER array, dimension (5*N) */
00200 
00201 /*  IFAIL   (output) INTEGER array, dimension (N) */
00202 /*          If JOBZ = 'V', then if INFO = 0, the first M elements of */
00203 /*          IFAIL are zero.  If INFO > 0, then IFAIL contains the */
00204 /*          indices of the eigenvectors that failed to converge. */
00205 /*          If JOBZ = 'N', then IFAIL is not referenced. */
00206 
00207 /*  INFO    (output) INTEGER */
00208 /*          = 0:  successful exit */
00209 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00210 /*          > 0:  if INFO = i, then i eigenvectors failed to converge. */
00211 /*                Their indices are stored in array IFAIL. */
00212 
00213 /*  ===================================================================== */
00214 
00215 /*     .. Parameters .. */
00216 /*     .. */
00217 /*     .. Local Scalars .. */
00218 /*     .. */
00219 /*     .. External Functions .. */
00220 /*     .. */
00221 /*     .. External Subroutines .. */
00222 /*     .. */
00223 /*     .. Intrinsic Functions .. */
00224 /*     .. */
00225 /*     .. Executable Statements .. */
00226 
00227 /*     Test the input parameters. */
00228 
00229     /* Parameter adjustments */
00230     --ap;
00231     --w;
00232     z_dim1 = *ldz;
00233     z_offset = 1 + z_dim1;
00234     z__ -= z_offset;
00235     --work;
00236     --rwork;
00237     --iwork;
00238     --ifail;
00239 
00240     /* Function Body */
00241     wantz = lsame_(jobz, "V");
00242     alleig = lsame_(range, "A");
00243     valeig = lsame_(range, "V");
00244     indeig = lsame_(range, "I");
00245 
00246     *info = 0;
00247     if (! (wantz || lsame_(jobz, "N"))) {
00248         *info = -1;
00249     } else if (! (alleig || valeig || indeig)) {
00250         *info = -2;
00251     } else if (! (lsame_(uplo, "L") || lsame_(uplo, 
00252             "U"))) {
00253         *info = -3;
00254     } else if (*n < 0) {
00255         *info = -4;
00256     } else {
00257         if (valeig) {
00258             if (*n > 0 && *vu <= *vl) {
00259                 *info = -7;
00260             }
00261         } else if (indeig) {
00262             if (*il < 1 || *il > max(1,*n)) {
00263                 *info = -8;
00264             } else if (*iu < min(*n,*il) || *iu > *n) {
00265                 *info = -9;
00266             }
00267         }
00268     }
00269     if (*info == 0) {
00270         if (*ldz < 1 || wantz && *ldz < *n) {
00271             *info = -14;
00272         }
00273     }
00274 
00275     if (*info != 0) {
00276         i__1 = -(*info);
00277         xerbla_("ZHPEVX", &i__1);
00278         return 0;
00279     }
00280 
00281 /*     Quick return if possible */
00282 
00283     *m = 0;
00284     if (*n == 0) {
00285         return 0;
00286     }
00287 
00288     if (*n == 1) {
00289         if (alleig || indeig) {
00290             *m = 1;
00291             w[1] = ap[1].r;
00292         } else {
00293             if (*vl < ap[1].r && *vu >= ap[1].r) {
00294                 *m = 1;
00295                 w[1] = ap[1].r;
00296             }
00297         }
00298         if (wantz) {
00299             i__1 = z_dim1 + 1;
00300             z__[i__1].r = 1., z__[i__1].i = 0.;
00301         }
00302         return 0;
00303     }
00304 
00305 /*     Get machine constants. */
00306 
00307     safmin = dlamch_("Safe minimum");
00308     eps = dlamch_("Precision");
00309     smlnum = safmin / eps;
00310     bignum = 1. / smlnum;
00311     rmin = sqrt(smlnum);
00312 /* Computing MIN */
00313     d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
00314     rmax = min(d__1,d__2);
00315 
00316 /*     Scale matrix to allowable range, if necessary. */
00317 
00318     iscale = 0;
00319     abstll = *abstol;
00320     if (valeig) {
00321         vll = *vl;
00322         vuu = *vu;
00323     } else {
00324         vll = 0.;
00325         vuu = 0.;
00326     }
00327     anrm = zlanhp_("M", uplo, n, &ap[1], &rwork[1]);
00328     if (anrm > 0. && anrm < rmin) {
00329         iscale = 1;
00330         sigma = rmin / anrm;
00331     } else if (anrm > rmax) {
00332         iscale = 1;
00333         sigma = rmax / anrm;
00334     }
00335     if (iscale == 1) {
00336         i__1 = *n * (*n + 1) / 2;
00337         zdscal_(&i__1, &sigma, &ap[1], &c__1);
00338         if (*abstol > 0.) {
00339             abstll = *abstol * sigma;
00340         }
00341         if (valeig) {
00342             vll = *vl * sigma;
00343             vuu = *vu * sigma;
00344         }
00345     }
00346 
00347 /*     Call ZHPTRD to reduce Hermitian packed matrix to tridiagonal form. */
00348 
00349     indd = 1;
00350     inde = indd + *n;
00351     indrwk = inde + *n;
00352     indtau = 1;
00353     indwrk = indtau + *n;
00354     zhptrd_(uplo, n, &ap[1], &rwork[indd], &rwork[inde], &work[indtau], &
00355             iinfo);
00356 
00357 /*     If all eigenvalues are desired and ABSTOL is less than or equal */
00358 /*     to zero, then call DSTERF or ZUPGTR and ZSTEQR.  If this fails */
00359 /*     for some eigenvalue, then try DSTEBZ. */
00360 
00361     test = FALSE_;
00362     if (indeig) {
00363         if (*il == 1 && *iu == *n) {
00364             test = TRUE_;
00365         }
00366     }
00367     if ((alleig || test) && *abstol <= 0.) {
00368         dcopy_(n, &rwork[indd], &c__1, &w[1], &c__1);
00369         indee = indrwk + (*n << 1);
00370         if (! wantz) {
00371             i__1 = *n - 1;
00372             dcopy_(&i__1, &rwork[inde], &c__1, &rwork[indee], &c__1);
00373             dsterf_(n, &w[1], &rwork[indee], info);
00374         } else {
00375             zupgtr_(uplo, n, &ap[1], &work[indtau], &z__[z_offset], ldz, &
00376                     work[indwrk], &iinfo);
00377             i__1 = *n - 1;
00378             dcopy_(&i__1, &rwork[inde], &c__1, &rwork[indee], &c__1);
00379             zsteqr_(jobz, n, &w[1], &rwork[indee], &z__[z_offset], ldz, &
00380                     rwork[indrwk], info);
00381             if (*info == 0) {
00382                 i__1 = *n;
00383                 for (i__ = 1; i__ <= i__1; ++i__) {
00384                     ifail[i__] = 0;
00385 /* L10: */
00386                 }
00387             }
00388         }
00389         if (*info == 0) {
00390             *m = *n;
00391             goto L20;
00392         }
00393         *info = 0;
00394     }
00395 
00396 /*     Otherwise, call DSTEBZ and, if eigenvectors are desired, ZSTEIN. */
00397 
00398     if (wantz) {
00399         *(unsigned char *)order = 'B';
00400     } else {
00401         *(unsigned char *)order = 'E';
00402     }
00403     indibl = 1;
00404     indisp = indibl + *n;
00405     indiwk = indisp + *n;
00406     dstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &rwork[indd], &
00407             rwork[inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &
00408             rwork[indrwk], &iwork[indiwk], info);
00409 
00410     if (wantz) {
00411         zstein_(n, &rwork[indd], &rwork[inde], m, &w[1], &iwork[indibl], &
00412                 iwork[indisp], &z__[z_offset], ldz, &rwork[indrwk], &iwork[
00413                 indiwk], &ifail[1], info);
00414 
00415 /*        Apply unitary matrix used in reduction to tridiagonal */
00416 /*        form to eigenvectors returned by ZSTEIN. */
00417 
00418         indwrk = indtau + *n;
00419         zupmtr_("L", uplo, "N", n, m, &ap[1], &work[indtau], &z__[z_offset], 
00420                 ldz, &work[indwrk], &iinfo);
00421     }
00422 
00423 /*     If matrix was scaled, then rescale eigenvalues appropriately. */
00424 
00425 L20:
00426     if (iscale == 1) {
00427         if (*info == 0) {
00428             imax = *m;
00429         } else {
00430             imax = *info - 1;
00431         }
00432         d__1 = 1. / sigma;
00433         dscal_(&imax, &d__1, &w[1], &c__1);
00434     }
00435 
00436 /*     If eigenvalues are not in order, then sort them, along with */
00437 /*     eigenvectors. */
00438 
00439     if (wantz) {
00440         i__1 = *m - 1;
00441         for (j = 1; j <= i__1; ++j) {
00442             i__ = 0;
00443             tmp1 = w[j];
00444             i__2 = *m;
00445             for (jj = j + 1; jj <= i__2; ++jj) {
00446                 if (w[jj] < tmp1) {
00447                     i__ = jj;
00448                     tmp1 = w[jj];
00449                 }
00450 /* L30: */
00451             }
00452 
00453             if (i__ != 0) {
00454                 itmp1 = iwork[indibl + i__ - 1];
00455                 w[i__] = w[j];
00456                 iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
00457                 w[j] = tmp1;
00458                 iwork[indibl + j - 1] = itmp1;
00459                 zswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], 
00460                          &c__1);
00461                 if (*info != 0) {
00462                     itmp1 = ifail[i__];
00463                     ifail[i__] = ifail[j];
00464                     ifail[j] = itmp1;
00465                 }
00466             }
00467 /* L40: */
00468         }
00469     }
00470 
00471     return 0;
00472 
00473 /*     End of ZHPEVX */
00474 
00475 } /* zhpevx_ */


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