      logical function hec_nextevt_zebra()
c
c read next event from data and save into common blocks
c in include files
c
c hec_nextevt_zebra = .true.  => event read successfully
c                   = .false. => event read successfully and eof
c
c     Author: 07.04.97   Dieter Striegel
c   modified: 29.04.97   Dugan O'Neil
c
      implicit none
c
      include'hec_par.inc'      !shared parameters
      include'hec_datacard.inc' !datacard values
      include'hec_evth.inc'     !event header
      include'hec_zebra.inc'    !zebra
c
c local variable declarations
c
      integer ibank
      integer nrunh, nevth, ndwpc, nadc
      character*4 cb
      logical getmore
c
      logical eof
      data eof/.false./
      save eof
c
c functions
c
      character*4 cfromi
c
c do not proceed if end of file already reached before
c
      if (eof) then
        eof = .false.
        hec_nextevt_zebra = .false.
        return
      endif
c
c reset bank counters
c
      ibank = 0
      nrunh = 0
      nevth = 0
      ndwpc = 0
      nadc = 0
c 
c loop over banks
c
      getmore = .true.
      do while (ibank .lt. maxbanks .and. getmore)
        if (i_event .gt. 1 .and. nevth .eq. 0) then
          nevth = 1
          call hec_evth_zebra
        endif
c
c read next bank
c         
        call fzin(in_typ(2), ixstor, ipointz, 2, ' ', 0, 0)
c        call dzshow('a bank', ixstor, ipointz, ' ', 0, 0, 0, 0)
c
        if (iquest(1) .gt. 0) then
c
c end of file
c
          getmore = .false.
          eof = .true.
          print *, ' *** end of zebra file reached'
c
        elseif (iquest(1) .lt. 0) then
c
c fzin error
c
          print *, ' *** fzin error in hec_nextevt_zebra', iquest(1)
          stop
        else
c
c count number of banks read
c
          ibank = ibank + 1
c
c get bank name
c
          cb = cfromi(iq(ipointz - 4))
c         print *, ' READ BANK ', cb
c
c RUNH
c
          if (cb .eq. 'RUNH') then
            nrunh = nrunh + 1
            call hec_runh_zebra
c
c EVTH
c for first event, the second EVTH bank signals the next event
c for other events, the first EVTH bank signals the next event
c
          elseif (cb .eq. 'EVTH') then
            nevth = nevth + 1
            if (i_event .eq. 1) then
              if (nevth .eq. 1) then
                call hec_evth_zebra
              else
                getmore = .false.
              endif
            else
              getmore = .false.
            endif
c
c DWPC
c
          elseif (cb .eq. 'DWPC') then
            ndwpc = ndwpc + 1
            call hec_dwpc_zebra
c
c ADC
c
          elseif (cb .eq. 'GEOE') then
            nadc = nadc + 1
            call hec_adc_zebra
          endif
        endif
      enddo
c
c assess event integrity
c for the first event, require RUNH, EVTH, ADC
c for the other events, require ADC, not RUNH
c note that required banks should have been found only
c once
c
      if (i_event .eq. 1) then
        if (nrunh .eq. 0) then
          print *, ' *** RUNH bank not found in first event'
          stop
        endif
      else
        if (nrunh .ne. 0) then
          print *, ' *** RUNH bank found in event', i_event
          stop
        endif
      endif
c
      if (nrunh .gt. 1) then
        print *, ' *** RUNH bank found ', nrunh, 
     +  ' times in event', i_event
        stop
      elseif (ndwpc .gt. 1) then
        print *, ' *** DWPC bank found ', ndwpc, 
     +  ' times in event', i_event
        stop
      elseif (nadc .eq. 0) then
        print *, ' *** ADC bank not found in event', i_event
        stop
      elseif (nadc .gt. 1) then
        print *, ' *** ADC bank found ', nadc, 
     +  ' times in event', i_event
        stop
      elseif (nevth .eq. 0) then
        print *, ' *** EVTH bank not found in event', i_event
        stop
      endif
c
c if the code makes it here, then the event is read 
c successfully
c
c allow a subsequent event to be read only if ready to do
c so by having found a EVTH bank signaling the next event
c
      hec_nextevt_zebra = .false.
      if (nevth .eq. 2) hec_nextevt_zebra = .true.
      if (nevth .eq. 1 .and. eof) hec_nextevt_zebra = .true.
c
      end


