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(MW=23,ML=44)
      dimension slp35(50,ML,MW),slp125(50,ML,MW)
      dimension a1(5,ML,MW),a2(5,ML,MW)
c
      NW=22
      NL=43
      OPEN(11,FILE='rateA.dat',STATUS='OLD')
      do 100 iW=1,NW
      do 100 iL=1,NL
        READ(11,*)a1(1,iL,iW),a1(2,iL,iW)
     *           ,a1(3,iL,iW),a1(4,iL,iW),a1(5,iL,iW)
        READ(11,*)a2(1,iL,iW),a2(2,iL,iW)
     *           ,a2(3,iL,iW),a2(4,iL,iW),a2(5,iL,iW)
        do i=0,3
          jj=i*10
          READ(11,*)(slp35(j+jj,iL,iW),j=1,10)
        end do
        READ(11,*)(slp35(j+40,iL,iW),j=1,9)
c
        READ(11,*)
        READ(11,*)
        do i=0,3
          jj=i*10
          READ(11,*)(slp125(j+jj,iL,iW),j=1,10)
        end do
        READ(11,*)(slp125(j+40,iL,iW),j=1,9)
  100 continue
      CLOSE(11)
c
      OPEN(12,FILE='rateA-out4.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)')
      do 200 iW=1,NW
      do 200 iL=1,NL
        slip35=0.d0
        slip125=0.d0
        do k=1,49
          slip35=slip35+slp35(k,iL,iW)
          slip125=slip125+slp125(k,iL,iW)
        end do
        slip35=slip35/2.d0
        slip125=slip125/2.d0
        slipr=dsqrt(slip35*slip35+slip125*slip125)
        write(12,1100)iL,iW,a1(1,iL,iW),a1(2,iL,iW),a1(5,iL,iW)
     *               ,a2(5,iL,iW),slip35,slip125,slipr
 1100   format(2(i4,','),6(f10.5,','),f10.5)
  200 continue
      CLOSE(12)
c
      stop
      END

