      Subroutine INTDER(Data)
c
c ***********************************************************************
c *                                                                     *
c *        Subroutine INTDER - To enable the user to integrate or       *
c *        compute the derivatives of values from data currently        *
c *        inside PLTPRG.  The user can use straight line, cubic        *
c *        spline, parametric spline (3 types), or a least-squares-fit  *
c *        polynomial to fit the existing data, for integration and     *
c *        computing the first and second derivative.  The resultant    *
c *        computed 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)
c
      Dimension Xvals(Nptmax),Yvals(Nptmax),Coefs(Nptmax),
     $          Tvals(Nptmax),Coefy(Nptmax),Tnew(Nptmax),Xloc(1),
     $          Yloc(1)
c
      Equivalence (Tnew(1),Yvals(1)),(Xloc(1),Coefy(1)),
     $            (Yloc(1),Coefy(151))
c
c          Get the columns to operate on, the X locations to evaluate the
c          integral/derivative at, the curve fit to use, and the operation
c          NOTE: The X and Y values to operate on are returned in the common
c          block MAIN variables X and Y
c
      Call Idget(Ix,Iy,Iopt,Ifit,Iorder,Npt,Xvals,Numbr,Data,Iflag,
     $           Xloc,Nxloc)
c
c          See if the user wished to abort this routine
c
      If (Iflag .EQ. 1) Return
c
c        Compute the data (depending upon the fit used)
c
      If (Ifit .EQ. 1) Then
c
c   ***  Straight line fit  ***
c
         If (Iopt .EQ. 1) Then
            Call Slintg(Xvals,Yvals,Numbr,X,Y,Npt)
         Else
            Call Slder(Xvals,Yvals,Numbr,X,Y,Npt)
         End If
c
      Else If (Ifit .EQ. 2) Then
c
c   ***  Least squares fit  ***
c
         Call Lsqfit(X,Y,Npt,Iorder,Coefs)
c
         Call Lsindf(Xvals,Yvals,Numbr,Coefs,Iorder,Iopt)
c
      Else If (Ifit .EQ. 3) Then
c
c   ***  Cubic spline fit  ***
c
         Call Csplin(X,Y,Npt,Coefs)
         If (Iopt .EQ. 1) Then
            Call Csint(Xvals,Yvals,Numbr,X,Y,Npt,Coefs)
         Else
            Call Csder(Xvals,Yvals,Numbr,X,Y,Npt,Coefs)
         End If
c
      Else If (Ifit .GE. 4 .AND. Ifit .LE. 6) Then
c
c   ***  Parametric spline fit  ***
c
         Itype = 1
         If (Ifit .EQ. 5) Itype = 2
c
c          Fit the parametric splines
c
         Call Psplin(X,Y,Npt,Tvals,Coefs,Coefy,Itype)
c
c          Get the T values at the new X values  (X and Y are funtions of T)
c
         Call Highpt(Tvals,X,Coefs,Npt)
         Call Csytox(Tnew,Xvals,Numbr,Tvals,X,Npt,Coefs)
c
c          Get the original data back (Might have been altered by
c          HIGHPT)
c
         Call Getvec(Data,Npoint,Ix,X,Npt)
         Call Getvec(Data,Npoint,Iy,Y,Npt)
         If (Ifit .NE. 6)  Call Sort(X,Y,Npt)
         Call Psplin(X,Y,Npt,Tvals,Coefs,Coefy,Itype)
c
c          Integrate/differentiate the parametric splines
c
         If (Iopt .EQ. 1) Then
            Call Psint(Xvals,Yvals,Tnew,Numbr,X,Y,Tvals,Npt,Coefs,Coefy)
         Else
            Call Psder(Xvals,Yvals,Tnew,Numbr,X,Y,Tvals,Npt,Coefs,Coefy)
         End If
c
      Else
         Call Lsqspl(Xloc,Yloc,Nxloc,X,Y,Npt,Coefs,Ifit-6)
         If (Iopt .EQ. 1) Then
            Call LSCINT(Xvals,Yvals,Numbr,Xloc,Yloc,Nxloc,Coefs)
         Else
            Call LSCDER(Xvals,Yvals,Numbr,Xloc,Yloc,Nxloc,Coefs)
         End If
      End If
c
c   ************  Write out the data values  *************
c
      Call Prout(Data,Xvals,Yvals,Numbr,Ix,Iy,Ifit,Iorder,Coefs)
c
      Return
      End
