      SUBROUTINE DPLE (ROWK,N,B,C,D,IP,IERR)
C     ******************************************************************
C     SOLUTION OF LINEAR EQUATIONS WITH REDUCED STORAGE
C     ******************************************************************
      DOUBLE PRECISION B(N),C(N),D(1)
      INTEGER IP(1)
      DOUBLE PRECISION BK,CJ,CK,C1,DKJ,ZERO
      EXTERNAL ROWK
      DATA ZERO/0.D0/
C
C     SET THE NECESSARY CONSTANTS
C
      IERR = 0
      NP1 = N + 1
      MAX = N*N/4 + N + 3
      K = 1
      IFLAG = -1
C
C     GET THE FIRST COLUMN OF THE TRANSPOSED SYSTEM
C
      CALL ROWK(N,1,C)
      BK = B(1)
C
      IF (N .GT. 1) GO TO 10
      IF (C(1) .EQ. ZERO) GO TO 200
      C(1) = BK/C(1)
      RETURN
C
C     FIND THE PIVOT FOR COLUMN 1
C
   10 M = 1
      DO 20 I = 2,N
      IF (DABS(C(M)) .LT. DABS(C(I))) M = I
   20 CONTINUE
C
      IP(1) = M
      C1 = C(M)
      C(M) = C(1)
      C(1) = C1
      IF (C(1) .EQ. ZERO) GO TO 200
C
C     FIND THE FIRST ELEMENTARY MATRIX AND STORE IT IN D
C
      DO 30 I = 2,N
   30 D(I-1) = -C(I)/C(1)
      D(N) = BK/C(1)
C
C     K LOOP - EACH K FOR A NEW COLUMN OF THE TRANSPOSED SYSTEM
C
      DO 120 K = 2,N
      KP1 = K + 1
      KM1 = K - 1
C
C       GET COLUMN K
C
      CALL ROWK(N,K,C)
      DO 40 J = 1,KM1
      M = IP(J)
      CJ = C(J)
      C(J) = C(M)
   40 C(M) = CJ
      BK = B(K)
C
      IFLAG = -IFLAG
      LCOL = NP1 - K
      LCOLP1 = LCOL + 1
      LASTM1 = 1
      LAST = MAX - N + K
      IF (K .EQ. 2) GO TO 50
C
      LASTM1 = MAX - N + KM1
      IF (IFLAG .LT. 0) LAST = LAST - N + K - 2
      IF (IFLAG .GT. 0) LASTM1 = LASTM1 - N + K - 3
C
C     J LOOP - EFFECT OF COLUMNS 1 TO K-1 OF L-INVERSE
C
   50 DO 61 J = 1,KM1
      CJ = C(J)
      IJ = (J-1)*LCOLP1
      IF (J .EQ. KM1) IJ = LASTM1 - 1
C
C     I LOOP - EFFECT OF L-INVERSE ON ROWS K TO N+1
C
      DO 60 I = K,N
      IJ = IJ + 1
   60 C(I) = C(I) + D(IJ)*CJ
   61 BK = BK - D(IJ+1)*CJ
C
C       K=N CASE
C
      M = K
      IF (K .LT. N) GO TO 70
      IF (C(K) .EQ. ZERO) GO TO 200
      D(LAST) = BK/C(K)
      GO TO 90
C
C     FIND THE PIVOT
C
   70 DO 71 I = KP1,N
      IF (DABS(C(M)) .LT. DABS(C(I))) M = I
   71 CONTINUE
C
      IP(K) = M
      CK = C(M)
      C(M) = C(K)
      C(K) = CK
      IF (C(K) .EQ. ZERO) GO TO 200
C
C     FIND THE K-TH ELEMENTARY MATRIX
C
      IK = LAST
      DO 80 I = KP1,N
      D(IK) = -C(I)/C(K)
   80 IK = IK + 1
      D(IK) = BK/C(K)
C
C     FORM THE PRODUCT OF THE ELEMENTARY MATRICES
C
   90 DO 110 J = 1,KM1
      KJOLD = J*LCOLP1 + K - NP1
      MJOLD = KJOLD + M - K
      IJ = (J-1)*LCOL
      IJOLD = IJ + J
      IF (J .NE. KM1) GO TO 100
C
      KJOLD = LASTM1
      MJOLD = LASTM1 + M - K
      IJOLD = LASTM1
C
  100 IK = LAST - 1
      DKJ = D(MJOLD)
      D(MJOLD) = D(KJOLD)
      DO 110 I = KP1,NP1
      IJ = IJ + 1
      IJOLD = IJOLD + 1
      IK = IK + 1
      D(IJ) = D(IJOLD) + D(IK)*DKJ
  110 CONTINUE
  120 CONTINUE
C
      LAST = MAX
      IF (IFLAG .LT. 0) LAST = MAX - 2
      D(N) = D(LAST)
C
C     INSERT THE SOLUTION IN C
C
      DO 130 I = 1,N
  130 C(I) = D(I)
C
      NM1 = N - 1
      DO 140 I = 1,NM1
      K = N - I
      M = IP(K)
      CK = C(K)
      C(K) = C(M)
  140 C(M) = CK
      RETURN
C
C     THE SYSTEM IS SINGULAR
C
  200 IERR = K
      RETURN
      END
