
%Get LBL data
gap_lbl = [7.2, 8, 10, 15, 20, 25, 50, 100, 160] * 1.e-3;  %(m)
i1x_lbl = [-5.3, 7, 5.6, -8.2, -9, -2, 47.1, 72, 79] * 1.e-6;  %(Tm)
i1y_lbl = [-25.2, -27.7, -29.8, -25.3, -22.8, -24.6, -49.7, -69.7, -69.3] * 1.e-6;  %(Tm)
i2x_lbl = [21.9, 61.3, 48.8, 5.6, 2.1, 20.8, 143.9, 186, 197.3] * 1.e-6;  %(Tm**2)
i2y_lbl = [28.7, -62.6, -61.3, -44, -32.3, -27.2, -59.9, -108.3, -118.2] * 1.e-6;  %(Tm**2)

%Fluxgate data
gap_flux = [160, 180] * 1.e-3;  %(m)
i1x_flux = [-2.7172e-05, -3.3008e-05];  %(Tm)
i1y_flux = [-7.1718e-05, -6.6920e-05];  %(Tm)

%Get SLAC data
mat_file = 'C:\Magdata\Long Coil\long_coil_anal.mat';
load(mat_file, 'param', 'header', 'gap', 'x_pos', 'y_pos', 'type', 'integ_ave', 'integ_rms');

%Make output file
plt_file = 'C:\Magdata\Long Coil\long_coil_anal_comp.ps';

%Plot I1x-----
index_array = find(type == 5);
gap_slac = gap(index_array);
i1x_slac = integ_ave(index_array);
i1x_slac_rms = integ_rms(index_array);

%Go to LBL coordinates
i1x_slac = -i1x_slac;

figure;
hold on;
plot(gap_lbl * 1.e3, i1x_lbl * 1.e6, 'b*-', 'linewidth', .5);
plot(gap_slac * 1.e3, i1x_slac * 1.e6, 'r*-', 'linewidth', .5);
plot(gap_flux * 1.e3, i1x_flux * 1.e6, 'k*');
%errorbar(gap_slac * 1.e3, i1x_slac * 1.e6, i1x_slac_rms * 1.e6, 'ro', 'linewidth', .5, 'markeredgecolor', 'r', 'markerfacecolor', 'r');
legend('LBNL', 'SLAC', 'Fluxgate', 'location', 'southeast');
xlim([0, 200]);
ylim([-100, 100]);
title('I1X vs Gap');
xlabel('Gap (mm)');
ylabel('I1X (\muTm)');
grid on;
zoom on;
hold off;
util_print_fig_init(plt_file);

%Plot I1y-----
index_array = find(type == 0);
gap_slac = gap(index_array);
i1y_slac = integ_ave(index_array);
i1y_slac_rms = integ_rms(index_array);

figure;
hold on;
plot(gap_lbl * 1.e3, i1y_lbl * 1.e6, 'b*-', 'linewidth', .5);
plot(gap_slac * 1.e3, i1y_slac * 1.e6, 'r*-', 'linewidth', .5);
plot(gap_flux * 1.e3, i1y_flux * 1.e6, 'k*');
%errorbar(gap_slac * 1.e3, i1y_slac * 1.e6, i1y_slac_rms * 1.e6, 'ro', 'linewidth', .5, 'markeredgecolor', 'r', 'markerfacecolor', 'r');
legend('LBNL', 'SLAC', 'Fluxgate', 'location', 'northeast');
xlim([0, 200]);
ylim([-100, 100]);
title('I1Y vs Gap');
xlabel('Gap (mm)');
ylabel('I1Y (\muTm)');
grid on;
zoom on;
hold off;
util_print_fig_init(plt_file);

%Plot I2x-----
index_array = find(type == 7);
gap_slac = gap(index_array);
i2x_slac = integ_ave(index_array);
i2x_slac_rms = integ_rms(index_array);

%Go to LBL coordinates
i2x_slac = -i2x_slac;

figure;
hold on;
plot(gap_lbl * 1.e3, i2x_lbl * 1.e6, 'b*-', 'linewidth', .5);
plot(gap_slac * 1.e3, i2x_slac * 1.e6, 'r*-', 'linewidth', .5);
%errorbar(gap_slac * 1.e3, i2x_slac * 1.e6, i2x_slac_rms * 1.e6, 'ro', 'linewidth', .5, 'markeredgecolor', 'r', 'markerfacecolor', 'r');
legend('LBNL', 'SLAC', 'location', 'southeast');
xlim([0, 200]);
ylim([-200, 200]);
title('I2X vs Gap');
xlabel('Gap (mm)');
ylabel('I2X (\muTm**2)');
grid on;
zoom on;
hold off;
util_print_fig_init(plt_file);

%Plot I2y-----
index_array = find(type == 2);
gap_slac = gap(index_array);
i2y_slac = integ_ave(index_array);
i2y_slac_rms = integ_rms(index_array);

figure;
hold on;
plot(gap_lbl * 1.e3, i2y_lbl * 1.e6, 'b*-', 'linewidth', .5);
plot(gap_slac * 1.e3, i2y_slac * 1.e6, 'r*-', 'linewidth', .5);
%errorbar(gap_slac * 1.e3, i2y_slac * 1.e6, i2y_slac_rms * 1.e6, 'ro', 'linewidth', .5, 'markeredgecolor', 'r', 'markerfacecolor', 'r');
legend('LBNL', 'SLAC', 'location', 'northeast');
xlim([0, 200]);
ylim([-200, 200]);
title('I2Y vs Gap');
xlabel('Gap (mm)');
ylabel('I2Y (\muTm**2)');
grid on;
zoom on;
hold off;
util_print_fig_init(plt_file);


