      FUNCTION AUTCORFV(IT,NV,NDAT,DAT,DMEAN,LMEAN) 
C Bernd Berg Nov 6 2007. Vector version of AUTCORF. The function 
C calculates the autocorrelation at IT from the input array of 
C vectors DAT(NV,NDAT). Allowed values of IT are IT=0,1, ... < NDAT.
      include 'implicit.sta'
      include 'constants.par'
      DIMENSION DAT(NV,NDAT),DMEAN(NV)
      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
      NN=NDAT-IT
      AUTCORF=ZERO
      DO I=1,NN ! Avoids to overwrite DAT array.
        DO IV=1,NV
          AUTCORF=AUTCORF+(DAT(IV,I)-DMEAN(IV))*(DAT(IV,I+IT)-DMEAN(IV))
        ENDDO    
      ENDDO    
      IF(LMEAN) THEN
        AUTCORFV=AUTCORF/(NN*ONE)*((NDAT*ONE)/(NDAT*ONE-ONE))
      ELSE
        AUTCORFV=AUTCORF/(NN*ONE)
      ENDIF
      RETURN
      END
