c-----------------------------------------------------------
c Chapter 19: Newton Forms of a Polynomalai(p171)
c-----------------------------------------------------------
c   Name of subroutine: POLY
c
c   Algorithm:Operations on polynomials in power and
c             factorial form.
c
c   input: n=6, A(1)=...=A(5)=0, A(6)=1   
c   complier: f77 poly.f
c-----------------------------------------------------------

c-----The program driver is in poly_2.f---------------------

c-----Subroutine begins here--------------------------------
      subroutine poly(n,a,x0,option,val)
      integer a(n),x0,option,val,z,w,eps
      logical gamma
      gamma=option.ne.0.and. option.ne.-1
      n1=max0(1,min0(n,option))
      if(option.lt.-1) n1=n
      eps=mod(max0(-option,0),2)
      w=-n*eps
      if(option .gt.-2) w=w+x0
      do 1 m=1,n1
      val=0
      z=w
      do 9 i=m,n
      z= z+eps
      val=a(n+m-i)+z*val
9     if (gamma) a(n+m-i)=val
1     if (option.lt.0) w=w+1
      return
      end


