clear all
close all

StaticPath = 'StaticResults/';

Depths =       [200 150 100 50];
PolyLengths =  [185 135 85 35];


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

CurrentFactors = .1:.2:1.7;

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

depthstr = '50m';

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

for j = 1:length(CurrentFactors);

for m = 4 %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 = 1;
  ENV.dynamiclambda = -.5;

  ENV.currentscale = CurrentFactors(j);

  LAYOUT.em_length = 21;
  LAYOUT.poly_nodespace = .5;  %meters per node
  LAYOUT.poly_length = PolyLengths(m);

  LAYOUT.shockle_length = 3;
  LAYOUT.shockle_nodespace = 0.5; %meters per node

  filename = [StaticPath make_filename(ENV,LAYOUT)]
 
  
  load([filename '.mat']);
  
  figure(fh1);
  plot(x,z-ENV.depth); 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);
  
  AnchorForceHoriz(j) = T(1)*sin(phi(1));
  AnchorForceVert(j) = T(1)*cos(phi(1));

  
 

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),2) ' m/s'], ...
       ['current = ' num2str(CurrentFactors(2),2) ' m/s'], ...
       ['current = ' num2str(CurrentFactors(3),2) ' m/s'], ...
       ['current = ' num2str(CurrentFactors(4),2) ' m/s'], ...
       ['current = ' num2str(CurrentFactors(5),2) ' m/s'], ...
       ['current = ' num2str(CurrentFactors(6),2) ' m/s'], ...
       ['current = ' num2str(CurrentFactors(7),2) ' m/s'], ...
       ['current = ' num2str(CurrentFactors(8),2) ' m/s'], ...
       ['current = ' num2str(CurrentFactors(9),2) ' m/s'], ...
        'Location','SouthEast');
title([LAYOUT.title ' Mooring Positions in Constant Current Profile']);   
%title([LAYOUT.title ' Mooring Positions in Linear Current Profile']);   
print('-dpdf',[depthstr '_MooringPositions_SlabCurrent']);

figure('Position',[520   173   766   925],'PaperOrientation','portrait','PaperPosition',[0 0 8.5 11]);
subplot(3,1,1)
plot(CurrentFactors,shockle_length)
xlabel('Current (m/s)');
ylabel('Shockle Length (meters)');
title([LAYOUT.title ' Shockle Behavior in Constant Current Profile']);   
%title([LAYOUT.title ' Shockle Behavior in Linear Current Profile']);   
subplot(3,1,2)
plot(CurrentFactors,shockle_tension)
xlabel('Current (m/s)');
ylabel('Mean Shockle Tension (lbs)');
subplot(3,1,3)
plot(CurrentFactors,shockle_angle)
xlabel('Current (m/s)');
ylabel('Mean Shockle Angle From Vertical (degrees)');
print('-dpdf',[depthstr '_ShockleBehavior_SlabCurrent']);

figure('Position',[520   173   766   925],'PaperOrientation','portrait','PaperPosition',[0 0 8.5 11]);
subplot(4,1,1)
plot(CurrentFactors,ESP_angle,CurrentFactors,Bail_angle)
xlabel('Current (m/s)');
ylabel('Angle From Vertical (degrees)');
legend('ESP Angle','Bail Angle','Location','NorthWest');
title([LAYOUT.title ' Constant Current Profile']);   
%title([LAYOUT.title ' Linear Current Profile']);   

subplot(4,1,2)
plot(CurrentFactors,Buoy_freeboard)
xlabel('Current (m/s)');
ylabel('Buoy Freeboard (m)');

subplot(4,1,3)
plot(CurrentFactors,ESP_Depth)
xlabel('Current (m/s)');
ylabel('Depth of top of ESP (m)');

subplot(4,1,4)
plot(CurrentFactors,AnchorForceVert,CurrentFactors,AnchorForceHoriz)
xlabel('Current (m/s)');
ylabel('Force on Anchor (lbs)');
legend('Vertical Force','Horizontal Force','Location','NorthWest');


print('-dpdf',[depthstr '_ElementPositioning_SlabCurrent']);

