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'
      read(*,'(a80)')infile1
      write(*,*)'Enter 2nd File Name of 3 Components'
      read(*,'(a80)')infile2
      write(*,*)'Enter 3rd File Name of 3 Components'
      read(*,'(a80)')infile3
c
      open(11,file=infile1,status='old')
c      open(11,file='00.txt',status='old')
        do i=1,23
          read(11,*)
        end do
        read(11,'(a80)')line
        write(*,*)line
        do i=1,21
          read(11,*)
        end do
        read(11,1000)nt,dt
 1000   format(i5,40x,f5.3)
        write(*,*)'nt & dt =',nt,dt
        do i=1,nt-8,8
          read(11,*)x(i),x(i+1),x(i+2),x(i+3)
     *             ,x(i+4),x(i+5),x(i+6),x(i+7)
        end do
      close(11)
c
      open(11,file=infile2,status='old')
c      open(11,file='00.txt',status='old')
        do i=1,23
          read(11,*)
        end do
        read(11,'(a80)')line
        write(*,*)line
        do i=1,21
          read(11,*)
        end do
        read(11,1000)nt,dt
        write(*,*)'nt & dt =',nt,dt
        do i=1,nt-8,8
          read(11,*)y(i),y(i+1),y(i+2),y(i+3)
     *             ,y(i+4),y(i+5),y(i+6),y(i+7)
        end do
      close(11)
c
      open(11,file=infile3,status='old')
c      open(11,file='00.txt',status='old')
        do i=1,23
          read(11,*)
        end do
        read(11,'(a80)')line
        write(*,*)line
        do i=1,21
          read(11,*)
        end do
        read(11,1000)nt,dt
        write(*,*)'nt & dt =',nt,dt
        do i=1,nt-8,8
          read(11,*)z(i),z(i+1),z(i+2),z(i+3)
     *             ,z(i+4),z(i+5),z(i+6),z(i+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
