001:       SUBROUTINE CHEMV(UPLO,N,ALPHA,A,LDA,X,INCX,BETA,Y,INCY)
002: *     .. Scalar Arguments ..
003:       COMPLEX ALPHA,BETA
004:       INTEGER INCX,INCY,LDA,N
005:       CHARACTER UPLO
006: *     ..
007: *     .. Array Arguments ..
008:       COMPLEX A(LDA,*),X(*),Y(*)
009: *     ..
010: *
011: *  Purpose
012: *  =======
013: *
014: *  CHEMV  performs the matrix-vector  operation
015: *
016: *     y := alpha*A*x + beta*y,
017: *
018: *  where alpha and beta are scalars, x and y are n element vectors and
019: *  A is an 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  - COMPLEX         .
043: *           On entry, ALPHA specifies the scalar alpha.
044: *           Unchanged on exit.
045: *
046: *  A      - COMPLEX          array of DIMENSION ( LDA, n ).
047: *           Before entry with  UPLO = 'U' or 'u', the leading n by n
048: *           upper triangular part of the array A must contain the upper
049: *           triangular part of the hermitian matrix and the strictly
050: *           lower triangular part of A is not referenced.
051: *           Before entry with UPLO = 'L' or 'l', the leading n by n
052: *           lower triangular part of the array A must contain the lower
053: *           triangular part of the hermitian matrix and the strictly
054: *           upper triangular part of A is not referenced.
055: *           Note that the imaginary parts of the diagonal elements need
056: *           not be set and are assumed to be zero.
057: *           Unchanged on exit.
058: *
059: *  LDA    - INTEGER.
060: *           On entry, LDA specifies the first dimension of A as declared
061: *           in the calling (sub) program. LDA must be at least
062: *           max( 1, n ).
063: *           Unchanged on exit.
064: *
065: *  X      - COMPLEX          array of dimension at least
066: *           ( 1 + ( n - 1 )*abs( INCX ) ).
067: *           Before entry, the incremented array X must contain the n
068: *           element vector x.
069: *           Unchanged on exit.
070: *
071: *  INCX   - INTEGER.
072: *           On entry, INCX specifies the increment for the elements of
073: *           X. INCX must not be zero.
074: *           Unchanged on exit.
075: *
076: *  BETA   - COMPLEX         .
077: *           On entry, BETA specifies the scalar beta. When BETA is
078: *           supplied as zero then Y need not be set on input.
079: *           Unchanged on exit.
080: *
081: *  Y      - COMPLEX          array of dimension at least
082: *           ( 1 + ( n - 1 )*abs( INCY ) ).
083: *           Before entry, the incremented array Y must contain the n
084: *           element vector y. On exit, Y is overwritten by the updated
085: *           vector y.
086: *
087: *  INCY   - INTEGER.
088: *           On entry, INCY specifies the increment for the elements of
089: *           Y. INCY must not be zero.
090: *           Unchanged on exit.
091: *
092: *  Further Details
093: *  ===============
094: *
095: *  Level 2 Blas routine.
096: *
097: *  -- Written on 22-October-1986.
098: *     Jack Dongarra, Argonne National Lab.
099: *     Jeremy Du Croz, Nag Central Office.
100: *     Sven Hammarling, Nag Central Office.
101: *     Richard Hanson, Sandia National Labs.
102: *
103: *  =====================================================================
104: *
105: *     .. Parameters ..
106:       COMPLEX ONE
107:       PARAMETER (ONE= (1.0E+0,0.0E+0))
108:       COMPLEX ZERO
109:       PARAMETER (ZERO= (0.0E+0,0.0E+0))
110: *     ..
111: *     .. Local Scalars ..
112:       COMPLEX TEMP1,TEMP2
113:       INTEGER I,INFO,IX,IY,J,JX,JY,KX,KY
114: *     ..
115: *     .. External Functions ..
116:       LOGICAL LSAME
117:       EXTERNAL LSAME
118: *     ..
119: *     .. External Subroutines ..
120:       EXTERNAL XERBLA
121: *     ..
122: *     .. Intrinsic Functions ..
123:       INTRINSIC CONJG,MAX,REAL
124: *     ..
125: *
126: *     Test the input parameters.
127: *
128:       INFO = 0
129:       IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN
130:           INFO = 1
131:       ELSE IF (N.LT.0) THEN
132:           INFO = 2
133:       ELSE IF (LDA.LT.MAX(1,N)) THEN
134:           INFO = 5
135:       ELSE IF (INCX.EQ.0) THEN
136:           INFO = 7
137:       ELSE IF (INCY.EQ.0) THEN
138:           INFO = 10
139:       END IF
140:       IF (INFO.NE.0) THEN
141:           CALL XERBLA('CHEMV ',INFO)
142:           RETURN
143:       END IF
144: *
145: *     Quick return if possible.
146: *
147:       IF ((N.EQ.0) .OR. ((ALPHA.EQ.ZERO).AND. (BETA.EQ.ONE))) RETURN
148: *
149: *     Set up the start points in  X  and  Y.
150: *
151:       IF (INCX.GT.0) THEN
152:           KX = 1
153:       ELSE
154:           KX = 1 - (N-1)*INCX
155:       END IF
156:       IF (INCY.GT.0) THEN
157:           KY = 1
158:       ELSE
159:           KY = 1 - (N-1)*INCY
160:       END IF
161: *
162: *     Start the operations. In this version the elements of A are
163: *     accessed sequentially with one pass through the triangular part
164: *     of A.
165: *
166: *     First form  y := beta*y.
167: *
168:       IF (BETA.NE.ONE) THEN
169:           IF (INCY.EQ.1) THEN
170:               IF (BETA.EQ.ZERO) THEN
171:                   DO 10 I = 1,N
172:                       Y(I) = ZERO
173:    10             CONTINUE
174:               ELSE
175:                   DO 20 I = 1,N
176:                       Y(I) = BETA*Y(I)
177:    20             CONTINUE
178:               END IF
179:           ELSE
180:               IY = KY
181:               IF (BETA.EQ.ZERO) THEN
182:                   DO 30 I = 1,N
183:                       Y(IY) = ZERO
184:                       IY = IY + INCY
185:    30             CONTINUE
186:               ELSE
187:                   DO 40 I = 1,N
188:                       Y(IY) = BETA*Y(IY)
189:                       IY = IY + INCY
190:    40             CONTINUE
191:               END IF
192:           END IF
193:       END IF
194:       IF (ALPHA.EQ.ZERO) RETURN
195:       IF (LSAME(UPLO,'U')) THEN
196: *
197: *        Form  y  when A is stored in upper triangle.
198: *
199:           IF ((INCX.EQ.1) .AND. (INCY.EQ.1)) THEN
200:               DO 60 J = 1,N
201:                   TEMP1 = ALPHA*X(J)
202:                   TEMP2 = ZERO
203:                   DO 50 I = 1,J - 1
204:                       Y(I) = Y(I) + TEMP1*A(I,J)
205:                       TEMP2 = TEMP2 + CONJG(A(I,J))*X(I)
206:    50             CONTINUE
207:                   Y(J) = Y(J) + TEMP1*REAL(A(J,J)) + ALPHA*TEMP2
208:    60         CONTINUE
209:           ELSE
210:               JX = KX
211:               JY = KY
212:               DO 80 J = 1,N
213:                   TEMP1 = ALPHA*X(JX)
214:                   TEMP2 = ZERO
215:                   IX = KX
216:                   IY = KY
217:                   DO 70 I = 1,J - 1
218:                       Y(IY) = Y(IY) + TEMP1*A(I,J)
219:                       TEMP2 = TEMP2 + CONJG(A(I,J))*X(IX)
220:                       IX = IX + INCX
221:                       IY = IY + INCY
222:    70             CONTINUE
223:                   Y(JY) = Y(JY) + TEMP1*REAL(A(J,J)) + ALPHA*TEMP2
224:                   JX = JX + INCX
225:                   JY = JY + INCY
226:    80         CONTINUE
227:           END IF
228:       ELSE
229: *
230: *        Form  y  when A is stored in lower triangle.
231: *
232:           IF ((INCX.EQ.1) .AND. (INCY.EQ.1)) THEN
233:               DO 100 J = 1,N
234:                   TEMP1 = ALPHA*X(J)
235:                   TEMP2 = ZERO
236:                   Y(J) = Y(J) + TEMP1*REAL(A(J,J))
237:                   DO 90 I = J + 1,N
238:                       Y(I) = Y(I) + TEMP1*A(I,J)
239:                       TEMP2 = TEMP2 + CONJG(A(I,J))*X(I)
240:    90             CONTINUE
241:                   Y(J) = Y(J) + ALPHA*TEMP2
242:   100         CONTINUE
243:           ELSE
244:               JX = KX
245:               JY = KY
246:               DO 120 J = 1,N
247:                   TEMP1 = ALPHA*X(JX)
248:                   TEMP2 = ZERO
249:                   Y(JY) = Y(JY) + TEMP1*REAL(A(J,J))
250:                   IX = JX
251:                   IY = JY
252:                   DO 110 I = J + 1,N
253:                       IX = IX + INCX
254:                       IY = IY + INCY
255:                       Y(IY) = Y(IY) + TEMP1*A(I,J)
256:                       TEMP2 = TEMP2 + CONJG(A(I,J))*X(IX)
257:   110             CONTINUE
258:                   Y(JY) = Y(JY) + ALPHA*TEMP2
259:                   JX = JX + INCX
260:                   JY = JY + INCY
261:   120         CONTINUE
262:           END IF
263:       END IF
264: *
265:       RETURN
266: *
267: *     End of CHEMV .
268: *
269:       END
270: