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

function [] = field_plot_peak_spacing(plt_file, param, z_peak_no_ends)

%Simplify the notation
z_peak = z_peak_no_ends;

%Find the distance between the field peaks
delta_z_peak = diff(z_peak);
center_z_peak = z_peak(1:length(z_peak)-1) + delta_z_peak/2.;

%Find the average and rms variation of the distance between the peak fields
delta_z_peak_ave = mean(delta_z_peak);
delta_z_peak_rms = std(delta_z_peak);

%Plot the spacing between the field peaks
%Indicate the average and rms values
if param.fig_vis == false
    figure('visible', 'off');
else
    figure('visible', 'on');
end
plot(center_z_peak, delta_z_peak, '-b*', 'linewidth', .25);
title('Fitted Peak Field Spacing vs Z, Excluding Ends');
xlabel('Z Position (m)');
ylabel('Peak Field Spacing (m)');
xlimits = xlim;
ylimits = ylim;
line(xlimits, [delta_z_peak_ave, delta_z_peak_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('Peak Field Spacing: Ave = %f m, RMS = %f m', delta_z_peak_ave, delta_z_peak_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
