001:       SUBROUTINE CHPR(UPLO,N,ALPHA,X,INCX,AP)
002: *     .. Scalar Arguments ..
003:       REAL ALPHA
004:       INTEGER INCX,N
005:       CHARACTER UPLO
006: *     ..
007: *     .. Array Arguments ..
008:       COMPLEX AP(*),X(*)
009: *     ..
010: *
011: *  Purpose
012: *  =======
013: *
014: *  CHPR    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, 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  - 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: *  AP     - COMPLEX          array of DIMENSION at least
058: *           ( ( n*( n + 1 ) )/2 ).
059: *           Before entry with  UPLO = 'U' or 'u', the array AP must
060: *           contain the upper triangular part of the hermitian matrix
061: *           packed sequentially, column by column, so that AP( 1 )
062: *           contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 1, 2 )
063: *           and a( 2, 2 ) respectively, and so on. On exit, the array
064: *           AP is overwritten by the upper triangular part of the
065: *           updated matrix.
066: *           Before entry with UPLO = 'L' or 'l', the array AP must
067: *           contain the lower triangular part of the hermitian matrix
068: *           packed sequentially, column by column, so that AP( 1 )
069: *           contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 2, 1 )
070: *           and a( 3, 1 ) respectively, and so on. On exit, the array
071: *           AP is overwritten by the lower triangular part of the
072: *           updated matrix.
073: *           Note that the imaginary parts of the diagonal elements need
074: *           not be set, they are assumed to be zero, and on exit they
075: *           are set to zero.
076: *
077: *  Further Details
078: *  ===============
079: *
080: *  Level 2 Blas routine.
081: *
082: *  -- Written on 22-October-1986.
083: *     Jack Dongarra, Argonne National Lab.
084: *     Jeremy Du Croz, Nag Central Office.
085: *     Sven Hammarling, Nag Central Office.
086: *     Richard Hanson, Sandia National Labs.
087: *
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,K,KK,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,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:       END IF
119:       IF (INFO.NE.0) THEN
120:           CALL XERBLA('CHPR  ',INFO)
121:           RETURN
122:       END IF
123: *
124: *     Quick return if possible.
125: *
126:       IF ((N.EQ.0) .OR. (ALPHA.EQ.REAL(ZERO))) RETURN
127: *
128: *     Set the start point in X if the increment is not unity.
129: *
130:       IF (INCX.LE.0) THEN
131:           KX = 1 - (N-1)*INCX
132:       ELSE IF (INCX.NE.1) THEN
133:           KX = 1
134:       END IF
135: *
136: *     Start the operations. In this version the elements of the array AP
137: *     are accessed sequentially with one pass through AP.
138: *
139:       KK = 1
140:       IF (LSAME(UPLO,'U')) THEN
141: *
142: *        Form  A  when upper triangle is stored in AP.
143: *
144:           IF (INCX.EQ.1) THEN
145:               DO 20 J = 1,N
146:                   IF (X(J).NE.ZERO) THEN
147:                       TEMP = ALPHA*CONJG(X(J))
148:                       K = KK
149:                       DO 10 I = 1,J - 1
150:                           AP(K) = AP(K) + X(I)*TEMP
151:                           K = K + 1
152:    10                 CONTINUE
153:                       AP(KK+J-1) = REAL(AP(KK+J-1)) + REAL(X(J)*TEMP)
154:                   ELSE
155:                       AP(KK+J-1) = REAL(AP(KK+J-1))
156:                   END IF
157:                   KK = KK + J
158:    20         CONTINUE
159:           ELSE
160:               JX = KX
161:               DO 40 J = 1,N
162:                   IF (X(JX).NE.ZERO) THEN
163:                       TEMP = ALPHA*CONJG(X(JX))
164:                       IX = KX
165:                       DO 30 K = KK,KK + J - 2
166:                           AP(K) = AP(K) + X(IX)*TEMP
167:                           IX = IX + INCX
168:    30                 CONTINUE
169:                       AP(KK+J-1) = REAL(AP(KK+J-1)) + REAL(X(JX)*TEMP)
170:                   ELSE
171:                       AP(KK+J-1) = REAL(AP(KK+J-1))
172:                   END IF
173:                   JX = JX + INCX
174:                   KK = KK + J
175:    40         CONTINUE
176:           END IF
177:       ELSE
178: *
179: *        Form  A  when lower triangle is stored in AP.
180: *
181:           IF (INCX.EQ.1) THEN
182:               DO 60 J = 1,N
183:                   IF (X(J).NE.ZERO) THEN
184:                       TEMP = ALPHA*CONJG(X(J))
185:                       AP(KK) = REAL(AP(KK)) + REAL(TEMP*X(J))
186:                       K = KK + 1
187:                       DO 50 I = J + 1,N
188:                           AP(K) = AP(K) + X(I)*TEMP
189:                           K = K + 1
190:    50                 CONTINUE
191:                   ELSE
192:                       AP(KK) = REAL(AP(KK))
193:                   END IF
194:                   KK = KK + N - J + 1
195:    60         CONTINUE
196:           ELSE
197:               JX = KX
198:               DO 80 J = 1,N
199:                   IF (X(JX).NE.ZERO) THEN
200:                       TEMP = ALPHA*CONJG(X(JX))
201:                       AP(KK) = REAL(AP(KK)) + REAL(TEMP*X(JX))
202:                       IX = JX
203:                       DO 70 K = KK + 1,KK + N - J
204:                           IX = IX + INCX
205:                           AP(K) = AP(K) + X(IX)*TEMP
206:    70                 CONTINUE
207:                   ELSE
208:                       AP(KK) = REAL(AP(KK))
209:                   END IF
210:                   JX = JX + INCX
211:                   KK = KK + N - J + 1
212:    80         CONTINUE
213:           END IF
214:       END IF
215: *
216:       RETURN
217: *
218: *     End of CHPR  .
219: *
220:       END
221: