      function fclazy(nmax,y,id,m,s,ifo,eps0)
      dimension y(nmax),s(m)

      eps=eps0
      nfound=0
 1    av=0
      do 10 n=(m-1)*id+1,nmax-ifo
        do 20 i=1,m
 20       if(abs(y(n-(m-i)*id)-s(i)).ge.eps) goto 10
        nfound=nfound+1                                ! if got here: neighbour
        av=av+y(n+ifo)                      ! average over future of neighbours
 10     continue
      eps=eps*1.2
      if(nfound.eq.0) goto 1                         ! try larger neighbourhood
      fclazy=av/nfound
      end
