function Plot_Test_Coil(Run_Number)
% Plot_Test_Coil analyzes the Run Number data and plots it.
%
%  Run_number, the run number to be plotted
%  dx is the amount the gap is moved.
% 
% Input: Runs are the run numbers to be summerized. 



   Gap_Int = Load_gap_int_plt(Run_Number);
   Temp =  Load_tstpar_small_coil(Run_Number);
    
% Temperature normalization multiplier for magnet blocks
 Temp_norm = ((([Temp.Jaw] - [Temp.Jaw(1)])*-0.0011)+1);

 
 % Correcting for the different temperatures at the different integal
 % measurements using difference in gap change corrected data

c=1;
for i=1:2:length(Gap_Int.corr_Integral)
    Gap_Int.Int_Gap_Temp_Corr(i) =  abs(Gap_Int.corr_Integral(i)*Temp_norm(c));
    Gap_Int.Int_Gap_Temp_Corr(i+1) =  abs(Gap_Int.corr_Integral(i+1)*Temp_norm(c)); 
    Gap_Int.Int_Temp_Corr(i) =  abs(Gap_Int.Gap_Integral(i)*Temp_norm(c));
    Gap_Int.Int_Temp_Corr(i+1) =  abs(Gap_Int.Gap_Integral(i+1)*Temp_norm(c)); 
        c = c+1;
        Temp_time(c) = Gap_Int.Time(i);       
end

Gap_Int.Int_Gap_Temp_Corr_mean = mean(Gap_Int.Int_Gap_Temp_Corr);
Gap_Int.Int_Gap_Temp_Corr_error = std(Gap_Int.Int_Gap_Temp_Corr)/mean(Gap_Int.Int_Gap_Temp_Corr);

figure
plot_with_mean_std(Gap_Int.Time/60, abs(Gap_Int.corr_Integral),'Time','(Hours)','Intgrated Voltage','(V)')
title(['Run ', num2str(Run_Number), ' Test Flex Board Gap Integral vs Time']);
hline(mean(Gap_Int.corr_Integral) + 2.5*std(Gap_Int.corr_Integral),'k--', 'mean + 2.5*std');
hline(mean(Gap_Int.corr_Integral) - 2.5*std(Gap_Int.corr_Integral),'k--','mean - 2.5*std');
%text((Gap_Int.Time(end)/60)/3,  mean(abs(Gap_Int.corr_Integral)) + 2.5*std(corr_Integral) ,['2*STD/Mean = ', num2str(Gap_Int.corr_error_no_flyer)]);


figure
plot(Gap_Int.Time/60, Gap_Int.Int_Gap_Temp_Corr, 'bo');
hold
plot(Gap_Int.Time/60, abs(Gap_Int.corr_Integral), 'r*');
plot(Gap_Int.Time/60, abs(Gap_Int.Gap_Integral), 'kd');
hline(mean(Gap_Int.Int_Gap_Temp_Corr),'k', ['mean = ', num2str(mean(abs(Gap_Int.Int_Gap_Temp_Corr)))]);
hline(mean(Gap_Int.Int_Gap_Temp_Corr) + mean(Gap_Int.Int_Gap_Temp_Corr)*0.0003 ,'k--', 'mean + mean*0.0003');
hline(mean(Gap_Int.Int_Gap_Temp_Corr) - mean(Gap_Int.Int_Gap_Temp_Corr)*0.0003,'k--','mean - mean*0.0003');
xlabel({'Time','(Hours)'});
ylabel({'Intgrated Voltage','(V)'})
title({['Run ',num2str(Run_Number), ' Test Flex Board Gap Integral vs. Time'], 'Temp Corrected'});
text((Gap_Int.Time(end)/60)/50, mean(Gap_Int.Int_Gap_Temp_Corr) - mean(Gap_Int.Int_Gap_Temp_Corr)*0.0004 ,['2*STD/Mean = ', num2str(2*std(Gap_Int.Int_Gap_Temp_Corr)/ mean(Gap_Int.Int_Gap_Temp_Corr))]);
legend('Gap Integral Gap and Temp corrected', 'Gap Integral Gap corrected', 'Gap Integral no correction');

% figure
% plot(Temp_time(1:end-1)/60, Temp_norm, 'bo');
% xlabel({'Time','(Hours)'});
% ylabel({'Temperature Correction'})
% title({['Run ',num2str(Run_Number), ' Jaw Temperature Correction Factor vs. Time']});


 % Output GI structure with run number to workspace
      Run_name = strcat('GI_run',num2str(Run_Number));
      assignin('base', Run_name, Gap_Int);
