%**************************************************************************
%This function plots the spacing between the field zeros.
%
%Input:
%plt_file, plot file for results
%param, structure containing the analysis parameters
%z_zero_no_ends, position of the field zeros, excluding the ends (m)
%
%Zachary Wolf, 10/23/06

function [] = field_plot_zero_spacing(plt_file, param, z_zero_no_ends)

%Simplify the notation
z_zero = z_zero_no_ends;

%Find the distance between the field zeros
delta_z_zero = diff(z_zero);
center_z_zero = z_zero(1:length(z_zero)-1) + delta_z_zero/2.;

%Find the average and rms variation of the distance between the zero fields
delta_z_zero_ave = mean(delta_z_zero);
delta_z_zero_rms = std(delta_z_zero);

%Plot the spacing between the field zeros
%Indicate the average and rms values
if param.fig_vis == false
    figure('visible', 'off');
else
    figure('visible', 'on');
end
plot(center_z_zero, delta_z_zero, '-b*', 'linewidth', .25);
title('Fitted Zero Field Spacing vs Z, Excluding Ends');
xlabel('Z Position (m)');
ylabel('Zero Field Spacing (m)');
xlimits = xlim;
ylimits = ylim;
line(xlimits, [delta_z_zero_ave, delta_z_zero_ave], 'color', 'k');
util_add_pole_num_to_plot(param);  %Add pole numbers to the plot
grid on;
zoom on;

%Add message
msg_pole_spacings = sprintf('Zero Field Spacing: Ave = %f m, RMS = %f m', delta_z_zero_ave, delta_z_zero_rms);
axes('position', [0, 0, 1, 1], 'visible', 'off');
text(0.07, 0.03, msg_pole_spacings, 'horizontalalignment', 'left', 'verticalalignment', 'bottom');

%Write the figures to the plot file
util_print_fig(plt_file);

%Done
