      subroutine autcorj(it,ndat,nbins,data,work,acorj,lmean)
c copyright, bernd berg, feb 14 2001.
c calculates the jackknife array of autocorrelation at it (0\le it).
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
      dimension data(ndat),work(nbins),acorj(nbins)
c
      dmean=zero
      if(lmean) dmean=stmean(ndat,data)
      nn=ndat-it
c
      nbin=nn/nbins
      nnj=nbins*nbin-nbin
      if(nbins.le.1) stop "autcorj: nbin.le.1!" ! datjack crashes.
      if(nnj.le.it) print*,"nn,nbin,nbins,nnj,it:",nn,nbin,nbins,nnj,it
      if(nnj.le.it) stop "autcorj: nnj.le.it!"
      do ibins=1,nbins
        work(ibins)=zero
        i1=1+(ibins-1)*nbin
        i2=ibins*nbin
        do i=i1,i2
          work(ibins)=work(ibins)+(data(i)-dmean)*(data(i+it)-dmean)
        end do    
        work(ibins)=work(ibins)/nbin
      end do    
      call datjack(nbins,work,acorj)
c correction of bias from dmean:
      if(lmean) then
      do ibins=1,nbins
        acorj(ibins)=(acorj(ibins)*ndat)/(ndat-1)
      end do    
      end if
c
      return
      end
