      Subroutine INTERP(Data)
c
c ***********************************************************************
c *                                                                     *
c *        Subroutine INTERP - To enable the user to interpolate        *
c *        values from data currently inside PLTPRG.  The user can      *
c *        use straight line, cubic spline, parametric spline           *
c *        (3 types), or a least-squares-fit polynomial to fit the      *
c *        existing data, for interpolation and extrapolation.  The     *
c *        interpolated values can be stored back as data, if desired.  *
c *                                                                     *
c *          Programmed by Steven C. Fisher, DTNSRDC Code 1522          *
c *                                                                     *
c ***********************************************************************
c
      Include 'Cmain'
c
      Virtual Data(1)
      Dimension Xvals(Npt_Max),Yvals(Npt_Max),Coefs(Npt_Max),
     $          Tvals(Npt_Max),Coefy(Npt_Max),Xloc(1),Yloc(1)
      Equivalence (Xloc(1),Coefy(1)),(Tvals(1),Yloc(1))
c
c           Get the data to interpolate, the fit, and the values
c           to interpolate at
c
      Call Initrp(Data,Ix,Iy,Npt,Xvals,Numbr,Xloc,Nxloc,
     $                  Icheck,Iorder,Iflag)
c
      If (Iflag .EQ. 1) Return
c
c        Compute the interpolated data (depending upon the fit used)
c
      If (Icheck .EQ. 1) Then
c
c         Straight line fit
c
         Istart = 2
         Do 40 I=1,Numbr
            Do 30 J=Istart,Npt
               If (Xvals(I) .LE. X(J) .OR. J .EQ. Npt) Go To 35
30          Continue
35          Continue
            Deltax = X(J) - X(J-1)
            If (Deltax .EQ. 0) Deltax = 1E-20
            Yvals(I) = (Y(J)-Y(J-1)) / Deltax * (Xvals(I)-X(J)) +Y(J)
            Istart = J
40       Continue
c
      Else If (Icheck .EQ. 2) Then
c
c          Least squares fit
c
         Call Lsqfit(X,Y,Npt,Iorder,Coefs)
         Call Lseval(Xvals,Yvals,Numbr,Iorder,Coefs)
c
      Else If (Icheck .EQ. 3) Then
c
c          Cubic spline fit
c
         Call Csplin(X,Y,Npt,Coefs)
         Call Cseval(Xvals,Yvals,Numbr,X,Y,Npt,Coefs)
c
      Else If (Icheck .LT. 7) Then
c
c          Parametric spline fit
c
         Itype = 1
         If (Icheck .EQ. 5) Itype = 2
         Call Psplin(X,Y,Npt,Tvals,Coefs,Coefy,Itype)
         Call Pseval(Xvals,Yvals,Numbr,X,Y,Npt,Tvals,Coefs,Coefy)
c
      Else If (Icheck .EQ. 7) Then
         Call Lsqseg(Xvals,Yvals,Numbr,X,Y,Npt,Iorder)
c
      Else If (Icheck .GE. 8) Then
c
c               Least squares spline fit
c
         Call Lsqspl(Xloc,Yloc,Nxloc,X,Y,Npt,Coefs,Icheck-7)
         Call Lssgev(Xvals,Yvals,Numbr,Xloc,Yloc,Nxloc,Coefs)
      End If
c
c          Write out the data values
c
      Call Prout(Data,Xvals,Yvals,Numbr,Ix,Iy,Icheck,Iorder,Coefs)
c
      Return
      End
