c------------------------------------------------------------------------------ subroutine bisect(f, inx0, inx1, tol, maxits, + status, root, resid, noofit, lastx0, lastx1) c------------------------------------------------------------------------------ integer count, limit, maxits, nobracs, noofit, solved, status real f, f0, fmid, inx0, inx1, lastx0, lastx1, + resid, root, tol, x0, x1, xmid parameter (solved=0, limit=1, nobrac=2) intrinsic abs external f x0 = inx0 x1 = inx1 f0 = f(x0) f1 = f(x1) if (f0*f1.gt.0) then c x0, x1 do not bracket the root status = nobrac else c do bisection do 10, count = 1, maxits xmid = (x0+x1)/2. fmid = f(xmid) if (f0*fmid.lt.0) then x1 = xmid else x0 = xmid f0 = fmid end if if (abs(x1-x0).le.tol) then status = solved goto 11 end if 10 continue status = limit 11 if (status.eq.solved) then root = (x0+x1)/2. resid = f(root) noofit = count end if if (status.eq.limit) then lastx0 = x0 lastx1 = x1 end if end if end c------------------------------------------------------------------------------ real function f(x) c------------------------------------------------------------------------------ real x intrinsic exp f = x - exp(1/x) return end