Program Met_Muller
! Main for 'muller'

external f
character(80) text(-1:2)
character(1) w
logical new_root, exist_p
character(260) fname0, fname
integer width
common p

character(132) f_text, f_source


text(0) =' * Toleranta EPS atinsa'
text(1) =' ** LNIT depasit'
text(2) =' * Radacina in aproximatiile initiale'
text(-1) =' ** Radical din numar negativ !'

10 format(a, \)

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

print 10, ' Nume fisier rezultate (Fara extensie): '
read *, fname0

fname =trim(fname0)//'.rez'
open(1, file =fname, form ='formatted', status ='unknown')

print 10,' Functia f(x) include parametrul "p" (Y,y / char) ?: '
read'(a)',w
exist_p =(w =='Y' .or. w =='y')

if(exist_p) then
print 10,' p=? : '
read*,p
endif

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

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

nrad =1

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


! Input values:
100 print 10,' Introdu eps, lnit: '
read *, eps, lnit

print 10,' Introdu x1, h: '
read *, x1, h

if(h<0) h =-h

! Assign:
x0 =x1 -h
x2 =x1 +h

! Test if any input is a root:

print 10, ' Cod de tiparire iteratii (0/#0): '
read *, ktip


! Write inputs & root no.:
iwn =width(nrad); iwlnit =width(lnit);
write(1, '(//, a, I<iwn>)') ' Radacina nr.', nrad

write(1,*) 'Aproximatii:', x0, x1, x2
write(1, '(a, 1pG10.3, a, I<iwlnit>, /)') ' EPS:', eps, '; LNIT: ', lnit

! Subroutine call:
kod =ktip
iter =lnit

call muller(f, x0, x1, x2, eps, iter, rad, kod)

200 continue
! Output values:
print '(/, a)', trim(text(kod))
print*, 'Rad =',rad, ':		f(Rad) =',f(rad)
print*, 'Numar de iteratii = ', iter

write(1, '(/, a)') text(kod)

if(kod ==0) then
write(1,*) ' Radacina =', rad,'; f(Radacina) =', f(rad)
else
write(1,*) ' Aproximatia curenta: x =', rad,'; f(x) =', f(rad)
endif

iwnlim =width(iter)
write(1, '(a, I<iwnlim>)') '  Numar de iteratii = ', iter


write(*, '(/, a, \)') ' Alta radacina ? (Y, y / char): '
read (*, '(a1)') w

new_root =w =='Y' .or. w=='y'
if(new_root) then
nrad =nrad +1
goto 100
endif

close(1)

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

END program Met_Muller
