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