function I=integ(func,param,a,b,N,hmin);
%INTEG is a program that integrates an arbitrary function from a to b
%  using a variable mesh spacing h. The mesh is stretched from a to b
%  by the factor hstret, such that h(i)=hstret^i*hmin. 
%
%  INPUTS:
%    (i) func = string giving name of function (mapping real # to real #)
%               to be integrated
%   (ii) param = parameter vector that is an argument for 'func'.m.  If 
%               no parameters required, set param= 0 here and in 'func'.
%    (i) a = a real number, beginning of range of integration
%   (ii) b = a real number, end of range of integration
%  (iii) N = integer, number of segments between a and b
%   (iv) hmin = width of first segment
%
%  OUTPUT: I = integral of function func(x,param), x in [a,b]
%
deta=1.0/N;
si=abs(b-a);
ck=1.0;
for kk=1:10;
   ek=exp(ck);
   ekde=exp(ck*deta);
   fk=hmin-si*(ekde-1.0)/(ek-1.0);
   fkp=-si*(deta*ekde-(ekde-1.0)*ek/(ek-1.0))/(ek-1.0);
   ck=ck-fk/fkp;
end;
ekm1=exp(ck)-1.0;
x(1)=a;
for kk=2:N;
   x(kk)=a+(b-a)*(exp(ck*deta*kk)-1.0)/ekm1;
end;
I=0;
for kk=1:N-1;
   xx=0.5*(x(kk+1)+x(kk));
   eval(['I=I+abs(x(kk+1)-x(kk))*',func,'(xx,param);']);
end;
