subroutine grafic(f)
use PAR
external f
! graficul unei functii f(x) - pe [a,b], cu pasul h
character(128) fname, w*1

logical exist_p/.FALSE./

! Graph index:
igrafic =igrafic+1
iunit =igrafic

if(igrafic >1) print '(a)'
print '(/, a, I2)', ' Graph # ', igrafic
 
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)', fname
fname =trim(fname)//'.dat'
open(iunit, file =fname)

nPas =nint((b-a)/h)
f_ant =f(a)

do j=0, nPas
x =a +j*h
f_j =f(x)

! schimbare de semn:
if(f_j ==0.0) then
write(iunit, *) x, f_j, '*'
else
    if(sign(1.,f_ant) ==sign(1., f_j)) then
    write(iunit, *) x, f_j  !f(x)
    else
    write(iunit, *) x, f_j, '*'
    endif
endif

f_ant =f_j

enddo

if(exist_p) then
print*,' Another parameter? (Y,y/char): '
read '(a1)', w
if(w =='Y'.or.w =='y') goto 100
endif

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