	subroutine fnc_ez2(fnc_e,fnc_veto,fnc_tower_max,
     +             fnc_yshowerwidth,fnc_flag,fnc_ierr)
c
c  second attempt at an easy FNC user routine
c
c  author: bill schmidke 14.11.97
c
c  changes from fnc_ez1:
c
c	- provide signal from veto plane farthest from FNC
c	  to avoid over-efficiency from backsplash
c
c	- add fnc_flag for FNC status
c
c output: fnc_e             - total energy in FNC (GeV)
c	  fnc_veto          - veto plane pulse height (approx. # mips)
c	  fnc_tower_max     - FNC tower with maximum energy (1-14)
c			    (= 0 if no positive energy in FNC front)
c         fnc_yshowerwidth  - FNC neutral shower vertical width (cm)
c	  fnc_flag          - = 0 FNC not suitable for physics
c			    = 1 FNC OK for physics
c			    > 1 special problems, maybe OK for physics,
c			        but use at own risk
c	  fnc_ierr          - = 0 if successful unpacking etc.
c			      = 1-9 error in fnc_upk
c			      = 11-19 error in fnc_cor
c
c         real: fnc_e,fnc_veto,fnc_yshowerwidth
c         integer: fnc_tower_max,fnc_flag,fnc_ierr
c
c  use: here 'neutral shower' means a shower in the FNC near the zero-
c	degree line, and 'proton tag' means a shower in the FNC above
c	the proton beam, possibly protons with x_L in the range 0.54-0.75
c
c	in all cases clean events without preshowering can be selected
c	by cutting on fnc_veto pulse height. (although tagged protons will
c	miss the veto counters, a cut on fnc_veto pulse height is recommended
c	to avoid preshowers.) veto inefficiency and overefficiency due
c	to backsplash is still being studied, so the pulse height is
c	provided as a parameter to vary in the analyses.
c   --> recommended cut: fnc_veto < 1.0
c
c   --> cut for neutral showers: fnc_tower_max in the range 6-9
c   --> cut for proton tags: fnc_tower_max in the range 13-14
c
c	neutral showers may be wide hadronic showers or narrow
c	electromagnetic showers. the vertical shower width is
c	provided as a parameter to discriminate between the two cases.
c   --> recommended cut for hadronic showers: 3.0 < fnc_yshowerwidth < 7.0
c   --> recommended cut for electromagnetic showers: fnc_yshowerwidth < 3.0
c	(this cut only valid for fnc_e>150GeV. energy dependence
c	of this cut for fnc_e<150GeV needs to be studied.)
c	(fnc_yshowerwidth only meaningful for fnc_tower_max in the range 6-9)
c
c	NOTE: this routine can also be used with FNC monte carlo data
c
	implicit none
c
	real fnc_e,fnc_t,fnc_veto,fnc_yshowerwidth
	integer fnc_tower_max,fnc_flag,fnc_ierr
c
	integer max_FNC
	parameter (max_FNC = 96)
	real e_raw(max_FNC),t_raw(max_FNC)
	real e_tru(max_FNC),t_tru(max_FNC)
c
c
	integer chan,twr,nax_twr
	real e_twr(14),e_max
	real e_wgt,e_sum,ey2_sum,et_sum
	real rmn_twr
c
c
c
	fnc_ierr = 0
c
c  zero output just in case
c
	fnc_e = 0.
	fnc_veto = 0.
	fnc_tower_max = 0
	fnc_yshowerwidth = 0.
c
c  get FNC status
c
	call fnc_take(fnc_flag)
c
c  unpack the raw data and apply calibration constants
c
	call fnc_upk(e_raw,t_raw,fnc_ierr)
	if(fnc_ierr.ne.0) return
	call fnc_cor(e_raw,t_raw,e_tru,t_tru,fnc_ierr)
	if(fnc_ierr.ne.0) return
c
c  make total energy sum
c
	fnc_e = 0.
	do chan=1,42
	   fnc_e = fnc_e + e_tru(chan)
	end do
c
c  use fnc_veto signal from plane farthest from FNC, 
c  normalized to 1. = 1 m.i.p.
c
	fnc_veto = e_tru(44)
c
c  make FNC front tower sums
c
	do twr=1,14
	   e_twr(twr) = e_tru(2*twr-1) + e_tru(2*twr)
	end do
c
c  find maximum tower (positive energy only)
c
	fnc_tower_max = 0
	e_max = 0.
	do twr=1,14
	   if(e_twr(twr).gt.e_max) then
	      fnc_tower_max = twr
	      e_max = e_twr(twr)
	   endif
	end do
c
c  find maximum tower adjacent to fnc_tower_max (for later use with rmn_twr)
c
	if(fnc_tower_max.eq.1) then
	   nax_twr = 2
	else if(fnc_tower_max.eq.14) then
	   nax_twr = 13
	else if(fnc_tower_max.gt.1.and.fnc_tower_max.lt.14) then
	   if(e_twr(fnc_tower_max+1).gt.e_twr(fnc_tower_max-1)) then
	      nax_twr = fnc_tower_max + 1
	   else
	      nax_twr = fnc_tower_max - 1
	   endif
	else
	   nax_twr = 0
	endif
c
c  make y-width for FNC front bottom
c
c
c  make e, e*y**2 sums
c
	e_sum = 0.
	ey2_sum = 0.
	do twr=1,10
	   e_wgt = amax1(e_twr(twr),0.)
	   e_sum = e_sum + e_wgt
	   ey2_sum = ey2_sum + e_wgt*(5.*float(twr-fnc_tower_max))**2
	end do
c
	if(e_sum.gt.0..and.ey2_sum.gt.0.) then
	   fnc_yshowerwidth = sqrt(ey2_sum/e_sum)
	else
	   fnc_yshowerwidth = 0.
	endif
c
c  make nearest tower ratio adjustment
c
	if(fnc_tower_max.gt.0.and.nax_twr.gt.0) then
  	   rmn_twr = e_twr(nax_twr)/(e_twr(fnc_tower_max)+e_twr(nax_twr))
	   rmn_twr = amax1(rmn_twr,0.)
	else
	   rmn_twr = 0.
	endif
c
	fnc_yshowerwidth = fnc_yshowerwidth - 4.*rmn_twr
	fnc_yshowerwidth = amax1(fnc_yshowerwidth,0.)
c
c  make time using max. tower channels > 1GeV
c
	if(fnc_tower_max.gt.0) then
	   e_sum = 0.
	   et_sum = 0.
	   do chan=2*fnc_tower_max-1,2*fnc_tower_max
	      if(e_tru(chan).gt.1.) then
		 e_sum = e_sum + e_tru(chan)
		 et_sum = et_sum + e_tru(chan)*t_tru(chan)
	      endif
	   end do
	   if(e_sum.gt.1.) then
	      fnc_t = et_sum/e_sum
	   else
	      fnc_t = 0.
	   endif
	else
	   fnc_t = 0.
	endif
c
c  successful completion
c
	fnc_ierr = 0
	return
	end
