      SUBROUTINE DPSLV (N, M, A, KA, B, KB, IERR)
C     ******************************************************************
C     PARTIAL PIVOT GAUSS SOLUTION OF LINEAR EQUATIONS
C     ******************************************************************
      DOUBLE PRECISION A(KA,N), B(KB,M)
      DOUBLE PRECISION C, P, ZERO
      DATA ZERO/0.D0/
C     -------------------
      NM1 = N - 1
      DO 33 K = 1,NM1
      KP1 = K + 1
C
C     SEARCH FOR THE K-TH PIVOT ELEMENT
C
      P = DABS(A(K,K))
      L = K
      DO 10 I = KP1,N
      C = DABS(A(I,K))
      IF (P .GE. C) GO TO 10
      P = C
      L = I
   10 CONTINUE
      IF (P .EQ. ZERO) GO TO 100
C
C     INTERCHANGING ROWS K AND L
C
      IF (K .EQ. L) GO TO 30
      DO 20 J = K,N
      C = A(K,J)
      A(K,J) = A(L,J)
   20 A(L,J) = C
      DO 21 J = 1,M
      C = B(K,J)
      B(K,J) = B(L,J)
   21 B(L,J) = C
C
C     ELIMINATE THE COEFFICIENTS OF X(K) IN THE ROWS I = K+1,...,N
C
   30 P = A(K,K)
      DO 33 I = KP1,N
      C = A(I,K)/P
      DO 31 J = KP1,N
   31 A(I,J) = A(I,J) - C*A(K,J)
      DO 32 J = 1,M
   32 B(I,J) = B(I,J) - C*B(K,J)
   33 CONTINUE
      IF (A(N,N) .EQ. ZERO) GO TO 100
C
C     BACKSOLVE THE TRIANGULAR SET OF EQUATIONS
C
      DO 42 J = 1,M
      K = N
      KM1 = NM1
      DO 41 L = 2,N
      B(K,J) = B(K,J)/A(K,K)
      C = B(K,J)
      DO 40 I = 1,KM1
   40 B(I,J) = B(I,J) - C*A(I,K)
      K = KM1
   41 KM1 = K - 1
   42 B(1,J) = B(1,J)/A(1,1)
      IERR = 0
      RETURN
C
C     ERROR RETURN
C
  100 IERR = 1
      RETURN
      END
