%**************************************************************************
%This function plots the magnetic field in the y-z plane whose x position
%is specified.  The closest x position with data points is 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 slice (m)
%
%Zachary Wolf, 3/31/08

function pm_plot_b_on_x_slice(plt_file, block, charge, mag_field, x_val_req)

%Initialize
figure;
hold on;

%Draw the projection of the blocks
for ii = 1 : block.num_block
    line([block.z_center(ii) - block.z_width(ii) / 2, block.z_center(ii) + block.z_width(ii) / 2],...
        [block.y_center(ii) + block.y_width(ii) / 2, block.y_center(ii) + block.y_width(ii) / 2]);  %Top
    line([block.z_center(ii) - block.z_width(ii) / 2, block.z_center(ii) + block.z_width(ii) / 2],...
        [block.y_center(ii) - block.y_width(ii) / 2, block.y_center(ii) - block.y_width(ii) / 2]);  %Bottom
    line([block.z_center(ii) - block.z_width(ii) / 2, block.z_center(ii) - block.z_width(ii) / 2],...
        [block.y_center(ii) - block.y_width(ii) / 2, block.y_center(ii) + block.y_width(ii) / 2]);  %Left
    line([block.z_center(ii) + block.z_width(ii) / 2, block.z_center(ii) + block.z_width(ii) / 2],...
        [block.y_center(ii) - block.y_width(ii) / 2, block.y_center(ii) + block.y_width(ii) / 2]);  %Right
end

%Draw the projection of the charges
index_array = find(charge.q > 0);
plot(charge.z(index_array), charge.y(index_array), 'r+');
index_array = find(charge.q < 0);
plot(charge.z(index_array), charge.y(index_array), 'kx');

%Plot the field
[x_close, ix_close] = min(abs(mag_field.x - x_val_req));
x_val = mag_field.x(ix_close(1));
index_array = find(mag_field.x == x_val);
quiver(mag_field.z(index_array), mag_field.y(index_array), mag_field.bz(index_array), mag_field.by(index_array));

%Labels
title(['Magnetic Field On Slice At X = ', num2str(x_val), ' m']);
xlabel('Z Position (m)');
ylabel('Y Position (m)');

%Finalize
grid on;
zoom on;
hold off;

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

%Done
