      program zero
c      implicit double precision (a-h,o-z)
      double precision a,b,r,re,ae,rr,func1,func,step
      dimension xray(101),yray(101)
      logical flag
      external func1,func
      n=101
      x=-1.
      do i=1,n
        xray(i)=x
        yray(i)=func1(dble(x))
        x=x+2.e-2
      end do
      write(*,*) 'zadaj krok'
      read(*,*) b
      CALL metafl('cons') 
      CALL DISINI ()
      CALL graf(-1.0,1.0,-1.0,0.25,-1.0,1.0,-1.0,0.2)
      call color('yellow')
      CALL name('x premenna','X')
      call name('y premenna','Y') 
      CALL TITLIN('hladanie nuloveho bodu',2) 
      call color('red')
      call thkcrv(5)
      call curve(xray,yray,n)
      call color('green')
      ixp=nxposn(-1.0)
      ixk=nxposn(1.0)
      iy=nyposn(0.0)
      call line(ixp,iy,ixk,iy)
      call hsymbl(20)
c      call disfin ()
c      open(1,file='c:/modelovanie/Output/zero.out')
      a=-1.0d0
c      b=0.2d0
      step=0.05d0
      re=1.d-5
      do i=1,10
         call dzero1(func1,a,step,re,flag)
         if (flag) then
             rr=func1(a)
             ix=nxposn(real(a))
             iy=nyposn(real(rr))
             call symbol(21,ix,iy)
         end if
         a=a+b
      end do
      call disfin ()
c      write(1,*) a,rr,iflag
c      close(1)
      end
c
      function func(x)
      implicit double precision (a-h,o-z)
      func=x*x*x+3.d-1
      return
      end     
      function func1(x)
      implicit double precision (a-h,o-z)
      func1=dsin(50.d0/(x+2.d0))
      return
      end     
c
      subroutine dzero(func,a,b,eer,lab)
      implicit double precision (a-h,o-z)
      real j
      logical lab
      character*1 si
      external func
      call color('blue')
      lab=.false. 
      fa=func(a)
      fb=func(b)
      sab=fa*fb
      j=1.0
      if (sab.GT.0.d0) return
10    continue
      dif=dabs(a-b)
      if (dif.LT.eer) then
         a=b
         lab=.true.
         call color('green')
         return
      end if
      c=0.5d0*(a+b)
      fc=func(c)
      ic=nxposn(real(c))
      ifc=nyposn(real(fc))
      call symbol(15,ic,ifc)
c      call intcha(i,1,si)
      if (j.LT.5) call number(j,-1,ic,ifc+30)
      j=j+1.0
      sac=fa*fc
      if (sac.GT.0.d0) then
         a=c
      else
         b=c
      end if
      go to 10
      end
c
      subroutine dzero1(func,a,step,eer,lab)
      implicit double precision (a-h,o-z)
      logical lab
      external func
      lab=.false. 
 20   fa=func(a)
      b=a+step
      fb=func(b)
      sab=fa*fb
      if (sab.GT.0.d0) then
         a=b
         go to 20
      else
 10      continue
         dif=dabs(a-b)
         if (dif.LT.eer) then
            a=b
            lab=.true.
            return
         end if
         c=0.5d0*(a+b)
         fc=func(c)
         sac=fa*fc
         if (sac.GT.0.d0) then
             a=c
         else
             b=c
         end if
         go to 10
      end if
      end
            
