1 SUBROUTINE ZHPEV( JOBZ, UPLO, N, AP, W, Z, LDZ, WORK, RWORK,
2 $ INFO )
3 *
4 * -- LAPACK driver routine (version 3.2) --
5 * -- LAPACK is a software package provided by Univ. of Tennessee, --
6 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
7 * November 2006
8 *
9 * .. Scalar Arguments ..
10 CHARACTER JOBZ, UPLO
11 INTEGER INFO, LDZ, N
12 * ..
13 * .. Array Arguments ..
14 DOUBLE PRECISION RWORK( * ), W( * )
15 COMPLEX*16 AP( * ), WORK( * ), Z( LDZ, * )
16 * ..
17 *
18 * Purpose
19 * =======
20 *
21 * ZHPEV computes all the eigenvalues and, optionally, eigenvectors of a
22 * complex Hermitian matrix in packed storage.
23 *
24 * Arguments
25 * =========
26 *
27 * JOBZ (input) CHARACTER*1
28 * = 'N': Compute eigenvalues only;
29 * = 'V': Compute eigenvalues and eigenvectors.
30 *
31 * UPLO (input) CHARACTER*1
32 * = 'U': Upper triangle of A is stored;
33 * = 'L': Lower triangle of A is stored.
34 *
35 * N (input) INTEGER
36 * The order of the matrix A. N >= 0.
37 *
38 * AP (input/output) COMPLEX*16 array, dimension (N*(N+1)/2)
39 * On entry, the upper or lower triangle of the Hermitian matrix
40 * A, packed columnwise in a linear array. The j-th column of A
41 * is stored in the array AP as follows:
42 * if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
43 * if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n.
44 *
45 * On exit, AP is overwritten by values generated during the
46 * reduction to tridiagonal form. If UPLO = 'U', the diagonal
47 * and first superdiagonal of the tridiagonal matrix T overwrite
48 * the corresponding elements of A, and if UPLO = 'L', the
49 * diagonal and first subdiagonal of T overwrite the
50 * corresponding elements of A.
51 *
52 * W (output) DOUBLE PRECISION array, dimension (N)
53 * If INFO = 0, the eigenvalues in ascending order.
54 *
55 * Z (output) COMPLEX*16 array, dimension (LDZ, N)
56 * If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal
57 * eigenvectors of the matrix A, with the i-th column of Z
58 * holding the eigenvector associated with W(i).
59 * If JOBZ = 'N', then Z is not referenced.
60 *
61 * LDZ (input) INTEGER
62 * The leading dimension of the array Z. LDZ >= 1, and if
63 * JOBZ = 'V', LDZ >= max(1,N).
64 *
65 * WORK (workspace) COMPLEX*16 array, dimension (max(1, 2*N-1))
66 *
67 * RWORK (workspace) DOUBLE PRECISION array, dimension (max(1, 3*N-2))
68 *
69 * INFO (output) INTEGER
70 * = 0: successful exit.
71 * < 0: if INFO = -i, the i-th argument had an illegal value.
72 * > 0: if INFO = i, the algorithm failed to converge; i
73 * off-diagonal elements of an intermediate tridiagonal
74 * form did not converge to zero.
75 *
76 * =====================================================================
77 *
78 * .. Parameters ..
79 DOUBLE PRECISION ZERO, ONE
80 PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
81 * ..
82 * .. Local Scalars ..
83 LOGICAL WANTZ
84 INTEGER IINFO, IMAX, INDE, INDRWK, INDTAU, INDWRK,
85 $ ISCALE
86 DOUBLE PRECISION ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN, SIGMA,
87 $ SMLNUM
88 * ..
89 * .. External Functions ..
90 LOGICAL LSAME
91 DOUBLE PRECISION DLAMCH, ZLANHP
92 EXTERNAL LSAME, DLAMCH, ZLANHP
93 * ..
94 * .. External Subroutines ..
95 EXTERNAL DSCAL, DSTERF, XERBLA, ZDSCAL, ZHPTRD, ZSTEQR,
96 $ ZUPGTR
97 * ..
98 * .. Intrinsic Functions ..
99 INTRINSIC SQRT
100 * ..
101 * .. Executable Statements ..
102 *
103 * Test the input parameters.
104 *
105 WANTZ = LSAME( JOBZ, 'V' )
106 *
107 INFO = 0
108 IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
109 INFO = -1
110 ELSE IF( .NOT.( LSAME( UPLO, 'L' ) .OR. LSAME( UPLO, 'U' ) ) )
111 $ THEN
112 INFO = -2
113 ELSE IF( N.LT.0 ) THEN
114 INFO = -3
115 ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
116 INFO = -7
117 END IF
118 *
119 IF( INFO.NE.0 ) THEN
120 CALL XERBLA( 'ZHPEV ', -INFO )
121 RETURN
122 END IF
123 *
124 * Quick return if possible
125 *
126 IF( N.EQ.0 )
127 $ RETURN
128 *
129 IF( N.EQ.1 ) THEN
130 W( 1 ) = AP( 1 )
131 RWORK( 1 ) = 1
132 IF( WANTZ )
133 $ Z( 1, 1 ) = ONE
134 RETURN
135 END IF
136 *
137 * Get machine constants.
138 *
139 SAFMIN = DLAMCH( 'Safe minimum' )
140 EPS = DLAMCH( 'Precision' )
141 SMLNUM = SAFMIN / EPS
142 BIGNUM = ONE / SMLNUM
143 RMIN = SQRT( SMLNUM )
144 RMAX = SQRT( BIGNUM )
145 *
146 * Scale matrix to allowable range, if necessary.
147 *
148 ANRM = ZLANHP( 'M', UPLO, N, AP, RWORK )
149 ISCALE = 0
150 IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
151 ISCALE = 1
152 SIGMA = RMIN / ANRM
153 ELSE IF( ANRM.GT.RMAX ) THEN
154 ISCALE = 1
155 SIGMA = RMAX / ANRM
156 END IF
157 IF( ISCALE.EQ.1 ) THEN
158 CALL ZDSCAL( ( N*( N+1 ) ) / 2, SIGMA, AP, 1 )
159 END IF
160 *
161 * Call ZHPTRD to reduce Hermitian packed matrix to tridiagonal form.
162 *
163 INDE = 1
164 INDTAU = 1
165 CALL ZHPTRD( UPLO, N, AP, W, RWORK( INDE ), WORK( INDTAU ),
166 $ IINFO )
167 *
168 * For eigenvalues only, call DSTERF. For eigenvectors, first call
169 * ZUPGTR to generate the orthogonal matrix, then call ZSTEQR.
170 *
171 IF( .NOT.WANTZ ) THEN
172 CALL DSTERF( N, W, RWORK( INDE ), INFO )
173 ELSE
174 INDWRK = INDTAU + N
175 CALL ZUPGTR( UPLO, N, AP, WORK( INDTAU ), Z, LDZ,
176 $ WORK( INDWRK ), IINFO )
177 INDRWK = INDE + N
178 CALL ZSTEQR( JOBZ, N, W, RWORK( INDE ), Z, LDZ,
179 $ RWORK( INDRWK ), INFO )
180 END IF
181 *
182 * If matrix was scaled, then rescale eigenvalues appropriately.
183 *
184 IF( ISCALE.EQ.1 ) THEN
185 IF( INFO.EQ.0 ) THEN
186 IMAX = N
187 ELSE
188 IMAX = INFO - 1
189 END IF
190 CALL DSCAL( IMAX, ONE / SIGMA, W, 1 )
191 END IF
192 *
193 RETURN
194 *
195 * End of ZHPEV
196 *
197 END
2 $ INFO )
3 *
4 * -- LAPACK driver routine (version 3.2) --
5 * -- LAPACK is a software package provided by Univ. of Tennessee, --
6 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
7 * November 2006
8 *
9 * .. Scalar Arguments ..
10 CHARACTER JOBZ, UPLO
11 INTEGER INFO, LDZ, N
12 * ..
13 * .. Array Arguments ..
14 DOUBLE PRECISION RWORK( * ), W( * )
15 COMPLEX*16 AP( * ), WORK( * ), Z( LDZ, * )
16 * ..
17 *
18 * Purpose
19 * =======
20 *
21 * ZHPEV computes all the eigenvalues and, optionally, eigenvectors of a
22 * complex Hermitian matrix in packed storage.
23 *
24 * Arguments
25 * =========
26 *
27 * JOBZ (input) CHARACTER*1
28 * = 'N': Compute eigenvalues only;
29 * = 'V': Compute eigenvalues and eigenvectors.
30 *
31 * UPLO (input) CHARACTER*1
32 * = 'U': Upper triangle of A is stored;
33 * = 'L': Lower triangle of A is stored.
34 *
35 * N (input) INTEGER
36 * The order of the matrix A. N >= 0.
37 *
38 * AP (input/output) COMPLEX*16 array, dimension (N*(N+1)/2)
39 * On entry, the upper or lower triangle of the Hermitian matrix
40 * A, packed columnwise in a linear array. The j-th column of A
41 * is stored in the array AP as follows:
42 * if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
43 * if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n.
44 *
45 * On exit, AP is overwritten by values generated during the
46 * reduction to tridiagonal form. If UPLO = 'U', the diagonal
47 * and first superdiagonal of the tridiagonal matrix T overwrite
48 * the corresponding elements of A, and if UPLO = 'L', the
49 * diagonal and first subdiagonal of T overwrite the
50 * corresponding elements of A.
51 *
52 * W (output) DOUBLE PRECISION array, dimension (N)
53 * If INFO = 0, the eigenvalues in ascending order.
54 *
55 * Z (output) COMPLEX*16 array, dimension (LDZ, N)
56 * If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal
57 * eigenvectors of the matrix A, with the i-th column of Z
58 * holding the eigenvector associated with W(i).
59 * If JOBZ = 'N', then Z is not referenced.
60 *
61 * LDZ (input) INTEGER
62 * The leading dimension of the array Z. LDZ >= 1, and if
63 * JOBZ = 'V', LDZ >= max(1,N).
64 *
65 * WORK (workspace) COMPLEX*16 array, dimension (max(1, 2*N-1))
66 *
67 * RWORK (workspace) DOUBLE PRECISION array, dimension (max(1, 3*N-2))
68 *
69 * INFO (output) INTEGER
70 * = 0: successful exit.
71 * < 0: if INFO = -i, the i-th argument had an illegal value.
72 * > 0: if INFO = i, the algorithm failed to converge; i
73 * off-diagonal elements of an intermediate tridiagonal
74 * form did not converge to zero.
75 *
76 * =====================================================================
77 *
78 * .. Parameters ..
79 DOUBLE PRECISION ZERO, ONE
80 PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
81 * ..
82 * .. Local Scalars ..
83 LOGICAL WANTZ
84 INTEGER IINFO, IMAX, INDE, INDRWK, INDTAU, INDWRK,
85 $ ISCALE
86 DOUBLE PRECISION ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN, SIGMA,
87 $ SMLNUM
88 * ..
89 * .. External Functions ..
90 LOGICAL LSAME
91 DOUBLE PRECISION DLAMCH, ZLANHP
92 EXTERNAL LSAME, DLAMCH, ZLANHP
93 * ..
94 * .. External Subroutines ..
95 EXTERNAL DSCAL, DSTERF, XERBLA, ZDSCAL, ZHPTRD, ZSTEQR,
96 $ ZUPGTR
97 * ..
98 * .. Intrinsic Functions ..
99 INTRINSIC SQRT
100 * ..
101 * .. Executable Statements ..
102 *
103 * Test the input parameters.
104 *
105 WANTZ = LSAME( JOBZ, 'V' )
106 *
107 INFO = 0
108 IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
109 INFO = -1
110 ELSE IF( .NOT.( LSAME( UPLO, 'L' ) .OR. LSAME( UPLO, 'U' ) ) )
111 $ THEN
112 INFO = -2
113 ELSE IF( N.LT.0 ) THEN
114 INFO = -3
115 ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
116 INFO = -7
117 END IF
118 *
119 IF( INFO.NE.0 ) THEN
120 CALL XERBLA( 'ZHPEV ', -INFO )
121 RETURN
122 END IF
123 *
124 * Quick return if possible
125 *
126 IF( N.EQ.0 )
127 $ RETURN
128 *
129 IF( N.EQ.1 ) THEN
130 W( 1 ) = AP( 1 )
131 RWORK( 1 ) = 1
132 IF( WANTZ )
133 $ Z( 1, 1 ) = ONE
134 RETURN
135 END IF
136 *
137 * Get machine constants.
138 *
139 SAFMIN = DLAMCH( 'Safe minimum' )
140 EPS = DLAMCH( 'Precision' )
141 SMLNUM = SAFMIN / EPS
142 BIGNUM = ONE / SMLNUM
143 RMIN = SQRT( SMLNUM )
144 RMAX = SQRT( BIGNUM )
145 *
146 * Scale matrix to allowable range, if necessary.
147 *
148 ANRM = ZLANHP( 'M', UPLO, N, AP, RWORK )
149 ISCALE = 0
150 IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
151 ISCALE = 1
152 SIGMA = RMIN / ANRM
153 ELSE IF( ANRM.GT.RMAX ) THEN
154 ISCALE = 1
155 SIGMA = RMAX / ANRM
156 END IF
157 IF( ISCALE.EQ.1 ) THEN
158 CALL ZDSCAL( ( N*( N+1 ) ) / 2, SIGMA, AP, 1 )
159 END IF
160 *
161 * Call ZHPTRD to reduce Hermitian packed matrix to tridiagonal form.
162 *
163 INDE = 1
164 INDTAU = 1
165 CALL ZHPTRD( UPLO, N, AP, W, RWORK( INDE ), WORK( INDTAU ),
166 $ IINFO )
167 *
168 * For eigenvalues only, call DSTERF. For eigenvectors, first call
169 * ZUPGTR to generate the orthogonal matrix, then call ZSTEQR.
170 *
171 IF( .NOT.WANTZ ) THEN
172 CALL DSTERF( N, W, RWORK( INDE ), INFO )
173 ELSE
174 INDWRK = INDTAU + N
175 CALL ZUPGTR( UPLO, N, AP, WORK( INDTAU ), Z, LDZ,
176 $ WORK( INDWRK ), IINFO )
177 INDRWK = INDE + N
178 CALL ZSTEQR( JOBZ, N, W, RWORK( INDE ), Z, LDZ,
179 $ RWORK( INDRWK ), INFO )
180 END IF
181 *
182 * If matrix was scaled, then rescale eigenvalues appropriately.
183 *
184 IF( ISCALE.EQ.1 ) THEN
185 IF( INFO.EQ.0 ) THEN
186 IMAX = N
187 ELSE
188 IMAX = INFO - 1
189 END IF
190 CALL DSCAL( IMAX, ONE / SIGMA, W, 1 )
191 END IF
192 *
193 RETURN
194 *
195 * End of ZHPEV
196 *
197 END