function sasha_int_v(z, vx1, vy1, vz1, vx2, vy2, vz2)

% clear all;
% addpath('C:\Users\abt6\Documents\SLAC Delta\SLAC Delta Prot test, Dec 13 2013\Delta Magnetic Meas Dec 12 2013');
% 
% %Magnetic field data name
% File_Name = 'DUTestOutput_200.dat'   % SPECTRA brilliance file und approximation  
% 
% [ind z vx1 vy1 vz1 vx2 vy2 vz2] = textread(File_Name ,'%f %f %f %f %f %f %f %f','headerlines',31);

dBx_off = 0;
dBy_off = 0;

Offset_Corr = 'true'; 

if Offset_Corr
dBx_off = 0.2*(mean(vx1(1:200))+mean(vx1(23800:24000)))/2
dBy_off = 0.2*(mean(vy1(1:200))+mean(vy1(23800:24000)))/2
end

Bx = 0.2*vx1 - dBx_off; % - mean(vx1(1:200)));
By = 0.2*vy1 - dBy_off; % - mean(vy1(1:100)));
Bz = 0.2*vz1; % - mean(vz1(1:100)));

% Corrector model
% By(1:500) = By(1:500)+ 0.0070;
% Bx(1:500) = Bx(1:500)+ 0.0023;

%n_step = size(z);
n_step = length(z);

I1x(1)=0;
I1y(1)=0;

for i=2:n_step
I1x(i) = I1x(i-1)+Bx(i)*(z(i)-z(i-1));
I1y(i) = I1y(i-1)+By(i)*(z(i)-z(i-1));
end
I1x_Tm = I1x(n_step);
I1y_Tm = I1y(n_step);

I2x(1)=0;
I2y(1)=0;
for i=2:n_step
I2x(i) = I2x(i-1)+I1x(i)*(z(i)-z(i-1));    
I2y(i) = I2y(i-1)+I1y(i)*(z(i)-z(i-1));
end
I2x_Tm2 = I2x(n_step);
I2y_Tm2 = I2y(n_step);

figure; 
plot(z, Bx,'b', z-0.002, By,'r');
axis([0 1.2 -1.25 1.25])
legend ('Bx','By'); 

figure; 
plot(z,I2x*1e6,'b', z-0.002, I2y*1e6, 'r');
axis([0 1.2 -125 125])
legend ('I2x [microT-m^2]','I2y [microT-m^2]'); 


I1x_microTm = I1x_Tm*1e6;
I2x_microTm2 = I2x_Tm2*1e6;

I1y_microTm = I1y_Tm*1e6;
I2y_microTm2 = I2y_Tm2*1e6;

Int_x_y = [I1x_microTm I2x_microTm2 I1y_microTm I2y_microTm2]
end

