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