      SUBROUTINE S8(NCD,IER,IOR,ITAG)
C-----GENERATES THE POLYNOMIALSBY CALLING ROUTINE CFIT
C.....CFIT RETURNS BEST CURVE FIT BY LEAST SQUARE METHOD
       DIMENSIONX(40),Y(40),A(10,10),COEF(10)
      COMMON/AR/BRAY(4,600),STRESS(200,4)
      COMMON/SIHI/IVECT(1800)
      IER=0
      NPTS=NCD
      IF(NPTS.GT.40)IER=3
      NSOEF=8
       IF(NPTS.LT.2)IER=3
      IF(NPTS.LT.8)NSOEF=NPTS
      PDVN=100.
      IF(IER.EQ.3)WRITE(6,46)IER
      IF(IER.EQ.3)RETURN
       DO 5 I=1,NPTS
      X(I)=BRAY(1,I)
      Y(I)=BRAY(2,I)
      WRITE(6,67)X(I),Y(I)
    5 CONTINUE
   67 FORMAT(2F20.5)
       NCOEF=2
  4    SUM=0.00
      CALL S7(NCOEF,COEF,NPTS,X,Y,DEVN,IER,A)
      WRITE(6,46)IER
   46 FORMAT(2X,5HERROR,I2)
      IF(DEVN.GT.PDVN)GO TO 3
       DO 25 J=1,NPTS
       POLY=COEF(1)
       DO 12 I=2,NCOEF
  12   POLY=POLY*X(J)+COEF(I)
C.....SETTING DATA INTO BRAY TO GIVE CONTINUOUS CURVE
       BRAY(1,J)=X(I)
       BRAY(2,J)=POLY
   25  CONTINUE
      NUMB=NCD
      L1=3
      CALL S3(L1,NUMB,NCD)
    3  N=NCOEF-1
      ITAG=8
      IF(N.LT.2)GO TO 2
      CALL DISPLY(3,ITAG)
    2 IR=1
      CALL VECTOR(1,BRAY,1,NCD,IVECT,IR,LA,7,0,.FALSE.)
      CALL DISPLY(6,ITAG,IVECT,IR,LA)
   11 WRITE(6,13)N
   13 FORMAT(1H0,15H POLY OF ORDER  ,I2)
       DO 88 J=1,NCOEF
   35 WRITE(6,20)J,COEF(J)
   20 FORMAT(1H0,6H COEF(,I2,3H)= ,F20.5)
  88   CONTINUE
      WRITE(6,21)DEVN
      PDVN=DEVN
   21 FORMAT(1H0,13H, DEVIATION = ,F20.5//)
       NCOEF=NCOEF+1
      IF(NCOEF.LT.NSOEF)GO TO 4
      RETURN
       END
