function [x, times] = IntegratorNetnoise(stepkind,deriv,N,dt,inicond, a1,eps,noise)
%
% function [x, times] = Integrator(stepkind,deriv,d,N,dt,inicond);
% Integration of ODEs using either Runge-Kutta (stepkind=0) or Euler (stepkind=1).
%
%deriv: @deriv the ODE of coupled Lorenz attractors
%N: number of nodes
%dt: time step
%inicond: initial conditions
%a1: rho value of the Lorenz attractor.
%eps: Matrix of the coupling strength
%noise: amplitude of the Gaussian noise
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% SETTING OF INTEGRATION-TIME AND -STEP %%%
%%% SETTING OF INITIAL CONDITIONS %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d = length(inicond);
times = [0:dt:(N-1)*dt];
x = zeros(length(times),d);
x(1,:) = inicond;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% ACTUAL CALL OF INTEGRATER %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if stepkind == 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% ITERATIVE CALL OF EULER STEPS %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
j = 1;
for steps=times(1:length(times)-1)
j = j +1;
x(j,:) = x(j-1,:) + dt*feval(deriv,x(j-1,:), a1,eps)'+randn(1,d).*noise;
end
else
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% ITERATIVE CALL OF RUNGE KUTTA STEPS %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
j = 1;
for steps=times(1:length(times)-1)
j = j +1;
k1 = dt*feval(deriv,x(j-1,:), a1,eps)';
k2 = dt*feval(deriv,x(j-1,:)+k1/2, a1,eps)';
k3 = dt*feval(deriv,x(j-1,:)+k2/2, a1,eps)';
k4 = dt*feval(deriv,x(j-1,:)+k3, a1,eps)';
x(j,:) = x(j-1,:) + k1/6+k2/3+k3/3+k4/6 + randn(1,d).*noise;
end
end
%%%%%%%%%%%%%%%%%%%%%%%