c COMXYZ.FOR
c
c  Ad-hoc program to concatonate xyz files.
c  Lin Cordell
c
      character*50 ifile,ofile
      character*1 ans
      icount=0
      write(6,1)
1     format(' Enter first input file name:')
      print 101
101   format(' *'$)
      read(5,100)ifile
100   format(a)
103   print*,'Is it binary, or ascii:'
      print 101
      read(5,100)ans
      if(ans.ne.'b'.and.ans.ne.'a') then
	print*, 'Enter binary or ascii, (b or a will serve):'
	go to 103
      endif
      if(icount.ne.0)go to 270
      write(6,201)
201   format(1x,'Enter output file name:')
      print 101
      read(5,100)ofile
      open(11,file=ofile,form='unformatted',status='new')
270   if(ans.eq.'b')then
	open(10,file=ifile,form='unformatted',status='old')
        i=0
271     read(10,end=250)x,y,z
        i=i+1
        write(11)x,y,z
        go to 271
      else
	open(10,file=ifile,form='formatted',status='old')
        i=0
272     read(10,*,end=250)x,y,z
        i=i+1
        write(11)x,y,z
        go to 272
      endif
250   icount=icount+i
      print*,'Points in this file =',i
252   print*,'Another ? (y or n):'
      print 101
      read(5,100)ans
      if(ans.ne.'y'.and.ans.ne.'n')then
	print*,'Answer yes or no:'
	go to 252
      endif
      if(ans.eq.'n')go to 900
      print*,'Enter next file name:'
      read(5,100)ifile
      go to 103
900   print*,'Total points =',icount
998   close(11)
999   close(10)
      stop
      end
