zheev.c
Go to the documentation of this file.
00001 /* zheev.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 integer c__1 = 1;
00019 static integer c_n1 = -1;
00020 static integer c__0 = 0;
00021 static doublereal c_b18 = 1.;
00022 
00023 /* Subroutine */ int zheev_(char *jobz, char *uplo, integer *n, doublecomplex 
00024         *a, integer *lda, doublereal *w, doublecomplex *work, integer *lwork, 
00025         doublereal *rwork, integer *info)
00026 {
00027     /* System generated locals */
00028     integer a_dim1, a_offset, i__1, i__2;
00029     doublereal d__1;
00030 
00031     /* Builtin functions */
00032     double sqrt(doublereal);
00033 
00034     /* Local variables */
00035     integer nb;
00036     doublereal eps;
00037     integer inde;
00038     doublereal anrm;
00039     integer imax;
00040     doublereal rmin, rmax;
00041     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00042             integer *);
00043     doublereal sigma;
00044     extern logical lsame_(char *, char *);
00045     integer iinfo;
00046     logical lower, wantz;
00047     extern doublereal dlamch_(char *);
00048     integer iscale;
00049     doublereal safmin;
00050     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00051             integer *, integer *);
00052     extern /* Subroutine */ int xerbla_(char *, integer *);
00053     doublereal bignum;
00054     extern doublereal zlanhe_(char *, char *, integer *, doublecomplex *, 
00055             integer *, doublereal *);
00056     integer indtau;
00057     extern /* Subroutine */ int dsterf_(integer *, doublereal *, doublereal *, 
00058              integer *), zlascl_(char *, integer *, integer *, doublereal *, 
00059             doublereal *, integer *, integer *, doublecomplex *, integer *, 
00060             integer *);
00061     integer indwrk;
00062     extern /* Subroutine */ int zhetrd_(char *, integer *, doublecomplex *, 
00063             integer *, doublereal *, doublereal *, doublecomplex *, 
00064             doublecomplex *, integer *, integer *);
00065     integer llwork;
00066     doublereal smlnum;
00067     integer lwkopt;
00068     logical lquery;
00069     extern /* Subroutine */ int zsteqr_(char *, integer *, doublereal *, 
00070             doublereal *, doublecomplex *, integer *, doublereal *, integer *), zungtr_(char *, integer *, doublecomplex *, integer *, 
00071             doublecomplex *, doublecomplex *, integer *, integer *);
00072 
00073 
00074 /*  -- LAPACK driver routine (version 3.2) -- */
00075 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00076 /*     November 2006 */
00077 
00078 /*     .. Scalar Arguments .. */
00079 /*     .. */
00080 /*     .. Array Arguments .. */
00081 /*     .. */
00082 
00083 /*  Purpose */
00084 /*  ======= */
00085 
00086 /*  ZHEEV computes all eigenvalues and, optionally, eigenvectors of a */
00087 /*  complex Hermitian matrix A. */
00088 
00089 /*  Arguments */
00090 /*  ========= */
00091 
00092 /*  JOBZ    (input) CHARACTER*1 */
00093 /*          = 'N':  Compute eigenvalues only; */
00094 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00095 
00096 /*  UPLO    (input) CHARACTER*1 */
00097 /*          = 'U':  Upper triangle of A is stored; */
00098 /*          = 'L':  Lower triangle of A is stored. */
00099 
00100 /*  N       (input) INTEGER */
00101 /*          The order of the matrix A.  N >= 0. */
00102 
00103 /*  A       (input/output) COMPLEX*16 array, dimension (LDA, N) */
00104 /*          On entry, the Hermitian matrix A.  If UPLO = 'U', the */
00105 /*          leading N-by-N upper triangular part of A contains the */
00106 /*          upper triangular part of the matrix A.  If UPLO = 'L', */
00107 /*          the leading N-by-N lower triangular part of A contains */
00108 /*          the lower triangular part of the matrix A. */
00109 /*          On exit, if JOBZ = 'V', then if INFO = 0, A contains the */
00110 /*          orthonormal eigenvectors of the matrix A. */
00111 /*          If JOBZ = 'N', then on exit the lower triangle (if UPLO='L') */
00112 /*          or the upper triangle (if UPLO='U') of A, including the */
00113 /*          diagonal, is destroyed. */
00114 
00115 /*  LDA     (input) INTEGER */
00116 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00117 
00118 /*  W       (output) DOUBLE PRECISION array, dimension (N) */
00119 /*          If INFO = 0, the eigenvalues in ascending order. */
00120 
00121 /*  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */
00122 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00123 
00124 /*  LWORK   (input) INTEGER */
00125 /*          The length of the array WORK.  LWORK >= max(1,2*N-1). */
00126 /*          For optimal efficiency, LWORK >= (NB+1)*N, */
00127 /*          where NB is the blocksize for ZHETRD returned by ILAENV. */
00128 
00129 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00130 /*          only calculates the optimal size of the WORK array, returns */
00131 /*          this value as the first entry of the WORK array, and no error */
00132 /*          message related to LWORK is issued by XERBLA. */
00133 
00134 /*  RWORK   (workspace) DOUBLE PRECISION array, dimension (max(1, 3*N-2)) */
00135 
00136 /*  INFO    (output) INTEGER */
00137 /*          = 0:  successful exit */
00138 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00139 /*          > 0:  if INFO = i, the algorithm failed to converge; i */
00140 /*                off-diagonal elements of an intermediate tridiagonal */
00141 /*                form did not converge to zero. */
00142 
00143 /*  ===================================================================== */
00144 
00145 /*     .. Parameters .. */
00146 /*     .. */
00147 /*     .. Local Scalars .. */
00148 /*     .. */
00149 /*     .. External Functions .. */
00150 /*     .. */
00151 /*     .. External Subroutines .. */
00152 /*     .. */
00153 /*     .. Intrinsic Functions .. */
00154 /*     .. */
00155 /*     .. Executable Statements .. */
00156 
00157 /*     Test the input parameters. */
00158 
00159     /* Parameter adjustments */
00160     a_dim1 = *lda;
00161     a_offset = 1 + a_dim1;
00162     a -= a_offset;
00163     --w;
00164     --work;
00165     --rwork;
00166 
00167     /* Function Body */
00168     wantz = lsame_(jobz, "V");
00169     lower = lsame_(uplo, "L");
00170     lquery = *lwork == -1;
00171 
00172     *info = 0;
00173     if (! (wantz || lsame_(jobz, "N"))) {
00174         *info = -1;
00175     } else if (! (lower || lsame_(uplo, "U"))) {
00176         *info = -2;
00177     } else if (*n < 0) {
00178         *info = -3;
00179     } else if (*lda < max(1,*n)) {
00180         *info = -5;
00181     }
00182 
00183     if (*info == 0) {
00184         nb = ilaenv_(&c__1, "ZHETRD", uplo, n, &c_n1, &c_n1, &c_n1);
00185 /* Computing MAX */
00186         i__1 = 1, i__2 = (nb + 1) * *n;
00187         lwkopt = max(i__1,i__2);
00188         work[1].r = (doublereal) lwkopt, work[1].i = 0.;
00189 
00190 /* Computing MAX */
00191         i__1 = 1, i__2 = (*n << 1) - 1;
00192         if (*lwork < max(i__1,i__2) && ! lquery) {
00193             *info = -8;
00194         }
00195     }
00196 
00197     if (*info != 0) {
00198         i__1 = -(*info);
00199         xerbla_("ZHEEV ", &i__1);
00200         return 0;
00201     } else if (lquery) {
00202         return 0;
00203     }
00204 
00205 /*     Quick return if possible */
00206 
00207     if (*n == 0) {
00208         return 0;
00209     }
00210 
00211     if (*n == 1) {
00212         i__1 = a_dim1 + 1;
00213         w[1] = a[i__1].r;
00214         work[1].r = 1., work[1].i = 0.;
00215         if (wantz) {
00216             i__1 = a_dim1 + 1;
00217             a[i__1].r = 1., a[i__1].i = 0.;
00218         }
00219         return 0;
00220     }
00221 
00222 /*     Get machine constants. */
00223 
00224     safmin = dlamch_("Safe minimum");
00225     eps = dlamch_("Precision");
00226     smlnum = safmin / eps;
00227     bignum = 1. / smlnum;
00228     rmin = sqrt(smlnum);
00229     rmax = sqrt(bignum);
00230 
00231 /*     Scale matrix to allowable range, if necessary. */
00232 
00233     anrm = zlanhe_("M", uplo, n, &a[a_offset], lda, &rwork[1]);
00234     iscale = 0;
00235     if (anrm > 0. && anrm < rmin) {
00236         iscale = 1;
00237         sigma = rmin / anrm;
00238     } else if (anrm > rmax) {
00239         iscale = 1;
00240         sigma = rmax / anrm;
00241     }
00242     if (iscale == 1) {
00243         zlascl_(uplo, &c__0, &c__0, &c_b18, &sigma, n, n, &a[a_offset], lda, 
00244                 info);
00245     }
00246 
00247 /*     Call ZHETRD to reduce Hermitian matrix to tridiagonal form. */
00248 
00249     inde = 1;
00250     indtau = 1;
00251     indwrk = indtau + *n;
00252     llwork = *lwork - indwrk + 1;
00253     zhetrd_(uplo, n, &a[a_offset], lda, &w[1], &rwork[inde], &work[indtau], &
00254             work[indwrk], &llwork, &iinfo);
00255 
00256 /*     For eigenvalues only, call DSTERF.  For eigenvectors, first call */
00257 /*     ZUNGTR to generate the unitary matrix, then call ZSTEQR. */
00258 
00259     if (! wantz) {
00260         dsterf_(n, &w[1], &rwork[inde], info);
00261     } else {
00262         zungtr_(uplo, n, &a[a_offset], lda, &work[indtau], &work[indwrk], &
00263                 llwork, &iinfo);
00264         indwrk = inde + *n;
00265         zsteqr_(jobz, n, &w[1], &rwork[inde], &a[a_offset], lda, &rwork[
00266                 indwrk], info);
00267     }
00268 
00269 /*     If matrix was scaled, then rescale eigenvalues appropriately. */
00270 
00271     if (iscale == 1) {
00272         if (*info == 0) {
00273             imax = *n;
00274         } else {
00275             imax = *info - 1;
00276         }
00277         d__1 = 1. / sigma;
00278         dscal_(&imax, &d__1, &w[1], &c__1);
00279     }
00280 
00281 /*     Set WORK(1) to optimal complex workspace size. */
00282 
00283     work[1].r = (doublereal) lwkopt, work[1].i = 0.;
00284 
00285     return 0;
00286 
00287 /*     End of ZHEEV */
00288 
00289 } /* zheev_ */


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