function [Xnew, F, FEs, iter, stop] = armijo(Func, Grad, X0, h0, maxit, acc, widx)

%Starting Evaluations
accur=0.5*10^(-acc);
FEs=0;
ll=length(X0);
hstep = h0;
Xold=X0';
stop=0;
iter=0;

while (stop==0)
       iter = iter + 1;
       F = feval(Func, Xold);
       grad_val = feval(Grad, Xold);

       if (widx==1)
               [hstep, FEwolfe] = wolfe(Xold, Func, grad_val, h0, F); 
               FEs = FEs + FEwolfe;
       else
               [hstep, FEswolfe] = swolfe(Xold, Func, Grad, h0, F); 
               FEs = FEs + FEswolfe;             
       end
       
       Xnew = Xold - hstep*grad_val;
       FEs = FEs +2*ll;

       if (norm(F)<=accur)  %norm(F,inf)<=accur)
               stop=1;
       elseif (norm(Xnew-Xold)<=accur)
               stop=2;
       elseif (norm(grad_val)<=accur)  %norm(grad,inf)<=accur)
               stop=3;
       elseif (iter > maxit)     %FEs>=maxit)
               stop=4;
       end

       Xold = Xnew;
end
end



