%**************************************************************************
%This function plots the measured and desired undulator field and the
%difference between the two.
%
%Input:
%plt_file, plot file for results
%param, structure containing analysis parameters
%z_peak_no_ends, position of field peaks, no ends (m)
%phasechange_peak_no_ends, desired phase change at the field peaks, no ends (rad)
%phasechange_fit_peak_no_ends, fitted desired phase change at the field peaks, no ends (rad)
%dphasechange_dz_fit_peak_no_ends, slope of the fitted desired phase change at the field peaks, no ends (rad / m) 
%
%Zachary Wolf, 11/18/06

function [] = setgap_plot_shim_phaserr(plt_file, param, z_peak_no_ends, phasechange_peak_no_ends, phasechange_fit_peak_no_ends, dphasechange_dz_fit_peak_no_ends)

%Plot the desired phase changes and the fit
if param.fig_vis == false
    figure('visible', 'off');
else
    figure('visible', 'on');
end
subplot(2, 1, 1);
hold on;
plot(z_peak_no_ends, phasechange_peak_no_ends, 'b*-', 'linewidth', 1);
plot(z_peak_no_ends, phasechange_fit_peak_no_ends, '-r', 'linewidth', 2.0);
legend('Measured', 'Fit', 'location', 'southwest');
title('Set Gap, Required Phase Change And Fit, No Ends');
ylabel('Phase Change (rad)');
util_add_pole_num_to_plot(param);  %Add pole numbers to the plot
grid on;
zoom on;
hold off;

%Plot the slope of the fitted desired phase change
subplot(2, 1, 2);
hold on;
plot(z_peak_no_ends, dphasechange_dz_fit_peak_no_ends, '-r', 'linewidth', 2.0); 
title('Set Gap, Required Phase Change Slope From Fit, No Ends');
ylabel('Phase Change Slope (rad / m)');
xlabel('Z Position (m)');
util_add_pole_num_to_plot(param);  %Add pole numbers to the plot
grid on;
zoom on;
hold off;

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

%Done
