001:       SUBROUTINE DPPTRF( 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:       DOUBLE PRECISION   AP( * )
013: *     ..
014: *
015: *  Purpose
016: *  =======
017: *
018: *  DPPTRF computes the Cholesky factorization of a real symmetric
019: *  positive definite matrix A stored in packed format.
020: *
021: *  The factorization has the form
022: *     A = U**T * U,  if UPLO = 'U', or
023: *     A = L  * L**T,  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) DOUBLE PRECISION array, dimension (N*(N+1)/2)
037: *          On entry, the upper or lower triangle of the symmetric 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**T*U or A = L*L**T, 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 symmetric matrix A:
062: *
063: *     a11 a12 a13 a14
064: *         a22 a23 a24
065: *             a33 a34     (aij = 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:       DOUBLE PRECISION   ONE, ZERO
076:       PARAMETER          ( ONE = 1.0D+0, ZERO = 0.0D+0 )
077: *     ..
078: *     .. Local Scalars ..
079:       LOGICAL            UPPER
080:       INTEGER            J, JC, JJ
081:       DOUBLE PRECISION   AJJ
082: *     ..
083: *     .. External Functions ..
084:       LOGICAL            LSAME
085:       DOUBLE PRECISION   DDOT
086:       EXTERNAL           LSAME, DDOT
087: *     ..
088: *     .. External Subroutines ..
089:       EXTERNAL           DSCAL, DSPR, DTPSV, XERBLA
090: *     ..
091: *     .. Intrinsic Functions ..
092:       INTRINSIC          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( 'DPPTRF', -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 DTPSV( 'Upper', 'Transpose', 'Non-unit', J-1, AP,
128:      $                     AP( JC ), 1 )
129: *
130: *           Compute U(J,J) and test for non-positive-definiteness.
131: *
132:             AJJ = AP( JJ ) - DDOT( J-1, AP( JC ), 1, AP( JC ), 1 )
133:             IF( AJJ.LE.ZERO ) THEN
134:                AP( JJ ) = AJJ
135:                GO TO 30
136:             END IF
137:             AP( JJ ) = SQRT( AJJ )
138:    10    CONTINUE
139:       ELSE
140: *
141: *        Compute the Cholesky factorization A = L*L'.
142: *
143:          JJ = 1
144:          DO 20 J = 1, N
145: *
146: *           Compute L(J,J) and test for non-positive-definiteness.
147: *
148:             AJJ = AP( JJ )
149:             IF( AJJ.LE.ZERO ) THEN
150:                AP( JJ ) = AJJ
151:                GO TO 30
152:             END IF
153:             AJJ = SQRT( AJJ )
154:             AP( JJ ) = AJJ
155: *
156: *           Compute elements J+1:N of column J and update the trailing
157: *           submatrix.
158: *
159:             IF( J.LT.N ) THEN
160:                CALL DSCAL( N-J, ONE / AJJ, AP( JJ+1 ), 1 )
161:                CALL DSPR( 'Lower', N-J, -ONE, AP( JJ+1 ), 1,
162:      $                    AP( JJ+N-J+1 ) )
163:                JJ = JJ + N - J + 1
164:             END IF
165:    20    CONTINUE
166:       END IF
167:       GO TO 40
168: *
169:    30 CONTINUE
170:       INFO = J
171: *
172:    40 CONTINUE
173:       RETURN
174: *
175: *     End of DPPTRF
176: *
177:       END
178: