      SUBROUTINE AUTCORVJ(IT,NV,NDAT,NBINS,DAT,DMEAN,WORK,ACORJ,LMEAN)
C Bernd Berg Nov 6 2007. Vector version of AUTCORJ.
C Calculates the jackknife array of autocorrelation at IT (0\le IT).
      include 'implicit.sta'
      include 'constants.par'
      DIMENSION DAT(NV,NDAT),WORK(NBINS),ACORJ(NBINS),DMEAN(NV)
C
      IF(LMEAN) THEN
        DO IV=1,NV
          DMEAN(IV)=ZERO
        ENDDO
        DO IDAT=1,NDAT
          DO IV=1,NV
            DMEAN(IV)=DMEAN(IV)+DAT(IV,IDAT)
          ENDDO
        ENDDO
        DO IV=1,NV
          DMEAN(IV)=DMEAN(IV)/NDAT
        ENDDO
      ENDIF
C
      NN=NDAT-IT
      NBIN=NN/NBINS
      NNJ=NBINS*NBIN-NBIN
      IF(NBINS.LE.1) STOP "AUTCORJ: NBIN.LE.1!" ! DATJACK crashes.
      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
          DO IV=1,NV
            WORK(IBINS)=WORK(IBINS)+(DAT(IV,I)-DMEAN(IV))*
     &                           (DAT(IV,I+IT)-DMEAN(IV))
          ENDDO
        ENDDO    
        WORK(IBINS)=WORK(IBINS)/NBIN
      ENDDO    
      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)
        ENDDO
      ENDIF
C
      RETURN
      END
