001:       SUBROUTINE SSPR(UPLO,N,ALPHA,X,INCX,AP)
002: *     .. Scalar Arguments ..
003:       REAL ALPHA
004:       INTEGER INCX,N
005:       CHARACTER UPLO
006: *     ..
007: *     .. Array Arguments ..
008:       REAL AP(*),X(*)
009: *     ..
010: *
011: *  Purpose
012: *  =======
013: *
014: *  SSPR    performs the symmetric rank 1 operation
015: *
016: *     A := alpha*x*x' + A,
017: *
018: *  where alpha is a real scalar, x is an n element vector and A is an
019: *  n by n symmetric matrix, supplied in packed form.
020: *
021: *  Arguments
022: *  ==========
023: *
024: *  UPLO   - CHARACTER*1.
025: *           On entry, UPLO specifies whether the upper or lower
026: *           triangular part of the matrix A is supplied in the packed
027: *           array AP as follows:
028: *
029: *              UPLO = 'U' or 'u'   The upper triangular part of A is
030: *                                  supplied in AP.
031: *
032: *              UPLO = 'L' or 'l'   The lower triangular part of A is
033: *                                  supplied in AP.
034: *
035: *           Unchanged on exit.
036: *
037: *  N      - INTEGER.
038: *           On entry, N specifies the order of the matrix A.
039: *           N must be at least zero.
040: *           Unchanged on exit.
041: *
042: *  ALPHA  - REAL            .
043: *           On entry, ALPHA specifies the scalar alpha.
044: *           Unchanged on exit.
045: *
046: *  X      - REAL             array of dimension at least
047: *           ( 1 + ( n - 1 )*abs( INCX ) ).
048: *           Before entry, the incremented array X must contain the n
049: *           element vector x.
050: *           Unchanged on exit.
051: *
052: *  INCX   - INTEGER.
053: *           On entry, INCX specifies the increment for the elements of
054: *           X. INCX must not be zero.
055: *           Unchanged on exit.
056: *
057: *  AP     - REAL             array of DIMENSION at least
058: *           ( ( n*( n + 1 ) )/2 ).
059: *           Before entry with  UPLO = 'U' or 'u', the array AP must
060: *           contain the upper triangular part of the symmetric matrix
061: *           packed sequentially, column by column, so that AP( 1 )
062: *           contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 1, 2 )
063: *           and a( 2, 2 ) respectively, and so on. On exit, the array
064: *           AP is overwritten by the upper triangular part of the
065: *           updated matrix.
066: *           Before entry with UPLO = 'L' or 'l', the array AP must
067: *           contain the lower triangular part of the symmetric matrix
068: *           packed sequentially, column by column, so that AP( 1 )
069: *           contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 2, 1 )
070: *           and a( 3, 1 ) respectively, and so on. On exit, the array
071: *           AP is overwritten by the lower triangular part of the
072: *           updated matrix.
073: *
074: *  Further Details
075: *  ===============
076: *
077: *  Level 2 Blas routine.
078: *
079: *  -- Written on 22-October-1986.
080: *     Jack Dongarra, Argonne National Lab.
081: *     Jeremy Du Croz, Nag Central Office.
082: *     Sven Hammarling, Nag Central Office.
083: *     Richard Hanson, Sandia National Labs.
084: *
085: *  =====================================================================
086: *
087: *     .. Parameters ..
088:       REAL ZERO
089:       PARAMETER (ZERO=0.0E+0)
090: *     ..
091: *     .. Local Scalars ..
092:       REAL TEMP
093:       INTEGER I,INFO,IX,J,JX,K,KK,KX
094: *     ..
095: *     .. External Functions ..
096:       LOGICAL LSAME
097:       EXTERNAL LSAME
098: *     ..
099: *     .. External Subroutines ..
100:       EXTERNAL XERBLA
101: *     ..
102: *
103: *     Test the input parameters.
104: *
105:       INFO = 0
106:       IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN
107:           INFO = 1
108:       ELSE IF (N.LT.0) THEN
109:           INFO = 2
110:       ELSE IF (INCX.EQ.0) THEN
111:           INFO = 5
112:       END IF
113:       IF (INFO.NE.0) THEN
114:           CALL XERBLA('SSPR  ',INFO)
115:           RETURN
116:       END IF
117: *
118: *     Quick return if possible.
119: *
120:       IF ((N.EQ.0) .OR. (ALPHA.EQ.ZERO)) RETURN
121: *
122: *     Set the start point in X if the increment is not unity.
123: *
124:       IF (INCX.LE.0) THEN
125:           KX = 1 - (N-1)*INCX
126:       ELSE IF (INCX.NE.1) THEN
127:           KX = 1
128:       END IF
129: *
130: *     Start the operations. In this version the elements of the array AP
131: *     are accessed sequentially with one pass through AP.
132: *
133:       KK = 1
134:       IF (LSAME(UPLO,'U')) THEN
135: *
136: *        Form  A  when upper triangle is stored in AP.
137: *
138:           IF (INCX.EQ.1) THEN
139:               DO 20 J = 1,N
140:                   IF (X(J).NE.ZERO) THEN
141:                       TEMP = ALPHA*X(J)
142:                       K = KK
143:                       DO 10 I = 1,J
144:                           AP(K) = AP(K) + X(I)*TEMP
145:                           K = K + 1
146:    10                 CONTINUE
147:                   END IF
148:                   KK = KK + J
149:    20         CONTINUE
150:           ELSE
151:               JX = KX
152:               DO 40 J = 1,N
153:                   IF (X(JX).NE.ZERO) THEN
154:                       TEMP = ALPHA*X(JX)
155:                       IX = KX
156:                       DO 30 K = KK,KK + J - 1
157:                           AP(K) = AP(K) + X(IX)*TEMP
158:                           IX = IX + INCX
159:    30                 CONTINUE
160:                   END IF
161:                   JX = JX + INCX
162:                   KK = KK + J
163:    40         CONTINUE
164:           END IF
165:       ELSE
166: *
167: *        Form  A  when lower triangle is stored in AP.
168: *
169:           IF (INCX.EQ.1) THEN
170:               DO 60 J = 1,N
171:                   IF (X(J).NE.ZERO) THEN
172:                       TEMP = ALPHA*X(J)
173:                       K = KK
174:                       DO 50 I = J,N
175:                           AP(K) = AP(K) + X(I)*TEMP
176:                           K = K + 1
177:    50                 CONTINUE
178:                   END IF
179:                   KK = KK + N - J + 1
180:    60         CONTINUE
181:           ELSE
182:               JX = KX
183:               DO 80 J = 1,N
184:                   IF (X(JX).NE.ZERO) THEN
185:                       TEMP = ALPHA*X(JX)
186:                       IX = JX
187:                       DO 70 K = KK,KK + N - J
188:                           AP(K) = AP(K) + X(IX)*TEMP
189:                           IX = IX + INCX
190:    70                 CONTINUE
191:                   END IF
192:                   JX = JX + INCX
193:                   KK = KK + N - J + 1
194:    80         CONTINUE
195:           END IF
196:       END IF
197: *
198:       RETURN
199: *
200: *     End of SSPR  .
201: *
202:       END
203: