      subroutine hec_hv_01
c
c fill geometry table and physics database array 
c July-September 2001
c                                                
      implicit none
c
      include'hec_par.inc'      ! parameter common
      include'hec_geo.inc'      ! geometry common
      include'hec_hvpar.inc'    ! hv geometry common
c
c local variable
c
      character fname*19, ctag*2
      integer fnum, ios
      parameter (fnum=20, fname='hec_hv.dat')
      integer i, j
      integer lookup(nmodhv_cal_max*nchhv_cal_max,5)
c
c reset geometry 
c
      call vzero (lookup, 5*nmodhv_cal_max*nchhv_cal_max)
      call vzero (hvtodb, 3*nmodhv_cal_max*nchhv_cal_max)
c
      nchcal_hv_used = 48 	    ! # of HV channels used for calorimeter
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 = 'xx'
      do while (ctag .ne. 'hv')
         read(fnum,FMT='(a2)',IOSTAT=ios,ERR=100,END=300) ctag
      enddo
c
c read lookup table
c
      do i = 1 , nchcal_hv_used
         read(fnum,FMT='(7I7)',IOSTAT=ios,ERR=100,END=300)
     &        (lookup(i,j),j=1,5)
c         print*,'channel',i,' lookup ', (lookup(i,j),j=1,5)
      enddo 						
c         
c fill correspondance table
c
      do i = 1 , nchcal_hv_used 
         hvtodb(lookup(i,1),lookup(i,2),1)=lookup(i,3)
         hvtodb(lookup(i,1),lookup(i,2),2)=lookup(i,4)
         hvtodb(lookup(i,1),lookup(i,2),3)=lookup(i,5)
      enddo
c
      close(fnum)              
c
      print *, ' *** 2001 HV correspondance table filled' 
      print *, '  '
c
      return
c
c treat end of file problems
c
 100  continue
      close(fnum)               
      print *, ' *** error accessing 2001 HV geometry file'
      stop
c
 300  continue
      close(fnum)            
      print *, ' *** error ',ios,' reading 2001 HV geometry tables'
      stop
c
      end


