You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

chpevd.f 12 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. *> \brief <b> CHPEVD computes the eigenvalues and, optionally, the left and/or right eigenvectors for OTHER matrices</b>
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CHPEVD + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chpevd.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chpevd.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chpevd.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CHPEVD( JOBZ, UPLO, N, AP, W, Z, LDZ, WORK, LWORK,
  22. * RWORK, LRWORK, IWORK, LIWORK, INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * CHARACTER JOBZ, UPLO
  26. * INTEGER INFO, LDZ, LIWORK, LRWORK, LWORK, N
  27. * ..
  28. * .. Array Arguments ..
  29. * INTEGER IWORK( * )
  30. * REAL RWORK( * ), W( * )
  31. * COMPLEX AP( * ), WORK( * ), Z( LDZ, * )
  32. * ..
  33. *
  34. *
  35. *> \par Purpose:
  36. * =============
  37. *>
  38. *> \verbatim
  39. *>
  40. *> CHPEVD computes all the eigenvalues and, optionally, eigenvectors of
  41. *> a complex Hermitian matrix A in packed storage. If eigenvectors are
  42. *> desired, it uses a divide and conquer algorithm.
  43. *>
  44. *> \endverbatim
  45. *
  46. * Arguments:
  47. * ==========
  48. *
  49. *> \param[in] JOBZ
  50. *> \verbatim
  51. *> JOBZ is CHARACTER*1
  52. *> = 'N': Compute eigenvalues only;
  53. *> = 'V': Compute eigenvalues and eigenvectors.
  54. *> \endverbatim
  55. *>
  56. *> \param[in] UPLO
  57. *> \verbatim
  58. *> UPLO is CHARACTER*1
  59. *> = 'U': Upper triangle of A is stored;
  60. *> = 'L': Lower triangle of A is stored.
  61. *> \endverbatim
  62. *>
  63. *> \param[in] N
  64. *> \verbatim
  65. *> N is INTEGER
  66. *> The order of the matrix A. N >= 0.
  67. *> \endverbatim
  68. *>
  69. *> \param[in,out] AP
  70. *> \verbatim
  71. *> AP is COMPLEX array, dimension (N*(N+1)/2)
  72. *> On entry, the upper or lower triangle of the Hermitian matrix
  73. *> A, packed columnwise in a linear array. The j-th column of A
  74. *> is stored in the array AP as follows:
  75. *> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
  76. *> if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n.
  77. *>
  78. *> On exit, AP is overwritten by values generated during the
  79. *> reduction to tridiagonal form. If UPLO = 'U', the diagonal
  80. *> and first superdiagonal of the tridiagonal matrix T overwrite
  81. *> the corresponding elements of A, and if UPLO = 'L', the
  82. *> diagonal and first subdiagonal of T overwrite the
  83. *> corresponding elements of A.
  84. *> \endverbatim
  85. *>
  86. *> \param[out] W
  87. *> \verbatim
  88. *> W is REAL array, dimension (N)
  89. *> If INFO = 0, the eigenvalues in ascending order.
  90. *> \endverbatim
  91. *>
  92. *> \param[out] Z
  93. *> \verbatim
  94. *> Z is COMPLEX array, dimension (LDZ, N)
  95. *> If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal
  96. *> eigenvectors of the matrix A, with the i-th column of Z
  97. *> holding the eigenvector associated with W(i).
  98. *> If JOBZ = 'N', then Z is not referenced.
  99. *> \endverbatim
  100. *>
  101. *> \param[in] LDZ
  102. *> \verbatim
  103. *> LDZ is INTEGER
  104. *> The leading dimension of the array Z. LDZ >= 1, and if
  105. *> JOBZ = 'V', LDZ >= max(1,N).
  106. *> \endverbatim
  107. *>
  108. *> \param[out] WORK
  109. *> \verbatim
  110. *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
  111. *> On exit, if INFO = 0, WORK(1) returns the required LWORK.
  112. *> \endverbatim
  113. *>
  114. *> \param[in] LWORK
  115. *> \verbatim
  116. *> LWORK is INTEGER
  117. *> The dimension of array WORK.
  118. *> If N <= 1, LWORK must be at least 1.
  119. *> If JOBZ = 'N' and N > 1, LWORK must be at least N.
  120. *> If JOBZ = 'V' and N > 1, LWORK must be at least 2*N.
  121. *>
  122. *> If LWORK = -1, then a workspace query is assumed; the routine
  123. *> only calculates the required sizes of the WORK, RWORK and
  124. *> IWORK arrays, returns these values as the first entries of
  125. *> the WORK, RWORK and IWORK arrays, and no error message
  126. *> related to LWORK or LRWORK or LIWORK is issued by XERBLA.
  127. *> \endverbatim
  128. *>
  129. *> \param[out] RWORK
  130. *> \verbatim
  131. *> RWORK is REAL array, dimension (MAX(1,LRWORK))
  132. *> On exit, if INFO = 0, RWORK(1) returns the required LRWORK.
  133. *> \endverbatim
  134. *>
  135. *> \param[in] LRWORK
  136. *> \verbatim
  137. *> LRWORK is INTEGER
  138. *> The dimension of array RWORK.
  139. *> If N <= 1, LRWORK must be at least 1.
  140. *> If JOBZ = 'N' and N > 1, LRWORK must be at least N.
  141. *> If JOBZ = 'V' and N > 1, LRWORK must be at least
  142. *> 1 + 5*N + 2*N**2.
  143. *>
  144. *> If LRWORK = -1, then a workspace query is assumed; the
  145. *> routine only calculates the required sizes of the WORK, RWORK
  146. *> and IWORK arrays, returns these values as the first entries
  147. *> of the WORK, RWORK and IWORK arrays, and no error message
  148. *> related to LWORK or LRWORK or LIWORK is issued by XERBLA.
  149. *> \endverbatim
  150. *>
  151. *> \param[out] IWORK
  152. *> \verbatim
  153. *> IWORK is INTEGER array, dimension (MAX(1,LIWORK))
  154. *> On exit, if INFO = 0, IWORK(1) returns the required LIWORK.
  155. *> \endverbatim
  156. *>
  157. *> \param[in] LIWORK
  158. *> \verbatim
  159. *> LIWORK is INTEGER
  160. *> The dimension of array IWORK.
  161. *> If JOBZ = 'N' or N <= 1, LIWORK must be at least 1.
  162. *> If JOBZ = 'V' and N > 1, LIWORK must be at least 3 + 5*N.
  163. *>
  164. *> If LIWORK = -1, then a workspace query is assumed; the
  165. *> routine only calculates the required sizes of the WORK, RWORK
  166. *> and IWORK arrays, returns these values as the first entries
  167. *> of the WORK, RWORK and IWORK arrays, and no error message
  168. *> related to LWORK or LRWORK or LIWORK is issued by XERBLA.
  169. *> \endverbatim
  170. *>
  171. *> \param[out] INFO
  172. *> \verbatim
  173. *> INFO is INTEGER
  174. *> = 0: successful exit
  175. *> < 0: if INFO = -i, the i-th argument had an illegal value.
  176. *> > 0: if INFO = i, the algorithm failed to converge; i
  177. *> off-diagonal elements of an intermediate tridiagonal
  178. *> form did not converge to zero.
  179. *> \endverbatim
  180. *
  181. * Authors:
  182. * ========
  183. *
  184. *> \author Univ. of Tennessee
  185. *> \author Univ. of California Berkeley
  186. *> \author Univ. of Colorado Denver
  187. *> \author NAG Ltd.
  188. *
  189. *> \ingroup hpevd
  190. *
  191. * =====================================================================
  192. SUBROUTINE CHPEVD( JOBZ, UPLO, N, AP, W, Z, LDZ, WORK, LWORK,
  193. $ RWORK, LRWORK, IWORK, LIWORK, INFO )
  194. *
  195. * -- LAPACK driver routine --
  196. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  197. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  198. *
  199. * .. Scalar Arguments ..
  200. CHARACTER JOBZ, UPLO
  201. INTEGER INFO, LDZ, LIWORK, LRWORK, LWORK, N
  202. * ..
  203. * .. Array Arguments ..
  204. INTEGER IWORK( * )
  205. REAL RWORK( * ), W( * )
  206. COMPLEX AP( * ), WORK( * ), Z( LDZ, * )
  207. * ..
  208. *
  209. * =====================================================================
  210. *
  211. * .. Parameters ..
  212. REAL ZERO, ONE
  213. PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
  214. COMPLEX CONE
  215. PARAMETER ( CONE = ( 1.0E+0, 0.0E+0 ) )
  216. * ..
  217. * .. Local Scalars ..
  218. LOGICAL LQUERY, WANTZ
  219. INTEGER IINFO, IMAX, INDE, INDRWK, INDTAU, INDWRK,
  220. $ ISCALE, LIWMIN, LLRWK, LLWRK, LRWMIN, LWMIN
  221. REAL ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN, SIGMA,
  222. $ SMLNUM
  223. * ..
  224. * .. External Functions ..
  225. LOGICAL LSAME
  226. REAL CLANHP, SLAMCH, SROUNDUP_LWORK
  227. EXTERNAL LSAME, CLANHP, SLAMCH, SROUNDUP_LWORK
  228. * ..
  229. * .. External Subroutines ..
  230. EXTERNAL CHPTRD, CSSCAL, CSTEDC, CUPMTR, SSCAL, SSTERF,
  231. $ XERBLA
  232. * ..
  233. * .. Intrinsic Functions ..
  234. INTRINSIC SQRT
  235. * ..
  236. * .. Executable Statements ..
  237. *
  238. * Test the input parameters.
  239. *
  240. WANTZ = LSAME( JOBZ, 'V' )
  241. LQUERY = ( LWORK.EQ.-1 .OR. LRWORK.EQ.-1 .OR. LIWORK.EQ.-1 )
  242. *
  243. INFO = 0
  244. IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
  245. INFO = -1
  246. ELSE IF( .NOT.( LSAME( UPLO, 'L' ) .OR. LSAME( UPLO, 'U' ) ) )
  247. $ THEN
  248. INFO = -2
  249. ELSE IF( N.LT.0 ) THEN
  250. INFO = -3
  251. ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
  252. INFO = -7
  253. END IF
  254. *
  255. IF( INFO.EQ.0 ) THEN
  256. IF( N.LE.1 ) THEN
  257. LWMIN = 1
  258. LIWMIN = 1
  259. LRWMIN = 1
  260. ELSE
  261. IF( WANTZ ) THEN
  262. LWMIN = 2*N
  263. LRWMIN = 1 + 5*N + 2*N**2
  264. LIWMIN = 3 + 5*N
  265. ELSE
  266. LWMIN = N
  267. LRWMIN = N
  268. LIWMIN = 1
  269. END IF
  270. END IF
  271. WORK( 1 ) = SROUNDUP_LWORK(LWMIN)
  272. RWORK( 1 ) = LRWMIN
  273. IWORK( 1 ) = LIWMIN
  274. *
  275. IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
  276. INFO = -9
  277. ELSE IF( LRWORK.LT.LRWMIN .AND. .NOT.LQUERY ) THEN
  278. INFO = -11
  279. ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
  280. INFO = -13
  281. END IF
  282. END IF
  283. *
  284. IF( INFO.NE.0 ) THEN
  285. CALL XERBLA( 'CHPEVD', -INFO )
  286. RETURN
  287. ELSE IF( LQUERY ) THEN
  288. RETURN
  289. END IF
  290. *
  291. * Quick return if possible
  292. *
  293. IF( N.EQ.0 )
  294. $ RETURN
  295. *
  296. IF( N.EQ.1 ) THEN
  297. W( 1 ) = REAL( AP( 1 ) )
  298. IF( WANTZ )
  299. $ Z( 1, 1 ) = CONE
  300. RETURN
  301. END IF
  302. *
  303. * Get machine constants.
  304. *
  305. SAFMIN = SLAMCH( 'Safe minimum' )
  306. EPS = SLAMCH( 'Precision' )
  307. SMLNUM = SAFMIN / EPS
  308. BIGNUM = ONE / SMLNUM
  309. RMIN = SQRT( SMLNUM )
  310. RMAX = SQRT( BIGNUM )
  311. *
  312. * Scale matrix to allowable range, if necessary.
  313. *
  314. ANRM = CLANHP( 'M', UPLO, N, AP, RWORK )
  315. ISCALE = 0
  316. IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
  317. ISCALE = 1
  318. SIGMA = RMIN / ANRM
  319. ELSE IF( ANRM.GT.RMAX ) THEN
  320. ISCALE = 1
  321. SIGMA = RMAX / ANRM
  322. END IF
  323. IF( ISCALE.EQ.1 ) THEN
  324. CALL CSSCAL( ( N*( N+1 ) ) / 2, SIGMA, AP, 1 )
  325. END IF
  326. *
  327. * Call CHPTRD to reduce Hermitian packed matrix to tridiagonal form.
  328. *
  329. INDE = 1
  330. INDTAU = 1
  331. INDRWK = INDE + N
  332. INDWRK = INDTAU + N
  333. LLWRK = LWORK - INDWRK + 1
  334. LLRWK = LRWORK - INDRWK + 1
  335. CALL CHPTRD( UPLO, N, AP, W, RWORK( INDE ), WORK( INDTAU ),
  336. $ IINFO )
  337. *
  338. * For eigenvalues only, call SSTERF. For eigenvectors, first call
  339. * CUPGTR to generate the orthogonal matrix, then call CSTEDC.
  340. *
  341. IF( .NOT.WANTZ ) THEN
  342. CALL SSTERF( N, W, RWORK( INDE ), INFO )
  343. ELSE
  344. CALL CSTEDC( 'I', N, W, RWORK( INDE ), Z, LDZ, WORK( INDWRK ),
  345. $ LLWRK, RWORK( INDRWK ), LLRWK, IWORK, LIWORK,
  346. $ INFO )
  347. CALL CUPMTR( 'L', UPLO, 'N', N, N, AP, WORK( INDTAU ), Z, LDZ,
  348. $ WORK( INDWRK ), IINFO )
  349. END IF
  350. *
  351. * If matrix was scaled, then rescale eigenvalues appropriately.
  352. *
  353. IF( ISCALE.EQ.1 ) THEN
  354. IF( INFO.EQ.0 ) THEN
  355. IMAX = N
  356. ELSE
  357. IMAX = INFO - 1
  358. END IF
  359. CALL SSCAL( IMAX, ONE / SIGMA, W, 1 )
  360. END IF
  361. *
  362. WORK( 1 ) = SROUNDUP_LWORK(LWMIN)
  363. RWORK( 1 ) = LRWMIN
  364. IWORK( 1 ) = LIWMIN
  365. RETURN
  366. *
  367. * End of CHPEVD
  368. *
  369. END