Program MSec
! Main pt. metoda secantei
external f
character(80) text(-2:1)
character(260) fname0, fname, w*1
integer width
common p; logical exist_p;

character(132) f_text, f_source
logical new_rad, new_p, new_tol


text(-2)=' ** Numitor nul'
text(-1)=' ** Proces divergent'
text(0) =' * Toleranta EPS atinsa'
text(1) =' ** Numarul de iteratii atins'

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')

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

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

nrad =1
new_p =.false.
new_tol =.true.

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

200 continue
if(new_p) then
print '(a, \)',' Alt "xtol" si "nlim" ? (Y/ char): '
read '(a)',w
new_tol =w=='Y' .or. w =='y'
endif

if(new_tol) then
print 10, ' Introdu eps, lnit: '
read *, eps, lnit0
endif

210 print 10, ' Introdu x0, x1: '
read *, x00, x10

! Test x0 =x1:
if(x00 ==x10) then
print '(/, a)',' x0 =x1. Valorile trebuie sa fie diferite !'
goto 210
endif

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

x0 =x00; x1 =x10
lnit =lnit0

iwn =width(nrad); iwlnit0 =width(lnit0);
write(1, '(/, a, I<iwn>, a1)') ' Radacina nr.', nrad

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


write(1,*) 'Aproximatii initiale: ', x00, x10
write(1, '(a, 1pG10.3, a, I<iwnlim0>, /)') ' EPS:', EPS, '; LNIT: ', lnit0

call SECANT(f, x0, x1, eps, lnit, rad, kod)

if(kod ==-1) then
print '(/,a)', trim(text(1))
write(1,'(/,a,\)'), trim(text(1))
endif

if(kod /=2) then
print '(/a)', trim(text(kod))
write(1, '(/, a)'), trim(text(kod))
endif

if(kod ==0) then
write(1,*) ' Radacina =', rad,'; f(Radacina) =', f(rad)
write(*,*) ' Radacina =', rad,'; f(Radacina) =', f(rad)

else
write(1,*) ' Aproximatia curenta: x =', rad,'; f(x) =', f(rad)
write(*,*) ' Aproximatia curenta: x =', rad,'; f(x) =', f(rad)
endif

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

! Alta radacina:
print*
print 10,' Alta radacina ? (Y/ char): '
read '(a)',w

new_rad =w=='Y' .or. w =='y'
new_p =.false.

IF(new_rad) then
nrad =nrad+1

	if(exist_p) then
	print '(a, \)',' Alt "p" ? (Y/ char): '
	read '(a)',w
	new_p =w=='Y' .or. w =='y'

	if(new_p) goto 100
	endif


print '(a, \)',' Alt "xtol" si "nlim" ? (Y/ char): '
read '(a)',w
new_tol =w=='Y' .or. w =='y'

if(new_tol) then
goto 200
else
goto 210
endif

ENDIF

close(1)

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

END
