*--------1---------2---------3---------4---------5---------6---------7--

      subroutine RUNDATA

* initialize BCS
*----------------------------------
      include './Include/bcs.inc'

* initialize DST branches
*----------------------------------
      include './Include/dstdata.inc'

* initialize NTUPLE variables
*----------------------------------
      include './Include/ntdata.inc'

* initialize RUN variables
*----------------------------------
      include './Include/rundata.inc'

* initialize user variables
*----------------------------------
      integer NHEAD, NDSTR, NZRCT
      integer BEGRAN, ENDRUN

* first program in a chain
*----------------------------------
      NONSENSE = .FALSE.

* event processing
*----------------------------------
      if (RUNFIL.eq.0) return

      RUNFOUND = .FALSE.

      NRUN = 0
      NEVT = 0

      NHEAD = NLINK('HEAD', 0)
      NDSTR = NLINK('DSTR', 0)
      NZRCT = NLINK('ZRCT', 0)

* run validation
*----------------------------------
      if ((NHEAD.gt.0).and.
     +    (NDSTR.gt.0).and.
     +    (NZRCT.gt.0)) then

        NRUN = IW(NHEAD + 2 + 0)
        NEVT = IW(NHEAD + 2 + 1)

        BEGRUN = IW(NDSTR + 1)
	ENDRUN = IW(NDSTR + 2)

        if ((NRUN.ge.BEGRUN).and.(NRUN.le.ENDRUN)) RUNFOUND = .TRUE.

        if (IBITS(IW(NZRCT+1),0,16).ne.49153) RUNFOUND = .FALSE. ! normal run
        if (IBITS(IW(NZRCT+3),8,2).ne.2)      RUNFOUND = .FALSE. ! phase 2
        if (IBITS(IW(NZRCT+6),0,1).eq.1)      RUNFOUND = .FALSE. ! permanent

      end if

* flag for further calculations
*----------------------------------
      if ((RUNFIL.eq.1).and.(.not.RUNFOUND)) NONSENSE = .TRUE.

      return
      end
