! Simpla precizie
! Metoda Laguerre pentru polinoame
! Zero-uri complexe
! Cu IMSL: CALL ZPLRC (NDEG, COEFF, ROOT)
! ndeg: gradul polinomului.
! coef: vectorul coef. incepand cu gradul cel mai mare
! root: tablou complex pt. radacini
!
! Polinom: p(z) =a_n*x^n +a_(n-1)*x^(n-1) + ... +a_1*z +a_0
! a_i = reali
!
! Fisier de date:
! 1) Titlul problemei: <=80 caractere.
! 2) Grad polinom: n
! 3) Coeficientii (reali): a_n, a_(n-1), ..., a_0
! Urmatoarea data este optionala:
! 4) Inverse: logic, pentru inversarea coeficientilor: T/F

include 'link_fnl_shared.h'


character(260) fname, dummy*80
real(4), allocatable :: coef(:)
complex, allocatable :: rad(:); complex polval;

integer status

!print '(a, \)', ' Input file: '
!read '(a)', fname
call GetFile(fname, status, 'Selecteaza Fisierul de Intrare'C)

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

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

read (1,*) n	! gradul
allocate (coef(0:n))
allocate (rad(n))

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

read (1, '(L)', err =100, end =100) inverse
if(inverse) then
do i=0, n
coef(i) =1./coef(i)
enddo
endif

100 print *, 'Coeficienti: ', (coef(i), i=n,0,-1)

200 write(1,*)
call ZPLRC (n, coef, rad)
!CALL ZPLRC (NDEG, COEFF, ROOT)

! Roots:
write(1,'(/, a)') ' Radacini:'
do i =1,n
write(1,*) i, rad(i)
enddo

! Polynomial values:
write(1,'(/, a)') ' Valori polinom:'
do i =1,n
write(1,*), i, polval(n, coef, rad(i))
enddo

END
