
        SUBROUTINE UGINIT

      COMMON/GCLIST/NHSTA,NGET ,NSAVE,NSETS,NPRIN,NGEOM,NVIEW,NPLOT
     +       ,NSTAT,LHSTA(20),LGET (20),LSAVE(20),LSETS(20),LPRIN(20)
     +             ,LGEOM(20),LVIEW(20),LPLOT(20),LSTAT(20)
      COMMON/GCFLAG/IDEBUG,IDEMIN,IDEMAX,ITEST,IDRUN,IDEVT,IEORUN
     +        ,IEOTRI,IEVENT,ISWIT(10),IFINIT(20),NEVENT,NRNDM(2)
      COMMON/GCFLAX/BATCH, NOLOG
      LOGICAL BATCH, NOLOG

      COMMON/GCUNIT/LIN,LOUT,NUNITS,LUNITS(5)
      INTEGER LIN,LOUT,NUNITS,LUNITS

      COMMON/GCMAIL/CHMAIL
      CHARACTER*132 CHMAIL

      COMMON/GCTIME/TIMINT,TIMEND,ITIME,IGDATE,IGTIME
      INTEGER ITIME,IGDATE,IGTIME
      REAL TIMINT,TIMEND
 
      common/inputinfo/x,y,z,dx,dy,dz
      common/outname/outname
      character*80 outname
      COMMON/UINIKIN/CXYZ(3),PXYZ(3),IPANU
      COMMON/SEED/K0
      INTEGER*4 K0

      CALL GINIT
      ITIME = -1
      igauto = 1

c GEANTINOS!

      IPANU=48

C      Read run data from input file
       OPEN(9,FILE='testbeam.inp',STATUS='OLD')

       NEVENT = 1
       READ(9,*) x,y,z,dx,dy,dz
       CLOSE(9)

       IDEMIN = -1
       IDEMAX = 1000

C         Initialize data structures and graphics package
        CALL GZINIT
        call GDINIT
C
C         Define standard particle and material data
        CALL GPART
        CALL GMATE
C
C         Define user particle and material data
        CALL UMATE
	CALL USERMENU
C
C         Define tracking medium parameters
        CALL UTRACKING
C
C         Define the geometrical setup
        CALL UGEOMETRY
C
C         Compute cross-sections and energy-loss tables
        CALL GPHYSI
C
	K0=INT(SECNDS(0.0))+1
        NRNDM(1) = IGDATE   ! from COMMON GCTIME
        NRNDM(2) = IGTIME   ! from COMMON GCTIME
C
        RETURN
        END
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        SUBROUTINE USERMENU

      COMMON/GCPHYS/IPAIR,SPAIR,SLPAIR,ZINTPA,STEPPA
     +             ,ICOMP,SCOMP,SLCOMP,ZINTCO,STEPCO
     +             ,IPHOT,SPHOT,SLPHOT,ZINTPH,STEPPH
     +             ,IPFIS,SPFIS,SLPFIS,ZINTPF,STEPPF
     +             ,IDRAY,SDRAY,SLDRAY,ZINTDR,STEPDR
     +             ,IANNI,SANNI,SLANNI,ZINTAN,STEPAN
     +             ,IBREM,SBREM,SLBREM,ZINTBR,STEPBR
     +             ,IHADR,SHADR,SLHADR,ZINTHA,STEPHA
     +             ,IMUNU,SMUNU,SLMUNU,ZINTMU,STEPMU
     +             ,IDCAY,SDCAY,SLIFE ,SUMLIF,DPHYS1
     +             ,ILOSS,SLOSS,SOLOSS,STLOSS,DPHYS2
     +             ,IMULS,SMULS,SOMULS,STMULS,DPHYS3
     +             ,IRAYL,SRAYL,SLRAYL,ZINTRA,STEPRA
      COMMON/GCCUTS/CUTGAM,CUTELE,CUTNEU,CUTHAD,CUTMUO,BCUTE,BCUTM
     +             ,DCUTE ,DCUTM ,PPCUTM,TOFMAX,GCUTS(5)
C
	IPAIR=1
	ICOMP=1
	IPHOT=1
	IPFIS=1
	IDRAY=1
	IANNI=1
	IBREM=1
	IHADR=1
	IMUNU=1
	ILOSS=2

        DPHYS1 = 0
 
        CUTGAM=.00001
        CUTELE=.0001
        CUTNEU=.00001
        CUTHAD=.0001
        CUTMUO=.00001

        RETURN
        END
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



 	SUBROUTINE GUKINE

      COMMON/GCFLAG/IDEBUG,IDEMIN,IDEMAX,ITEST,IDRUN,IDEVT,IEORUN
     +        ,IEOTRI,IEVENT,ISWIT(10),IFINIT(20),NEVENT,NRNDM(2)
      COMMON/GCFLAX/BATCH, NOLOG
      LOGICAL BATCH, NOLOG

      COMMON/GCKINE/IKINE,PKINE(10),ITRA,ISTAK,IVERT,IPART,ITRTYP
     +      ,NAPART(5),AMASS,CHARGE,TLIFE,VERT(3),PVERT(4),IPAOLD

      COMMON/GCONST/PI,TWOPI,PIBY2,DEGRAD,RADDEG,CLIGHT,BIG,EMASS
      COMMON/GCONSX/EMMU,PMASS,AVO

      COMMON/UINIKIN/CXYZ(3),PXYZ(3),IPANU
      COMMON/SEED/K0
      INTEGER*4 K0

      common/inputinfo/x,y,z,dx,dy,dz
      dimension xyz(3)

        KK = MOD(IEVENT,10000)
        IF(KK.EQ.0) WRITE(*,*)IEVENT,NEVENT
 
        call vecfill(cxyz,x,y,z)
        call vecfill(xyz,dx,dy,dz)

	EGAMMA = 1.
	AMASS=0.
	IF(IPANU.EQ.13)AMASS=.939573
	IF(IPANU.EQ.14)AMASS=.93828
	EGAMMA=SQRT(EGAMMA*EGAMMA+2*EGAMMA*AMASS)
        call vecfill(pxyz,xyz(1)*egamma,xyz(2)*egamma,xyz(3)*egamma)

        CALL GSVERT(CXYZ,0,0,0,0,NVERT)
        CALL GSKINE(PXYZ,IPANU,NVERT,0,0,NT)
	IF(IDEBUG.EQ.1) THEN
		  CALL GPKINE(0)
		  CALL GPVERT(0)
	ENDIF

        RETURN
        END
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


        SUBROUTINE GUSTEP

      COMMON/GCFLAG/IDEBUG,IDEMIN,IDEMAX,ITEST,IDRUN,IDEVT,IEORUN
     +        ,IEOTRI,IEVENT,ISWIT(10),IFINIT(20),NEVENT,NRNDM(2)
      COMMON/GCFLAX/BATCH, NOLOG
      LOGICAL BATCH, NOLOG

      COMMON/GCKINE/IKINE,PKINE(10),ITRA,ISTAK,IVERT,IPART,ITRTYP
     +      ,NAPART(5),AMASS,CHARGE,TLIFE,VERT(3),PVERT(4),IPAOLD

      INTEGER MXGKIN
      PARAMETER (MXGKIN=100)
      COMMON/GCKING/KCASE,NGKINE,GKIN(5,MXGKIN),
     +                           TOFD(MXGKIN),IFLGK(MXGKIN)
      INTEGER       KCASE,NGKINE ,IFLGK
      REAL          GKIN,TOFD

      PARAMETER (NWSTAK=12,NWINT=11,NWREAL=12,NWTRAC=NWINT+NWREAL+5)
      COMMON /GCSTAK/ NJTMAX, NJTMIN, NTSTKP, NTSTKS, NDBOOK, NDPUSH,
     +                NJFREE, NJGARB, NJINVO, LINSAV(15), LMXSAV(15)

      PARAMETER (MAXMEC=30)
      COMMON/GCTRAK/VECT(7),GETOT,GEKIN,VOUT(7),NMEC,LMEC(MAXMEC)
     + ,NAMEC(MAXMEC),NSTEP ,MAXNST,DESTEP,DESTEL,SAFETY,SLENG
     + ,STEP  ,SNEXT ,SFIELD,TOFG  ,GEKRAT,UPWGHT,IGNEXT,INWVOL
     + ,ISTOP ,IGAUTO,IEKBIN, ILOSL, IMULL,INGOTO,NLDOWN,NLEVIN
     + ,NLVSAV,ISTORY

      COMMON/GCTMED/NUMED,NATMED(5),ISVOL,IFIELD,FIELDM,TMAXFD,STEMAX
     +      ,DEEMAX,EPSIL,STMIN,CFIELD,PREC,IUPD,ISTPAR,NUMOLD

      COMMON/GCSETS/IHSET,IHDET,ISET,IDET,IDTYPE,NVNAME,NUMBV(20)

      COMMON/GCVOLU/NLEVEL,NAMES(15),NUMBER(15),
     +LVOLUM(15),LINDEX(15),INFROM,NLEVMX,NLDEV(15),LINMX(15),
     +GTRAN(3,15),GRMAT(10,15),GONLY(15),GLX(3)

      CHARACTER*4 NOMS(15)

        DO I=1,15
		   CALL UHTOC(NAMES(I),4,NOMS(I),4)
	END DO

        IF(NGKINE.GT.0) THEN
           DO I=1,NGKINE
              CALL GSKING(I)
           END DO
        ENDIF	

C       Store the space point coordinates in JXYZ for drawing
        call gsxyz

        IF (IDEBUG.EQ.1) CALL GPCXYZ
 
        RETURN
        END
C
C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
      SUBROUTINE GUOUT

      END
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        SUBROUTINE UGLAST

      COMMON/GCFLAG/IDEBUG,IDEMIN,IDEMAX,ITEST,IDRUN,IDEVT,IEORUN
     +        ,IEOTRI,IEVENT,ISWIT(10),IFINIT(20),NEVENT,NRNDM(2)
      COMMON/GCFLAX/BATCH, NOLOG
      LOGICAL BATCH, NOLOG

        CALL GLAST
 
        RETURN
        END
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        SUBROUTINE GUTREV
        CALL GTREVE
        CALL GDXYZ(0)
        RETURN
        END
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        SUBROUTINE GUTRAK
	CALL GTRACK
	RETURN
	END
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	SUBROUTINE GUPHAD
	CALL GPGHEI
	END
C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	SUBROUTINE GUHADR
	CALL GHEISH
	END
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	REAL FUNCTION RAN(DUM)
C  To be able to use the function RAN instead of the sunroutine GRNDM
	IMPLICIT NONE
	REAL*4 DUM,R
	CALL GRNDM(R,1)
	RAN = R
	RETURN
	END
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       REAL FUNCTION GASRAN(DUM)
C Returns a normally distributed deviate with zero mean and unit variance
       DATA ISET/0/
       IF (ISET.EQ.0) THEN
1        V1=2.*RAN(DUM)-1
         V2=2.*RAN(DUM)-1
         R=V1**2+V2**2
         IF(R.GE.1..OR.R.EQ.0) GO TO 1
         FAC=SQRT(-2.*LOG(R)/R)
         GSET=V1*FAC
         GASRAN=V2*FAC
         ISET=1
       ELSE
         GASRAN=GSET
         ISET=0
       ENDIF
       RETURN
       END
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
