program dPOLALL
! Metoda NEWTON pt. polinoame: numar de 'NR' radacini.
! Prin iterare in polinomul original
! Dubla precizie

implicit real(8) (a-h, o-z)
real(8), allocatable ::A(:), X(:), p(:)
integer, allocatable:: IE(:), nit(:)
character(255) fname, dummy*80


write(*,'(a\)') ' Fisier date: '
read(*,'(a)') fname

OPEN(UNIT=1, FILE =fname, STATUS ='OLD')

read(1,'(a80)') dummy

READ(1,*) N,NR,ktip
if(nr.eq.0) nr=n
!
allocate (a(0:n),x(1:nr),ie(1:nr),nit(1:nr), &
p(1:nr),STAT=ierr)

!
read(1,*) (A(I),I=N,0,-1)
read(1,*) EPS,ITMAX0
READ(1,*) (X(K),K=1,NR)

kodrad =0
read(1,*, iostat =istat) kodrad	! #0: rad =rad*n


DO K=1,NR
X0=X(K)
itmax=itmax0
ier =ktip

if(ier /=0) then
write(1,*)
write(1,*) 'Aproximatia:', x0
endif

CALL POL_direct(N, A, X0, EPS, ITMAX, RAD, B, IER)
    X(K)=RAD
    ie(k)=ier
    nit(k)=itmax
	p(k) =b
ENDDO

write(*,'(a1,a80)') ' ',dummy
write(*,*) ' ** Radacinile:'

write(1,*)
write(1,*) ' ** Radacinile:'
write(1,'(a)') '	Rad						      Cod	Iteratii	p(Rad)'


DO k=1,nr
write(*,*) X(K), IE(K), nit(k), '  ', p(k)
write(1,*) X(K), IE(K), nit(k), '  ', p(k)
ENDDO

if(kodrad /=0) then
write(1,*)
DO k=1,nr
write(1,*) X(K)*n
ENDDO
endif

END


