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 slip(ML,MW),rake(ML,MW),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
      pi=datan(1.d0)*4.d0
      OPEN(12,FILE='rateA-out5.csv',STATUS='unknown')
      do 200 k=2,48
        do 220 iW=1,NW
        do 220 iL=1,NL
          s35 =slp35(k,iL,iW)
          s125=slp125(k,iL,iW)
          slip(iL,iW)=dsqrt(s35*s35+s125*s125)/2.d0
          if(s35.ne.0.d0)then
            rake(iL,iW)=datan(s125/s35)*180.d0/pi+35.d0
          else
            rake(iL,iW)=90.d0
          end if
  220   continue
        write(12,*)'Slip (m) and Rake (Deg) of Time Window',k-1
        write(12,1000)(iL,iL=1,NL)
 1000   format('slip',100(',L',i2))
        do 240 iW=1,NW
          write(12,1100)iW,(slip(iL,iW),iL=1,NL)
 1100     format('W',i2,100(',',f10.5))
  240   continue
        write(12,1020)(iL,iL=1,NL)
 1020   format('rake',100(',L',i2))
        do 260 iW=1,NW
          write(12,1100)iW,(rake(iL,iW),iL=1,NL)
  260   continue
  200 continue
c
      CLOSE(12)
c
      stop
      END

