C
      PROGRAM diff
C
      PARAMETER(MWV=33000)
      CHARACTER INFILE*20
      dimension X1(0:MWV),X2(0:MWV),X3(0:MWV),t(0:mwv)
      dimension acc(mwv),vel(mwv)
C
      WRITE(*,*)
      WRITE(*,*) 'Differentiation of displacement data'
      WRITE(*,*) 'Read from "***_dis" '
      WRITE(*,*) '------------------------------------------------------
     +-----------'
      WRITE(*,*)
C
C  Prompt for input RECON'ed file
C
      WRITE(*,1010) 
 1010 FORMAT(1X,'Enter name "***_dis')
      READ(*,1020) INFILE
 1020 FORMAT(A20)
C      
C *** Read input data file  ***
C
      OPEN(11,FILE=INFILE)
        i=1
   10   read(11,*,end=11)t(i),x1(i),x2(i),x3(i)
        i=i+1
        goto 10
   11 CLOSE(11)
c
      NT=i-1
      dt=t(2)-t(1)
      write(*,*)'NT and DT=',NT,DT
      dur=(nt-1)*dt
      write(*,*)'Duration (sec)=',dur
c
      x1(0)=0.0
      x2(0)=0.0
      x3(0)=0.0
      t(0)=-dt
      do i=1,nt-1
         t0=t(i-1)
         t1=t(i)
         t2=t(i+1)
         y0=x1(i-1)
         y1=x1(i)
         y2=x1(i+1)
         dy1=y1-y0
         dy2=y2-y1
         a=(dy2-dy1)/(2.0*dt*dt)
         b=dy1/dt-a*(t0+t1)
         vel(i)=2.0*a*t1+b
         acc(i)=2.0*a
      end do
c *** output ***
c
      write(*,*)
      write(*,*)'Skip Data (no=0; yes=skip number)?'
      read(*,*)iskip
      iskip=iskip+1
      WRITE(*,*)'vel' 
      OPEN(10,FILE='vel',STATUS='unknown')
      do i=1,nt,iskip
        write(10,2000)t(i),vel(i)
      end do
      CLOSE(10)
      WRITE(*,*)'acc' 
      OPEN(11,FILE='acc',STATUS='unknown')
      do i=1,nt,iskip
        write(11,2000)t(i),acc(i)
      end do
 2000 format(4e13.5)
      CLOSE(11)
c
        STOP
	END
