      program outputcsv

c2022.9.13 新本牧SEADOM7、CP50の現地データ対応用。その他の対応は知らない。
      
      character filein*1000,dumm*1000
      character fileout*10
      character cc*400,ccdum*22
      
      dimension aa(12)
      
      fileout='file00.csv'

      
  991 open(10,file="00-SEADOM7-CP50site.txt")
      
      read(10,*)
      read(10,*) nmax
      read(10,*)
      do nn=1,nmax
       IFLE=10+nn
       read(10,'(a1000)') filein
       open(IFLE,file=filein)
      end do
      read(10,*)
      read(10,*) zeoid
      read(10,*)
      read(10,*) tx,ty,tz,tth
      read(10,*)
      read(10,*) kcut
      read(10,*)
      read(10,*) ipass
      read(10,*)
      read(10,*) nstay
      
cヘッダ読み飛ばし
      do kk=1,kcut
       do nn=1,nmax
        IFLE=10+nn
        read(IFLE,*,end=990)
       end do
      end do

      nco=0
cCP5001部分
      do
       nco=nco+1
       write(*,*) 
       write(*,*) nco,'step'

c        read(11,*,end=990) (aa(ny),ny=0,11)
        read(11,'(a)',end=990) cc
       ip = index( cc, ',' )
       ccdum=cc(:ip-1)
       read(cc(ip+1:),*) (aa(j),j=1,11)

c-CP5001本体
        open(22,file='file02.csv')
        write(22,'(a25,7(a2,f12.3))') 
     _   ccdum,',',aa(7),',',aa(8),',',aa(9)-zeoid,',',
     _   aa(4),',',aa(5),',',aa(6)
        close(22)

c-CP5001旋回体
        open(23,file='file03.csv')
        write(23,'(a25,7(a2,f12.3))') 
     _   ccdum,',',aa(7),',',aa(8),',',aa(9)-zeoid,',',
     _   aa(11),',',aa(5),',',aa(6)
        close(23)

c-CP5001ブーム
        open(24,file='file04.csv')
        write(24,'(a25,7(a2,f12.3))') 
     _   ccdum,',',aa(7)+4.8*cos(aa(11)*3.1415/180.),',',
     _   aa(8)+4.8*sin(aa(11)*3.1415/180),',',aa(9)-zeoid+7.41,',',
     _   aa(11),',',aa(10),',',aa(6)
        close(24)

c        read(12,*,,end=990) (aa(ny),ny=0,9)
        read(12,'(a)',end=990) cc
       ip = index( cc, ',' )
       ccdum=cc(:ip-1)
       read(cc(ip+1:),*) (aa(j),j=1,9)

c-SEDCOM7本体
        open(25,file='file05.csv')
        write(25,'(a25,7(a2,f12.3))') 
     _   ccdum,',',aa(1),',',aa(2),',',aa(3),',',
     _   aa(4),',',aa(5),',',aa(6)
        close(25)

c-SEDCOM7重錘
        open(26,file='file06.csv')
        write(26,'(a25,7(a2,f12.3))') 
     _   ccdum,',',aa(7),',',aa(8),',',aa(9),',',
     _   aa(4),',',aa(5),',',aa(6)
        close(26)

c-SEDCOM7目標
        open(27,file='file01.csv')
        write(27,'(a25,15(a2,f12.3))') 
     _   ccdum,',',aa(1),',',aa(2),',',aa(3),',',
     _   aa(4),',',aa(5),',',aa(6),',',
     _   tx-aa(1),',',ty-aa(2),',',tz-aa(3),',',
     _   tx,',',ty,',',tz,',',tth-aa(4)
        close(27)
                
        do ip=1,ipass
c         read(IFLE,*,end=990)
         read(11,*,end=990)
         read(12,*,end=990)
        end do
       call sleep(1)
      end do
      pause 
  990 continue
      close(10)
      close(11)
      close(12)
      
      if(nstay > 0)then
       write(*,*) 
       write(*,*) '再開まで',nstay,'秒待機中'
       call sleep(nstay)  
       go to 991
      end if
      
      pause
      end program
      
