function [err,tim] = driver_fhbvm( fun, MM, last )
%
%  [err,tim] = driver_fhbvm( fun, MM, [, last] )
%
%  Driver for fhbvm for the problem defined by the function fun:
%      fun   = string with the function identifier;
%      MM    = vectors with the M parameters;
%      last  = flag to check the accuracy in the last point only.
%
%  In output:
%      err  = mescd obtained;
%      tim  = elapsed time.
%
last = nargin<3;
disp(['FHBVM on ' fun])
if last
   disp('error check on the whole solution')
else
   disp('error check in the last point')
end   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[alpha,T,y0] = feval(fun);
y0  = y0;
lh  = length(MM);
err = zeros(lh,1);
tim = err;
for i = 1:lh
    [t,y,stats]  = fhbvm( fun, y0, T, MM(i) );
    tim(i) = sum(stats);
    if last
        yt = feval(fun,t);
    else
        yt = feval(fun,T);
        y  = y(end,:);
    end
    err(i) = mescd(y,yt);
end
eval(sprintf(['save ' fun '_fhbvm err tim MM']))
return