*file member=anxx_load library=snoman language=fortran77 date=08:Nov:2004
     
 <<<      subroutine anxx_load(anxx_online)
     
    *     ANxx:  load channel status based on ANXX banks.
     
    *     Contact:  M. Huang,  Texas.
     
    *     Revision History:
    *     ================
     
    *     4.0196  A. Krumins    first version
    *     4.0196  P. Skensved   simplify the code
    *     5.01    M. Huang      modify to include more than one flagged mechanisms
    *                           and more than one ANXX banks
     
     
    *     Parameters:
    *     ==========
     
    *     Common block access:
    *     ===================
    *     (ignoring internal and environmental access)
     
    *      anxx_online    out   *
     
     
    *     Specification:
    *     =============
     
    *     This subroutine loads channel status based on ANxx banks.
     
     
          implicit none
     
          include 'mt.inc'
          include 'anxx_load_com.inc'
          include 'zunit.inc'
     
    *     Argument Declarations:
    *     =====================
     
    *     Local Variable Declarations:
    *     ===========================
     
          integer i, j, lcn, nflag, tot_word
          integer anxx_online(0:9727,2)
     
    *     Now, we can initialize common blocks.  When we first run SNOMAN,
    *     we assume all tubes to be good.
     
          total_bad_tubes = 0
     
          do lcn = 0, 9727
             do j = 1, 2
                anxx_online(lcn,j) = 0
             end do
          end do
     
    *     If we're here the titles file has been read in already.
    *     Only the channels which are bad are listed in ANXX banks.
     
    *     Set local common block anxx_online
     
    *     Format of ANXX banks:
    *      -- first  column : logical channel number
    *      -- second column : number of flagged types
    *                         = 0 means the channel is good
    *                         > 0 means the channel is bad
    *      -- third to last columns : flagged types
     
          if(ldanxx .ne. 0) then
             do j = 1, 9728
                if (j .eq. 1) then
                   lcn   = icons(ldanxx+2)
                   nflag = icons(ldanxx+3)
                   anxx_online(lcn,1) = icons(ldanxx+3)
                   tot_word = 1
                else
                   tot_word = tot_word + 2 + nflag
                   lcn   = icons(ldanxx+tot_word+1)
                   nflag = icons(ldanxx+tot_word+2)
                   anxx_online(lcn,1) = icons(ldanxx+tot_word+2)
                endif
     
                if ( icons(ldanxx+tot_word+1) .eq. -9999 ) go to 110
     
                do i = 1, nflag
                   anxx_online(lcn,2) = anxx_online(lcn,2) +
         +                              2**icons(ldanxx+tot_word+2+i)
                end do
                total_bad_tubes = total_bad_tubes + 1
     
             end do
     
     110     continue
             write(iqlog,2070)  total_bad_tubes
             write(iqprnt,2070)  total_bad_tubes
     
          else
             write(iqlog,3500)
             write(iqprnt,3500)
          endif
     
     2070 format('ANxx flagged ', i8, ' bad channels')
     3500 format('No  ANxx bank to initialize !')
     
          return
          end
     
    *endfile member=anxx_load