  
         program makent

         character*20 out
         character*8 filename

         out='$Enter L1-Filename:'
         write(6,2)out
2        format(a)
         read(5,2)filename

C         call makenth(filename)
         call makentc(filename)
         call makentp(filename)
         call makentx(filename)

         end


         subroutine makenth(filename) 

         integer itime(3), idata1(4), idata2(10)
         real rtime(1), rdata1(16), rdata2(20)
         character*18 ctime(4), cdata(50)
         character*20 epoch
         character*8 filename
         character*40 file
         real*8 repoch
C
         parameter(npawc=500000)
	 common/pawc/hmemo(npawc)
C
         common /ntupr/ itime, rtime, idata1, idata2, rdata1, rdata2
         common /ntupc/ epoch

         data ctime / 'pb5yr[0,2100]:I', 'pb5day[0,366]:I', 
     +                'pb5ms:I', 'min95:R' /
         data cdata /  
     +        'STAT1[-707,255]:I',  'STAT2[-707,255]:I',
     +        'STAT3[-707,255]:I',  'STAT4[-707,255]:I', 
     +        'U5V:R',    'U27V:R',   'U6V:R',  'Um6V:R', 
     +        'I5V:R',    'I27V:R',   'I6V:R',  'Im6V:R',
     +      'TEBox:R',    'a_bs:R',  'b_bs:R',
     +         'c_bs:R',  'd_bs:R',  'e_bs:R',  'f_bs:R',  'g_hv:R',
     +       'CSTAT1[-707,255]:I', 'CSTAT2[-707,255]:I',
     +       'CSTAT3[-707,255]:I', 'CSTAT4[-707,255]:I',
     +        'LVPC1:R', 'LVPC2:R', 'LVPC3:R', 'LVPC4:R', 
     +        'LVPC5:R', 'LVPC6:R', 'LVPC7:R', 'LVPC8:R',
     +       'PDUST1[-707,1]:I', 'PDUHK1:R',
     +       'PDUST2[-707,1]:I', 'PDUHK2:R',
     +       'heat1[-707,1]:I', 'heat2[-707,1]:I', 
     +       'heat3[-707,1]:I', 'heat4[-707,1]:I',
     +       'therm1:R','therm2:R','therm3:R','therm4:R','therm5:R',
     +       'therm6:R','therm7:R','therm8:R','therm9:R', 'rangl:R'   /

         lin=41
         lout=42
         id=102
         call hlimit(npawc)
         file='platte30:[soho.nt]'//filename//'.nth'
         call hropen(lout,'NTUPLE',file,'N',1024,istat)
         call hbnt(id,'EPHIN HSK L1',' ')
         do i=1,3
           call hbname(id,'ntupr',itime(i), ctime(i))
	 enddo
         call hbname(id,'ntupr',rtime, ctime(4))
         call hbnamc(id,'ntupc',epoch, 'epoch:C*20')
	 do i=1,4
           call hbname(id,'ntupr',idata1(i),cdata(i))
	 enddo
	 do i=1,16
           call hbname(id,'ntupr',rdata1(i),cdata(i+4))
	 enddo
	 do i=1,4
           call hbname(id,'ntupr',idata2(i),cdata(i+20))
	 enddo
	 do i=1,8
           call hbname(id,'ntupr',rdata2(i),cdata(i+24))
	 enddo
         call hbname(id,'ntupr',idata2(5),cdata(33))
         call hbname(id,'ntupr',rdata2(9),cdata(34))
         call hbname(id,'ntupr',idata2(6),cdata(35))
         call hbname(id,'ntupr',rdata2(10),cdata(36))
	 do i=1,4
           call hbname(id,'ntupr',idata2(i+6),cdata(i+36))
	 enddo
	 do i=1,10
           call hbname(id,'ntupr',rdata2(i+10),cdata(i+40))
	 enddo
         file='platte40:[soho.l1.hsk]'//filename//'.hsk'
         open(unit=lin,file=file,form='formatted',type='old',readonly)
         ik=0
10       read(lin,*,end=20,err=20,iostat=ios)itime,rtime,repoch,idata1,
     +        rdata1,idata2(1),idata2(2),idata2(3),idata2(4),
     +        rdata2(1),rdata2(2),rdata2(3),rdata2(4),
     +        rdata2(5),rdata2(6),rdata2(7),rdata2(8),
     +        idata2(5),rdata2(9),idata2(6),rdata2(10),
     +        idata2(7),idata2(8),idata2(9),idata2(10),
     +        rdata2(11),rdata2(12),rdata2(13),rdata2(14),
     +        rdata2(15),rdata2(16),rdata2(17),rdata2(18),
     +        rdata2(19),rdata2(20)
         ik=ik+1
         encode(20,12,epoch)repoch
12       format(f18.2) 
         call hfnt(id)
         go to 10
20       call hrout(id,icycle,' ')
	 print*,' HSK:  C entries:  ',ik,'  ios:  ',ios
         call hrend('NTUPLE')
         close (lin)
         close (lout)
         end


         subroutine makentc(filename)

         integer itime(3), idata(96), mode
         real rtime(1)
         character*15 ctime(4)
         character*16 cdata(96)
         character*20 epoch
         character*8 filename
         character*40 file
         real*8 repoch
C
         parameter(npawc=500000)
	 common/pawc/hmemo(npawc)
C
         common /ntupr/ itime, rtime, idata
         common /ntupc/ epoch

         data ctime / 'pb5yr[0,2100]:I', 'pb5day[0,366]:I',
     +                'pb5ms:I', 'min95:R' /
         data cdata /  
     +           'G0:I',   'A00:I', 
     +          'A01:I',   'A02:I',
     +          'A03:I',   'A04:I',
     +          'A05:I',   'B00:I',
     +          'B01:I',   'B02:I',
     +          'B03:I',   'B04:I',
     +          'B05:I',    'C0:I',
     +           'D0:I',    'E0:I',
     +           'F0:I',  'P4GM:I',
     +         'P4GR:I',   'P4S:I',
     +         'P8GM:I',  'P8GR:I',
     +          'P8S:I',  'H4GM:I',
     +         'H4GR:I',  'H4S1:I',
     +        'H4S23:I',  'H8GM:I',
     +         'H8GR:I',  'H8S1:I',
     +        'H8S23:I',  'E150:I', 
     +         'E300:I', 'E1300:I',
     +        'E3000:I',   'INT:I',
     +        'P25GM:I', 'P25GR:I',
     +         'P25S:I', 'P41GM:I',
     +        'P41GR:I',  'P41S:I',
     +        'H25GM:I', 'H25GR:I', 
     +        'H25S1:I','H25S23:I',
     +        'H41GM:I', 'H41GR:I',
     +        'H41S1:I','H41S23:I',
     +          'CT0:I',   'CT1:I', 
     +          'CT2:I',   'CT3:I',
     +          'CT4:I',   'CT5:I',
     +        'HBin1:I', 'HBin2:I',
     +        'HBin3:I', 'HBin4:I',
     +        'HBin5:I', 'HBin6:I', 
     +        'HBin7:I', 'HBin8:I',
     +        'HBin9:I','HBin10:I',
     +       'HBin11:I','HBin12:I',
     +       'HBin13:I','HBin14:I',
     +       'HBin15:I','HBin16:I',
     +       'HBin17:I','HBin18:I',
     +       'HBin19:I','HBin20:I',
     +       'HBin21:I','HBin22:I',
     +       'HBin23:I','HBin24:I',
     +       'HBin25:I','HBin26:I',
     +       'HBin27:I','HBin28:I',
     +       'HBin29:I','HBin30:I',
     +       'HBin31:I','HBin32:I', 
     +        'stat1[0,255]:I',   'stat2[0,255]:I',
     +        'stat3[0,255]:I',   'stat4[0,255]:I', 
     +        'stat5[0,255]:I',  'liolen[0,368]:I',
     +      'ephlen[0,2000]:I', 'esulen[0,5756]:I' /

         lin=41 
         lout=42
         id=101
         call hlimit(npawc)
         file='platte30:[soho.nt]'//filename//'.ntc'
         call hropen(lout,'NTUPLE',file,'N',1024,istat)
         call hbnt(id,'EPHIN Counters L1',' ')
         do i=1,3
           call hbname(id,'ntupr',itime(i), ctime(i))
	 enddo
         call hbname(id,'ntupr',rtime, ctime(4))
         call hbnamc(id,'ntupc',epoch, 'epoch:C*20')
	 do i=1,96
           call hbname(id,'ntupr',idata(i), cdata(i))
	 enddo
         file='platte40:[soho.l1.sci]'//filename//'.sci'
         open(unit=lin,file=file,form='formatted',type='old',readonly)  
         ik=0
10       read(lin,*,err=20,iostat=ios)itime,rtime,repoch,idata
         ik=ik+1
         encode(20,12,epoch) repoch
12       format(f18.2) 

         if ((idata(95).gt.0).and.(idata(2).ge.0)) then
           mode=jbit(idata(89),7)+2*jbit(idata(89),8)
         else
           mode=0
         endif
         if (mode.ne.1) then
           print*,itime(1),itime(2),itime(3),'  Mode= ',mode,
     +            '  EphLen=',idata(95)
         endif

         call hfnt(id)
         go to 10
20       call hrout(id,icycle,' ')
	 print*,' CNT:  C entries:  ',ik,'  ios:  ',ios
         call hrend('NTUPLE')
         close (lin) 
         close (lout)
         end


         subroutine makentp(filename)

         integer itime(3), idata(14)
         real rtime(1)
         character*15 ctime(4)
         character*14 cdata(14)
         character*8 filename
         character*40 file
C
         parameter(npawc=500000)
	 common/pawc/hmemo(npawc)
         common/quest/iquest(100) 
C
         common /ntupr/ itime, rtime, idata

         data ctime / 'pb5yr[0,2100]:I', 'pb5day[0,366]:I',
     +                'pb5ms:I', 'min95:R' /
         data cdata /  
     +        'COINC[0,12]:I',  'ASEG[0,5]:I', 'BSEG[0,5]:I', 
     +        'APHA[0,1023]:I', 'ACHN[0,1]:I',
     +        'BPHA[0,1023]:I', 'BCHN[0,1]:I', 
     +        'CPHA[0,1023]:I', 'CCHN[0,1]:I',
     +        'DPHA[0,1023]:I', 'DCHN[0,1]:I',
     +        'EPHA[0,1023]:I', 'ECHN[0,1]:I', 'PRIO[0,1]:I' /

         lin=41
         lout=42
         id=100
         call hlimit(npawc)
         file='platte30:[soho.nt]'//filename//'.ntp' 
         iquest(10)=65000
         call hropen(lout,'NTUPLE',file,'NQ',1024,istat)
         call hbnt(id,'EPHIN PHA L1',' ')
         do i=1,3
           call hbname(id,'ntupr',itime(i), ctime(i))
	 enddo
         call hbname(id,'ntupr',rtime, ctime(4))
	 do i=1,14
           call hbname(id,'ntupr',idata(i), cdata(i))
	 enddo
         file='platte40:[soho.l1.pha]'//filename//'.pha'
         open(unit=lin,file=file,form='formatted',type='old',readonly) 
         ik=0
10       read(lin,*,err=20,iostat=ios)itime,rtime,idata
         ik=ik+1

         if ((idata(2).gt.5).or.(idata(3).gt.5)) then
            print*,itime,rtime,idata
         endif
 
         call hfnt(id)
         go to 10
20       call hrout(id,icycle,' ')
	 print*,' PHA:  C entries:  ',ik,'  ios:  ',ios
         call hrend('NTUPLE')
         close (lout)
         close (lin)
         end


         subroutine makentx(filename)

         integer itime(3), idata(14)
         real rtime(1)
         character*15 ctime(4)
         character*14 cdata(14)
         character*8 filename
         character*40 file
C
         parameter(npawc=500000)
	 common/pawc/hmemo(npawc)
         common/quest/iquest(100) 
C
         common /ntupr/ itime, rtime, idata

         data ctime / 'pb5yr[0,2100]:I', 'pb5day[0,366]:I',
     +                'pb5ms:I', 'min95:R' /
         data cdata /  
     +        'COINC[0,12]:I',  'ASEG[0,5]:I', 'BSEG[0,5]:I', 
     +        'APHA[0,1023]:I', 'ACHN[0,1]:I',
     +        'BPHA[0,1023]:I', 'BCHN[0,1]:I', 
     +        'CPHA[0,1023]:I', 'CCHN[0,1]:I',
     +        'DPHA[0,1023]:I', 'DCHN[0,1]:I',
     +        'EPHA[0,1023]:I', 'ECHN[0,1]:I', 'PRIO[0,1]:I' /

         lin=41
         lout=42
         id=100
         call hlimit(npawc)
         file='platte30:[soho.nt]'//filename//'.ntx' 
         iquest(10)=65000
         call hropen(lout,'NTUPLE',file,'NQ',1024,istat)
         call hbnt(id,'EPHIN PHA L1',' ')
         do i=1,3
           call hbname(id,'ntupr',itime(i), ctime(i))
	 enddo
         call hbname(id,'ntupr',rtime, ctime(4))
	 do i=1,14
           call hbname(id,'ntupr',idata(i), cdata(i))
	 enddo
         file='platte40:[soho.l1.pha]'//filename//'.phx'
         open(unit=lin,file=file,form='formatted',type='old',readonly) 
         ik=0
10       read(lin,*,err=20,iostat=ios)itime,rtime,idata
         if ((idata(2).gt.5).or.(idata(3).gt.5)) then
            print*,itime,rtime,idata
         endif
         if (idata(1).lt.12) then 
           ik=ik+1
           call hfnt(id)
         endif
         go to 10
20       call hrout(id,icycle,' ')
	 print*,' PHX:  C entries:  ',ik,'  ios:  ',ios
         call hrend('NTUPLE')
         close (lout)
         close (lin)
         end

