%script for plotting 3d view of bending. A waterfall tyoe view
% First do a bending calculation on the nodes of interest.
% Script for calculating the bending angle per meter for each mooring node
% in selected sections. The section is a continous number of
% nodes_of_interest so that the difference calculation works out.

% Euler angle = phi_t (in Radians)
% Lagrangian coordinate for each node = s
% Degrees = Radians*180/pi

close all
clear all
% Define run parameters so proper file is loaded

           H_S = [ 2.5 2.5 3.5 3.5 4 4 4.5 4.5 ];  %meters
           PER = [ 7.9 7.9 9.3 9.3 10 10 10.6 10.6 ];  %Seconds
           SCOPES = [1.25 1.35 1.25 1.35 1.25 1.35 1.25 1.35];
          
 % for dir_num = [1 2 3 4 5 6 7 8] 
for dir_num = [7]
   
    suffix = ['MUCE-600lbs-200d-24mSnubber-AsBuilt',num2str(dir_num)];  
 
  path = ['./',suffix,'/']; 

    scope = SCOPES(dir_num);
    wave_per = PER(dir_num);
    wave_amp = H_S(dir_num)/2 ;
    
      
for run_num = [3]
    
    
    
% Load appropriate file
datafile = ['Res-',num2str(run_num),'c-',num2str(scope),'s-200d-',num2str(wave_amp),'A-',num2str(wave_per),'T-7W-8SL'];
load([path,datafile,'.mat']);
load([path,datafile,'-spec.mat']);

% Create array x_b of the actual node numbers of bending nodes of interest
 x_b = [first_FC_node-10:first_UC_node+150]; % For floated section


% Create subset array of the actual Lagrangian position for bending nodes of interest 
s_b = s(x_b)';

% Create array of Lagrangian distance between bending nodes of interest, s_diff
s_diff = diff(s_b')';

% Create array of the nodes_of_interest array numbers that corrospond to
% the actual node numbers
[~, nodes_bending, ib] = intersect(nodes,x_b);

% Create array of angle differences between section of nodes_of_interest, deg_diff_t
% for section of interest nodes_bending
rad_diff_t = diff(phi_t(:,nodes_bending)')';

% Expand the size and value of s_diff to match the size of rad_diff_t
[r c] = size(rad_diff_t); % First, what size is rad_diff_t?
s_diff_expand = (ones(r,1)*s_diff); % Matrix multiply using column x row to build full array

% Calculate radians per meter by dividing deg_diff by s_diff_expand (=node
% spacing).
rad_m = rad_diff_t./s_diff_expand;

% Convert to degrees
deg_m = rad_m(:,:)*(180/pi);

% Plot results
h = figure('color','w','Position',[487   703   756   391]);

% Pull current plot settings
ax1 = gca;

% Set current axis color and font. This will be degrees/meter axis
set(ax1,'XColor','k','YColor','k','FontSize',12)

% Plot data against Lagrangian position
x1 = s_b(:,1:end-1);
y1 = deg_m(:,1:end);
data1 = line(x1,y1);

% Create second axes in same position as first axes but change location
ax2 = axes('Position',get(ax1,'Position'),...
           'XAxisLocation','top',...
           'YAxisLocation','right',...
           'Color','none',...
           'XColor','k','YColor','k','FontSize',12);

% Make second x and y axis ticks invisible.
set(ax2,'xtick',[])
set(ax2,'ytick',[])

% Label plot
title(['Bending At Cable Floats ',datafile],'color','k','FontSize',12);
xlabel(ax1,'Lagrangian Distance From Anchor - Meters','color','k','FontSize',12);
ylabel(ax1,'Degrees Per Meter','color','k','FontSize',12);

%hgsave([path,'FloatBending_',num2str(run_num),'c_current'])
%delete (h)
end

% Expand the Langranian position matrix to match the size of the Y data
% for all of the time steps.
f1 = size(y1);
x2 = (ones(f1(1),1)*x1);

% Create an array of the time step numbers
run = 1:f1(1);
run = (ones(f1(2),1)*run);
run = run.'; % Transpose array to match y1


end


for i = 1:3001
  
    plot3(run(i,:),x2(i,:),y1(i,:))
pause
end
