Program Muller_C
! Main for 'muller'
! Double precision
!
! Data File (Input): Specified by the user.
! Content:
! 1) Problem title/description: text of 80 chars.
! 2) Exist_p (Logical): T or F (true/false). If function defined in "f_complex.f90" contains a parameter.
! 2-1) Parameter "p": only if exist_p is true.
! 3) nrad: No. of desired roots.
! 4) z1(1:nrad): Initial approximations: "nrad" complex (or real) values.
! 5) h: step: real
! 6) EPS, LNIT: Tolerance; Limit number of iterations.
! 7) ktip: Printing code: 0/1
!
! Output data are written in the Data File, after the input data.
!
external f; complex(8) f;
complex(8) rad

character(80) title, text_eps 
character(1) w
logical new_root, exist_p
character(260) fname
integer width
real(8) p; common p;

complex(8), allocatable ::z1(:), z0(:), z2(:)
real(8) h

character(132) f_text, f_source


text_eps ='       * EPS nu s-a atins.'

f_source ='f_complex.f90'
call F_Expr(f_source, f_text)
write(*, '(1x, a)') trim(f_text)

print '(a, \)', ' Nume fisier intrare: '
read *, fname

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

read(1,'(a)') title

read(1, '(L)') exist_p
if(exist_p) then
read(1,*) p
endif

read(1,*) nrad

allocate(z1(nrad))
z1 =(0.,0.)

read(1,*) (z1(i), i=1,nrad)
read(1,*) h

read(1,*) eps, lnit

read(1,*) ktip

!end read

! Allocate:
allocate(z0(nrad),z2(nrad))

z2 =z1 +cmplx(0,h)
z0 =z1 +cmplx(0,-h)

! Test if any input is a root:

write(1, '(//, a)') ' Metoda MULLER (Complex)'

write(1, '(1x, a)') trim(f_text)

if(exist_p) then
write(1,*) 'p:', p
endif

! Write inputs & root no.:
iwlnit =width(lnit);
write(1, '(/, a, 1pG10.3, a, I<iwlnit>, /)') ' EPS:', eps, '; LNIT: ', lnit


write(1, '(/, a, t15, a, t63, a)') ' #',' Radacina', 'Iteratii'

DO irad =1,nrad

! Subroutine call:
kod =ktip
iter =lnit
call Muller_Complex(f, h, z0(irad), z1(irad), z2(irad), eps, iter, rad, kod)

! Output values:
iwi =width(irad)+1
iwiter =width(iter)

if(kod ==0) then
write(1, '(/, I<iwi>, g,g, t63, I<iwiter>, /)') irad, rad, iter
write(*,*); write(*,*) irad, rad, iter;

else
write(1, '(/, I<iwi>, 2g, t63, I<iwiter>,a /)') irad, rad, iter, text_eps
write(*,*); write(*,*) irad, rad, iter, text_eps
endif

write(1,*) '     f =', f(rad)

ENDDO

close(1)

print '(/, a, a, /)', ' * Fisier de rezultate: ', trim(fname)

END program Muller_C
