%% Copyright (C) 2020 jandr
%%
%% This program is free software: you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation, either version 3 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program.  If not, see <https://www.gnu.org/licenses/>.

%% -*- texinfo -*-
%% @deftypefn {} {@var{retval} =} LoadDObjectResults (@var{input1}, @var{input2})
%%
%% @seealso{}
%% @end deftypefn

%% Author: jandr <jandr@DESKTOP-APS9VFR>
%% Created: 2020-12-19

function retval = ParseCableResults (CableDObjectName)

retval.t = CableDObjectName.results(:,1);
retval.n_elements = size(CableDObjectName.tensions,2)-1;
retval.n_nodes = retval.n_elements+1;

%Compute node distance along cable
retval.Unstretched_Node_s = [0 cumsum(CableDObjectName.lengths(1,2:end))];
%retval.Stretched_Node_s = [0 cumsum(CableDObjectName.lengthsStretched(1,2:end))];


retval.Xdot = CableDObjectName.results(:,2:6:end-2);
retval.X  = CableDObjectName.results(:,3:6:end-2);
retval.Ydot = CableDObjectName.results(:,4:6:end-2);
retval.Y  = CableDObjectName.results(:,5:6:end-2);
retval.Zdot = CableDObjectName.results(:,6:6:end-2);
retval.Z  = CableDObjectName.results(:,7:6:end-2);

retval.MeanX = mean(retval.X,1);
retval.MeanY = mean(retval.Y,1);
retval.MeanZ = mean(retval.Z,1);

%Evaluate Tension at Nodes
retval.ElementTensions_s =  CableDObjectName.tensions(:,2:end);

retval.NodeTensions_s(:,1) = (CableDObjectName.reactionLoads(:,2).^2+CableDObjectName.reactionLoads(:,3).^2+CableDObjectName.reactionLoads(:,4).^2).^.5;
for i = 2:retval.n_elements 
  retval.NodeTensions_s(:,i) = max(CableDObjectName.tensions(:,i-1),CableDObjectName.tensions(:,i));
end
retval.NodeTensions_s(:,retval.n_elements+1) = (CableDObjectName.reactionLoads(:,8).^2+CableDObjectName.reactionLoads(:,9).^2+CableDObjectName.reactionLoads(:,10).^2).^.5;


retval.Node0HorizForce = (CableDObjectName.reactionLoads(:,2).^2+CableDObjectName.reactionLoads(:,3).^2).^.5;
retval.Node0VertForce = CableDObjectName.reactionLoads(:,4);
retval.NodeNHorizForce = (CableDObjectName.reactionLoads(:,8).^2+CableDObjectName.reactionLoads(:,9).^2).^.5;
retval.NodeNVertForce = CableDObjectName.reactionLoads(:,10);




retval.epsilon = (CableDObjectName.lengthsStretched(:,2:end)-CableDObjectName.lengths(:,2:end))./CableDObjectName.lengths(:,2:end);

retval.submergenceProbe = CableDObjectName.submergenceProbe(:,2);

endfunction
