%**************************************************************************
%This function plots By vs z along a line whose x position and y position
%are specified.  The closest x and y positions with data points are used.
%
%Input:
%plt_file, plot file for results
%block, structure containing the block information
%charge, structure containing the magnetic charge information
%mag_field, structure containing the magnetic field information
%x_val_req, requested x position of line to plot By along (m)
%y_val_req, requested y position of line to plot By along (m)
%
%Zachary Wolf, 3/31/08

function ppm_plot_by_vs_z(plt_file, block, charge, mag_field, x_val_req, y_val_req)

%Initialize
figure;
hold on;

%Mark the blocks
for ii = 1 : block.num_block
    plot(block.z_center(ii) - block.z_width(ii) / 2, 0, 'r+');
    plot(block.z_center(ii) + block.z_width(ii) / 2, 0, 'r+');
end

%Plot the field
[x_close, ix_close] = min(abs(mag_field.x - x_val_req));
x_val = mag_field.x(ix_close(1));
[y_close, iy_close] = min(abs(mag_field.y - y_val_req));
y_val = mag_field.y(iy_close(1));
index_array = find((mag_field.x == x_val) & (mag_field.y == y_val) == 1);
plot(mag_field.z(index_array), mag_field.by(index_array));

%Labels
title(['By vs Z On Line At X = ', num2str(x_val), ' m, Y = ', num2str(y_val), ' m']);
xlabel('Z (m)');
ylabel('By (T)');

%Finalize
grid on;
zoom on;
hold off;

%Print
orient landscape;
print('-append', '-dpsc', plt_file);

%Done
