      subroutine hec_pass2
c
c pass 2 over data set
c
      implicit none
c
      include'hec_par.inc'      !shared parameters
      include'hec_datacard.inc' !datacard values
      include'hec_evth.inc'     !event header
c
c local variable declaration
c
      logical hec_nextevt
      external hec_nextevt
      logical again
c
      print *, ' '
      print *, ' *** starting user pass 2'
c
c initialise data io for pass
c
      call hec_io_pass_ini
c
c user initialization for pass 2
c
      call user_ini2
c
c loop over events. Need to start with nevent = 1 for backward compatibility  
c
      i_event = 1
      again = .true.

      do while (i_event .le. n_evtmax .and. again)
c
c read next event
c
         again = hec_nextevt()
         
         if (again) then 
            if (mod(i_event, 1000) .eq. 0 .or. i_event .eq. 1) then
               print *, ' *** starting event number ', i_event
            endif
c
c process event
c
            call hec_evt
c
c user analysis for a given event
c
            call user_evt2
c
c handle end of event data io
c
            call hec_io_pass_evt
c
            i_event = i_event + 1

         endif
c
      enddo                     ! enddo over events
c
c reset number of events
c
      i_event = i_event - 1
      print *, ' *** events processed      ', i_event
c
c user analysis at end of event loop
c
      call user_ana2
c
c handle data io at pass end
c
      call hec_io_pass_ter
c
      print *, ' *** user pass 2 done'
c
      end

 
              
            
          
