% 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

% Load appropriate file

close all

clear all

% Directory of first set of data files to load
suffix = 'IFREMER-600lbs-400d-1Snubber-test16';
path = ['./',suffix,'/'];

datafile = 'Res-1c-1.25s-400d-0A-0T-5W-24SL'

% Load configuration "Snubber" data at condition
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
x_b = [first_FC_node-10:first_UC_node+1000]

% 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
[c, 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)')' % For dynamic data on nodes
% of interest
rad_diff_t = diff(phi_s(:,nodes_bending)') % For static data

% Calculate degrees per meter by dividing deg_diff by s_diff (=node
% spacing). s_diff array is expanded to match size of deg_diff_t for
% function to work OK.
rad_m = rad_diff_t./(ones(length(rad_diff_t),1)*s_diff)

% Convert to degrees
deg_m = rad_m(:,:)*(180/pi)

% Plot results
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);

title('Bending Per Meter With 24 Meter Snubber - Design Condition','color','k','FontSize',12);
xlabel(ax1,'Lagrangian Distance From Anchor','color','k','FontSize',12);
ylabel(ax1,'Degrees Per Meter','color','k','FontSize',12);

% Set the x- and y-coordinates of the textbox object:
x_tex = [0.001 0.026 .336 .042];

% Create the textbox 
txtbx = annotation('textbox',x_tex,'String',datafile,'FontSize',12);
               