close all
clear all

L0 = 460;  %cm

files = dir('*.bnc');

Tension = [];
Xhead = [];
Date = [];
Time = [];

for i = 2:length(files)
   [date{i} time{i} tension{i} xhead{i}] = textread(files(i).name,'%s %s %*f %*d %*d %f %f %*f %*f %*f %*f %*f %*s'); 
    
   Tension = [Tension ; tension{i}];
   Xhead = [Xhead ; xhead{i}];
   Date = [Date ; date{i}];
   Time = [Time ; time{i}];

end

datenumber = datenum(strcat(Date,Time),'dd-mmm-yyyyHH:MM:SS.FFF');

figure('Position',[ 1000         589        1366         909],'PaperPositionMode','manual','PaperOrientation','portrait','PaperType','usletter','PaperPosition',[0 0 8.5 11]);
ah1 = subplot(3,1,1)
plot(datenumber,Xhead,'-');
xlabel('time');
ylabel('Cross-Head Position (in)');
datetick('x','dd-mmm HH:MM','keepticks');
ah2 = subplot(3,1,2)
plot(datenumber,Tension,'-');
xlabel('time');
ylabel('Tension (lbs)');
datetick('x','dd-mmm HH:MM','keepticks');

ah3 = subplot(3,1,3)
plot(Xhead,Tension,'-');
xlabel('Cross-Head Position (in)');
ylabel('Tension (lbs)');

linkaxes([ah1 ah2],'x');

print('-dpdf','CyclicElongationAndTension');


Flange = Xhead*2.54+472;

Strain = (Flange-L0)/L0;

figure
plot(Xhead,Tension)

figure
plot(Strain,Tension);




for i = 2:length(files)
  flange = xhead{i}*2.54+472;
  strain{i} = (flange-L0)/L0;
  hold all
end

figure('Position',[1000 596 1392 902]);
k = 1;
for i = 1+[2 1 3];  %Adjust plot porder  
  plot(strain{i},tension{i})
  leg_str{k} = files(i).name; k = k+1;
  hold all
end
title('Tension Versus Strain, Overall Assembly')
legend(leg_str,'Location','NorthWest');


a = 1.95;
clear strain;
for i = [2 3 4]
  flange = xhead{i}*2.54+472;
  strain{i} = (flange-L0)/L0;
  strain{i} = strain{i}/(1-1.2*4*a/(3*(L0/100)));
end

figure('Position',[1000 596 1392 902]);
k = 1;
for i = 1+[2 1 3];  %Adjust plot porder  
  plot(strain{i},tension{i})
  leg_str{k} = files(i).name; k = k+1;
  hold all
end
title('Tension Versus Strain, Compliant Section')
legend(leg_str,'Location','NorthWest');

