00001 /* zhbgvd.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 doublecomplex c_b1 = {1.,0.}; 00019 static doublecomplex c_b2 = {0.,0.}; 00020 00021 /* Subroutine */ int zhbgvd_(char *jobz, char *uplo, integer *n, integer *ka, 00022 integer *kb, doublecomplex *ab, integer *ldab, doublecomplex *bb, 00023 integer *ldbb, doublereal *w, doublecomplex *z__, integer *ldz, 00024 doublecomplex *work, integer *lwork, doublereal *rwork, integer * 00025 lrwork, integer *iwork, integer *liwork, integer *info) 00026 { 00027 /* System generated locals */ 00028 integer ab_dim1, ab_offset, bb_dim1, bb_offset, z_dim1, z_offset, i__1; 00029 00030 /* Local variables */ 00031 integer inde; 00032 char vect[1]; 00033 integer llwk2; 00034 extern logical lsame_(char *, char *); 00035 integer iinfo; 00036 extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *, 00037 integer *, doublecomplex *, doublecomplex *, integer *, 00038 doublecomplex *, integer *, doublecomplex *, doublecomplex *, 00039 integer *); 00040 integer lwmin; 00041 logical upper; 00042 integer llrwk; 00043 logical wantz; 00044 integer indwk2; 00045 extern /* Subroutine */ int xerbla_(char *, integer *), dsterf_( 00046 integer *, doublereal *, doublereal *, integer *), zstedc_(char *, 00047 integer *, doublereal *, doublereal *, doublecomplex *, integer * 00048 , doublecomplex *, integer *, doublereal *, integer *, integer *, 00049 integer *, integer *), zhbtrd_(char *, char *, integer *, 00050 integer *, doublecomplex *, integer *, doublereal *, doublereal *, 00051 doublecomplex *, integer *, doublecomplex *, integer *); 00052 integer indwrk, liwmin; 00053 extern /* Subroutine */ int zhbgst_(char *, char *, integer *, integer *, 00054 integer *, doublecomplex *, integer *, doublecomplex *, integer *, 00055 doublecomplex *, integer *, doublecomplex *, doublereal *, 00056 integer *), zlacpy_(char *, integer *, integer *, 00057 doublecomplex *, integer *, doublecomplex *, integer *); 00058 integer lrwmin; 00059 extern /* Subroutine */ int zpbstf_(char *, integer *, integer *, 00060 doublecomplex *, integer *, integer *); 00061 logical lquery; 00062 00063 00064 /* -- LAPACK driver routine (version 3.2) -- */ 00065 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00066 /* November 2006 */ 00067 00068 /* .. Scalar Arguments .. */ 00069 /* .. */ 00070 /* .. Array Arguments .. */ 00071 /* .. */ 00072 00073 /* Purpose */ 00074 /* ======= */ 00075 00076 /* ZHBGVD computes all the eigenvalues, and optionally, the eigenvectors */ 00077 /* of a complex generalized Hermitian-definite banded eigenproblem, of */ 00078 /* the form A*x=(lambda)*B*x. Here A and B are assumed to be Hermitian */ 00079 /* and banded, and B is also positive definite. If eigenvectors are */ 00080 /* desired, it uses a divide and conquer algorithm. */ 00081 00082 /* The divide and conquer algorithm makes very mild assumptions about */ 00083 /* floating point arithmetic. It will work on machines with a guard */ 00084 /* digit in add/subtract, or on those binary machines without guard */ 00085 /* digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */ 00086 /* Cray-2. It could conceivably fail on hexadecimal or decimal machines */ 00087 /* without guard digits, but we know of none. */ 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 triangles of A and B are stored; */ 00098 /* = 'L': Lower triangles of A and B are stored. */ 00099 00100 /* N (input) INTEGER */ 00101 /* The order of the matrices A and B. N >= 0. */ 00102 00103 /* KA (input) INTEGER */ 00104 /* The number of superdiagonals of the matrix A if UPLO = 'U', */ 00105 /* or the number of subdiagonals if UPLO = 'L'. KA >= 0. */ 00106 00107 /* KB (input) INTEGER */ 00108 /* The number of superdiagonals of the matrix B if UPLO = 'U', */ 00109 /* or the number of subdiagonals if UPLO = 'L'. KB >= 0. */ 00110 00111 /* AB (input/output) COMPLEX*16 array, dimension (LDAB, N) */ 00112 /* On entry, the upper or lower triangle of the Hermitian band */ 00113 /* matrix A, stored in the first ka+1 rows of the array. The */ 00114 /* j-th column of A is stored in the j-th column of the array AB */ 00115 /* as follows: */ 00116 /* if UPLO = 'U', AB(ka+1+i-j,j) = A(i,j) for max(1,j-ka)<=i<=j; */ 00117 /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+ka). */ 00118 00119 /* On exit, the contents of AB are destroyed. */ 00120 00121 /* LDAB (input) INTEGER */ 00122 /* The leading dimension of the array AB. LDAB >= KA+1. */ 00123 00124 /* BB (input/output) COMPLEX*16 array, dimension (LDBB, N) */ 00125 /* On entry, the upper or lower triangle of the Hermitian band */ 00126 /* matrix B, stored in the first kb+1 rows of the array. The */ 00127 /* j-th column of B is stored in the j-th column of the array BB */ 00128 /* as follows: */ 00129 /* if UPLO = 'U', BB(kb+1+i-j,j) = B(i,j) for max(1,j-kb)<=i<=j; */ 00130 /* if UPLO = 'L', BB(1+i-j,j) = B(i,j) for j<=i<=min(n,j+kb). */ 00131 00132 /* On exit, the factor S from the split Cholesky factorization */ 00133 /* B = S**H*S, as returned by ZPBSTF. */ 00134 00135 /* LDBB (input) INTEGER */ 00136 /* The leading dimension of the array BB. LDBB >= KB+1. */ 00137 00138 /* W (output) DOUBLE PRECISION array, dimension (N) */ 00139 /* If INFO = 0, the eigenvalues in ascending order. */ 00140 00141 /* Z (output) COMPLEX*16 array, dimension (LDZ, N) */ 00142 /* If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of */ 00143 /* eigenvectors, with the i-th column of Z holding the */ 00144 /* eigenvector associated with W(i). The eigenvectors are */ 00145 /* normalized so that Z**H*B*Z = I. */ 00146 /* If JOBZ = 'N', then Z is not referenced. */ 00147 00148 /* LDZ (input) INTEGER */ 00149 /* The leading dimension of the array Z. LDZ >= 1, and if */ 00150 /* JOBZ = 'V', LDZ >= N. */ 00151 00152 /* WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */ 00153 /* On exit, if INFO=0, WORK(1) returns the optimal LWORK. */ 00154 00155 /* LWORK (input) INTEGER */ 00156 /* The dimension of the array WORK. */ 00157 /* If N <= 1, LWORK >= 1. */ 00158 /* If JOBZ = 'N' and N > 1, LWORK >= N. */ 00159 /* If JOBZ = 'V' and N > 1, LWORK >= 2*N**2. */ 00160 00161 /* If LWORK = -1, then a workspace query is assumed; the routine */ 00162 /* only calculates the optimal sizes of the WORK, RWORK and */ 00163 /* IWORK arrays, returns these values as the first entries of */ 00164 /* the WORK, RWORK and IWORK arrays, and no error message */ 00165 /* related to LWORK or LRWORK or LIWORK is issued by XERBLA. */ 00166 00167 /* RWORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LRWORK)) */ 00168 /* On exit, if INFO=0, RWORK(1) returns the optimal LRWORK. */ 00169 00170 /* LRWORK (input) INTEGER */ 00171 /* The dimension of array RWORK. */ 00172 /* If N <= 1, LRWORK >= 1. */ 00173 /* If JOBZ = 'N' and N > 1, LRWORK >= N. */ 00174 /* If JOBZ = 'V' and N > 1, LRWORK >= 1 + 5*N + 2*N**2. */ 00175 00176 /* If LRWORK = -1, then a workspace query is assumed; the */ 00177 /* routine only calculates the optimal sizes of the WORK, RWORK */ 00178 /* and IWORK arrays, returns these values as the first entries */ 00179 /* of the WORK, RWORK and IWORK arrays, and no error message */ 00180 /* related to LWORK or LRWORK or LIWORK is issued by XERBLA. */ 00181 00182 /* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */ 00183 /* On exit, if INFO=0, IWORK(1) returns the optimal LIWORK. */ 00184 00185 /* LIWORK (input) INTEGER */ 00186 /* The dimension of array IWORK. */ 00187 /* If JOBZ = 'N' or N <= 1, LIWORK >= 1. */ 00188 /* If JOBZ = 'V' and N > 1, LIWORK >= 3 + 5*N. */ 00189 00190 /* If LIWORK = -1, then a workspace query is assumed; the */ 00191 /* routine only calculates the optimal sizes of the WORK, RWORK */ 00192 /* and IWORK arrays, returns these values as the first entries */ 00193 /* of the WORK, RWORK and IWORK arrays, and no error message */ 00194 /* related to LWORK or LRWORK or LIWORK is issued by XERBLA. */ 00195 00196 /* INFO (output) INTEGER */ 00197 /* = 0: successful exit */ 00198 /* < 0: if INFO = -i, the i-th argument had an illegal value */ 00199 /* > 0: if INFO = i, and i is: */ 00200 /* <= N: the algorithm failed to converge: */ 00201 /* i off-diagonal elements of an intermediate */ 00202 /* tridiagonal form did not converge to zero; */ 00203 /* > N: if INFO = N + i, for 1 <= i <= N, then ZPBSTF */ 00204 /* returned INFO = i: B is not positive definite. */ 00205 /* The factorization of B could not be completed and */ 00206 /* no eigenvalues or eigenvectors were computed. */ 00207 00208 /* Further Details */ 00209 /* =============== */ 00210 00211 /* Based on contributions by */ 00212 /* Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */ 00213 00214 /* ===================================================================== */ 00215 00216 /* .. Parameters .. */ 00217 /* .. */ 00218 /* .. Local Scalars .. */ 00219 /* .. */ 00220 /* .. External Functions .. */ 00221 /* .. */ 00222 /* .. External Subroutines .. */ 00223 /* .. */ 00224 /* .. Executable Statements .. */ 00225 00226 /* Test the input parameters. */ 00227 00228 /* Parameter adjustments */ 00229 ab_dim1 = *ldab; 00230 ab_offset = 1 + ab_dim1; 00231 ab -= ab_offset; 00232 bb_dim1 = *ldbb; 00233 bb_offset = 1 + bb_dim1; 00234 bb -= bb_offset; 00235 --w; 00236 z_dim1 = *ldz; 00237 z_offset = 1 + z_dim1; 00238 z__ -= z_offset; 00239 --work; 00240 --rwork; 00241 --iwork; 00242 00243 /* Function Body */ 00244 wantz = lsame_(jobz, "V"); 00245 upper = lsame_(uplo, "U"); 00246 lquery = *lwork == -1 || *lrwork == -1 || *liwork == -1; 00247 00248 *info = 0; 00249 if (*n <= 1) { 00250 lwmin = 1; 00251 lrwmin = 1; 00252 liwmin = 1; 00253 } else if (wantz) { 00254 /* Computing 2nd power */ 00255 i__1 = *n; 00256 lwmin = i__1 * i__1 << 1; 00257 /* Computing 2nd power */ 00258 i__1 = *n; 00259 lrwmin = *n * 5 + 1 + (i__1 * i__1 << 1); 00260 liwmin = *n * 5 + 3; 00261 } else { 00262 lwmin = *n; 00263 lrwmin = *n; 00264 liwmin = 1; 00265 } 00266 if (! (wantz || lsame_(jobz, "N"))) { 00267 *info = -1; 00268 } else if (! (upper || lsame_(uplo, "L"))) { 00269 *info = -2; 00270 } else if (*n < 0) { 00271 *info = -3; 00272 } else if (*ka < 0) { 00273 *info = -4; 00274 } else if (*kb < 0 || *kb > *ka) { 00275 *info = -5; 00276 } else if (*ldab < *ka + 1) { 00277 *info = -7; 00278 } else if (*ldbb < *kb + 1) { 00279 *info = -9; 00280 } else if (*ldz < 1 || wantz && *ldz < *n) { 00281 *info = -12; 00282 } 00283 00284 if (*info == 0) { 00285 work[1].r = (doublereal) lwmin, work[1].i = 0.; 00286 rwork[1] = (doublereal) lrwmin; 00287 iwork[1] = liwmin; 00288 00289 if (*lwork < lwmin && ! lquery) { 00290 *info = -14; 00291 } else if (*lrwork < lrwmin && ! lquery) { 00292 *info = -16; 00293 } else if (*liwork < liwmin && ! lquery) { 00294 *info = -18; 00295 } 00296 } 00297 00298 if (*info != 0) { 00299 i__1 = -(*info); 00300 xerbla_("ZHBGVD", &i__1); 00301 return 0; 00302 } else if (lquery) { 00303 return 0; 00304 } 00305 00306 /* Quick return if possible */ 00307 00308 if (*n == 0) { 00309 return 0; 00310 } 00311 00312 /* Form a split Cholesky factorization of B. */ 00313 00314 zpbstf_(uplo, n, kb, &bb[bb_offset], ldbb, info); 00315 if (*info != 0) { 00316 *info = *n + *info; 00317 return 0; 00318 } 00319 00320 /* Transform problem to standard eigenvalue problem. */ 00321 00322 inde = 1; 00323 indwrk = inde + *n; 00324 indwk2 = *n * *n + 1; 00325 llwk2 = *lwork - indwk2 + 2; 00326 llrwk = *lrwork - indwrk + 2; 00327 zhbgst_(jobz, uplo, n, ka, kb, &ab[ab_offset], ldab, &bb[bb_offset], ldbb, 00328 &z__[z_offset], ldz, &work[1], &rwork[indwrk], &iinfo); 00329 00330 /* Reduce Hermitian band matrix to tridiagonal form. */ 00331 00332 if (wantz) { 00333 *(unsigned char *)vect = 'U'; 00334 } else { 00335 *(unsigned char *)vect = 'N'; 00336 } 00337 zhbtrd_(vect, uplo, n, ka, &ab[ab_offset], ldab, &w[1], &rwork[inde], & 00338 z__[z_offset], ldz, &work[1], &iinfo); 00339 00340 /* For eigenvalues only, call DSTERF. For eigenvectors, call ZSTEDC. */ 00341 00342 if (! wantz) { 00343 dsterf_(n, &w[1], &rwork[inde], info); 00344 } else { 00345 zstedc_("I", n, &w[1], &rwork[inde], &work[1], n, &work[indwk2], & 00346 llwk2, &rwork[indwrk], &llrwk, &iwork[1], liwork, info); 00347 zgemm_("N", "N", n, n, n, &c_b1, &z__[z_offset], ldz, &work[1], n, & 00348 c_b2, &work[indwk2], n); 00349 zlacpy_("A", n, n, &work[indwk2], n, &z__[z_offset], ldz); 00350 } 00351 00352 work[1].r = (doublereal) lwmin, work[1].i = 0.; 00353 rwork[1] = (doublereal) lrwmin; 00354 iwork[1] = liwmin; 00355 return 0; 00356 00357 /* End of ZHBGVD */ 00358 00359 } /* zhbgvd_ */