```001:       SUBROUTINE DGETRS( TRANS, N, NRHS, A, LDA, IPIV, B, LDB, INFO )
002: *
003: *  -- LAPACK 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:       CHARACTER          TRANS
010:       INTEGER            INFO, LDA, LDB, N, NRHS
011: *     ..
012: *     .. Array Arguments ..
013:       INTEGER            IPIV( * )
014:       DOUBLE PRECISION   A( LDA, * ), B( LDB, * )
015: *     ..
016: *
017: *  Purpose
018: *  =======
019: *
020: *  DGETRS solves a system of linear equations
021: *     A * X = B  or  A' * X = B
022: *  with a general N-by-N matrix A using the LU factorization computed
023: *  by DGETRF.
024: *
025: *  Arguments
026: *  =========
027: *
028: *  TRANS   (input) CHARACTER*1
029: *          Specifies the form of the system of equations:
030: *          = 'N':  A * X = B  (No transpose)
031: *          = 'T':  A'* X = B  (Transpose)
032: *          = 'C':  A'* X = B  (Conjugate transpose = Transpose)
033: *
034: *  N       (input) INTEGER
035: *          The order of the matrix A.  N >= 0.
036: *
037: *  NRHS    (input) INTEGER
038: *          The number of right hand sides, i.e., the number of columns
039: *          of the matrix B.  NRHS >= 0.
040: *
041: *  A       (input) DOUBLE PRECISION array, dimension (LDA,N)
042: *          The factors L and U from the factorization A = P*L*U
043: *          as computed by DGETRF.
044: *
045: *  LDA     (input) INTEGER
046: *          The leading dimension of the array A.  LDA >= max(1,N).
047: *
048: *  IPIV    (input) INTEGER array, dimension (N)
049: *          The pivot indices from DGETRF; for 1<=i<=N, row i of the
050: *          matrix was interchanged with row IPIV(i).
051: *
052: *  B       (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
053: *          On entry, the right hand side matrix B.
054: *          On exit, the solution matrix X.
055: *
056: *  LDB     (input) INTEGER
057: *          The leading dimension of the array B.  LDB >= max(1,N).
058: *
059: *  INFO    (output) INTEGER
060: *          = 0:  successful exit
061: *          < 0:  if INFO = -i, the i-th argument had an illegal value
062: *
063: *  =====================================================================
064: *
065: *     .. Parameters ..
066:       DOUBLE PRECISION   ONE
067:       PARAMETER          ( ONE = 1.0D+0 )
068: *     ..
069: *     .. Local Scalars ..
070:       LOGICAL            NOTRAN
071: *     ..
072: *     .. External Functions ..
073:       LOGICAL            LSAME
074:       EXTERNAL           LSAME
075: *     ..
076: *     .. External Subroutines ..
077:       EXTERNAL           DLASWP, DTRSM, XERBLA
078: *     ..
079: *     .. Intrinsic Functions ..
080:       INTRINSIC          MAX
081: *     ..
082: *     .. Executable Statements ..
083: *
084: *     Test the input parameters.
085: *
086:       INFO = 0
087:       NOTRAN = LSAME( TRANS, 'N' )
088:       IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
089:      \$    LSAME( TRANS, 'C' ) ) THEN
090:          INFO = -1
091:       ELSE IF( N.LT.0 ) THEN
092:          INFO = -2
093:       ELSE IF( NRHS.LT.0 ) THEN
094:          INFO = -3
095:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
096:          INFO = -5
097:       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
098:          INFO = -8
099:       END IF
100:       IF( INFO.NE.0 ) THEN
101:          CALL XERBLA( 'DGETRS', -INFO )
102:          RETURN
103:       END IF
104: *
105: *     Quick return if possible
106: *
107:       IF( N.EQ.0 .OR. NRHS.EQ.0 )
108:      \$   RETURN
109: *
110:       IF( NOTRAN ) THEN
111: *
112: *        Solve A * X = B.
113: *
114: *        Apply row interchanges to the right hand sides.
115: *
116:          CALL DLASWP( NRHS, B, LDB, 1, N, IPIV, 1 )
117: *
118: *        Solve L*X = B, overwriting B with X.
119: *
120:          CALL DTRSM( 'Left', 'Lower', 'No transpose', 'Unit', N, NRHS,
121:      \$               ONE, A, LDA, B, LDB )
122: *
123: *        Solve U*X = B, overwriting B with X.
124: *
125:          CALL DTRSM( 'Left', 'Upper', 'No transpose', 'Non-unit', N,
126:      \$               NRHS, ONE, A, LDA, B, LDB )
127:       ELSE
128: *
129: *        Solve A' * X = B.
130: *
131: *        Solve U'*X = B, overwriting B with X.
132: *
133:          CALL DTRSM( 'Left', 'Upper', 'Transpose', 'Non-unit', N, NRHS,
134:      \$               ONE, A, LDA, B, LDB )
135: *
136: *        Solve L'*X = B, overwriting B with X.
137: *
138:          CALL DTRSM( 'Left', 'Lower', 'Transpose', 'Unit', N, NRHS, ONE,
139:      \$               A, LDA, B, LDB )
140: *
141: *        Apply row interchanges to the solution vectors.
142: *
143:          CALL DLASWP( NRHS, B, LDB, 1, N, IPIV, -1 )
144:       END IF
145: *
146:       RETURN
147: *
148: *     End of DGETRS
149: *
150:       END
151: ```