C....*...1.........2.........3.........4.........5.........6.........7.*.......8
C     PERSMO   2/3/72
C
C     PURPOSE
C     SMOOTH A PERIODOGRAM USING WEIGHTS W
C
C     USAGE
C     CALL PERSMO(P,NP,W,LW,R)
C
C     ARGUMENTS
C     P  - INPUT VECTOR OF PERIODOGRAM ORDINATES.
C     NP - LENGTH OF P AND R.
C     W  - INPUT VECTOR OF WEIGHTS.
C     LW - LENGTH OF W.  LW MUST BE AN ODD INTEGER AND LESS THAN NP.
C     R  - OUTPUT VECTOR OF LENGTH NP.
C
C     REMARKS
C     THE VECTOR R IS FILLED WITH THE MOVING AVERAGE
C     R(I)=W(1)*P(I-(LW-1)/2)+...+W(LW)*P(I+(LW-1)/2)
C     WHERE THE ELEMENTS
C     P(1-(LW-1)/2),P(2-(LW-1)/2),...,P(-1),P(0),P(1),P(2)
C     P(NP),P(NP+1),...,P(NP+(LW-1)/2)
C     ARE TAKEN AS
C     P(1+(LW-1)/2),P((LW-1)/2),...,P(3),P(2),P(2),P(2)
C     P(NP),P(NP-1),...,P(NP-(LW-1)/2)
C     RESPECTIVELY.
C
      SUBROUTINE PERSMO(P,NP,W,LW,R)
      implicit real*8 (a-h,o-z)
      save
      REAL*8 P(2), W(1), R(1)
      INTEGER CENTER
      P1=P(1)
      P(1)=P(2)
      CENTER=LW/2+1
      DO 15 I=1,NP
      Z=0.d0
      DO 10 J=1,LW
      K=I+J-CENTER
      IF(K.LE.0)K=IABS(K)+2
      IF(K.GT.NP) K=NP+NP-K
10    Z=Z+W(J)*P(K)
15    R(I)=Z
      P(1)=P1
      RETURN
      END
