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


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