%**************************************************************************
%This function plots B and Int_B_dz vs Z at the exit.
%
%Input:
%plt_file, plot file for results
%b_name, 'Bx' or 'By'
%z, z positions the field was measured at (m)
%b, measured field strength (T)
%int_b_dz, first integral of the field (Tm)
%z_dev_exit, device exit z position (m)
%z_field_end, z position where the fringe field stops at the exit end (m)
%
%Zachary Wolf
%8/5/11

function [] = field_plot_fringe_exit(plt_file, b_name, z, b, int_b_dz, z_dev_exit, z_field_end)

%Check
if (z_field_end <= z_dev_exit)
    return;
end

%Determine quantities to plot
index_array = find(z > (z_dev_exit - .05));
z_exit = z(index_array);
b_exit = b(index_array);
int_b_dz_exit = int_b_dz(index_array);

%Plot the field
figure;
subplot(2, 1, 1);
hold on;
plot(z_exit, b_exit, 'linewidth', 0.5);
title([b_name, ' And Field Integral At The Exit']);
%title([b_name, ' vs Z']);
ylabel([b_name, ' (T)']);
grid on;
zoom on;

%Draw a line at the device exit
y_lim = ylim;
line([z_dev_exit, z_dev_exit], y_lim, 'Color', 'r', 'LineStyle', '--');

%Plot a point at the fringe limit
index_array = find(z < z_field_end);
b_field_end = b(index_array(end));
plot(z_field_end, b_field_end, 'r*');

%Plot the first field integral
subplot(2, 1, 2);
hold on;
plot(z_exit, int_b_dz_exit, 'linewidth', 0.5);
%title(['\int ', b_name, ' dz vs Z']);
ylabel(['\int ', b_name, ' dz (Tm)']);
xlabel('Z (m)');
grid on;
zoom on;

%Draw a line at the device exit
y_lim = ylim;
line([z_dev_exit, z_dev_exit], y_lim, 'Color', 'r', 'LineStyle', '--');

%Plot at point at the fringe limit
index_array = find(z < z_field_end);
int_b_dz_field_end = int_b_dz(index_array(end));
plot(z_field_end, int_b_dz_field_end, 'r*');

%Print
util_print_fig(plt_file);

%Done
