clear variables;close all;clc
% This is an example about how to access and analyze the HDF5 results
% A load cases is provided to the variable "loadCase". A list of mooring
% cases (up to 8) to be compared is then provided to the "moorCaseList" array. 
% The controller identifier is provided to the ctrID string
% Three figures will pop up when the script is ran:
% - Figure 1 has wind turbine time series (thurst, rotor speed, power)
% - Figure 2 has Nacelle vel. motions (surge, sway, yaw)
% - Figure 3 has the axial tension at the top of the lines (1, 3, 5)
% 
% Note that the .h5 files and the "readHDF5" function have to be at the
% same folder.

loadCase = 3; % Load case number

moorCaseStr = {'HNMG';'HMG';'NL4S';'NL4M';'LT';'FRS';'CLW4';'BL4'}; % Mooring case identifiers
moorCaseList = [1:2]; % Mooring cases to be compared

ctrID = 'BLAYS'; % Controller ID

legendStr = {}; % Empty legend cell to be filled with the mooring cases identifiers

for moorCase = moorCaseList % loop on mooring cases
    [simData] = readHDF5(moorCase,loadCase,ctrID); % calls readHDF5 function
    % Nacelle time series
    motionTime = simData.Dynamic.Nacelle.LocalVelocity.Time;
    nacVelSurge = simData.Dynamic.Nacelle.LocalVelocity.XLvelocityTotalmotion;
    nacVelSway = simData.Dynamic.Nacelle.LocalVelocity.YLvelocityTotalmotion;
    nacVelYaw = simData.Dynamic.Nacelle.LocalVelocity.ZLang_vel_Totalmotion;
    % Wind turbine time series
    wtTime  = simData.Dynamic.WindTurbine.Time;
    RotSpeed  = simData.Dynamic.WindTurbine.RotSpeed*pi/180;
    RotThrust  = simData.Dynamic.WindTurbine.AeroForceX;
    RotPower  = simData.Dynamic.WindTurbine.GenPower;
    
    legendStr =  [legendStr cell2mat(moorCaseStr(moorCase))]; % Update legend string
    
    % Plot figures for the current mooring case
    figure(1)
    subplot(3,1,1)
    plot(wtTime,RotSpeed)
    hold on
    subplot(3,1,2)
    plot(wtTime,RotThrust)
    hold on
    subplot(3,1,3)
    plot(wtTime,RotPower)
    hold on
    figure(2)
    subplot(3,1,1)
    plot(motionTime,nacVelSurge)
    hold on
    subplot(3,1,2)
    plot(motionTime,nacVelSway)
    hold on
    subplot(3,1,3)
    plot(motionTime,nacVelYaw)
    hold on

end

% Adjust plots (axes, legend, etc)
figure(1)
subplot(3,1,1)
title('Rotor speed')
grid on
xlabel('Time (s)')
ylabel('\Omega (rad/s)')
legend(legendStr)
subplot(3,1,2)
title('Rotor thrust')
grid on
xlabel('Time (s)')
ylabel('Thrust (N)')
subplot(3,1,3)
title('Rotor power')
grid on
xlabel('Time (s)')
ylabel('Power (W)')

figure(2)
subplot(3,1,1)
title('Nacelle vel. surge')
grid on
xlabel('Time (s)')
ylabel('X (m/s)')
legend(legendStr)
subplot(3,1,2)
title('Nacelle vel. sway')
grid on
xlabel('Time (s)')
ylabel('Y (m/s)')
subplot(3,1,3)
title('Nacelle vel. yaw')
grid on
xlabel('Time (s)')
ylabel('\Psi (deg/s)')




