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='SSU-N00.txt'
      infile2='SSU-N90.txt'
      infile3='SSU-UP.txt'
      dt=0.005
      write(*,*)' assumed dt =',dt
c
      open(11,file=infile1,status='old')
c      open(11,file='00.txt',status='old')
        do i=1,5
          read(11,*)
        end do
        read(11,'(a80)')line
        write(*,*)line
        do i=1,36
          read(11,*)
        end do
        i=0
   10   in=i*8+1
        read(11,1000,end=15)(x(in+j),j=0,7)
 1000   format(8e10.4)
        i=i+1
        goto 10
   15   write(*,*)'i,in=',i,in
        nt=i*8-8
        write(*,*)'nt=',nt
      close(11)
c
      open(11,file=infile2,status='old')
        do i=1,5
          read(11,*)
        end do
        read(11,'(a80)')line
        write(*,*)line
        do i=1,36
          read(11,*)
        end do
        i=0
   20   in=i*8+1
        read(11,1000,end=25)(y(in+j),j=0,7)
        i=i+1
        goto 20
   25   write(*,*)'i,in=',i,in
        nt=i*8-8
        write(*,*)'nt=',nt
      close(11)
c
      open(11,file=infile3,status='old')
        do i=1,5
          read(11,*)
        end do
        read(11,'(a80)')line
        write(*,*)line
        do i=1,36
          read(11,*)
        end do
        i=0
   30   in=i*8+1
        read(11,1000,end=35)(z(in+j),j=0,7)
        i=i+1
        goto 30
   35   write(*,*)'i,in=',i,in
        nt=i*8-8
        write(*,*)'nt=',nt
      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
