zhbgvx.c
Go to the documentation of this file.
00001 /* zhbgvx.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 integer c__1 = 1;
00021 
00022 /* Subroutine */ int zhbgvx_(char *jobz, char *range, char *uplo, integer *n, 
00023         integer *ka, integer *kb, doublecomplex *ab, integer *ldab, 
00024         doublecomplex *bb, integer *ldbb, doublecomplex *q, integer *ldq, 
00025         doublereal *vl, doublereal *vu, integer *il, integer *iu, doublereal *
00026         abstol, integer *m, doublereal *w, doublecomplex *z__, integer *ldz, 
00027         doublecomplex *work, doublereal *rwork, integer *iwork, integer *
00028         ifail, integer *info)
00029 {
00030     /* System generated locals */
00031     integer ab_dim1, ab_offset, bb_dim1, bb_offset, q_dim1, q_offset, z_dim1, 
00032             z_offset, i__1, i__2;
00033 
00034     /* Local variables */
00035     integer i__, j, jj;
00036     doublereal tmp1;
00037     integer indd, inde;
00038     char vect[1];
00039     logical test;
00040     integer itmp1, indee;
00041     extern logical lsame_(char *, char *);
00042     integer iinfo;
00043     char order[1];
00044     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
00045             doublereal *, integer *), zgemv_(char *, integer *, integer *, 
00046             doublecomplex *, doublecomplex *, integer *, doublecomplex *, 
00047             integer *, doublecomplex *, doublecomplex *, integer *);
00048     logical upper, wantz;
00049     extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *, 
00050             doublecomplex *, integer *), zswap_(integer *, doublecomplex *, 
00051             integer *, doublecomplex *, integer *);
00052     logical alleig, indeig;
00053     integer indibl;
00054     logical valeig;
00055     extern /* Subroutine */ int xerbla_(char *, integer *);
00056     integer indiwk, indisp;
00057     extern /* Subroutine */ int dsterf_(integer *, doublereal *, doublereal *, 
00058              integer *), dstebz_(char *, char *, integer *, doublereal *, 
00059             doublereal *, integer *, integer *, doublereal *, doublereal *, 
00060             doublereal *, integer *, integer *, doublereal *, integer *, 
00061             integer *, doublereal *, integer *, integer *), 
00062             zhbtrd_(char *, char *, integer *, integer *, doublecomplex *, 
00063             integer *, doublereal *, doublereal *, doublecomplex *, integer *, 
00064              doublecomplex *, integer *);
00065     integer indrwk, indwrk;
00066     extern /* Subroutine */ int zhbgst_(char *, char *, integer *, integer *, 
00067             integer *, doublecomplex *, integer *, doublecomplex *, integer *, 
00068              doublecomplex *, integer *, doublecomplex *, doublereal *, 
00069             integer *), zlacpy_(char *, integer *, integer *, 
00070             doublecomplex *, integer *, doublecomplex *, integer *);
00071     integer nsplit;
00072     extern /* Subroutine */ int zpbstf_(char *, integer *, integer *, 
00073             doublecomplex *, integer *, integer *), zstein_(integer *, 
00074              doublereal *, doublereal *, integer *, doublereal *, integer *, 
00075             integer *, doublecomplex *, integer *, doublereal *, integer *, 
00076             integer *, integer *), zsteqr_(char *, integer *, doublereal *, 
00077             doublereal *, doublecomplex *, integer *, doublereal *, integer *);
00078 
00079 
00080 /*  -- LAPACK driver routine (version 3.2) -- */
00081 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00082 /*     November 2006 */
00083 
00084 /*     .. Scalar Arguments .. */
00085 /*     .. */
00086 /*     .. Array Arguments .. */
00087 /*     .. */
00088 
00089 /*  Purpose */
00090 /*  ======= */
00091 
00092 /*  ZHBGVX computes all the eigenvalues, and optionally, the eigenvectors */
00093 /*  of a complex generalized Hermitian-definite banded eigenproblem, of */
00094 /*  the form A*x=(lambda)*B*x. Here A and B are assumed to be Hermitian */
00095 /*  and banded, and B is also positive definite.  Eigenvalues and */
00096 /*  eigenvectors can be selected by specifying either all eigenvalues, */
00097 /*  a range of values or a range of indices for the desired eigenvalues. */
00098 
00099 /*  Arguments */
00100 /*  ========= */
00101 
00102 /*  JOBZ    (input) CHARACTER*1 */
00103 /*          = 'N':  Compute eigenvalues only; */
00104 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00105 
00106 /*  RANGE   (input) CHARACTER*1 */
00107 /*          = 'A': all eigenvalues will be found; */
00108 /*          = 'V': all eigenvalues in the half-open interval (VL,VU] */
00109 /*                 will be found; */
00110 /*          = 'I': the IL-th through IU-th eigenvalues will be found. */
00111 
00112 /*  UPLO    (input) CHARACTER*1 */
00113 /*          = 'U':  Upper triangles of A and B are stored; */
00114 /*          = 'L':  Lower triangles of A and B are stored. */
00115 
00116 /*  N       (input) INTEGER */
00117 /*          The order of the matrices A and B.  N >= 0. */
00118 
00119 /*  KA      (input) INTEGER */
00120 /*          The number of superdiagonals of the matrix A if UPLO = 'U', */
00121 /*          or the number of subdiagonals if UPLO = 'L'. KA >= 0. */
00122 
00123 /*  KB      (input) INTEGER */
00124 /*          The number of superdiagonals of the matrix B if UPLO = 'U', */
00125 /*          or the number of subdiagonals if UPLO = 'L'. KB >= 0. */
00126 
00127 /*  AB      (input/output) COMPLEX*16 array, dimension (LDAB, N) */
00128 /*          On entry, the upper or lower triangle of the Hermitian band */
00129 /*          matrix A, stored in the first ka+1 rows of the array.  The */
00130 /*          j-th column of A is stored in the j-th column of the array AB */
00131 /*          as follows: */
00132 /*          if UPLO = 'U', AB(ka+1+i-j,j) = A(i,j) for max(1,j-ka)<=i<=j; */
00133 /*          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+ka). */
00134 
00135 /*          On exit, the contents of AB are destroyed. */
00136 
00137 /*  LDAB    (input) INTEGER */
00138 /*          The leading dimension of the array AB.  LDAB >= KA+1. */
00139 
00140 /*  BB      (input/output) COMPLEX*16 array, dimension (LDBB, N) */
00141 /*          On entry, the upper or lower triangle of the Hermitian band */
00142 /*          matrix B, stored in the first kb+1 rows of the array.  The */
00143 /*          j-th column of B is stored in the j-th column of the array BB */
00144 /*          as follows: */
00145 /*          if UPLO = 'U', BB(kb+1+i-j,j) = B(i,j) for max(1,j-kb)<=i<=j; */
00146 /*          if UPLO = 'L', BB(1+i-j,j)    = B(i,j) for j<=i<=min(n,j+kb). */
00147 
00148 /*          On exit, the factor S from the split Cholesky factorization */
00149 /*          B = S**H*S, as returned by ZPBSTF. */
00150 
00151 /*  LDBB    (input) INTEGER */
00152 /*          The leading dimension of the array BB.  LDBB >= KB+1. */
00153 
00154 /*  Q       (output) COMPLEX*16 array, dimension (LDQ, N) */
00155 /*          If JOBZ = 'V', the n-by-n matrix used in the reduction of */
00156 /*          A*x = (lambda)*B*x to standard form, i.e. C*x = (lambda)*x, */
00157 /*          and consequently C to tridiagonal form. */
00158 /*          If JOBZ = 'N', the array Q is not referenced. */
00159 
00160 /*  LDQ     (input) INTEGER */
00161 /*          The leading dimension of the array Q.  If JOBZ = 'N', */
00162 /*          LDQ >= 1. If JOBZ = 'V', LDQ >= max(1,N). */
00163 
00164 /*  VL      (input) DOUBLE PRECISION */
00165 /*  VU      (input) DOUBLE PRECISION */
00166 /*          If RANGE='V', the lower and upper bounds of the interval to */
00167 /*          be searched for eigenvalues. VL < VU. */
00168 /*          Not referenced if RANGE = 'A' or 'I'. */
00169 
00170 /*  IL      (input) INTEGER */
00171 /*  IU      (input) INTEGER */
00172 /*          If RANGE='I', the indices (in ascending order) of the */
00173 /*          smallest and largest eigenvalues to be returned. */
00174 /*          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
00175 /*          Not referenced if RANGE = 'A' or 'V'. */
00176 
00177 /*  ABSTOL  (input) DOUBLE PRECISION */
00178 /*          The absolute error tolerance for the eigenvalues. */
00179 /*          An approximate eigenvalue is accepted as converged */
00180 /*          when it is determined to lie in an interval [a,b] */
00181 /*          of width less than or equal to */
00182 
00183 /*                  ABSTOL + EPS *   max( |a|,|b| ) , */
00184 
00185 /*          where EPS is the machine precision.  If ABSTOL is less than */
00186 /*          or equal to zero, then  EPS*|T|  will be used in its place, */
00187 /*          where |T| is the 1-norm of the tridiagonal matrix obtained */
00188 /*          by reducing AP to tridiagonal form. */
00189 
00190 /*          Eigenvalues will be computed most accurately when ABSTOL is */
00191 /*          set to twice the underflow threshold 2*DLAMCH('S'), not zero. */
00192 /*          If this routine returns with INFO>0, indicating that some */
00193 /*          eigenvectors did not converge, try setting ABSTOL to */
00194 /*          2*DLAMCH('S'). */
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 /*          If INFO = 0, the eigenvalues in ascending order. */
00202 
00203 /*  Z       (output) COMPLEX*16 array, dimension (LDZ, N) */
00204 /*          If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of */
00205 /*          eigenvectors, with the i-th column of Z holding the */
00206 /*          eigenvector associated with W(i). The eigenvectors are */
00207 /*          normalized so that Z**H*B*Z = I. */
00208 /*          If JOBZ = 'N', then Z is not referenced. */
00209 
00210 /*  LDZ     (input) INTEGER */
00211 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00212 /*          JOBZ = 'V', LDZ >= N. */
00213 
00214 /*  WORK    (workspace) COMPLEX*16 array, dimension (N) */
00215 
00216 /*  RWORK   (workspace) DOUBLE PRECISION array, dimension (7*N) */
00217 
00218 /*  IWORK   (workspace) INTEGER array, dimension (5*N) */
00219 
00220 /*  IFAIL   (output) INTEGER array, dimension (N) */
00221 /*          If JOBZ = 'V', then if INFO = 0, the first M elements of */
00222 /*          IFAIL are zero.  If INFO > 0, then IFAIL contains the */
00223 /*          indices of the eigenvectors that failed to converge. */
00224 /*          If JOBZ = 'N', then IFAIL is not referenced. */
00225 
00226 /*  INFO    (output) INTEGER */
00227 /*          = 0:  successful exit */
00228 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00229 /*          > 0:  if INFO = i, and i is: */
00230 /*             <= N:  then i eigenvectors failed to converge.  Their */
00231 /*                    indices are stored in array IFAIL. */
00232 /*             > N:   if INFO = N + i, for 1 <= i <= N, then ZPBSTF */
00233 /*                    returned INFO = i: B is not positive definite. */
00234 /*                    The factorization of B could not be completed and */
00235 /*                    no eigenvalues or eigenvectors were computed. */
00236 
00237 /*  Further Details */
00238 /*  =============== */
00239 
00240 /*  Based on contributions by */
00241 /*     Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */
00242 
00243 /*  ===================================================================== */
00244 
00245 /*     .. Parameters .. */
00246 /*     .. */
00247 /*     .. Local Scalars .. */
00248 /*     .. */
00249 /*     .. External Functions .. */
00250 /*     .. */
00251 /*     .. External Subroutines .. */
00252 /*     .. */
00253 /*     .. Intrinsic Functions .. */
00254 /*     .. */
00255 /*     .. Executable Statements .. */
00256 
00257 /*     Test the input parameters. */
00258 
00259     /* Parameter adjustments */
00260     ab_dim1 = *ldab;
00261     ab_offset = 1 + ab_dim1;
00262     ab -= ab_offset;
00263     bb_dim1 = *ldbb;
00264     bb_offset = 1 + bb_dim1;
00265     bb -= bb_offset;
00266     q_dim1 = *ldq;
00267     q_offset = 1 + q_dim1;
00268     q -= q_offset;
00269     --w;
00270     z_dim1 = *ldz;
00271     z_offset = 1 + z_dim1;
00272     z__ -= z_offset;
00273     --work;
00274     --rwork;
00275     --iwork;
00276     --ifail;
00277 
00278     /* Function Body */
00279     wantz = lsame_(jobz, "V");
00280     upper = lsame_(uplo, "U");
00281     alleig = lsame_(range, "A");
00282     valeig = lsame_(range, "V");
00283     indeig = lsame_(range, "I");
00284 
00285     *info = 0;
00286     if (! (wantz || lsame_(jobz, "N"))) {
00287         *info = -1;
00288     } else if (! (alleig || valeig || indeig)) {
00289         *info = -2;
00290     } else if (! (upper || lsame_(uplo, "L"))) {
00291         *info = -3;
00292     } else if (*n < 0) {
00293         *info = -4;
00294     } else if (*ka < 0) {
00295         *info = -5;
00296     } else if (*kb < 0 || *kb > *ka) {
00297         *info = -6;
00298     } else if (*ldab < *ka + 1) {
00299         *info = -8;
00300     } else if (*ldbb < *kb + 1) {
00301         *info = -10;
00302     } else if (*ldq < 1 || wantz && *ldq < *n) {
00303         *info = -12;
00304     } else {
00305         if (valeig) {
00306             if (*n > 0 && *vu <= *vl) {
00307                 *info = -14;
00308             }
00309         } else if (indeig) {
00310             if (*il < 1 || *il > max(1,*n)) {
00311                 *info = -15;
00312             } else if (*iu < min(*n,*il) || *iu > *n) {
00313                 *info = -16;
00314             }
00315         }
00316     }
00317     if (*info == 0) {
00318         if (*ldz < 1 || wantz && *ldz < *n) {
00319             *info = -21;
00320         }
00321     }
00322 
00323     if (*info != 0) {
00324         i__1 = -(*info);
00325         xerbla_("ZHBGVX", &i__1);
00326         return 0;
00327     }
00328 
00329 /*     Quick return if possible */
00330 
00331     *m = 0;
00332     if (*n == 0) {
00333         return 0;
00334     }
00335 
00336 /*     Form a split Cholesky factorization of B. */
00337 
00338     zpbstf_(uplo, n, kb, &bb[bb_offset], ldbb, info);
00339     if (*info != 0) {
00340         *info = *n + *info;
00341         return 0;
00342     }
00343 
00344 /*     Transform problem to standard eigenvalue problem. */
00345 
00346     zhbgst_(jobz, uplo, n, ka, kb, &ab[ab_offset], ldab, &bb[bb_offset], ldbb, 
00347              &q[q_offset], ldq, &work[1], &rwork[1], &iinfo);
00348 
00349 /*     Solve the standard eigenvalue problem. */
00350 /*     Reduce Hermitian band matrix to tridiagonal form. */
00351 
00352     indd = 1;
00353     inde = indd + *n;
00354     indrwk = inde + *n;
00355     indwrk = 1;
00356     if (wantz) {
00357         *(unsigned char *)vect = 'U';
00358     } else {
00359         *(unsigned char *)vect = 'N';
00360     }
00361     zhbtrd_(vect, uplo, n, ka, &ab[ab_offset], ldab, &rwork[indd], &rwork[
00362             inde], &q[q_offset], ldq, &work[indwrk], &iinfo);
00363 
00364 /*     If all eigenvalues are desired and ABSTOL is less than or equal */
00365 /*     to zero, then call DSTERF or ZSTEQR.  If this fails for some */
00366 /*     eigenvalue, then try DSTEBZ. */
00367 
00368     test = FALSE_;
00369     if (indeig) {
00370         if (*il == 1 && *iu == *n) {
00371             test = TRUE_;
00372         }
00373     }
00374     if ((alleig || test) && *abstol <= 0.) {
00375         dcopy_(n, &rwork[indd], &c__1, &w[1], &c__1);
00376         indee = indrwk + (*n << 1);
00377         i__1 = *n - 1;
00378         dcopy_(&i__1, &rwork[inde], &c__1, &rwork[indee], &c__1);
00379         if (! wantz) {
00380             dsterf_(n, &w[1], &rwork[indee], info);
00381         } else {
00382             zlacpy_("A", n, n, &q[q_offset], ldq, &z__[z_offset], ldz);
00383             zsteqr_(jobz, n, &w[1], &rwork[indee], &z__[z_offset], ldz, &
00384                     rwork[indrwk], info);
00385             if (*info == 0) {
00386                 i__1 = *n;
00387                 for (i__ = 1; i__ <= i__1; ++i__) {
00388                     ifail[i__] = 0;
00389 /* L10: */
00390                 }
00391             }
00392         }
00393         if (*info == 0) {
00394             *m = *n;
00395             goto L30;
00396         }
00397         *info = 0;
00398     }
00399 
00400 /*     Otherwise, call DSTEBZ and, if eigenvectors are desired, */
00401 /*     call ZSTEIN. */
00402 
00403     if (wantz) {
00404         *(unsigned char *)order = 'B';
00405     } else {
00406         *(unsigned char *)order = 'E';
00407     }
00408     indibl = 1;
00409     indisp = indibl + *n;
00410     indiwk = indisp + *n;
00411     dstebz_(range, order, n, vl, vu, il, iu, abstol, &rwork[indd], &rwork[
00412             inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &rwork[
00413             indrwk], &iwork[indiwk], info);
00414 
00415     if (wantz) {
00416         zstein_(n, &rwork[indd], &rwork[inde], m, &w[1], &iwork[indibl], &
00417                 iwork[indisp], &z__[z_offset], ldz, &rwork[indrwk], &iwork[
00418                 indiwk], &ifail[1], info);
00419 
00420 /*        Apply unitary matrix used in reduction to tridiagonal */
00421 /*        form to eigenvectors returned by ZSTEIN. */
00422 
00423         i__1 = *m;
00424         for (j = 1; j <= i__1; ++j) {
00425             zcopy_(n, &z__[j * z_dim1 + 1], &c__1, &work[1], &c__1);
00426             zgemv_("N", n, n, &c_b2, &q[q_offset], ldq, &work[1], &c__1, &
00427                     c_b1, &z__[j * z_dim1 + 1], &c__1);
00428 /* L20: */
00429         }
00430     }
00431 
00432 L30:
00433 
00434 /*     If eigenvalues are not in order, then sort them, along with */
00435 /*     eigenvectors. */
00436 
00437     if (wantz) {
00438         i__1 = *m - 1;
00439         for (j = 1; j <= i__1; ++j) {
00440             i__ = 0;
00441             tmp1 = w[j];
00442             i__2 = *m;
00443             for (jj = j + 1; jj <= i__2; ++jj) {
00444                 if (w[jj] < tmp1) {
00445                     i__ = jj;
00446                     tmp1 = w[jj];
00447                 }
00448 /* L40: */
00449             }
00450 
00451             if (i__ != 0) {
00452                 itmp1 = iwork[indibl + i__ - 1];
00453                 w[i__] = w[j];
00454                 iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
00455                 w[j] = tmp1;
00456                 iwork[indibl + j - 1] = itmp1;
00457                 zswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], 
00458                          &c__1);
00459                 if (*info != 0) {
00460                     itmp1 = ifail[i__];
00461                     ifail[i__] = ifail[j];
00462                     ifail[j] = itmp1;
00463                 }
00464             }
00465 /* L50: */
00466         }
00467     }
00468 
00469     return 0;
00470 
00471 /*     End of ZHBGVX */
00472 
00473 } /* zhbgvx_ */


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