function [x, times] = integrator(deriv,d,N,dt,inicond)
%
% function [x, times] = Integrator(stepkind,deriv,d,N,dt,inicond);
%
% @deriv: specifies the script of the derivative, e.g. @LorenzODE_B
% d: dimension
% N: Number of datapoints
% dt: time step
% inicond: initial conditions
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% SETTING OF INTEGRATION-TIME AND -STEP %%%
%%% SETTING OF INITIAL CONDITIONS %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
times = [0:dt:(N-1)*dt];
x = zeros(length(times),d);
x(1,:) = inicond;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% ACTUAL CALL OF INTEGRATER %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
j = 1;
for steps=times(1:length(times)-1);
j = j +1;
k1 = dt*feval(deriv,x(j-1,:))';
k2 = dt*feval(deriv,x(j-1,:)+k1/2)';
k3 = dt*feval(deriv,x(j-1,:)+k2/2)';
k4 = dt*feval(deriv,x(j-1,:)+k3)';
x(j,:) = x(j-1,:) + k1/6+k2/3+k3/3+k4/6;
end