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