      SUBROUTINE SPSLV(N,A,IA,JA,B,R,C,MAX,X,ITEMP,RTEMP,IERR)
C  ---------------------------------------------------------------------
C  SPSLV CALLS NSPIV1 WHICH USES SPARSE GAUSSIAN ELIMINATION WITH
C  COLUMN INTERCHANGES TO SOLVE THE LINEAR SYSTEM A X = B.  THE
C  ELIMINATION PHASE PERFORMS ROW OPERATIONS ON A AND B TO OBTAIN
C  A UNIT UPPER TRIANGULAR MATRIX U AND A VECTOR Y.  THE SOLUTION
C  PHASE SOLVES U X = Y.
C
C
C  INPUT ARGUMENTS---
C
C  N      INTEGER NUMBER OF EQUATIONS AND UNKNOWNS
C
C  A      REAL ARRAY WITH ONE ENTRY PER NONZERO IN A, CONTAINING THE
C         ACTUAL NONZEROES.  (SEE MATRIX STORAGE DESCRIPTION BELOW)
C
C  IA     INTEGER ARRAY OF N+1 ENTRIES CONTAINING ROW POINTERS TO A
C         (SEE MATRIX STORAGE DESCRIPTION BELOW)
C
C  JA     INTEGER ARRAY WITH ONE ENTRY PER NONZERO IN A, CONTAINING
C         COLUMN NUMBERS OF THE NONZEROES OF A.  (SEE MATRIX STORAGE
C         DESCRIPTION BELOW)
C
C  B      REAL ARRAY OF N ENTRIES CONTAINING RIGHT HAND SIDE DATA
C
C  R      INTEGER ARRAY OF N ENTRIES SPECIFYING THE ORDER OF THE
C         ROWS OF A (I.E., THE ELIMINATION ORDER FOR THE EQUATIONS)
C
C  C      INTEGER ARRAY OF N ENTRIES SPECIFYING THE ORDER OF THE
C         COLUMNS OF A.  C IS ALSO AN OUTPUT ARGUMENT
C
C  MAX    INTEGER NUMBER SPECIFYING MAXIMUM NUMBER OF OFF-DIAGONAL
C         NONZERO ENTRIES OF U WHICH MAY BE STORED
C
C  ITEMP  INTEGER ARRAY OF 3*N + MAX + 2 ENTRIES, FOR INTERNAL USE
C
C  RTEMP  REAL ARRAY OF N + MAX ENTRIES FOR INTERNAL USE
C
C
C  OUTPUT ARGUMENTS---
C
C  C      INTEGER ARRAY OF N ENTRIES SPECIFYING THE ORDER OF THE
C         COLUMNS OF U.  C IS ALSO AN INPUT ARGUMENT
C
C  X      REAL ARRAY OF N ENTRIES CONTAINING THE SOLUTION VECTOR
C
C  IERR   INTEGER NUMBER WHICH INDICATES ERROR CONDITIONS OR
C         THE ACTUAL NUMBER OF OFF-DIAGONAL ENTRIES IN U (FOR
C         SUCCESSFUL COMPLETION)
C
C         IERR VALUES ARE---
C
C         0 LT IERR             SUCCESSFUL COMPLETION. IERR=MAX(1,M)
C                               WHERE M IS THE NUMBER OF OFF-DIAGONAL
C                               NONZERO ENTRIES OF U.
C
C         IERR = 0              ERROR.  N IS LESS THAN OR EQUAL TO 0
C
C         -N LE IERR LT 0       ERROR.  ROW NUMBER IABS(IERR) OF A IS
C                               IS NULL
C
C         -2*N LE IERR LT -N    ERROR.  ROW NUMBER IABS(IERR+N) HAS A
C                               DUPLICATE ENTRY
C
C         -3*N LE IERR LT -2*N  ERROR.  ROW NUMBER IABS(IERR+2*N)
C                               HAS A ZERO PIVOT
C
C         -4*N LE IERR LT -3*N  ERROR.  ROW NUMBER IABS(IERR+3*N)
C                               EXCEEDS STORAGE
C
C
C  STORAGE OF SPARSE MATRICES---
C
C  THE SPARSE MATRIX A IS STORED USING THREE ARRAYS IA, JA, AND A.
C  THE ARRAY A CONTAINS THE NONZEROES OF THE MATRIX ROW-BY-ROW, NOT
C  NECESSARILY IN ORDER OF INCREASING COLUMN NUMBER.  THE ARRAY JA
C  CONTAINS THE COLUMN NUMBERS CORRESPONDING TO THE NONZEROES STORED
C  IN THE ARRAY A (I.E., IF THE NONZERO STORED IN A(K) IS IN
C  COLUMN J, THEN JA(K) = J).  THE ARRAY IA CONTAINS POINTERS TO THE
C  ROWS OF NONZEROES/COLUMN INDICES IN THE ARRAY A/JA (I.E.,
C  A(IA(I))/JA(IA(I)) IS THE FIRST ENTRY FOR ROW I IN THE ARRAY A/JA).
C  IA(N+1) IS SET SO THAT IA(N+1) - IA(1) = THE NUMBER OF NONZERO
C  ELEMENTS IN A.
C  ----------------------
      REAL A(1),B(1),X(1),RTEMP(1)
      INTEGER IA(1),JA(1),R(1),C(1),IC(1),ITEMP(1)
      INTEGER IU,JU,U,Y,P
C
      IERR = 0
      IF (N .LE. 0) RETURN
C
C  SET INDICES TO DIVIDE TEMPORARY STORAGE FOR NSPIV1
C
      Y = 1
      U = Y + N
      P = N + 1
      IU = P + N + 1
      JU = IU + N + 1
C
C  COMPUTE THE INVERSE PERMUTATION OF C
C
      DO 10 K = 1,N
      L = C(K)
   10 ITEMP(L) = K
C
C  CALL NSPIV1 TO PERFORM COMPUTATIONS
C
      CALL NSPIV1 (N,IA,JA,A,B,MAX,R,C,ITEMP(1),X,RTEMP(Y),ITEMP(P),
     *             ITEMP(IU),ITEMP(JU),RTEMP(U),IERR)
      IF (IERR .EQ. 0) IERR = 1
      RETURN
      END
