zhbev.c
Go to the documentation of this file.
00001 /* zhbev.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 doublereal c_b11 = 1.;
00019 static integer c__1 = 1;
00020 
00021 /* Subroutine */ int zhbev_(char *jobz, char *uplo, integer *n, integer *kd, 
00022         doublecomplex *ab, integer *ldab, doublereal *w, doublecomplex *z__, 
00023         integer *ldz, doublecomplex *work, doublereal *rwork, integer *info)
00024 {
00025     /* System generated locals */
00026     integer ab_dim1, ab_offset, z_dim1, z_offset, i__1;
00027     doublereal d__1;
00028 
00029     /* Builtin functions */
00030     double sqrt(doublereal);
00031 
00032     /* Local variables */
00033     doublereal eps;
00034     integer inde;
00035     doublereal anrm;
00036     integer imax;
00037     doublereal rmin, rmax;
00038     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00039             integer *);
00040     doublereal sigma;
00041     extern logical lsame_(char *, char *);
00042     integer iinfo;
00043     logical lower, wantz;
00044     extern doublereal dlamch_(char *);
00045     integer iscale;
00046     doublereal safmin;
00047     extern doublereal zlanhb_(char *, char *, integer *, integer *, 
00048             doublecomplex *, integer *, doublereal *);
00049     extern /* Subroutine */ int xerbla_(char *, integer *);
00050     doublereal bignum;
00051     extern /* Subroutine */ int dsterf_(integer *, doublereal *, doublereal *, 
00052              integer *), zlascl_(char *, integer *, integer *, doublereal *, 
00053             doublereal *, integer *, integer *, doublecomplex *, integer *, 
00054             integer *), zhbtrd_(char *, char *, integer *, integer *, 
00055             doublecomplex *, integer *, doublereal *, doublereal *, 
00056             doublecomplex *, integer *, doublecomplex *, integer *);
00057     integer indrwk;
00058     doublereal smlnum;
00059     extern /* Subroutine */ int zsteqr_(char *, integer *, doublereal *, 
00060             doublereal *, doublecomplex *, integer *, doublereal *, integer *);
00061 
00062 
00063 /*  -- LAPACK driver routine (version 3.2) -- */
00064 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00065 /*     November 2006 */
00066 
00067 /*     .. Scalar Arguments .. */
00068 /*     .. */
00069 /*     .. Array Arguments .. */
00070 /*     .. */
00071 
00072 /*  Purpose */
00073 /*  ======= */
00074 
00075 /*  ZHBEV computes all the eigenvalues and, optionally, eigenvectors of */
00076 /*  a complex Hermitian band matrix A. */
00077 
00078 /*  Arguments */
00079 /*  ========= */
00080 
00081 /*  JOBZ    (input) CHARACTER*1 */
00082 /*          = 'N':  Compute eigenvalues only; */
00083 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00084 
00085 /*  UPLO    (input) CHARACTER*1 */
00086 /*          = 'U':  Upper triangle of A is stored; */
00087 /*          = 'L':  Lower triangle of A is stored. */
00088 
00089 /*  N       (input) INTEGER */
00090 /*          The order of the matrix A.  N >= 0. */
00091 
00092 /*  KD      (input) INTEGER */
00093 /*          The number of superdiagonals of the matrix A if UPLO = 'U', */
00094 /*          or the number of subdiagonals if UPLO = 'L'.  KD >= 0. */
00095 
00096 /*  AB      (input/output) COMPLEX*16 array, dimension (LDAB, N) */
00097 /*          On entry, the upper or lower triangle of the Hermitian band */
00098 /*          matrix A, stored in the first KD+1 rows of the array.  The */
00099 /*          j-th column of A is stored in the j-th column of the array AB */
00100 /*          as follows: */
00101 /*          if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */
00102 /*          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+kd). */
00103 
00104 /*          On exit, AB is overwritten by values generated during the */
00105 /*          reduction to tridiagonal form.  If UPLO = 'U', the first */
00106 /*          superdiagonal and the diagonal of the tridiagonal matrix T */
00107 /*          are returned in rows KD and KD+1 of AB, and if UPLO = 'L', */
00108 /*          the diagonal and first subdiagonal of T are returned in the */
00109 /*          first two rows of AB. */
00110 
00111 /*  LDAB    (input) INTEGER */
00112 /*          The leading dimension of the array AB.  LDAB >= KD + 1. */
00113 
00114 /*  W       (output) DOUBLE PRECISION array, dimension (N) */
00115 /*          If INFO = 0, the eigenvalues in ascending order. */
00116 
00117 /*  Z       (output) COMPLEX*16 array, dimension (LDZ, N) */
00118 /*          If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal */
00119 /*          eigenvectors of the matrix A, with the i-th column of Z */
00120 /*          holding the eigenvector associated with W(i). */
00121 /*          If JOBZ = 'N', then Z is not referenced. */
00122 
00123 /*  LDZ     (input) INTEGER */
00124 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00125 /*          JOBZ = 'V', LDZ >= max(1,N). */
00126 
00127 /*  WORK    (workspace) COMPLEX*16 array, dimension (N) */
00128 
00129 /*  RWORK   (workspace) DOUBLE PRECISION array, dimension (max(1,3*N-2)) */
00130 
00131 /*  INFO    (output) INTEGER */
00132 /*          = 0:  successful exit. */
00133 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00134 /*          > 0:  if INFO = i, the algorithm failed to converge; i */
00135 /*                off-diagonal elements of an intermediate tridiagonal */
00136 /*                form did not converge to zero. */
00137 
00138 /*  ===================================================================== */
00139 
00140 /*     .. Parameters .. */
00141 /*     .. */
00142 /*     .. Local Scalars .. */
00143 /*     .. */
00144 /*     .. External Functions .. */
00145 /*     .. */
00146 /*     .. External Subroutines .. */
00147 /*     .. */
00148 /*     .. Intrinsic Functions .. */
00149 /*     .. */
00150 /*     .. Executable Statements .. */
00151 
00152 /*     Test the input parameters. */
00153 
00154     /* Parameter adjustments */
00155     ab_dim1 = *ldab;
00156     ab_offset = 1 + ab_dim1;
00157     ab -= ab_offset;
00158     --w;
00159     z_dim1 = *ldz;
00160     z_offset = 1 + z_dim1;
00161     z__ -= z_offset;
00162     --work;
00163     --rwork;
00164 
00165     /* Function Body */
00166     wantz = lsame_(jobz, "V");
00167     lower = lsame_(uplo, "L");
00168 
00169     *info = 0;
00170     if (! (wantz || lsame_(jobz, "N"))) {
00171         *info = -1;
00172     } else if (! (lower || lsame_(uplo, "U"))) {
00173         *info = -2;
00174     } else if (*n < 0) {
00175         *info = -3;
00176     } else if (*kd < 0) {
00177         *info = -4;
00178     } else if (*ldab < *kd + 1) {
00179         *info = -6;
00180     } else if (*ldz < 1 || wantz && *ldz < *n) {
00181         *info = -9;
00182     }
00183 
00184     if (*info != 0) {
00185         i__1 = -(*info);
00186         xerbla_("ZHBEV ", &i__1);
00187         return 0;
00188     }
00189 
00190 /*     Quick return if possible */
00191 
00192     if (*n == 0) {
00193         return 0;
00194     }
00195 
00196     if (*n == 1) {
00197         if (lower) {
00198             i__1 = ab_dim1 + 1;
00199             w[1] = ab[i__1].r;
00200         } else {
00201             i__1 = *kd + 1 + ab_dim1;
00202             w[1] = ab[i__1].r;
00203         }
00204         if (wantz) {
00205             i__1 = z_dim1 + 1;
00206             z__[i__1].r = 1., z__[i__1].i = 0.;
00207         }
00208         return 0;
00209     }
00210 
00211 /*     Get machine constants. */
00212 
00213     safmin = dlamch_("Safe minimum");
00214     eps = dlamch_("Precision");
00215     smlnum = safmin / eps;
00216     bignum = 1. / smlnum;
00217     rmin = sqrt(smlnum);
00218     rmax = sqrt(bignum);
00219 
00220 /*     Scale matrix to allowable range, if necessary. */
00221 
00222     anrm = zlanhb_("M", uplo, n, kd, &ab[ab_offset], ldab, &rwork[1]);
00223     iscale = 0;
00224     if (anrm > 0. && anrm < rmin) {
00225         iscale = 1;
00226         sigma = rmin / anrm;
00227     } else if (anrm > rmax) {
00228         iscale = 1;
00229         sigma = rmax / anrm;
00230     }
00231     if (iscale == 1) {
00232         if (lower) {
00233             zlascl_("B", kd, kd, &c_b11, &sigma, n, n, &ab[ab_offset], ldab, 
00234                     info);
00235         } else {
00236             zlascl_("Q", kd, kd, &c_b11, &sigma, n, n, &ab[ab_offset], ldab, 
00237                     info);
00238         }
00239     }
00240 
00241 /*     Call ZHBTRD to reduce Hermitian band matrix to tridiagonal form. */
00242 
00243     inde = 1;
00244     zhbtrd_(jobz, uplo, n, kd, &ab[ab_offset], ldab, &w[1], &rwork[inde], &
00245             z__[z_offset], ldz, &work[1], &iinfo);
00246 
00247 /*     For eigenvalues only, call DSTERF.  For eigenvectors, call ZSTEQR. */
00248 
00249     if (! wantz) {
00250         dsterf_(n, &w[1], &rwork[inde], info);
00251     } else {
00252         indrwk = inde + *n;
00253         zsteqr_(jobz, n, &w[1], &rwork[inde], &z__[z_offset], ldz, &rwork[
00254                 indrwk], info);
00255     }
00256 
00257 /*     If matrix was scaled, then rescale eigenvalues appropriately. */
00258 
00259     if (iscale == 1) {
00260         if (*info == 0) {
00261             imax = *n;
00262         } else {
00263             imax = *info - 1;
00264         }
00265         d__1 = 1. / sigma;
00266         dscal_(&imax, &d__1, &w[1], &c__1);
00267     }
00268 
00269     return 0;
00270 
00271 /*     End of ZHBEV */
00272 
00273 } /* zhbev_ */


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