%**************************************************************************
%This function plots B and Int_B_dz vs Z at the entrance.
%
%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_enter, device entrance z position (m)
%z_field_start, z position where the fringe field starts at the entrance end (m)
%
%Zachary Wolf
%8/5/11

function [] = field_plot_fringe_enter(plt_file, b_name, z, b, int_b_dz, z_dev_enter, z_field_start)

%Check
if (z_field_start >= z_dev_enter)
    return;
end

%Determine quantities to plot
index_array = find(z < (z_dev_enter + .05));
z_enter = z(index_array);
b_enter = b(index_array);
int_b_dz_enter = int_b_dz(index_array);

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

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

%Plot at point at the fringe limit
index_array = find(z > z_field_start);
b_field_start = b(index_array(1));
plot(z_field_start, b_field_start, 'r*');

%Plot the first field integral
subplot(2, 1, 2);
hold on;
plot(z_enter, int_b_dz_enter, '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 entrance
y_lim = ylim;
line([z_dev_enter, z_dev_enter], y_lim, 'Color', 'r', 'LineStyle', '--');

%Plot at point at the fringe limit
index_array = find(z > z_field_start);
int_b_dz_field_start = int_b_dz(index_array(1));
plot(z_field_start, int_b_dz_field_start, 'r*');

%Print
util_print_fig(plt_file);

%Done
