001:       SUBROUTINE CSPSV( UPLO, N, NRHS, AP, 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:       CHARACTER          UPLO
010:       INTEGER            INFO, LDB, N, NRHS
011: *     ..
012: *     .. Array Arguments ..
013:       INTEGER            IPIV( * )
014:       COMPLEX            AP( * ), B( LDB, * )
015: *     ..
016: *
017: *  Purpose
018: *  =======
019: *
020: *  CSPSV computes the solution to a complex system of linear equations
021: *     A * X = B,
022: *  where A is an N-by-N symmetric matrix stored in packed format and X
023: *  and B are N-by-NRHS matrices.
024: *
025: *  The diagonal pivoting method is used to factor A as
026: *     A = U * D * U**T,  if UPLO = 'U', or
027: *     A = L * D * L**T,  if UPLO = 'L',
028: *  where U (or L) is a product of permutation and unit upper (lower)
029: *  triangular matrices, D is symmetric and block diagonal with 1-by-1
030: *  and 2-by-2 diagonal blocks.  The factored form of A is then used to
031: *  solve the system of equations A * X = B.
032: *
033: *  Arguments
034: *  =========
035: *
036: *  UPLO    (input) CHARACTER*1
037: *          = 'U':  Upper triangle of A is stored;
038: *          = 'L':  Lower triangle of A is stored.
039: *
040: *  N       (input) INTEGER
041: *          The number of linear equations, i.e., the order of the
042: *          matrix A.  N >= 0.
043: *
044: *  NRHS    (input) INTEGER
045: *          The number of right hand sides, i.e., the number of columns
046: *          of the matrix B.  NRHS >= 0.
047: *
048: *  AP      (input/output) COMPLEX array, dimension (N*(N+1)/2)
049: *          On entry, the upper or lower triangle of the symmetric matrix
050: *          A, packed columnwise in a linear array.  The j-th column of A
051: *          is stored in the array AP as follows:
052: *          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
053: *          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
054: *          See below for further details.
055: *
056: *          On exit, the block diagonal matrix D and the multipliers used
057: *          to obtain the factor U or L from the factorization
058: *          A = U*D*U**T or A = L*D*L**T as computed by CSPTRF, stored as
059: *          a packed triangular matrix in the same storage format as A.
060: *
061: *  IPIV    (output) INTEGER array, dimension (N)
062: *          Details of the interchanges and the block structure of D, as
063: *          determined by CSPTRF.  If IPIV(k) > 0, then rows and columns
064: *          k and IPIV(k) were interchanged, and D(k,k) is a 1-by-1
065: *          diagonal block.  If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0,
066: *          then rows and columns k-1 and -IPIV(k) were interchanged and
067: *          D(k-1:k,k-1:k) is a 2-by-2 diagonal block.  If UPLO = 'L' and
068: *          IPIV(k) = IPIV(k+1) < 0, then rows and columns k+1 and
069: *          -IPIV(k) were interchanged and D(k:k+1,k:k+1) is a 2-by-2
070: *          diagonal block.
071: *
072: *  B       (input/output) COMPLEX array, dimension (LDB,NRHS)
073: *          On entry, the N-by-NRHS right hand side matrix B.
074: *          On exit, if INFO = 0, the N-by-NRHS solution matrix X.
075: *
076: *  LDB     (input) INTEGER
077: *          The leading dimension of the array B.  LDB >= max(1,N).
078: *
079: *  INFO    (output) INTEGER
080: *          = 0:  successful exit
081: *          < 0:  if INFO = -i, the i-th argument had an illegal value
082: *          > 0:  if INFO = i, D(i,i) is exactly zero.  The factorization
083: *                has been completed, but the block diagonal matrix D is
084: *                exactly singular, so the solution could not be
085: *                computed.
086: *
087: *  Further Details
088: *  ===============
089: *
090: *  The packed storage scheme is illustrated by the following example
091: *  when N = 4, UPLO = 'U':
092: *
093: *  Two-dimensional storage of the symmetric matrix A:
094: *
095: *     a11 a12 a13 a14
096: *         a22 a23 a24
097: *             a33 a34     (aij = aji)
098: *                 a44
099: *
100: *  Packed storage of the upper triangle of A:
101: *
102: *  AP = [ a11, a12, a22, a13, a23, a33, a14, a24, a34, a44 ]
103: *
104: *  =====================================================================
105: *
106: *     .. External Functions ..
107:       LOGICAL            LSAME
108:       EXTERNAL           LSAME
109: *     ..
110: *     .. External Subroutines ..
111:       EXTERNAL           CSPTRF, CSPTRS, XERBLA
112: *     ..
113: *     .. Intrinsic Functions ..
114:       INTRINSIC          MAX
115: *     ..
116: *     .. Executable Statements ..
117: *
118: *     Test the input parameters.
119: *
120:       INFO = 0
121:       IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
122:          INFO = -1
123:       ELSE IF( N.LT.0 ) THEN
124:          INFO = -2
125:       ELSE IF( NRHS.LT.0 ) THEN
126:          INFO = -3
127:       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
128:          INFO = -7
129:       END IF
130:       IF( INFO.NE.0 ) THEN
131:          CALL XERBLA( 'CSPSV ', -INFO )
132:          RETURN
133:       END IF
134: *
135: *     Compute the factorization A = U*D*U' or A = L*D*L'.
136: *
137:       CALL CSPTRF( UPLO, N, AP, IPIV, INFO )
138:       IF( INFO.EQ.0 ) THEN
139: *
140: *        Solve the system A*X = B, overwriting B with X.
141: *
142:          CALL CSPTRS( UPLO, N, NRHS, AP, IPIV, B, LDB, INFO )
143: *
144:       END IF
145:       RETURN
146: *
147: *     End of CSPSV
148: *
149:       END
150: