C
C *** grfft.f is a FORTRAN code to obtain seismograms in the time domain,
C     which are computed from grpoint.f and grfault.f
C
      PROGRAM grfftsp
C
      IMPLICIT REAL*8(A-H,O-Z)
      PARAMETER(Msflt=1000)
      dimension slp35(50,Msflt),slp125(50,Msflt)
      dimension a1(5,Msflt),a2(5,Msflt)
c
      NW=22
      NL=43
      OPEN(11,FILE='rateA.dat',STATUS='OLD')
      do 100 n=1,NW*NL
        READ(11,*)a1(1,n),a1(2,n),a1(3,n),a1(4,n),a1(5,n)
        READ(11,*)a2(1,n),a2(2,n),a2(3,n),a2(4,n),a2(5,n),n2
        do i=0,3
          jj=i*10
          READ(11,*)(slp35(j+jj,n),j=1,10)
        end do
        READ(11,*)(slp35(j+40,n),j=1,9)
c
        READ(11,*)
        READ(11,*)
        do i=0,3
          jj=i*10
          READ(11,*)(slp125(j+jj,n),j=1,10)
        end do
        READ(11,*)(slp125(j+40,n),j=1,9)
  100 continue
      CLOSE(11)
c
      OPEN(12,FILE='rateA-out1.csv',STATUS='unknown')
      write(12,1000)
 1000 format('L No.,W No.,L Location(km),W Location (km),Depth(km)
     *,Rupture Time (s),Slip35 (m),Slip125 (m),Slip (m)')
      n=0
      do 200 iW=1,NW
      do 210 iL=1,NL
        n=n+1
        slip35=0.d0
        slip125=0.d0
        do j=1,49
          slip35=slip35+slp35(j,n)
          slip125=slip125+slp125(j,n)
        end do
        slip35=slip35/2.d0
        slip125=slip125/2.d0
        slipr=dsqrt(slip35*slip35+slip125*slip125)
        write(12,1100)iL,iW,a1(1,n),a1(2,n),a1(5,n),a2(5,n)
     *               ,slip35,slip125,slipr
 1100   format(2(i4,','),6(f10.5,','),f10.5)
  210 continue
  200 continue
      CLOSE(12)
C
      write(*,*)
      write(*,*)'Enter Fault Num. for Outputing Slip Rate Func (1-946)'
      read(*,*)Nout
      OPEN(12,FILE='rateA-out2.csv',STATUS='unknown')
      write(12,*)'time(s), SR35(m/s):',Nout,',SR125(m/s):',Nout
      do 300 it=1,49
        time=dfloat(it-1)*0.5d0
        write(12,*)time,',',slp35(it,Nout),',',slp125(it,Nout)
  300 continue
      CLOSE(12)
C
      stop
      END

