clear all
close all

basedir = ['../HamiltonRuns/ASIS_Mooring_80_d25/'];


Tp = 10;
curr = [80];
depth = 25;
wind = 0;
Hs = [4];
Tp = 16;

for i = 1:length(curr)
  for j = 1:length(Hs)
     directory = [basedir 'Results' MakeFileNameDescriptor(curr(i), depth, wind, Hs(j), Tp) '_wvh180/']
 
env = LoadEnvironment(directory);
MooringRiser = LoadCableResults(directory,'Mooring');
HoseTether = LoadCableResults(directory,'Tether');
ASIS_BUOY = LoadRigidBodyResults(directory,'ASIS_BUOY');

WindAndWater = LoadWindAndWaterConditions(directory);


MooringRiserResults = ParseCableResults(MooringRiser);
HoseTetherResults = ParseCableResults(HoseTether);

WindAndWaterResults = ParseWindAndWaterResults(WindAndWater,env.WaterDepth);


figure('Position',[  227    441   1569    998],'paperorientation','landscape','papersize',[17 11]);
ah1 = subplot(3,7,[1,8,15]);

lh = plot(WindAndWaterResults.MeanCurrentX,-WindAndWaterResults.CurrentHeights,'k-');
hold all;
set(lh,'linewidth',3);
lh = plot(WindAndWaterResults.MeanWindX/10,WindAndWaterResults.WindHeights,'b-');
set(lh,'linewidth',2);



plot(WindAndWaterResults.CurrentX,-WindAndWaterResults.CurrentHeights)
plot(WindAndWaterResults.WindX/10,WindAndWaterResults.WindHeights)

lh = plot(WindAndWaterResults.MeanCurrentX,-WindAndWaterResults.CurrentHeights,'k-');
set(lh,'linewidth',3);
lh = plot(WindAndWaterResults.MeanWindX/10,WindAndWaterResults.WindHeights,'b-');
set(lh,'linewidth',2);
legend('Mean Water X-Vel','Mean Wind X-Vel (/10)');
xlabel('(m/s)');
ylabel('(m)');
grid on
title('Horiz. Water Speed')

ah2 = subplot(3,7,[2,3,9,10,16,17]);
plot(MooringRiserResults.X',-MooringRiserResults.Z');
hold all
set(gca,'ColorOrderIndex',1);
plot(HoseTetherResults.X',-HoseTetherResults.Z');

lh = plot(MooringRiserResults.MeanX',-MooringRiserResults.MeanZ','-k');
set(lh,'linewidth',3);
lh = plot(HoseTetherResults.MeanX',-HoseTetherResults.MeanZ','-k');
set(lh,'linewidth',3);


xlabel('m');
ylabel('m');
grid on
hold on
title('Mooring Location');

%Match Current ylim to mooring plot
set(ah1,'ylim',get(ah2,'ylim'));


ah3 = subplot(3,7,[4,5])
plot(WindAndWaterResults.t,WindAndWaterResults.SeaHeightAtOrigin);
grid on
xlabel('time (s)');
ylabel('Sea Height at Origin (m)');
title('Sea Height at Origin');

ah4 = subplot(3,7,[11 12])
plot(MooringRiserResults.ElementTensions_s/4.45,100*MooringRiserResults.epsilon);
hold all
plot(HoseTetherResults.ElementTensions_s/4.45,100*HoseTetherResults.epsilon);
grid on
xlabel('Tension (lbs)');
ylabel('Strain (%)');
title('Strain Versus Tension');


ah4 = subplot(3,7,[18 19])

plot((MooringRiserResults.Unstretched_Node_s(:,end)-MooringRiserResults.Unstretched_Node_s)',MooringRiserResults.NodeTensions_s'/4.45);
hold all;
set(gca,'ColorOrderIndex',1);
plot((MooringRiserResults.Unstretched_Node_s(:,end)+HoseTetherResults.Unstretched_Node_s(:,end)-HoseTetherResults.Unstretched_Node_s)',HoseTetherResults.NodeTensions_s'/4.45);
grid on
xlabel('Distance from Anchor along unstreteched mooring (m)')
ylabel('Tension (lbs)');
title('Mooring Tension Snapshots');

ah5 = subplot(3,7,[6 7]);
plot(HoseTetherResults.t,-HoseTetherResults.Node0HorizForce/4.45);
hold all
plot(HoseTetherResults.t,-HoseTetherResults.Node0VertForce/4.45);
legend('Horiz Force','Vert Force');
xlabel('time (s)');
ylabel('(lbs)');
grid on
title('Force on Buoy');

ah6 = subplot(3,7,[13 14]);
plot(HoseTetherResults.t,MooringRiserResults.NodeNHorizForce/4.45);
hold all
plot(HoseTetherResults.t,-MooringRiserResults.NodeNVertForce/4.45);
legend('Horiz Force','Vert Force');
xlabel('time (s)');
ylabel('(lbs)');
grid on
title('Force on Anchor');

print([directory 'ResultsSummary' MakeFileNameDescriptor(curr(i), depth, wind, Hs(j), Tp) '.pdf'],'-landscape');

save([directory 'ResultsSummary.mat'],'-mat7-binary');


  end
end
