% 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

% Load appropriate file
% Directory of first set of data files to load
suffix = 'IFREMER-600lbs-400d-1Snubber-test18';
path = ['./',suffix,'/'];

datafile = 'Res-3c-1.25s-400d-2.28A-10.66T-11.66W-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


% 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)')' 

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

% 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 Per Meter With 24 Meter Snubber - 25 Year Storm Condition','color','k','FontSize',12);
xlabel(ax1,'Lagrangian Distance From Anchor - Meters','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);
               