```001:       SUBROUTINE SSBMV(UPLO,N,K,ALPHA,A,LDA,X,INCX,BETA,Y,INCY)
002: *     .. Scalar Arguments ..
003:       REAL ALPHA,BETA
004:       INTEGER INCX,INCY,K,LDA,N
005:       CHARACTER UPLO
006: *     ..
007: *     .. Array Arguments ..
008:       REAL A(LDA,*),X(*),Y(*)
009: *     ..
010: *
011: *  Purpose
012: *  =======
013: *
014: *  SSBMV  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 symmetric 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  - REAL            .
048: *           On entry, ALPHA specifies the scalar alpha.
049: *           Unchanged on exit.
050: *
051: *  A      - REAL             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 symmetric 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 symmetric 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 symmetric 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 symmetric 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: *           Unchanged on exit.
089: *
090: *  LDA    - INTEGER.
091: *           On entry, LDA specifies the first dimension of A as declared
092: *           in the calling (sub) program. LDA must be at least
093: *           ( k + 1 ).
094: *           Unchanged on exit.
095: *
096: *  X      - REAL             array of DIMENSION at least
097: *           ( 1 + ( n - 1 )*abs( INCX ) ).
098: *           Before entry, the incremented array X must contain the
099: *           vector x.
100: *           Unchanged on exit.
101: *
102: *  INCX   - INTEGER.
103: *           On entry, INCX specifies the increment for the elements of
104: *           X. INCX must not be zero.
105: *           Unchanged on exit.
106: *
107: *  BETA   - REAL            .
108: *           On entry, BETA specifies the scalar beta.
109: *           Unchanged on exit.
110: *
111: *  Y      - REAL             array of DIMENSION at least
112: *           ( 1 + ( n - 1 )*abs( INCY ) ).
113: *           Before entry, the incremented array Y must contain the
114: *           vector y. On exit, Y is overwritten by the updated vector y.
115: *
116: *  INCY   - INTEGER.
117: *           On entry, INCY specifies the increment for the elements of
118: *           Y. INCY must not be zero.
119: *           Unchanged on exit.
120: *
121: *
122: *  Level 2 Blas routine.
123: *
124: *  -- Written on 22-October-1986.
125: *     Jack Dongarra, Argonne National Lab.
126: *     Jeremy Du Croz, Nag Central Office.
127: *     Sven Hammarling, Nag Central Office.
128: *     Richard Hanson, Sandia National Labs.
129: *
130: *
131: *     .. Parameters ..
132:       REAL ONE,ZERO
133:       PARAMETER (ONE=1.0E+0,ZERO=0.0E+0)
134: *     ..
135: *     .. Local Scalars ..
136:       REAL TEMP1,TEMP2
137:       INTEGER I,INFO,IX,IY,J,JX,JY,KPLUS1,KX,KY,L
138: *     ..
139: *     .. External Functions ..
140:       LOGICAL LSAME
141:       EXTERNAL LSAME
142: *     ..
143: *     .. External Subroutines ..
144:       EXTERNAL XERBLA
145: *     ..
146: *     .. Intrinsic Functions ..
147:       INTRINSIC MAX,MIN
148: *     ..
149: *
150: *     Test the input parameters.
151: *
152:       INFO = 0
153:       IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN
154:           INFO = 1
155:       ELSE IF (N.LT.0) THEN
156:           INFO = 2
157:       ELSE IF (K.LT.0) THEN
158:           INFO = 3
159:       ELSE IF (LDA.LT. (K+1)) THEN
160:           INFO = 6
161:       ELSE IF (INCX.EQ.0) THEN
162:           INFO = 8
163:       ELSE IF (INCY.EQ.0) THEN
164:           INFO = 11
165:       END IF
166:       IF (INFO.NE.0) THEN
167:           CALL XERBLA('SSBMV ',INFO)
168:           RETURN
169:       END IF
170: *
171: *     Quick return if possible.
172: *
173:       IF ((N.EQ.0) .OR. ((ALPHA.EQ.ZERO).AND. (BETA.EQ.ONE))) RETURN
174: *
175: *     Set up the start points in  X  and  Y.
176: *
177:       IF (INCX.GT.0) THEN
178:           KX = 1
179:       ELSE
180:           KX = 1 - (N-1)*INCX
181:       END IF
182:       IF (INCY.GT.0) THEN
183:           KY = 1
184:       ELSE
185:           KY = 1 - (N-1)*INCY
186:       END IF
187: *
188: *     Start the operations. In this version the elements of the array A
189: *     are accessed sequentially with one pass through A.
190: *
191: *     First form  y := beta*y.
192: *
193:       IF (BETA.NE.ONE) THEN
194:           IF (INCY.EQ.1) THEN
195:               IF (BETA.EQ.ZERO) THEN
196:                   DO 10 I = 1,N
197:                       Y(I) = ZERO
198:    10             CONTINUE
199:               ELSE
200:                   DO 20 I = 1,N
201:                       Y(I) = BETA*Y(I)
202:    20             CONTINUE
203:               END IF
204:           ELSE
205:               IY = KY
206:               IF (BETA.EQ.ZERO) THEN
207:                   DO 30 I = 1,N
208:                       Y(IY) = ZERO
209:                       IY = IY + INCY
210:    30             CONTINUE
211:               ELSE
212:                   DO 40 I = 1,N
213:                       Y(IY) = BETA*Y(IY)
214:                       IY = IY + INCY
215:    40             CONTINUE
216:               END IF
217:           END IF
218:       END IF
219:       IF (ALPHA.EQ.ZERO) RETURN
220:       IF (LSAME(UPLO,'U')) THEN
221: *
222: *        Form  y  when upper triangle of A is stored.
223: *
224:           KPLUS1 = K + 1
225:           IF ((INCX.EQ.1) .AND. (INCY.EQ.1)) THEN
226:               DO 60 J = 1,N
227:                   TEMP1 = ALPHA*X(J)
228:                   TEMP2 = ZERO
229:                   L = KPLUS1 - J
230:                   DO 50 I = MAX(1,J-K),J - 1
231:                       Y(I) = Y(I) + TEMP1*A(L+I,J)
232:                       TEMP2 = TEMP2 + A(L+I,J)*X(I)
233:    50             CONTINUE
234:                   Y(J) = Y(J) + TEMP1*A(KPLUS1,J) + ALPHA*TEMP2
235:    60         CONTINUE
236:           ELSE
237:               JX = KX
238:               JY = KY
239:               DO 80 J = 1,N
240:                   TEMP1 = ALPHA*X(JX)
241:                   TEMP2 = ZERO
242:                   IX = KX
243:                   IY = KY
244:                   L = KPLUS1 - J
245:                   DO 70 I = MAX(1,J-K),J - 1
246:                       Y(IY) = Y(IY) + TEMP1*A(L+I,J)
247:                       TEMP2 = TEMP2 + A(L+I,J)*X(IX)
248:                       IX = IX + INCX
249:                       IY = IY + INCY
250:    70             CONTINUE
251:                   Y(JY) = Y(JY) + TEMP1*A(KPLUS1,J) + ALPHA*TEMP2
252:                   JX = JX + INCX
253:                   JY = JY + INCY
254:                   IF (J.GT.K) THEN
255:                       KX = KX + INCX
256:                       KY = KY + INCY
257:                   END IF
258:    80         CONTINUE
259:           END IF
260:       ELSE
261: *
262: *        Form  y  when lower triangle of A is stored.
263: *
264:           IF ((INCX.EQ.1) .AND. (INCY.EQ.1)) THEN
265:               DO 100 J = 1,N
266:                   TEMP1 = ALPHA*X(J)
267:                   TEMP2 = ZERO
268:                   Y(J) = Y(J) + TEMP1*A(1,J)
269:                   L = 1 - J
270:                   DO 90 I = J + 1,MIN(N,J+K)
271:                       Y(I) = Y(I) + TEMP1*A(L+I,J)
272:                       TEMP2 = TEMP2 + A(L+I,J)*X(I)
273:    90             CONTINUE
274:                   Y(J) = Y(J) + ALPHA*TEMP2
275:   100         CONTINUE
276:           ELSE
277:               JX = KX
278:               JY = KY
279:               DO 120 J = 1,N
280:                   TEMP1 = ALPHA*X(JX)
281:                   TEMP2 = ZERO
282:                   Y(JY) = Y(JY) + TEMP1*A(1,J)
283:                   L = 1 - J
284:                   IX = JX
285:                   IY = JY
286:                   DO 110 I = J + 1,MIN(N,J+K)
287:                       IX = IX + INCX
288:                       IY = IY + INCY
289:                       Y(IY) = Y(IY) + TEMP1*A(L+I,J)
290:                       TEMP2 = TEMP2 + A(L+I,J)*X(IX)
291:   110             CONTINUE
292:                   Y(JY) = Y(JY) + ALPHA*TEMP2
293:                   JX = JX + INCX
294:                   JY = JY + INCY
295:   120         CONTINUE
296:           END IF
297:       END IF
298: *
299:       RETURN
300: *
301: *     End of SSBMV .
302: *
303:       END
304: ```