! Graficul unei functii f(x) - pe [a,b], cu pasul h;
! Schimbarea de semn - daca exista: marcata cu un *.
!
subroutine grafic(f)
use work
external f
character(128) fname0, fname*260, w*1

logical exist_p/.FALSE./
character(12) a_str, b_str
character(1) op_br/'['/, cl_br/']'/, comma/','/

iunit =1

write(*,'(a)') fun_expression

print '(a\)', ' Function depends on Parameter? (Y,y/char): '
read '(a1)', w
if(w=='Y'.or.w=='y') then
exist_p =.TRUE.

100 print '(a\)',' Input parameter "p": '
read *, p
endif

print '(a\)', ' Input a, b, h: '
read *, a,b,h
print '(a\)', ' Input file name - No extension: '
read '(a)', fname0


!fname =trim(fname0)//'.dat'
fname =Dat_Directory(:l_Dat)//'\'//trim(fname0)//'.dat'
open(iunit, file =fname)

!write(iunit,'(a,\)') trim(fun_expression) 
if(exist_p) then
write(iunit,'(a,\)') trim(fun_expression) 
write(iunit, '(a, 1pE14.6, a1)') ';   p =', p, ';'

else
write(iunit,'(a)') trim(fun_expression) 
endif

write(a_str, '(F12.4)') a
a_str =adjustl(a_str)

write(b_str, '(F12.4)') b
b_str =adjustl(b_str)

write(iunit, '(a, 1pE11.4)') op_br//trim(a_str)//comma//trim(b_str)//cl_br//';   h =', h
write(iunit, *)

f_ant =f(a)

nPas =nint((b-a)/h)
no_roots =0

do j=0, nPas
x =a +j*h
f_j =f(x)
! schimbare de semn:
if(sign(1.,f_ant) ==sign(1., f_j)) then
write(iunit, *) x, f_j  !f(x)
else
write(iunit, *) x, f_j, '*'
no_roots =no_roots +1
endif

f_ant =f_j
enddo

write(iunit, *) 'No. of roots: ', no_roots

write(*,'(/, a, a)') ' Fisier de iesire: ', trim(fname)
close(iunit)

if(exist_p) then
write(*, '(/, a, \)') ' Another parameter? (Y,y/char): '
read '(a1)', w
if(w=='Y'.or.w=='y') then
iunit =iunit +1
goto 100
endif

endif


END
