      program sp810        ! AS data for 20000 events
      implicit none        ! 時間差分布は指数分布
      integer i, j

      character dummy*10
      integer Ns, hh1,mm1,ss1,ms1, hh2,mm2,ss2,ms2
      real*8 s1,  s2,  ds12
      parameter( Ns=20000 )                    ! 20000 events

      integer Ntmax, Ntmax1                    ! 時間差分布を求めるために
      parameter( Ntmax=150, Ntmax1=Ntmax+1 )
      real*8 tmin, tmax, dt, box(Ntmax1)       ! tmin～tmax(sec) Ntmax分割
      parameter( tmin=0, tmax=300 )            ! 0～300secまで150分割
      integer cnt(Ntmax)
      data    cnt/Ntmax*0/

      real*8 sum, ave
      data   sum/0d0/

      real*8 x, y

      real*8 lambda                            ! 平均値
      real*8 f, t
      f(t) = 1d0/lambda * exp(-t/lambda)       ! 指数関数

      real*8 detection_Time                    ! 観測時間(sec)

      dt     = ( tmax - tmin ) / Ntmax
      box(1) = tmin
      do j=1,Ntmax
      box(j+1)= box(j) + dt
      enddo

      open(1,file='070109.DAT')
      read(1,*) dummy
      read(1,*) dummy
      read(1,*) dummy

      read(1, '(3i2,i7)') hh1, mm1, ss1, ms1
        s1  = hh1*60*60 + mm1*60 + ss1 + ms1*1d-6

      do i=1,Ns-1
        read(1, '(3i2,i7)') hh2, mm2, ss2, ms2
        s2  = hh2*60*60 + mm2*60 + ss2 + ms2*1d-6
        ds12= s2 - s1
        if(ds12.lt.0) then
            ds12 = ds12 + __*__*__
        endif
        do j=1,Ntmax                            ! 時間差の度数分布
            if( ______.le.ds12 .and. ____.lt.________ ) then
                cnt(j) = ______ + 1
                go to 1000
            endif
        enddo
 1000   continue
        sum = sum + ds12
        hh1 = hh2
        mm1 = mm2
        ss1 = ss2
        ms1 = ms2
        s1  = s2
      enddo
      close(1)

      ave = sum / (Ns-1)
      write(*,'(/4x,a5,1pe12.5,a4)') 'ave =',ave,' sec'

      open(3, file='sp810.dat')
      lambda = ave
      do j=1,Ntmax
        x = box(j)+dt/2d0
        y = float(cnt(j))/dt/(Ns-1)            ! 時間差の確率密度の分布
        write(3,*) x, y, f(x)
      enddo
      close(3)

      open(4, file='sp810_lambda.dat')         ! <-- lambda
      write(4,*) lambda
      close(4)

      open(5, file='sp810_detection_Time.dat') ! <-- detection_Time
      detection_Time = sum
      write(5,*) detection_Time
      close(5)

      stop
      end