001:       SUBROUTINE CHER(UPLO,N,ALPHA,X,INCX,A,LDA)
002: *     .. Scalar Arguments ..
003:       REAL ALPHA
004:       INTEGER INCX,LDA,N
005:       CHARACTER UPLO
006: *     ..
007: *     .. Array Arguments ..
008:       COMPLEX A(LDA,*),X(*)
009: *     ..
010: *
011: *  Purpose
012: *  =======
013: *
014: *  CHER   performs the hermitian rank 1 operation
015: *
016: *     A := alpha*x*conjg( x' ) + A,
017: *
018: *  where alpha is a real scalar, x is an n element vector and A is an
019: *  n by n hermitian 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  - REAL            .
043: *           On entry, ALPHA specifies the scalar alpha.
044: *           Unchanged on exit.
045: *
046: *  X      - COMPLEX          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      - COMPLEX          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 hermitian 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 hermitian 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: *           Note that the imaginary parts of the diagonal elements need
071: *           not be set, they are assumed to be zero, and on exit they
072: *           are set to zero.
073: *
074: *  LDA    - INTEGER.
075: *           On entry, LDA specifies the first dimension of A as declared
076: *           in the calling (sub) program. LDA must be at least
077: *           max( 1, n ).
078: *           Unchanged on exit.
079: *
080: *
081: *  Level 2 Blas routine.
082: *
083: *  -- Written on 22-October-1986.
084: *     Jack Dongarra, Argonne National Lab.
085: *     Jeremy Du Croz, Nag Central Office.
086: *     Sven Hammarling, Nag Central Office.
087: *     Richard Hanson, Sandia National Labs.
088: *
089: *
090: *     .. Parameters ..
091:       COMPLEX ZERO
092:       PARAMETER (ZERO= (0.0E+0,0.0E+0))
093: *     ..
094: *     .. Local Scalars ..
095:       COMPLEX TEMP
096:       INTEGER I,INFO,IX,J,JX,KX
097: *     ..
098: *     .. External Functions ..
099:       LOGICAL LSAME
100:       EXTERNAL LSAME
101: *     ..
102: *     .. External Subroutines ..
103:       EXTERNAL XERBLA
104: *     ..
105: *     .. Intrinsic Functions ..
106:       INTRINSIC CONJG,MAX,REAL
107: *     ..
108: *
109: *     Test the input parameters.
110: *
111:       INFO = 0
112:       IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN
113:           INFO = 1
114:       ELSE IF (N.LT.0) THEN
115:           INFO = 2
116:       ELSE IF (INCX.EQ.0) THEN
117:           INFO = 5
118:       ELSE IF (LDA.LT.MAX(1,N)) THEN
119:           INFO = 7
120:       END IF
121:       IF (INFO.NE.0) THEN
122:           CALL XERBLA('CHER  ',INFO)
123:           RETURN
124:       END IF
125: *
126: *     Quick return if possible.
127: *
128:       IF ((N.EQ.0) .OR. (ALPHA.EQ.REAL(ZERO))) RETURN
129: *
130: *     Set the start point in X if the increment is not unity.
131: *
132:       IF (INCX.LE.0) THEN
133:           KX = 1 - (N-1)*INCX
134:       ELSE IF (INCX.NE.1) THEN
135:           KX = 1
136:       END IF
137: *
138: *     Start the operations. In this version the elements of A are
139: *     accessed sequentially with one pass through the triangular part
140: *     of A.
141: *
142:       IF (LSAME(UPLO,'U')) THEN
143: *
144: *        Form  A  when A is stored in upper triangle.
145: *
146:           IF (INCX.EQ.1) THEN
147:               DO 20 J = 1,N
148:                   IF (X(J).NE.ZERO) THEN
149:                       TEMP = ALPHA*CONJG(X(J))
150:                       DO 10 I = 1,J - 1
151:                           A(I,J) = A(I,J) + X(I)*TEMP
152:    10                 CONTINUE
153:                       A(J,J) = REAL(A(J,J)) + REAL(X(J)*TEMP)
154:                   ELSE
155:                       A(J,J) = REAL(A(J,J))
156:                   END IF
157:    20         CONTINUE
158:           ELSE
159:               JX = KX
160:               DO 40 J = 1,N
161:                   IF (X(JX).NE.ZERO) THEN
162:                       TEMP = ALPHA*CONJG(X(JX))
163:                       IX = KX
164:                       DO 30 I = 1,J - 1
165:                           A(I,J) = A(I,J) + X(IX)*TEMP
166:                           IX = IX + INCX
167:    30                 CONTINUE
168:                       A(J,J) = REAL(A(J,J)) + REAL(X(JX)*TEMP)
169:                   ELSE
170:                       A(J,J) = REAL(A(J,J))
171:                   END IF
172:                   JX = JX + INCX
173:    40         CONTINUE
174:           END IF
175:       ELSE
176: *
177: *        Form  A  when A is stored in lower triangle.
178: *
179:           IF (INCX.EQ.1) THEN
180:               DO 60 J = 1,N
181:                   IF (X(J).NE.ZERO) THEN
182:                       TEMP = ALPHA*CONJG(X(J))
183:                       A(J,J) = REAL(A(J,J)) + REAL(TEMP*X(J))
184:                       DO 50 I = J + 1,N
185:                           A(I,J) = A(I,J) + X(I)*TEMP
186:    50                 CONTINUE
187:                   ELSE
188:                       A(J,J) = REAL(A(J,J))
189:                   END IF
190:    60         CONTINUE
191:           ELSE
192:               JX = KX
193:               DO 80 J = 1,N
194:                   IF (X(JX).NE.ZERO) THEN
195:                       TEMP = ALPHA*CONJG(X(JX))
196:                       A(J,J) = REAL(A(J,J)) + REAL(TEMP*X(JX))
197:                       IX = JX
198:                       DO 70 I = J + 1,N
199:                           IX = IX + INCX
200:                           A(I,J) = A(I,J) + X(IX)*TEMP
201:    70                 CONTINUE
202:                   ELSE
203:                       A(J,J) = REAL(A(J,J))
204:                   END IF
205:                   JX = JX + INCX
206:    80         CONTINUE
207:           END IF
208:       END IF
209: *
210:       RETURN
211: *
212: *     End of CHER  .
213: *
214:       END
215: