      subroutine hec_ntuple_book
c
c routine to initialize column-wise ntuples for ntuple package
c see manual/ntuple.tex for variable description
c
        implicit none
c
c parameter and geometry commons
c
        include'hec_par.inc'        ! shared parameters
        include'hec_datacard.inc'   ! datacard values
        include'hec_geo.inc'        ! geometry correspondance tables
        include'hec_ntuple.inc'     ! ntuple common
        include'hec_ntuple_sys.inc' ! ntuple system common
c
        integer istat, num
	character*512 tags_runh_a,tags_runh_b,tags_runh_c,tags_evt_a
        character*512 tags_evt_b,tags_mwpc,tags_sc
        character*3 cnum
c
c initialize list of column names for run header
c
        num = i_adc_dim
        num = min(999, max(num, 100))
        write(cnum(1:3), '(i3)') num
	tags_runh_a = 'hec_runno:i,hec_runpd:i,hec_beame:r,'//
     +  'hec_noevt:i,'//
     +  'hec_parttype:i,'//
     +  'hec_cryox:r,hec_tabley:r,hec_zbeam:r,'//
     +  'hec_peakf:i,hec_cal_version:i,hec_dig_version:i,'//
     +  'hec_shower:i,hec_eunit:i'
        tags_runh_b = 'hec_adc_max[0,'//cnum//']:i,'//
     +  'hec_index(hec_adc_max):i'
        tags_runh_c = 'hec_cells_used[0,'//cnum//']:i,'//
     +  'hec_ped_rms(hec_cells_used):r,'//
     +  'hec_ieta(hec_cells_used):i,'//
     +  'hec_iphi(hec_cells_used):i,'//
     +  'hec_iz(hec_cells_used):i,'//
     +  'hec_ic(hec_cells_used):i'
c
c names for event ntuple - standard block
c
        tags_evt_a = 'hec_evtno:i,hec_trig(5):i'
        tags_evt_b = 'hec_signal('//cnum//'):r'
c
c names for event ntuple - mwpc block
c
        tags_mwpc = 'hec_xbeam:r,hec_ybeam:r,hec_xslop:r,hec_yslop:r,'//
     +              'hec_xbeam_ok:i,hec_ybeam_ok:i'
c
c names for slow control ntuple
c
        tags_sc = 'hec_time:i,hec_lartemp(8):r,hec_press:r,'//
     +            'hec_adc_used[0,'//cnum//']:i,'//
     +            'hec_hvcor(hec_adc_used):r'
c
c open hbook file for standard ntuple
c
	call hropen(io_ntp,'ntuple','ntuple.hbook','n',1024,istat)
	if (istat .ne. 0) then
	   print*, 'error opening ntuple file'
	   return
	endif
c
c initialize (book) ntuples (disk resident)
c
	call hbnt(id_ntuple_run,'standard run ntuple','D')
	call hbnt(id_ntuple_evt,'standard event ntuple','D')
	call hbnt(id_ntuple_slc,'standard slow control ntuple','D')
c
c define columns for run header ntuple
c
	call hbname(id_ntuple_run,'hecrunh',hec_runno,tags_runh_a)
	call hbname(id_ntuple_run,'hecrunh',hec_adc_max,tags_runh_b)
	call hbname(id_ntuple_run,'hecrunh',hec_cells_used,tags_runh_c)
c
c define columns for event ntuple standard block
c
	call hbname(id_ntuple_evt,'hecevt',hec_evtno,tags_evt_a)
        call hbname(id_ntuple_evt,'hecevt',hec_signal,tags_evt_b)
c
c define columns for event ntuple MWPC block (if requested)
c
	if (mk_beam .ne. 0) 
     +    call hbname(id_ntuple_evt,'hecmwpc',hec_xbeam,tags_mwpc)
c
c define columns for slow control ntuple
c
	call hbname(id_ntuple_slc,'hecsc',hec_time,tags_sc)
c
        return 
        end










