      SUBROUTINE UFILES

      implicit none

      include 'sane_cwn.inc'
      include 'beta_geom.inc'
      include 'sane_misc.inc'

      CHARACTER*(*) FILNAM
      CHARACTER*26 outfile
      PARAMETER (FILNAM='a1p.dat')
      character*80 arg
      integer istat
*
*
      OPEN(UNIT=4,FILE=FILNAM,STATUS='OLD',FORM='FORMATTED')

 
C Check command line inputs
      
      if (iargc().ne.2) then
        stop 'usage: a1p_mc <iter #> <part #>'
      endif

      call getarg(1,arg)
      read(arg,'(i3)') iteration
      call getarg(2,arg)
      read(arg,'(i1)') particle

!      write(outfile, '("ntup/a1p_geant.",i3,".",i1,".hbook")') 
      write(outfile, '("a1p_geant.",i3,".",i1,".hbook")') 
     1      iteration,particle

      write(*,*) 'SETTING UP NTUPLE'

      call hropen(1,'SANE',outfile,'N',1024,ISTAT)
      call hbnt(nt_geant,'SANE Ntuple',' ')

      call hbname(nt_geant,'THROW',cwn_E,
     1            'E:R'
     1          //',p:R'
     1          //',xsn:R'
     1          //',asym:R'
     1          //',tht:R'
     1          //',phi:R'
     1          //',u(6):R'
     1          //',part:R'
     1          //',z:R'
     1          //',n:R'
     1                             )

      call hbname(nt_geant,'BLOCK',cwn_dedl,
     1            'dedl(6):R'
     1          //',cerphot:I'
     1          //',nb[0,2000]:I'
     1          //',bx(nb)[0,100]:I'
     1          //',by(nb)[0,100]:I'
     1          //',bg(nb):I'
     1          //',be(nb):R'
     1                             )

      call hbname(nt_geant,'PART',cwn_p_ng,
     1            'p_ng[0,20]:I'
     1          //',p_ne[0,20]:I'
     1          //',p_np[0,20]:I'
     1          //',p_gx(p_ng):R'
     1          //',p_gy(p_ng):R'
     1          //',p_ge(p_ng):R'
     1          //',p_ex(p_ne):R'
     1          //',p_ey(p_ne):R'
     1          //',p_ee(p_ne):R'
     1          //',p_px(p_np):R'
     1          //',p_py(p_np):R'
     1          //',p_pe(p_np):R'
     1                             )

      call hbname(nt_geant,'CERENKOV',cwn_cergood,
     1            'cergood[0,1000]:I'
     1          //',cg_x(cergood):R'
     1          //',cg_y(cergood):R'
     1          //',cg_xp(cergood):R'
     1          //',cg_yp(cergood):R'
     1                             )

      write(*,*) 'DONE INITIALIZING NTUPLE'

      return
      END
