C....*...1.........2.........3.........4.........5.........6.........7.*.......8
C     DAUTO1   2/7/75
C
C     PURPOSE
C     COMPUTE AUTOCOVARIANCES OF SERIES X FOR LAGS 0 TO L-1
C
C     USAGE
C     CALL AUTO1(X,N,L,R)
C
C     ARGUMENTS
C     X - INPUT VECTOR OF LENGTH N CONTAINING THE TIME SERIES.
C         REAL*8
C     N - LENGTH OF X.
C         INTEGER*4
C     L - LENGTH OF R.  L MUST BE LESS THAN N.
C         INTEGER*4
C     R - OUTPUT VECTOR OF LENGTH L CONTAINING AUTOCOVARIANCES.
C         REAL*8
C
C     REMARK
C     N MUST BE GREATER THAN L.  IF NOT, R(1) IS SET EQUAL TO ZERO AND
C     RETURN IS MADE.
C     R(J)=(1/N)*(SUM:I=1,N-J+1|(X(I)-XBAR)*(X(I+J-1)-XBAR))
C     XBAR=(1/N)*(SUM:I=1,N|X(I))
C
C
      SUBROUTINE DAUTO1(A,N,L,R)
      IMPLICIT REAL*8 (A-H,O-Z)
      save
      REAL*8 A(1),R(1)
C
C     CALCULATE AVERAGE OF TIME SERIES A
C
      AVER=0.D0
      IF(N-L) 50,50,100
50    R(1)=0.D0
      RETURN
100   DO 110 I=1,N
110   AVER=AVER+A(I)
      FN=N
      AVER=AVER/FN
C
C     CALCULATE AUTOCOVARIANCES
C
      DO 130 J=1,L
      NJ=N-J+1
      SUM=0.D0
      DO 120 I=1,NJ
      IJ=I+J-1
120   SUM=SUM+(A(I)-AVER)*(A(IJ)-AVER)
130   R(J)=SUM/FN
      RETURN
      END
