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.

chetf2.f 20 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. *> \brief \b CHETF2 computes the factorization of a complex Hermitian matrix, using the diagonal pivoting method (unblocked algorithm calling Level 2 BLAS).
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CHETF2 + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetf2.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetf2.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetf2.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CHETF2( UPLO, N, A, LDA, IPIV, INFO )
  22. *
  23. * .. Scalar Arguments ..
  24. * CHARACTER UPLO
  25. * INTEGER INFO, LDA, N
  26. * ..
  27. * .. Array Arguments ..
  28. * INTEGER IPIV( * )
  29. * COMPLEX A( LDA, * )
  30. * ..
  31. *
  32. *
  33. *> \par Purpose:
  34. * =============
  35. *>
  36. *> \verbatim
  37. *>
  38. *> CHETF2 computes the factorization of a complex Hermitian matrix A
  39. *> using the Bunch-Kaufman diagonal pivoting method:
  40. *>
  41. *> A = U*D*U**H or A = L*D*L**H
  42. *>
  43. *> where U (or L) is a product of permutation and unit upper (lower)
  44. *> triangular matrices, U**H is the conjugate transpose of U, and D is
  45. *> Hermitian and block diagonal with 1-by-1 and 2-by-2 diagonal blocks.
  46. *>
  47. *> This is the unblocked version of the algorithm, calling Level 2 BLAS.
  48. *> \endverbatim
  49. *
  50. * Arguments:
  51. * ==========
  52. *
  53. *> \param[in] UPLO
  54. *> \verbatim
  55. *> UPLO is CHARACTER*1
  56. *> Specifies whether the upper or lower triangular part of the
  57. *> Hermitian matrix A is stored:
  58. *> = 'U': Upper triangular
  59. *> = 'L': Lower triangular
  60. *> \endverbatim
  61. *>
  62. *> \param[in] N
  63. *> \verbatim
  64. *> N is INTEGER
  65. *> The order of the matrix A. N >= 0.
  66. *> \endverbatim
  67. *>
  68. *> \param[in,out] A
  69. *> \verbatim
  70. *> A is COMPLEX array, dimension (LDA,N)
  71. *> On entry, the Hermitian matrix A. If UPLO = 'U', the leading
  72. *> n-by-n upper triangular part of A contains the upper
  73. *> triangular part of the matrix A, and the strictly lower
  74. *> triangular part of A is not referenced. If UPLO = 'L', the
  75. *> leading n-by-n lower triangular part of A contains the lower
  76. *> triangular part of the matrix A, and the strictly upper
  77. *> triangular part of A is not referenced.
  78. *>
  79. *> On exit, the block diagonal matrix D and the multipliers used
  80. *> to obtain the factor U or L (see below for further details).
  81. *> \endverbatim
  82. *>
  83. *> \param[in] LDA
  84. *> \verbatim
  85. *> LDA is INTEGER
  86. *> The leading dimension of the array A. LDA >= max(1,N).
  87. *> \endverbatim
  88. *>
  89. *> \param[out] IPIV
  90. *> \verbatim
  91. *> IPIV is INTEGER array, dimension (N)
  92. *> Details of the interchanges and the block structure of D.
  93. *>
  94. *> If UPLO = 'U':
  95. *> If IPIV(k) > 0, then rows and columns k and IPIV(k) were
  96. *> interchanged and D(k,k) is a 1-by-1 diagonal block.
  97. *>
  98. *> If IPIV(k) = IPIV(k-1) < 0, then rows and columns
  99. *> k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k)
  100. *> is a 2-by-2 diagonal block.
  101. *>
  102. *> If UPLO = 'L':
  103. *> If IPIV(k) > 0, then rows and columns k and IPIV(k) were
  104. *> interchanged and D(k,k) is a 1-by-1 diagonal block.
  105. *>
  106. *> If IPIV(k) = IPIV(k+1) < 0, then rows and columns
  107. *> k+1 and -IPIV(k) were interchanged and D(k:k+1,k:k+1)
  108. *> is a 2-by-2 diagonal block.
  109. *> \endverbatim
  110. *>
  111. *> \param[out] INFO
  112. *> \verbatim
  113. *> INFO is INTEGER
  114. *> = 0: successful exit
  115. *> < 0: if INFO = -k, the k-th argument had an illegal value
  116. *> > 0: if INFO = k, D(k,k) is exactly zero. The factorization
  117. *> has been completed, but the block diagonal matrix D is
  118. *> exactly singular, and division by zero will occur if it
  119. *> is used to solve a system of equations.
  120. *> \endverbatim
  121. *
  122. * Authors:
  123. * ========
  124. *
  125. *> \author Univ. of Tennessee
  126. *> \author Univ. of California Berkeley
  127. *> \author Univ. of Colorado Denver
  128. *> \author NAG Ltd.
  129. *
  130. *> \ingroup complexHEcomputational
  131. *
  132. *> \par Further Details:
  133. * =====================
  134. *>
  135. *> \verbatim
  136. *>
  137. *> 09-29-06 - patch from
  138. *> Bobby Cheng, MathWorks
  139. *>
  140. *> Replace l.210 and l.392
  141. *> IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
  142. *> by
  143. *> IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. SISNAN(ABSAKK) ) THEN
  144. *>
  145. *> 01-01-96 - Based on modifications by
  146. *> J. Lewis, Boeing Computer Services Company
  147. *> A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA
  148. *>
  149. *> If UPLO = 'U', then A = U*D*U**H, where
  150. *> U = P(n)*U(n)* ... *P(k)U(k)* ...,
  151. *> i.e., U is a product of terms P(k)*U(k), where k decreases from n to
  152. *> 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
  153. *> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
  154. *> defined by IPIV(k), and U(k) is a unit upper triangular matrix, such
  155. *> that if the diagonal block D(k) is of order s (s = 1 or 2), then
  156. *>
  157. *> ( I v 0 ) k-s
  158. *> U(k) = ( 0 I 0 ) s
  159. *> ( 0 0 I ) n-k
  160. *> k-s s n-k
  161. *>
  162. *> If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k).
  163. *> If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k),
  164. *> and A(k,k), and v overwrites A(1:k-2,k-1:k).
  165. *>
  166. *> If UPLO = 'L', then A = L*D*L**H, where
  167. *> L = P(1)*L(1)* ... *P(k)*L(k)* ...,
  168. *> i.e., L is a product of terms P(k)*L(k), where k increases from 1 to
  169. *> n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
  170. *> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
  171. *> defined by IPIV(k), and L(k) is a unit lower triangular matrix, such
  172. *> that if the diagonal block D(k) is of order s (s = 1 or 2), then
  173. *>
  174. *> ( I 0 0 ) k-1
  175. *> L(k) = ( 0 I 0 ) s
  176. *> ( 0 v I ) n-k-s+1
  177. *> k-1 s n-k-s+1
  178. *>
  179. *> If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k).
  180. *> If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k),
  181. *> and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1).
  182. *> \endverbatim
  183. *>
  184. * =====================================================================
  185. SUBROUTINE CHETF2( UPLO, N, A, LDA, IPIV, INFO )
  186. *
  187. * -- LAPACK computational routine --
  188. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  189. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  190. *
  191. * .. Scalar Arguments ..
  192. CHARACTER UPLO
  193. INTEGER INFO, LDA, N
  194. * ..
  195. * .. Array Arguments ..
  196. INTEGER IPIV( * )
  197. COMPLEX A( LDA, * )
  198. * ..
  199. *
  200. * =====================================================================
  201. *
  202. * .. Parameters ..
  203. REAL ZERO, ONE
  204. PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
  205. REAL EIGHT, SEVTEN
  206. PARAMETER ( EIGHT = 8.0E+0, SEVTEN = 17.0E+0 )
  207. * ..
  208. * .. Local Scalars ..
  209. LOGICAL UPPER
  210. INTEGER I, IMAX, J, JMAX, K, KK, KP, KSTEP
  211. REAL ABSAKK, ALPHA, COLMAX, D, D11, D22, R1, ROWMAX,
  212. $ TT
  213. COMPLEX D12, D21, T, WK, WKM1, WKP1, ZDUM
  214. * ..
  215. * .. External Functions ..
  216. LOGICAL LSAME, SISNAN
  217. INTEGER ICAMAX
  218. REAL SLAPY2
  219. EXTERNAL LSAME, ICAMAX, SLAPY2, SISNAN
  220. * ..
  221. * .. External Subroutines ..
  222. EXTERNAL CHER, CSSCAL, CSWAP, XERBLA
  223. * ..
  224. * .. Intrinsic Functions ..
  225. INTRINSIC ABS, AIMAG, CMPLX, CONJG, MAX, REAL, SQRT
  226. * ..
  227. * .. Statement Functions ..
  228. REAL CABS1
  229. * ..
  230. * .. Statement Function definitions ..
  231. CABS1( ZDUM ) = ABS( REAL( ZDUM ) ) + ABS( AIMAG( ZDUM ) )
  232. * ..
  233. * .. Executable Statements ..
  234. *
  235. * Test the input parameters.
  236. *
  237. INFO = 0
  238. UPPER = LSAME( UPLO, 'U' )
  239. IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
  240. INFO = -1
  241. ELSE IF( N.LT.0 ) THEN
  242. INFO = -2
  243. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  244. INFO = -4
  245. END IF
  246. IF( INFO.NE.0 ) THEN
  247. CALL XERBLA( 'CHETF2', -INFO )
  248. RETURN
  249. END IF
  250. *
  251. * Initialize ALPHA for use in choosing pivot block size.
  252. *
  253. ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
  254. *
  255. IF( UPPER ) THEN
  256. *
  257. * Factorize A as U*D*U**H using the upper triangle of A
  258. *
  259. * K is the main loop index, decreasing from N to 1 in steps of
  260. * 1 or 2
  261. *
  262. K = N
  263. 10 CONTINUE
  264. *
  265. * If K < 1, exit from loop
  266. *
  267. IF( K.LT.1 )
  268. $ GO TO 90
  269. KSTEP = 1
  270. *
  271. * Determine rows and columns to be interchanged and whether
  272. * a 1-by-1 or 2-by-2 pivot block will be used
  273. *
  274. ABSAKK = ABS( REAL( A( K, K ) ) )
  275. *
  276. * IMAX is the row-index of the largest off-diagonal element in
  277. * column K, and COLMAX is its absolute value.
  278. * Determine both COLMAX and IMAX.
  279. *
  280. IF( K.GT.1 ) THEN
  281. IMAX = ICAMAX( K-1, A( 1, K ), 1 )
  282. COLMAX = CABS1( A( IMAX, K ) )
  283. ELSE
  284. COLMAX = ZERO
  285. END IF
  286. *
  287. IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. SISNAN(ABSAKK) ) THEN
  288. *
  289. * Column K is or underflow, or contains a NaN:
  290. * set INFO and continue
  291. *
  292. IF( INFO.EQ.0 )
  293. $ INFO = K
  294. KP = K
  295. A( K, K ) = REAL( A( K, K ) )
  296. ELSE
  297. IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
  298. *
  299. * no interchange, use 1-by-1 pivot block
  300. *
  301. KP = K
  302. ELSE
  303. *
  304. * JMAX is the column-index of the largest off-diagonal
  305. * element in row IMAX, and ROWMAX is its absolute value
  306. *
  307. JMAX = IMAX + ICAMAX( K-IMAX, A( IMAX, IMAX+1 ), LDA )
  308. ROWMAX = CABS1( A( IMAX, JMAX ) )
  309. IF( IMAX.GT.1 ) THEN
  310. JMAX = ICAMAX( IMAX-1, A( 1, IMAX ), 1 )
  311. ROWMAX = MAX( ROWMAX, CABS1( A( JMAX, IMAX ) ) )
  312. END IF
  313. *
  314. IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
  315. *
  316. * no interchange, use 1-by-1 pivot block
  317. *
  318. KP = K
  319. ELSE IF( ABS( REAL( A( IMAX, IMAX ) ) ).GE.ALPHA*ROWMAX )
  320. $ THEN
  321. *
  322. * interchange rows and columns K and IMAX, use 1-by-1
  323. * pivot block
  324. *
  325. KP = IMAX
  326. ELSE
  327. *
  328. * interchange rows and columns K-1 and IMAX, use 2-by-2
  329. * pivot block
  330. *
  331. KP = IMAX
  332. KSTEP = 2
  333. END IF
  334. END IF
  335. *
  336. KK = K - KSTEP + 1
  337. IF( KP.NE.KK ) THEN
  338. *
  339. * Interchange rows and columns KK and KP in the leading
  340. * submatrix A(1:k,1:k)
  341. *
  342. CALL CSWAP( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 )
  343. DO 20 J = KP + 1, KK - 1
  344. T = CONJG( A( J, KK ) )
  345. A( J, KK ) = CONJG( A( KP, J ) )
  346. A( KP, J ) = T
  347. 20 CONTINUE
  348. A( KP, KK ) = CONJG( A( KP, KK ) )
  349. R1 = REAL( A( KK, KK ) )
  350. A( KK, KK ) = REAL( A( KP, KP ) )
  351. A( KP, KP ) = R1
  352. IF( KSTEP.EQ.2 ) THEN
  353. A( K, K ) = REAL( A( K, K ) )
  354. T = A( K-1, K )
  355. A( K-1, K ) = A( KP, K )
  356. A( KP, K ) = T
  357. END IF
  358. ELSE
  359. A( K, K ) = REAL( A( K, K ) )
  360. IF( KSTEP.EQ.2 )
  361. $ A( K-1, K-1 ) = REAL( A( K-1, K-1 ) )
  362. END IF
  363. *
  364. * Update the leading submatrix
  365. *
  366. IF( KSTEP.EQ.1 ) THEN
  367. *
  368. * 1-by-1 pivot block D(k): column k now holds
  369. *
  370. * W(k) = U(k)*D(k)
  371. *
  372. * where U(k) is the k-th column of U
  373. *
  374. * Perform a rank-1 update of A(1:k-1,1:k-1) as
  375. *
  376. * A := A - U(k)*D(k)*U(k)**H = A - W(k)*1/D(k)*W(k)**H
  377. *
  378. R1 = ONE / REAL( A( K, K ) )
  379. CALL CHER( UPLO, K-1, -R1, A( 1, K ), 1, A, LDA )
  380. *
  381. * Store U(k) in column k
  382. *
  383. CALL CSSCAL( K-1, R1, A( 1, K ), 1 )
  384. ELSE
  385. *
  386. * 2-by-2 pivot block D(k): columns k and k-1 now hold
  387. *
  388. * ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
  389. *
  390. * where U(k) and U(k-1) are the k-th and (k-1)-th columns
  391. * of U
  392. *
  393. * Perform a rank-2 update of A(1:k-2,1:k-2) as
  394. *
  395. * A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**H
  396. * = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**H
  397. *
  398. IF( K.GT.2 ) THEN
  399. *
  400. D = SLAPY2( REAL( A( K-1, K ) ),
  401. $ AIMAG( A( K-1, K ) ) )
  402. D22 = REAL( A( K-1, K-1 ) ) / D
  403. D11 = REAL( A( K, K ) ) / D
  404. TT = ONE / ( D11*D22-ONE )
  405. D12 = A( K-1, K ) / D
  406. D = TT / D
  407. *
  408. DO 40 J = K - 2, 1, -1
  409. WKM1 = D*( D11*A( J, K-1 )-CONJG( D12 )*A( J, K ) )
  410. WK = D*( D22*A( J, K )-D12*A( J, K-1 ) )
  411. DO 30 I = J, 1, -1
  412. A( I, J ) = A( I, J ) - A( I, K )*CONJG( WK ) -
  413. $ A( I, K-1 )*CONJG( WKM1 )
  414. 30 CONTINUE
  415. A( J, K ) = WK
  416. A( J, K-1 ) = WKM1
  417. A( J, J ) = CMPLX( REAL( A( J, J ) ), 0.0E+0 )
  418. 40 CONTINUE
  419. *
  420. END IF
  421. *
  422. END IF
  423. END IF
  424. *
  425. * Store details of the interchanges in IPIV
  426. *
  427. IF( KSTEP.EQ.1 ) THEN
  428. IPIV( K ) = KP
  429. ELSE
  430. IPIV( K ) = -KP
  431. IPIV( K-1 ) = -KP
  432. END IF
  433. *
  434. * Decrease K and return to the start of the main loop
  435. *
  436. K = K - KSTEP
  437. GO TO 10
  438. *
  439. ELSE
  440. *
  441. * Factorize A as L*D*L**H using the lower triangle of A
  442. *
  443. * K is the main loop index, increasing from 1 to N in steps of
  444. * 1 or 2
  445. *
  446. K = 1
  447. 50 CONTINUE
  448. *
  449. * If K > N, exit from loop
  450. *
  451. IF( K.GT.N )
  452. $ GO TO 90
  453. KSTEP = 1
  454. *
  455. * Determine rows and columns to be interchanged and whether
  456. * a 1-by-1 or 2-by-2 pivot block will be used
  457. *
  458. ABSAKK = ABS( REAL( A( K, K ) ) )
  459. *
  460. * IMAX is the row-index of the largest off-diagonal element in
  461. * column K, and COLMAX is its absolute value.
  462. * Determine both COLMAX and IMAX.
  463. *
  464. IF( K.LT.N ) THEN
  465. IMAX = K + ICAMAX( N-K, A( K+1, K ), 1 )
  466. COLMAX = CABS1( A( IMAX, K ) )
  467. ELSE
  468. COLMAX = ZERO
  469. END IF
  470. *
  471. IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. SISNAN(ABSAKK) ) THEN
  472. *
  473. * Column K is zero or underflow, contains a NaN:
  474. * set INFO and continue
  475. *
  476. IF( INFO.EQ.0 )
  477. $ INFO = K
  478. KP = K
  479. A( K, K ) = REAL( A( K, K ) )
  480. ELSE
  481. IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
  482. *
  483. * no interchange, use 1-by-1 pivot block
  484. *
  485. KP = K
  486. ELSE
  487. *
  488. * JMAX is the column-index of the largest off-diagonal
  489. * element in row IMAX, and ROWMAX is its absolute value
  490. *
  491. JMAX = K - 1 + ICAMAX( IMAX-K, A( IMAX, K ), LDA )
  492. ROWMAX = CABS1( A( IMAX, JMAX ) )
  493. IF( IMAX.LT.N ) THEN
  494. JMAX = IMAX + ICAMAX( N-IMAX, A( IMAX+1, IMAX ), 1 )
  495. ROWMAX = MAX( ROWMAX, CABS1( A( JMAX, IMAX ) ) )
  496. END IF
  497. *
  498. IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
  499. *
  500. * no interchange, use 1-by-1 pivot block
  501. *
  502. KP = K
  503. ELSE IF( ABS( REAL( A( IMAX, IMAX ) ) ).GE.ALPHA*ROWMAX )
  504. $ THEN
  505. *
  506. * interchange rows and columns K and IMAX, use 1-by-1
  507. * pivot block
  508. *
  509. KP = IMAX
  510. ELSE
  511. *
  512. * interchange rows and columns K+1 and IMAX, use 2-by-2
  513. * pivot block
  514. *
  515. KP = IMAX
  516. KSTEP = 2
  517. END IF
  518. END IF
  519. *
  520. KK = K + KSTEP - 1
  521. IF( KP.NE.KK ) THEN
  522. *
  523. * Interchange rows and columns KK and KP in the trailing
  524. * submatrix A(k:n,k:n)
  525. *
  526. IF( KP.LT.N )
  527. $ CALL CSWAP( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 )
  528. DO 60 J = KK + 1, KP - 1
  529. T = CONJG( A( J, KK ) )
  530. A( J, KK ) = CONJG( A( KP, J ) )
  531. A( KP, J ) = T
  532. 60 CONTINUE
  533. A( KP, KK ) = CONJG( A( KP, KK ) )
  534. R1 = REAL( A( KK, KK ) )
  535. A( KK, KK ) = REAL( A( KP, KP ) )
  536. A( KP, KP ) = R1
  537. IF( KSTEP.EQ.2 ) THEN
  538. A( K, K ) = REAL( A( K, K ) )
  539. T = A( K+1, K )
  540. A( K+1, K ) = A( KP, K )
  541. A( KP, K ) = T
  542. END IF
  543. ELSE
  544. A( K, K ) = REAL( A( K, K ) )
  545. IF( KSTEP.EQ.2 )
  546. $ A( K+1, K+1 ) = REAL( A( K+1, K+1 ) )
  547. END IF
  548. *
  549. * Update the trailing submatrix
  550. *
  551. IF( KSTEP.EQ.1 ) THEN
  552. *
  553. * 1-by-1 pivot block D(k): column k now holds
  554. *
  555. * W(k) = L(k)*D(k)
  556. *
  557. * where L(k) is the k-th column of L
  558. *
  559. IF( K.LT.N ) THEN
  560. *
  561. * Perform a rank-1 update of A(k+1:n,k+1:n) as
  562. *
  563. * A := A - L(k)*D(k)*L(k)**H = A - W(k)*(1/D(k))*W(k)**H
  564. *
  565. R1 = ONE / REAL( A( K, K ) )
  566. CALL CHER( UPLO, N-K, -R1, A( K+1, K ), 1,
  567. $ A( K+1, K+1 ), LDA )
  568. *
  569. * Store L(k) in column K
  570. *
  571. CALL CSSCAL( N-K, R1, A( K+1, K ), 1 )
  572. END IF
  573. ELSE
  574. *
  575. * 2-by-2 pivot block D(k)
  576. *
  577. IF( K.LT.N-1 ) THEN
  578. *
  579. * Perform a rank-2 update of A(k+2:n,k+2:n) as
  580. *
  581. * A := A - ( L(k) L(k+1) )*D(k)*( L(k) L(k+1) )**H
  582. * = A - ( W(k) W(k+1) )*inv(D(k))*( W(k) W(k+1) )**H
  583. *
  584. * where L(k) and L(k+1) are the k-th and (k+1)-th
  585. * columns of L
  586. *
  587. D = SLAPY2( REAL( A( K+1, K ) ),
  588. $ AIMAG( A( K+1, K ) ) )
  589. D11 = REAL( A( K+1, K+1 ) ) / D
  590. D22 = REAL( A( K, K ) ) / D
  591. TT = ONE / ( D11*D22-ONE )
  592. D21 = A( K+1, K ) / D
  593. D = TT / D
  594. *
  595. DO 80 J = K + 2, N
  596. WK = D*( D11*A( J, K )-D21*A( J, K+1 ) )
  597. WKP1 = D*( D22*A( J, K+1 )-CONJG( D21 )*A( J, K ) )
  598. DO 70 I = J, N
  599. A( I, J ) = A( I, J ) - A( I, K )*CONJG( WK ) -
  600. $ A( I, K+1 )*CONJG( WKP1 )
  601. 70 CONTINUE
  602. A( J, K ) = WK
  603. A( J, K+1 ) = WKP1
  604. A( J, J ) = CMPLX( REAL( A( J, J ) ), 0.0E+0 )
  605. 80 CONTINUE
  606. END IF
  607. END IF
  608. END IF
  609. *
  610. * Store details of the interchanges in IPIV
  611. *
  612. IF( KSTEP.EQ.1 ) THEN
  613. IPIV( K ) = KP
  614. ELSE
  615. IPIV( K ) = -KP
  616. IPIV( K+1 ) = -KP
  617. END IF
  618. *
  619. * Increase K and return to the start of the main loop
  620. *
  621. K = K + KSTEP
  622. GO TO 50
  623. *
  624. END IF
  625. *
  626. 90 CONTINUE
  627. RETURN
  628. *
  629. * End of CHETF2
  630. *
  631. END