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

      subroutine MASKDB

      include './Include/bcs.inc'

      integer NBTRI, BLENGTH, MASK(200), FLAG(200)
      integer I, J, K, L, M

      character*6 WORD, ENTRY(200), Null
      character BCOPY(1200), Hit(8)

      common /MASKS/ MASK, FLAG
      
* initialize variables
*----------------------------------
      parameter (Null = ' +0000')
      data Hit/'1', '2', '3','4', '5', '6', '7', '8'/

      do I = 1, 1200
        BCOPY(I) = ''
      end do

      do I = 1, 200
        MASK(I) = 0
	FLAG(I) = 0
	ENTRY(I) = Null
      end do

* BTRI bank access
*----------------------------------
      NBTRI = NDB('BTRI')
      if (NBTRI.gt.0) then
        BLENGTH = IW(NBTRI)

        K = 0
        do I = 1, BLENGTH
          do J = 1, 4
	    K = K + 1
            BCOPY(K) = char(IBITS(IW(NBTRI + I), 8*(J-1), 8))
          end do
        end do
      end if

      BLENGTH = BLENGTH * 4 / 6

      K = 0
      do I = 1, BLENGTH
        do J = 1, 6
	  K = K + 1
          WORD(J:J) = BCOPY(K)
	end do
        ENTRY(I) = WORD
      end do

      do I = 1, BLENGTH

        WORD = ENTRY(I)

        if (WORD(2:2).eq.'-') then
          FLAG(I) = 1
	end if

        M = 0
	do J = 1, 4
	  K = J + 2
	  do L = 1, 8
	    M = M + 1
	    if (WORD(K:K).eq.Hit(L)) MASK(I) = MASK(I) + 2**(M - 1)
	  end do
        end do
      end do

      return
      end
