001:       SUBROUTINE DSYR(UPLO,N,ALPHA,X,INCX,A,LDA)
002: *     .. Scalar Arguments ..
003:       DOUBLE PRECISION ALPHA
004:       INTEGER INCX,LDA,N
005:       CHARACTER UPLO
006: *     ..
007: *     .. Array Arguments ..
008:       DOUBLE PRECISION A(LDA,*),X(*)
009: *     ..
010: *
011: *  Purpose
012: *  =======
013: *
014: *  DSYR   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.
020: *
021: *  Arguments
022: *  ==========
023: *
024: *  UPLO   - CHARACTER*1.
025: *           On entry, UPLO specifies whether the upper or lower
026: *           triangular part of the array A is to be referenced as
027: *           follows:
028: *
029: *              UPLO = 'U' or 'u'   Only the upper triangular part of A
030: *                                  is to be referenced.
031: *
032: *              UPLO = 'L' or 'l'   Only the lower triangular part of A
033: *                                  is to be referenced.
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: *  A      - DOUBLE PRECISION array of DIMENSION ( LDA, n ).
058: *           Before entry with  UPLO = 'U' or 'u', the leading n by n
059: *           upper triangular part of the array A must contain the upper
060: *           triangular part of the symmetric matrix and the strictly
061: *           lower triangular part of A is not referenced. On exit, the
062: *           upper triangular part of the array A is overwritten by the
063: *           upper triangular part of the updated matrix.
064: *           Before entry with UPLO = 'L' or 'l', the leading n by n
065: *           lower triangular part of the array A must contain the lower
066: *           triangular part of the symmetric matrix and the strictly
067: *           upper triangular part of A is not referenced. On exit, the
068: *           lower triangular part of the array A is overwritten by the
069: *           lower triangular part of the updated matrix.
070: *
071: *  LDA    - INTEGER.
072: *           On entry, LDA specifies the first dimension of A as declared
073: *           in the calling (sub) program. LDA must be at least
074: *           max( 1, n ).
075: *           Unchanged on exit.
076: *
077: *
078: *  Level 2 Blas routine.
079: *
080: *  -- Written on 22-October-1986.
081: *     Jack Dongarra, Argonne National Lab.
082: *     Jeremy Du Croz, Nag Central Office.
083: *     Sven Hammarling, Nag Central Office.
084: *     Richard Hanson, Sandia National Labs.
085: *
086: *
087: *     .. Parameters ..
088:       DOUBLE PRECISION ZERO
089:       PARAMETER (ZERO=0.0D+0)
090: *     ..
091: *     .. Local Scalars ..
092:       DOUBLE PRECISION TEMP
093:       INTEGER I,INFO,IX,J,JX,KX
094: *     ..
095: *     .. External Functions ..
096:       LOGICAL LSAME
097:       EXTERNAL LSAME
098: *     ..
099: *     .. External Subroutines ..
100:       EXTERNAL XERBLA
101: *     ..
102: *     .. Intrinsic Functions ..
103:       INTRINSIC MAX
104: *     ..
105: *
106: *     Test the input parameters.
107: *
108:       INFO = 0
109:       IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN
110:           INFO = 1
111:       ELSE IF (N.LT.0) THEN
112:           INFO = 2
113:       ELSE IF (INCX.EQ.0) THEN
114:           INFO = 5
115:       ELSE IF (LDA.LT.MAX(1,N)) THEN
116:           INFO = 7
117:       END IF
118:       IF (INFO.NE.0) THEN
119:           CALL XERBLA('DSYR  ',INFO)
120:           RETURN
121:       END IF
122: *
123: *     Quick return if possible.
124: *
125:       IF ((N.EQ.0) .OR. (ALPHA.EQ.ZERO)) RETURN
126: *
127: *     Set the start point in X if the increment is not unity.
128: *
129:       IF (INCX.LE.0) THEN
130:           KX = 1 - (N-1)*INCX
131:       ELSE IF (INCX.NE.1) THEN
132:           KX = 1
133:       END IF
134: *
135: *     Start the operations. In this version the elements of A are
136: *     accessed sequentially with one pass through the triangular part
137: *     of A.
138: *
139:       IF (LSAME(UPLO,'U')) THEN
140: *
141: *        Form  A  when A is stored in upper triangle.
142: *
143:           IF (INCX.EQ.1) THEN
144:               DO 20 J = 1,N
145:                   IF (X(J).NE.ZERO) THEN
146:                       TEMP = ALPHA*X(J)
147:                       DO 10 I = 1,J
148:                           A(I,J) = A(I,J) + X(I)*TEMP
149:    10                 CONTINUE
150:                   END IF
151:    20         CONTINUE
152:           ELSE
153:               JX = KX
154:               DO 40 J = 1,N
155:                   IF (X(JX).NE.ZERO) THEN
156:                       TEMP = ALPHA*X(JX)
157:                       IX = KX
158:                       DO 30 I = 1,J
159:                           A(I,J) = A(I,J) + X(IX)*TEMP
160:                           IX = IX + INCX
161:    30                 CONTINUE
162:                   END IF
163:                   JX = JX + INCX
164:    40         CONTINUE
165:           END IF
166:       ELSE
167: *
168: *        Form  A  when A is stored in lower triangle.
169: *
170:           IF (INCX.EQ.1) THEN
171:               DO 60 J = 1,N
172:                   IF (X(J).NE.ZERO) THEN
173:                       TEMP = ALPHA*X(J)
174:                       DO 50 I = J,N
175:                           A(I,J) = A(I,J) + X(I)*TEMP
176:    50                 CONTINUE
177:                   END IF
178:    60         CONTINUE
179:           ELSE
180:               JX = KX
181:               DO 80 J = 1,N
182:                   IF (X(JX).NE.ZERO) THEN
183:                       TEMP = ALPHA*X(JX)
184:                       IX = JX
185:                       DO 70 I = J,N
186:                           A(I,J) = A(I,J) + X(IX)*TEMP
187:                           IX = IX + INCX
188:    70                 CONTINUE
189:                   END IF
190:                   JX = JX + INCX
191:    80         CONTINUE
192:           END IF
193:       END IF
194: *
195:       RETURN
196: *
197: *     End of DSYR  .
198: *
199:       END
200: