% Wet Cable Pumpdown
% 50 kapton cables (no PFA cables)
% DB25, twisted, overall shielded, with a PEEK overbraid
% not cleaned, not baked
close all;
clear all;

% Initial pumpdown with RGA
filename='wet_cable_pumpdown_7-3-12_23pm.txt';
nhead=25;
fid = fopen(filename);
celldata = textscan(fid,'%f, %f, %f,','headerlines',nhead);
[t1,pN1,pW1] = celldata{:,:,:};
t1=t1/3600+90.2458;
fclose(fid);

filename='wet_cable_pumpdown_7-16-3-08pm.txt';
nhead=25;
fid = fopen(filename);
celldata = textscan(fid,'%f, %f, %f,','headerlines',nhead);
[t2,pN2,pW2] = celldata{:,:,:};
t2=t2/3600+261.7772;
fclose(fid);

filename='wet_cable_pumpdown_7-17_3-29pm.txt';
nhead=25;
fid = fopen(filename);
celldata = textscan(fid,'%f, %f, %f,','headerlines',nhead);
[t3,pN3,pW3] = celldata{:,:,:};
t3=t3/3600+576.2199;
fclose(fid);

% plot data
loglog(t1,pN1,'color',[.8 .8 .8],'LineWidth',2);
hold on;
loglog(t2,pN2,'color',[.8 .8 .8],'LineWidth',2);
loglog(t3,pN3,'color',[.8 .8 .8],'LineWidth',2);
loglog(t1,pW1,'-g','LineWidth',2);
loglog(t2,pW2,'-g','LineWidth',2);
loglog(t3,pW3,'-g','LineWidth',2);
axis([100 1000 1e-8 1e-4])
xlabel('Time [hr]','FontWeight','bold')
ylabel('Partial Pressure [Torr]','FontWeight','bold')
grid
title('\fontsize{16}WET CABLE PUMPDOWN',...
      'FontWeight','bold')
set(gcf,'color',[0.8 1 0.8]);

% power law fit 1
log10t1=log10(t1);
log10pW1=log10(pW1);
[p,S]=polyfit(log10t1,log10pW1,1);
f1=polyval(p,log10t1,S);
loglog(t1,10.^f1,'-r');
p(1)

t2start=t2(length(t2))-3*24;
x=find(t2>t2start);
tf2=t2(x);
log10tf2=log10(tf2);
pWf2=pW2(x);
log10pWf2=log10(pWf2);
[p2,S2]=polyfit(log10tf2,log10pWf2,1);
f2=polyval(p2,log10tf2,S2);
loglog(tf2,10.^f2,'-r');
p2(1)
legend('N2 (AMU28) RT','N2 (AMU28) RT','N2 (AMU28), 53C ~16 hrs','H2O (AMU18)', ...
    'H2O (AMU18)','H2O (AMU18), 53C ~16 hrs','fit 7 days > 90hrs, slope = -1.42',...
    'fit 3 days > 466 hrs, slope = -1.54')


