001:       SUBROUTINE ZHPR(UPLO,N,ALPHA,X,INCX,AP)
002: *     .. Scalar Arguments ..
003:       DOUBLE PRECISION ALPHA
004:       INTEGER INCX,N
005:       CHARACTER UPLO
006: *     ..
007: *     .. Array Arguments ..
008:       DOUBLE COMPLEX AP(*),X(*)
009: *     ..
010: *
011: *  Purpose
012: *  =======
013: *
014: *  ZHPR    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  - DOUBLE PRECISION.
043: *           On entry, ALPHA specifies the scalar alpha.
044: *           Unchanged on exit.
045: *
046: *  X      - COMPLEX*16       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*16       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: *
078: *  Level 2 Blas routine.
079: *
080: *  -- Written on 22-October-1986.
081: *     Jack Dongarra, Argonne National Lab.
082: *     Jeremy Du Croz, Nag Central Office.
083: *     Sven Hammarling, Nag Central Office.
084: *     Richard Hanson, Sandia National Labs.
085: *
086: *
087: *     .. Parameters ..
088:       DOUBLE COMPLEX ZERO
089:       PARAMETER (ZERO= (0.0D+0,0.0D+0))
090: *     ..
091: *     .. Local Scalars ..
092:       DOUBLE COMPLEX TEMP
093:       INTEGER I,INFO,IX,J,JX,K,KK,KX
094: *     ..
095: *     .. External Functions ..
096:       LOGICAL LSAME
097:       EXTERNAL LSAME
098: *     ..
099: *     .. External Subroutines ..
100:       EXTERNAL XERBLA
101: *     ..
102: *     .. Intrinsic Functions ..
103:       INTRINSIC DBLE,DCONJG
104: *     ..
105: *
106: *     Test the input parameters.
107: *
108:       INFO = 0
109:       IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN
110:           INFO = 1
111:       ELSE IF (N.LT.0) THEN
112:           INFO = 2
113:       ELSE IF (INCX.EQ.0) THEN
114:           INFO = 5
115:       END IF
116:       IF (INFO.NE.0) THEN
117:           CALL XERBLA('ZHPR  ',INFO)
118:           RETURN
119:       END IF
120: *
121: *     Quick return if possible.
122: *
123:       IF ((N.EQ.0) .OR. (ALPHA.EQ.DBLE(ZERO))) RETURN
124: *
125: *     Set the start point in X if the increment is not unity.
126: *
127:       IF (INCX.LE.0) THEN
128:           KX = 1 - (N-1)*INCX
129:       ELSE IF (INCX.NE.1) THEN
130:           KX = 1
131:       END IF
132: *
133: *     Start the operations. In this version the elements of the array AP
134: *     are accessed sequentially with one pass through AP.
135: *
136:       KK = 1
137:       IF (LSAME(UPLO,'U')) THEN
138: *
139: *        Form  A  when upper triangle is stored in AP.
140: *
141:           IF (INCX.EQ.1) THEN
142:               DO 20 J = 1,N
143:                   IF (X(J).NE.ZERO) THEN
144:                       TEMP = ALPHA*DCONJG(X(J))
145:                       K = KK
146:                       DO 10 I = 1,J - 1
147:                           AP(K) = AP(K) + X(I)*TEMP
148:                           K = K + 1
149:    10                 CONTINUE
150:                       AP(KK+J-1) = DBLE(AP(KK+J-1)) + DBLE(X(J)*TEMP)
151:                   ELSE
152:                       AP(KK+J-1) = DBLE(AP(KK+J-1))
153:                   END IF
154:                   KK = KK + J
155:    20         CONTINUE
156:           ELSE
157:               JX = KX
158:               DO 40 J = 1,N
159:                   IF (X(JX).NE.ZERO) THEN
160:                       TEMP = ALPHA*DCONJG(X(JX))
161:                       IX = KX
162:                       DO 30 K = KK,KK + J - 2
163:                           AP(K) = AP(K) + X(IX)*TEMP
164:                           IX = IX + INCX
165:    30                 CONTINUE
166:                       AP(KK+J-1) = DBLE(AP(KK+J-1)) + DBLE(X(JX)*TEMP)
167:                   ELSE
168:                       AP(KK+J-1) = DBLE(AP(KK+J-1))
169:                   END IF
170:                   JX = JX + INCX
171:                   KK = KK + J
172:    40         CONTINUE
173:           END IF
174:       ELSE
175: *
176: *        Form  A  when lower triangle is stored in AP.
177: *
178:           IF (INCX.EQ.1) THEN
179:               DO 60 J = 1,N
180:                   IF (X(J).NE.ZERO) THEN
181:                       TEMP = ALPHA*DCONJG(X(J))
182:                       AP(KK) = DBLE(AP(KK)) + DBLE(TEMP*X(J))
183:                       K = KK + 1
184:                       DO 50 I = J + 1,N
185:                           AP(K) = AP(K) + X(I)*TEMP
186:                           K = K + 1
187:    50                 CONTINUE
188:                   ELSE
189:                       AP(KK) = DBLE(AP(KK))
190:                   END IF
191:                   KK = KK + N - J + 1
192:    60         CONTINUE
193:           ELSE
194:               JX = KX
195:               DO 80 J = 1,N
196:                   IF (X(JX).NE.ZERO) THEN
197:                       TEMP = ALPHA*DCONJG(X(JX))
198:                       AP(KK) = DBLE(AP(KK)) + DBLE(TEMP*X(JX))
199:                       IX = JX
200:                       DO 70 K = KK + 1,KK + N - J
201:                           IX = IX + INCX
202:                           AP(K) = AP(K) + X(IX)*TEMP
203:    70                 CONTINUE
204:                   ELSE
205:                       AP(KK) = DBLE(AP(KK))
206:                   END IF
207:                   JX = JX + INCX
208:                   KK = KK + N - J + 1
209:    80         CONTINUE
210:           END IF
211:       END IF
212: *
213:       RETURN
214: *
215: *     End of ZHPR  .
216: *
217:       END
218: