001:       SUBROUTINE DSPR(UPLO,N,ALPHA,X,INCX,AP)
002: *     .. Scalar Arguments ..
003:       DOUBLE PRECISION ALPHA
004:       INTEGER INCX,N
005:       CHARACTER UPLO
006: *     ..
007: *     .. Array Arguments ..
008:       DOUBLE PRECISION AP(*),X(*)
009: *     ..
010: *
011: *  Purpose
012: *  =======
013: *
014: *  DSPR    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  - DOUBLE PRECISION.
043: *           On entry, ALPHA specifies the scalar alpha.
044: *           Unchanged on exit.
045: *
046: *  X      - DOUBLE PRECISION 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     - DOUBLE PRECISION 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: *
075: *  Level 2 Blas routine.
076: *
077: *  -- Written on 22-October-1986.
078: *     Jack Dongarra, Argonne National Lab.
079: *     Jeremy Du Croz, Nag Central Office.
080: *     Sven Hammarling, Nag Central Office.
081: *     Richard Hanson, Sandia National Labs.
082: *
083: *
084: *     .. Parameters ..
085:       DOUBLE PRECISION ZERO
086:       PARAMETER (ZERO=0.0D+0)
087: *     ..
088: *     .. Local Scalars ..
089:       DOUBLE PRECISION TEMP
090:       INTEGER I,INFO,IX,J,JX,K,KK,KX
091: *     ..
092: *     .. External Functions ..
093:       LOGICAL LSAME
094:       EXTERNAL LSAME
095: *     ..
096: *     .. External Subroutines ..
097:       EXTERNAL XERBLA
098: *     ..
099: *
100: *     Test the input parameters.
101: *
102:       INFO = 0
103:       IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN
104:           INFO = 1
105:       ELSE IF (N.LT.0) THEN
106:           INFO = 2
107:       ELSE IF (INCX.EQ.0) THEN
108:           INFO = 5
109:       END IF
110:       IF (INFO.NE.0) THEN
111:           CALL XERBLA('DSPR  ',INFO)
112:           RETURN
113:       END IF
114: *
115: *     Quick return if possible.
116: *
117:       IF ((N.EQ.0) .OR. (ALPHA.EQ.ZERO)) RETURN
118: *
119: *     Set the start point in X if the increment is not unity.
120: *
121:       IF (INCX.LE.0) THEN
122:           KX = 1 - (N-1)*INCX
123:       ELSE IF (INCX.NE.1) THEN
124:           KX = 1
125:       END IF
126: *
127: *     Start the operations. In this version the elements of the array AP
128: *     are accessed sequentially with one pass through AP.
129: *
130:       KK = 1
131:       IF (LSAME(UPLO,'U')) THEN
132: *
133: *        Form  A  when upper triangle is stored in AP.
134: *
135:           IF (INCX.EQ.1) THEN
136:               DO 20 J = 1,N
137:                   IF (X(J).NE.ZERO) THEN
138:                       TEMP = ALPHA*X(J)
139:                       K = KK
140:                       DO 10 I = 1,J
141:                           AP(K) = AP(K) + X(I)*TEMP
142:                           K = K + 1
143:    10                 CONTINUE
144:                   END IF
145:                   KK = KK + J
146:    20         CONTINUE
147:           ELSE
148:               JX = KX
149:               DO 40 J = 1,N
150:                   IF (X(JX).NE.ZERO) THEN
151:                       TEMP = ALPHA*X(JX)
152:                       IX = KX
153:                       DO 30 K = KK,KK + J - 1
154:                           AP(K) = AP(K) + X(IX)*TEMP
155:                           IX = IX + INCX
156:    30                 CONTINUE
157:                   END IF
158:                   JX = JX + INCX
159:                   KK = KK + J
160:    40         CONTINUE
161:           END IF
162:       ELSE
163: *
164: *        Form  A  when lower triangle is stored in AP.
165: *
166:           IF (INCX.EQ.1) THEN
167:               DO 60 J = 1,N
168:                   IF (X(J).NE.ZERO) THEN
169:                       TEMP = ALPHA*X(J)
170:                       K = KK
171:                       DO 50 I = J,N
172:                           AP(K) = AP(K) + X(I)*TEMP
173:                           K = K + 1
174:    50                 CONTINUE
175:                   END IF
176:                   KK = KK + N - J + 1
177:    60         CONTINUE
178:           ELSE
179:               JX = KX
180:               DO 80 J = 1,N
181:                   IF (X(JX).NE.ZERO) THEN
182:                       TEMP = ALPHA*X(JX)
183:                       IX = JX
184:                       DO 70 K = KK,KK + N - J
185:                           AP(K) = AP(K) + X(IX)*TEMP
186:                           IX = IX + INCX
187:    70                 CONTINUE
188:                   END IF
189:                   JX = JX + INCX
190:                   KK = KK + N - J + 1
191:    80         CONTINUE
192:           END IF
193:       END IF
194: *
195:       RETURN
196: *
197: *     End of DSPR  .
198: *
199:       END
200: