      subroutine hec_geo_feb00
c
c fill geometry table and physics database array 
c August 1999                                     
c                                                
c lookup table read from file (ic is ADC#)
c        lookup(ic,1) = ic    
c        lookup(ic,2) = i_pad   
c        lookup(ic,3) = i_z     
c        lookup(ic,4) = i_eta   
c        lookup(ic,5) = i_phi  
c        lookup(ic,6) = i_mod  
c        lookup(ic,7) = i_seg  
c
      implicit none
c
      include'hec_par.inc'      ! parameter common
      include'hec_datacard.inc' ! datacard values
      include'hec_geo.inc'      ! geometry common
c
c local variable
c
      character fname*19, ctag*3
      integer fnum, ios
      parameter (fnum=20, fname='hec_geo.dat')
      integer i_look_dim
      parameter (i_look_dim = 7)
      integer lookup(i_adc_dim, i_look_dim) 		! lookup table
      integer i, j, ic, i_mod, i_seg, i_pad, i_eta, i_phi, i_z
c
c reset geometry
c
      call vzero (ictodb, 3*i_adc_dim)
      call vzero (ictoph, 3*i_adc_dim)
      call vzero (dbtoic, i_mod_max*i_seg_max*i_pad_max)
      call vzero (phtoic, i_mod_max*i_seg_max*i_pad_max)
      call vzero (lookup, i_look_dim*i_adc_dim)
c
      i_adc_used = 300 				! set geometry used
      i_tim_used = 16
c
      i_mod_used = 1
      i_seg_used = 2
      i_pad_used = 24
c
      i_eta_used = 14
      i_phi_used = 2
      i_z_used   = 2
c
c read database file
c
      open (UNIT=fnum,IOSTAT=ios,ERR=100,FILE=fname,
     &                STATUS='OLD',
     &                ACCESS='SEQUENTIAL',FORM='FORMATTED')
c
c skip header and look for geometry table
c
      ctag = 'xxx'
      do while (ctag .ne. 'geo')
        read(fnum,FMT='(a3)',IOSTAT=ios,ERR=100,END=300) ctag
      enddo
c
c read table
c
      do i = 1, i_adc_used
        read(fnum,FMT='(7I7)',IOSTAT=ios,ERR=100,END=300)
     &  ( lookup(i,j), j=1, i_look_dim)
        if (i.ne.lookup(i,1)) then 			! check lookup table
          print *, ' *** inconsistent database file at ic', i
          print *, ' *** database: ',(lookup(i,j) ,j=1, i_look_dim)
          stop
        endif 						! if (i.ne.lookup(i,1)) then
      enddo 						! do i=1, i_adc_used
c         
      close(fnum)               ! close database file
c
c fill tables
c
      do ic=1, i_adc_used
c
        i_mod = lookup(ic,6)
        i_seg = lookup(ic,7)
        i_pad = lookup(ic,2)
c
        ictodb(ic,1) = i_mod
        ictodb(ic,2) = i_seg
        ictodb(ic,3) = i_pad
        if ((i_mod.eq.0).or.(i_seg.eq.0).or.(i_pad.eq.0)) then
          continue 					! unconnected ADC
        else
          dbtoic(i_mod,i_seg,i_pad) = ic
        endif 						! if ((i_mod.eq.0).or.(i
c
        i_eta = lookup(ic,4)
        i_phi = lookup(ic,5)
        i_z   = lookup(ic,3)
c
        ictoph(ic,1) = i_eta
        ictoph(ic,2) = i_phi
        ictoph(ic,3) = i_z
        if ((i_eta.eq.0).or.(i_phi.eq.0).or.(i_z.eq.0)) then
          continue					! unconnected ADC
        else
          phtoic(i_eta,i_phi,i_z) = ic
        endif 						! if ((i_eta.eq.0).or...
      enddo 						! do ic=1, i_adc_used
c
      print *, ' *** Feb 2000 geometry correspondence tables filled'
c
      return
c
c treat end of file problems
c
 100  continue
      close(fnum)               ! close database file
      print *, ' *** error accessing Feb 2000 geometry file'
      stop
c
 300  continue
      close(fnum)               ! close database file
      print *, ' *** problems reading Feb 2000 geometry tables'
      stop
c
      end


