      function autcorf(it,ndat,data,lmean) ! bernd berg, feb 14 2001.
c the function calculates the autocorrelation at it from the input array 
c data of autocorrelations. allowed values of it are it=0,1, ... < ndat.
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
      dimension data(ndat)
      dmean=zero
      if(lmean) dmean=stmean(ndat,data)
      nn=ndat-it
      autcorf=zero
      do i=1,nn
        autcorf=autcorf+(data(i)-dmean)*(data(i+it)-dmean)
      end do    
      if(lmean) autcorf=autcorf/(nn*one)*((ndat*one)/(ndat*one-one))
      if(.not.lmean) autcorf=autcorf/(nn*one)
      return
      end
