c
c *** Program reading COSMOS's CDMG-Type Strong Motion Data
c
      program read
c
      dimension X(33000),Y(33000),Z(33000)
      character line*80,infile1*80,infile2*80,infile3*80
c
      write(*,*)'Program for Reading CDMG-TYpe Strong Motion Data'
      write(*,*)
      write(*,*)'Enter 1st File Name of 3 Components'
c      read(*,'(a80)')infile1
      write(*,*)'Enter 2nd File Name of 3 Components'
c      read(*,'(a80)')infile2
      write(*,*)'Enter 3rd File Name of 3 Components'
c      read(*,'(a80)')infile3
      
      infile1='ARL-N00.txt'
      infile2='ARL-N90.txt'
      infile3='ARL-UP.txt'
      dt=0.02
      nt=3000
      write(*,*)' assumed dt & nt =',dt,nt
c
      open(11,file=infile1,status='old')
        do i=1,7
          read(11,*)
        end do
        read(11,'(a80)')line
        write(*,*)line
        do i=1,38
          read(11,*)
        end do
        do i=1,nt-8,8
          read(11,*)(x(i+j),j=0,7)
        end do
      close(11)
c
      open(11,file=infile2,status='old')
        do i=1,7
          read(11,*)
        end do
        read(11,'(a80)')line
        write(*,*)line
        do i=1,38
          read(11,*)
        end do
        do i=1,nt-8,8
          read(11,*)(y(i+j),j=0,7)
        end do
      close(11)
c
      open(11,file=infile3,status='old')
        do i=1,7
          read(11,*)
        end do
        read(11,'(a80)')line
        write(*,*)line
        do i=1,38
          read(11,*)
        end do
        do i=1,nt-8,8
          read(11,*)(z(i+j),j=0,7)
        end do
      close(11)
c
      write(*,*)
      write(*,*)'Enter Output Acceleration File Name (CSV format)'
      read(*,'(a80)')infile1
      open(11,file=infile1,status='unknown')
        do i=1,nt
          t=dt*(i-1)
          write(11,2000)t,x(i),y(i),z(i)
        end do
      close(11)
 2000 format(f7.3,3(',',f10.3))
c
      stop
      end
