text:
c
c--------------------------- prot ---------------------------------
c
        subroutine prot(centE,Ebot,ddeng,alt,altkm,
     &        iprt,nspec,nen,nang,nango2,nalt,jpreci,mcount,
     &        prodprotelec,primprotelec,fluxprimprot,qprimprot,
     &        prodionprot,gmu,gwt,densig,densneut)
c
        implicit none
        include 'TRANSPORT.INC'
c
c 	Lus dans input :
c 	  production des proto-ions
c 		proprotion_init(E,sp,z)		: cm-3.s-1.eV-1
c 	  production des proto-electrons
c		proelec_init(z)			: cm-3.s-1
c 	  production de protoelectrons (somme des proto-ions)
c 		proprotel_init (z,E)		: cm-3.s-1.eV-1
c
c 	Outputs
c
c 		prodprotelec(z) 		: cm-3.s-1
c 		primprotelec(z,E)		: cm-3.s-1.eV-1
c 		fluxprimprot(z,E)		: cm-2.s-1.eV-1.sr-1
c 		qprimprot(E,z,A)		: cm-2.s-1.eV-1.sr-1
c 	Outputs pour le moment gardes en interne (en attendant que ca
c 	serve) : ion production rate (m-3 s-1)
c	prodionprot (isp,ialt)                  : cm-3.s-1
c 	1,2,3,4,5,6 -> N2+,O2+,O+,H+,He+,N+
c
c 	INPUTS
        integer iprt(40),mcount(5),nspec
        real centE(nbren),Ebot(nbren),ddeng(nbren)
        real alt(nbralt),altkm(nbralt),densneut(8,nbralt)
        real gmu(2*nbrango2),gwt(2*nbrango2)
        integer nen,nang,nalt,nango2
c
c 	INTERNAL PARAMETERS
c
c 	Parametres du flux de protons selon Hardy :
        real en_moy_keV,en_moy_eV,eflux,correc,eflux_init
        real Echar_protons
        real fluxdown(nbren,nbrango2),fluxup(nbren,nbrango2)
        real lonmag,latmag,tmag,cofo,cofh,cofn,Fe0,Ee0,Fi0,Ei0
    	real Flux_part_int,Flux_ener_int,chi0,Eprotelec
c	prodionprot_init (isp,ialt)                  : cm-3.s-1
c 	1,2,3,4 -> N2+,O2+,O+,N+
c 	Isotropie du flux
        integer isotro
        real Bmag,dipangle,Enord,Eest,vperpnord,vperpest,vhorizon,vpara
        real ddp,Jtop
        integer ikp,lit,iener
        data lit/0/		! On passe par le code simplifie
        common/buff/lonmag,latmag,tmag,ikp,cofo,cofh,cofn,chi0,
     &                  Fe0,Ee0,Fi0,Ei0,
     &                  Bmag,dipangle,Enord,Eest,
     &                  vperpnord,vperpest,vhorizon,vpara,ddp,Jtop
        real xnN2(nbralt),xnO2(nbralt),xnO1(nbralt)
        integer iz
        real xmin,xmax,ymin,ymax,tab(300)

c 	Lus :
        integer nnen, nz,nspecprot
        real proprotion_init(nbren,2,200)
        real eprot(nbren),z(200)
c
c 	Calcules
        real proprotel_init(200,nbren),prodionprot_init(4,nbralt)
        real zmin,zmax,eprotmin,eprotmax,alp
c
        real pi,r2pi,densig(nbralt,nbren)
        real finput(nbren),foutput(nbren),finter(nbren,200)
        real proelec_init(200),prodion(200,nbrsp*2)
        integer ialt,ien,isp,jpreci,iang
c
c 	OUTPUTS
        real prodprotelec(nbralt),prodionprot(6,nbralt)
        real qti(nbralt),qia(4,nbralt)
        real primprotelec(nbralt,nbren)
        real fluxprimprot(nbralt,nbren)
        real qprimprot(nbren,nbralt,-nbrango2:nbrango2)
c
900  	format (5f10.2)
910  	format (5(1pe10.2))
920  	format (20x,'Altitude:',f10.2,' km')
1000 	format (/,'Input protoelectron production [cm-3.s-1.eV-1]')
1010 	format (/,'# of Energies and altitudes for primary ',/,
     &        'protoelectron fluxes (nnen,nz):',2i10)
1040 	format (/,' Prod. (proprotel_init) (cm-3.s-1.eV-1):')
1050 	format (/,'# of Energies and altitudes for secondary ',/,
     &        'electon fluxes (nen,nalt):',2i10)
1060 	format (/,' Primary protoelectron flux : (cm-2.s-1.eV-1) :')
1070 	format (/,' no of e. and alt. for sec. ',
     &        'el. fluxes (nen,nalt):',2i10)
1080 	format ('Primary interpolated prod. :(cm-3.s-1.eV-1):')
1090	format('Electron primary production due to protons impact',/,
     &      '(prodprotelec) [cm-3.s-1]')
c
        do ialt = 1,nalt
          prodprotelec(ialt) = 0.
 	        do ien = 1,nen
              primprotelec(ialt,ien) = 0.
              fluxprimprot(ialt,ien) = 0.
              do iang = -nango2,nango2
!                  	      qprimprot(ien,ialt,iang) = 0.
              enddo
            enddo
        enddo
        if(jpreci.le.2) return
c
c 	Si on est ici, c'est qu'on a des protons.
        pi=atan(1.)*4.
        r2pi = 1./(pi*2.)
c
c 	Si on lit les donnees protons depuis un fichier, lit = 1
c 	Si on les calcule a partir du code low_protons, lit = 0
c
c
        if (lit.eq.0)then
c
            iz = 0
            do ialt = 1,nalt
              if(altkm(ialt).le.840.)then
                iz = iz+1
                z(iz) = altkm(ialt)
                xnN2(iz) = densneut(1,ialt)
                xnO2(iz) = densneut(2,ialt)
                xnO1(iz) = densneut(3,ialt)
              endif
            enddo
            nz = iz
c
c 	  Calcul de l'energie caracteristique des ions
c
          call hardion(latmag,tmag,ikp,Flux_part_int,Flux_ener_int)
c
c         Les sorties de hardion sont en log decimal :
c         Flux de particules integre [cm-2.s-1.sr-1]
c
          Flux_part_int=10.**Flux_part_int
c
c         Flux d'energie integre [keV.cm-2.s-1.sr-1]
c
          Flux_ener_int=10.**Flux_ener_int
c
c         On assume que la forme du flux est une maxwellienne, bien que
c         hardy et al,(JGR Mai90, p4229-4248, 1985) ont publie des
c         formes de flux dont ils precisent autant que faire se peut
c         qu'elles ne sont justement pas maxwelliennes. Helas, ils ne
c         donnent pas une loi generale de representation de leurs
c         precipitations.
c         Pour une maxwellienne F = k E exp(-E/Eo), on a
c         Flux de particules = integrale de  k F(E) dE
c         Flux d'energie     = integrale de  k E F(E) dE
c         Le rapport des 2 donne l'energie moyenne
c             Eo = (Flux d'energie/2*Flux de particules)
c
          en_moy_keV = Flux_ener_int/(2.*Flux_part_int)	! en keV
          en_moy_eV = en_moy_keV*1000.			! en eV

          Fi0=6.2832*Flux_ener_int*1.6e-12
          Ei0= en_moy_eV
c
c	  1 Erg.cm-2.s-1 = 1 mW.m-2
c 	  Pour avoir le flux d'energie en mW.m-2 a partir de
c 	  eV.cm-2.s-1.sr-1 il faut multiplier par
c 	  1e4(cm2/m2)*1.602 e-19(J/eV)*1 (W.s/J)*1e3(mW/W)
c 	  *4 pi (sr)* eflux (eV.cm-2.s-1.sr-1)
c 	  Le 4 pi vient de l'isotropie du flux dans Hardy. Est-ce
c 	  exact ?
c
 	  eflux_init = Flux_ener_int*20.131e-12 	! mW.m-2
c
c ----------------
cc 	  Valeurs test :
cc 	  Attention ! l'energie moyenne est 2 fois l'energie
cc 	  caracteristique de la maxwellienne.
c 	  eflux_init  = 1.         		! mW.m-2 (=erg.cm-2.s-1)
c         Flux_ener_int=eflux_init/20.131e-12	! keV.cm-2.s-1.sr-1
c 	  Echar_protons = 5.			! keV
c 	  en_moy_keV = 2.* Echar_protons
c 	  en_moy_eV = 1000.* en_moy_keV
c ----------------
c
c 	  On veut des productions par electron volt. Le programme de
c 	  Marina les donne en global. On va donc calculer dans chaque
c 	  energie de la grille combien on a de particules,
c 	  puis faire comme si elles se repartissaient de facon
c 	  maxwellienne dans chaque element de la grille. On appellera
c 	  lowflux pour chacune de ces valeurs, et on divisera par
c 	  la largeur du pas de grille.
c
          isotro=2		! tout va vers le bas
          call inmaxwl(Flux_ener_int,en_moy_eV,nango2,nen,centE,
     .                  isotro,gmu,fluxdown,fluxup)
          call normflux(Flux_ener_int,nango2,nen,centE,ddeng,gmu,gwt,
     .                  fluxdown,fluxup)
c
c 	  A partir de maintenant, on fait comme si chaque flux etait
c 	  repartit dans sa case suivant une maxwellienne
c
 	  do ien = nen,1,-1
c 	    Calcul de l'energie de l'electron ejecte. Je fais une
c 	    approximation honteuse : suivant la these de MG, quelque
c 	    soit la particule incidente de haute energie, l'energie
c 	    perdue est 1/alpha *sqrt(seuil*centE(ien)/1836)
c 	    Le seuil vaut 17,15,16 pour N2,O2,O, soit ... 16 (j'ai
c 	    honte).
c 	    alpha vaut 0.91
c 	    L'energie de l'electron est donc sqrt(centE(ien))/10.
 	    Eprotelec = sqrt(centE(ien))/10.
c
c           search in which box iener to put the created electron.
            call search (nen,Ebot,ddeng,Eprotelec,iener)

c 	    Il faut calculer le flux d'energie integree dans
c 	    chaque boite [eV.cm-2.s-1.sr-1]
 	    eflux = centE(ien)*ddeng(ien)*fluxdown(ien,1)

c 	    comme on est completement forward, il n'y a pas de
c 	    multiplication par 2pi, car on est directement en
c 	    eV.cm-2.s-1
            eflux = eflux*1.602e-12		! mW.m-2
 	    alp = centE(ien)*1.e-3		! keV
c
  	    call low_proton(eflux,alp,nz,z,xnN2,xnO2,xnO1,
     .		qti,qia)
c
c 	    Calcul des sorties de prot.f
 	    do ialt = 1,nz
 	      prodprotelec(ialt) = prodprotelec(ialt)+qti(ialt)
 	      primprotelec(ialt,iener)= primprotelec(ialt,iener)+
     .			qti(ialt)/ddeng(ien)
  	    enddo 		! sur les altitudes
 	  enddo			! sur les energies
c 	  Passage de m-3 s-1 a cm-3 s-1
          do ialt = 1,nz
            prodprotelec(ialt) = prodprotelec(ialt)/1.e+06
            primprotelec(ialt,ien)= primprotelec(ialt,ien)/1.e+06
          enddo

c
c         On passe en flux.
 	  do ialt = 1,nz
 	    do ien = 1,nen
              fluxprimprot(ialt,ien)=
     .               primprotelec(ialt,ien)/densig(ialt,ien)
              do iang=-nango2,nango2
                qprimprot(ien,ialt,iang)=primprotelec(ialt,ien)/4./pi
              enddo
            enddo
 	  enddo
c
c 	  Cette facon de faire a sans doute change la production qu'
c 	  on aurait eue normalement. On va renormaliser
c
  	  call low_proton(eflux_init,en_moy_keV,nz,z,
     .		xnN2,xnO2,xnO1,qti,prodionprot_init)
c 	  Passage en cm-3.s-1
 	  do ialt = 1,nz
 	    qti(ialt) = qti(ialt)/1.e+6
 	    prodionprot(1,ialt) = prodionprot_init(1,ialt)/1.e+6  !N2+
 	    prodionprot(2,ialt) = prodionprot_init(2,ialt)/1.e+6  !O2+
 	    prodionprot(3,ialt) = prodionprot_init(3,ialt)/1.e+6  !O+
 	    prodionprot(4,ialt) = 0.			  !H+ thermique
 	    prodionprot(5,ialt) = 0.				  !He+
 	    prodionprot(6,ialt) = prodionprot_init(4,ialt)/1.e+6  !N+
 	  enddo
c
 	  do ialt = 1,nz
 	    if(qti(ialt).eq.0. .or. prodprotelec(ialt).eq.0.) then
 	      correc = 0.
 	    else
 	      correc = qti(ialt)/prodprotelec(ialt)
 	    endif
 	    prodprotelec(ialt) = qti(ialt)
            do ien = 1,nen
 	      primprotelec(ialt,ien)= primprotelec(ialt,ien)*correc
              fluxprimprot(ialt,ien)= fluxprimprot(ialt,ien)*correc
              do iang=-nango2,nango2
                qprimprot(ien,ialt,iang)=qprimprot(ien,ialt,iang)*correc
              enddo
            enddo
 	  enddo
c
c 	  Il faut maintenant revenir aux altitudes de transelec
c
 	else if(lit.eq.1) then
          open (58,file='dir.data/dir.linux/dir.cine/SOURCE_OUT_V',
     &             status='old')
          rewind(58)
c
c  *      read in primary protoelectron flux data
c         nnen   : # energies.
c         nz     : # altitudes.
c         eprot   : energies.
c         z      : altitudes.
c
 	  call xline(1,58)
          read  (58,*) nnen, nz,nspecprot
 	  if (nnen.gt.nbren)then
 	    write(6,*)'Tableau des productions de proto-electrons'
 	    write(6,*)'de taille en E > nbren. Declarer dans sub. prot'
 	    write(6,*)'un tableau de bonne taille et recommencer'
 	    stop
	  endif
 	  if (nz.gt.200)then
 	    write(6,*)'Tableau des productions de proto-electrons'
 	    write(6,*)'de taille en z > 200. Declarer dans sub. prot'
 	    write(6,*)'un tableau de bonne taille et recommencer'
 	    stop
	  endif

 	  call xline(1,58)
          read  (58,*) (eprot(ien), ien = 1,nnen)
 	  call xline(1,58)
          read  (58,*) (z(ialt), ialt = 1,nz)
c         production de H+ et H en cm-3s-1eV-1
 	  call xline(1,58)
          read  (58,*) (((proprotion_init(ien,isp,ialt),ien=1,nnen),
     .		      isp=1,2),ialt=1,nz)
          do ien = 1,nnen
 	    do ialt = 1,nz
              proprotion_init(ien,1,ialt)=
     .			.75*proprotion_init(ien,1,ialt)
              proprotion_init(ien,2,ialt)=
     .			.75*proprotion_init(ien,2,ialt)
 	    enddo
 	  enddo
c         La somme vaut la production des protoelec. en cm-3s-1eV-1
          do ien = 1,nnen
            do ialt = 1,nz
              proprotel_init(ialt,ien)=
     .		proprotion_init(ien,1,ialt)+proprotion_init(ien,2,ialt)
            enddo
          enddo
c         Production des protoelectrons en cm-3.s-1  (prion)
 	  call xline(1,58)
          read  (58,*) (proelec_init(ialt), ialt = 1,nz)
 	  do ialt = 1,nz
            proelec_init(ialt)=.75*proelec_init(ialt)
 	  enddo
 	  close(58)
c
 	  call mnmx(z,nz,zmin,zmax,0)
 	  call mnmx(eprot,nnen,eprotmin,eprotmax,0)
c
      	  if(iprt(22).eq.1)then
      	    write (fic_transout,1000)
            write (fic_transout,*) 'Altitudes (z)'
            write (fic_transout,900) (z(ialt), ialt = 1,nz)
            write (fic_transout,*) 'Energies (eprot)'
            write (fic_transout,910) (eprot(ien), ien = 1,nnen)
            write (fic_transout,1040)
            do ialt=1,nz
              write(fic_transout,920)  z(ialt)
              write (fic_transout,910)(proprotel_init(ialt,ien),
     .					ien = 1,nnen)
c             [proprotel_init]=cm-3.s-1.eV-1
 	    enddo
      	  endif
c
c 	  Interpolations en altitude
c 	  Production totale
 	  call intlin(nz,z,proelec_init,nalt,altkm,prodprotelec)
 	  do ialt = 1,nalt
 	    if(altkm(ialt).lt.zmin .or. altkm(ialt).gt.zmax)
     .		prodprotelec(ialt)=0.
 	  enddo
c
c 	  Interpolation en energie:
	  do ialt=1,nz
	    do ien=1,nnen
	      finput(ien)=proprotel_init(ialt,ien)
 	    enddo
 	    call intlin(nnen,eprot,finput,nen,centE,foutput)
	    do ien=1,nen
	      finter(ien,ialt)=foutput(ien)
 	    enddo
 	  enddo
c
c 	  Interpolation en altitude:
 	  do ien=1,nen
 	    if(centE(ien).gt.eprotmin .and. centE(ien).lt.eprotmax) then
	      do ialt=1,nz
	        finput(ialt)=finter(ien,ialt)
 	      enddo
 	      call intlin(nz,z,finput,nalt,altkm,foutput)
	      do ialt=1,nalt
 	        if(altkm(ialt).gt.zmin .and. altkm(ialt).lt.zmax)
     .	  	  primprotelec(ialt,ien)=foutput(ialt)
 	      enddo
 	    endif
 	  enddo
c
          if(iprt(22).eq.1)then
c           print primary production rate.
            write (fic_transout,1070) nen, nalt
            write (fic_transout,*) 'Altitudes (alt)'
            write (fic_transout,900) (altkm(ialt), ialt = 1,nalt)
            write (fic_transout,*) 'Energies (e)'
            write (fic_transout,910) (centE(ien), ien = 1,nen)
            write (fic_transout,1080)
            do ialt=1,nalt,mcount(5)
              write(fic_transout,920)  altkm(ialt)
              write (fic_transout,910)(primprotelec(ialt,ien),ien=1,nen)
 	    enddo
          endif
c
c 	  On passe en flux.
 	  do ien = 1,nen
	    do ialt=1,nalt
  	      fluxprimprot(ialt,ien)=
     .		primprotelec(ialt,ien)/densig(ialt,ien)
              do iang=-nango2,nango2
c 	        La division par 2 pi vient de l'integration polaire
                qprimprot(ien,ialt,iang)= fluxprimprot(ialt,ien)* r2pi
c 	        On redivise par 2 parce que le flux primaire est
c 	        isotrope (la moitie vers le haut et la moitie vers le
c 	        bas)
                qprimprot(ien,ialt,iang)= qprimprot(ien,ialt,iang)/2.
c 	        On redivise par 2 pour avoir 0,5 erg et pas 1
                qprimprot(ien,ialt,iang)= qprimprot(ien,ialt,iang)/2.
 	      enddo
 	    enddo
 	  enddo
c
          if(iprt(21).eq.1 .or. iprt(22).eq.1)then
c           print normalized source function.
            write (fic_transout,1050) nen, nalt
            write (fic_transout,*) 'Energies (e)'
            write (fic_transout,910) (centE(ien), ien = 1,nen)
            write (fic_transout,*) 'Altitudes (alt)'
            write (fic_transout,900) (altkm(ialt), ialt = 1,nalt)
            write (fic_transout,1090)
            write (fic_transout,900) (prodprotelec(ialt), ialt = 1,nalt)
            write (fic_transout,1060)
            do ialt=1,nalt,mcount(5)
              write(fic_transout,920)  altkm(ialt)
              write(fic_transout,910)(primprotelec(ialt,ien),ien=1,nen)
 	    enddo
          endif
c
 	endif 			! sur calcul ou lecture
c
        return
        end

max_stars_repo_name: space-physics/transcar

max_issues_repo_name: scivision/transcar

max_forks_repo_name: scivision/transcar


text:
Richard M. Brunelle (born: 25 September 1933, Temecula, California; died: 3 May 2009, Davis, California), music teacher at Davis High School from 1967 to 1993, and choir director at Davis Community Church.  He was born and raised in http://en.wikipedia.org/wiki/Temecula,_California Temecula, California where he developed his musical talents and played organ and piano at church services and social functions.  He received his bachelors degree in piano performance from http://en.wikipedia.org/wiki/San_Diego_State_University San Diego State and then served as a chaplains assistant, organist, and music director in the Army.  While stationed in Germany, he met and married his wife, Edelgard.  After the first of three children was born, the family moved to Davis, where he began his teaching career at Davis High School.  At the high school he founded the Davis High School Madrigal Singers DHS Madrigals, Jazz Choir, and Jazz Band, and also directed the DHS Orchestra.  He was very popular and influential to his students and community, and brought out very high quality performances from groups under his direction.

In the community Brunelle was a founding member of the Davis Comic Opera Company and participated in fundraising concerts to benefit Citizens Who Care.

In 1980 he received the A. G. Brinley Award, the Harmony in Our Lives Award in 1988, Outstanding California Music Educator in 1990, and California Teacher of the Year in 1992.

A 40th anniversary Madrigal reunion concert was given in his honor at the Mondavi Center in 2007.

He was posthumously inducted into the Davis High School http://www.dhsblueandwhite.org/hofmembers.html Hall of Fame in Davis Senior High School Hall of Fame 2010.  The Brunelle Theater auditorium at DHS is named after him.

Sources:

1988 Oct. 13, Highwheelers concert: Brunelle wins award Sunday, Weekend Magazine, Davis Enterprise, pg. 2.

Wydick, Judy; 1993, __Mad Capers: Richard Brunelles twentyseven years at Davis High School : with a focus on the Madrigal Choir__, Davis, Calif.: Davis Joint Unified School District, 230 pp.

2007, video: http://www.youtube.com/watch?vrrn005PKZ3g 40th Anniversary Davis High School Madrigal Singers Reunion.  Posted 6 May 2011.  Retrieved 26 Jan. 2013.

2009 May 6, Davis beloved Music Man dies at 75, Davis Enterprise, pg. A1.

ext: f

max_stars_repo_name: voflo/Search

max_issues_repo_name: voflo/Search

max_forks_repo_name: voflo/Search


text:
C
C
C +-----------------------------------------------------------------+
C |                                                                 |
C |                Copyright (C) 1986 by UCAR                       |
C |        University Corporation for Atmospheric Research          |
C |                    All Rights Reserved                          |
C |                                                                 |
C |                 NCARGRAPHICS  Version 1.00                      |
C |                                                                 |
C +-----------------------------------------------------------------+
C
C
C ---------------------------------------------------------------------
C
      SUBROUTINE EZXY (XDRA,YDRA,NPTS,LABG)
C
      REAL XDRA(*),YDRA(*)
C
      CHARACTER*(*) LABG
C
C The routine EZXY draws one curve through the points (XDRA(I),YDRA(I)),
C for I = 1, 2, ... NPTS.
C
C Do statistics-gathering call.
C
      LOGICAL Q8Q4
      SAVE Q8Q4
      DATA Q8Q4 /.TRUE./
      IF (Q8Q4) THEN
        CALL Q8QST4('GRAPHX','AUTOGRAPH','EZXY','VERSION 07')
        Q8Q4 = .FALSE.
      ENDIF
C
C +NOAO
C
      call agdflt
C
C -NOAO
      CALL AGGETI ('SET .',ISET)
      CALL AGGETI ('FRAM.',IFRA)
C
      CALL AGEZSU (2,XDRA,YDRA,NPTS,1,NPTS,LABG,IIVX,IIEX,IIVY,IIEY)
      CALL AGBACK
C
      IF (ISET.GE.0) CALL AGCURV (XDRA,1,YDRA,1,NPTS,1)
C
      IF (IFRA.EQ.1) CALL FRAME
C
C +NOAO
C
      call initag
C
C -NOAO
      RETURN
C
      END

max_stars_repo_name: ysBach/irafdocgen

max_issues_repo_name: kirxkirx/iraf

max_forks_repo_name: kirxkirx/iraf


text:
	SUBROUTINE DSCTYP  ( szctyp, ictwid, size, jctwid, iret )
C************************************************************************
C* DSCTYP								*
C* 									*
C* This subroutine sets the cloud type symbol parameters.  If these 	*
C* parameters are not positive, no changes are made.   			*
C* 									*
C* DSCTYP  ( SZCTYP, ICTWID, SIZE, JCTWID, IRET )			*
C*                                                                    	*
C* Input parameters:							*
C* 	SZCTYP		REAL		Cloud type symbol size 		*
C*                                      multiplier			*
C* 					  <=0 = no change		*
C*      ICTWID		INTEGER		Cloud type symbol width 	*
C*					multiplier			*
C*                                        <=0 = no change		*
C* Output parameters:							*
C*	SIZE		REAL		Cloud type symbol size		*
C*	JCTWID		INTEGER		Cloud type symbol width		*
C* 	IRET		INTEGER		Return code			*
C**									*
C* Log:									*
C* S. Schotz/GSC	 3/90						*
C************************************************************************
	INCLUDE 	'FUNCCODE.PRM'
	INCLUDE		'ERROR.PRM'
	INCLUDE		'DEVACT.CMN'
C*
	INTEGER 	isend (2), ircv
C------------------------------------------------------------------------
C*	Load input parameters into buffer and write them to the mailbox.
C
	isend (1) = 4
	isend (2) = CSCTYP
	CALL GPUT  ( isend,  2, iret )
	IF  ( iret .ne. NORMAL )  RETURN
C
	CALL GPUTR  ( szctyp, 1, iret )
	IF  ( iret .ne. NORMAL )  RETURN
C
	CALL GPUT  ( ictwid, 1, iret )
	IF  ( iret .ne. NORMAL )  RETURN
C
C*	Get output parameters.
C
	CALL GGET  ( iret, 1, ier )
	IF  ( ier .ne. NORMAL )  iret = ier
C*
	CALL GGETR  ( size, 1, ier )
	IF  ( ier .ne. NORMAL )  THEN
	    iret = ier
	ELSE
C
C*	    Save the ACTIVE weather symbol size in common block
C*	    variable.
C
	    tctsz = size
	END IF
C*
        CALL GGET  ( ircv, 1, ier )
        IF  ( ier .ne. NORMAL ) THEN
            iret = ier
        ELSE
C
C*          Save the ACTIVE width in common block and
C*          output variable
C
            jctwid = ircv
            mctwid = jctwid
        END IF
C*
	RETURN
	END

max_stars_repo_name: oxelson/gempak

max_issues_repo_name: oxelson/gempak

max_forks_repo_name: oxelson/gempak


Module br_mod_dist
    Implicit None

    ! *********************************************************************
    ! *      br_mod -- An F90 module for computing the Blackwell-Rao      *
    ! *                estimator given signal samples from the posterior  *
    ! *                                                                   *
    ! *                 Written by Hans Kristian Eriksen                  *
    ! *                                                                   *
    ! *                Copyright 2006, all rights reserved                *
    ! *                                                                   *
    ! *                                                                   *
    ! *   NB! The code is provided as is, and *no* guarantees are given   *
    ! *       as far as either accuracy or correctness goes.              *
    ! *                                                                   *
    ! *  If used for published results, please cite these papers:         *
    ! *                                                                   *
    ! *      - Eriksen et al. 2006, ApJ, submitted, astro-ph/0606088      *
    ! *      - Chu et al. 2005, Phys. Rev. D, 71, 103002                  *
    ! *                                                                   *
    ! *********************************************************************
    ! E. Komatsu, March 5, 2009
    ! -- Changed the orders of do-loops for a better performance
    !    [thanks to Raphael Flauger]

    Integer, Parameter, Private :: i4b = Selected_int_kind(8)
    Integer, Parameter, Private :: sp = Selected_real_kind(5, 30)
    Integer, Parameter, Private :: dp = Selected_real_kind(12, 200)
    Integer, Parameter, Private :: lgt = Kind(.True.)

    Integer(i4b), Private :: lmin, lmax, numsamples, numchain
    Logical(lgt), Private :: first_eval
    Real(dp), Private :: offset
    Real(dp), Allocatable, Dimension(:, :, :), Private :: sigmas

Contains

    ! Initialization routines
    Subroutine initialize_br_mod(lmin_in, sigmas_in)
        Implicit None

        Integer(i4b), Intent(In) :: lmin_in
        Real(sp), Dimension(lmin_in:, 1:, 1:), Intent(In) :: sigmas_in

        Integer(i4b) :: i, j, ell

        lmin = lmin_in
        lmax = Size(sigmas_in(:, 1, 1)) + lmin - 1
        numchain = Size(sigmas_in(lmin, :, 1))
        numsamples = Size(sigmas_in(lmin, 1, :))
        first_eval = .True.

        Allocate(sigmas(lmin:lmax, numchain, numsamples))
        sigmas = Real(sigmas_in, dp)
        ! --- original
        !    do ell = lmin, lmax
        !       do i = 1, numchain
        !          do j = 1, numsamples
        ! ---
        Do j = 1, numsamples
            Do i = 1, numchain
                Do ell = lmin, lmax
                    If (sigmas(ell, i, j) .Le. 0.0) Then
                        Print *, "Error: sigma value <= zero."
                        Print *, "sigma value is ", sigmas(ell, i, j)
                        Print *, "at(ell,chain,sample) = ", ell, i, j
                        Stop
                    End If
                End Do
            End Do
        End Do

    End Subroutine initialize_br_mod

    Subroutine clean_up_br_mod
        Implicit None

        If (Allocated(sigmas)) Deallocate(sigmas)

    End Subroutine clean_up_br_mod

    ! Base computation routine
    Subroutine compute_br_estimator(cls, lnL)
        Implicit None

        Real(dp), Dimension(lmin:), Intent(In) :: cls
        Real(dp), Intent(Out) :: lnL

        Integer(i4b) :: i, j, l
        Real(dp) :: subtotal, x

        If (first_eval) Then
            Call compute_largest_term(cls)
            first_eval = .False.
        End If

        ! Compute the Blackwell-Rao estimator
        lnL = 0.d0

        ! --- original
        !    do i = 1, numchain
        !       do j = 1, numsamples
        ! --- RF

        Do j = 1, numsamples
            Do i = 1, numchain
                ! ---
                subtotal = 0.d0
                Do l = lmin, lmax
                    x = sigmas(l, i, j) / cls(l)
                    subtotal = subtotal + &
                        & 0.5d0 * Real(2*l+1, dp) * (-x+Log(x)) - Log(Real(sigmas(l, i, j), dp))
                End Do

                lnL = lnL + Exp(subtotal-offset)

            End Do
        End Do

        If (lnL > 1e-20) Then
            lnL = Log(lnL)
        Else
            lnL = Log(1e-30)
        End If

        ! print *, lnL

    End Subroutine compute_br_estimator

    ! Routine for reading the Gibbs sigma samples
    Subroutine read_gibbs_chain(filename, unit, lmax, numchains, numsamples, Data)
        Implicit None

        Character(Len=*), Intent(In) :: filename
        Integer(i4b), Intent(In) :: unit
        Integer(i4b), Intent(Out) :: lmax, numchains, numsamples
        Real(sp), Pointer, Dimension(:, :, :) :: Data

        Integer(i4b) :: l, status, blocksize, readwrite, numspec, i, j, k
        Integer(i4b) :: fpixel, group, numargs
        Logical(lgt) :: anyf
        Real(sp) :: nullval
        Character(Len=80) :: comment

        Integer(i4b), Dimension(4) :: naxes
        Real(sp), Pointer, Dimension(:, :, :, :) :: indata

        status = 0
        readwrite = 0
        nullval = 0.

        ! numargs = 1
        numargs = 0

        ! Open the result file
        Call ftopen(unit, Trim(filename), readwrite, blocksize, status)

        ! Read keywords
        Call ftgkyj(unit, 'LMAX', lmax, comment, status)
        Call ftgkyj(unit, 'NUMSAMP', numsamples, comment, status)
        Call ftgkyj(unit, 'NUMCHAIN', numchains, comment, status)
        Call ftgkyj(unit, 'NUMSPEC', numspec, comment, status)

        Allocate(Data(0:lmax, numchains, numsamples))
        Nullify(indata)
        Allocate(indata(0:lmax, 1:1, 1:numchains, 1:numargs+numsamples))

!!$    print *, "Allocated arrays"

        ! Read the binned power spectrum array
        group = 1
        fpixel = 1
        Call ftgpve(unit, group, fpixel, Size(indata), nullval, indata, anyf, status)

!!$    print *, "Read data"

        Call ftclos(unit, status)

!!$    print *, "Closed file"

        ! --- original
        !    do i = 0, lmax
        !       do j = 1, numchains
        !          do k = numargs+1, numargs+numsamples
        ! --- RF
        Do k = numargs + 1, numargs + numsamples
            Do j = 1, numchains
                Do i = 0, lmax
                    ! ---
                    Data(i, j, k) = indata(i, 1, j, k)
                    ! data(:,:,:) = indata(0:lmax,1:1,1:numchains,numargs+1:numargs+numsamples)
                End Do
            End Do
        End Do

!!$    print *, "Deallocating data"

        Deallocate(indata)

!!$    print *, "Leaving subroutine"

    End Subroutine read_gibbs_chain

    ! Utility routine for initializing the offset to be subtracted from each term
    ! to avoid overflow errors. Only called with the first power spectrum
    Subroutine compute_largest_term(cls)
        Implicit None

        Real(dp), Dimension(lmin:), Intent(In) :: cls

        Integer(i4b) :: i, j, l
        Real(dp) :: subtotal, x

        ! Compute the Blackwell-Rao estimator
        offset = - 1.6375e30

        ! --- original
        !    do i = 1, numchain
        !       do j = 1, numsamples
        ! --- RF

        Do j = 1, numsamples
            Do i = 1, numchain
                ! ---
                subtotal = 0.d0
                Do l = lmin, lmax
                    x = sigmas(l, i, j) / cls(l)
                    subtotal = subtotal + &
                        & 0.5d0 * Real(2*l+1, dp) * (-x+Log(x)) - Log(Real(sigmas(l, i, j), dp))
                End Do

                offset = Max(offset, subtotal)

            End Do
        End Do

        If (offset <-1.637e30) Then
            Print *, "Error: offset in br_mod_dist not being computed properly"
            Print *, "lmin = ", lmin
            Print *, "lmax = ", lmax
            Print *, "numchain = ", numchain
            Print *, "numsamples = ", numsamples
            Print *, "offset = ", offset
            Print *, "cls = ", cls(lmin:lmax)
            Print *, "sigmas(lmin:lmax, 10, 10) = ", sigmas(lmin:lmax, 10, 10)
            Stop
        End If

    End Subroutine compute_largest_term

End Module br_mod_dist


text:
C*******************************************************************
C*          MadEvent - Pythia interface.                           *
C*                                                                 *
C*                                                                 *
C*   Adapted version from ME2pythia 1.66 (J.Alwall)                *
C*                                                                 *
C*       Simon de Visscher August 2010   sdevissc@cern.ch          *
C*        - Complete upgrade to 1.66                               *
C*        - Addition of showerkt                                   *
C*        - Addition of resonance exclusion for BSM matching       *
C*                                                                 *
C*       Christophe Saout 2009                                     *
C*        - Improvement of JetMatching interface                   *
C*                                                                 *
C*       Dorian Kcira 2008.02.05                                         *
C*        -First implementation of KtMLM in CMSSW                  *
C*       - Improvement of matching routines                        *
C*                                                                 *
C*                                                                 *
C*******************************************************************

C*********************************************************************
C...UPINIT
C...Routine called by PYINIT to set up user-defined processes.
C*********************************************************************
      SUBROUTINE MGINIT(npara,param,value)

      IMPLICIT NONE

      integer npara
      character*20 param(*),value(*)

c      CHARACTER*132 CHAR_READ

C...Pythia parameters.
      INTEGER MSTP,MSTI,MRPY
      DOUBLE PRECISION PARP,PARI,RRPY
      COMMON/PYPARS/MSTP(200),PARP(200),MSTI(200),PARI(200)
      COMMON/PYDATR/MRPY(6),RRPY(100)

C...User process initialization commonblock.
      INTEGER MAXPUP
      PARAMETER (MAXPUP=100)
      INTEGER IDBMUP,PDFGUP,PDFSUP,IDWTUP,NPRUP,LPRUP
      DOUBLE PRECISION EBMUP,XSECUP,XERRUP,XMAXUP
      COMMON/HEPRUP/IDBMUP(2),EBMUP(2),PDFGUP(2),PDFSUP(2),
     &   IDWTUP,NPRUP,XSECUP(MAXPUP),XERRUP(MAXPUP),XMAXUP(MAXPUP),
     &   LPRUP(MAXPUP)

C...Extra commonblock to transfer run info.
      INTEGER LNHIN,LNHOUT,MSCAL,IEVNT,ICKKW,ISCALE
      COMMON/UPPRIV/LNHIN,LNHOUT,MSCAL,IEVNT,ICKKW,ISCALE
      DATA LNHIN,LNHOUT,MSCAL,IEVNT,ICKKW,ISCALE/77,6,1,0,0,1/
      SAVE /UPPRIV/

C...Inputs for the matching algorithm
      double precision etcjet,rclmax,etaclmax,qcut,clfact,showerkt
      integer maxjets,minjets,iexcfile,ktsche,mektsc,nexcres,excres(30)
      integer nqmatch,nexcproc,iexcproc(MAXPUP),iexcval(MAXPUP)
      logical nosingrad,jetprocs
      common/MEMAIN/etcjet,rclmax,etaclmax,qcut,showerkt,clfact,
     $   maxjets,minjets,iexcfile,ktsche,mektsc,nexcres,excres,
     $   nqmatch,nexcproc,iexcproc,iexcval,nosingrad,jetprocs

C...Parameter arrays (local)
C      integer maxpara
C      parameter (maxpara=1000)
C      integer npara,iseed
C      character*20 param(maxpara),value(maxpara)

C...Lines to read in assumed never longer than 200 characters.
C      INTEGER MAXLEN,IBEG,IPR,I
C      PARAMETER (MAXLEN=200)
C      CHARACTER*(MAXLEN) STRING

C...Functions
C      INTEGER iexclusive
C      EXTERNAL iexclusive

C...Format for reading lines.
C      CHARACTER*6 STRFMT
C      STRFMT='(A000)'
C      WRITE(STRFMT(3:5),'(I3)') MAXLEN

C...Extract the model parameter card and read it.
C      CALL MODELPAR(LNHIN)

c...Read the <init> block information

C...Loop until finds line beginning with "<init>" or "<init ".
C  100 READ(LNHIN,STRFMT,END=130,ERR=130) STRING
C...Pick out random number seed and use for PYR initialization
C      IF(INDEX(STRING,'iseed').NE.0)THEN
C         READ(STRING,*) iseed
C         IF(iseed.gt.0) THEN
C            WRITE(LNHOUT,*) 'Initializing PYR with random seed ',iseed
c            MRPY(1) = iseed
C            MRPY(2) = 0
C         ENDIF
C      ENDIF
C      IBEG=0
C  110 IBEG=IBEG+1
C...Allow indentation.
C      IF(STRING(IBEG:IBEG).EQ.' '.AND.IBEG.LT.MAXLEN-5) GOTO 110
C      IF(STRING(IBEG:IBEG+5).NE.'<init>'.AND.
C     &STRING(IBEG:IBEG+5).NE.'<init ') GOTO 100

C...Read first line of initialization info.
C      READ(LNHIN,*,END=130,ERR=130) IDBMUP(1),IDBMUP(2),EBMUP(1),
C     &EBMUP(2),PDFGUP(1),PDFGUP(2),PDFSUP(1),PDFSUP(2),IDWTUP,NPRUP

C...Read NPRUP subsequent lines with information on each process.
C      DO 120 IPR=1,NPRUP
C        READ(LNHIN,*,END=130,ERR=130) XSECUP(IPR),XERRUP(IPR),
C     &  XMAXUP(IPR),LPRUP(IPR)
C  120 CONTINUE

C...Set PDFLIB or LHAPDF pdf number for Pythia

C      IF(PDFSUP(1).NE.19070.AND.(PDFSUP(1).NE.0.OR.PDFSUP(2).NE.0))THEN
c     Not CTEQ5L, which is standard in Pythia
C         CALL PYGIVE('MSTP(52)=2')
c     The following works for both PDFLIB and LHAPDF (where PDFGUP(1)=0)
c     But note that the MadEvent output uses the LHAPDF numbering scheme
C        IF(PDFSUP(1).NE.0)THEN
C           MSTP(51)=1000*PDFGUP(1)+PDFSUP(1)
C        ELSE
C           MSTP(51)=1000*PDFGUP(2)+PDFSUP(2)
C        ENDIF
C      ENDIF

C...Initialize widths and partial widths for resonances.
C      CALL PYINRE

C...Calculate xsec reduction due to non-decayed resonances
C...based on first event only!

C      CALL BRSUPP

C      REWIND(LNHIN)

C...Extract cuts and matching parameters
C      CALL read_params(LNHIN,npara,param,value,maxpara)

C      call get_integer(npara,param,value," ickkw ",ickkw,0)
C      if(ickkw.eq.1)then
C         call get_integer(npara,param,value," ktscheme ",mektsc,1)
C         write(*,*)'Running matching with ME ktscheme ',mektsc
C      endif
C
C...Set kt clustering scheme (if not already set)
C
      integer i
      call initpydata
      write(*,*)"MGINIT: ickkw is ",ickkw
      write(*,*)"MGINIT: ktscheme is ",mektsc
      write(*,*)"MGINIT: QCut is ",qcut
      write(*,*)"MGINIT: Showerkt is ",showerkt
	  do 10 i = 1, nexcres
         write(*,*) 'EXCRES(', i,')=',EXCRES(i)
  10  continue

      IF(ABS(IDBMUP(1)).EQ.11.AND.ABS(IDBMUP(2)).EQ.11.AND.
     $     IDBMUP(1).EQ.-IDBMUP(2).AND.ktsche.EQ.0)THEN
         ktsche=1
      ELSE IF(ktsche.EQ.0) THEN
         ktsche=4313
      ENDIF

C...Enhance primordial kt
c      CALL PYGIVE('PARP(91)=2.5')
c      CALL PYGIVE('PARP(93)=15')

      IF(ickkw.gt.0) CALL set_matching(npara,param,value)

C...For photon initial states from protons: Set proton not to break up
      CALL PYGIVE('MSTP(98)=1')

C      IF(ickkw.gt.0.and.(NPRUP.gt.1.or.iexclusive(LPRUP(1)).ne.-1))
C     $     CALL set_matching(LNHIN,npara,param,value)

C...For photon initial states from protons: Set proton not to break up
C      CALL PYGIVE('MSTP(98)=1')

C...Reset event numbering
C      IEVNT=0

      RETURN

C...Error exit: give up if initalization does not work.
C  130 WRITE(*,*) ' Failed to read LHEF initialization information.'
C      WRITE(*,*) ' Event generation will be stopped.'
C      STOP
      END

C*********************************************************************
C...UPEVNT
C...Routine called by PYEVNT or PYEVNW to get user process event
C*********************************************************************
      SUBROUTINE MGEVNT

      IMPLICIT NONE

C...Pythia parameters.
      INTEGER MSTP,MSTI
      DOUBLE PRECISION PARP,PARI
      COMMON/PYPARS/MSTP(200),PARP(200),MSTI(200),PARI(200)

C...User process initialization commonblock.
      INTEGER MAXPUP
      PARAMETER (MAXPUP=100)
      INTEGER IDBMUP,PDFGUP,PDFSUP,IDWTUP,NPRUP,LPRUP
      DOUBLE PRECISION EBMUP,XSECUP,XERRUP,XMAXUP
      COMMON/HEPRUP/IDBMUP(2),EBMUP(2),PDFGUP(2),PDFSUP(2),
     &   IDWTUP,NPRUP,XSECUP(MAXPUP),XERRUP(MAXPUP),XMAXUP(MAXPUP),
     &   LPRUP(MAXPUP)
C...User process event common block.
      INTEGER MAXNUP
      PARAMETER (MAXNUP=500)
      INTEGER NUP,IDPRUP,IDUP,ISTUP,MOTHUP,ICOLUP
      DOUBLE PRECISION XWGTUP,SCALUP,AQEDUP,AQCDUP,PUP,VTIMUP,SPINUP
      COMMON/HEPEUP/NUP,IDPRUP,XWGTUP,SCALUP,AQEDUP,AQCDUP,IDUP(MAXNUP),
     &   ISTUP(MAXNUP),MOTHUP(2,MAXNUP),ICOLUP(2,MAXNUP),PUP(5,MAXNUP),
     &   VTIMUP(MAXNUP),SPINUP(MAXNUP)
C...Pythia common blocks
      INTEGER PYCOMP,KCHG,MINT,NPART,NPARTD,IPART,MAXNUR
      DOUBLE PRECISION PMAS,PARF,VCKM,VINT,PTPART
C...Particle properties + some flavour parameters.
      COMMON/PYDAT2/KCHG(500,4),PMAS(500,4),PARF(2000),VCKM(4,4)
      COMMON/PYINT1/MINT(400),VINT(400)
      PARAMETER (MAXNUR=1000)
      COMMON/PYPART/NPART,NPARTD,IPART(MAXNUR),PTPART(MAXNUR)

C...Extra commonblock to transfer run info.
      INTEGER LNHIN,LNHOUT,MSCAL,IEVNT,ICKKW,ISCALE
      COMMON/UPPRIV/LNHIN,LNHOUT,MSCAL,IEVNT,ICKKW,ISCALE

C...Inputs for the matching algorithm
      double precision etcjet,rclmax,etaclmax,qcut,clfact,showerkt
      integer maxjets,minjets,iexcfile,ktsche,mektsc,nexcres,excres(30)
      integer nqmatch,nexcproc,iexcproc(MAXPUP),iexcval(MAXPUP)
      logical nosingrad,jetprocs
      common/MEMAIN/etcjet,rclmax,etaclmax,qcut,showerkt,clfact,
     $   maxjets,minjets,iexcfile,ktsche,mektsc,nexcres,excres,
     $   nqmatch,nexcproc,iexcproc,iexcval,nosingrad,jetprocs

C...Commonblock to transfer event-by-event matching info
      INTEGER NLJETS,IEXC,Ifile
      DOUBLE PRECISION PTCLUS
      COMMON/MEMAEV/PTCLUS(20),NLJETS,IEXC,Ifile

C...Local variables
      INTEGER I,NEX,KP(MAXNUP),MOTH,NUPREAD,II,iexcl
      DOUBLE PRECISION PSUM,ESUM
C...Lines to read in assumed never longer than 200 characters.
      INTEGER MAXLEN
      PARAMETER (MAXLEN=200)

C...Functions
      INTEGER iexclusive
      EXTERNAL iexclusive
C...Format for reading lines.
C      CHARACTER*6 STRFMT
C      CHARACTER*1 CDUM

C      STRFMT='(A000)'
C      WRITE(STRFMT(3:5),'(I3)') MAXLEN

C...Loop until finds line beginning with "<event>" or "<event ".
C  100 READ(LNHIN,STRFMT,END=900,ERR=900) STRING
C      IBEG=0
C  110 IBEG=IBEG+1
C...Allow indentation.
C      IF(STRING(IBEG:IBEG).EQ.' '.AND.IBEG.LT.MAXLEN-6) GOTO 110
C      IF(STRING(IBEG:IBEG+6).NE.'<event>'.AND.
C     &STRING(IBEG:IBEG+6).NE.'<event ') GOTO 100

C...Read first line of event info.
C      READ(LNHIN,*,END=900,ERR=900) NUPREAD,IDPRUP,XWGTUP,SCALUP,
C     &AQEDUP,AQCDUP

      NUPREAD=NUP

C...Read NUP subsequent lines with information on each particle.
      ESUM=0d0
      PSUM=0d0
      NEX=2
      NUP=1
C      write(*,*)'SCALUP=',SCALUP
      DO 120 I=1,NUPREAD
C      write(*,*)IDUP(NUP),' ',ISTUP(NUP),' ',MOTHUP(1,NUP)
C     &  ,' ',MOTHUP(2,NUP),' ',ICOLUP(1,NUP),' ',ICOLUP(2,NUP)
C     &  ,' ',(PUP(J,NUP),J=1,5),' ',VTIMUP(NUP),' ',SPINUP(NUP)
c        READ(LNHIN,*,END=900,ERR=900) IDUP(NUP),ISTUP(NUP),
c     &  MOTHUP(1,NUP),MOTHUP(2,NUP),ICOLUP(1,NUP),ICOLUP(2,NUP),
c     &  (PUP(J,NUP),J=1,5),VTIMUP(NUP),SPINUP(NUP)
C...Reset resonance momentum to prepare for mass shifts
        IF(ISTUP(NUP).EQ.2) PUP(3,NUP)=0
        IF(ISTUP(NUP).EQ.1)THEN
           NEX=NEX+1
C...Mrenna:  only if 4 < pdgId < 21
           IF(PUP(5,NUP).EQ.0D0.AND.IABS(IDUP(NUP)).GT.3
     $         .AND.IDUP(NUP).LT.21) THEN
C...Set massless particle masses to Pythia default. Adjust z-momentum.
              PUP(5,NUP)=PMAS(IABS(PYCOMP(IDUP(NUP))),1)
              PUP(3,NUP)=SIGN(SQRT(MAX(0d0,PUP(4,NUP)**2-PUP(5,NUP)**2-
     $           PUP(1,NUP)**2-PUP(2,NUP)**2)),PUP(3,NUP))
           ENDIF
           PSUM=PSUM+PUP(3,NUP)
C...Set mother resonance momenta
           MOTH=MOTHUP(1,NUP)
           DO WHILE (MOTH.GT.2)
             PUP(3,MOTH)=PUP(3,MOTH)+PUP(3,NUP)
             MOTH=MOTHUP(1,MOTH)
           ENDDO
        ENDIF
        NUP=NUP+1
  120 CONTINUE
      NUP=NUP-1

C...Increment event number
C      IEVNT=IEVNT+1

C..Adjust mass of resonances
      DO I=1,NUP
         IF(ISTUP(I).EQ.2)THEN
            PUP(5,I)=SQRT(PUP(4,I)**2-PUP(1,I)**2-PUP(2,I)**2-
     $             PUP(3,I)**2)
         ENDIF
      ENDDO

C...Adjust energy and momentum of incoming particles
C...In massive case need to solve quadratic equation
c      PM1=PUP(5,1)**2
c      PM2=PUP(5,2)**2
c      A1=4d0*(ESUM**2-PSUM**2)
c      A2=ESUM**2-PSUM**2+PM2-PM1
c      A3=2d0*PSUM*A2
c      A4=A3/A1
c      A5=(A2**2-4d0*ESUM**2*PM2)/A1
c
c      PUP(3,2)=A4+SIGN(SQRT(A4**2+A5),PUP(3,2))
c      PUP(3,1)=PSUM-PUP(3,2)
c      PUP(4,1)=SQRT(PUP(3,1)**2+PM1)
c      PUP(4,2)=SQRT(PUP(3,2)**2+PM2)

      ESUM=PUP(4,1)+PUP(4,2)

C...Assuming massless incoming particles - otherwise Pythia adjusts
C...the momenta to make them massless
C     IF(IDBMUP(1).GT.100.AND.IDBMUP(2).GT.100)THEN
C       DO I=1,2
C          PUP(3,I)=0.5d0*(PSUM+SIGN(ESUM,PUP(3,I)))
C          PUP(5,I)=0d0
C        ENDDO
C        PUP(4,1)=ABS(PUP(3,1))
C        PUP(4,2)=ESUM-PUP(4,1)
C      ENDIF

C...If you want to use some other scale for parton showering then the
C...factorisation scale given by MadEvent, please implement the function PYMASC
C...(example function included below)

      IF(ickkw.eq.0.AND.MSCAL.GT.0) CALL PYMASC(SCALUP)
c      IF(MINT(35).eq.3.AND.ickkw.EQ.1) SCALUP=SQRT(PARP(67))*SCALUP

C...Read FSR scale for all FS particles (as comment in event file)
C      IF(ickkw.eq.1)THEN
C        READ(LNHIN,*,END=900,ERR=130) CDUM,(PTPART(I),I=1,NEX)
C 130    CONTINUE
C      ENDIF

      IF(ickkw.gt.0) THEN
c
c   Set up number of jets
c
C         write(*,*)'Setting up the number of jets'
         NLJETS=0
         NPART=0
C         write(*,*)'Cycling on 3->NUP'
         do i=3,NUP
C            write(*,*)'Iteration: i=',i
            if(ISTUP(i).ne.1) cycle
C            write(*,*)'Npart++'
            NPART=NPART+1
            IPART(NPART)=i
            if(iabs(IDUP(i)).gt.nqmatch.and.IDUP(i).ne.21) cycle
            if(MOTHUP(1,i).gt.2) cycle
C     Remove final-state partons that combine to color singlets
            IF((ABS(IDBMUP(1)).NE.11.OR.IDBMUP(1).NE.-IDBMUP(2)).AND.
     $           nosingrad) THEN
               DO II=3,NUP
                  IF(II.NE.i.AND.ISTUP(II).EQ.1)THEN
                     IF((IDUP(II).EQ.-IDUP(i).OR.
     $                    IDUP(i).EQ.21.AND.IDUP(II).EQ.21).AND.
     $                    ICOLUP(1,II).EQ.ICOLUP(2,i).AND.
     $                    ICOLUP(2,II).EQ.ICOLUP(1,i))then
c                        print *,'Found color singlet'
                        CALL PYLIST(7)
                        GOTO 140
                     endif
                  ENDIF
               ENDDO
            ENDIF
            NLJETS=NLJETS+1
C            WRITE(*,*) ' NLJETS=',NLJETS
            PTCLUS(NLJETS)=PTPART(NPART)
c            print *,'   Adding a jet and NLJETS=',NLJETS,' and
c     $        PTCLUS(',NLJETS,')=',PTCLUS(NLJETS)
 140        continue
         enddo
         CALL ALPSOR(PTCLUS,nljets,KP,1)

         if(jetprocs) IDPRUP=LPRUP(NLJETS-MINJETS+1)

         IF(ickkw.eq.1) THEN
c   ... and decide whether exclusive or inclusive
            iexcl=iexclusive(IDPRUP)
            if((IEXCFILE.EQ.0.and.NLJETS.eq.MAXJETS.or.
     $           iexcl.eq.0).and.
     $           iexcl.ne.1)then
               IEXC=0
            else if(iexcl.eq.-1)then
               IEXC=-1
            else
               IEXC=1
            endif
         ENDIF
      ENDIF
c      write( *,*)'finishing MGEVNT'
      RETURN

C...Error exit, typically when no more events.
C  900 WRITE(*,*) ' Failed to read LHEF event information,'
C      WRITE(*,*) ' assume end of file has been reached.'
C      NUP=0
C      MINT(51)=2
C      write( *,*)'finishing MGEVNT'
C      RETURN
      END

C*********************************************************************
C...UPVETO
C...Subroutine to implement the MLM jet matching criterion
C*********************************************************************
      SUBROUTINE MGVETO(IPVETO)

      IMPLICIT NONE

C...Pythia common blocks
      INTEGER MINT
      DOUBLE PRECISION VINT
      COMMON/PYINT1/MINT(400),VINT(400)
      INTEGER MSTP,MSTI
      DOUBLE PRECISION PARP,PARI
      COMMON/PYPARS/MSTP(200),PARP(200),MSTI(200),PARI(200)

C...GUP Event common block
      INTEGER MAXNUP
      PARAMETER (MAXNUP=500)
      INTEGER NUP,IDPRUP,IDUP,ISTUP,MOTHUP,ICOLUP
      DOUBLE PRECISION XWGTUP,SCALUP,AQEDUP,AQCDUP,PUP,VTIMUP,SPINUP
      COMMON/HEPEUP/NUP,IDPRUP,XWGTUP,SCALUP,AQEDUP,AQCDUP,
     &              IDUP(MAXNUP),ISTUP(MAXNUP),MOTHUP(2,MAXNUP),
     &              ICOLUP(2,MAXNUP),PUP(5,MAXNUP),VTIMUP(MAXNUP),
     &              SPINUP(MAXNUP)
C...User process initialization commonblock.
      INTEGER MAXPUP
      PARAMETER (MAXPUP=100)
      INTEGER IDBMUP,PDFGUP,PDFSUP,IDWTUP,NPRUP,LPRUP
      DOUBLE PRECISION EBMUP,XSECUP,XERRUP,XMAXUP
      COMMON/HEPRUP/IDBMUP(2),EBMUP(2),PDFGUP(2),PDFSUP(2),
     &   IDWTUP,NPRUP,XSECUP(MAXPUP),XERRUP(MAXPUP),XMAXUP(MAXPUP),
     &   LPRUP(MAXPUP)
C...HEPEVT commonblock.
      INTEGER NMXHEP,NEVHEP,NHEP,ISTHEP,IDHEP,JMOHEP,JDAHEP
      PARAMETER (NMXHEP=4000)
      COMMON/HEPEVT/NEVHEP,NHEP,ISTHEP(NMXHEP),IDHEP(NMXHEP),
     &JMOHEP(2,NMXHEP),JDAHEP(2,NMXHEP),PHEP(5,NMXHEP),VHEP(4,NMXHEP)
      DOUBLE PRECISION PHEP,VHEP
      SAVE /HEPEVT/
      INTEGER IPVETO
C...GETJET commonblocks
      INTEGER MNCY,MNCPHI,NCY,NCPHI,NJMAX,JETNO,NCJET
      DOUBLE PRECISION YCMIN,YCMAX,DELY,DELPHI,ET,STHCAL,CTHCAL,CPHCAL,
     &  SPHCAL,PCJET,ETJET
      PARAMETER (MNCY=200)
      PARAMETER (MNCPHI=200)
      COMMON/CALORM/DELY,DELPHI,ET(MNCY,MNCPHI),
     $CTHCAL(MNCY),STHCAL(MNCY),CPHCAL(MNCPHI),SPHCAL(MNCPHI),
     $YCMIN,YCMAX,NCY,NCPHI
      PARAMETER (NJMAX=500)
      COMMON/GETCOMM/PCJET(4,NJMAX),ETJET(NJMAX),JETNO(MNCY,MNCPHI),
     $NCJET
      DOUBLE PRECISION PI
      PARAMETER (PI=3.141593D0)
C
      DOUBLE PRECISION PSERAP
      INTEGER K(NJMAX),KP(NJMAX),kpj(njmax)

C...Variables for the kT-clustering
      INTEGER NMAX,NN,NSUB,JET,NJETM,IHARD,IP1,IP2
      DOUBLE PRECISION PP,PJET
      DOUBLE PRECISION ECUT,Y,YCUT
      PARAMETER (NMAX=512)
      DIMENSION JET(NMAX),Y(NMAX),PP(4,NMAX),PJET(4,NMAX)
      INTEGER NNM
      DOUBLE PRECISION YM(NMAX),PPM(4,NMAX)

C...kt clustering common block
      INTEGER NMAXKT,NUM,HIST
      PARAMETER (NMAXKT=512)
      DOUBLE PRECISION PPP,KT,ETOT,RSQ,KTP,KTS,KTLAST
      COMMON /KTCOMM/ETOT,RSQ,PPP(9,NMAXKT),KTP(NMAXKT,NMAXKT),
     $   KTS(NMAXKT),KT(NMAXKT),KTLAST(NMAXKT),HIST(NMAXKT),NUM

C...Extra commonblock to transfer run info.
      INTEGER LNHIN,LNHOUT,MSCAL,IEVNT,ICKKW,ISCALE
      COMMON/UPPRIV/LNHIN,LNHOUT,MSCAL,IEVNT,ICKKW,ISCALE

C...Inputs for the matching algorithm
C   clfact determines how jet-to parton matching is done
C   kt-jets: default=1
C    clfact >= 0: Max mult. if within clfact*max(qcut,Q(partNmax)) from jet, others within clfact*qcut
C    clfact < 0: Max mult. if within |clfact|*Q(jetNmax) from jet, other within |clfact|*qcut
C   cone-jets: default=1.5
C    Matching if within clfact*RCLMAX

C...Inputs for the matching algorithm
      double precision etcjet,rclmax,etaclmax,qcut,clfact,showerkt
      integer maxjets,minjets,iexcfile,ktsche,mektsc,nexcres,excres(30)
      integer nqmatch,nexcproc,iexcproc(MAXPUP),iexcval(MAXPUP)
      logical nosingrad,jetprocs
      common/MEMAIN/etcjet,rclmax,etaclmax,qcut,showerkt,clfact,
     $   maxjets,minjets,iexcfile,ktsche,mektsc,nexcres,excres,
     $   nqmatch,nexcproc,iexcproc,iexcval,nosingrad,jetprocs

C...Commonblock to transfer event-by-event matching info
      INTEGER NLJETS,IEXC,Ifile
      DOUBLE PRECISION PTCLUS
      COMMON/MEMAEV/PTCLUS(20),NLJETS,IEXC,Ifile

      INTEGER nvarev,nvar2
      PARAMETER (nvarev=57,nvar2=6)

      REAL*4 varev(nvarev)
      COMMON/HISTDAT/varev

C...Pythia common blocks
      INTEGER NPART,NPARTD,IPART,MAXNUR
	  DOUBLE PRECISION PTPART
      PARAMETER (MAXNUR=1000)
      COMMON/PYPART/NPART,NPARTD,IPART(MAXNUR),PTPART(MAXNUR)

	  INTEGER flag
	  COMMON/OUTTREE/flag

	  CHARACTER*8 htit(nvarev),htit2(nvar2)
      DATA htit/'Npart','Qjet1','Qjet2','Qjet3','Qjet4',
     $   'Ptcjet1','Ptcjet2','Ptcjet3','Ptcjet4',
     $   'Etacjet1','Etacjet2','Etacjet3','Etacjet4',
     $   'Phicjet1','Phicjet2','Phicjet3','Phicjet4',
     $   'Ptjet1','Ptjet2','Ptjet3','Ptjet4',
     $   'Etajet1','Etajet2','Etajet3','Etajet4',
     $   'Phijet1','Phijet2','Phijet3','Phijet4',
     $   'Idres1','Ptres1','Etares1','Phires1',
     $   'Idres2','Ptres2','Etares2','Phires2',
     $   'Ptlep1','Etmiss','Htjets',
     $   'Ptb','Etab','Ptbbar','Etabbar','Ptbj','Etabj',
     $   'Qpar1','Qpar2','Qpar3','Qpar4',
     $   'Ptpar1','Ptpar2','Ptpar3','Ptpar4',
     $   'Ncjets','Njets','Nfile'/
      DATA htit2/'Npart','Qjet1','Qjet2','Qjet3','Qjet4','Nfile'/

C   local variables
      double precision tiny
      parameter (tiny=1d-3)
      integer idbg
      data idbg/0/

      integer i,j,ihep,nmatch,jrmin,KPT(MAXNUP),nres,ii
      double precision etajet,phijet,delr,dphi,delrmin,ptjet
      double precision p(4,10),pt(10),eta(10),phi(10)
      INTEGER IMO
      logical norad(20)
      REAL*4 var2(nvar2)

c      if(NLJETS.GT.0)then
c        idbg=1
c      else
c        idbg=0
c      endif

c      write(*,*)'Entering MGVETO'
c      write(*,*)'qcut is ',qcut,' and showerkt is ',showerkt
      IPVETO=0
c     Return if not MLM matching (or non-matched subprocess)

      IF(ICKKW.LE.0.OR.IEXC.eq.-1) RETURN

      IF(NLJETS.LT.MINJETS.OR.NLJETS.GT.MAXJETS)THEN
        if(idbg.eq.1)
     $     WRITE(LNHOUT,*) 'Failed due to NLJETS ',NLJETS,' < ',MINJETS,
     $        ' or > ',MAXJETS
         GOTO 999
      ENDIF

C      write(*,*)'Throw event if it contains an excluded resonance'
      NRES=0
      DO I=1,NUP
c	     write(*,*)'cycling on particles'
        IF(ISTUP(I).EQ.2)THEN
c			write(*,*)'found S2, now comparin with the ',nexcres,' excres'
           DO J=1,nexcres
c			write(*,*)'comparing ',IDUP(I),' and ',EXCRES(J)
              IF(IDUP(I).EQ.EXCRES(J)) NRES=NRES+1
           ENDDO
        ENDIF
      ENDDO
      IF(NRES.GT.0)THEN
c		write(*,*)'Event',IEVNT,
c     &  ' thrown because of ',NRES,'e r'
c     CALL PYLIST(7)
         GOTO 999
      ENDIF

c init uninit variables
      jrmin = 0

C   Set up vetoed mothers
c      DO I=1,MAXNUP
c        INORAD(I)=0
c      ENDDO
c      DO IHEP=1,NUP-2
c        if(ISTHEP(ihep).gt.1.and.iabs(IDHEP(ihep)).gt.8) then
c        if(iabs(IDHEP(ihep)).gt.5.and.IDHEP(ihep).ne.21) then
c          INORAD(ihep)=1
c        endif
c      ENDDO

c
c     reconstruct parton-level event
c     Set norad for daughters of decayed particles, to not include
c     radiation from these in matched jets
c
      if(idbg.eq.1) then
        write(LNHOUT,*) ' '
        write(LNHOUT,*) 'new event '
c        CALL PYLIST(1)
        CALL PYLIST(7)
        CALL PYLIST(5)
        write(LNHOUT,*) 'PARTONS'
      endif
      i=0
      do ihep=3,nup
         NORAD(ihep)=.false.
        if((ABS(IDBMUP(1)).NE.11.OR.IDBMUP(1).NE.-IDBMUP(2)).AND.
     $        MOTHUP(1,ihep).gt.2) goto 100
        if(ISTUP(ihep).ne.1.or.
     $     (iabs(IDUP(ihep)).gt.nqmatch.and.IDUP(ihep).ne.21)) cycle
c     If quark or gluon making singlet system with other final-state parton
c     remove (since unseen singlet resonance) unless e+e- collision
        IF((ABS(IDBMUP(1)).NE.11.OR.IDBMUP(1).NE.-IDBMUP(2)).AND.
     $       nosingrad)THEN
           DO II=3,NUP
              IF(II.NE.ihep.AND.ISTUP(II).EQ.1)THEN
                 IF((IDUP(II).EQ.-IDUP(ihep).OR.
     $                IDUP(ihep).EQ.21.AND.IDUP(II).EQ.21).AND.
     $                ICOLUP(1,II).EQ.ICOLUP(2,ihep).AND.
     $                ICOLUP(2,II).EQ.ICOLUP(1,ihep))
     $                GOTO 100
              ENDIF
           ENDDO
        ENDIF
        i=i+1
        do j=1,4
          p(j,i)=pup(j,ihep)
        enddo
        pt(i)=sqrt(p(1,i)**2+p(2,i)**2)
        if(i.LE.4) varev(50+i)=pt(i)
        eta(i)=-log(tan(0.5d0*atan2(pt(i)+tiny,p(3,i))))
        phi(i)=atan2(p(2,i),p(1,i))
        if(idbg.eq.1) then
          write(LNHOUT,*) pt(i),eta(i),phi(i)
        endif
        cycle
 100    norad(ihep)=.true.
      enddo
      if(i.ne.NLJETS)then
        print *,'Error in UPVETO: Wrong number of jets found ',i,NLJETS
        CALL PYLIST(7)
        CALL PYLIST(2)
        stop
      endif
C Bubble-sort PTs in descending order
      DO I=1,3
         DO J=4,I+1,-1
            IF(varev(50+J).GT.varev(50+I))THEN
               PTJET=varev(50+J)
               varev(50+J)=varev(50+I)
               varev(50+I)=PTJET
            ENDIF
         ENDDO
      ENDDO
C     Set status for non-clustering partons to 2
      DO ihep=1,NHEP
c         ISTORG(ihep)=ISTHEP(ihep)
         IF(ISTHEP(ihep).EQ.1.AND.iabs(IDHEP(ihep)).GT.5.AND.
     $        IDHEP(ihep).NE.21) THEN
            ISTHEP(ihep)=2
         ELSEIF(ISTHEP(ihep).EQ.1.AND.JMOHEP(1,ihep).GT.0) then
            IMO=JMOHEP(1,ihep)
            DO WHILE(IMO.GT.0)
c           Trace mothers, if non-radiating => daughter is decay - remove
              IF(IMO.le.NUP-2.and.norad(IMO+2)) GOTO 105
              IMO=JMOHEP(1,IMO)
            ENDDO
            cycle
 105        ISTHEP(ihep)=2
         ENDIF
      ENDDO

c      DO ihep=1,NHEP
c            print *,'Part ',ihep,' status=',ISTHEP(ihep),'
c     $   PID=',iabs(IDHEP(ihep)),' mother number=',
c     $  JMOHEP(1,ihep),' status=',ISTHEP(JMOHEP(1,
c     $     ihep)),' PID=',IDHEP(JMOHEP(1,ihep))
c      ENDDO

      DO ihep=1,NHEP

	if ( jmohep(1,ihep) .gt. 0 ) then
c
c         If valid mother and status is 2 and a mother of 6<PID>nqmatch =>reject from particle list
c
         IF(ISTHEP(JMOHEP(1,ihep)).EQ.2
     $    .AND.iabs(IDHEP(JMOHEP(1,ihep))).GT.nqmatch.AND.
     $    iabs(IDHEP(JMOHEP(1,ihep))).LT.6) THEN
c            print *,'Have found: part ',ihep,' status=',ISTHEP(ihep),
c     $      'PID=',iabs(IDHEP(ihep)),' mother number=',
c     $      JMOHEP(1,ihep),' status=',ISTHEP(JMOHEP(1,
c     $      ihep)),' PID=',IDHEP(JMOHEP(1,ihep))
          ISTHEP(ihep)=2
         ENDIF
         IF(ISTHEP(ihep).eq.1.AND.iabs(IDHEP(ihep)).GT.
     $     nqmatch.AND.iabs(IDHEP(ihep)).LT.6.AND.
     $     ISTHEP(JMOHEP(1,ihep)).EQ.2.AND.iabs(IDHEP(JMOHEP(1,ihep)))
     $     .EQ.21) goto 999
c
        endif

      ENDDO
c
c      DO ihep=1,NHEP
c          IF(ISTHEP(ihep).EQ.1)print *,'After selection:  Part ',
c     $ ihep,' status=',ISTHEP(ihep),'PID=',iabs(IDHEP(ihep))
c     $   ,' mother number=',JMOHEP(1,ihep),' status=',
c     $   ISTHEP(JMOHEP(1,ihep)),' PID=',IDHEP(JMOHEP(1,ihep))
c       ENDDO

C     Prepare histogram filling
        DO I=1,4
          var2(1+I)=-1
          varev(46+I)=-1
          varev(50+I)=-1
        ENDDO

      I=0
      if(idbg.eq.1) then
        do i=1,nhep
          write(LNHOUT,1000)i,isthep(i),idhep(i),jmohep(1,i),jmohep(2,i)
     $         ,phep(1,i),phep(2,i),phep(3,i)
        enddo
 1000   format(5(i4,1x),3(f12.5,1x))
      endif

      IF(ICKKW.EQ.2) GOTO 150
      IF(MSTP(61).eq.0..and.MSTP(71).eq.0)then
c      write(*,*)'No showering - just print out event'
      ELSE IF(qcut.le.0d0)then
c      write(*,*)'qcut<0'

      IF(clfact.EQ.0d0) clfact=1.5d0

c      CALL PYLIST(7)
c      CALL PYLIST(2)
c      CALL PYLIST(5)
c     Start from the partonic system
      IF(NLJETS.GT.0) CALL ALPSOR(pt,nljets,KP,2)
c     reconstruct showered jets
c
      YCMAX=ETACLMAX+RCLMAX
      YCMIN=-YCMAX
      CALL CALINIM
      CALL CALDELM(1,1)
      CALL GETJETM(RCLMAX,ETCJET,ETACLMAX)
c     analyse only events with at least nljets-reconstructed jets
      IF(NCJET.GT.0) CALL ALPSOR(ETJET,NCJET,K,2)
      if(idbg.eq.1) then
        write(LNHOUT,*) 'JETS'
        do i=1,ncjet
          j=k(ncjet+1-i)
          ETAJET=PSERAP(PCJET(1,j))
          PHIJET=ATAN2(PCJET(2,j),PCJET(1,j))
          write(LNHOUT,*) etjet(j),etajet,phijet
        enddo
      endif
      IF(NCJET.LT.NLJETS) THEN
        if(idbg.eq.1)
     $     WRITE(LNHOUT,*) 'Failed due to NCJET ',NCJET,' < ',NLJETS
        GOTO 999
      endif
c     associate partons and jets, using min(delr) as criterion
      NMATCH=0
      DO I=1,NCJET
        KPJ(I)=0
      ENDDO
      DO I=1,NLJETS
        DELRMIN=1D5
        DO 110 J=1,NCJET
          IF(KPJ(J).NE.0) GO TO 110
          ETAJET=PSERAP(PCJET(1,J))
          PHIJET=ATAN2(PCJET(2,J),PCJET(1,J))
          DPHI=ABS(PHI(KP(NLJETS-I+1))-PHIJET)
          IF(DPHI.GT.PI) DPHI=2.*PI-DPHI
          DELR=SQRT((ETA(KP(NLJETS-I+1))-ETAJET)**2+(DPHI)**2)
          IF(DELR.LT.DELRMIN) THEN
            DELRMIN=DELR
            JRMIN=J
          ENDIF
 110    CONTINUE
        IF(DELRMIN.LT.clfact*RCLMAX) THEN
          NMATCH=NMATCH+1
          KPJ(JRMIN)=I
        ENDIF
C     WRITE(*,*) 'PARTON-JET',I,' best match:',k(ncjet+1-jrmin)
c     $           ,delrmin
      ENDDO
      IF(NMATCH.LT.NLJETS)  THEN
        if(idbg.eq.1)
     $     WRITE(LNHOUT,*) 'Failed due to NMATCH ',NMATCH,' < ',NLJETS
        GOTO 999
      endif
C REJECT EVENTS WITH LARGER JET MULTIPLICITY FROM EXCLUSIVE SAMPLE
      IF(NCJET.GT.NLJETS.AND.IEXC.EQ.1)  THEN
        if(idbg.eq.1)
     $     WRITE(LNHOUT,*) 'Failed due to NCJET ',NCJET,' > ',NLJETS
        GOTO 999
      endif
C     VETO EVENTS WHERE MATCHED JETS ARE SOFTER THAN NON-MATCHED ONES
      IF(IEXC.NE.1) THEN
        J=NCJET
        DO I=1,NLJETS
          IF(KPJ(K(J)).EQ.0) GOTO 999
          J=J-1
        ENDDO
      ENDIF

      else                      ! qcut.gt.0
      if(showerkt.eq.1.0) then
c      write(*,*)"qcut>=0 and showerkt=1 ==> Veto events where
c     & first shower emission has kt > YCUT"

        IF(NLJETS.EQ.0)THEN
           VINT(358)=0
        ENDIF

        IF(idbg.eq.1) THEN
C           PRINT *,'Using shower emission pt method'
C           write(*,*)'Using shower emission pt method'
C           write(*,*)'qcut, ptclus(1), vint(357),vint(358),vint(360): ',
C     $          qcut,ptclus(1),vint(357),vint(358),vint(360)

C      PRINT *,'qcut, ptclus(1), vint(357),vint(358),vint(360): ',
C     $          qcut,ptclus(1),vint(357),vint(358),vint(360)
        ENDIF
        YCUT=qcut**2

        IF(NLJETS.GT.0.AND.PTCLUS(1)**2.LT.YCUT) THEN
          if(idbg.eq.1)
     $       WRITE(LNHOUT,*) 'Failed due to KT ',
     $       PTCLUS(1),' < ',SQRT(YCUT)
          GOTO 999
        ENDIF
c        PRINT *,'Y,VINT:',SQRT(Y(NLJETS+1)),SQRT(VINT(390))
C        write(*,*)'Y,VINT:',SQRT(Y(NLJETS+1)),SQRT(VINT(390))
C        write(*,*)'mektsc 357, 358: ',mektsc,' ',VINT(357),' ',VINT(358)
        IF(IEXC.EQ.1.AND.
     $       ((mektsc.eq.1.and.MAX(VINT(357),VINT(358)).GT.SQRT(YCUT))
     $       .OR.
     $       (mektsc.eq.2.and.MAX(VINT(360),VINT(358)).GT.SQRT(YCUT))))
     $       THEN
C            write(*,*)'rejection'
          if(idbg.eq.1)
     $       WRITE(LNHOUT,*)
     $       'Failed due to ',max(VINT(357),VINT(358)),' > ',SQRT(YCUT)
          GOTO 999
        ENDIF
C        PRINT *,NLJETS,IEXC,SQRT(VINT(390)),PTCLUS(1),SQRT(YCUT)
C        write(*,*)'NLJets, iexc, VINT, ptclus(1), sqrt(ycut)',NLJETS
c     &,IEXC,SQRT(VINT(390)),PTCLUS(1),SQRT(YCUT)
c     Highest multiplicity case
        IF(IEXC.EQ.0.AND.NLJETS.GT.0.AND.
     $       ((mektsc.eq.1.and.MAX(VINT(357),VINT(358)).GT.PTCLUS(1))
     $       .OR.
     $       (mektsc.eq.2.and.MAX(VINT(360),VINT(358)).GT.PTCLUS(1))))
     $       THEN
c     $     VINT(390).GT.PTCLUS(1)**2)THEN
          if(idbg.eq.1)
     $       WRITE(LNHOUT,*)
     $       'Failed due to ',max(VINT(357),VINT(358)),' > ',PTCLUS(1)
          GOTO 999
        ENDIF
c
      else                      ! not shower kt method

        IF(clfact.EQ.0d0) clfact=1d0

C---FIND FINAL STATE COLOURED PARTICLES
        NN=0
        DO IHEP=1,NHEP
          IF (ISTHEP(IHEP).EQ.1
     $       .AND.(ABS(IDHEP(IHEP)).LE.5.OR.IDHEP(IHEP).EQ.21)) THEN
            PTJET=sqrt(PHEP(1,IHEP)**2+PHEP(2,IHEP)**2)
            ETAJET=ABS(LOG(MIN((SQRT(PTJET**2+PHEP(3,IHEP)**2)+
     $       ABS(PHEP(3,IHEP)))/PTJET,1d5)))
            IF(ETAJET.GT.etaclmax) cycle
            NN=NN+1
            IF (NN.GT.NMAX) then
              CALL PYLIST(2)
              PRINT *, 'Too many particles: ', NN
              NN=NN-1
              GOTO 120
            endif
            DO I=1,4
              PP(I,NN)=PHEP(I,IHEP)
            ENDDO
          ELSE if(idbg.eq.1)THEN
            PRINT *,'Skipping particle ',IHEP,ISTHEP(IHEP),IDHEP(IHEP)
          ENDIF
        ENDDO

C...Cluster event to find values of Y including jet matching but not veto of too many jets
C...Only used to fill the beforeveto Root tree
 120    ECUT=1
        IF (NN.GT.1) then
          CALL KTCLUS(KTSCHE,PP,NN,ECUT,Y,*999)
          if(idbg.eq.1)
     $       WRITE(LNHOUT,*) 'Clustering values:',
     $       (SQRT(Y(i)),i=1,MIN(NN,3))

C       Print out values in the case where all jets are matched at the
C       value of the NLJETS:th clustering
        var2(1)=NLJETS
        var2(6)= Ifile

        if(NLJETS.GT.MINJETS)then
          YCUT=Y(NLJETS)
          CALL KTRECO(MOD(KTSCHE,10),PP,NN,ECUT,YCUT,YCUT,PJET,JET,
     $       NCJET,NSUB,*999)

C     Cluster jets with first hard parton
          DO I=1,NLJETS
            DO J=1,4
              PPM(J,I)=PJET(J,I)
            ENDDO
          ENDDO

          NJETM=NLJETS
          DO IHARD=1,NLJETS
            NNM=NJETM+1
            DO J=1,4
              PPM(J,NNM)=p(J,IHARD)
            ENDDO
            CALL KTCLUS(KTSCHE,PPM,NNM,ECUT,YM,*999)
            IF(YM(NNM).GT.YCUT) THEN
C       Parton not clustered
              GOTO 130
            ENDIF

C       Find jet clustered with parton

            IP1=HIST(NNM)/NMAXKT
            IP2=MOD(HIST(NNM),NMAXKT)
            IF(IP2.NE.NNM.OR.IP1.LE.0)THEN
              GOTO 130
            ENDIF
            DO I=IP1,NJETM-1
              DO J=1,4
                PPM(J,I)=PPM(J,I+1)
              ENDDO
            ENDDO
            NJETM=NJETM-1
          ENDDO                 ! IHARD=1,NLJETS
        endif                   ! NLJETS.GT.MINJETS

        DO I=1,MIN(NN,4)
          var2(1+I)=SQRT(Y(I))
        ENDDO
        WRITE(15,4001) (var2(I),I=1,nvar2)

 130    CONTINUE
C   Now perform jet clustering at the value chosen in qcut

        CALL KTCLUS(KTSCHE,PP,NN,ECUT,Y,*999)

        YCUT=qcut**2
        NCJET=0

C     Reconstruct jet momenta
          CALL KTRECO(MOD(KTSCHE,10),PP,NN,ECUT,YCUT,YCUT,PJET,JET,
     $       NCJET,NSUB,*999)

        ELSE IF (NN.EQ.1) THEN

          Y(1)=PP(1,1)**2+PP(2,1)**2
          IF(Y(1).GT.YCUT)THEN
            NCJET=1
            DO I=1,4
              PJET(I,1)=PP(I,1)
            ENDDO
          ENDIF
        endif

        if(idbg.eq.1) then
          write(LNHOUT,*) 'JETS'
          do i=1,ncjet
            PTJET =SQRT(PJET(1,i)**2+PJET(2,i)**2)
            ETAJET=PSERAP(PJET(1,i))
            PHIJET=ATAN2(PJET(2,i),PJET(1,i))
            write(LNHOUT,*) ptjet,etajet,phijet
          enddo
        endif

        IF(NCJET.LT.NLJETS) THEN
          if(idbg.eq.1)
     $       WRITE(LNHOUT,*) 'Failed due to NCJET ',NCJET,' < ',NLJETS
          GOTO 999
        endif

C...Right number of jets - but the right jets?
C     For max. multiplicity case, count jets only to the NHARD:th jet
        IF(IEXC.EQ.0)THEN
           IF(NLJETS.GT.0)THEN
              YCUT=Y(NLJETS)
              CALL KTRECO(MOD(KTSCHE,10),PP,NN,ECUT,YCUT,YCUT,PJET,JET,
     $             NCJET,NSUB,*999)
              IF(clfact.GE.0d0) THEN
                 CALL ALPSOR(PTCLUS,nljets,KPT,2)
                 YCUT=MAX(qcut,PTCLUS(KPT(1)))**2
              ENDIF
           ENDIF
        ELSE IF(NCJET.GT.NLJETS) THEN
           if(idbg.eq.1)
     $       WRITE(LNHOUT,*) 'Failed due to NCJET ',NCJET,' > ',NLJETS
           GOTO 999
        ENDIF
C     Cluster jets with hard partons, one at a time
        DO I=1,NLJETS
          DO J=1,4
            PPM(J,I)=PJET(J,I)
          ENDDO
        ENDDO

        NJETM=NLJETS
        IF(clfact.NE.0) YCUT=clfact**2*YCUT
c        YCUT=qcut**2
c        YCUT=(1.5*qcut)**2

        DO 140 IHARD=1,NLJETS
          NN=NJETM+1
          DO J=1,4
            PPM(J,NN)=p(J,IHARD)
          ENDDO
          CALL KTCLUS(KTSCHE,PPM,NN,ECUT,Y,*999)

          IF(Y(NN).GT.YCUT) THEN
C       Parton not clustered
          if(idbg.eq.1)
     $       WRITE(LNHOUT,*) 'Failed due to parton ',IHARD,
     $         ' not clustered: ',Y(NN)
            GOTO 999
          ENDIF

C       Find jet clustered with parton

          IP1=HIST(NN)/NMAXKT
          IP2=MOD(HIST(NN),NMAXKT)
          IF(IP2.NE.NN.OR.IP1.LE.0)THEN
          if(idbg.eq.1)
     $       WRITE(LNHOUT,*) 'Failed due to parton ',IHARD,
     $         ' not clustered: ',IP1,IP2,NN,HIST(NN)
            GOTO 999
          ENDIF
C     Remove jet clustered with parton
          DO I=IP1,NJETM-1
            DO J=1,4
              PPM(J,I)=PPM(J,I+1)
            ENDDO
          ENDDO
          NJETM=NJETM-1
 140   CONTINUE

      endif                     ! pt-ordered showers
      endif                     ! qcut.gt.0
C...Cluster particles with |eta| < etaclmax for histograms
 150  NN=0
      DO IHEP=1,NHEP
         IF (ISTHEP(IHEP).EQ.1
     $        .AND.(ABS(IDHEP(IHEP)).LE.5.OR.IDHEP(IHEP).EQ.21)) THEN
            PTJET=sqrt(PHEP(1,IHEP)**2+PHEP(2,IHEP)**2)
            ETAJET=ABS(LOG(MIN((SQRT(PTJET**2+PHEP(3,IHEP)**2)+
     $           ABS(PHEP(3,IHEP)))/PTJET,1d5)))
            IF(ETAJET.GT.etaclmax) cycle
            NN=NN+1
            IF (NN.GT.NMAX) then
               CALL PYLIST(2)
               PRINT *, 'Too many particles: ', NN
               NN=NN-1
               GOTO 160
            ENDIF
            DO I=1,4
               PP(I,NN)=PHEP(I,IHEP)
            ENDDO
         ELSE if(idbg.eq.1)THEN
            PRINT *,'Skipping particle ',IHEP,ISTHEP(IHEP),IDHEP(IHEP)
         ENDIF
      ENDDO

 160  ECUT=1
      IF (NN.GT.1) THEN
         CALL KTCLUS(KTSCHE,PP,NN,ECUT,Y,*999)
      ELSE IF(NN.EQ.1) THEN
         Y(1)=PP(1,NN)**2+PP(2,NN)**2
      ENDIF

      DO I=1,MIN(NN,4)
         varev(46+I)=SQRT(Y(I))
      ENDDO

c      write(*,*)' finishing up mgveto, with ipveto= ', ipveto
        OPEN (10, FILE='events.tree')
c       WRITE(10,'(a)') '# File with ntuple events with the variables:'
c      WRITE(10,CGIVE0) (htit(I)(1:len_trim(htit(I))),I=1,nvarev)
c      write (*,'(a)'),(htit(I)(1:len_trim(htit(I))),I=47,50)
c      write (*,4001),(varev(I),I=47,50)
       if (flag.eq.1) then
          varev(1)=NLJETS
          WRITE(10,4001) varev(1),(varev(I),I=47,50)
c          WRITE(*,4001) varev(1),(varev(I),I=47,50)
      endif

      RETURN
 4001 FORMAT(50E15.6)
c HERWIG/PYTHIA TERMINATION:

 999  IPVETO=1
c      write(*,*)' finishing up mgveto, with ipveto= ', ipveto
      END

C*********************************************************************
C   PYMASC
C   Implementation of scale used in Pythia parton showers
C*********************************************************************
      SUBROUTINE PYMASC(scale)
      IMPLICIT NONE

C...Arguments
      REAL*8 scale

C...Functions
      REAL*8 SMDOT5

C...User process initialization commonblock.
      INTEGER MAXPUP
      PARAMETER (MAXPUP=100)
      INTEGER IDBMUP,PDFGUP,PDFSUP,IDWTUP,NPRUP,LPRUP
      DOUBLE PRECISION EBMUP,XSECUP,XERRUP,XMAXUP
      COMMON/HEPRUP/IDBMUP(2),EBMUP(2),PDFGUP(2),PDFSUP(2),
     &   IDWTUP,NPRUP,XSECUP(MAXPUP),XERRUP(MAXPUP),XMAXUP(MAXPUP),
     &   LPRUP(MAXPUP)
C...User process event common block.
      INTEGER MAXNUP
      PARAMETER (MAXNUP=500)
      INTEGER NUP,IDPRUP,IDUP,ISTUP,MOTHUP,ICOLUP
      DOUBLE PRECISION XWGTUP,SCALUP,AQEDUP,AQCDUP,PUP,VTIMUP,SPINUP
      COMMON/HEPEUP/NUP,IDPRUP,XWGTUP,SCALUP,AQEDUP,AQCDUP,IDUP(MAXNUP),
     &   ISTUP(MAXNUP),MOTHUP(2,MAXNUP),ICOLUP(2,MAXNUP),PUP(5,MAXNUP),
     &   VTIMUP(MAXNUP),SPINUP(MAXNUP)

C...Extra commonblock to transfer run info.
      INTEGER LNHIN,LNHOUT,MSCAL,IEVNT,ICKKW,ISCALE
      COMMON/UPPRIV/LNHIN,LNHOUT,MSCAL,IEVNT,ICKKW,ISCALE

C...Local variables
      INTEGER ICC1,ICC2,IJ,IDC1,IDC2,IC,IC1,IC2
      REAL*8 QMIN,QTMP

C   Just use the scale read off the event record
      scale=SCALUP

C   Alternatively:

C...  Guesses for the correct scale
C     Assumptions:
C     (1) if the initial state is a color singlet, then
C     use s-hat for the scale
C
C     (2) if color flow to the final state, use the minimum
C     of the dot products of color connected pairs
C     (times two for consistency with above)

        QMIN=SMDOT5(PUP(1,1),PUP(1,2))
        ICC1=1
        ICC2=2
C
C     For now, there is no generic way to guarantee the "right"
C     scale choice.  Here, we take the HERWIG pt. of view and
C     choose the dot product of the colored connected "primary"
C     pairs.
C

        DO 101 IJ=1,NUP
          IF(MOTHUP(2,IJ).GT.2) GOTO 101
          IDC1=ICOLUP(1,IJ)
          IDC2=ICOLUP(2,IJ)
          IF(IDC1.EQ.0) IDC1=-1
          IF(IDC2.EQ.0) IDC2=-2

          DO 201 IC=IJ+1,NUP
            IF(MOTHUP(2,IC).GT.2) GOTO 201
            IC1=ICOLUP(1,IC)
            IC2=ICOLUP(2,IC)
            IF(ISTUP(IC)*ISTUP(IJ).GE.1) THEN
              IF(IDC1.EQ.IC2.OR.IDC2.EQ.IC1) THEN
                QTMP=SMDOT5(PUP(1,IJ),PUP(1,IC))
                IF(QTMP.LT.QMIN) THEN
                  QMIN=QTMP
                  ICC1=IJ
                  ICC2=IC
                ENDIF
              ENDIF
            ELSEIF(ISTUP(IC)*ISTUP(IJ).LE.-1) THEN
              IF(IDC1.EQ.IC1.OR.IDC2.EQ.IC2) THEN
                QTMP=SMDOT5(PUP(1,IJ),PUP(1,IC))
                IF(QTMP.LT.QMIN) THEN
                  QMIN=QTMP
                  ICC1=IJ
                  ICC2=IC
                ENDIF
              ENDIF
            ENDIF
 201      CONTINUE
 101    CONTINUE

        scale=QMIN

      RETURN
      END

C...SMDOT5
C   Helper function

      FUNCTION SMDOT5(V1,V2)
      IMPLICIT NONE
      REAL*8 SMDOT5,TEMP
      REAL*8 V1(5),V2(5)
      INTEGER I

      SMDOT5=0D0
      TEMP=V1(4)*V2(4)
      DO I=1,3
        TEMP=TEMP-V1(I)*V2(I)
      ENDDO

      SMDOT5=SQRT(ABS(TEMP))

      RETURN
      END

C*********************************************************************
C...set_matching
C...Sets parameters for the matching, i.e. cuts and jet multiplicities
C*********************************************************************

      SUBROUTINE set_matching(npara,param,value)
      implicit none
c
c   arguments
c
      integer npara
      character*20 param(*),value(*)

C...Pythia parameters.
      INTEGER MSTP,MSTI
      DOUBLE PRECISION PARP,PARI
      COMMON/PYPARS/MSTP(200),PARP(200),MSTI(200),PARI(200)

C...User process initialization commonblock.
      INTEGER MAXPUP
      PARAMETER (MAXPUP=100)
      INTEGER IDBMUP,PDFGUP,PDFSUP,IDWTUP,NPRUP,LPRUP
      DOUBLE PRECISION EBMUP,XSECUP,XERRUP,XMAXUP
      COMMON/HEPRUP/IDBMUP(2),EBMUP(2),PDFGUP(2),PDFSUP(2),
     &   IDWTUP,NPRUP,XSECUP(MAXPUP),XERRUP(MAXPUP),XMAXUP(MAXPUP),
     &   LPRUP(MAXPUP)

C...User process event common block.
      INTEGER MAXNUP
      PARAMETER (MAXNUP=500)
      INTEGER NUP,IDPRUP,IDUP,ISTUP,MOTHUP,ICOLUP
      DOUBLE PRECISION XWGTUP,SCALUP,AQEDUP,AQCDUP,PUP,VTIMUP,SPINUP
      COMMON/HEPEUP/NUP,IDPRUP,XWGTUP,SCALUP,AQEDUP,AQCDUP,IDUP(MAXNUP),
     &   ISTUP(MAXNUP),MOTHUP(2,MAXNUP),ICOLUP(2,MAXNUP),PUP(5,MAXNUP),
     &   VTIMUP(MAXNUP),SPINUP(MAXNUP)

C...Extra commonblock to transfer run info.
      INTEGER LNHIN,LNHOUT,MSCAL,IEVNT,ICKKW,ISCALE
      COMMON/UPPRIV/LNHIN,LNHOUT,MSCAL,IEVNT,ICKKW,ISCALE

C...Inputs for the matching algorithm
      double precision etcjet,rclmax,etaclmax,qcut,clfact,showerkt
      integer maxjets,minjets,iexcfile,ktsche,mektsc,nexcres,excres(30)
      integer nqmatch,nexcproc,iexcproc(MAXPUP),iexcval(MAXPUP)
      logical nosingrad,jetprocs
      common/MEMAIN/etcjet,rclmax,etaclmax,qcut,showerkt,clfact,
     $   maxjets,minjets,iexcfile,ktsche,mektsc,nexcres,excres,
     $   nqmatch,nexcproc,iexcproc,iexcval,nosingrad,jetprocs

c      DATA ktsche,maxjets,minjets,nexcres/0,-1,-1,0/
c      DATA ktsche,nexcres/0,0/
c      DATA qcut,clfact,showerkt/0d0,0d0,0d0/

C...Commonblock to transfer event-by-event matching info
      INTEGER NLJETS,IEXC,Ifile
      DOUBLE PRECISION PTCLUS
      COMMON/MEMAEV/PTCLUS(20),NLJETS,IEXC,Ifile

C...Local variables
      INTEGER I,MAXNJ,NREAD,MINJ,MAXJ
      parameter(MAXNJ=6)
      DOUBLE PRECISION XSTOT(MAXNJ),XSECTOT
      DOUBLE PRECISION ptjmin,etajmax,drjmin,ptbmin,etabmax,xqcut

      integer icount

C...Functions
      INTEGER iexclusive
      EXTERNAL iexclusive

C...Initialize the icount counter to detect infinite loops
      icount=0

C...Need lower scale for final state radiation in e+e-
      IF(IABS(IDBMUP(1)).EQ.11.AND.IABS(IDBMUP(2)).EQ.11) then
        CALL PYGIVE('PARP(71)=1')
      ENDIF

C...CRUCIAL FOR JET-PARTON MATCHING: CALL UPVETO, ALLOW JET-PARTON MATCHING
C      call pygive('MSTP(143)=1')

C
C...Check jet multiplicities and set processes
C
      DO I=1,MAXNJ
        XSTOT(I)=0D0
      ENDDO
      MINJ=MAXNJ
      MAXJ=0
      NREAD=0
      NUP=0
      DO WHILE(.true.)
C	  write(LNHOUT,*)'Launching MGEVNT'
        CALL MGEVNT()
		write(LNHOUT,*)'NLJETS=',NLJETS

	icount = icount+1
        if (icount.gt.10) then
          write (LNHOUT,*)
     &      'GeneratorInterface/PartonShowerVeto ME2phythia:'
     &      //' Aborting, loop in set_matching above ',icount,' cycles'
          write (LNHOUT,*) 'NUP = ',NUP,' IEXC = ',IEXC
          stop
        endif

        IF(NUP.eq.0) goto 20
        IF(IEXC.EQ.-1) cycle

        if(NLJETS.GT.MAXJ) MAXJ=NLJETS
        if(NLJETS.LT.MINJ) MINJ=NLJETS
c        XSTOT(NLJETS+1)=XSTOT(NLJETS+1)+XWGTUP
        XSTOT(NLJETS+1)=XSTOT(NLJETS+1)+1
        NREAD=NREAD+1
      ENDDO

 20   continue

C      REWIND(iunit)

      write(LNHOUT,*) 'Minimum number of jets in file: ',MINJ
      write(LNHOUT,*) 'Maximum number of jets in file: ',MAXJ

      XSECTOT=0d0
      DO I=1,NPRUP
         XSECTOT=XSECTOT+XSECUP(I)
      ENDDO
		write(LNHOUT,*)'NPRUP=',NPRUP
      IF(NPRUP.eq.1.AND.MINJ.lt.MAXJ)THEN
C...If different process ids not set by user, set by jet number

         jetprocs=.true.
         IF(IEXCFILE.eq.0.AND.iexclusive(LPRUP(1)).ne.1) THEN
            nexcproc=1
            IEXCPROC(1)=MAXJ-MINJ
            IEXCVAL(1)=0
         ENDIF
         NPRUP=1+MAXJ-MINJ
         DO I=MINJ,MAXJ
            XSECUP(1+I-MINJ) = XSECTOT*XSTOT(I+1)/NREAD
            XMAXUP(1+I-MINJ) = XMAXUP(1)
            LPRUP(1+I-MINJ)  = I-MINJ
         ENDDO
      ELSE IF(IEXCFILE.EQ.0) THEN
C...Check if any IEXCPROC set, then set IEXCFILE=1
         DO I=1,NPRUP
            IF(iexclusive(LPRUP(I)).EQ.0) IEXCFILE=1
         ENDDO
      ENDIF

      WRITE(LNHOUT,*) ' Number of Events Read:: ',NREAD
      WRITE(LNHOUT,*) ' Total cross section (pb):: ',XSECTOT
      WRITE(LNHOUT,*) ' Process   Cross Section (pb):: '
      DO I=1,NPRUP
        WRITE(LNHOUT,'(I5,E23.5)') I,XSECUP(I)
      ENDDO

      IF(MINJETS.EQ.-1) MINJETS=MINJ
      IF(MAXJETS.EQ.-1) MAXJETS=MAXJ
      write(LNHOUT,*) 'Minimum number of jets allowed: ',MINJETS
      write(LNHOUT,*) 'Maximum number of jets allowed: ',MAXJETS
      write(LNHOUT,*) 'IEXCFILE = ',IEXCFILE
      write(LNHOUT,*) 'jetprocs = ',jetprocs
      DO I=1,NPRUP
         write(LNHOUT,*) 'IEXCPROC(',LPRUP(I),') = ',
     $        iexclusive(LPRUP(I))
      ENDDO

C      CALL FLUSH()

C...Run PYPTFS instead of PYSHOW
c        CALL PYGIVE("MSTJ(41)=12")

c***********************************************************************
c   Read in jet cuts
c***********************************************************************

        call get_real   (npara,param,value," ptj " ,ptjmin,7d3)
        call get_real   (npara,param,value," etaj " ,etajmax,7d3)
        call get_real   (npara,param,value," ptb " ,ptbmin,7d3)
        call get_real   (npara,param,value," etab " ,etabmax,7d3)
        call get_real   (npara,param,value," drjj " ,drjmin,7d3)
        call get_real   (npara,param,value," xqcut " ,xqcut,0d0)

        if(qcut.lt.xqcut) then
           if(showerkt.eq.1) then
              qcut=xqcut
           else
              qcut=max(xqcut*1.2,xqcut+5)
           endif
        endif
        if(xqcut.le.0)then
           write(*,*) 'Warning! ME generation QCUT = 0. QCUT set to 0!'
           qcut=0
        endif

c        etajmax=min(etajmax,etabmax)
c        ptjmin=max(ptjmin,ptbmin)

c      IF(ICKKW.EQ.1) THEN
c        WRITE(*,*) ' '
c        WRITE(*,*) 'INPUT 0 FOR INCLUSIVE JET SAMPLE, 1 FOR EXCLUSIVE'
c        WRITE(*,*) '(SELECT 0 FOR HIGHEST PARTON MULTIPLICITY SAMPLE)'
c        WRITE(*,*) '(SELECT 1 OTHERWISE)'
c        READ(*,*) IEXCFILE
c      ENDIF

C     INPUT PARAMETERS FOR CONE ALGORITHM

        IF(ETCJET.LE.PTJMIN)THEN
           ETCJET=MAX(PTJMIN+5,1.2*PTJMIN)
        ENDIF

        RCLMAX=DRJMIN
        ETACLMAX=ETAJMAX
        IF(qcut.le.0)THEN
          WRITE(*,*) 'JET CONE PARAMETERS FOR MATCHING:'
          WRITE(*,*) 'ET>',ETCJET,' R=',RCLMAX
          WRITE(*,*) 'DR(PARTON-JET)<',1.5*RCLMAX
          WRITE(*,*) 'ETA(JET)<',ETACLMAX
      ELSE IF(ickkw.eq.1) THEN
        WRITE(*,*) 'KT JET PARAMETERS FOR MATCHING:'
        WRITE(*,*) 'QCUT=',qcut
        WRITE(*,*) 'ETA(JET)<',ETACLMAX
        WRITE(*,*) 'Note that in ME generation, qcut = ',xqcut
        write(*,*)'the showerkt param is ',showerkt
        if(showerkt.eq.1.0)THEN
C             WRITE(*,*) 'shower kt is activated'
        endif
        if(showerkt.eq.1.0.and.MSTP(81).LT.20)THEN
          WRITE(*,*)'WARNING: "shower kt" needs pT-ordered showers'
          WRITE(*,*)'         Setting MSTP(81)=',20+MOD(MSTP(81),10)
          MSTP(81)=20+MOD(MSTP(81),10)
       endif
      else if(ickkw.eq.2)then
c     Turn off color coherence suppressions (leave this to ME)
        CALL PYGIVE('MSTP(62)=2')
        CALL PYGIVE('MSTP(67)=0')
        if(MSTP(81).LT.20)THEN
          WRITE(*,*)'WARNING: Must run CKKW with pt-ordered showers'
          WRITE(*,*)'         Setting MSTP(81)=',20+MOD(MSTP(81),10)
          MSTP(81)=20+MOD(MSTP(81),10)
        endif
      endif
      return
      end

      subroutine get_real(npara,param,value,name,var,def_value)
c----------------------------------------------------------------------------------
c   finds the parameter named "name" in param and associate to "value" in value
c----------------------------------------------------------------------------------
      implicit none

c
c   arguments
c
      integer npara
      character*20 param(*),value(*)
      character*(*)  name
      real*8 var,def_value
c
c   local
c
      logical found
      integer i
c
c   start
c
c      write(*,*)'entered get_real subroutine, looking for ',name,
c     &' there are ',npara,' parameters'
      i=1
      found=.false.
      do while(.not.found.and.i.le.npara)
c         write(*,*)'trying ',param(i)
        found = (index(param(i),name).ne.0)
        if (found) read(value(i),*) var
c     if (found) write (*,*) name,var
        i=i+1
      enddo
      if (.not.found) then
        write (*,*) "Warning: parameter ",name," not found"
        write (*,*) "         setting it to default value ",def_value
        var=def_value
      else
        write(*,*) 'Found parameter ',name,var
      endif
      return

      end
c

      subroutine get_integer(npara,param,value,name,var,def_value)
c----------------------------------------------------------------------------------
c   finds the parameter named "name" in param and associate to "value" in value
c----------------------------------------------------------------------------------
      implicit none
c
c   arguments
c
      integer npara
      character*20 param(*),value(*)
      character*(*)  name
      integer var,def_value
c
c   local
c
      logical found
      integer i
c
c   start
c
      i=1
      found=.false.
      do while(.not.found.and.i.le.npara)
        found = (index(param(i),name).ne.0)
        if (found) read(value(i),*) var
c     if (found) write (*,*) name,var
        i=i+1
      enddo
      if (.not.found) then
        write (*,*) "Warning: parameter ",name," not found"
        write (*,*) "         setting it to default value ",def_value
        var=def_value
      else
        write(*,*)'Found parameter ',name,var
      endif
      return

      end

C-----------------------------------------------------------------------
      SUBROUTINE ALPSOR(A,N,K,IOPT)
C-----------------------------------------------------------------------
C     Sort A(N) into ascending order
C     IOPT = 1 : return sorted A and index array K
C     IOPT = 2 : return index array K only
C-----------------------------------------------------------------------
      DOUBLE PRECISION A(N),B(5000)
      INTEGER N,I,J,IOPT,K(N),IL(5000),IR(5000)
      IF (N.GT.5000) then
        write(*,*) 'Too many entries to sort in alpsrt, stop'
        stop
      endif
      if(n.le.0) return
      IL(1)=0
      IR(1)=0
      DO 10 I=2,N
      IL(I)=0
      IR(I)=0
      J=1
   2  IF(A(I).GT.A(J)) GOTO 5
      IF(IL(J).EQ.0) GOTO 4
      J=IL(J)
      GOTO 2
   4  IR(I)=-J
      IL(J)=I
      GOTO 10
   5  IF(IR(J).LE.0) GOTO 6
      J=IR(J)
      GOTO 2
   6  IR(I)=IR(J)
      IR(J)=I
  10  CONTINUE
      I=1
      J=1
      GOTO 8
  20  J=IL(J)
   8  IF(IL(J).GT.0) GOTO 20
   9  K(I)=J
      B(I)=A(J)
      I=I+1
      IF(IR(J)) 12,30,13
  13  J=IR(J)
      GOTO 8
  12  J=-IR(J)
      GOTO 9
  30  IF(IOPT.EQ.2) RETURN
      DO 31 I=1,N
  31  A(I)=B(I)
      END

C-----------------------------------------------------------------------
C----Calorimeter simulation obtained from Frank Paige 23 March 1988-----
C
C          USE
C
C     CALL CALINIM
C     CALL CALSIMM
C
C          THEN TO FIND JETS WITH A SIMPLIFIED VERSION OF THE UA1 JET
C          ALGORITHM WITH JET RADIUS RJET AND MINIMUM SCALAR TRANSVERSE
C          ENERGY EJCUT
C            (RJET=1., EJCUT=5. FOR UA1)
C          USE
C
C     CALL GETJETM(RJET,EJCUT)
C
C
C-----------------------------------------------------------------------
C
C          ADDED BY MIKE SEYMOUR: PARTON-LEVEL CALORIMETER. ALL PARTONS
C          ARE CONSIDERED TO BE HADRONS, SO IN FACT RESEM IS IGNORED
C
C     CALL CALPARM
C
C          HARD PARTICLE CALORIMETER. ONLY USES THOSE PARTICLES WHICH
C          CAME FROM THE HARD PROCESS, AND NOT THE UNDERLYING EVENT
C
C     CALL CALHARM
C
C-----------------------------------------------------------------------
      SUBROUTINE CALINIM
C
C          INITIALIZE CALORIMETER FOR CALSIMM AND GETJETM.  NOTE THAT
C          BECAUSE THE INITIALIZATION IS SEPARATE, CALSIMM CAN BE
C          CALLED MORE THAN ONCE TO SIMULATE PILEUP OF SEVERAL EVENTS.
C
      IMPLICIT NONE
C...GETJET commonblocks
      INTEGER MNCY,MNCPHI,NCY,NCPHI,NJMAX,JETNO,NCJET
      DOUBLE PRECISION YCMIN,YCMAX,DELY,DELPHI,ET,STHCAL,CTHCAL,CPHCAL,
     &  SPHCAL,PCJET,ETJET
      PARAMETER (MNCY=200)
      PARAMETER (MNCPHI=200)
      COMMON/CALORM/DELY,DELPHI,ET(MNCY,MNCPHI),
     $CTHCAL(MNCY),STHCAL(MNCY),CPHCAL(MNCPHI),SPHCAL(MNCPHI),
     $YCMIN,YCMAX,NCY,NCPHI
      PARAMETER (NJMAX=500)
      COMMON/GETCOMM/PCJET(4,NJMAX),ETJET(NJMAX),JETNO(MNCY,MNCPHI),
     $     NCJET

      INTEGER IPHI,IY
      DOUBLE PRECISION PI,PHIX,YX,THX
      PARAMETER (PI=3.141593D0)
      LOGICAL FSTCAL
      DATA FSTCAL/.TRUE./
C
C          INITIALIZE ET ARRAY.
      DO 100 IPHI=1,NCPHI
      DO 100 IY=1,NCY
100   ET(IY,IPHI)=0.
C
      IF (FSTCAL) THEN
C          CALCULATE TRIG. FUNCTIONS.
        DELPHI=2.*PI/FLOAT(NCPHI)
        DO 200 IPHI=1,NCPHI
        PHIX=DELPHI*(IPHI-.5)
        CPHCAL(IPHI)=COS(PHIX)
        SPHCAL(IPHI)=SIN(PHIX)
200     CONTINUE
        DELY=(YCMAX-YCMIN)/FLOAT(NCY)
        DO 300 IY=1,NCY
        YX=DELY*(IY-.5)+YCMIN
        THX=2.*ATAN(EXP(-YX))
        CTHCAL(IY)=COS(THX)
        STHCAL(IY)=SIN(THX)
300     CONTINUE
        FSTCAL=.FALSE.
      ENDIF
      END
C
      SUBROUTINE CALSIMM
C
C          SIMPLE CALORIMETER SIMULATION.  ASSUME UNIFORM Y AND PHI
C          BINS
C...HEPEVT commonblock.
      INTEGER NMXHEP,NEVHEP,NHEP,ISTHEP,IDHEP,JMOHEP,JDAHEP
      PARAMETER (NMXHEP=4000)
      COMMON/HEPEVT/NEVHEP,NHEP,ISTHEP(NMXHEP),IDHEP(NMXHEP),
     &JMOHEP(2,NMXHEP),JDAHEP(2,NMXHEP),PHEP(5,NMXHEP),VHEP(4,NMXHEP)
      DOUBLE PRECISION PHEP,VHEP
      SAVE /HEPEVT/

C...GETJET commonblocks
      INTEGER MNCY,MNCPHI,NCY,NCPHI,NJMAX,JETNO,NCJET
      DOUBLE PRECISION YCMIN,YCMAX,DELY,DELPHI,ET,STHCAL,CTHCAL,CPHCAL,
     &  SPHCAL,PCJET,ETJET
      PARAMETER (MNCY=200)
      PARAMETER (MNCPHI=200)
      COMMON/CALORM/DELY,DELPHI,ET(MNCY,MNCPHI),
     $CTHCAL(MNCY),STHCAL(MNCY),CPHCAL(MNCPHI),SPHCAL(MNCPHI),
     $YCMIN,YCMAX,NCY,NCPHI
      PARAMETER (NJMAX=500)
      COMMON/GETCOMM/PCJET(4,NJMAX),ETJET(NJMAX),JETNO(MNCY,MNCPHI),
     $     NCJET

      INTEGER IHEP,ID,IY,IPHI
      DOUBLE PRECISION PI,YIP,PSERAP,PHIIP,EIP
      PARAMETER (PI=3.141593D0)
C
C          FILL CALORIMETER
C
      DO 200 IHEP=1,NHEP
      IF (ISTHEP(IHEP).EQ.1) THEN
        YIP=PSERAP(PHEP(1,IHEP))
        IF(YIP.LT.YCMIN.OR.YIP.GT.YCMAX) GOTO 200
        ID=ABS(IDHEP(IHEP))
C---EXCLUDE TOP QUARK, LEPTONS, PROMPT PHOTONS
        IF ((ID.GE.11.AND.ID.LE.16).OR.ID.EQ.6.OR.ID.EQ.22) GOTO 200
C
        PHIIP=ATAN2(PHEP(2,IHEP),PHEP(1,IHEP))
        IF(PHIIP.LT.0.) PHIIP=PHIIP+2.*PI
        IY=INT((YIP-YCMIN)/DELY)+1
        IPHI=INT(PHIIP/DELPHI)+1
        EIP=PHEP(4,IHEP)
C            WEIGHT BY SIN(THETA)
        ET(IY,IPHI)=ET(IY,IPHI)+EIP*STHCAL(IY)
      ENDIF
  200 CONTINUE
      END
      SUBROUTINE GETJETM(RJET,EJCUT,ETAJCUT)
C
C          SIMPLE JET-FINDING ALGORITHM (SIMILAR TO UA1).
C
C     FIND HIGHEST REMAINING CELL > ETSTOP AND SUM SURROUNDING
C          CELLS WITH--
C            DELTA(Y)**2+DELTA(PHI)**2<RJET**2
C            ET>ECCUT.
C          KEEP JETS WITH ET>EJCUT AND ABS(ETA)<ETAJCUT
C          THE UA1 PARAMETERS ARE RJET=1.0 AND EJCUT=5.0
C
      IMPLICIT NONE
C...GETJET commonblocks
      INTEGER MNCY,MNCPHI,NCY,NCPHI,NJMAX,JETNO,NCJET
      DOUBLE PRECISION YCMIN,YCMAX,DELY,DELPHI,ET,STHCAL,CTHCAL,CPHCAL,
     &  SPHCAL,PCJET,ETJET
      PARAMETER (MNCY=200)
      PARAMETER (MNCPHI=200)
      COMMON/CALORM/DELY,DELPHI,ET(MNCY,MNCPHI),
     $CTHCAL(MNCY),STHCAL(MNCY),CPHCAL(MNCPHI),SPHCAL(MNCPHI),
     $YCMIN,YCMAX,NCY,NCPHI
      PARAMETER (NJMAX=500)
      COMMON/GETCOMM/PCJET(4,NJMAX),ETJET(NJMAX),JETNO(MNCY,MNCPHI),
     $     NCJET

      INTEGER IPHI,IY,J,K,NPHI1,NPHI2,NY1,
     &  NY2,IPASS,IYMX,IPHIMX,ITLIS,IPHI1,IPHIX,IY1,IYX
      DOUBLE PRECISION PI,RJET,
     &  ETMAX,ETSTOP,RR,ECCUT,PX,EJCUT
      PARAMETER (PI=3.141593D0)
      DOUBLE PRECISION ETAJCUT,PSERAP
C
C          PARAMETERS
      DATA ECCUT/0.1D0/
      DATA ETSTOP/1.5D0/
      DATA ITLIS/6/
C
C          INITIALIZE
C
      DO 100 IPHI=1,NCPHI
      DO 100 IY=1,NCY
100   JETNO(IY,IPHI)=0
      DO 110 J=1,NJMAX
      ETJET(J)=0.
      DO 110 K=1,4
110   PCJET(K,J)=0.
      NCJET=0
      NPHI1=RJET/DELPHI
      NPHI2=2*NPHI1+1
      NY1=RJET/DELY
      NY2=2*NY1+1
      IPASS=0
C-ap  initialize these two too to avoid compiler warnings
      iymx = 0
      iphimx = 0
C-ap  end
C
C          FIND HIGHEST CELL REMAINING
C
1     ETMAX=0.
      DO 200 IPHI=1,NCPHI
      DO 210 IY=1,NCY
      IF(ET(IY,IPHI).LT.ETMAX) GOTO 210
      IF(JETNO(IY,IPHI).NE.0) GOTO 210
      ETMAX=ET(IY,IPHI)
      IYMX=IY
      IPHIMX=IPHI
210   CONTINUE
200   CONTINUE
      IF(ETMAX.LT.ETSTOP) RETURN
C
C          SUM CELLS
C
      IPASS=IPASS+1
      IF(IPASS.GT.NCY*NCPHI) THEN
        WRITE(ITLIS,8888) IPASS
8888    FORMAT(//' ERROR IN GETJETM...IPASS > ',I6)
        RETURN
      ENDIF
      NCJET=NCJET+1
      IF(NCJET.GT.NJMAX) THEN
        WRITE(ITLIS,9999) NCJET
9999    FORMAT(//' ERROR IN GETJETM...NCJET > ',I5)
        RETURN
      ENDIF
      DO 300 IPHI1=1,NPHI2
      IPHIX=IPHIMX-NPHI1-1+IPHI1
      IF(IPHIX.LE.0) IPHIX=IPHIX+NCPHI
      IF(IPHIX.GT.NCPHI) IPHIX=IPHIX-NCPHI
      DO 310 IY1=1,NY2
      IYX=IYMX-NY1-1+IY1
      IF(IYX.LE.0) GOTO 310
      IF(IYX.GT.NCY) GOTO 310
      IF(JETNO(IYX,IPHIX).NE.0) GOTO 310
      RR=(DELY*(IY1-NY1-1))**2+(DELPHI*(IPHI1-NPHI1-1))**2
      IF(RR.GT.RJET**2) GOTO 310
      IF(ET(IYX,IPHIX).LT.ECCUT) GOTO 310
      PX=ET(IYX,IPHIX)/STHCAL(IYX)
C          ADD CELL TO JET
      PCJET(1,NCJET)=PCJET(1,NCJET)+PX*STHCAL(IYX)*CPHCAL(IPHIX)
      PCJET(2,NCJET)=PCJET(2,NCJET)+PX*STHCAL(IYX)*SPHCAL(IPHIX)
      PCJET(3,NCJET)=PCJET(3,NCJET)+PX*CTHCAL(IYX)
      PCJET(4,NCJET)=PCJET(4,NCJET)+PX
      ETJET(NCJET)=ETJET(NCJET)+ET(IYX,IPHIX)
      JETNO(IYX,IPHIX)=NCJET
310   CONTINUE
300   CONTINUE
C
C          DISCARD JET IF ET < EJCUT.
C
      IF(ETJET(NCJET).GT.EJCUT.AND.ABS(PSERAP(PCJET(1,NCJET))).LT
     $     .ETAJCUT) GOTO 1
      ETJET(NCJET)=0.
      DO 400 K=1,4
400   PCJET(K,NCJET)=0.
      NCJET=NCJET-1
      GOTO 1
      END
C-----------------------------------------------------------------------
      SUBROUTINE CALDELM(ISTLO,ISTHI)
C     LABEL ALL PARTICLES WITH STATUS BETWEEN ISTLO AND ISTHI (UNTIL A
C     PARTICLE WITH STATUS ISTOP IS FOUND) AS FINAL-STATE, CALL CALSIMM
C     AND THEN PUT LABELS BACK TO NORMAL
C-----------------------------------------------------------------------
      IMPLICIT NONE
      INTEGER MAXNUP
      PARAMETER(MAXNUP=500)
C...HEPEVT commonblock.
      INTEGER NMXHEP,NEVHEP,NHEP,ISTHEP,IDHEP,JMOHEP,JDAHEP
      PARAMETER (NMXHEP=4000)
      COMMON/HEPEVT/NEVHEP,NHEP,ISTHEP(NMXHEP),IDHEP(NMXHEP),
     &JMOHEP(2,NMXHEP),JDAHEP(2,NMXHEP),PHEP(5,NMXHEP),VHEP(4,NMXHEP)
      DOUBLE PRECISION PHEP,VHEP
      SAVE /HEPEVT/
      INTEGER ISTLO,ISTHI

C...Avoid gcc 4.3.4 warnings.
      ISTLO=ISTLO
      ISTHI=ISTHI
      CALL CALSIMM
      END

C****************************************************
C iexclusive returns whether exclusive process or not
C****************************************************

      integer function iexclusive(iproc)
      implicit none

      integer iproc, i
      INTEGER MAXPUP
      PARAMETER (MAXPUP=100)

C...Inputs for the matching algorithm
      double precision etcjet,rclmax,etaclmax,qcut,clfact,showerkt
      integer maxjets,minjets,iexcfile,ktsche,mektsc,nexcres,excres(30)
      integer nqmatch,nexcproc,iexcproc(MAXPUP),iexcval(MAXPUP)
      logical nosingrad,jetprocs
      common/MEMAIN/etcjet,rclmax,etaclmax,qcut,showerkt,clfact,
     $   maxjets,minjets,iexcfile,ktsche,mektsc,nexcres,excres,
     $   nqmatch,nexcproc,iexcproc,iexcval,nosingrad,jetprocs

      iexclusive=-2
      do i=1,nexcproc
         if(iproc.eq.iexcproc(i)) then
            iexclusive=iexcval(i)
            return
         endif
      enddo

      return
      end

C*********************************************************************

      subroutine initpydata

      INTEGER KCHG
      DOUBLE PRECISION PMAS,PARF,VCKM
      COMMON/PYDAT2/KCHG(500,4),PMAS(500,4),PARF(2000),VCKM(4,4)
      INTEGER MSTP,MSTI
      DOUBLE PRECISION PARP,PARI
      COMMON/PYPARS/MSTP(200),PARP(200),MSTI(200),PARI(200)

      if(PMAS(1,1).lt.0.1D0.or.PMAS(1,1).gt.1.) THEN

        PMAS(1,1) = 0.33D0
        PMAS(2,1) = 0.33D0
        PMAS(3,1) = 0.5D0
        PMAS(4,1) = 1.5D0
        PMAS(5,1) = 4.8D0
        PMAS(6,1) = 175D0
        PMas(7,1) = 400D0
        PMas(8,1) = 400D0
        PMas(9,1) = 0D0
        PMas(10,1) = 0D0
        PMas(11,1) = 0.0005D0
        PMas(12,1) = 0D0
        PMas(13,1) = 0.10566D0
        PMas(14,1) = 0D0
        PMas(15,1) = 1.777D0
        PMas(16,1) = 0D0
        PMas(17,1) = 400D0
        PMas(18,1) = 0D0
        PMas(19,1) = 0D0
        PMas(20,1) = 0D0
        PMAS(21,1) = 0D0

        MSTP(61) = 2
        MSTP(71) = 1
        MSTP(183)= 2013

      endif

      return
      end

C***********************************
C Common block initialization block
C***********************************

      BLOCK DATA MEPYDAT

      INTEGER MAXPUP
      PARAMETER (MAXPUP=100)
C...Inputs for the matching algorithm
      double precision etcjet,rclmax,etaclmax,qcut,clfact,showerkt
      integer maxjets,minjets,iexcfile,ktsche,mektsc,nexcres,excres(30)
      integer nqmatch,nexcproc,iexcproc(MAXPUP),iexcval(MAXPUP)
      logical nosingrad,jetprocs
      common/MEMAIN/etcjet,rclmax,etaclmax,qcut,showerkt,clfact,
     $   maxjets,minjets,iexcfile,ktsche,mektsc,nexcres,excres,
     $   nqmatch,nexcproc,iexcproc,iexcval,nosingrad,jetprocs

C...GETJET commonblocks
      INTEGER MNCY,MNCPHI,NCY,NCPHI,NJMAX,JETNO,NCJET
      DOUBLE PRECISION YCMIN,YCMAX,DELY,DELPHI,ET,STHCAL,CTHCAL,CPHCAL,
     &  SPHCAL,PCJET,ETJET
      PARAMETER (MNCY=200)
      PARAMETER (MNCPHI=200)
      COMMON/CALORM/DELY,DELPHI,ET(MNCY,MNCPHI),
     $CTHCAL(MNCY),STHCAL(MNCY),CPHCAL(MNCPHI),SPHCAL(MNCPHI),
     $YCMIN,YCMAX,NCY,NCPHI

C...Extra commonblock to transfer run info.
      INTEGER LNHIN,LNHOUT,MSCAL,IEVNT,ICKKW,ISCALE
      COMMON/UPPRIV/LNHIN,LNHOUT,MSCAL,IEVNT,ICKKW,ISCALE

C...Initialization statements
      DATA showerkt/0.0/
      DATA qcut,clfact,etcjet/0d0,0d0,0d0/
      DATA ktsche,mektsc,maxjets,minjets,nexcres/0,1,-1,-1,0/
      DATA nqmatch/5/
      DATA nexcproc/0/
      DATA iexcproc/MAXPUP*-1/
      DATA iexcval/MAXPUP*-2/
C      DATA nosingrad,showerkt,jetprocs/.false.,.false.,.false./

      DATA NCY,NCPHI/50,60/

      DATA LNHIN,LNHOUT,MSCAL,IEVNT,ICKKW,ISCALE/77,6,0,0,0,1/

C      nosingrad = .false.
C      showerkt = .false.
C      jetprocs = .false.

      END

max_stars_repo_name: gputtley/cmssw

max_issues_repo_name: gputtley/cmssw

max_forks_repo_name: gputtley/cmssw


text:
         function func(logic)
         logical::logic,func,ent
			func=(.not. logic)
			return
         entry ent(logic)
			ent=(.not. logic)
			return
         end function

max_stars_repo_name: xevolver/xevxml

max_issues_repo_name: xevolver/xevxml

max_forks_repo_name: xevolver/xevxml