clear all
close all

StaticPath = 'StaticResults/1d2_Poly/';

Depths =         [199.5];
PolyLengths =  [186];


WaveHeights = [2];
WaveAmps = WaveHeights/2;
WavePers = [10];

CurrentFactors = .3:.2:1.3;

fh1 = figure('Position',[520   173   766   925],'PaperOrientation','portrait','PaperPosition',[0 0 8.5 11]);



for i = length(WaveAmps):-1:1

for j = 1:length(CurrentFactors);

for m = 1:length(Depths)

  
  ENV.depth = Depths(m);
  ENV.tf = 200; 
  ENV.tf = 0; 
  ENV.dt = .1;
  ENV.ramptime = 30;
  ENV.xwaveamp = WaveAmps(i);
  ENV.xwaveperiod = WavePers(i);
  ENV.xwavephase = 0;
  ENV.xwind = 5;
  ENV.dynamiclambda = -.5;

  ENV.currentscale = CurrentFactors(j);

  LAYOUT.em_length = 15;
  LAYOUT.poly_nodespace = .5;  %meters per node
  LAYOUT.poly_length = PolyLengths(m);
  LAYOUT.em_length = 15;
  LAYOUT.shockle_length = 3;
  LAYOUT.shockle_nodespace = 0.5; %meters per node
 
  ENV.xcurrent = NaN(2,2);
  
  filename = [StaticPath make_filename(ENV,LAYOUT)]
 
  
  load([filename '.mat']);
  
  figure(fh1);
  plot(x,z); hold all;

  idx = find(strcmp(seg_name,'shockle_lockout'));
  last = seg_nodes(idx);
  first = last - seg_n_nodes(idx) + 1;
  shockle_length(j) = sqrt((x(last)-x(first)).^2+(z(last)-z(first)).^2);
  shockle_tension(j) = mean(T(first:last));
  shockle_angle(j) = mean(phi(first:last)*180/pi);
  
  idx = find(strcmp(seg_name,'BatteryCase'));
  last = seg_nodes(idx);
  first = last - seg_n_nodes(idx) + 1;
  ESP_angle(j) = mean(phi(first:last)*180/pi);
  
  ESP_Depth(j) = depth-z(last)-.84*cos(phi(last));
 
  
  idx = find(strcmp(seg_name,'Bail'));
  last = seg_nodes(idx);
  first = last - seg_n_nodes(idx) + 1;
  Bail_angle(j) = mean(phi(first:last)*180/pi);
  
  Buoy_draft(j) = depth-z(end);
  Buoy_freeboard(j) = 1.75-Buoy_draft(j);
  
  
  
 

end   %End of m-loop (Mooring Depths)

end   %End of j-loop (current factors)

end   %End of i-loop (sea state)

figure(fh1)
axis equal
xlabel('meters');
ylabel('meters');
legend(['current = ' num2str(CurrentFactors(1)/.515,2) ' kts'], ...
       ['current = ' num2str(CurrentFactors(2)/.515,2) ' kts'], ...
       ['current = ' num2str(CurrentFactors(3)/.515,2) ' kts'], ...
       ['current = ' num2str(CurrentFactors(4)/.515,2) ' kts'], ...
       ['current = ' num2str(CurrentFactors(5)/.515,2) ' kts'], ...
       ['current = ' num2str(CurrentFactors(6)/.515,2) ' kts'], ...
        'Location','SouthEast');
title('Mooring Positions in Slab Currents, 7/8" Polyester Rope');
%print('-dpdf','200m_MooringPositions_SlabCurrent_7d8Poly');

figure('Position',[520   173   766   925],'PaperOrientation','portrait','PaperPosition',[0 0 8.5 11]);
subplot(3,1,1)
plot(CurrentFactors/.515,shockle_length)
xlabel('Current (kts)');
ylabel('Shockle Length (meters)');
title('Shockle Behavior');
subplot(3,1,2)
plot(CurrentFactors/.515,shockle_tension)
xlabel('Current (kts)');
ylabel('Mean Shockle Tension (lbs)');
subplot(3,1,3)
plot(CurrentFactors/.515,shockle_angle)
xlabel('Current (kts)');
ylabel('Mean Shockle Angle From Vertical (degrees)');
%print('-dpdf','200m_ShockleBehavior');

figure('Position',[520   173   766   925],'PaperOrientation','portrait','PaperPosition',[0 0 8.5 11]);
subplot(3,1,1)
plot(CurrentFactors/.515,ESP_angle,CurrentFactors/.515,Bail_angle)
xlabel('Current (kts)');
ylabel('Angle From Vertical (degrees)');
legend('ESP Angle','Bail Angle');

subplot(3,1,2)
plot(CurrentFactors/.515,Buoy_freeboard)
xlabel('Current (kts)');
ylabel('Buoy Freeboard (m)');

subplot(3,1,3)
plot(CurrentFactors/.515,ESP_Depth)
xlabel('Current (kts)');
ylabel('Depth of top of ESP (m)');
%print('-dpdf','200m_ElementPositioning');

save('1d2Results.mat','CurrentFactors','Buoy_freeboard','ESP_Depth');

