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