
      SUBROUTINE SMOOTH(N,B,M,YMIN,YMAX)
C                                                           **********
C                                                           **SMOOTH**
C                                                           **********
      DIMENSION AA(25),SM(64),B(4096)
C LEAST SQUARE MOVING AVERAGE 5,7,9,11,15,19,25 PT SMOOTH
   39 IF(M.NE.19)GO TO 40
      AA(1)=-136.
      AA(2)=-51.
      AA(3)=24.
      AA(4)=89.
      AA(5)=144.
      AA(6)=189.
      AA(7)=224.
      AA(8)=249.
      AA(9)=264.
      AA(10)=269.
      AA(11)=264.
      AA(12)=249.
      AA(13)=224.
      AA(14)=189.
      AA(15)=144.
      AA(16)=89.
      AA(17)=24.
      AA(18)=-51.
      AA(19)=-136.
      S=2261.
      GO TO 47
   40 IF(M.NE.11) GO TO 41
      AA(1)=-36.
      AA(2)=9.
      AA(3)=44.
      AA(4)=69.
      AA(5)=84.
      AA(6)=89.
      AA(7)=84.
      AA(8)=69.
      AA(9)=44.
      AA(10)=9.
      AA(11)=-36.
      S=429.
      GO TO 47
   41 IF(M.NE.5) GO TO 42
      AA(1)=-3.
      AA(2)=12.
      AA(3)=17.
      AA(4)=12.
      AA(5)=-3.
      S=35.
      GO TO 47
   42 IF(M.NE.25) GO TO 43
      AA(1)=-253.
      AA(2)=-138.
      AA(3)=-33.
      AA(4)=62.
      AA(5)=147.
      AA(6)=222.
      AA(7)=287.
      AA(8)=343.
      AA(9)=387.
      AA(10)=422.
      AA(11)=447.
      AA(12)=462.
      AA(13)=467.
      AA(14)=462.
      AA(15)=447.
      AA(16)=422.
      AA(17)=387.
      AA(18)=343.
      AA(19)=287.
      AA(20)=222.
      AA(21)=147.
      AA(22)=62.
      AA(23)=-33.
      AA(24)=-138.
      AA(25)=-253.
      S=5175.
      GO TO 47
   43 IF(M.NE.7) GO TO 44
      AA(1)=-2.
      AA(2)=3.
      AA(3)=6.
      AA(4)=7.
      AA(5)=6.
      AA(6)=3.
      AA(7)=-2.
      S=21.
      GO TO 47
   44 IF(M.NE.9) GO TO 45
      AA(1)=-21.
      AA(2)=14.
      AA(3)=39.
      AA(4)=54.
      AA(5)=59.
      AA(6)=54.
      AA(7)=39.
      AA(8)=14.
      AA(9)=-21.
      S=231.
      GO TO 47
   45 IF(M.NE.15) GO TO 46
      AA(1)=-78.
      AA(2)=-13.
      AA(3)=42.
      AA(4)=87.
      AA(5)=122.
      AA(6)=147.
      AA(7)=162.
      AA(8)=167.
      AA(9)=162.
      AA(10)=147.
      AA(11)=122.
      AA(12)=87.
      AA(13)=42.
      AA(14)=-13.
      AA(15)=-78.
      S=1105.
      GO TO 47
   46 WRITE(7,1) M
    1 FORMAT(/1X,'THE NUMBER OF SMOOTHING PTS ENTERED WAS ',I2,
     X', AN INVALID NUMBER.'/1X,'PLEASE ENTER ONE OF THE FOLLOWING ',
     X'VALID NUMBERS -- 05,07,09,11,15,19,25')
      READ(5,4) M
    4 FORMAT(I2)
      GO TO 39
   47 M2=M/2
      K=M2
      DO 5 J=1,M2
      SM(J)=B(J)
    5 CONTINUE
      MM=0
    2 MM=MM+1
      SUM=0.0
      M5=MM+M-1
      IF(M5.GT.N) GO TO 20
      J1=0
      DO 3 I=MM,M5
      J1=J1+1
    3 SUM=SUM+AA(J1)*B(I)
      K=K + 1
      SM(K)=SUM/S
      IF(K.NE.64)GO TO 2
      WRITE(13) (SM(J),J=1,64)
      K=0
      GO TO 2
   20 K=K + 1
      DO 7 J=K,64
      J1=MM + M2
      IF(J1.GT.N)GO TO 6
      SM(J)=B(J1)
      GO TO 11
    6 SM(J)=0.
   11 MM=MM + 1
    7 CONTINUE
      WRITE(13) (SM(J),J=1,64)
      REWIND 13
      YMIN=9999.
      YMAX=0.0
      K=65
      DO 9 J=1,N
      IF(K.LT.65)GO TO 8
      K=1
      READ(13,END=10) (SM(L),L=1,64)
    8 T=SM(K)
      B(J)=T
      IF(T.GT.YMAX)YMAX=T
      IF(T.LT.YMIN)YMIN=T
      K=K + 1
    9 CONTINUE
   10 REWIND 13
D     PAUSE
D     WRITE(7,1000) (B(J),J=1,N)
D1000 FORMAT(1X,10F7.1)
      RETURN
      END
