1 /* ./src_f77/zhpgvx.f -- translated by f2c (version 20030320).
2    You must link the resulting object file with the libraries:
3 	-lf2c -lm   (in that order)
4 */
5 
6 #include <punc/vf2c.h>
7 
8 /* Table of constant values */
9 
10 static integer c__1 = 1;
11 
zhpgvx_(integer * itype,char * jobz,char * range,char * uplo,integer * n,doublecomplex * ap,doublecomplex * bp,doublereal * vl,doublereal * vu,integer * il,integer * iu,doublereal * abstol,integer * m,doublereal * w,doublecomplex * z__,integer * ldz,doublecomplex * work,doublereal * rwork,integer * iwork,integer * ifail,integer * info,ftnlen jobz_len,ftnlen range_len,ftnlen uplo_len)12 /* Subroutine */ int zhpgvx_(integer *itype, char *jobz, char *range, char *
13 	uplo, integer *n, doublecomplex *ap, doublecomplex *bp, doublereal *
14 	vl, doublereal *vu, integer *il, integer *iu, doublereal *abstol,
15 	integer *m, doublereal *w, doublecomplex *z__, integer *ldz,
16 	doublecomplex *work, doublereal *rwork, integer *iwork, integer *
17 	ifail, integer *info, ftnlen jobz_len, ftnlen range_len, ftnlen
18 	uplo_len)
19 {
20     /* System generated locals */
21     integer z_dim1, z_offset, i__1;
22 
23     /* Local variables */
24     static integer j;
25     extern logical lsame_(char *, char *, ftnlen, ftnlen);
26     static char trans[1];
27     static logical upper, wantz;
28     extern /* Subroutine */ int ztpmv_(char *, char *, char *, integer *,
29 	    doublecomplex *, doublecomplex *, integer *, ftnlen, ftnlen,
30 	    ftnlen), ztpsv_(char *, char *, char *, integer *, doublecomplex *
31 	    , doublecomplex *, integer *, ftnlen, ftnlen, ftnlen);
32     static logical alleig, indeig, valeig;
33     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen), zhpgst_(
34 	    integer *, char *, integer *, doublecomplex *, doublecomplex *,
35 	    integer *, ftnlen), zhpevx_(char *, char *, char *, integer *,
36 	    doublecomplex *, doublereal *, doublereal *, integer *, integer *,
37 	     doublereal *, integer *, doublereal *, doublecomplex *, integer *
38 	    , doublecomplex *, doublereal *, integer *, integer *, integer *,
39 	    ftnlen, ftnlen, ftnlen), zpptrf_(char *, integer *, doublecomplex
40 	    *, integer *, ftnlen);
41 
42 
43 /*  -- LAPACK driver routine (version 3.0) -- */
44 /*     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */
45 /*     Courant Institute, Argonne National Lab, and Rice University */
46 /*     June 30, 1999 */
47 
48 /*     .. Scalar Arguments .. */
49 /*     .. */
50 /*     .. Array Arguments .. */
51 /*     .. */
52 
53 /*  Purpose */
54 /*  ======= */
55 
56 /*  ZHPGVX computes selected eigenvalues and, optionally, eigenvectors */
57 /*  of a complex generalized Hermitian-definite eigenproblem, of the form */
58 /*  A*x=(lambda)*B*x,  A*Bx=(lambda)*x,  or B*A*x=(lambda)*x.  Here A and */
59 /*  B are assumed to be Hermitian, stored in packed format, and B is also */
60 /*  positive definite.  Eigenvalues and eigenvectors can be selected by */
61 /*  specifying either a range of values or a range of indices for the */
62 /*  desired eigenvalues. */
63 
64 /*  Arguments */
65 /*  ========= */
66 
67 /*  ITYPE   (input) INTEGER */
68 /*          Specifies the problem type to be solved: */
69 /*          = 1:  A*x = (lambda)*B*x */
70 /*          = 2:  A*B*x = (lambda)*x */
71 /*          = 3:  B*A*x = (lambda)*x */
72 
73 /*  JOBZ    (input) CHARACTER*1 */
74 /*          = 'N':  Compute eigenvalues only; */
75 /*          = 'V':  Compute eigenvalues and eigenvectors. */
76 
77 /*  RANGE   (input) CHARACTER*1 */
78 /*          = 'A': all eigenvalues will be found; */
79 /*          = 'V': all eigenvalues in the half-open interval (VL,VU] */
80 /*                 will be found; */
81 /*          = 'I': the IL-th through IU-th eigenvalues will be found. */
82 
83 /*  UPLO    (input) CHARACTER*1 */
84 /*          = 'U':  Upper triangles of A and B are stored; */
85 /*          = 'L':  Lower triangles of A and B are stored. */
86 
87 /*  N       (input) INTEGER */
88 /*          The order of the matrices A and B.  N >= 0. */
89 
90 /*  AP      (input/output) COMPLEX*16 array, dimension (N*(N+1)/2) */
91 /*          On entry, the upper or lower triangle of the Hermitian matrix */
92 /*          A, packed columnwise in a linear array.  The j-th column of A */
93 /*          is stored in the array AP as follows: */
94 /*          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
95 /*          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */
96 
97 /*          On exit, the contents of AP are destroyed. */
98 
99 /*  BP      (input/output) COMPLEX*16 array, dimension (N*(N+1)/2) */
100 /*          On entry, the upper or lower triangle of the Hermitian matrix */
101 /*          B, packed columnwise in a linear array.  The j-th column of B */
102 /*          is stored in the array BP as follows: */
103 /*          if UPLO = 'U', BP(i + (j-1)*j/2) = B(i,j) for 1<=i<=j; */
104 /*          if UPLO = 'L', BP(i + (j-1)*(2*n-j)/2) = B(i,j) for j<=i<=n. */
105 
106 /*          On exit, the triangular factor U or L from the Cholesky */
107 /*          factorization B = U**H*U or B = L*L**H, in the same storage */
108 /*          format as B. */
109 
110 /*  VL      (input) DOUBLE PRECISION */
111 /*  VU      (input) DOUBLE PRECISION */
112 /*          If RANGE='V', the lower and upper bounds of the interval to */
113 /*          be searched for eigenvalues. VL < VU. */
114 /*          Not referenced if RANGE = 'A' or 'I'. */
115 
116 /*  IL      (input) INTEGER */
117 /*  IU      (input) INTEGER */
118 /*          If RANGE='I', the indices (in ascending order) of the */
119 /*          smallest and largest eigenvalues to be returned. */
120 /*          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
121 /*          Not referenced if RANGE = 'A' or 'V'. */
122 
123 /*  ABSTOL  (input) DOUBLE PRECISION */
124 /*          The absolute error tolerance for the eigenvalues. */
125 /*          An approximate eigenvalue is accepted as converged */
126 /*          when it is determined to lie in an interval [a,b] */
127 /*          of width less than or equal to */
128 
129 /*                  ABSTOL + EPS *   max( |a|,|b| ) , */
130 
131 /*          where EPS is the machine precision.  If ABSTOL is less than */
132 /*          or equal to zero, then  EPS*|T|  will be used in its place, */
133 /*          where |T| is the 1-norm of the tridiagonal matrix obtained */
134 /*          by reducing AP to tridiagonal form. */
135 
136 /*          Eigenvalues will be computed most accurately when ABSTOL is */
137 /*          set to twice the underflow threshold 2*DLAMCH('S'), not zero. */
138 /*          If this routine returns with INFO>0, indicating that some */
139 /*          eigenvectors did not converge, try setting ABSTOL to */
140 /*          2*DLAMCH('S'). */
141 
142 /*  M       (output) INTEGER */
143 /*          The total number of eigenvalues found.  0 <= M <= N. */
144 /*          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
145 
146 /*  W       (output) DOUBLE PRECISION array, dimension (N) */
147 /*          On normal exit, the first M elements contain the selected */
148 /*          eigenvalues in ascending order. */
149 
150 /*  Z       (output) COMPLEX*16 array, dimension (LDZ, N) */
151 /*          If JOBZ = 'N', then Z is not referenced. */
152 /*          If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
153 /*          contain the orthonormal eigenvectors of the matrix A */
154 /*          corresponding to the selected eigenvalues, with the i-th */
155 /*          column of Z holding the eigenvector associated with W(i). */
156 /*          The eigenvectors are normalized as follows: */
157 /*          if ITYPE = 1 or 2, Z**H*B*Z = I; */
158 /*          if ITYPE = 3, Z**H*inv(B)*Z = I. */
159 
160 /*          If an eigenvector fails to converge, then that column of Z */
161 /*          contains the latest approximation to the eigenvector, and the */
162 /*          index of the eigenvector is returned in IFAIL. */
163 /*          Note: the user must ensure that at least max(1,M) columns are */
164 /*          supplied in the array Z; if RANGE = 'V', the exact value of M */
165 /*          is not known in advance and an upper bound must be used. */
166 
167 /*  LDZ     (input) INTEGER */
168 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
169 /*          JOBZ = 'V', LDZ >= max(1,N). */
170 
171 /*  WORK    (workspace) COMPLEX*16 array, dimension (2*N) */
172 
173 /*  RWORK   (workspace) DOUBLE PRECISION array, dimension (7*N) */
174 
175 /*  IWORK   (workspace) INTEGER array, dimension (5*N) */
176 
177 /*  IFAIL   (output) INTEGER array, dimension (N) */
178 /*          If JOBZ = 'V', then if INFO = 0, the first M elements of */
179 /*          IFAIL are zero.  If INFO > 0, then IFAIL contains the */
180 /*          indices of the eigenvectors that failed to converge. */
181 /*          If JOBZ = 'N', then IFAIL is not referenced. */
182 
183 /*  INFO    (output) INTEGER */
184 /*          = 0:  successful exit */
185 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
186 /*          > 0:  ZPPTRF or ZHPEVX returned an error code: */
187 /*             <= N:  if INFO = i, ZHPEVX failed to converge; */
188 /*                    i eigenvectors failed to converge.  Their indices */
189 /*                    are stored in array IFAIL. */
190 /*             > N:   if INFO = N + i, for 1 <= i <= n, then the leading */
191 /*                    minor of order i of B is not positive definite. */
192 /*                    The factorization of B could not be completed and */
193 /*                    no eigenvalues or eigenvectors were computed. */
194 
195 /*  Further Details */
196 /*  =============== */
197 
198 /*  Based on contributions by */
199 /*     Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */
200 
201 /*  ===================================================================== */
202 
203 /*     .. Local Scalars .. */
204 /*     .. */
205 /*     .. External Functions .. */
206 /*     .. */
207 /*     .. External Subroutines .. */
208 /*     .. */
209 /*     .. Intrinsic Functions .. */
210 /*     .. */
211 /*     .. Executable Statements .. */
212 
213 /*     Test the input parameters. */
214 
215     /* Parameter adjustments */
216     --ap;
217     --bp;
218     --w;
219     z_dim1 = *ldz;
220     z_offset = 1 + z_dim1;
221     z__ -= z_offset;
222     --work;
223     --rwork;
224     --iwork;
225     --ifail;
226 
227     /* Function Body */
228     wantz = lsame_(jobz, "V", (ftnlen)1, (ftnlen)1);
229     upper = lsame_(uplo, "U", (ftnlen)1, (ftnlen)1);
230     alleig = lsame_(range, "A", (ftnlen)1, (ftnlen)1);
231     valeig = lsame_(range, "V", (ftnlen)1, (ftnlen)1);
232     indeig = lsame_(range, "I", (ftnlen)1, (ftnlen)1);
233 
234     *info = 0;
235     if (*itype < 0 || *itype > 3) {
236 	*info = -1;
237     } else if (! (wantz || lsame_(jobz, "N", (ftnlen)1, (ftnlen)1))) {
238 	*info = -2;
239     } else if (! (alleig || valeig || indeig)) {
240 	*info = -3;
241     } else if (! (upper || lsame_(uplo, "L", (ftnlen)1, (ftnlen)1))) {
242 	*info = -4;
243     } else if (*n < 0) {
244 	*info = -5;
245     } else if (valeig && *n > 0 && *vu <= *vl) {
246 	*info = -9;
247     } else if (indeig && *il < 1) {
248 	*info = -10;
249     } else if (indeig && (*iu < min(*n,*il) || *iu > *n)) {
250 	*info = -11;
251     } else if (*ldz < 1 || wantz && *ldz < *n) {
252 	*info = -16;
253     }
254     if (*info != 0) {
255 	i__1 = -(*info);
256 	xerbla_("ZHPGVX", &i__1, (ftnlen)6);
257 	return 0;
258     }
259 
260 /*     Quick return if possible */
261 
262     if (*n == 0) {
263 	return 0;
264     }
265 
266 /*     Form a Cholesky factorization of B. */
267 
268     zpptrf_(uplo, n, &bp[1], info, (ftnlen)1);
269     if (*info != 0) {
270 	*info = *n + *info;
271 	return 0;
272     }
273 
274 /*     Transform problem to standard eigenvalue problem and solve. */
275 
276     zhpgst_(itype, uplo, n, &ap[1], &bp[1], info, (ftnlen)1);
277     zhpevx_(jobz, range, uplo, n, &ap[1], vl, vu, il, iu, abstol, m, &w[1], &
278 	    z__[z_offset], ldz, &work[1], &rwork[1], &iwork[1], &ifail[1],
279 	    info, (ftnlen)1, (ftnlen)1, (ftnlen)1);
280 
281     if (wantz) {
282 
283 /*        Backtransform eigenvectors to the original problem. */
284 
285 	if (*info > 0) {
286 	    *m = *info - 1;
287 	}
288 	if (*itype == 1 || *itype == 2) {
289 
290 /*           For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */
291 /*           backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */
292 
293 	    if (upper) {
294 		*(unsigned char *)trans = 'N';
295 	    } else {
296 		*(unsigned char *)trans = 'C';
297 	    }
298 
299 	    i__1 = *m;
300 	    for (j = 1; j <= i__1; ++j) {
301 		ztpsv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 +
302 			1], &c__1, (ftnlen)1, (ftnlen)1, (ftnlen)8);
303 /* L10: */
304 	    }
305 
306 	} else if (*itype == 3) {
307 
308 /*           For B*A*x=(lambda)*x; */
309 /*           backtransform eigenvectors: x = L*y or U'*y */
310 
311 	    if (upper) {
312 		*(unsigned char *)trans = 'C';
313 	    } else {
314 		*(unsigned char *)trans = 'N';
315 	    }
316 
317 	    i__1 = *m;
318 	    for (j = 1; j <= i__1; ++j) {
319 		ztpmv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 +
320 			1], &c__1, (ftnlen)1, (ftnlen)1, (ftnlen)8);
321 /* L20: */
322 	    }
323 	}
324     }
325 
326     return 0;
327 
328 /*     End of ZHPGVX */
329 
330 } /* zhpgvx_ */
331 
332