C$TEST PREA
C TO RUN AS A MAIN PROGRAM REMOVE NEXT LINE
      SUBROUTINE PREA
C***********************************************************************
C
C  EXAMPLE OF USE OF THE PORT PROGRAM SPFOR
C
C***********************************************************************
       INTEGER N1, N2, N, MCP(500), MRP(500), MAXIW, IW, I
       INTEGER I1MACH, IREAD, IWRITE, ISTAK(19000)
       EXTERNAL QUEI
       COMMON /QUE/ A1, A2, N1, N2, N
       COMMON /CSTAK/ ISTAK
       IREAD = I1MACH(1)
       IWRITE = I1MACH(2)
       CALL ISTKIN(19000, 2)
  10   READ(IREAD,11)N1, N2
  11   FORMAT(2I3)
       IF (N1. EQ. 0) STOP
       WRITE(IWRITE,12)N1, N2
  12   FORMAT(4H N1=,I3,4H N2=,I3)
       N = (N1+1)*(N2+1)
C
C DETERMINE THE ORDERING
C
       CALL SPFOR(N, QUEI, MCP)
C
C GET THE WORK SPACE FROM THE STORAGE STACK
C
       MAXIW = ISTKQU(2)-3*N-50
       IW = ISTKGT(MAXIW, 2)
C
C DETERMINE THE SYMBOLIC FACTORIZATION
C
       DO 20 I=1,N
          MRP(I) = MCP(I)
  20   CONTINUE
       CALL SPFSF(N, MRP, MCP, QUEI, ISTAK(IW), MAXIW, ISIZE)
       WRITE(IWRITE,21)ISIZE
  21   FORMAT(34H SPACE NEEDED FOR DECOMPOSITION - ,I8)
C
C REDO THE FACTORIZATION WITHOUT PIVOTING
C
       DO 30 I = 1,N
          MCP(I) = I
          MRP(I) = I
  30   CONTINUE
       CALL SPFSF(N, MRP, MCP, QUEI, ISTAK(IW), MAXIW, ISIZE)
       WRITE(IWRITE, 31) ISIZE
  31   FORMAT(34H SPACE NEEDED WITHOUT ORDERING -   ,I8)
       CALL ISTKRL(1)
       GO TO 10
       END
       SUBROUTINE QUEI(I, JCOL, NUM)
       INTEGER I, NUM, JCOL(100), N, N1, N2, II, JJ, J
       COMMON /QUE/ A1, A2, N1, N2, N
       IF (I.NE.N) GO TO 20
C PROCESS LAST ROW
       DO 10 J=1, N
          JCOL(J) = J
  10   CONTINUE
       NUM = N
       RETURN
  20   N2P1=N2+1
C DETERMINE WHICH BLOCK
       II=(I-1)/N2P1
C DETERMINE THE POSITION IN THE BLOCK
       JJ = MOD(I-1, N2P1)
       JCOL(1) = I
C INSERT THE DIAGONAL ELEMENT
       NUM = 1
       IF (II .EQ. 0) GO TO 30
C THIS IS NOT THE FIRST ROW OF THE CURRENT BLOCK
       JCOL(2) = I-N2P1
       NUM = 2
  30   IF (JJ.EQ.0) GO TO 40
C THIS IS NOT THE FIRST ROW OF THE CURRENT BLOCK
       NUM = NUM+1
       JCOL(NUM) = I-1
  40   IF (JJ.EQ. N2) GO TO 50
C THIS IS NOT THE LAST ROW OF THE CURRENT BLOCK
       NUM=NUM+1
       JCOL(NUM)= I+1
  50   IF (II .EQ. N1) RETURN
       NUM = NUM +1
       JCOL(NUM) = I+N2P1
       RETURN
       END
C
C DATA FOR THE EXAMPLE IN THE PORT SHEET...  (REMOVE THE C
C IN COLUMN 1 BEFORE FEEDING THIS DATA TO THE PROGRAM ABOVE.)
C$DATA
C10 10
C15 15
C19 19
C 0  0
