zhbevd.c
Go to the documentation of this file.
00001 /* zhbevd.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_b13 = 1.;
00021 static integer c__1 = 1;
00022 
00023 /* Subroutine */ int zhbevd_(char *jobz, char *uplo, integer *n, integer *kd, 
00024         doublecomplex *ab, integer *ldab, doublereal *w, doublecomplex *z__, 
00025         integer *ldz, doublecomplex *work, integer *lwork, doublereal *rwork, 
00026         integer *lrwork, integer *iwork, integer *liwork, integer *info)
00027 {
00028     /* System generated locals */
00029     integer ab_dim1, ab_offset, z_dim1, z_offset, i__1;
00030     doublereal d__1;
00031 
00032     /* Builtin functions */
00033     double sqrt(doublereal);
00034 
00035     /* Local variables */
00036     doublereal eps;
00037     integer inde;
00038     doublereal anrm;
00039     integer imax;
00040     doublereal rmin, rmax;
00041     integer llwk2;
00042     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00043             integer *);
00044     doublereal sigma;
00045     extern logical lsame_(char *, char *);
00046     integer iinfo;
00047     extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *, 
00048             integer *, doublecomplex *, doublecomplex *, integer *, 
00049             doublecomplex *, integer *, doublecomplex *, doublecomplex *, 
00050             integer *);
00051     integer lwmin;
00052     logical lower;
00053     integer llrwk;
00054     logical wantz;
00055     integer indwk2;
00056     extern doublereal dlamch_(char *);
00057     integer iscale;
00058     doublereal safmin;
00059     extern doublereal zlanhb_(char *, char *, integer *, integer *, 
00060             doublecomplex *, integer *, doublereal *);
00061     extern /* Subroutine */ int xerbla_(char *, integer *);
00062     doublereal bignum;
00063     extern /* Subroutine */ int dsterf_(integer *, doublereal *, doublereal *, 
00064              integer *), zlascl_(char *, integer *, integer *, doublereal *, 
00065             doublereal *, integer *, integer *, doublecomplex *, integer *, 
00066             integer *), zstedc_(char *, integer *, doublereal *, 
00067             doublereal *, doublecomplex *, integer *, doublecomplex *, 
00068             integer *, doublereal *, integer *, integer *, integer *, integer 
00069             *), zhbtrd_(char *, char *, integer *, integer *, 
00070             doublecomplex *, integer *, doublereal *, doublereal *, 
00071             doublecomplex *, integer *, doublecomplex *, integer *);
00072     integer indwrk, liwmin;
00073     extern /* Subroutine */ int zlacpy_(char *, integer *, integer *, 
00074             doublecomplex *, integer *, doublecomplex *, integer *);
00075     integer lrwmin;
00076     doublereal smlnum;
00077     logical lquery;
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 /*  ZHBEVD computes all the eigenvalues and, optionally, eigenvectors of */
00093 /*  a complex Hermitian band matrix A.  If eigenvectors are desired, it */
00094 /*  uses a divide and conquer algorithm. */
00095 
00096 /*  The divide and conquer algorithm makes very mild assumptions about */
00097 /*  floating point arithmetic. It will work on machines with a guard */
00098 /*  digit in add/subtract, or on those binary machines without guard */
00099 /*  digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */
00100 /*  Cray-2. It could conceivably fail on hexadecimal or decimal machines */
00101 /*  without guard digits, but we know of none. */
00102 
00103 /*  Arguments */
00104 /*  ========= */
00105 
00106 /*  JOBZ    (input) CHARACTER*1 */
00107 /*          = 'N':  Compute eigenvalues only; */
00108 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00109 
00110 /*  UPLO    (input) CHARACTER*1 */
00111 /*          = 'U':  Upper triangle of A is stored; */
00112 /*          = 'L':  Lower triangle of A is stored. */
00113 
00114 /*  N       (input) INTEGER */
00115 /*          The order of the matrix A.  N >= 0. */
00116 
00117 /*  KD      (input) INTEGER */
00118 /*          The number of superdiagonals of the matrix A if UPLO = 'U', */
00119 /*          or the number of subdiagonals if UPLO = 'L'.  KD >= 0. */
00120 
00121 /*  AB      (input/output) COMPLEX*16 array, dimension (LDAB, N) */
00122 /*          On entry, the upper or lower triangle of the Hermitian band */
00123 /*          matrix A, stored in the first KD+1 rows of the array.  The */
00124 /*          j-th column of A is stored in the j-th column of the array AB */
00125 /*          as follows: */
00126 /*          if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */
00127 /*          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+kd). */
00128 
00129 /*          On exit, AB is overwritten by values generated during the */
00130 /*          reduction to tridiagonal form.  If UPLO = 'U', the first */
00131 /*          superdiagonal and the diagonal of the tridiagonal matrix T */
00132 /*          are returned in rows KD and KD+1 of AB, and if UPLO = 'L', */
00133 /*          the diagonal and first subdiagonal of T are returned in the */
00134 /*          first two rows of AB. */
00135 
00136 /*  LDAB    (input) INTEGER */
00137 /*          The leading dimension of the array AB.  LDAB >= KD + 1. */
00138 
00139 /*  W       (output) DOUBLE PRECISION array, dimension (N) */
00140 /*          If INFO = 0, the eigenvalues in ascending order. */
00141 
00142 /*  Z       (output) COMPLEX*16 array, dimension (LDZ, N) */
00143 /*          If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal */
00144 /*          eigenvectors of the matrix A, with the i-th column of Z */
00145 /*          holding the eigenvector associated with W(i). */
00146 /*          If JOBZ = 'N', then Z is not referenced. */
00147 
00148 /*  LDZ     (input) INTEGER */
00149 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00150 /*          JOBZ = 'V', LDZ >= max(1,N). */
00151 
00152 /*  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */
00153 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00154 
00155 /*  LWORK   (input) INTEGER */
00156 /*          The dimension of the array WORK. */
00157 /*          If N <= 1,               LWORK must be at least 1. */
00158 /*          If JOBZ = 'N' and N > 1, LWORK must be at least N. */
00159 /*          If JOBZ = 'V' and N > 1, LWORK must be at least 2*N**2. */
00160 
00161 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00162 /*          only calculates the optimal sizes of the WORK, RWORK and */
00163 /*          IWORK arrays, returns these values as the first entries of */
00164 /*          the WORK, RWORK and IWORK arrays, and no error message */
00165 /*          related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
00166 
00167 /*  RWORK   (workspace/output) DOUBLE PRECISION array, */
00168 /*                                         dimension (LRWORK) */
00169 /*          On exit, if INFO = 0, RWORK(1) returns the optimal LRWORK. */
00170 
00171 /*  LRWORK  (input) INTEGER */
00172 /*          The dimension of array RWORK. */
00173 /*          If N <= 1,               LRWORK must be at least 1. */
00174 /*          If JOBZ = 'N' and N > 1, LRWORK must be at least N. */
00175 /*          If JOBZ = 'V' and N > 1, LRWORK must be at least */
00176 /*                        1 + 5*N + 2*N**2. */
00177 
00178 /*          If LRWORK = -1, then a workspace query is assumed; the */
00179 /*          routine only calculates the optimal sizes of the WORK, RWORK */
00180 /*          and IWORK arrays, returns these values as the first entries */
00181 /*          of the WORK, RWORK and IWORK arrays, and no error message */
00182 /*          related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
00183 
00184 /*  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
00185 /*          On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
00186 
00187 /*  LIWORK  (input) INTEGER */
00188 /*          The dimension of array IWORK. */
00189 /*          If JOBZ = 'N' or N <= 1, LIWORK must be at least 1. */
00190 /*          If JOBZ = 'V' and N > 1, LIWORK must be at least 3 + 5*N . */
00191 
00192 /*          If LIWORK = -1, then a workspace query is assumed; the */
00193 /*          routine only calculates the optimal sizes of the WORK, RWORK */
00194 /*          and IWORK arrays, returns these values as the first entries */
00195 /*          of the WORK, RWORK and IWORK arrays, and no error message */
00196 /*          related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
00197 
00198 /*  INFO    (output) INTEGER */
00199 /*          = 0:  successful exit. */
00200 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00201 /*          > 0:  if INFO = i, the algorithm failed to converge; i */
00202 /*                off-diagonal elements of an intermediate tridiagonal */
00203 /*                form did not converge to zero. */
00204 
00205 /*  ===================================================================== */
00206 
00207 /*     .. Parameters .. */
00208 /*     .. */
00209 /*     .. Local Scalars .. */
00210 /*     .. */
00211 /*     .. External Functions .. */
00212 /*     .. */
00213 /*     .. External Subroutines .. */
00214 /*     .. */
00215 /*     .. Intrinsic Functions .. */
00216 /*     .. */
00217 /*     .. Executable Statements .. */
00218 
00219 /*     Test the input parameters. */
00220 
00221     /* Parameter adjustments */
00222     ab_dim1 = *ldab;
00223     ab_offset = 1 + ab_dim1;
00224     ab -= ab_offset;
00225     --w;
00226     z_dim1 = *ldz;
00227     z_offset = 1 + z_dim1;
00228     z__ -= z_offset;
00229     --work;
00230     --rwork;
00231     --iwork;
00232 
00233     /* Function Body */
00234     wantz = lsame_(jobz, "V");
00235     lower = lsame_(uplo, "L");
00236     lquery = *lwork == -1 || *liwork == -1 || *lrwork == -1;
00237 
00238     *info = 0;
00239     if (*n <= 1) {
00240         lwmin = 1;
00241         lrwmin = 1;
00242         liwmin = 1;
00243     } else {
00244         if (wantz) {
00245 /* Computing 2nd power */
00246             i__1 = *n;
00247             lwmin = i__1 * i__1 << 1;
00248 /* Computing 2nd power */
00249             i__1 = *n;
00250             lrwmin = *n * 5 + 1 + (i__1 * i__1 << 1);
00251             liwmin = *n * 5 + 3;
00252         } else {
00253             lwmin = *n;
00254             lrwmin = *n;
00255             liwmin = 1;
00256         }
00257     }
00258     if (! (wantz || lsame_(jobz, "N"))) {
00259         *info = -1;
00260     } else if (! (lower || lsame_(uplo, "U"))) {
00261         *info = -2;
00262     } else if (*n < 0) {
00263         *info = -3;
00264     } else if (*kd < 0) {
00265         *info = -4;
00266     } else if (*ldab < *kd + 1) {
00267         *info = -6;
00268     } else if (*ldz < 1 || wantz && *ldz < *n) {
00269         *info = -9;
00270     }
00271 
00272     if (*info == 0) {
00273         work[1].r = (doublereal) lwmin, work[1].i = 0.;
00274         rwork[1] = (doublereal) lrwmin;
00275         iwork[1] = liwmin;
00276 
00277         if (*lwork < lwmin && ! lquery) {
00278             *info = -11;
00279         } else if (*lrwork < lrwmin && ! lquery) {
00280             *info = -13;
00281         } else if (*liwork < liwmin && ! lquery) {
00282             *info = -15;
00283         }
00284     }
00285 
00286     if (*info != 0) {
00287         i__1 = -(*info);
00288         xerbla_("ZHBEVD", &i__1);
00289         return 0;
00290     } else if (lquery) {
00291         return 0;
00292     }
00293 
00294 /*     Quick return if possible */
00295 
00296     if (*n == 0) {
00297         return 0;
00298     }
00299 
00300     if (*n == 1) {
00301         i__1 = ab_dim1 + 1;
00302         w[1] = ab[i__1].r;
00303         if (wantz) {
00304             i__1 = z_dim1 + 1;
00305             z__[i__1].r = 1., z__[i__1].i = 0.;
00306         }
00307         return 0;
00308     }
00309 
00310 /*     Get machine constants. */
00311 
00312     safmin = dlamch_("Safe minimum");
00313     eps = dlamch_("Precision");
00314     smlnum = safmin / eps;
00315     bignum = 1. / smlnum;
00316     rmin = sqrt(smlnum);
00317     rmax = sqrt(bignum);
00318 
00319 /*     Scale matrix to allowable range, if necessary. */
00320 
00321     anrm = zlanhb_("M", uplo, n, kd, &ab[ab_offset], ldab, &rwork[1]);
00322     iscale = 0;
00323     if (anrm > 0. && anrm < rmin) {
00324         iscale = 1;
00325         sigma = rmin / anrm;
00326     } else if (anrm > rmax) {
00327         iscale = 1;
00328         sigma = rmax / anrm;
00329     }
00330     if (iscale == 1) {
00331         if (lower) {
00332             zlascl_("B", kd, kd, &c_b13, &sigma, n, n, &ab[ab_offset], ldab, 
00333                     info);
00334         } else {
00335             zlascl_("Q", kd, kd, &c_b13, &sigma, n, n, &ab[ab_offset], ldab, 
00336                     info);
00337         }
00338     }
00339 
00340 /*     Call ZHBTRD to reduce Hermitian band matrix to tridiagonal form. */
00341 
00342     inde = 1;
00343     indwrk = inde + *n;
00344     indwk2 = *n * *n + 1;
00345     llwk2 = *lwork - indwk2 + 1;
00346     llrwk = *lrwork - indwrk + 1;
00347     zhbtrd_(jobz, uplo, n, kd, &ab[ab_offset], ldab, &w[1], &rwork[inde], &
00348             z__[z_offset], ldz, &work[1], &iinfo);
00349 
00350 /*     For eigenvalues only, call DSTERF.  For eigenvectors, call ZSTEDC. */
00351 
00352     if (! wantz) {
00353         dsterf_(n, &w[1], &rwork[inde], info);
00354     } else {
00355         zstedc_("I", n, &w[1], &rwork[inde], &work[1], n, &work[indwk2], &
00356                 llwk2, &rwork[indwrk], &llrwk, &iwork[1], liwork, info);
00357         zgemm_("N", "N", n, n, n, &c_b2, &z__[z_offset], ldz, &work[1], n, &
00358                 c_b1, &work[indwk2], n);
00359         zlacpy_("A", n, n, &work[indwk2], n, &z__[z_offset], ldz);
00360     }
00361 
00362 /*     If matrix was scaled, then rescale eigenvalues appropriately. */
00363 
00364     if (iscale == 1) {
00365         if (*info == 0) {
00366             imax = *n;
00367         } else {
00368             imax = *info - 1;
00369         }
00370         d__1 = 1. / sigma;
00371         dscal_(&imax, &d__1, &w[1], &c__1);
00372     }
00373 
00374     work[1].r = (doublereal) lwmin, work[1].i = 0.;
00375     rwork[1] = (doublereal) lrwmin;
00376     iwork[1] = liwmin;
00377     return 0;
00378 
00379 /*     End of ZHBEVD */
00380 
00381 } /* zhbevd_ */


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