      SUBROUTINE IPREP (NEQ, Y, RWORK, IA, JA, IPFLAG, F, JAC)
CLLL. OPTIMIZE
      EXTERNAL F, JAC
      INTEGER NEQ, IA, JA, IPFLAG
      INTEGER ILLIN, INIT, LYH, LEWT, LACOR, LSAVF, LWM, LIWM,
     1   MXSTEP, MXHNIL, NHNIL, NTREP, NSLAST, NYH, IOWNS
      INTEGER ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, METH, MITER, 
     1   MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU
      INTEGER IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP,
     1   IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA,
     2   LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ,
     3   NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU
      INTEGER I, IMAX, LEWTN, LYHD, LYHN
      DOUBLE PRECISION Y, RWORK
      DOUBLE PRECISION ROWNS, 
     1   CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND
      DOUBLE PRECISION RLSS
      DIMENSION NEQ(1), Y(1), RWORK(1), IA(1), JA(1)
      COMMON /LS0001/ ROWNS(209),
     1   CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND,
     2   ILLIN, INIT, LYH, LEWT, LACOR, LSAVF, LWM, LIWM,
     3   MXSTEP, MXHNIL, NHNIL, NTREP, NSLAST, NYH, IOWNS(6),
     4   ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, METH, MITER,
     5   MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU
      COMMON /LSS001/ RLSS(6),
     1   IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP,
     2   IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA,
     3   LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ,
     4   NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU
C-----------------------------------------------------------------------
C THIS ROUTINE SERVES AS AN INTERFACE BETWEEN THE DRIVER AND
C SUBROUTINE PREP.  IT IS CALLED ONLY IF MITER IS 1 OR 2.
C TASKS PERFORMED HERE ARE..
C  * CALL PREP,
C  * RESET THE REQUIRED WM SEGMENT LENGTH LENWK,
C  * MOVE YH BACK TO ITS FINAL LOCATION (FOLLOWING WM IN RWORK),
C  * RESET POINTERS FOR YH, SAVF, EWT, AND ACOR, AND
C  * MOVE EWT TO ITS NEW POSITION IF ISTATE = 1.
C IPFLAG IS AN OUTPUT ERROR INDICATION FLAG.  IPFLAG = 0 IF THERE WAS 
C NO TROUBLE, AND IPFLAG IS THE VALUE OF THE PREP ERROR FLAG IPPER
C IF THERE WAS TROUBLE IN SUBROUTINE PREP.
C-----------------------------------------------------------------------
      IPFLAG = 0
C CALL PREP TO DO MATRIX PREPROCESSING OPERATIONS. ---------------------
      CALL PREP (NEQ, Y, RWORK(LYH), RWORK(LSAVF), RWORK(LEWT),
     1   RWORK(LACOR), IA, JA, RWORK(LWM), RWORK(LWM), IPFLAG, F, JAC)
      LENWK = MAX0(LREQ,LWMIN)
      IF (IPFLAG .LT. 0) RETURN
C IF PREP WAS SUCCESSFUL, MOVE YH TO END OF REQUIRED SPACE FOR WM. -----
      LYHN = LWM + LENWK
      IF (LYHN .GT. LYH) RETURN
      LYHD = LYH - LYHN
      IF (LYHD .EQ. 0) GO TO 20
      IMAX = LYHN - 1 + LENYHM
      DO 10 I = LYHN,IMAX
 10     RWORK(I) = RWORK(I+LYHD)
      LYH = LYHN
C RESET POINTERS FOR SAVF, EWT, AND ACOR. ------------------------------
 20   LSAVF = LYH + LENYH
      LEWTN = LSAVF + N
      LACOR = LEWTN + N
      IF (ISTATC .EQ. 3) GO TO 40
C IF ISTATE = 1, MOVE EWT (LEFT) TO ITS NEW POSITION. ------------------
      IF (LEWTN .GT. LEWT) RETURN
      DO 30 I = 1,N 
 30     RWORK(I+LEWTN-1) = RWORK(I+LEWT-1)
 40   LEWT = LEWTN
      RETURN
C----------------------- END OF SUBROUTINE IPREP -----------------------
      END 
