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