*--------1---------2---------3---------4---------5---------6---------7--

      subroutine NTINIT

* initialize BCS
*----------------------------------
      include './Include/bcs.inc'

* initialize DST variables
*----------------------------------
      include './Include/dstdata.inc'

* initialize NTUPLE
*----------------------------------
      include './Include/ntdata.inc'
      data UNNAM /'MYFILE'/, IHBK /40/, NTFOUND /.FALSE./

      integer IHBLENGTH
      parameter (IHBLENGTH = 4000000)
      common /PAWC/ H(IHBLENGTH)

* initialize RUN variables
*----------------------------------
      include './Include/rundata.inc'

* initialize TEL variables
*----------------------------------
      include './Include/teldata.inc'

* initialize VERTEX variables
*----------------------------------
      include './Include/vtxdata.inc'

* initialize SPACAL variables
*----------------------------------
      include './Include/spldata.inc'

* initialize BST Strip variables
*----------------------------------
      include './Include/strdata.inc'

* initialize BST Pad variables
*----------------------------------
      include './Include/paddata.inc'

* initialize user variables
*----------------------------------
      character FILNAM*72, CHAINT*4
      integer NHBKO

* define NTUPLE parameters
*----------------------------------
      NHBKO = IW(NAMIND('HBKO'))

      if (NHBKO.gt.0) then

        NTFOUND = .TRUE.
        LUNHBK = IW(NHBKO + 1)

          FILNAM = ' '
        do I = 1, IW(NHBKO) - 1
          FILNAM((4*I - 3):(4*I)) = CHAINT(IW(NHBKO + I + 1))
        end do

* open NTUPLE file
*----------------------------------
        call HLIMIT(IHBLENGTH)
        call HROPEN(LUNHBK, UNNAM, FILNAM, 'N', 1024, ISTAT)
        call HBNT(IHBK, 'The Pad Ntuple', ' ')

* format RUN variables
*----------------------------------
        if (RUNFIL.eq.1) call HBNAME(IHBK, 'RUNINFO', NRUN,
     +                                     'NRUN:I, NEVT:I')

* format subsystem L1 TEs
*----------------------------------
        if (TELFIL.eq.1) call HBNAME(IHBK, 'L1TES', STTBST,
     +                       'STTBST[0,1]:I, STTPAD[0,1]:I,'//
     +                       'STTXXX[0,1]:I, STTR20[0,1]:I,'//
     +                       'STTR30[0,1]:I, STTR40[0,1]:I,'//
     +                       'SPELM1[0,1]:I, SPELM2[0,1]:I,'//
     +                       'SPHAD1[0,1]:I, SPHAD2[0,1]:I,'//
     +                       'FITIA[0,1]:I,  FITBG[0,1]:I,'//
     +                       'BTOFBG[0,1]:I, STOFBG[0,1]:I,'//
     +                       'VETOBG[0,1]:I, PADTRG[0,1]:I,'//
     +                       'PADHAL[0,1]:I, PADVTO[0,1]:I,'//
     +                       'S0RAW[0,1]:I,  S0ACT[0,1]:I,'//
     +                       'S2RAW[0,1]:I,  S2ACT[0,1]:I,'//
     +                       'S3RAW[0,1]:I,  S3ACT[0,1]:I,'//
     +                       'S4RAW[0,1]:I,  S4ACT[0,1]:I,'//
     +                       'S7RAW[0,1]:I,  S7ACT[0,1]:I,'//
     +                       'S8RAW[0,1]:I,  S8ACT[0,1]:I,'//
     +                       'S9RAW[0,1]:I,  S9ACT[0,1]:I,'//
     +                       'L2TR20[0,1]:I, L2TR30[0,1]:I,'//
     +                       'L2TR40[0,1]:I')

* format VERTEX variables
*----------------------------------
        if (VTXFIL.eq.1) call HBNAME(IHBK, 'VERTEX', XV,
     +                                     'XV, YV, ZV')

* format SPACAL variables
*----------------------------------
        if (SPLFIL.eq.1) call HBNAME(IHBK, 'SPACAL', NSEL,
     +                       'NSEL[0,100]:I,ESEL(NSEL):R,'//
     +                       'XSEL(NSEL):R, YSEL(NSEL):R,'//
     +                       'ZSEL(NSEL):R, RSEL(NSEL):R,'//
     +                       'LIET(25):I')

* format BST Strip variables
*----------------------------------
        if (STRFIL.eq.1) call HBNAME(IHBK, 'BSTRIP', NTRK,
     +                       'NTRK[0,5]:I,'//
     +                       'INRAD(NTRK):R, dIR(NTRK):R,'//
     +                       'PHBST(NTRK):R, dPH(NTRK):R,'//
     +                       'THBST(NTRK):R, dTH(NTRK):R,'//
     +                       'XVBST(NTRK):R, dXV(NTRK):R,'//
     +                       'YVBST(NTRK):R, dYV(NTRK):R,'//
     +                       'ZVBST(NTRK):R, dZV(NTRK):R,'//
     +                       'NTRHIT(NTRK):I')

* format BST Pad variables
*----------------------------------
        if (PADFIL.eq.1) call HBNAME(IHBK, 'BSTPAD', Raw_P0,
     +                       'Raw_P0(12)[0,255]:I,'//
     +                       'Raw_P1(12)[0,255]:I,'//
     +                       'Raw_P2(12)[0,255]:I,'//
     +                       'Raw_P3(12)[0,255]:I,'//
     +                       'Top_Trg(12)[0,1]:I,'//
     +                       'Top_Vto(12)[0,1]:I,'//
     +                       'Top_Ang(12)[0,15]:I,'//
     +                       'TC_inn[0,1]:I, TC_out[0,1]:I,'//
     +                       'TC_hal[0,1]:I, TC_mul[0,1]:I')
        end if

      return
      end
