1 /* ./src_f77/dspgv.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 
dspgv_(integer * itype,char * jobz,char * uplo,integer * n,doublereal * ap,doublereal * bp,doublereal * w,doublereal * z__,integer * ldz,doublereal * work,integer * info,ftnlen jobz_len,ftnlen uplo_len)12 /* Subroutine */ int dspgv_(integer *itype, char *jobz, char *uplo, integer *
13 	n, doublereal *ap, doublereal *bp, doublereal *w, doublereal *z__,
14 	integer *ldz, doublereal *work, integer *info, ftnlen jobz_len,
15 	ftnlen uplo_len)
16 {
17     /* System generated locals */
18     integer z_dim1, z_offset, i__1;
19 
20     /* Local variables */
21     static integer j, neig;
22     extern logical lsame_(char *, char *, ftnlen, ftnlen);
23     extern /* Subroutine */ int dspev_(char *, char *, integer *, doublereal *
24 	    , doublereal *, doublereal *, integer *, doublereal *, integer *,
25 	    ftnlen, ftnlen);
26     static char trans[1];
27     static logical upper;
28     extern /* Subroutine */ int dtpmv_(char *, char *, char *, integer *,
29 	    doublereal *, doublereal *, integer *, ftnlen, ftnlen, ftnlen),
30 	    dtpsv_(char *, char *, char *, integer *, doublereal *,
31 	    doublereal *, integer *, ftnlen, ftnlen, ftnlen);
32     static logical wantz;
33     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen), dpptrf_(
34 	    char *, integer *, doublereal *, integer *, ftnlen), dspgst_(
35 	    integer *, char *, integer *, doublereal *, doublereal *, integer
36 	    *, ftnlen);
37 
38 
39 /*  -- LAPACK driver routine (version 3.0) -- */
40 /*     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */
41 /*     Courant Institute, Argonne National Lab, and Rice University */
42 /*     September 30, 1994 */
43 
44 /*     .. Scalar Arguments .. */
45 /*     .. */
46 /*     .. Array Arguments .. */
47 /*     .. */
48 
49 /*  Purpose */
50 /*  ======= */
51 
52 /*  DSPGV computes all the eigenvalues and, optionally, the eigenvectors */
53 /*  of a real generalized symmetric-definite eigenproblem, of the form */
54 /*  A*x=(lambda)*B*x,  A*Bx=(lambda)*x,  or B*A*x=(lambda)*x. */
55 /*  Here A and B are assumed to be symmetric, stored in packed format, */
56 /*  and B is also positive definite. */
57 
58 /*  Arguments */
59 /*  ========= */
60 
61 /*  ITYPE   (input) INTEGER */
62 /*          Specifies the problem type to be solved: */
63 /*          = 1:  A*x = (lambda)*B*x */
64 /*          = 2:  A*B*x = (lambda)*x */
65 /*          = 3:  B*A*x = (lambda)*x */
66 
67 /*  JOBZ    (input) CHARACTER*1 */
68 /*          = 'N':  Compute eigenvalues only; */
69 /*          = 'V':  Compute eigenvalues and eigenvectors. */
70 
71 /*  UPLO    (input) CHARACTER*1 */
72 /*          = 'U':  Upper triangles of A and B are stored; */
73 /*          = 'L':  Lower triangles of A and B are stored. */
74 
75 /*  N       (input) INTEGER */
76 /*          The order of the matrices A and B.  N >= 0. */
77 
78 /*  AP      (input/output) DOUBLE PRECISION array, dimension */
79 /*                            (N*(N+1)/2) */
80 /*          On entry, the upper or lower triangle of the symmetric matrix */
81 /*          A, packed columnwise in a linear array.  The j-th column of A */
82 /*          is stored in the array AP as follows: */
83 /*          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
84 /*          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */
85 
86 /*          On exit, the contents of AP are destroyed. */
87 
88 /*  BP      (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
89 /*          On entry, the upper or lower triangle of the symmetric matrix */
90 /*          B, packed columnwise in a linear array.  The j-th column of B */
91 /*          is stored in the array BP as follows: */
92 /*          if UPLO = 'U', BP(i + (j-1)*j/2) = B(i,j) for 1<=i<=j; */
93 /*          if UPLO = 'L', BP(i + (j-1)*(2*n-j)/2) = B(i,j) for j<=i<=n. */
94 
95 /*          On exit, the triangular factor U or L from the Cholesky */
96 /*          factorization B = U**T*U or B = L*L**T, in the same storage */
97 /*          format as B. */
98 
99 /*  W       (output) DOUBLE PRECISION array, dimension (N) */
100 /*          If INFO = 0, the eigenvalues in ascending order. */
101 
102 /*  Z       (output) DOUBLE PRECISION array, dimension (LDZ, N) */
103 /*          If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of */
104 /*          eigenvectors.  The eigenvectors are normalized as follows: */
105 /*          if ITYPE = 1 or 2, Z**T*B*Z = I; */
106 /*          if ITYPE = 3, Z**T*inv(B)*Z = I. */
107 /*          If JOBZ = 'N', then Z is not referenced. */
108 
109 /*  LDZ     (input) INTEGER */
110 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
111 /*          JOBZ = 'V', LDZ >= max(1,N). */
112 
113 /*  WORK    (workspace) DOUBLE PRECISION array, dimension (3*N) */
114 
115 /*  INFO    (output) INTEGER */
116 /*          = 0:  successful exit */
117 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
118 /*          > 0:  DPPTRF or DSPEV returned an error code: */
119 /*             <= N:  if INFO = i, DSPEV failed to converge; */
120 /*                    i off-diagonal elements of an intermediate */
121 /*                    tridiagonal form did not converge to zero. */
122 /*             > N:   if INFO = n + i, for 1 <= i <= n, then the leading */
123 /*                    minor of order i of B is not positive definite. */
124 /*                    The factorization of B could not be completed and */
125 /*                    no eigenvalues or eigenvectors were computed. */
126 
127 /*  ===================================================================== */
128 
129 /*     .. Local Scalars .. */
130 /*     .. */
131 /*     .. External Functions .. */
132 /*     .. */
133 /*     .. External Subroutines .. */
134 /*     .. */
135 /*     .. Executable Statements .. */
136 
137 /*     Test the input parameters. */
138 
139     /* Parameter adjustments */
140     --ap;
141     --bp;
142     --w;
143     z_dim1 = *ldz;
144     z_offset = 1 + z_dim1;
145     z__ -= z_offset;
146     --work;
147 
148     /* Function Body */
149     wantz = lsame_(jobz, "V", (ftnlen)1, (ftnlen)1);
150     upper = lsame_(uplo, "U", (ftnlen)1, (ftnlen)1);
151 
152     *info = 0;
153     if (*itype < 0 || *itype > 3) {
154 	*info = -1;
155     } else if (! (wantz || lsame_(jobz, "N", (ftnlen)1, (ftnlen)1))) {
156 	*info = -2;
157     } else if (! (upper || lsame_(uplo, "L", (ftnlen)1, (ftnlen)1))) {
158 	*info = -3;
159     } else if (*n < 0) {
160 	*info = -4;
161     } else if (*ldz < 1 || wantz && *ldz < *n) {
162 	*info = -9;
163     }
164     if (*info != 0) {
165 	i__1 = -(*info);
166 	xerbla_("DSPGV ", &i__1, (ftnlen)6);
167 	return 0;
168     }
169 
170 /*     Quick return if possible */
171 
172     if (*n == 0) {
173 	return 0;
174     }
175 
176 /*     Form a Cholesky factorization of B. */
177 
178     dpptrf_(uplo, n, &bp[1], info, (ftnlen)1);
179     if (*info != 0) {
180 	*info = *n + *info;
181 	return 0;
182     }
183 
184 /*     Transform problem to standard eigenvalue problem and solve. */
185 
186     dspgst_(itype, uplo, n, &ap[1], &bp[1], info, (ftnlen)1);
187     dspev_(jobz, uplo, n, &ap[1], &w[1], &z__[z_offset], ldz, &work[1], info,
188 	    (ftnlen)1, (ftnlen)1);
189 
190     if (wantz) {
191 
192 /*        Backtransform eigenvectors to the original problem. */
193 
194 	neig = *n;
195 	if (*info > 0) {
196 	    neig = *info - 1;
197 	}
198 	if (*itype == 1 || *itype == 2) {
199 
200 /*           For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */
201 /*           backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */
202 
203 	    if (upper) {
204 		*(unsigned char *)trans = 'N';
205 	    } else {
206 		*(unsigned char *)trans = 'T';
207 	    }
208 
209 	    i__1 = neig;
210 	    for (j = 1; j <= i__1; ++j) {
211 		dtpsv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 +
212 			1], &c__1, (ftnlen)1, (ftnlen)1, (ftnlen)8);
213 /* L10: */
214 	    }
215 
216 	} else if (*itype == 3) {
217 
218 /*           For B*A*x=(lambda)*x; */
219 /*           backtransform eigenvectors: x = L*y or U'*y */
220 
221 	    if (upper) {
222 		*(unsigned char *)trans = 'T';
223 	    } else {
224 		*(unsigned char *)trans = 'N';
225 	    }
226 
227 	    i__1 = neig;
228 	    for (j = 1; j <= i__1; ++j) {
229 		dtpmv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 +
230 			1], &c__1, (ftnlen)1, (ftnlen)1, (ftnlen)8);
231 /* L20: */
232 	    }
233 	}
234     }
235     return 0;
236 
237 /*     End of DSPGV */
238 
239 } /* dspgv_ */
240 
241