%**************************************************************************
%This function plots the integral of the y component of the magnetic field
%as a function of z along a line whose x and y positions are specified.
%
%Input:
%plt_file, plot file for results
%block, structure containing the block information
%charge, structure containing the magnetic charge information
%x_val, x position of the integral (m)
%y_val, y position of the integral (m)
%z, position along the integral (m)
%int_by_dz, cumulative integral of By along z (Tm)
%
%Zachary Wolf, 2/7/11

function virtual_shim_plot_intbydz_vs_z(plt_file, block, charge, x_val, y_val, z, int_by_dz)

%Initialize
figure;
hold on;

%Mark the block positions
for ii = 1 : length(block)
    p1 = [- block(ii).dim(1) / 2,   block(ii).dim(2) / 2,   block(ii).dim(3) / 2];
    p2 = [  block(ii).dim(1) / 2,   block(ii).dim(2) / 2,   block(ii).dim(3) / 2];
    p3 = [- block(ii).dim(1) / 2, - block(ii).dim(2) / 2,   block(ii).dim(3) / 2];
    p4 = [  block(ii).dim(1) / 2, - block(ii).dim(2) / 2,   block(ii).dim(3) / 2];
    p5 = [- block(ii).dim(1) / 2,   block(ii).dim(2) / 2, - block(ii).dim(3) / 2];
    p6 = [  block(ii).dim(1) / 2,   block(ii).dim(2) / 2, - block(ii).dim(3) / 2];
    p7 = [- block(ii).dim(1) / 2, - block(ii).dim(2) / 2, - block(ii).dim(3) / 2];
    p8 = [  block(ii).dim(1) / 2, - block(ii).dim(2) / 2, - block(ii).dim(3) / 2];
    p1g = p1 * block(ii).rot + block(ii).trans;
    p2g = p2 * block(ii).rot + block(ii).trans;
    p3g = p3 * block(ii).rot + block(ii).trans;
    p4g = p4 * block(ii).rot + block(ii).trans;
    p5g = p5 * block(ii).rot + block(ii).trans;
    p6g = p6 * block(ii).rot + block(ii).trans;
    p7g = p7 * block(ii).rot + block(ii).trans;
    p8g = p8 * block(ii).rot + block(ii).trans;
    z_max = max([p1g(3), p2g(3), p3g(3), p4g(3), p5g(3), p6g(3), p7g(3), p8g(3)]);
    z_min = min([p1g(3), p2g(3), p3g(3), p4g(3), p5g(3), p6g(3), p7g(3), p8g(3)]);
    plot(z_min, 0, 'r+');
    plot(z_max, 0, 'r+');
end

%Plot the field integral
plot(z, int_by_dz);

%Labels
title(['Int By dz vs Z At X = ', num2str(x_val), ' m, Y = ', num2str(y_val), ' m']);
xlabel('Z (m)');
ylabel('Int By dz (Tm)');

%Finalize
grid on;
zoom on;
hold off;

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

%Done
