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

      subroutine PADDATA

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

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

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

* initialize BST Pad variables
*----------------------------------
      include './Include/paddata.inc'

* initialize user variables
*----------------------------------
      integer NSITR
      integer BIT, nBIT, BYTE, nBYTE

* event processing
*----------------------------------
      do I = 1, 12
        Raw_P0(I) = 0
        Raw_P1(I) = 0
        Raw_P2(I) = 0
        Raw_P3(I) = 0

        Top_Trg(I) = 0
        Top_Vto(I) = 0
        Top_Ang(I) = 0
      end do

      TC_inn = 0
      TC_out = 0
      TC_hal = 0
      TC_mul = 0

      PADFOUND = .FALSE.

      if ((PADFIL.eq.0).or.NONSENSE) return

      NSITR = NLINK('SITR', 12)

      if (NSITR.gt.0) then

        PADFOUND = .TRUE.

        do I = 1, 12
          Raw_P0(I) = IBITS(not(IW(NSITR + 3 + I)),  0, 8)
          Raw_P1(I) = IBITS(not(IW(NSITR + 3 + I)),  8, 8)
          Raw_P2(I) = IBITS(not(IW(NSITR + 3 + I)), 16, 8)
          Raw_P3(I) = IBITS(not(IW(NSITR + 3 + I)), 24, 8)
	end do

        Top_Trg(1)  = BIT(IW(NSITR + 16), 31)
        Top_Trg(2)  = BIT(IW(NSITR + 16), 23) 
        Top_Trg(3)  = BIT(IW(NSITR + 16), 15)   
        Top_Trg(4)  = BIT(IW(NSITR + 16),  7)
        Top_Trg(5)  = BIT(IW(NSITR + 17), 31)
        Top_Trg(6)  = BIT(IW(NSITR + 17), 23)
        Top_Trg(7)  = BIT(IW(NSITR + 17), 15)
        Top_Trg(8)  = BIT(IW(NSITR + 17),  7)
        Top_Trg(9)  = BIT(IW(NSITR + 18), 31)
        Top_Trg(10) = BIT(IW(NSITR + 18), 23)
        Top_Trg(11) = BIT(IW(NSITR + 18), 15)
        Top_Trg(12) = BIT(IW(NSITR + 18),  7)


C        write(*,*)'TOP_TRG:', (Top_Trg(I), I = 1, 12)

        Top_Vto(1)  = BIT(IW(NSITR + 16), 30)
        Top_Vto(2)  = BIT(IW(NSITR + 16), 22) 
        Top_Vto(3)  = BIT(IW(NSITR + 16), 14)   
        Top_Vto(4)  = BIT(IW(NSITR + 16),  6)
        Top_Vto(5)  = BIT(IW(NSITR + 17), 30)
        Top_Vto(6)  = BIT(IW(NSITR + 17), 22)
        Top_Vto(7)  = BIT(IW(NSITR + 17), 14)
        Top_Vto(8)  = BIT(IW(NSITR + 17),  6)
        Top_Vto(9)  = BIT(IW(NSITR + 18), 30)
        Top_Vto(10) = BIT(IW(NSITR + 18), 22)
        Top_Vto(11) = BIT(IW(NSITR + 18), 14)
        Top_Vto(12) = BIT(IW(NSITR + 18),  6)

C        write(*,*)'TOP_VTO:', (Top_Vto(I), I = 1, 12)

        Top_Ang(1)  = BYTE(IW(NSITR + 16), 25, 4)
        Top_Ang(2)  = BYTE(IW(NSITR + 16), 17, 4) 
        Top_Ang(3)  = BYTE(IW(NSITR + 16),  9, 4)   
        Top_Ang(4)  = BYTE(IW(NSITR + 16),  1, 4)
        Top_Ang(5)  = BYTE(IW(NSITR + 17), 25, 4)
        Top_Ang(6)  = BYTE(IW(NSITR + 17), 17, 4)
        Top_Ang(7)  = BYTE(IW(NSITR + 17),  9, 4)
        Top_Ang(8)  = BYTE(IW(NSITR + 17),  1, 4) 
        Top_Ang(9)  = BYTE(IW(NSITR + 18), 25, 4)   
        Top_Ang(10) = BYTE(IW(NSITR + 18), 17, 4)
        Top_Ang(11) = BYTE(IW(NSITR + 18),  9, 4)
        Top_Ang(12) = BYTE(IW(NSITR + 18),  1, 4)


C        write(*,*)'TOP_ANG:', (Top_Ang(I), I = 1, 12)
C        write(*,*)'--------------'

        TC_inn = BIT(IW(NSITR + 19), 0)
	TC_out = BIT(IW(NSITR + 19), 1)
	TC_hal = BIT(IW(NSITR + 19), 2)
        TC_mul = BIT(IW(NSITR + 19), 3)

      end if

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

      return
      end

      integer function BIT(A, B)
      integer A, B
        BIT = IBITS(A, B, 1)
      return
      end

      integer function nBIT(A, B)
      integer A, B
        nBIT = IBITS(NOT(A), B, 1)
      return
      end

      integer function BYTE(A, B, C)
      integer A, B, C
        BYTE = IBITS(A, B, C)
      return
      end

      integer function nBYTE(A, B, C)
      integer A, B, C
        nBYTE = IBITS(NOT(A), B, C)
      return
      end
