clear all
close all


%directory = '../DockingMooring_10/Results_d75_c.75_w0_Hs0_Tp0';
path = '../DockingMooring_13/';
directory = 'Results_d75_c.75_w7.5_Hs4_Tp8';

env = LoadEnvironment([path directory]);
MooringRiser = LoadCableResults([path directory],'Mooring');
Buoy = LoadRigidBodyResults([path directory],'Buoy');
WindAndWater = LoadWindAndWaterConditions([path directory]);


MooringRiserResults = ParseCableResults(MooringRiser);
BuoyResults = ParseRigidBodyResults(Buoy);

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);

lh = plot(MooringRiserResults.MeanX',-MooringRiserResults.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);
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);
%plot((MooringRiserResults.Unstretched_Node_s(:,end)-MooringRiserResults.Unstretched_Node_s(2:end))',MooringRiser.tensions(:,2:end));

set(gca,'ColorOrderIndex',1);
grid on
xlabel('Distance from Anchor along unstreteched mooring (m)')
ylabel('Tension (lbs)');
title('Mooring Tension Snapshots');

ah5 = subplot(3,7,[6 7]);
plot(BuoyResults.t,39.4*BuoyResults.FreeBoard);
legend('Dist. Above Water (Buoy Center)');
xlabel('time (s)');
ylabel('(in)');
grid on
title('Freeboard');

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

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

print([path directory '/' directory '_Summary.pdf'],'-dpdf'); %,'-landscape');

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


