001:       SUBROUTINE SPPTRF( 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:       REAL               AP( * )
014: *     ..
015: *
016: *  Purpose
017: *  =======
018: *
019: *  SPPTRF computes the Cholesky factorization of a real symmetric
020: *  positive definite matrix A stored in packed format.
021: *
022: *  The factorization has the form
023: *     A = U**T * U,  if UPLO = 'U', or
024: *     A = L  * L**T,  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) REAL array, dimension (N*(N+1)/2)
038: *          On entry, the upper or lower triangle of the symmetric 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**T*U or A = L*L**T, 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 symmetric matrix A:
063: *
064: *     a11 a12 a13 a14
065: *         a22 a23 a24
066: *             a33 a34     (aij = 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:       REAL               ONE, ZERO
077:       PARAMETER          ( ONE = 1.0E+0, ZERO = 0.0E+0 )
078: *     ..
079: *     .. Local Scalars ..
080:       LOGICAL            UPPER
081:       INTEGER            J, JC, JJ
082:       REAL               AJJ
083: *     ..
084: *     .. External Functions ..
085:       LOGICAL            LSAME
086:       REAL               SDOT
087:       EXTERNAL           LSAME, SDOT
088: *     ..
089: *     .. External Subroutines ..
090:       EXTERNAL           SSCAL, SSPR, STPSV, XERBLA
091: *     ..
092: *     .. Intrinsic Functions ..
093:       INTRINSIC          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( 'SPPTRF', -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 STPSV( 'Upper', 'Transpose', 'Non-unit', J-1, AP,
129:      $                     AP( JC ), 1 )
130: *
131: *           Compute U(J,J) and test for non-positive-definiteness.
132: *
133:             AJJ = AP( JJ ) - SDOT( J-1, AP( JC ), 1, AP( JC ), 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 = 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 SSCAL( N-J, ONE / AJJ, AP( JJ+1 ), 1 )
162:                CALL SSPR( '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 SPPTRF
177: *
178:       END
179: