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


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