PROGRAM C_POL
use dfwin
! Calculul valorii polinomului (real) - forma data si imbricata
! - de la Z0 la Z1 cu pasul PAS
! - prin ciclu; prin functia polinomiala.
! Coef.: a(n), ..., a(0)
!
! Fisier de date:
! 1) n = gradul polinomului
! 2) a(n), a(n-1), ..., a(0) = coeficientii
! 3) z0, z1, pas = 3 reali
!
! Rulati cu optimizare: None; Full.
!
real, allocatable:: a(:)
real(8) pid
!character(100) nume

character(260) fname, dummy*80
integer status


!print '(a, \)', ' Fisier de intrare: '
!read '(a)', nume
!open (1, file =nume, form='formatted', status ='old')

call GetFile(fname, status, 'Selecteaza Fisierul de Intrare'C)
lfn =lstrlen(fname)

open(1, file =fname, status ='old', form ='formatted')

read(1,'(a)') dummy		! Title

read(1,*) n
allocate (a(0:n))

read(1,*) (a(i),i =n,0,-1)

read(1,*) z0, z1, pas

write(1, '(/, a)') ' Calcul prin ciclu:'
!write(1, '(a)') '  x         p-Dat             p-Imbricat        p-Imbricat in Dubla Precizie'
write(1, '(a)') &
  '  x         p-Dat             p-Imbricat        p-Imbricat in	  Err(p_Dat)    Err(p_Imbricat)'
write(1,'(a)') &
  '                                                Dubla precizie'

DO Z =z0,z1,pas
! forma data:
p =a(0)
zk =1.
do k =1,n
zk =zk*z
p =p +a(k) *zk
enddo

! imbricat:
pi =a(n)
pid =dble(a(n))
do  k =n-1,0,-1
pi =a(k) +z*pi
pid =dble(a(k)) +dble(z)*pid
enddo

!write (1,10) z, p, pi, pid
write (1,10) z, p, pi, pid, pid-p, pid-pi
ENDDO


write(1, '(/,a)') ' Calcul prin functie:'
write(1, '(a)') '  x         p-Dat             p-Imbricat'

do x =z0,z1,pas
call sub_pol(x, p0, p1)
write (1,10) x, p0, p1
enddo

write(1,*)
10 format(' ',f6.3, 2(3x,1pg15.7), :, 3x,1pg15.7, 2(3x,1pg11.3))

write(*,*)
write(*,*) 'Fisier de iesire:', fname(:lfn)
end

