```001:       SUBROUTINE DTPSV(UPLO,TRANS,DIAG,N,AP,X,INCX)
002: *     .. Scalar Arguments ..
003:       INTEGER INCX,N
004:       CHARACTER DIAG,TRANS,UPLO
005: *     ..
006: *     .. Array Arguments ..
007:       DOUBLE PRECISION AP(*),X(*)
008: *     ..
009: *
010: *  Purpose
011: *  =======
012: *
013: *  DTPSV  solves one of the systems of equations
014: *
015: *     A*x = b,   or   A'*x = b,
016: *
017: *  where b and x are n element vectors and A is an n by n unit, or
018: *  non-unit, upper or lower triangular matrix, supplied in packed form.
019: *
020: *  No test for singularity or near-singularity is included in this
021: *  routine. Such tests must be performed before calling this routine.
022: *
023: *  Arguments
024: *  ==========
025: *
026: *  UPLO   - CHARACTER*1.
027: *           On entry, UPLO specifies whether the matrix is an upper or
028: *           lower triangular matrix as follows:
029: *
030: *              UPLO = 'U' or 'u'   A is an upper triangular matrix.
031: *
032: *              UPLO = 'L' or 'l'   A is a lower triangular matrix.
033: *
034: *           Unchanged on exit.
035: *
036: *  TRANS  - CHARACTER*1.
037: *           On entry, TRANS specifies the equations to be solved as
038: *           follows:
039: *
040: *              TRANS = 'N' or 'n'   A*x = b.
041: *
042: *              TRANS = 'T' or 't'   A'*x = b.
043: *
044: *              TRANS = 'C' or 'c'   A'*x = b.
045: *
046: *           Unchanged on exit.
047: *
048: *  DIAG   - CHARACTER*1.
049: *           On entry, DIAG specifies whether or not A is unit
050: *           triangular as follows:
051: *
052: *              DIAG = 'U' or 'u'   A is assumed to be unit triangular.
053: *
054: *              DIAG = 'N' or 'n'   A is not assumed to be unit
055: *                                  triangular.
056: *
057: *           Unchanged on exit.
058: *
059: *  N      - INTEGER.
060: *           On entry, N specifies the order of the matrix A.
061: *           N must be at least zero.
062: *           Unchanged on exit.
063: *
064: *  AP     - DOUBLE PRECISION array of DIMENSION at least
065: *           ( ( n*( n + 1 ) )/2 ).
066: *           Before entry with  UPLO = 'U' or 'u', the array AP must
067: *           contain the upper triangular matrix packed sequentially,
068: *           column by column, so that AP( 1 ) contains a( 1, 1 ),
069: *           AP( 2 ) and AP( 3 ) contain a( 1, 2 ) and a( 2, 2 )
070: *           respectively, and so on.
071: *           Before entry with UPLO = 'L' or 'l', the array AP must
072: *           contain the lower triangular matrix packed sequentially,
073: *           column by column, so that AP( 1 ) contains a( 1, 1 ),
074: *           AP( 2 ) and AP( 3 ) contain a( 2, 1 ) and a( 3, 1 )
075: *           respectively, and so on.
076: *           Note that when  DIAG = 'U' or 'u', the diagonal elements of
077: *           A are not referenced, but are assumed to be unity.
078: *           Unchanged on exit.
079: *
080: *  X      - DOUBLE PRECISION array of dimension at least
081: *           ( 1 + ( n - 1 )*abs( INCX ) ).
082: *           Before entry, the incremented array X must contain the n
083: *           element right-hand side vector b. On exit, X is overwritten
084: *           with the solution vector x.
085: *
086: *  INCX   - INTEGER.
087: *           On entry, INCX specifies the increment for the elements of
088: *           X. INCX must not be zero.
089: *           Unchanged on exit.
090: *
091: *  Further Details
092: *  ===============
093: *
094: *  Level 2 Blas routine.
095: *
096: *  -- Written on 22-October-1986.
097: *     Jack Dongarra, Argonne National Lab.
098: *     Jeremy Du Croz, Nag Central Office.
099: *     Sven Hammarling, Nag Central Office.
100: *     Richard Hanson, Sandia National Labs.
101: *
102: *  =====================================================================
103: *
104: *     .. Parameters ..
105:       DOUBLE PRECISION ZERO
106:       PARAMETER (ZERO=0.0D+0)
107: *     ..
108: *     .. Local Scalars ..
109:       DOUBLE PRECISION TEMP
110:       INTEGER I,INFO,IX,J,JX,K,KK,KX
111:       LOGICAL NOUNIT
112: *     ..
113: *     .. External Functions ..
114:       LOGICAL LSAME
115:       EXTERNAL LSAME
116: *     ..
117: *     .. External Subroutines ..
118:       EXTERNAL XERBLA
119: *     ..
120: *
121: *     Test the input parameters.
122: *
123:       INFO = 0
124:       IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN
125:           INFO = 1
126:       ELSE IF (.NOT.LSAME(TRANS,'N') .AND. .NOT.LSAME(TRANS,'T') .AND.
127:      +         .NOT.LSAME(TRANS,'C')) THEN
128:           INFO = 2
129:       ELSE IF (.NOT.LSAME(DIAG,'U') .AND. .NOT.LSAME(DIAG,'N')) THEN
130:           INFO = 3
131:       ELSE IF (N.LT.0) THEN
132:           INFO = 4
133:       ELSE IF (INCX.EQ.0) THEN
134:           INFO = 7
135:       END IF
136:       IF (INFO.NE.0) THEN
137:           CALL XERBLA('DTPSV ',INFO)
138:           RETURN
139:       END IF
140: *
141: *     Quick return if possible.
142: *
143:       IF (N.EQ.0) RETURN
144: *
145:       NOUNIT = LSAME(DIAG,'N')
146: *
147: *     Set up the start point in X if the increment is not unity. This
148: *     will be  ( N - 1 )*INCX  too small for descending loops.
149: *
150:       IF (INCX.LE.0) THEN
151:           KX = 1 - (N-1)*INCX
152:       ELSE IF (INCX.NE.1) THEN
153:           KX = 1
154:       END IF
155: *
156: *     Start the operations. In this version the elements of AP are
157: *     accessed sequentially with one pass through AP.
158: *
159:       IF (LSAME(TRANS,'N')) THEN
160: *
161: *        Form  x := inv( A )*x.
162: *
163:           IF (LSAME(UPLO,'U')) THEN
164:               KK = (N* (N+1))/2
165:               IF (INCX.EQ.1) THEN
166:                   DO 20 J = N,1,-1
167:                       IF (X(J).NE.ZERO) THEN
168:                           IF (NOUNIT) X(J) = X(J)/AP(KK)
169:                           TEMP = X(J)
170:                           K = KK - 1
171:                           DO 10 I = J - 1,1,-1
172:                               X(I) = X(I) - TEMP*AP(K)
173:                               K = K - 1
174:    10                     CONTINUE
175:                       END IF
176:                       KK = KK - J
177:    20             CONTINUE
178:               ELSE
179:                   JX = KX + (N-1)*INCX
180:                   DO 40 J = N,1,-1
181:                       IF (X(JX).NE.ZERO) THEN
182:                           IF (NOUNIT) X(JX) = X(JX)/AP(KK)
183:                           TEMP = X(JX)
184:                           IX = JX
185:                           DO 30 K = KK - 1,KK - J + 1,-1
186:                               IX = IX - INCX
187:                               X(IX) = X(IX) - TEMP*AP(K)
188:    30                     CONTINUE
189:                       END IF
190:                       JX = JX - INCX
191:                       KK = KK - J
192:    40             CONTINUE
193:               END IF
194:           ELSE
195:               KK = 1
196:               IF (INCX.EQ.1) THEN
197:                   DO 60 J = 1,N
198:                       IF (X(J).NE.ZERO) THEN
199:                           IF (NOUNIT) X(J) = X(J)/AP(KK)
200:                           TEMP = X(J)
201:                           K = KK + 1
202:                           DO 50 I = J + 1,N
203:                               X(I) = X(I) - TEMP*AP(K)
204:                               K = K + 1
205:    50                     CONTINUE
206:                       END IF
207:                       KK = KK + (N-J+1)
208:    60             CONTINUE
209:               ELSE
210:                   JX = KX
211:                   DO 80 J = 1,N
212:                       IF (X(JX).NE.ZERO) THEN
213:                           IF (NOUNIT) X(JX) = X(JX)/AP(KK)
214:                           TEMP = X(JX)
215:                           IX = JX
216:                           DO 70 K = KK + 1,KK + N - J
217:                               IX = IX + INCX
218:                               X(IX) = X(IX) - TEMP*AP(K)
219:    70                     CONTINUE
220:                       END IF
221:                       JX = JX + INCX
222:                       KK = KK + (N-J+1)
223:    80             CONTINUE
224:               END IF
225:           END IF
226:       ELSE
227: *
228: *        Form  x := inv( A' )*x.
229: *
230:           IF (LSAME(UPLO,'U')) THEN
231:               KK = 1
232:               IF (INCX.EQ.1) THEN
233:                   DO 100 J = 1,N
234:                       TEMP = X(J)
235:                       K = KK
236:                       DO 90 I = 1,J - 1
237:                           TEMP = TEMP - AP(K)*X(I)
238:                           K = K + 1
239:    90                 CONTINUE
240:                       IF (NOUNIT) TEMP = TEMP/AP(KK+J-1)
241:                       X(J) = TEMP
242:                       KK = KK + J
243:   100             CONTINUE
244:               ELSE
245:                   JX = KX
246:                   DO 120 J = 1,N
247:                       TEMP = X(JX)
248:                       IX = KX
249:                       DO 110 K = KK,KK + J - 2
250:                           TEMP = TEMP - AP(K)*X(IX)
251:                           IX = IX + INCX
252:   110                 CONTINUE
253:                       IF (NOUNIT) TEMP = TEMP/AP(KK+J-1)
254:                       X(JX) = TEMP
255:                       JX = JX + INCX
256:                       KK = KK + J
257:   120             CONTINUE
258:               END IF
259:           ELSE
260:               KK = (N* (N+1))/2
261:               IF (INCX.EQ.1) THEN
262:                   DO 140 J = N,1,-1
263:                       TEMP = X(J)
264:                       K = KK
265:                       DO 130 I = N,J + 1,-1
266:                           TEMP = TEMP - AP(K)*X(I)
267:                           K = K - 1
268:   130                 CONTINUE
269:                       IF (NOUNIT) TEMP = TEMP/AP(KK-N+J)
270:                       X(J) = TEMP
271:                       KK = KK - (N-J+1)
272:   140             CONTINUE
273:               ELSE
274:                   KX = KX + (N-1)*INCX
275:                   JX = KX
276:                   DO 160 J = N,1,-1
277:                       TEMP = X(JX)
278:                       IX = KX
279:                       DO 150 K = KK,KK - (N- (J+1)),-1
280:                           TEMP = TEMP - AP(K)*X(IX)
281:                           IX = IX - INCX
282:   150                 CONTINUE
283:                       IF (NOUNIT) TEMP = TEMP/AP(KK-N+J)
284:                       X(JX) = TEMP
285:                       JX = JX - INCX
286:                       KK = KK - (N-J+1)
287:   160             CONTINUE
288:               END IF
289:           END IF
290:       END IF
291: *
292:       RETURN
293: *
294: *     End of DTPSV .
295: *
296:       END
297: ```