      program resort
      double precision col(1:12),pc,n,tmp
      character filename1*99, filename2*99
      integer i,j,k
      integer function iargc

      call inarg(n,filename1,filename2)

      n=1.0d3
      pc=3.085678d18
      write(*,*) "   z(cm)    A_V_eff   CII158    OI63      OI146     CI
     &610    CI370      PE"
      
      open(UNIT=1,file=filename1,status="old")
      open(UNIT=2,file=filename2,status="old")
      open(UNIT=3,file="av.basis.new", status="old")
      do j=1,5
         read(1,*)
         read(2,*)
      end do
      read(3,*)
  5   read(1,*,err=10) (col(i),i=1,7)
      read(2,*,err=10) tmp,tmp,col(8)
      read(3,*)col(9),tmp
      col(2)=col(2)*pc
      do j=3,8
        col(j)=10**col(j)
      enddo
      write(*,'(8(1pe10.3))')col(2),col(9),col(5),col(3),col(4),
     &     col(6),col(7),col(8)
      goto 5
  10  close(1)
      end

      subroutine inarg(n,filename1,filename2)

      integer function iargc
      integer argnum
      double precision n
      character progname*20, filename1*99
      character filename2*99
      character*20 infile
      logical ex
      argnum=iargc()
      call getarg(0,progname)
      proglen= index(progname,' ')  - 1
      if(argnum.ne.2) then
         write(*,*)"USAGE:"
         write(*,*)progname(1:proglen),"datafile "
         write(*,*)
         stop
      end if
      call getarg(1,filename1)
      inquire(file=filename1, exist=ex)
      call getarg(1,filename2)
      inquire(file=filename2, exist=ex)

      if (.not. ex) then
         write(*,*) "ERROR: files  not found !"
         write(*,*) "Please check name and path."
         stop
      end if
      return

      end
