
c234567
      program dantestc4
      common/pawc/hmemor(1000000)
      common /iinput/kstore(500000),hstore(500000),icc(1),nnn,istart,
     1 nrun,nbur,icount
      dimension nhsta(1)
      character*6 aa
      character*60 sfile
       call hlimit(200000) 
      write(*,*)' load histos',istart
      call hbook1(30110,' spill 5ms ',1000,1000.,6000.,0.) ! full range
      call hbook1(31110,' hits for spill 5ms ',1000,1000.,6000.,0.) ! full range
      call hminim(30110,1.0)
      call hminim(31110,1.0)
      call hbook1(32110,' hits / spill 5ms ',1000,1000.,6000.,0.) ! full range
      call hbook1(33110,' spill / hits 5ms ',1000,1000.,6000.,0.) ! full range
      call hbook1(110,' spill 5ms ',1000,1000.,6000.,0.) ! full range ! Fig 2
      call hbook1(1110,' hits forspill 5ms ',1000,1000.,6000.,0.) ! full range
      call hmaxim(110,1000.)
      call hmaxim(33110,2.5)

      call hbook1(101,' spill 1ms ',4000,1500.,5500.,0.)
      call hbook1(102,' spill 5ms ',800,1500.,5500.,0.) ! 
      call hbook1(103,' spill 25ms ',160,1500.,5500.,0.)
      call hbook1(104,' spill .5 ms ',1000,1500.,2000.,0.)

      call hbook1(200,' mean 1 ms ',50,50.,150.,0.)
      call hbook1(201,' sd/sqrt(mean) 1 ms ',60,1.,4.,0.)
      call hbook1(202,' skewness 1 ms ',50,-1.,1.,0.)
      call hbook1(203,' kurtosis  1 ms ',40,1.,5.,0.)
    
      call hbook1(204,' lf noise ',25,0.,0.5,0.)
      call hbook1(205,' 100 Hz noise ',25,0.,0.25,0.)
      call hbook1(206,' total  noise ',30,0.,0.6,0.)
      call hbook1(207,' high spill % ',25,0.,25.,0.)
      call hbook1(307,' high folded spill % ',50,0.,50.,0.)
c     histos for BQI   -----------------------------------
      call hbook1(400,' hits - skewness ',100,0.,2.5,0.) 
      call hbook1(401,' spill - max ',100,500.,1500.,0.) 
      call hbook1(402,' spill - min ',100,0.,500.,0.) 
      call hbook1(403,' % removed Fig 1 ',100,0.,25.,0.) 
      call hbook1(404,' noise ',50,0.,100.,0.) 
      call hbook1(405,' 100 HZ ',25,0.,25000.,0.) 
      call hbook1(406,' 50 HZ ',50,0.,20000.,0.) 
      call hbook1(407,' % removed Fig 1 ',100,0.,10.,0.) 
      call hbook1(408,' 35 HZ ',50,0.,100000.,0.) 
      call hbook1(410,' BQI ',20,0.,10.,0.)
      call hbook1(420,' BQI ',20,0.,10.,0.)
c     ----------------------------------------------------

      call hbook2(301,' sd/sqrt(mean) vs skewness ',
     1 60,1.,4.,50,-1.,1.,0.)
      call hbook2(302,' sd/sqrt(mean) vs kurtosis ',
     1 60,1.,4.,40,1.,5.,0.)
      call hbook2(303,' skewness  vs kurtosis ',
     1 50,-1.,1.,40,1.,5.,0.)

      call hbook2(304,' sd/sqrt(mean) vs lf noise ',
     1 60,1.,4.,25,0.,0.5,0.)
      call hbook2(305,' sd/sqrt(mean) vs 100 Hz',
     1 60,1.,4.,25,0.,0.25,0.)
      call hbook2(306,' sd/sqrt(mean) vs total noise',
     1 60,1.,4.,30,0.,0.6,0.)

      call hbook1(800,' spill - folded ',231,0.,924.,0.) ! for sps time det

      call hbook1(8000,' freq ',250,0.,250.,0.)  ! Fig 4 <<<<<<<<<<<<<<<<
      call hbook1(9000,' RMS ',50,0.,1000.,0.)
      call hbook1(9100,' First Difference 1 ms ',50,-100.,150.,0.)
      call hbook1(9200,' correlelogram',2000,0.,1000.,0.)  ! Fig 5 <<<<<<<<<<<<<<
      call hbook2(10000,' corrected folded spill, spill ',
     1 231,0.,924.,500,1100.,6100.,0.) !  Fig 1 <<<<<<<<<<<<<<<
      call hbook1(11000,' Corrected folded time',
     1 231,0.,924.,0.)
      call hbook1(12000,' Uncorrected folded time',
     1 231,0.,924.,0.)   !  Fig 3 <<<<<<<<<<<<<<<<<<<<<<<<<<<
      call hmaxim(12000,600.)
      call hbook1(12001,' Uncorrected folded time',
     1 231,0.,924.,0.)
      call hmaxim(12001,400.)
      call hbook1(12100,' first diff.Uncorrected folded time',
     1 231,0.,924.,0.)
      call hbook1(12300,' 2ndt diff.Uncorrected folded time',
     1 231,0.,924.,0.)
      call hbook1(12200,' fisrt diff.Uncorrected folded time distr.',
     1 150,-500.,1000.,0.)

      call hbook1(7000,' hits ',125,0.,250.,0.) ! Fig 8 <<<<<<<<<<<<<<<<<
      call hbook1(7100,' hits 2.0 - 5.0 ',125,0.,250.,0.)
      call hmaxim(7000,25000)
      call hmaxim(7100,20000)
      call hbook2(20000,'  spill, hits ',
     1 500,1100.,6100.,50,0.,250.,0.)      ! Fig 6 <<<<<<<<<<<<<<<<<<<<<
      call hbook2(21000,' folded spill, hits ',
     1 231,0.,924.,50,0.,250.,0.)          ! Fig 7 <<<<<<<<<<<<<<<<<<<<<< 

       icount = 0

       do ik = 1,140
       icc(1) = ik

       if(icc(1).eq.1)sfile = 'afiles2/elis_2023-3340-1140-ian03.txt'
       if(icc(1).eq.2)sfile = 'afiles2/elis_2023-3340-1141-ian03.txt'
       if(icc(1).eq.3)sfile = 'afiles2/elis_2023-3340-1142-ian03.txt'
       if(icc(1).eq.4)sfile = 'afiles2/elis_2023-3340-1143-ian03.txt'
       if(icc(1).eq.5)sfile = 'afiles2/elis_2023-3340-1144-ian03.txt'
       if(icc(1).eq.6)sfile = 'afiles2/elis_2023-3340-1145-ian03.txt'
       if(icc(1).eq.7)sfile = 'afiles2/elis_2023-3340-1146-ian03.txt'
       if(icc(1).eq.8)sfile = 'afiles2/elis_2023-3340-1147-ian03.txt'
       if(icc(1).eq.9)sfile = 'afiles2/elis_2023-3340-1148-ian03.txt'
       if(icc(1).eq.10)sfile = 'afiles2/elis_2023-3340-1149-ian03.txt'
       if(icc(1).eq.11)sfile = 'afiles2/elis_2023-3340-1150-ian03.txt'
       if(icc(1).eq.12)sfile = 'afiles2/elis_2023-3340-1151-ian03.txt'
       if(icc(1).eq.13)sfile = 'afiles2/elis_2023-3340-1152-ian03.txt'
       if(icc(1).eq.14)sfile = 'afiles2/elis_2023-3340-1153-ian03.txt'
       if(icc(1).eq.15)sfile = 'afiles2/elis_2023-3340-1154-ian03.txt'
       if(icc(1).eq.16)sfile = 'afiles2/elis_2023-3340-1155-ian03.txt'
       if(icc(1).eq.17)sfile = 'afiles2/elis_2023-3340-1156-ian03.txt'
       if(icc(1).eq.18)sfile = 'afiles2/elis_2023-3340-1157-ian03.txt'
       if(icc(1).eq.19)sfile = 'afiles2/elis_2023-3340-1158-ian03.txt'
       if(icc(1).eq.20)sfile = 'afiles2/elis_2023-3340-1159-ian03.txt'
       if(icc(1).eq.21)sfile = 'afiles2/elis_2023-3340-1160-ian03.txt'
       if(icc(1).eq.22)sfile = 'afiles2/elis_2023-3340-1161-ian03.txt'
       if(icc(1).eq.23)sfile = 'afiles2/elis_2023-3340-1162-ian03.txt'
       if(icc(1).eq.24)sfile = 'afiles2/elis_2023-3340-1163-ian03.txt'
       if(icc(1).eq.25)sfile = 'afiles2/elis_2023-3340-1164-ian03.txt'
       if(icc(1).eq.26)sfile = 'afiles2/elis_2023-3340-1165-ian03.txt'
       if(icc(1).eq.27)sfile = 'afiles2/elis_2023-3340-1166-ian03.txt'
       if(icc(1).eq.28)sfile = 'afiles2/elis_2023-3340-1167-ian03.txt'
       if(icc(1).eq.29)sfile = 'afiles2/elis_2023-3340-1168-ian03.txt'
       if(icc(1).eq.30)sfile = 'afiles2/elis_2023-3340-1169-ian03.txt'
       if(icc(1).eq.31)sfile = 'afiles2/elis_2023-3340-1170-ian03.txt'
       if(icc(1).eq.32)sfile = 'afiles2/elis_2023-3340-1171-ian03.txt'
       if(icc(1).eq.33)sfile = 'afiles2/elis_2023-3340-1172-ian03.txt'
       if(icc(1).eq.34)sfile = 'afiles2/elis_2023-3340-1173-ian03.txt'
       if(icc(1).eq.35)sfile = 'afiles2/elis_2023-3340-1174-ian03.txt'
       if(icc(1).eq.36)sfile = 'afiles2/elis_2023-3340-1175-ian03.txt'
       if(icc(1).eq.37)sfile = 'afiles2/elis_2023-3340-1176-ian03.txt'
       if(icc(1).eq.38)sfile = 'afiles2/elis_2023-3340-1177-ian03.txt'
       if(icc(1).eq.39)sfile = 'afiles2/elis_2023-3340-1178-ian03.txt'
       if(icc(1).eq.40)sfile = 'afiles2/elis_2023-3340-1179-ian03.txt'
       if(icc(1).eq.41)sfile = 'afiles2/elis_2023-3340-1180-ian03.txt'
       if(icc(1).eq.42)sfile = 'afiles2/elis_2023-3340-1181-ian03.txt'
       if(icc(1).eq.43)sfile = 'afiles2/elis_2023-3340-1182-ian03.txt'
       if(icc(1).eq.44)sfile = 'afiles2/elis_2023-3340-1183-ian03.txt'
       if(icc(1).eq.45)sfile = 'afiles2/elis_2023-3340-1184-ian03.txt'
       if(icc(1).eq.46)sfile = 'afiles2/elis_2023-3340-1185-ian03.txt'
       if(icc(1).eq.47)sfile = 'afiles2/elis_2023-3340-1186-ian03.txt'
       if(icc(1).eq.48)sfile = 'afiles2/elis_2023-3340-1187-ian03.txt'
       if(icc(1).eq.49)sfile = 'afiles2/elis_2023-3340-1188-ian03.txt'
       if(icc(1).eq.50)sfile = 'afiles2/elis_2023-3340-1189-ian03.txt'
       if(icc(1).eq.51)sfile = 'afiles2/elis_2023-3340-1190-ian03.txt'
       if(icc(1).eq.52)sfile = 'afiles2/elis_2023-3340-1191-ian03.txt'
       if(icc(1).eq.53)sfile = 'afiles2/elis_2023-3340-1192-ian03.txt'
       if(icc(1).eq.54)sfile = 'afiles2/elis_2023-3340-1193-ian03.txt'
       if(icc(1).eq.55)sfile = 'afiles2/elis_2023-3340-1194-ian03.txt'
       if(icc(1).eq.56)sfile = 'afiles2/elis_2023-3340-1195-ian03.txt'
       if(icc(1).eq.57)sfile = 'afiles2/elis_2023-3340-1196-ian03.txt'
       if(icc(1).eq.58)sfile = 'afiles2/elis_2023-3340-1197-ian03.txt'
       if(icc(1).eq.59)sfile = 'afiles2/elis_2023-3340-1198-ian03.txt'
       if(icc(1).eq.60)sfile = 'afiles2/elis_2023-3340-1199-ian03.txt'
       if(icc(1).eq.61)sfile = 'afiles2/elis_2023-3340-1200-ian03.txt'
       if(icc(1).eq.62)sfile = 'afiles2/elis_2023-3340-1201-ian03.txt'
       if(icc(1).eq.63)sfile = 'afiles2/elis_2023-3340-1202-ian03.txt'
       if(icc(1).eq.64)sfile = 'afiles2/elis_2023-3340-1203-ian03.txt'
       if(icc(1).eq.65)sfile = 'afiles2/elis_2023-3340-1204-ian03.txt'
       if(icc(1).eq.66)sfile = 'afiles2/elis_2023-3340-1205-ian03.txt'
       if(icc(1).eq.67)sfile = 'afiles2/elis_2023-3340-1206-ian03.txt'
       if(icc(1).eq.68)sfile = 'afiles2/elis_2023-3340-1207-ian03.txt'
       if(icc(1).eq.69)sfile = 'afiles2/elis_2023-3340-1208-ian03.txt'
       if(icc(1).eq.70)sfile = 'afiles2/elis_2023-3340-1209-ian03.txt'
       if(icc(1).eq.71)sfile = 'afiles2/elis_2023-3340-1210-ian03.txt'
       if(icc(1).eq.72)sfile = 'afiles2/elis_2023-3340-1211-ian03.txt'
       if(icc(1).eq.73)sfile = 'afiles2/elis_2023-3340-1212-ian03.txt'
       if(icc(1).eq.74)sfile = 'afiles2/elis_2023-3340-1213-ian03.txt'
       if(icc(1).eq.75)sfile = 'afiles2/elis_2023-3340-1214-ian03.txt'
       if(icc(1).eq.76)sfile = 'afiles2/elis_2023-3340-1215-ian03.txt'
       if(icc(1).eq.77)sfile = 'afiles2/elis_2023-3340-1216-ian03.txt'
       if(icc(1).eq.78)sfile = 'afiles2/elis_2023-3340-1217-ian03.txt'
       if(icc(1).eq.79)sfile = 'afiles2/elis_2023-3340-1218-ian03.txt'
       if(icc(1).eq.80)sfile = 'afiles2/elis_2023-3340-1219-ian03.txt'
       if(icc(1).eq.81)sfile = 'afiles2/elis_2023-3340-1220-ian03.txt'
       if(icc(1).eq.82)sfile = 'afiles2/elis_2023-3340-1221-ian03.txt'
       if(icc(1).eq.83)sfile = 'afiles2/elis_2023-3340-1222-ian03.txt'
       if(icc(1).eq.84)sfile = 'afiles2/elis_2023-3340-1223-ian03.txt'
       if(icc(1).eq.85)sfile = 'afiles2/elis_2023-3340-1224-ian03.txt'
       if(icc(1).eq.86)sfile = 'afiles2/elis_2023-3340-1225-ian03.txt'
       if(icc(1).eq.87)sfile = 'afiles2/elis_2023-3340-1226-ian03.txt'
       if(icc(1).eq.88)sfile = 'afiles2/elis_2023-3340-1227-ian03.txt'
       if(icc(1).eq.89)sfile = 'afiles2/elis_2023-3340-1228-ian03.txt'
       if(icc(1).eq.90)sfile = 'afiles2/elis_2023-3340-1229-ian03.txt'
       if(icc(1).eq.91)sfile = 'afiles2/elis_2023-3340-1230-ian03.txt'
       if(icc(1).eq.92)sfile = 'afiles2/elis_2023-3340-1231-ian03.txt'
       if(icc(1).eq.93)sfile = 'afiles2/elis_2023-3340-1232-ian03.txt'
       if(icc(1).eq.94)sfile = 'afiles2/elis_2023-3340-1233-ian03.txt'
       if(icc(1).eq.95)sfile = 'afiles2/elis_2023-3340-1234-ian03.txt'
       if(icc(1).eq.96)sfile = 'afiles2/elis_2023-3340-1235-ian03.txt'
       if(icc(1).eq.98)sfile = 'afiles2/elis_2023-3340-1237-ian03.txt'
       if(icc(1).eq.99)sfile = 'afiles2/elis_2023-3340-1238-ian03.txt'
       if(icc(1).eq.100)sfile = 'afiles2/elis_2023-3340-1239-ian03.txt'
       if(icc(1).eq.101)sfile = 'afiles2/elis_2023-3340-1240-ian03.txt'
       if(icc(1).eq.102)sfile = 'afiles2/elis_2023-3340-1241-ian03.txt'
       if(icc(1).eq.103)sfile = 'afiles2/elis_2023-3340-1242-ian03.txt'
       if(icc(1).eq.104)sfile = 'afiles2/elis_2023-3340-1243-ian03.txt'
       if(icc(1).eq.105)sfile = 'afiles2/elis_2023-3340-1244-ian03.txt'
       if(icc(1).eq.106)sfile = 'afiles2/elis_2023-3340-1245-ian03.txt'
       if(icc(1).eq.107)sfile = 'afiles2/elis_2023-3340-1246-ian03.txt'
       if(icc(1).eq.108)sfile = 'afiles2/elis_2023-3340-1247-ian03.txt'
       if(icc(1).eq.109)sfile = 'afiles2/elis_2023-3340-1248-ian03.txt'
       if(icc(1).eq.110)sfile = 'afiles2/elis_2023-3340-1249-ian03.txt'
       if(icc(1).eq.111)sfile = 'afiles2/elis_2023-3340-1250-ian03.txt'
       if(icc(1).eq.112)sfile = 'afiles2/elis_2023-3340-1251-ian03.txt'
       if(icc(1).eq.113)sfile = 'afiles2/elis_2023-3340-1252-ian03.txt'
       if(icc(1).eq.114)sfile = 'afiles2/elis_2023-3340-1253-ian03.txt'
       if(icc(1).eq.115)sfile = 'afiles2/elis_2023-3340-1254-ian03.txt'
       if(icc(1).eq.116)sfile = 'afiles2/elis_2023-3340-1255-ian03.txt'
       if(icc(1).eq.117)sfile = 'afiles2/elis_2023-3340-1256-ian03.txt'
       if(icc(1).eq.118)sfile = 'afiles2/elis_2023-3340-1257-ian03.txt'
       if(icc(1).eq.119)sfile = 'afiles2/elis_2023-3340-1258-ian03.txt'
       if(icc(1).eq.120)sfile = 'afiles2/elis_2023-3340-1259-ian03.txt'
       if(icc(1).eq.121)sfile = 'afiles2/elis_2023-3340-1260-ian03.txt'
       if(icc(1).eq.122)sfile = 'afiles2/elis_2023-3340-1261-ian03.txt'
       if(icc(1).eq.123)sfile = 'afiles2/elis_2023-3340-1262-ian03.txt'
       if(icc(1).eq.124)sfile = 'afiles2/elis_2023-3340-1263-ian03.txt'
       if(icc(1).eq.125)sfile = 'afiles2/elis_2023-3340-1264-ian03.txt'
       if(icc(1).eq.126)sfile = 'afiles2/elis_2023-3340-1265-ian03.txt'
       if(icc(1).eq.127)sfile = 'afiles2/elis_2023-3340-1266-ian03.txt'
       if(icc(1).eq.128)sfile = 'afiles2/elis_2023-3340-1267-ian03.txt'
       if(icc(1).eq.129)sfile = 'afiles2/elis_2023-3340-1268-ian03.txt'
       if(icc(1).eq.130)sfile = 'afiles2/elis_2023-3340-1269-ian03.txt'
       if(icc(1).eq.131)sfile = 'afiles2/elis_2023-3340-1270-ian03.txt'
       if(icc(1).eq.132)sfile = 'afiles2/elis_2023-3340-1271-ian03.txt'
       if(icc(1).eq.133)sfile = 'afiles2/elis_2023-3340-1272-ian03.txt'
       if(icc(1).eq.134)sfile = 'afiles2/elis_2023-3340-1273-ian03.txt'
       if(icc(1).eq.135)sfile = 'afiles2/elis_2023-3340-1274-ian03.txt'
       if(icc(1).eq.136)sfile = 'afiles2/elis_2023-3340-1275-ian03.txt'
       if(icc(1).eq.137)sfile = 'afiles2/elis_2023-3340-1276-ian03.txt'
       if(icc(1).eq.138)sfile = 'afiles2/elis_2023-3340-1277-ian03.txt'
       if(icc(1).eq.139)sfile = 'afiles2/elis_2023-3340-1278-ian03.txt'
       if(icc(1).eq.140)sfile = 'afiles2/elis_2023-3340-1279-ian03.txt'

      open(unit=19,file=sfile,status='unknown') 
      read(19,5510,END=999)aa,nrun,nbur
 5510 format(a6,2i9)
      nnn =0
      nn = 500000 !  max input - see arrays
      do k =1,nn
      read(19,5513,END=999)aa,kk,kid,kcode,kstamp,nhsta(1)
      nnn = nnn+1
 5513 format(a6,2i9,2z10,i8)
      kstore(nnn) = kstamp !  for ffb determination
      hstore(nnn) = nhsta(1) !  store hits for folded plots
      enddo
 999  continue
      write(*,*)' run burst number ',nrun, '  ',nbur, ' ',nnn
      istart = 1
      if(icc(1).eq.1)istart =0
      call fkdev340f
      enddo

      call hprint(400)
      call hprint(401)
      call hprint(402)
      call hprint(403)
      call hprint(404)
      call hprint(405)
      call hprint(406)
      call hprint(407)
      call hprint(408)
      call hprint(420)

      stop
      end
      subroutine fkdev340f
c     single file 
      common /iinput/kstore(500000),hstore(500000),icc(1),nnn,istart,
     1 nrun,nbur,icount
      common/pawc/hmemor(1000000)
      dimension cont(8000),aamp(2000),ccont(1000)
c      dimension cont2(231,50),ccont2(231,50)
       dimension cont2(231,500)
       dimension ccont2(231,500)
       dimension cont3(231,50)
       dimension ccont3(231,50)
*      dimension kstore(500000) 
*      dimension hstore(500000) 
      dimension rs(2000),nhsta(1)
      dimension js(10000),jjs(10000)
*     dimension icc(1),iplot(1)
      dimension iplot(1)
      character*6 aa
      character*60 sfile
      character*4 sout
      character*13 ssout
c     double precision smean5,rms5,rms52

      go to 234  ! no histo setting

       call hlimit(200000) 
      write(*,*)' load histos',istart
      call hbook1(30110,' spill 5ms ',1000,1000.,6000.,0.) ! full range
      call hbook1(31110,' hits for spill 5ms ',1000,1000.,6000.,0.) ! full range
      call hminim(30110,1.0)
      call hminim(31110,1.0)
      call hbook1(32110,' hits / spill 5ms ',1000,1000.,6000.,0.) ! full range
      call hbook1(33110,' spill / hits 5ms ',1000,1000.,6000.,0.) ! full range
      call hbook1(110,' spill 5ms ',1000,1000.,6000.,0.) ! full range ! Fig 2
      call hbook1(1110,' hits forspill 5ms ',1000,1000.,6000.,0.) ! full range
      call hmaxim(110,1000.)
      call hmaxim(33110,2.5)

      call hbook1(101,' spill 1ms ',4000,1500.,5500.,0.)
      call hbook1(102,' spill 5ms ',800,1500.,5500.,0.) ! 
      call hbook1(103,' spill 25ms ',160,1500.,5500.,0.)
      call hbook1(104,' spill .5 ms ',1000,1500.,2000.,0.)

      call hbook1(200,' mean 1 ms ',50,50.,150.,0.)
      call hbook1(201,' sd/sqrt(mean) 1 ms ',60,1.,4.,0.)
      call hbook1(202,' skewness 1 ms ',50,-1.,1.,0.)
      call hbook1(203,' kurtosis  1 ms ',40,1.,5.,0.)
    
      call hbook1(204,' lf noise ',25,0.,0.5,0.)
      call hbook1(205,' 100 Hz noise ',25,0.,0.25,0.)
      call hbook1(206,' total  noise ',30,0.,0.6,0.)
      call hbook1(207,' high spill % ',25,0.,25.,0.)
      call hbook1(307,' high folded spill % ',50,0.,50.,0.)
c     histos for BQI   -----------------------------------
      call hbook1(400,' hits - skewness ',100,0.,2.5,0.) 
      call hbook1(401,' spill - max ',100,500.,1500.,0.) 
      call hbook1(402,' spill - min ',100,0.,500.,0.) 
      call hbook1(403,' % removed Fig 1 ',100,0.,25.,0.) 
      call hbook1(404,' noise ',50,0.,100.,0.) 
      call hbook1(405,' 100 HZ ',25,0.,25000.,0.) 
      call hbook1(406,' 50 HZ ',50,0.,20000.,0.) 
      call hbook1(407,' % removed Fig 1 ',100,0.,10.,0.) 
      call hbook1(408,' 35 HZ ',50,0.,100000.,0.) 
      call hbook1(410,' BQI ',20,0.,10.,0.)
      call hbook1(420,' BQI ',20,0.,10.,0.)
c     ----------------------------------------------------

      call hbook2(301,' sd/sqrt(mean) vs skewness ',
     1 60,1.,4.,50,-1.,1.,0.)
      call hbook2(302,' sd/sqrt(mean) vs kurtosis ',
     1 60,1.,4.,40,1.,5.,0.)
      call hbook2(303,' skewness  vs kurtosis ',
     1 50,-1.,1.,40,1.,5.,0.)

      call hbook2(304,' sd/sqrt(mean) vs lf noise ',
     1 60,1.,4.,25,0.,0.5,0.)
      call hbook2(305,' sd/sqrt(mean) vs 100 Hz',
     1 60,1.,4.,25,0.,0.25,0.)
      call hbook2(306,' sd/sqrt(mean) vs total noise',
     1 60,1.,4.,30,0.,0.6,0.)

      call hbook1(800,' spill - folded ',231,0.,924.,0.) ! for sps time det

      call hbook1(8000,' freq ',250,0.,250.,0.)  ! Fig 4 <<<<<<<<<<<<<<<<
      call hbook1(9000,' RMS ',50,0.,1000.,0.)
      call hbook1(9100,' First Difference 1 ms ',50,-100.,150.,0.)
      call hbook1(9200,' correlelogram',2000,0.,1000.,0.)  ! Fig 5 <<<<<<<<<<<<<<
      call hbook2(10000,' corrected folded spill, spill ',
     1 231,0.,924.,500,1100.,6100.,0.) !  Fig 1 <<<<<<<<<<<<<<<
      call hbook1(11000,' Corrected folded time',
     1 231,0.,924.,0.)
      call hbook1(12000,' Uncorrected folded time',
     1 231,0.,924.,0.)   !  Fig 3 <<<<<<<<<<<<<<<<<<<<<<<<<<<
      call hmaxim(12000,600.)
      call hbook1(12001,' Uncorrected folded time',
     1 231,0.,924.,0.)
      call hmaxim(12001,400.)
      call hbook1(12100,' first diff.Uncorrected folded time',
     1 231,0.,924.,0.)
      call hbook1(12300,' 2ndt diff.Uncorrected folded time',
     1 231,0.,924.,0.)
      call hbook1(12200,' fisrt diff.Uncorrected folded time distr.',
     1 150,-500.,1000.,0.)

      call hbook1(7000,' hits ',125,0.,250.,0.) ! Fig 8 <<<<<<<<<<<<<<<<<
      call hbook1(7100,' hits 2.0 - 5.0 ',125,0.,250.,0.)
      call hmaxim(7000,25000)
      call hmaxim(7100,20000)
      call hbook2(20000,'  spill, hits ',
     1 500,1100.,6100.,50,0.,250.,0.)      ! Fig 6 <<<<<<<<<<<<<<<<<<<<<
      call hbook2(21000,' folded spill, hits ',
     1 231,0.,924.,50,0.,250.,0.)          ! Fig 7 <<<<<<<<<<<<<<<<<<<<<< 


 234   continue ! skip histos


       istart =1


      do k =1,nnn
*     read(19,5513,END=999)aa,kk,kid,kcode,kstamp,nhsta(1)
*     nnn = nnn+1
*5513 format(a6,2i9,2z10,i8)
*     kstore(nnn) = kstamp !  for ffb determination
*     hstore(nnn) = nhsta(1) !  store hits for folded plots
      kstamp = kstore(k)
      nhsta(1) = hstore(k)
      fm = float(kstamp)/40000d0 ! ms
      call hfill(110,fm,0.,1.) ! full spill 5 ms Fig 2  <<<<<
      call hfill(30110,fm,0.,1.) ! full spill 5 ms
      temp = nhsta(1)
      call hfill(31110,fm,0.,temp) ! full spill 5 ms hits sum
      call hfill(101,fm,0.,1.)
      call hfill(102,fm,0.,1.)
      call hfill(103,fm,0.,1.)
      call hfill(104,fm,0.,1.)

      temp = nhsta(1)
      call hfill(7000,temp,0.,1.) ! hits  Fig 8   <<<<<<<<<
      if(fm.gt.2000..and.fm.lt.5000.)then
      call hfill(7100,temp,0.,1.) ! hits
      endif
c     call hfill(20000,temp,fm,1.) ! hits vs spill
      call hfill(20000,fm,temp,1.) !  spill vs hits   Fig 6 <<<<<<<<<
      enddo
 999  continue

      ffb = 923.99155  !  fold time approx used if 555 goto operative <<<<<<<<
*     write(*,*)' count  ', nnn
*     write(*,*)' '
      close (19)
c------------------------------------------------------------------

c     ratio hits/triggers
      c1 =hsum(31110)
      c1 =1./c1
      c2 = hsum(30110)
      c2 = 1./c2
      call hopera(31110,'/',30110,32110,c1,c2)
      call hopera(30110,'/',31110,33110,c2,c1)


c------------------------------------------------------------------
c      determine sps time  *****************************************************
c     comment out next line to determine fold time ( ie sps phase )      
      goto 555 ! no determination - use approx ffb to save timw
 800  continue 
      call hreset(800,' ')    
      ffs = 923.9910 ! mod 24/2/23
      ffb=  0
      cmin2 = 5000.
      do i=1,50 ! mod 24/2/23 
      ff = i
      fff = ffs+(ff-1.)*0.00005
      do k=1,nnn
      dtemp = mod(float(kstore(k)),fff) ! change  26/2/23
c     correct the time here -----------------------------
c     4th order correction - apply over full range
      tempy = kstore(k)/40000.d0 
      xxx = tempy - 1500.
      xxx = xxx/1000.
      corr = 2.4*xxx**3    ! xxx in sec 
      temp = dtemp
      temp=temp-corr
      if(temo.lt.0.)temp = temp +924. ! added here 3/6/23
C     if(k.lt.20)write(*,*)' ',k,i, kstore(k),temp 

      call hfill(800,temp,0.,1.)
      enddo  !k
      call hunpak(800,cont,' ',0)
c     write(*,*)' fff ',fff
c     write(*,*)' cont ',(cont(kk),kk= 1,231)
      cmin = 5000.
      do kk = 2,230
      if(cont(kk).lt.cmin)then
      cmin = cont(kk)
      kkmin = kk
      endif
      enddo
      call hix(800,kkmin,var) 
c     write(*,*)' fff , cmin, kkmin ', fff,cmin,kkmin 
      if(cmin.lt.cmin2)then
      cmin2 = cmin
      ffb = fff
      endif
      call hreset(800,' ')
      enddo  !
*     scal(1) = ffb - 923.
*     write(*,*)' --------------------------'
*     write(*,*)' '
*     write(*,*)' optimum value ',ffb 
*     write(*,*)' '
*     write(*,*)' --------------------------'
********************** *******************************

 555  continue  ! used if sps time NOT determined per burst


*     scal(1) = ffb - 923.


c     get folded plots using optimised sps time - ffb
c     or approx sps time if go to 555 operative

      do k = 1,nnn 
      kstamp = kstore(k)
      tempx = mod(float(kstamp),ffb)  !  folded spill
      tempy = float(kstamp)/40000d0  ! ms spill
      xxx = (tempy -1500.)/1000.
      corr = 2.4*xxx**3
      ctempx = tempx - corr ! corrected folded spill
      if(ctempx.lt.0.)ctempx = ctempx +924.0
      call hfill(10000,ctempx,tempy,1.) ! fig 1
      call hfill(11000,ctempx,0.,1.) !  not used
      temp = hstore(k) !   optimised sps ffb used here for folded spill
      call hfill(21000,ctempx,temp,1.) ! corrected folded spill vs hits Fig 7
      if(tempy.gt.1200..and.tempy.lt.2200.)then ! standard
*     if(tempy.gt.2000..and.tempy.lt.5000.)then ! temp mod
c     uncorrected folded
      call hfill(12000,tempx,0.,1.) ! used - Fig 3
      endif
      enddo ! k loop







c------------------------------------------------------------------


c     go to 333  !  do not reorder <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

c     REORDER time plots
c     
c     reorder folded spill plot..................................
      call hunpak(12000,cont,' ',0) ! projection
      call hunpak(10000,cont2,' ',0) ! 2D spill
      call hunpak(21000,cont3,' ',0) ! 2D hits
      cmin = 1000000.
      jmin = 1
      do j =1,231
      if(cont(j).lt.cmin)then 
      cmin = cont(j)
      jmin = j
      endif
      enddo 
      do j = 1,231
      k =  j - jmin + 1
      if(k.lt.1)k = k +231
      ccont(k) = cont(j)
      do jj = 1,500
      ccont2(k,jj) =cont2(j,jj)
      enddo
      do jj =1,50
      ccont3(k,jj) = cont3(j,jj) 
      enddo
      enddo
c     reordered plots
      call hpak(12000,ccont)
      call hpak(10000,ccont2)
      call hpak(21000,ccont3)
c     end reorder
 333  continue

c     -------------------------------------------------



c     examine 2D spill / folded spill reordered
      fmaxcont = 0
      fmean = 0.
      frms = 0.
      crem = 0. 
      nb = 0
      do j = 1,231
      do jj = 1,500
      if(ccont2(j,jj).gt.fmaxcont)fmaxcont = ccont2(j,jj)
      if(ccont2(j,jj).gt.0.)then  !4
      fmean = fmean +ccont2(j,jj)
      frms = frms + ccont2(j,jj)**2 
      fnum = fnum + 1.
c     remove bad regions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
      jk = 0
      jjk =0
      csave = 0
*     if(ccont2(j,jj).gt.20.)then !3
      if(ccont2(j,jj).gt.10.)then !3  240623 HIGH DENSITY REGION Fig 1
      csave = ccont2(j,jj) ! triggers removed
      crem = crem +csave ! sum removed triggers
      ccont2(j,jj) = 0. ! <<<<<<<<<<<<<<<< remove 2d
      jk = j
      jjk = jj
      if(nb.lt.10000)nb = nb +1
      js(nb) = jk
      jjs(nb) = jjk
      endif !3
      if(jk.ne.0.and.jjk.ne.0)then !2
c     bad area
      call hijxy(10000,jk,jjk,x,y) ! edge of bad region
c     correct 12000 (ccont) if in spill range
      if(y.gt.1200.0.and.y.lt.2200.)then ! 1
      ccont(jk) = ccont(jk) - csave    ! remove 1d in spill range
      endif ! 1
      endif ! 2
      endif ! 4
      enddo 
      enddo
c**********************************REPLACE******************
      call hpak(10000,ccont2) ! Fig 1
      call hpak(12000,ccont)  ! Fig 3
c     bad regions removed 
c**********************************REPLACE******************

      frms = sqrt(frms/fnum)
      fmean = fmean/fnum
      crem = crem/float(nnn)*100.

      call hfill(403,crem,0.,1.) ! BQI fraction of Fig 1 removed <<<<<
      call hfill(407,crem,0.,1.) ! BQI fraction of Fig 1 removed <<<<<
*     if(icc(1).eq.140)then
c     call hprint(403)
*     endif

*     vcrem(1) = crem
*     write(*,*)' ------------------------'
*     write(*,*)' ------------------------'
*     write(*,*)' ccont2 mean rms max ',fmean,frms, fmaxcont
*     write(*,*)' % spill removed ',crem,' number blocks removed ',nb
*     write(*,*)' ------------------------'
*     write(*,*)' ------------------------'
     
      
c     ---------------------------------------
      go to 330 !  omit this section
c     folded uncorrected spill   statistics
      call hunpak(12000,cont,' ',0)
      tot = 0.
      f500 = 0.
      smean = 0
      fj = 0.
      do j = 1,231
      if(cont(j).gt.200.)then
      smean = smean + cont(j)
      fj = fj  +1.
      endif
      enddo
      smean = smean/fj
      rms = 0
      do j = 1,231
      if(cont(j).gt.200.) rms = rms +(cont(j) -smean)**2
      enddo
      rms = sqrt(rms/fj)
      itemp =rms
*     irms(1) = itemp
*     write(*,*)' ---------------------------'
*     write(*,*)' RMS folded spill ',ii,rms
*     write(*,*)' ---------------------------'
      do j =1,231
      tot = tot + cont(j)
      if(cont(j).gt.500.)f500 = f500 +cont(j)
      enddo
      f500 = f500/tot  !fraction gt 500
      f500 = f500*100.
      itemp = f500
*     ispf(1) = itemp
      call hfill(307,f500,0.,1.)
 330  continue
c--------------------------------------------------------
c--------------------------------------------------------

c     BQI  not used in this code
c     folded spill structure examination ---------------
c     count bunches
      cmax =0
      do j = 1,231
      if(cont(j).gt.cmax)cmax = cont(j)
      enddo
      do j =1,231
      cont(j) = cont(j) - 0.25*cmax ! set level of bunch transition - to +
      enddo
      call hpak(12001,cont) ! histogram Fig  3  alternative
c     count changes - to + to get structure of spill
      ch = 0.
      do j = 2,231
      if(cont(j-1).lt.0..and.cont(j).gt.0.)then   
      ch = ch +1
      endif
      enddo
*     vch(1) = ch
*     write(*,*)' *******************************'
*     write(*,*)' *******************************'
*     write(*,*)' *******************************'
*     write(*,*)' ',ch,' bunches '   
*     write(*,*)' *******************************'
*     write(*,*)' *******************************'
*     write(*,*)' *******************************'
c     end  folded spill structure examination ---------------

c--------------------------------------------------------
c--------------------------------------------------------
      go to 331
c     SPILL plots -  not used !!!
      call hunpak(102,cont,' ',0) ! 5 ms interval 1.5 - 5.5
      tot = 0.
      t600 =0.
      do jj =1,800
      call hfill(9000,cont(jj),0.,1.)
      tot = tot + cont(jj)
      if(cont(jj).gt.600.)t600 = t600 + cont(jj)
      enddo
*     write(*,*)' '
      f600 = t600/tot ! fraction entries gt 600
      itemp = f600*100
*     ispi(1) = itemp
c     1.5 - 5.5 sec
      call hunpak(101,cont,' ',0) ! 1 ms interval

c     first difference plots
      do i = 1,3999
      temp = cont(i+1) -cont(i) ! first diference of spill
      call hfill(9100,temp,0.,1.)
      enddo
 331  continue
c -----------------------------------------------------------

      go to 222
c     not used
c     spill statistics for 1 ms
      fnn = 4000
      smean = 0.
      do i = 1,fnn
      smean = smean +cont(i)
      enddo
      smean = smean/fnn
      sd = 0.
      skew = 0.
      skurt = 0.
      do i = 1,fnn
      sd = sd + (cont(i) - smean)**2
      skew = skew + (cont(i) - smean)**3
      skurt = skurt + (cont(i) - smean)**4
      enddo

      sd =sqrt(sd/fnn)
      isd = sd
c     irms1(1) = isd  !  for display 1ms
      skew = skew/sd**3/fnn
      skurt = skurt/sd**4/fnn
c     try excess RMS <<<<<<<<<<<<<<<<<<
      sd = sqrt(sd**2-n)  !  mod
      sdn = sd/sqrt(smean)

*     write(*,*)' mean,sd/sqrt(mean),skewness,kurtosis ',
*    1 ii, smean,sdn,skew,skurt    
*     write(*,*)' '
*     write(*,*)' %fraction gt 600.',ii,f600*100.
*     write(*,*)' %folded fraction gt 500.',ii,f500
      f600 = f600*100. !  to %


      call hfill(200,smean,0.,1.)
      call hfill(201,sdn,0.,1.)
      call hfill(202,skew,0.,1.)
      call hfill(203,skurt,0.,1.)
      call hfill(207,f600,0.,1.)     

      call hfill(301,sdn,skew,1.)
      call hfill(302,sdn,skurt,1.)
      call hfill(303,skew,skurt,1.)
  222 continue
c-------------------------------------------


*     periodogram    
c     1.5 - 5.5 sec
      call hunpak(101,cont,' ',0) ! 1 ms interval
 
      ssm = 0.
      do i =1,1000
      ssm = ssm + cont(i)
      enddo
      ssm = ssm/1000.
*     ssm = 0. !    <<<<<<<<< note <<<<<<<<<<<<<
      do i = 1,1000
      cont(i) = cont(i) - ssm
      enddo
      pi2 = 6.283185
      pi = 3.141592654
c     form periodogram
      do iw = 0,999 ! freq
      xs = 0.
      xc =0.
      do i = 1,1000
      t = i
      t = t/1000.  ! ms
      fq = iw
      xs = xs + cont(i)*sin(pi2*fq*t)
      xc = xc + cont(i)*cos(pi2*fq*t)
      enddo
      aamp(iw+1) = (xs**2 + xc**2)
      aamp(iw+1) = sqrt(aamp(iw+1))
      temp =iw
      call hfill(8000,temp,0.,aamp(iw+1))  !  Fig 4 <<<<<<<<<<<
      enddo
c-------------------------------------------------
c     correlogram

      call hunpak(104,cont,' ',0)
      yb = 0
      ny = 0. 
      il =1
      ih = 1000
      do i = il,ih
      yb = yb + cont(i)
      ny = ny +1
      enddo

      yb = yb/float(ny)
      y2 = 0.
      do i = il,ih
      y2 = y2 + (cont(i)-yb)**2
      enddo



*     write(*,*)' '
      do is = 1,ny-1
      rs(is) = 0.
      do it = 1,ny -is
      rs(is) = rs(is) + (cont(it)-yb)*(cont(it+is)-yb)/y2
*     write(*,*)' is it it+is ',is, it , is +it
      enddo
*     write(*,*)' spill is rs ', is,'  ',rs(is)
      temp = is 
      temp = temp*0.5
      temp1= rs(is)*float(ny)/float(ny-is) 
      call hfill(9200,temp,0.,temp1)  !  Fig 5  <<<<<<<<<<<<<
      enddo 
*     write(*,*)' '

*     periodogram   end 
c------------------------------------------------
c     noise levels
c     background ~ 400.
      sn1 = 0.
      do j = 1,40
      sn1 = sn1 + aamp(j) - 400.
      enddo
      sn2 = 0.
      do j = 95,105
      sn2 = sn2 + aamp(j) - 400.
      enddo

      s100 =0.
      do j = 98,102
      s100 = s100 + aamp(j)
      enddo
      call hfill(405,s100,0.,1.) !  BQI amplitude 100 HZ <<<<<<<<<<<
c     if(icc(1).eq.140)call hprint(405)

      s50 = 0.
      do j = 48,52
      s50 = s50 + aamp(j)
      enddo
      call hfill(406,s50,0.,1.)  ! BQI amplitude 50 Hz  <<<<<<<<<<<<<<
c     if(icc(1).eq.140)call hprint(406)


      s35 = 0.
      do j = 1,35
      s35 = s35 + aamp(j)
      enddo
      call hfill(408,s35,0.,1.)

c     sn2 = abs(sn2)  ! avoid small negative numbers
      sn3 = 0.
      do j = 1,155
      sn3 = sn3 + aamp(j) !  total signal
      enddo
      sn4 = 0.
      do j = 1,155
      sn4 =  sn4 + aamp(j) -400.  ! total noise 
      enddo

c     max amplitude
      amax = 0
      do j = 1,500
      if(aamp(j).gt.amax)then
      jmax = j
      amax = aamp(j)
      endif 
      enddo       
     
c     for consistency - less sensitive to 400 subtraction
c     but can omit 50 Hz signal

c     sn4 = sn1 + sn2        

      noise = sn4*100./sn3 ! total noise
      temp = noise
      call hfill(404,temp,0.,1.) ! BQI noise in FA <<<<<<<<<<<<<<<
      if(icc(1).eq.140)then
c     call hprint(404)
      endif

c     inoi(1) = noise
      noise = sn2/sn3*100. !  100 Hz
c     n100(1)  = noise
c      replace by max amplitude
      itemp = amax
c     n100(1) = itemp 
c     ifreq(1) = jmax -1 
*     write(*,*)' sn2-100,sn4-tot-noise,sn3-tot-sig',
*    1  sn2,sn4,sn3
*     write(*,*)' noise:  low ,100 Hz, total ',sn1,sn2,sn3        
*     write(*,*)' noise fractions low, 100 Hz, total noise ',
*    1  sn1/sn3, sn2/sn3, sn4/sn3

      call hfill(204,sn1/sn3,0.,1.)
      call hfill(205,sn2/sn3,0.,1.)
      call hfill(206,sn4/sn3,0.,1.)

      call hfill(304,sdn,sn1/sn3,1.)
      call hfill(305,sdn,sn2/sn3,1.)
      call hfill(306,sdn,sn4/sn3,1.)

c234567
c     maximum in 5ms spill plot
c     + mean, rms  range limited
      call hunpak(110,cont,' ',0)
      smax = 0.
      smin = 1000.
      smean5 = 0.
      rms5 = 0.
      fn5 =0.
      do j = 1,1000
      if(cont(j).gt.smax)smax = cont(j)
      if(j.gt.200.and.j.lt.800)then
      if(cont(j).lt.smin)smin = cont(j)
      if(abs(cont(j) - 500.).lt.250.)then
      smean5 = smean5 + cont(j)
      rms5 = rms5 + cont(j)**2
      fn5 = fn5 + 1. 
      endif
      endif
      enddo
c     imx5(1) = smax
c     imn5(1) = smin
      smean5 = smean5/fn5
      rms5 =rms5/fn5
      rms5  = sqrt(rms5 -smean5**2)

c     check
      rms52 = 0.
      fn5 =0.
      do j =1,1000
      if(j.gt.200.and.j.lt.800)then
      if(abs(cont(j) - 500.).lt.250.)then
      rms52 = rms52 + (cont(j)-smean5)**2
      fn5 = fn5 + 1. 
      endif
      endif
      enddo
      rms52 = sqrt(rms52/fn5)

*     write(*,*)' '
*     write(*,*)' MIN/MAX       ',ii,smin,smax 
*     write(*,*)' 5 ms mean rms ',ii,smean5,rms5,rms52
*     write(*,*)' '

      call hfill(401,smax,0.,1.)  ! BQI max of spill <<<<<<<<<<<<<<<<<<<
      call hfill(402,smin,0.,1.)  ! BQI min of spill <<<<<<<<<<<<<<<<<<<
*      if(icc(1).eq.140)then
c     call hprint(401)
c     call hprint(402)
*     endif


c     stats for hits


c     stats for hits ---------------------------
      nhtot = 0
      nh100 = 0
      do k = 1,nnn
      nhtot = nhtot + hstore(k)
      if(hstore(k).gt.100)nh100 = nh100 +hstore(k)
      enddo
c     fraction of hits > 100
      fnhits = float(nh100)/float(nhtot)
      itemp = fnhits*100.
c     vhigh(1) = itemp
*     write(*,*)'  '
*     write(*,*)' *****************************'
*     write(*,*)' *****************************'
*     write(*,*)' % high hits ',itemp
*     write(*,*)' *****************************'
*     write(*,*)' *****************************'
*     write(*,*)'  '


      call hunpak(7000,cont,' ',0)
      hmean = 0.
      fn = 0.
      do j =1,125
      v = float(j)*2. -1. ! bin center
      hmean = hmean + cont(j)*v
      fn = fn +cont(j)
      enddo
      hmean = hmean/fn
      hrms = 0.
      hskew = 0.
      hkur = 0.
      do j =1,125
      v = float(j)*2. -1. ! bin center
      hrms = hrms + cont(j)*(v - hmean)**2
      hskew = hskew + cont(j)*(v - hmean)**3
      hkur = hkur + cont(j)*(v - hmean)**4
      enddo
      hrms = sqrt(hrms/fn)
      hskew = hskew/fn/hrms**3
      hkur = hkur/fn/hrms**4
*     write(*,*)' '
*     write(*,*)' HITS , mean rms  skewness kurtosis',
*    1 ii,hmean,hrms,hskew,hkur
*     write(*,*)' '
c     vhskew(1) = hskew
c     vhkur(1) = hkur

      call hfill(400,hskew,0.,1.)  !  BQI  hskew - hits skewness <<<<<
c     if(icc(1).eq.140)call hprint(400)


*     make plots for large BGI 

      iplot(1) = 0 ! no   plots made unless BQI set
      if(crem.gt.5.0)then
      iplot(1) = 4 ! removed Fig 1 reset (4.) 040723 
      call hfill(410,4.,0.,1.) ! flag for individual events
      call hfill(420,4.,0.,1.) ! accumulates flags of BQI - printed
      endif
      if(hskew.gt.1.0)then
      iplot(1) = 1 ! skewness hits
      call hfill(410,1.,0.,1.)
      call hfill(420,1.,0.,1.)
      endif
c     if(noise.gt.75.0)iplot(1) = 1  ! ? noise  level
      if(smax.gt.800.)then
      iplot(1) = 2 ! max Fig 2
      call hfill(410,2.,0.,1.)
      call hfill(420,2.,0.,1.)
      endif
      if(smin.lt.100.)then
      iplot(1) = 3 ! min Fig 2 ! added 040723
      call hfill(410,3.,0.,1.)
      call hfill(420,3.,0.,1.)
      endif
c     if(vch(1).gt.10.)iplot(1) = 1  !bunches
c     if(vhigh(1).gt.5.)iplot(1) = 1  ! added 04/07/23 %hits > 100
c     if(s100.gt.14000.)iplot(1) = 1  ! test 100 HZ  06/0723
c      iplot(1) =1



      if(iplot(1).gt.0)then
      icount = icount + 1
      write(*,*)' count run burst  BQI ', icount,nrun,nbur, iplot(1)
      write(sout,'(i4)')nbur
      ssout = 'burst'//sout// '.'//'dat'
      write(*,*)' ',sout,'  ',ssout
**********single file output *****************************
      call hrput(0,ssout,'n') ! output dat file per event
**********************************************************
      endif

      call hreset(101,' ')
      call hreset(102,' ')
      call hreset(103,' ')
      call hreset(104,' ')
      call hreset(110,' ')
      call hreset(410,' ')
      call hreset(7000,' ')
      call hreset(8000,' ')
      call hreset(9200,' ')
      call hreset(10000,' ')
      call hreset(12000,' ')
      call hreset(12001,' ')
      call hreset(20000,' ')
      call hreset(21000,' ')








*     call hrput(0,'fkdev340.dat','n')
*      stop
      return
      end


