C(((((((((((((((((((((((((((((((( GENMAN (((((((((((((((((((((((((((((((
high <----- level ---- low
GENAS0                          fix mode (1 or 4 dimensional)
   GENAS1                       fix 1ry type, energy, angle
       GENAS                    sample parameters for 1 shower
          DEPOB                 fix observation depth
             SCINTI             fix detector (with or without Pb)
                 SMPNP          sample # of ptcl at given r
                 SMPSCO         sample scintillator output for 1 ptcl
                 SMPDT          sample delay time
------------------------- inquiry subs listed below ---------------
             QAGE               inquire age of current shower
             QAGEH              inquire age of each component
                                shower for heavy 1ry
             QASP               inquire total # of ptcls
             QASPH              inquire # of ptcls by each component
                                shower for heavy 1ry
             QMOLU              inquire Moliere unit
          QCOG                  inquire center of gravity
          QCOGH                 inquire center of gravity of each
                                component shower for heavy 1ry.
          Q1STZ                 inquire 1st collision depth
          Q1STH                 inquire 1st collision height
          Q1STHH                inquire effective 1st collision height
                                for heavy 1ry
QGENV                           inquire version #.

 ***  A lower level subroutine must be called after all the
      higher level subroutines have been called. (Say, to call SMPNP
      all of GENAS0,GENAS1,GENAS,DEPOB,SCINTI must be called in this
      order).
      However, this rule is not applied among the inquiry subroutines
      (say, QASP can be called without calling QCOG etc).
 ***  Subroutines in the same level may be called in any order.
      (e.g, SMPSCO may be called without calling SMPNP)
 ***  At a given level, the program flow may be returned to
      any higher level subroutine call.
      (E.g, after calling SMPNP, the user may call any of SCINTI,
      DEPOB, GENAS,... depending on his needs).

Calling sequence:
   (If not explicitly stated, all variables follow the usual
    FORTRAN convention of integer, real declaration).

 GENAS0(mode)
     mode: input.  1==> 1 dimensional simulation
                   2==> 4 dimensional simulation
                        (but (x,y) is only in r=sqrt(x**2+y**2)
 GENAS1(kin, ein, cosz)
     kin:  input.  0---> gamma 1ry
                   1---> proton 1ry
                   2---> alpha  1ry
                   3---> L     <mass #> 8
                   4---> M             14
                   5---> H             25
                   6---> VH            35
                   7---> Fe 1ry        56
     ein:  input. 1ry total energy in TeV  (few to 10**8)
     cosz: input. 1ry zenith angle ( must be > 0.6)
 GENAS
      No parameter.  1 shower is generated internally.
 DEPOB(depth, icon)
    depth:  input.  vertical depth of observation point (g/cm**2)
    icon:  output.  0==> o.k
                    1==> age is too young as A.S. result may
                         not be guaranteed.
                    2==> no A.S because 1st collision point is
                         deeper than "depth".

                 The user may wonder why this call cannot be
                 put at a higher level since, depth is usually
                 not changed.   One reason is that depth may be
                 changed if he want to see the transition of
                 the shower, and there is another essential
                 reason internally.

 SCINTI(jsc, discri)
     jsc:   input   1===> no Pb on the detector
                    2===> 0.5 cm Pb on the detector
   discri:  input   0. should be put
                    (in some case the user may put discrimination
                     level in particle number.  But such
                     discrimination should be done at programs
                     to use GENAS).
 SMPNP(r, area, an, n)  **** after version 2.1 and later ****
       r:   input.  core distance (measured perpendicular to the
                    shower axis).  in m
    area:   input.  detector area in m**2 ( placed horizontally)
      an:   output.  average # of particles falling on the detector
                    These are particles (gamma or electron) which can
                    emit photons in the scintillator
                    (scinti output > discri=0.0). Hadrons
                    and muons are not included.
       n:   output. sampled # of particles falling on the detector
                    The sampling is done from the Poisson distribution
                    with the mean "an".
 SMPNP(r, an, n)  **** before version 2.1 ****
       r:   input.  core distance (measured perpendicular to the
                    shower axis).  in m
      an:   output.  average # of particles at r.  /m**2 perpendicular
                    to the shower axis (not horizontal area).
                    These are particles (gamma or electron) which can
                    emit photons in the scintillator set horizontally
                    (scinti output > discri=0.0). Hadrons
                    and muons are not included.
       n:   output. sampled # of particles at r. (/m**2).
                    The sampling is done from the Poisson distribution
                    with the mean "an". (area is perpendicular to
                    the shower axis).
 SMPSCO(r, equivp)
       r:  input.   core distance (m) (see note in SMPNP).
   equivp: output.  sampled scintillator output produced
                    by 1 particle (electron or gamma)
                    in unit of particle number.   (1 equivalent
                    particle number is defined by the peak
                    position of scinti output when 1 single
                    relativistic charged particle passes through
                    the scintillator vertically).
                    This should be taken as output from scinti
                    so that the photons to be received by PMT or
                    charge amount to ADC may be different from
                    this one due to the detector structure etc.
                    (Reflection, path length difference etc).
                    Such treatment should be done by the user.

 SMPDT(r, equivp, dt)
      r:  input.  core distance (m) (see note in SMPNP)
 equivp:  input.  scinti output. usually give the value obtained
                  by SMPSCO
     dt:  output. delay time of the particle that gives the scinti
                  output "equivp".  Time is measured from the flat
                  front of the air shower (in ns). time 0 is at r=0.


 ---------------------------------------------------------------
 QAGE(age)
    age:  output.  age of the present shower
 QAGEH(nc, ageh)
    nc: output. # of component (proton) showers
                The maximum value of  nc is the maximum mass
                number of the heavy primary the user uses.
  ageh(i):  output. (i=1,nc). age of each component shower
 QASP(bne, ene)
     bne:  output.  size of the present shower corresponding to
                    B approximation (i.e., all electron #).
     ene:  output.  all particle # which can give scinti output
                    >discri=0.0.
 QASPH(nc, anc)
     nc: output.  see QAGEH
     anc(i): output. (i=1,nc).  # of electrons corresponding to
                   B-approx. for i-th component shower
 QMOLU(rm)
    rm: output.  Moriere unit.  This is the usual  Moliere unit
                 calculated at 2 r.l above the observation
                 point along the 1ry direction.
                       ~~~~~~~~~~~~~~~~~~~~~~~~
 QCOG(cog)
    cog: output. center of gravity of the present shower(g/cm**2).
                 This is the slant depth.
 QCOGH(nc, cogh, zh)
    nc: see QAGEH
    cogh(i): output.  (i=1, nc).  COG of each component shower
    zh(i): output.   (i=1, nc).   first collision depth of
                    each component shower (g/cm**2)
 Q1STZ(z)
      z: output. slant depth of the 1st collision point (g/cm**2)
                 of the current shower
 Q1STH(h)
      h: output. slant height from zob to 1st collision point (m)
                 Note that h is in real*8.
 Q1STHH(h)
      h: output. slant height from zob to the effective 1st
                 collision point (m) for heavy 1ry
                 Note that h is in real*8.
QGENV(vn)
      vn: character*8    vn='GENAS2.0' may be returned.

                 ~~~~~~~~~~~~~~~~~~~~~~~~
 QCSVC(a,b,c,d, tm, toff, tmx)
     all are output.
         Parameters to express the present shower (in this
         parametalization, no fluctuation is yet introduced
         except for the center of the gravity of the shower and
         also no effect of the detector).
         f(t)=a*t**c exp(b(1-t) + d(1-t**2))
           d=(c-b)/2
           t=(T-toff)/tmx
    where T(>toff) is the depth (g/cm**2) of observation.
    f gives the Ne (# of electrons equivalent to B-approximation).


*********** Typical structure of GENAS usage ********************
   GENAS0
      loop1; fix 1ry type, energy, angle
         GENAS1
            GENAS
            DEPOB
               loop2; do below for each detector
                   SMPNP; sample n particles falling on the detector
                   loop3; do below for n particles
                       SMPSCO ; get scintillator output
                       SMPDT ; get delay time
                   loop3 end
                   store ADC and TDC values for the detector
               loop2 end
               get age, 1st int. height etc if needed.
               write  result for the 1 event
      loop1 end
      if need to generate more, goto loop1


***** very important note ****

      loop2 should be so constructed that the detectors of the same
      structure should be processed in a consecutive order.  (Otherwise
      the computation time will be much longer).  For instance, if you
      have detectors with Pb and without Pb cover, they should not be
      processed like:  1st one is with Pb, 2nd one is without Pb, 3rd
      one is with Pb...  You  should process all detectors with Pb
      first and then those without Pb or v.v.  If their # is almost the
      same, and if they are processed mixed, the computation time will
      become 4 to 5 times.

      In loop3, if the primary energy is high and the detector is near
      the core, n becomes very large.  If SMPSCO and SMPDT are executed
      so many times, long computation time is needed.  The user may
      truncate the loop at a moderate number where ADC is  saturated.
      The smallest delay time at this point will correspond to the most
      forward particle.

         After or during the generation of air showers, the user may
      set discrimination for trigger etc. (For this purpose don't
      use discri in SCINTI).  The discrimination may set by particle
      number which is conceptually equivalent to ADC value or the
      total amount of charge fed to ADC.   This is somewhat different
      from the experimental situation where discri is set for the
      pulse height but not charge amount.  Therefore the user must
      take into account such difference and if the user wants to
      compare the simulated results with experimental ones, he should
      re-trigger the experimental data by particle number (ADC value
      converted to particle #) with somewhat higher discrimination
      level than the data taking time (see ref.3).  The user may, of
      course, simulate the pulse height distribution by some or other
      means and directly compare the result with the experimental dat a
      without re-trigger (However, the pulse height simulation is
      rather difficult for multiple particles arriving
      intermittently).

  ------------------------------------------------------------------
      The following names should not be used in the user's own
      subprogram names or common names which are recognized as
      external names.

      $ASCNS $DEG $DEGB $DEGB2 $DEGB3 $DEG2 $DEG3 $GENAS $HEAVY $SIMCN
      AVCOG0 AVCOG1 AVNE0 AVNE1 AVSCV0 CHIMS COGG0 COGG1 COGG2 COGP0
      COGP1 COGP2 COLPG COLPP DEGB DEGBB DEGB2B DEGB3B DEG2B DEG3B DENAIR
      DEPOB DSTAIR GENAS GENASB GENAS0 GENAS1 HAIR HVYFRG INISC1
      INISC2 KADE KADEB KADEBA KADEBB KADEBC KADEB1 KADEB2 KADEB3
      KADEB4 KADEB5 KADEB6 KADEB7 KADEB8 KADEB9 KADE1 KADE10 KADE11
      KADE12 KADE2 KADE3 KADE4 KADE5 KADE6 KADE7 KADE8 KADE9 KANIN
      KASGUS KATEG1 KATEG3 KBINOM KCFG KCFGB KCFP KCFPB KCNVB KDEG
      KDEGB KDEGB1 KDEGB2 KDEGB3 KDEG1 KDEG2 KDEG3 KDHIN KDIG KDIGB
      KDIGB0 KDIG0 KDIP KDIPB KDIPB0 KDIP0 KDT KDTB KDTBA KDTBB KDTB1
      KDTDE1 KDTDE3 KDTFF KDTFFB KDT1 KDT1A KDT1A1 KDT1A2 KDT1A3
      KDT1A4 KDT1B KEFG KEFGB KEFP KEFPB KESE0G KESE0P KFMAX KFMIN
      KFRAC KFRGE KGAUSS KGETS KGETS1 KIDE KIDEB KIDEB1 KIDEB2 KIDEB3
      KIDE1 KIDE2 KIDE3 KIERF KINTP3 KLEE KLENA KMFPTB KMOLU KMOVER
      KNRML KNRML2 KPOISN KPPTPA KPPXS KREPSC KSFRAG KSINN KSUMR KUDIG
      KUDIGB KUDIP KUDIPB K4PTDI MFPG MFPHV MFPP NDTSG NDTSP PPXSEC
      QAGE QAGEH QASP QASPH QCOG QCOGH QGENV QMOLU QSCINT QSCVC Q1STH
      Q1STHH Q1STZ SCINTI SCOG0 SCVBC SCVCOE SCVG0 SCVP0 SHAIR SIGG
      SIGP SMPCOG SMPDT SMPNE SMPNE1 SMPNP SMPSCO STNDG STNDP STONE
      STZSS SZAIR ZAIR ZTSSS
C)))))))))))))))))))))))))))))))) GENMAN )))))))))))))))))))))))))))))))
C(((((((((((((((((((((((((((((((( TEST1 ((((((((((((((((((((((((((((((((
C              TEST GENAS BY SIMPLE USAGE.
C        MAKES TRANSITION CURVE OF A.S BY 300 TEV ALFA
C              OUTPUT DISK FOR GRAPHIC USE
      OPEN(13,FILE='C2S5001.#GD.DATA')
C           1 DIMENSIONAL SIMULATION
      CALL GENAS0(0)
C             ALFA   300 TEV COS=1.0
        CALL GENAS1(2, 300.,   1.0)
C             GENERATE 1000 EVENTS
        DO  900 I=1,  1000
          CALL GENAS
          DO 100 DPTH=100., 1500., 100.
             CALL DEPOB(DPTH, ICON)
             IF(ICON .LE. 1) THEN
C                  5MM  LEAD     DETECTOR
                  CALL SCINTI(2, 0.)
C                      GET BN=ELECTRON # IN B- APPROX AND
C                   EN=EFFECTIVE # OF PTCLS WHICH GIVE SCINTILLATOR
C                   OUTPUT >0
                  CALL QASP(BN, EN)
C                   OUTPUT FOR GRAPHIC USE
                  WRITE(13) DPTH, BN
             ENDIF
  100     CONTINUE
  900    CONTINUE
       END
C)))))))))))))))))))))))))))))))) TEST1 ))))THIS LINE SHOULD BE ERASED))
C(((((((((((((((((((((((((((((((( TEST2 ((((((((((((((((((((((((((((((((
C            TEST GENAS BY SIMPLE USAGE
C            OPEN DISK FOR GRAPHIC USE
        OPEN(13, FILE='C2S5001.#GD.DATA')
C            4 DIMENSTIONAL
        CALL GENAS0(1)
C             GENERATE 50000 SHOWERS (1M26S BY FACOM M780S1)
        DO 20 K=1,  50000
C                 PROTON SHOWER  100 TEV
            CALL GENAS1(1,  100., 1.0)
C                  INIT ONE SHOWER
               CALL GENAS
                  CALL DEPOB(600.,  ICON)
                  IF(ICON .LE. 1) THEN
C                          5 MM LEAD DETECTOR
                      CALL SCINTI(2,  0.)
C                          SAMPLE CORE DISTANCE (NOT SO REALISTIC).
C                          THIS IS  NOT A GENAS FUNCTION
                      CALL SAMPR(RI)
C                          # OF PTCL /M**2 PERPENDICULAR TO AXIS
                      CALL SMPNP(RI, 1.,  AVN, N)
C                          SAMPLE SCINTI OUTPUT IN PTCL #
                      CALL SMPSCO(RI, EQVP)
C                          ITS DELAY TIME
                      CALL SMPDT(RI, EQVP, DT)
                      WRITE(13) RI, EQVP, DT
                  ENDIF
   10          CONTINUE
   20   CONTINUE
       END
       SUBROUTINE SAMPR(R)
            CALL RNDC(V)
            CALL RNDC(U)
            IF(U .LT. .5) THEN
               R=-20.*LOG(V)
            ELSEIF(U .LT. .9) THEN
               R=-100.*LOG(V)
            ELSE
               R=-500.*LOG(V)
            ENDIF
        END
C)))))))))))))))))))))))))))))))) TEST2 ))))THIS LINE SHOULD BE ERASED))
