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


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