      subroutine hec_geo_aug98
c
c fill geometry table and physics database array 
c August 1998                                     
c                                                
c mod01: iz = 1, pad   1 ..  24                      
c        iz = 2, pad  25 ..  47  (pad 48       absent) 
c        iz = 3, pad  51 ..  72  (pad 49, 50   absent) 
c mod02: iz = 1, pad  73 ..  96
c        iz = 2, pad  97 .. 119  (pad 120      absent)
c        iz = 3, pad 123 .. 144  (pad 121, 122 absent) 
c                             
c lookup table read from file:
c        lookup(ADC#,1) = ADC#    
c        lookup(ADC#,2) = PAD#    
c        lookup(ADC#,3) = i_pad   
c        lookup(ADC#,4) = i_z     
c        lookup(ADC#,5) = i_eta   
c        lookup(ADC#,6) = i_phi  
c        lookup(ADC#,7) = i_mod  
c        lookup(ADC#,8) = 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      include'hec_runh.inc'     ! run header
c
c local variable
c
      integer i, j, ic, i_mod, i_seg, i_pad, i_eta, i_phi, i_z
      integer lookup(i_adc_dim,8) 		! lookup table
      integer fnum, ios
      character fname*19, ctag*3
      parameter (fnum=20, fname='hec_geo.dat')
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,8*i_adc_dim)

      i_adc_used = 144 				! set geometry used
      i_tim_used = 32

      i_mod_used = 2
      i_seg_used = 3
      i_pad_used = 24

      i_eta_used = 14
      i_phi_used = 4
      i_z_used   = 3
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='(8I7)',IOSTAT=ios,ERR=100,END=300)
     &  ( lookup(i,j), j=1, 8 )
        if (i.ne.lookup(i,1)) then 			! check lookup table
          print *, ' *** inconsistent database file at ADC#', i
          print *, ' *** database: ',(lookup(i,j) ,j=1, 8)
          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,7)
        i_seg = lookup(ic,8)
        i_pad = lookup(ic,3)
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,5)
        i_phi = lookup(ic,6)
        i_z   = lookup(ic,4)
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...
c
      enddo 						! do ic=1, i_adc_used
c
      print *, ' *** August 98 geometry correspondence tables filled'
c
      return
c
c treat end of file problem
c
 100  continue
      close(fnum)               ! close database file
      print *, ' *** error accessing August 98 geometry file'
      stop
c
 300  continue
      close(fnum)               ! close database file
      print *, ' *** problems reading August 98 geometry tables'
      stop
c
      end


