```001:       SUBROUTINE CGTTS2( ITRANS, N, NRHS, DL, D, DU, DU2, IPIV, B, LDB )
002: *
003: *  -- LAPACK auxiliary routine (version 3.2) --
004: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
005: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
006: *     November 2006
007: *
008: *     .. Scalar Arguments ..
009:       INTEGER            ITRANS, LDB, N, NRHS
010: *     ..
011: *     .. Array Arguments ..
012:       INTEGER            IPIV( * )
013:       COMPLEX            B( LDB, * ), D( * ), DL( * ), DU( * ), DU2( * )
014: *     ..
015: *
016: *  Purpose
017: *  =======
018: *
019: *  CGTTS2 solves one of the systems of equations
020: *     A * X = B,  A**T * X = B,  or  A**H * X = B,
021: *  with a tridiagonal matrix A using the LU factorization computed
022: *  by CGTTRF.
023: *
024: *  Arguments
025: *  =========
026: *
027: *  ITRANS  (input) INTEGER
028: *          Specifies the form of the system of equations.
029: *          = 0:  A * X = B     (No transpose)
030: *          = 1:  A**T * X = B  (Transpose)
031: *          = 2:  A**H * X = B  (Conjugate transpose)
032: *
033: *  N       (input) INTEGER
034: *          The order of the matrix A.
035: *
036: *  NRHS    (input) INTEGER
037: *          The number of right hand sides, i.e., the number of columns
038: *          of the matrix B.  NRHS >= 0.
039: *
040: *  DL      (input) COMPLEX array, dimension (N-1)
041: *          The (n-1) multipliers that define the matrix L from the
042: *          LU factorization of A.
043: *
044: *  D       (input) COMPLEX array, dimension (N)
045: *          The n diagonal elements of the upper triangular matrix U from
046: *          the LU factorization of A.
047: *
048: *  DU      (input) COMPLEX array, dimension (N-1)
049: *          The (n-1) elements of the first super-diagonal of U.
050: *
051: *  DU2     (input) COMPLEX array, dimension (N-2)
052: *          The (n-2) elements of the second super-diagonal of U.
053: *
054: *  IPIV    (input) INTEGER array, dimension (N)
055: *          The pivot indices; for 1 <= i <= n, row i of the matrix was
056: *          interchanged with row IPIV(i).  IPIV(i) will always be either
057: *          i or i+1; IPIV(i) = i indicates a row interchange was not
058: *          required.
059: *
060: *  B       (input/output) COMPLEX array, dimension (LDB,NRHS)
061: *          On entry, the matrix of right hand side vectors B.
062: *          On exit, B is overwritten by the solution vectors X.
063: *
064: *  LDB     (input) INTEGER
065: *          The leading dimension of the array B.  LDB >= max(1,N).
066: *
067: *  =====================================================================
068: *
069: *     .. Local Scalars ..
070:       INTEGER            I, J
071:       COMPLEX            TEMP
072: *     ..
073: *     .. Intrinsic Functions ..
074:       INTRINSIC          CONJG
075: *     ..
076: *     .. Executable Statements ..
077: *
078: *     Quick return if possible
079: *
080:       IF( N.EQ.0 .OR. NRHS.EQ.0 )
081:      \$   RETURN
082: *
083:       IF( ITRANS.EQ.0 ) THEN
084: *
085: *        Solve A*X = B using the LU factorization of A,
086: *        overwriting each right hand side vector with its solution.
087: *
088:          IF( NRHS.LE.1 ) THEN
089:             J = 1
090:    10       CONTINUE
091: *
092: *           Solve L*x = b.
093: *
094:             DO 20 I = 1, N - 1
095:                IF( IPIV( I ).EQ.I ) THEN
096:                   B( I+1, J ) = B( I+1, J ) - DL( I )*B( I, J )
097:                ELSE
098:                   TEMP = B( I, J )
099:                   B( I, J ) = B( I+1, J )
100:                   B( I+1, J ) = TEMP - DL( I )*B( I, J )
101:                END IF
102:    20       CONTINUE
103: *
104: *           Solve U*x = b.
105: *
106:             B( N, J ) = B( N, J ) / D( N )
107:             IF( N.GT.1 )
108:      \$         B( N-1, J ) = ( B( N-1, J )-DU( N-1 )*B( N, J ) ) /
109:      \$                       D( N-1 )
110:             DO 30 I = N - 2, 1, -1
111:                B( I, J ) = ( B( I, J )-DU( I )*B( I+1, J )-DU2( I )*
112:      \$                     B( I+2, J ) ) / D( I )
113:    30       CONTINUE
114:             IF( J.LT.NRHS ) THEN
115:                J = J + 1
116:                GO TO 10
117:             END IF
118:          ELSE
119:             DO 60 J = 1, NRHS
120: *
121: *           Solve L*x = b.
122: *
123:                DO 40 I = 1, N - 1
124:                   IF( IPIV( I ).EQ.I ) THEN
125:                      B( I+1, J ) = B( I+1, J ) - DL( I )*B( I, J )
126:                   ELSE
127:                      TEMP = B( I, J )
128:                      B( I, J ) = B( I+1, J )
129:                      B( I+1, J ) = TEMP - DL( I )*B( I, J )
130:                   END IF
131:    40          CONTINUE
132: *
133: *           Solve U*x = b.
134: *
135:                B( N, J ) = B( N, J ) / D( N )
136:                IF( N.GT.1 )
137:      \$            B( N-1, J ) = ( B( N-1, J )-DU( N-1 )*B( N, J ) ) /
138:      \$                          D( N-1 )
139:                DO 50 I = N - 2, 1, -1
140:                   B( I, J ) = ( B( I, J )-DU( I )*B( I+1, J )-DU2( I )*
141:      \$                        B( I+2, J ) ) / D( I )
142:    50          CONTINUE
143:    60       CONTINUE
144:          END IF
145:       ELSE IF( ITRANS.EQ.1 ) THEN
146: *
147: *        Solve A**T * X = B.
148: *
149:          IF( NRHS.LE.1 ) THEN
150:             J = 1
151:    70       CONTINUE
152: *
153: *           Solve U**T * x = b.
154: *
155:             B( 1, J ) = B( 1, J ) / D( 1 )
156:             IF( N.GT.1 )
157:      \$         B( 2, J ) = ( B( 2, J )-DU( 1 )*B( 1, J ) ) / D( 2 )
158:             DO 80 I = 3, N
159:                B( I, J ) = ( B( I, J )-DU( I-1 )*B( I-1, J )-DU2( I-2 )*
160:      \$                     B( I-2, J ) ) / D( I )
161:    80       CONTINUE
162: *
163: *           Solve L**T * x = b.
164: *
165:             DO 90 I = N - 1, 1, -1
166:                IF( IPIV( I ).EQ.I ) THEN
167:                   B( I, J ) = B( I, J ) - DL( I )*B( I+1, J )
168:                ELSE
169:                   TEMP = B( I+1, J )
170:                   B( I+1, J ) = B( I, J ) - DL( I )*TEMP
171:                   B( I, J ) = TEMP
172:                END IF
173:    90       CONTINUE
174:             IF( J.LT.NRHS ) THEN
175:                J = J + 1
176:                GO TO 70
177:             END IF
178:          ELSE
179:             DO 120 J = 1, NRHS
180: *
181: *           Solve U**T * x = b.
182: *
183:                B( 1, J ) = B( 1, J ) / D( 1 )
184:                IF( N.GT.1 )
185:      \$            B( 2, J ) = ( B( 2, J )-DU( 1 )*B( 1, J ) ) / D( 2 )
186:                DO 100 I = 3, N
187:                   B( I, J ) = ( B( I, J )-DU( I-1 )*B( I-1, J )-
188:      \$                        DU2( I-2 )*B( I-2, J ) ) / D( I )
189:   100          CONTINUE
190: *
191: *           Solve L**T * x = b.
192: *
193:                DO 110 I = N - 1, 1, -1
194:                   IF( IPIV( I ).EQ.I ) THEN
195:                      B( I, J ) = B( I, J ) - DL( I )*B( I+1, J )
196:                   ELSE
197:                      TEMP = B( I+1, J )
198:                      B( I+1, J ) = B( I, J ) - DL( I )*TEMP
199:                      B( I, J ) = TEMP
200:                   END IF
201:   110          CONTINUE
202:   120       CONTINUE
203:          END IF
204:       ELSE
205: *
206: *        Solve A**H * X = B.
207: *
208:          IF( NRHS.LE.1 ) THEN
209:             J = 1
210:   130       CONTINUE
211: *
212: *           Solve U**H * x = b.
213: *
214:             B( 1, J ) = B( 1, J ) / CONJG( D( 1 ) )
215:             IF( N.GT.1 )
216:      \$         B( 2, J ) = ( B( 2, J )-CONJG( DU( 1 ) )*B( 1, J ) ) /
217:      \$                     CONJG( D( 2 ) )
218:             DO 140 I = 3, N
219:                B( I, J ) = ( B( I, J )-CONJG( DU( I-1 ) )*B( I-1, J )-
220:      \$                     CONJG( DU2( I-2 ) )*B( I-2, J ) ) /
221:      \$                     CONJG( D( I ) )
222:   140       CONTINUE
223: *
224: *           Solve L**H * x = b.
225: *
226:             DO 150 I = N - 1, 1, -1
227:                IF( IPIV( I ).EQ.I ) THEN
228:                   B( I, J ) = B( I, J ) - CONJG( DL( I ) )*B( I+1, J )
229:                ELSE
230:                   TEMP = B( I+1, J )
231:                   B( I+1, J ) = B( I, J ) - CONJG( DL( I ) )*TEMP
232:                   B( I, J ) = TEMP
233:                END IF
234:   150       CONTINUE
235:             IF( J.LT.NRHS ) THEN
236:                J = J + 1
237:                GO TO 130
238:             END IF
239:          ELSE
240:             DO 180 J = 1, NRHS
241: *
242: *           Solve U**H * x = b.
243: *
244:                B( 1, J ) = B( 1, J ) / CONJG( D( 1 ) )
245:                IF( N.GT.1 )
246:      \$            B( 2, J ) = ( B( 2, J )-CONJG( DU( 1 ) )*B( 1, J ) ) /
247:      \$                        CONJG( D( 2 ) )
248:                DO 160 I = 3, N
249:                   B( I, J ) = ( B( I, J )-CONJG( DU( I-1 ) )*
250:      \$                        B( I-1, J )-CONJG( DU2( I-2 ) )*
251:      \$                        B( I-2, J ) ) / CONJG( D( I ) )
252:   160          CONTINUE
253: *
254: *           Solve L**H * x = b.
255: *
256:                DO 170 I = N - 1, 1, -1
257:                   IF( IPIV( I ).EQ.I ) THEN
258:                      B( I, J ) = B( I, J ) - CONJG( DL( I ) )*
259:      \$                           B( I+1, J )
260:                   ELSE
261:                      TEMP = B( I+1, J )
262:                      B( I+1, J ) = B( I, J ) - CONJG( DL( I ) )*TEMP
263:                      B( I, J ) = TEMP
264:                   END IF
265:   170          CONTINUE
266:   180       CONTINUE
267:          END IF
268:       END IF
269: *
270: *     End of CGTTS2
271: *
272:       END
273: ```