      PROGRAM trapzx
c     Driver para a rotina trapz
      INTEGER k,NMAX
      REAL*8 a,b,dt,t,func,told,EPS,at
      EXTERNAL func
      PARAMETER(NMAX=50,EPS=1.d-10)
      write(*,*) 'Digite a e b:'
      read(*,*) a,b
      write(*,*)
c     Compute the first approximations before comparisons
      do 10 k=0,4
         call trapz(a,b,t,k,func)
 10   continue
c     Start the comparisons
      do 20 k=5,NMAX
         told=t
         call trapz(a,b,t,k,func)
         dt=abs(t-told)
         at=EPS*abs(t)
         if (dt.lt.at) then
            write(*,100) 'k=',k,'told=',told,'t=',t
            STOP
         endif
 20   continue
      write(*,*) 'Numero de iteracoes excedido'
 100  format(a2,i2,a12,e20.12,a5,e20.12)
      END
