      SUBROUTINE SPORD(M,N,IA,R,W)
C     ---------------------------------------------------------
C     SPORD ORDERS THE ROWS OF AN MXN SPARSE MATRIX A,IA,JA
C     BY INCREASING LENGTH. THE ROW ORDERING IS GIVEN IN R.
C     ---------------------------------------------------------
C     W IS A WORK SPACE OF DIMENSION M+N+1.
C     -----------------
      INTEGER IA(1),R(M),W(1)
C
      NP1 = N + 1
      DO 10 NUM = 1,NP1
   10 W(NUM) = 0
C
      I = M
      DO 20 II = 1,M
      NUM = IA(I+1) - IA(I) + 1
      L = NP1 + I
      W(L) = W(NUM)
      W(NUM) = I
   20 I = I - 1
C
      NUM = 1
      K = W(NUM)
      DO 32 I = 1,M
   30 IF (K .NE. 0) GO TO 31
      NUM = NUM + 1
      K = W(NUM)
      GO TO 30
   31 R(I) = K
      L = NP1 + K
      K = W(L)
   32 CONTINUE
      RETURN
      END
