function [err,tim] = driver_fcoll( fun, gauss, r, NN, last )
%
%  [err,tim] = driver_fcoll( fun, gauss, r, NN, [, last] )
%
%  Driver for fcoll for the problem defined by the function fun:
%      fun   = string with the function identifier;
%      gauss = number of Gauss-Legendre abscissae;
%      r     = parameter of the graded mesh (>=1);
%      NN    = vectors with the N parameters;
%      last  = flag to check the accuracy in the last point only.
%
%  In output:
%      err  = mescd obtained;
%      tim  = elapsed time.
%
last = nargin<5;
disp(['FCOLL on ' fun])
fprintf('%i Gauss-Legendre nodes and r=%g\n',gauss,r)
if last
   disp('error check on the whole solution')
else
   disp('error check in the last point')
end   
if r<1, error('r?'), end
eta = zeros(gauss,1);
if gauss==1
    eta = 0.5;  error('gauss>1')
elseif gauss==2
    eta(1) = (3-sqrt(3))/6; eta(2) = (3+sqrt(3))/6;
elseif gauss==3
    eta(1) = (5-sqrt(15))/10; eta(2) = 0.5; eta(3) = (5+sqrt(15))/10;
elseif gauss==4
    eta(1) = (35-sqrt(525+70*sqrt(30)))/70; 
    eta(4) = (35+sqrt(525+70*sqrt(30)))/70;
    eta(2) = (35-sqrt(525-70*sqrt(30)))/70;
    eta(3) = (35+sqrt(525-70*sqrt(30)))/70;
elseif gauss==5
    eta(1) = (21-sqrt(245+14*sqrt(70)))/42;
    eta(5) = (21+sqrt(245+14*sqrt(70)))/42;
    eta(2) = (21-sqrt(245-14*sqrt(70)))/42;
    eta(4) = (21+sqrt(245-14*sqrt(70)))/42;
    eta(3) = 0.5;
else
    error('gauss?')
end    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f = @(t,y) feval(fun,t,y);
[alpha,T,y0] = feval(fun);
y0  = y0(:);
lh  = length(NN);
err = zeros(lh,1);
tim = err;
for i = 1:lh
    tic
    [t,y]  = fcoll( f, T, y0, alpha, eta, r, NN(i) );
    tim(i) = toc;
    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 '_fcoll-%i-%i err tim NN'],gauss,r))
return