001:       SUBROUTINE CPPTRF( UPLO, N, AP, 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, N
010: *     ..
011: *     .. Array Arguments ..
012:       COMPLEX            AP( * )
013: *     ..
014: *
015: *  Purpose
016: *  =======
017: *
018: *  CPPTRF computes the Cholesky factorization of a complex Hermitian
019: *  positive definite matrix A stored in packed format.
020: *
021: *  The factorization has the form
022: *     A = U**H * U,  if UPLO = 'U', or
023: *     A = L  * L**H,  if UPLO = 'L',
024: *  where U is an upper triangular matrix and L is lower triangular.
025: *
026: *  Arguments
027: *  =========
028: *
029: *  UPLO    (input) CHARACTER*1
030: *          = 'U':  Upper triangle of A is stored;
031: *          = 'L':  Lower triangle of A is stored.
032: *
033: *  N       (input) INTEGER
034: *          The order of the matrix A.  N >= 0.
035: *
036: *  AP      (input/output) COMPLEX array, dimension (N*(N+1)/2)
037: *          On entry, the upper or lower triangle of the Hermitian matrix
038: *          A, packed columnwise in a linear array.  The j-th column of A
039: *          is stored in the array AP as follows:
040: *          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
041: *          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
042: *          See below for further details.
043: *
044: *          On exit, if INFO = 0, the triangular factor U or L from the
045: *          Cholesky factorization A = U**H*U or A = L*L**H, in the same
046: *          storage format as A.
047: *
048: *  INFO    (output) INTEGER
049: *          = 0:  successful exit
050: *          < 0:  if INFO = -i, the i-th argument had an illegal value
051: *          > 0:  if INFO = i, the leading minor of order i is not
052: *                positive definite, and the factorization could not be
053: *                completed.
054: *
055: *  Further Details
056: *  ===============
057: *
058: *  The packed storage scheme is illustrated by the following example
059: *  when N = 4, UPLO = 'U':
060: *
061: *  Two-dimensional storage of the Hermitian matrix A:
062: *
063: *     a11 a12 a13 a14
064: *         a22 a23 a24
065: *             a33 a34     (aij = conjg(aji))
066: *                 a44
067: *
068: *  Packed storage of the upper triangle of A:
069: *
070: *  AP = [ a11, a12, a22, a13, a23, a33, a14, a24, a34, a44 ]
071: *
072: *  =====================================================================
073: *
074: *     .. Parameters ..
075:       REAL               ZERO, ONE
076:       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
077: *     ..
078: *     .. Local Scalars ..
079:       LOGICAL            UPPER
080:       INTEGER            J, JC, JJ
081:       REAL               AJJ
082: *     ..
083: *     .. External Functions ..
084:       LOGICAL            LSAME
085:       COMPLEX            CDOTC
086:       EXTERNAL           LSAME, CDOTC
087: *     ..
088: *     .. External Subroutines ..
089:       EXTERNAL           CHPR, CSSCAL, CTPSV, XERBLA
090: *     ..
091: *     .. Intrinsic Functions ..
092:       INTRINSIC          REAL, SQRT
093: *     ..
094: *     .. Executable Statements ..
095: *
096: *     Test the input parameters.
097: *
098:       INFO = 0
099:       UPPER = LSAME( UPLO, 'U' )
100:       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
101:          INFO = -1
102:       ELSE IF( N.LT.0 ) THEN
103:          INFO = -2
104:       END IF
105:       IF( INFO.NE.0 ) THEN
106:          CALL XERBLA( 'CPPTRF', -INFO )
107:          RETURN
108:       END IF
109: *
110: *     Quick return if possible
111: *
112:       IF( N.EQ.0 )
113:      $   RETURN
114: *
115:       IF( UPPER ) THEN
116: *
117: *        Compute the Cholesky factorization A = U'*U.
118: *
119:          JJ = 0
120:          DO 10 J = 1, N
121:             JC = JJ + 1
122:             JJ = JJ + J
123: *
124: *           Compute elements 1:J-1 of column J.
125: *
126:             IF( J.GT.1 )
127:      $         CALL CTPSV( 'Upper', 'Conjugate transpose', 'Non-unit',
128:      $                     J-1, AP, AP( JC ), 1 )
129: *
130: *           Compute U(J,J) and test for non-positive-definiteness.
131: *
132:             AJJ = REAL( AP( JJ ) ) - CDOTC( J-1, AP( JC ), 1, AP( JC ),
133:      $            1 )
134:             IF( AJJ.LE.ZERO ) THEN
135:                AP( JJ ) = AJJ
136:                GO TO 30
137:             END IF
138:             AP( JJ ) = SQRT( AJJ )
139:    10    CONTINUE
140:       ELSE
141: *
142: *        Compute the Cholesky factorization A = L*L'.
143: *
144:          JJ = 1
145:          DO 20 J = 1, N
146: *
147: *           Compute L(J,J) and test for non-positive-definiteness.
148: *
149:             AJJ = REAL( AP( JJ ) )
150:             IF( AJJ.LE.ZERO ) THEN
151:                AP( JJ ) = AJJ
152:                GO TO 30
153:             END IF
154:             AJJ = SQRT( AJJ )
155:             AP( JJ ) = AJJ
156: *
157: *           Compute elements J+1:N of column J and update the trailing
158: *           submatrix.
159: *
160:             IF( J.LT.N ) THEN
161:                CALL CSSCAL( N-J, ONE / AJJ, AP( JJ+1 ), 1 )
162:                CALL CHPR( 'Lower', N-J, -ONE, AP( JJ+1 ), 1,
163:      $                    AP( JJ+N-J+1 ) )
164:                JJ = JJ + N - J + 1
165:             END IF
166:    20    CONTINUE
167:       END IF
168:       GO TO 40
169: *
170:    30 CONTINUE
171:       INFO = J
172: *
173:    40 CONTINUE
174:       RETURN
175: *
176: *     End of CPPTRF
177: *
178:       END
179: