001:       SUBROUTINE CGESV( N, NRHS, A, LDA, IPIV, B, LDB, INFO )
002: *
003: *  -- LAPACK driver 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            INFO, LDA, LDB, N, NRHS
010: *     ..
011: *     .. Array Arguments ..
012:       INTEGER            IPIV( * )
013:       COMPLEX            A( LDA, * ), B( LDB, * )
014: *     ..
015: *
016: *  Purpose
017: *  =======
018: *
019: *  CGESV computes the solution to a complex system of linear equations
020: *     A * X = B,
021: *  where A is an N-by-N matrix and X and B are N-by-NRHS matrices.
022: *
023: *  The LU decomposition with partial pivoting and row interchanges is
024: *  used to factor A as
025: *     A = P * L * U,
026: *  where P is a permutation matrix, L is unit lower triangular, and U is
027: *  upper triangular.  The factored form of A is then used to solve the
028: *  system of equations A * X = B.
029: *
030: *  Arguments
031: *  =========
032: *
033: *  N       (input) INTEGER
034: *          The number of linear equations, i.e., the order of the
035: *          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/output) COMPLEX array, dimension (LDA,N)
042: *          On entry, the N-by-N coefficient matrix A.
043: *          On exit, the factors L and U from the factorization
044: *          A = P*L*U; the unit diagonal elements of L are not stored.
045: *
046: *  LDA     (input) INTEGER
047: *          The leading dimension of the array A.  LDA >= max(1,N).
048: *
049: *  IPIV    (output) INTEGER array, dimension (N)
050: *          The pivot indices that define the permutation matrix P;
051: *          row i of the matrix was interchanged with row IPIV(i).
052: *
053: *  B       (input/output) COMPLEX array, dimension (LDB,NRHS)
054: *          On entry, the N-by-NRHS matrix of right hand side matrix B.
055: *          On exit, if INFO = 0, the N-by-NRHS solution matrix X.
056: *
057: *  LDB     (input) INTEGER
058: *          The leading dimension of the array B.  LDB >= max(1,N).
059: *
060: *  INFO    (output) INTEGER
061: *          = 0:  successful exit
062: *          < 0:  if INFO = -i, the i-th argument had an illegal value
063: *          > 0:  if INFO = i, U(i,i) is exactly zero.  The factorization
064: *                has been completed, but the factor U is exactly
065: *                singular, so the solution could not be computed.
066: *
067: *  =====================================================================
068: *
069: *     .. External Subroutines ..
070:       EXTERNAL           CGETRF, CGETRS, XERBLA
071: *     ..
072: *     .. Intrinsic Functions ..
073:       INTRINSIC          MAX
074: *     ..
075: *     .. Executable Statements ..
076: *
077: *     Test the input parameters.
078: *
079:       INFO = 0
080:       IF( N.LT.0 ) THEN
081:          INFO = -1
082:       ELSE IF( NRHS.LT.0 ) THEN
083:          INFO = -2
084:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
085:          INFO = -4
086:       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
087:          INFO = -7
088:       END IF
089:       IF( INFO.NE.0 ) THEN
090:          CALL XERBLA( 'CGESV ', -INFO )
091:          RETURN
092:       END IF
093: *
094: *     Compute the LU factorization of A.
095: *
096:       CALL CGETRF( N, N, A, LDA, IPIV, INFO )
097:       IF( INFO.EQ.0 ) THEN
098: *
099: *        Solve the system A*X = B, overwriting B with X.
100: *
101:          CALL CGETRS( 'No transpose', N, NRHS, A, LDA, IPIV, B, LDB,
102:      $                INFO )
103:       END IF
104:       RETURN
105: *
106: *     End of CGESV
107: *
108:       END
109: