001:       SUBROUTINE CLAHEF( UPLO, N, NB, KB, A, LDA, IPIV, W, LDW, INFO )
002: *
003: *  -- LAPACK routine (version 3.2) --
004: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
005: *     November 2006
006: *
007: *     .. Scalar Arguments ..
008:       CHARACTER          UPLO
009:       INTEGER            INFO, KB, LDA, LDW, N, NB
010: *     ..
011: *     .. Array Arguments ..
012:       INTEGER            IPIV( * )
013:       COMPLEX            A( LDA, * ), W( LDW, * )
014: *     ..
015: *
016: *  Purpose
017: *  =======
018: *
019: *  CLAHEF computes a partial factorization of a complex Hermitian
020: *  matrix A using the Bunch-Kaufman diagonal pivoting method. The
021: *  partial factorization has the form:
022: *
023: *  A  =  ( I  U12 ) ( A11  0  ) (  I    0   )  if UPLO = 'U', or:
024: *        ( 0  U22 ) (  0   D  ) ( U12' U22' )
025: *
026: *  A  =  ( L11  0 ) (  D   0  ) ( L11' L21' )  if UPLO = 'L'
027: *        ( L21  I ) (  0  A22 ) (  0    I   )
028: *
029: *  where the order of D is at most NB. The actual order is returned in
030: *  the argument KB, and is either NB or NB-1, or N if N <= NB.
031: *  Note that U' denotes the conjugate transpose of U.
032: *
033: *  CLAHEF is an auxiliary routine called by CHETRF. It uses blocked code
034: *  (calling Level 3 BLAS) to update the submatrix A11 (if UPLO = 'U') or
035: *  A22 (if UPLO = 'L').
036: *
037: *  Arguments
038: *  =========
039: *
040: *  UPLO    (input) CHARACTER*1
041: *          Specifies whether the upper or lower triangular part of the
042: *          Hermitian matrix A is stored:
043: *          = 'U':  Upper triangular
044: *          = 'L':  Lower triangular
045: *
046: *  N       (input) INTEGER
047: *          The order of the matrix A.  N >= 0.
048: *
049: *  NB      (input) INTEGER
050: *          The maximum number of columns of the matrix A that should be
051: *          factored.  NB should be at least 2 to allow for 2-by-2 pivot
052: *          blocks.
053: *
054: *  KB      (output) INTEGER
055: *          The number of columns of A that were actually factored.
056: *          KB is either NB-1 or NB, or N if N <= NB.
057: *
058: *  A       (input/output) COMPLEX array, dimension (LDA,N)
059: *          On entry, the Hermitian matrix A.  If UPLO = 'U', the leading
060: *          n-by-n upper triangular part of A contains the upper
061: *          triangular part of the matrix A, and the strictly lower
062: *          triangular part of A is not referenced.  If UPLO = 'L', the
063: *          leading n-by-n lower triangular part of A contains the lower
064: *          triangular part of the matrix A, and the strictly upper
065: *          triangular part of A is not referenced.
066: *          On exit, A contains details of the partial factorization.
067: *
068: *  LDA     (input) INTEGER
069: *          The leading dimension of the array A.  LDA >= max(1,N).
070: *
071: *  IPIV    (output) INTEGER array, dimension (N)
072: *          Details of the interchanges and the block structure of D.
073: *          If UPLO = 'U', only the last KB elements of IPIV are set;
074: *          if UPLO = 'L', only the first KB elements are set.
075: *
076: *          If IPIV(k) > 0, then rows and columns k and IPIV(k) were
077: *          interchanged and D(k,k) is a 1-by-1 diagonal block.
078: *          If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and
079: *          columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k)
080: *          is a 2-by-2 diagonal block.  If UPLO = 'L' and IPIV(k) =
081: *          IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were
082: *          interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block.
083: *
084: *  W       (workspace) COMPLEX array, dimension (LDW,NB)
085: *
086: *  LDW     (input) INTEGER
087: *          The leading dimension of the array W.  LDW >= max(1,N).
088: *
089: *  INFO    (output) INTEGER
090: *          = 0: successful exit
091: *          > 0: if INFO = k, D(k,k) is exactly zero.  The factorization
092: *               has been completed, but the block diagonal matrix D is
093: *               exactly singular.
094: *
095: *  =====================================================================
096: *
097: *     .. Parameters ..
098:       REAL               ZERO, ONE
099:       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
100:       COMPLEX            CONE
101:       PARAMETER          ( CONE = ( 1.0E+0, 0.0E+0 ) )
102:       REAL               EIGHT, SEVTEN
103:       PARAMETER          ( EIGHT = 8.0E+0, SEVTEN = 17.0E+0 )
104: *     ..
105: *     .. Local Scalars ..
106:       INTEGER            IMAX, J, JB, JJ, JMAX, JP, K, KK, KKW, KP,
107:      $                   KSTEP, KW
108:       REAL               ABSAKK, ALPHA, COLMAX, R1, ROWMAX, T
109:       COMPLEX            D11, D21, D22, Z
110: *     ..
111: *     .. External Functions ..
112:       LOGICAL            LSAME
113:       INTEGER            ICAMAX
114:       EXTERNAL           LSAME, ICAMAX
115: *     ..
116: *     .. External Subroutines ..
117:       EXTERNAL           CCOPY, CGEMM, CGEMV, CLACGV, CSSCAL, CSWAP
118: *     ..
119: *     .. Intrinsic Functions ..
120:       INTRINSIC          ABS, AIMAG, CONJG, MAX, MIN, REAL, SQRT
121: *     ..
122: *     .. Statement Functions ..
123:       REAL               CABS1
124: *     ..
125: *     .. Statement Function definitions ..
126:       CABS1( Z ) = ABS( REAL( Z ) ) + ABS( AIMAG( Z ) )
127: *     ..
128: *     .. Executable Statements ..
129: *
130:       INFO = 0
131: *
132: *     Initialize ALPHA for use in choosing pivot block size.
133: *
134:       ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
135: *
136:       IF( LSAME( UPLO, 'U' ) ) THEN
137: *
138: *        Factorize the trailing columns of A using the upper triangle
139: *        of A and working backwards, and compute the matrix W = U12*D
140: *        for use in updating A11 (note that conjg(W) is actually stored)
141: *
142: *        K is the main loop index, decreasing from N in steps of 1 or 2
143: *
144: *        KW is the column of W which corresponds to column K of A
145: *
146:          K = N
147:    10    CONTINUE
148:          KW = NB + K - N
149: *
150: *        Exit from loop
151: *
152:          IF( ( K.LE.N-NB+1 .AND. NB.LT.N ) .OR. K.LT.1 )
153:      $      GO TO 30
154: *
155: *        Copy column K of A to column KW of W and update it
156: *
157:          CALL CCOPY( K-1, A( 1, K ), 1, W( 1, KW ), 1 )
158:          W( K, KW ) = REAL( A( K, K ) )
159:          IF( K.LT.N ) THEN
160:             CALL CGEMV( 'No transpose', K, N-K, -CONE, A( 1, K+1 ), LDA,
161:      $                  W( K, KW+1 ), LDW, CONE, W( 1, KW ), 1 )
162:             W( K, KW ) = REAL( W( K, KW ) )
163:          END IF
164: *
165:          KSTEP = 1
166: *
167: *        Determine rows and columns to be interchanged and whether
168: *        a 1-by-1 or 2-by-2 pivot block will be used
169: *
170:          ABSAKK = ABS( REAL( W( K, KW ) ) )
171: *
172: *        IMAX is the row-index of the largest off-diagonal element in
173: *        column K, and COLMAX is its absolute value
174: *
175:          IF( K.GT.1 ) THEN
176:             IMAX = ICAMAX( K-1, W( 1, KW ), 1 )
177:             COLMAX = CABS1( W( IMAX, KW ) )
178:          ELSE
179:             COLMAX = ZERO
180:          END IF
181: *
182:          IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
183: *
184: *           Column K is zero: set INFO and continue
185: *
186:             IF( INFO.EQ.0 )
187:      $         INFO = K
188:             KP = K
189:             A( K, K ) = REAL( A( K, K ) )
190:          ELSE
191:             IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
192: *
193: *              no interchange, use 1-by-1 pivot block
194: *
195:                KP = K
196:             ELSE
197: *
198: *              Copy column IMAX to column KW-1 of W and update it
199: *
200:                CALL CCOPY( IMAX-1, A( 1, IMAX ), 1, W( 1, KW-1 ), 1 )
201:                W( IMAX, KW-1 ) = REAL( A( IMAX, IMAX ) )
202:                CALL CCOPY( K-IMAX, A( IMAX, IMAX+1 ), LDA,
203:      $                     W( IMAX+1, KW-1 ), 1 )
204:                CALL CLACGV( K-IMAX, W( IMAX+1, KW-1 ), 1 )
205:                IF( K.LT.N ) THEN
206:                   CALL CGEMV( 'No transpose', K, N-K, -CONE,
207:      $                        A( 1, K+1 ), LDA, W( IMAX, KW+1 ), LDW,
208:      $                        CONE, W( 1, KW-1 ), 1 )
209:                   W( IMAX, KW-1 ) = REAL( W( IMAX, KW-1 ) )
210:                END IF
211: *
212: *              JMAX is the column-index of the largest off-diagonal
213: *              element in row IMAX, and ROWMAX is its absolute value
214: *
215:                JMAX = IMAX + ICAMAX( K-IMAX, W( IMAX+1, KW-1 ), 1 )
216:                ROWMAX = CABS1( W( JMAX, KW-1 ) )
217:                IF( IMAX.GT.1 ) THEN
218:                   JMAX = ICAMAX( IMAX-1, W( 1, KW-1 ), 1 )
219:                   ROWMAX = MAX( ROWMAX, CABS1( W( JMAX, KW-1 ) ) )
220:                END IF
221: *
222:                IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
223: *
224: *                 no interchange, use 1-by-1 pivot block
225: *
226:                   KP = K
227:                ELSE IF( ABS( REAL( W( IMAX, KW-1 ) ) ).GE.ALPHA*ROWMAX )
228:      $                   THEN
229: *
230: *                 interchange rows and columns K and IMAX, use 1-by-1
231: *                 pivot block
232: *
233:                   KP = IMAX
234: *
235: *                 copy column KW-1 of W to column KW
236: *
237:                   CALL CCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 )
238:                ELSE
239: *
240: *                 interchange rows and columns K-1 and IMAX, use 2-by-2
241: *                 pivot block
242: *
243:                   KP = IMAX
244:                   KSTEP = 2
245:                END IF
246:             END IF
247: *
248:             KK = K - KSTEP + 1
249:             KKW = NB + KK - N
250: *
251: *           Updated column KP is already stored in column KKW of W
252: *
253:             IF( KP.NE.KK ) THEN
254: *
255: *              Copy non-updated column KK to column KP
256: *
257:                A( KP, KP ) = REAL( A( KK, KK ) )
258:                CALL CCOPY( KK-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ),
259:      $                     LDA )
260:                CALL CLACGV( KK-1-KP, A( KP, KP+1 ), LDA )
261:                CALL CCOPY( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 )
262: *
263: *              Interchange rows KK and KP in last KK columns of A and W
264: *
265:                IF( KK.LT.N )
266:      $            CALL CSWAP( N-KK, A( KK, KK+1 ), LDA, A( KP, KK+1 ),
267:      $                        LDA )
268:                CALL CSWAP( N-KK+1, W( KK, KKW ), LDW, W( KP, KKW ),
269:      $                     LDW )
270:             END IF
271: *
272:             IF( KSTEP.EQ.1 ) THEN
273: *
274: *              1-by-1 pivot block D(k): column KW of W now holds
275: *
276: *              W(k) = U(k)*D(k)
277: *
278: *              where U(k) is the k-th column of U
279: *
280: *              Store U(k) in column k of A
281: *
282:                CALL CCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 )
283:                R1 = ONE / REAL( A( K, K ) )
284:                CALL CSSCAL( K-1, R1, A( 1, K ), 1 )
285: *
286: *              Conjugate W(k)
287: *
288:                CALL CLACGV( K-1, W( 1, KW ), 1 )
289:             ELSE
290: *
291: *              2-by-2 pivot block D(k): columns KW and KW-1 of W now
292: *              hold
293: *
294: *              ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
295: *
296: *              where U(k) and U(k-1) are the k-th and (k-1)-th columns
297: *              of U
298: *
299:                IF( K.GT.2 ) THEN
300: *
301: *                 Store U(k) and U(k-1) in columns k and k-1 of A
302: *
303:                   D21 = W( K-1, KW )
304:                   D11 = W( K, KW ) / CONJG( D21 )
305:                   D22 = W( K-1, KW-1 ) / D21
306:                   T = ONE / ( REAL( D11*D22 )-ONE )
307:                   D21 = T / D21
308:                   DO 20 J = 1, K - 2
309:                      A( J, K-1 ) = D21*( D11*W( J, KW-1 )-W( J, KW ) )
310:                      A( J, K ) = CONJG( D21 )*
311:      $                           ( D22*W( J, KW )-W( J, KW-1 ) )
312:    20             CONTINUE
313:                END IF
314: *
315: *              Copy D(k) to A
316: *
317:                A( K-1, K-1 ) = W( K-1, KW-1 )
318:                A( K-1, K ) = W( K-1, KW )
319:                A( K, K ) = W( K, KW )
320: *
321: *              Conjugate W(k) and W(k-1)
322: *
323:                CALL CLACGV( K-1, W( 1, KW ), 1 )
324:                CALL CLACGV( K-2, W( 1, KW-1 ), 1 )
325:             END IF
326:          END IF
327: *
328: *        Store details of the interchanges in IPIV
329: *
330:          IF( KSTEP.EQ.1 ) THEN
331:             IPIV( K ) = KP
332:          ELSE
333:             IPIV( K ) = -KP
334:             IPIV( K-1 ) = -KP
335:          END IF
336: *
337: *        Decrease K and return to the start of the main loop
338: *
339:          K = K - KSTEP
340:          GO TO 10
341: *
342:    30    CONTINUE
343: *
344: *        Update the upper triangle of A11 (= A(1:k,1:k)) as
345: *
346: *        A11 := A11 - U12*D*U12' = A11 - U12*W'
347: *
348: *        computing blocks of NB columns at a time (note that conjg(W) is
349: *        actually stored)
350: *
351:          DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB
352:             JB = MIN( NB, K-J+1 )
353: *
354: *           Update the upper triangle of the diagonal block
355: *
356:             DO 40 JJ = J, J + JB - 1
357:                A( JJ, JJ ) = REAL( A( JJ, JJ ) )
358:                CALL CGEMV( 'No transpose', JJ-J+1, N-K, -CONE,
359:      $                     A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, CONE,
360:      $                     A( J, JJ ), 1 )
361:                A( JJ, JJ ) = REAL( A( JJ, JJ ) )
362:    40       CONTINUE
363: *
364: *           Update the rectangular superdiagonal block
365: *
366:             CALL CGEMM( 'No transpose', 'Transpose', J-1, JB, N-K,
367:      $                  -CONE, A( 1, K+1 ), LDA, W( J, KW+1 ), LDW,
368:      $                  CONE, A( 1, J ), LDA )
369:    50    CONTINUE
370: *
371: *        Put U12 in standard form by partially undoing the interchanges
372: *        in columns k+1:n
373: *
374:          J = K + 1
375:    60    CONTINUE
376:          JJ = J
377:          JP = IPIV( J )
378:          IF( JP.LT.0 ) THEN
379:             JP = -JP
380:             J = J + 1
381:          END IF
382:          J = J + 1
383:          IF( JP.NE.JJ .AND. J.LE.N )
384:      $      CALL CSWAP( N-J+1, A( JP, J ), LDA, A( JJ, J ), LDA )
385:          IF( J.LE.N )
386:      $      GO TO 60
387: *
388: *        Set KB to the number of columns factorized
389: *
390:          KB = N - K
391: *
392:       ELSE
393: *
394: *        Factorize the leading columns of A using the lower triangle
395: *        of A and working forwards, and compute the matrix W = L21*D
396: *        for use in updating A22 (note that conjg(W) is actually stored)
397: *
398: *        K is the main loop index, increasing from 1 in steps of 1 or 2
399: *
400:          K = 1
401:    70    CONTINUE
402: *
403: *        Exit from loop
404: *
405:          IF( ( K.GE.NB .AND. NB.LT.N ) .OR. K.GT.N )
406:      $      GO TO 90
407: *
408: *        Copy column K of A to column K of W and update it
409: *
410:          W( K, K ) = REAL( A( K, K ) )
411:          IF( K.LT.N )
412:      $      CALL CCOPY( N-K, A( K+1, K ), 1, W( K+1, K ), 1 )
413:          CALL CGEMV( 'No transpose', N-K+1, K-1, -CONE, A( K, 1 ), LDA,
414:      $               W( K, 1 ), LDW, CONE, W( K, K ), 1 )
415:          W( K, K ) = REAL( W( K, K ) )
416: *
417:          KSTEP = 1
418: *
419: *        Determine rows and columns to be interchanged and whether
420: *        a 1-by-1 or 2-by-2 pivot block will be used
421: *
422:          ABSAKK = ABS( REAL( W( K, K ) ) )
423: *
424: *        IMAX is the row-index of the largest off-diagonal element in
425: *        column K, and COLMAX is its absolute value
426: *
427:          IF( K.LT.N ) THEN
428:             IMAX = K + ICAMAX( N-K, W( K+1, K ), 1 )
429:             COLMAX = CABS1( W( IMAX, K ) )
430:          ELSE
431:             COLMAX = ZERO
432:          END IF
433: *
434:          IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
435: *
436: *           Column K is zero: set INFO and continue
437: *
438:             IF( INFO.EQ.0 )
439:      $         INFO = K
440:             KP = K
441:             A( K, K ) = REAL( A( K, K ) )
442:          ELSE
443:             IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
444: *
445: *              no interchange, use 1-by-1 pivot block
446: *
447:                KP = K
448:             ELSE
449: *
450: *              Copy column IMAX to column K+1 of W and update it
451: *
452:                CALL CCOPY( IMAX-K, A( IMAX, K ), LDA, W( K, K+1 ), 1 )
453:                CALL CLACGV( IMAX-K, W( K, K+1 ), 1 )
454:                W( IMAX, K+1 ) = REAL( A( IMAX, IMAX ) )
455:                IF( IMAX.LT.N )
456:      $            CALL CCOPY( N-IMAX, A( IMAX+1, IMAX ), 1,
457:      $                        W( IMAX+1, K+1 ), 1 )
458:                CALL CGEMV( 'No transpose', N-K+1, K-1, -CONE, A( K, 1 ),
459:      $                     LDA, W( IMAX, 1 ), LDW, CONE, W( K, K+1 ),
460:      $                     1 )
461:                W( IMAX, K+1 ) = REAL( W( IMAX, K+1 ) )
462: *
463: *              JMAX is the column-index of the largest off-diagonal
464: *              element in row IMAX, and ROWMAX is its absolute value
465: *
466:                JMAX = K - 1 + ICAMAX( IMAX-K, W( K, K+1 ), 1 )
467:                ROWMAX = CABS1( W( JMAX, K+1 ) )
468:                IF( IMAX.LT.N ) THEN
469:                   JMAX = IMAX + ICAMAX( N-IMAX, W( IMAX+1, K+1 ), 1 )
470:                   ROWMAX = MAX( ROWMAX, CABS1( W( JMAX, K+1 ) ) )
471:                END IF
472: *
473:                IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
474: *
475: *                 no interchange, use 1-by-1 pivot block
476: *
477:                   KP = K
478:                ELSE IF( ABS( REAL( W( IMAX, K+1 ) ) ).GE.ALPHA*ROWMAX )
479:      $                   THEN
480: *
481: *                 interchange rows and columns K and IMAX, use 1-by-1
482: *                 pivot block
483: *
484:                   KP = IMAX
485: *
486: *                 copy column K+1 of W to column K
487: *
488:                   CALL CCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 )
489:                ELSE
490: *
491: *                 interchange rows and columns K+1 and IMAX, use 2-by-2
492: *                 pivot block
493: *
494:                   KP = IMAX
495:                   KSTEP = 2
496:                END IF
497:             END IF
498: *
499:             KK = K + KSTEP - 1
500: *
501: *           Updated column KP is already stored in column KK of W
502: *
503:             IF( KP.NE.KK ) THEN
504: *
505: *              Copy non-updated column KK to column KP
506: *
507:                A( KP, KP ) = REAL( A( KK, KK ) )
508:                CALL CCOPY( KP-KK-1, A( KK+1, KK ), 1, A( KP, KK+1 ),
509:      $                     LDA )
510:                CALL CLACGV( KP-KK-1, A( KP, KK+1 ), LDA )
511:                IF( KP.LT.N )
512:      $            CALL CCOPY( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 )
513: *
514: *              Interchange rows KK and KP in first KK columns of A and W
515: *
516:                CALL CSWAP( KK-1, A( KK, 1 ), LDA, A( KP, 1 ), LDA )
517:                CALL CSWAP( KK, W( KK, 1 ), LDW, W( KP, 1 ), LDW )
518:             END IF
519: *
520:             IF( KSTEP.EQ.1 ) THEN
521: *
522: *              1-by-1 pivot block D(k): column k of W now holds
523: *
524: *              W(k) = L(k)*D(k)
525: *
526: *              where L(k) is the k-th column of L
527: *
528: *              Store L(k) in column k of A
529: *
530:                CALL CCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 )
531:                IF( K.LT.N ) THEN
532:                   R1 = ONE / REAL( A( K, K ) )
533:                   CALL CSSCAL( N-K, R1, A( K+1, K ), 1 )
534: *
535: *                 Conjugate W(k)
536: *
537:                   CALL CLACGV( N-K, W( K+1, K ), 1 )
538:                END IF
539:             ELSE
540: *
541: *              2-by-2 pivot block D(k): columns k and k+1 of W now hold
542: *
543: *              ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k)
544: *
545: *              where L(k) and L(k+1) are the k-th and (k+1)-th columns
546: *              of L
547: *
548:                IF( K.LT.N-1 ) THEN
549: *
550: *                 Store L(k) and L(k+1) in columns k and k+1 of A
551: *
552:                   D21 = W( K+1, K )
553:                   D11 = W( K+1, K+1 ) / D21
554:                   D22 = W( K, K ) / CONJG( D21 )
555:                   T = ONE / ( REAL( D11*D22 )-ONE )
556:                   D21 = T / D21
557:                   DO 80 J = K + 2, N
558:                      A( J, K ) = CONJG( D21 )*
559:      $                           ( D11*W( J, K )-W( J, K+1 ) )
560:                      A( J, K+1 ) = D21*( D22*W( J, K+1 )-W( J, K ) )
561:    80             CONTINUE
562:                END IF
563: *
564: *              Copy D(k) to A
565: *
566:                A( K, K ) = W( K, K )
567:                A( K+1, K ) = W( K+1, K )
568:                A( K+1, K+1 ) = W( K+1, K+1 )
569: *
570: *              Conjugate W(k) and W(k+1)
571: *
572:                CALL CLACGV( N-K, W( K+1, K ), 1 )
573:                CALL CLACGV( N-K-1, W( K+2, K+1 ), 1 )
574:             END IF
575:          END IF
576: *
577: *        Store details of the interchanges in IPIV
578: *
579:          IF( KSTEP.EQ.1 ) THEN
580:             IPIV( K ) = KP
581:          ELSE
582:             IPIV( K ) = -KP
583:             IPIV( K+1 ) = -KP
584:          END IF
585: *
586: *        Increase K and return to the start of the main loop
587: *
588:          K = K + KSTEP
589:          GO TO 70
590: *
591:    90    CONTINUE
592: *
593: *        Update the lower triangle of A22 (= A(k:n,k:n)) as
594: *
595: *        A22 := A22 - L21*D*L21' = A22 - L21*W'
596: *
597: *        computing blocks of NB columns at a time (note that conjg(W) is
598: *        actually stored)
599: *
600:          DO 110 J = K, N, NB
601:             JB = MIN( NB, N-J+1 )
602: *
603: *           Update the lower triangle of the diagonal block
604: *
605:             DO 100 JJ = J, J + JB - 1
606:                A( JJ, JJ ) = REAL( A( JJ, JJ ) )
607:                CALL CGEMV( 'No transpose', J+JB-JJ, K-1, -CONE,
608:      $                     A( JJ, 1 ), LDA, W( JJ, 1 ), LDW, CONE,
609:      $                     A( JJ, JJ ), 1 )
610:                A( JJ, JJ ) = REAL( A( JJ, JJ ) )
611:   100       CONTINUE
612: *
613: *           Update the rectangular subdiagonal block
614: *
615:             IF( J+JB.LE.N )
616:      $         CALL CGEMM( 'No transpose', 'Transpose', N-J-JB+1, JB,
617:      $                     K-1, -CONE, A( J+JB, 1 ), LDA, W( J, 1 ),
618:      $                     LDW, CONE, A( J+JB, J ), LDA )
619:   110    CONTINUE
620: *
621: *        Put L21 in standard form by partially undoing the interchanges
622: *        in columns 1:k-1
623: *
624:          J = K - 1
625:   120    CONTINUE
626:          JJ = J
627:          JP = IPIV( J )
628:          IF( JP.LT.0 ) THEN
629:             JP = -JP
630:             J = J - 1
631:          END IF
632:          J = J - 1
633:          IF( JP.NE.JJ .AND. J.GE.1 )
634:      $      CALL CSWAP( J, A( JP, 1 ), LDA, A( JJ, 1 ), LDA )
635:          IF( J.GE.1 )
636:      $      GO TO 120
637: *
638: *        Set KB to the number of columns factorized
639: *
640:          KB = K - 1
641: *
642:       END IF
643:       RETURN
644: *
645: *     End of CLAHEF
646: *
647:       END
648: