%**************************************************************************
%This function plots the slippage.
%
%Input:
%plt_file, plot file for results
%z, position along the undulator (m)
%slip, slippage (m)
%z_peak, z positions of the field peaks (m)
%
%Zachary Wolf, 6/26/10

function [] = slip_plot_slip_pole(plt_file, z, slip, z_peak)

%Initialize
figure;
hold on;

%Plot the slippage
plot(z, slip, 'linewidth', 2.);

%Labels
title('Slippage');
ylabel('Slippage (m)');
xlabel('Z (m)');

%Add pole numbers
if length(z_peak) > 1
    
    %Set the axes limits to the current values
    axis(axis);

    %Get the locations of the plot x axis (z) tick marks
    z_tick = get(gca, 'xtick');

    %Find the closest pole to each tick position
    for ii = 1 : length(z_tick)
        [z_peak_close, iz_peak_close] = min(abs(z_peak - z_tick(ii)));
        n_pole(ii) = iz_peak_close(1);
    end

    %Get the y axis limits
    y_lim = get(gca, 'ylim');

    %Write the pole numbers above the z positions at the ticks
    for ii = 1 : length(n_pole)
        if (z_tick(ii) >= z_peak(1)) && (z_tick(ii) <= z_peak(end))
            lbl = num2str(n_pole(ii));
            text(z_tick(ii), y_lim(2), lbl, 'horizontalalignment', 'center', 'verticalalignment', 'top', 'color', 'blue');
        end
    end

    %Write a note that the numbers are pole numbers
    text(z_tick(end), y_lim(2), ' Pole', 'horizontalalignment', 'left', 'verticalalignment', 'top', 'color', 'blue');
    
%Finish adding pole numbers
end

%Finalize
grid on;
zoom on;
hold off;

%Print
util_print_fig(plt_file);

%Done
