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