      real function twalk(option)

      include 'rs_test.inc'

      real
     $     option               ! option what to fit

      integer
     $     len
      parameter
     $     (len = 20*20)

      integer
     $     irun,
     $     index
      
      logical 
     $     first,
     $     accept
      real
     $     run_current,
     $     num(len), den(len)
      save 
     $     num, den,
     $     run_current,
     $     first, 
     $     irun

      vector dtda(len)

      data first /.true./

      if (first) then
         first   = .false.
         counter = 0
         call vzero(den,len)
         call vzero(num,len)
         run_current = 0
         irun        = 0
      endif

      if (run.ne.run_current) then
         irun = irun + 1
         run_current = run
         write(*,'(i3,2x,a,i6)') 
     $        irun, 'Processing run', int(run_current)
      endif

      accept = .false.
      if (option.eq.0.) accept = .true.
      if (option.eq.1. .and. sec.ge.01.and.sec.le.06) accept=.true.
      if (option.eq.2. .and. sec.ge.07.and.sec.le.12) accept=.true.
      if (option.eq.3. .and. sec.ge.13.and.sec.le.18) accept=.true.
      if (option.eq.4. .and. sec.ge.19.and.sec.le.24) accept=.true.
      if (option.eq.5. .and.(lay.eq.01.or.lay.eq.19)) accept=.true.
      if (option.eq.6. .and. lay.ge.02.and.lay.le.06) accept=.true.
      if (option.eq.7. .and. lay.ge.07.and.lay.le.10) accept=.true.
      if (option.eq.8. .and. lay.ge.11.and.lay.le.14) accept=.true.
      if (option.eq.9. .and. lay.ge.15.and.lay.le.18) accept=.true.

      if (accept) then
        index = int(amp) + (irun-1)*20
         den(index) = den(index) + nm*(a2m-am*am)
         num(index) = num(index) + nm*(tam-tm*am)
        dtda(index) = num(index) / den(index)
      endif

      twalk = dtda(5)

      return
      end





