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


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