Program Bisection
! Main for 'bis'

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

character(132) f_text, f_source


text(-2)=' ** Eroare: "a" nu poate fi egal cu "b" !'
text(-1)=' ** Eroare: f(a)*f(b) >0'
text(0) =' * Toleranta EPS atinsa'
text(1) =' ** LNIT depasit'
text(2) =' * Radacina in "a" sau "b"'

10 format(a, \)

f_source ='fun.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 / 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 BISECTIEI'
write(1,'(1x, a)') trim(f_text)

if(exist_p) then
write(1, '(/, a, 1pg14.7)') ' p = ',p
endif


nrad =1

! Input values:
100 print 10,' Introdu a, b: '
read *, a, b

if(a ==b) then
kod =-2
write(*, '(/, a)') text(kod); write(1, '(/, a)') text(kod);
goto 100
endif

print 10,' Introdu eps, lnit: '
read *, eps, lnit

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,*) 'Interval:', a, b
!write(1,*) 'Toleranta:', eps, '; Numar limita de iteratii:', lnit
write(1, '(a, 1pG10.3, a, I<iwlnit>, /)') ' EPS:', EPS, '; LNIT: ', lnit

! Subroutine call:
iter =lnit
call BIS(f, a, b, eps, iter, rad, kod, ktip)

200 continue
! Output values:
if(ktip /=0) then
write(*,*); write(1,*);
endif

print *,' Rezultate:'
print *
print '(a)', text(kod)

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

if(kod >=0) then
print *, 'Radacina =', rad
print *, 'F(Radacina) =', f(rad)
print * ,'Numar de iteratii:', iter

write(1,*) 'Radacina =', rad
write(1,*) 'F(Radacina) =', f(rad)
iwi =width(iter)
write(1,'(a, I<iwi>)') 'Numar de iteratii: ', iter
endif

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 Bisection
