function [VarRos] = dataExtract(H,T,A,O)
% [VarRos] = dataExtract(H,T,A,O)
% H - Wave Height in cm
% T - Period
% A - Opening Ratio in %
% O - Incident Angle (Degrees)
%
% VarRos(:,1:14)  - Wave Gauge Data
% VarRos(:,15)    - Fixed Model Surface Elevation
% VarRos(:,16:17) - Floating Model Pressure
% VarRos(:,18:19) - Fixed Model Pressure
% VarRos(:,20:23) - Load Cells
% VarRos(:,24)    - Time
% VarRos(:,25:27) - Translational Motion
% VarRos(:,28:30) - Rotational Motion

%% Find Trial file and start time
% Find the Trial Name
[ExpName, TrialN] = TrialFind(H,T,A,O);

% Find the start of the data based on the statistically significant start
% time
if T > 0
period = [1.25 1.5 1.75 2 2.25 2.5 3 4 5 6];                                    % Define wave periods to read from
%tstart = [74 64 64 64 65 66 63 63.5];                                         % Define start times that correspond to the period tested
tstart = [62 64 64 64 65 66 67 68 68 68];                                        % Define start times that correspond to the period tested
% tstart = [1 1 1 1 1 1 1 1 1 1];                                        % Define start times that correspond to the period tested
elseif T == -1
    period = -1;
    % tstart = 50;
    tstart = 0.01;
end
    

for i = 1:length(period)
    
    if T == period(i)
        t0 = tstart(i)*100;
    end
    
    i = i+1;
end

% Define end time based on 10 wave cycles
if T > 0
tf = t0+T*10*100;
elseif T == -1
    tf = 3500*100;
end

% Define directory to find data
sharename = 'C:\Users\ulmn\Documents\MATLAB\projects\2021\TEAMERUHOWC\data\inter';

% Read Wave Gauge Data
N0 = 'wg';

for i = 1:15
    N2 = horzcat(N0,num2str(i),'.txt');
    wg(:,i) = readmatrix(fullfile(sharename,ExpName,TrialN,N2));
end

% Read Pressure Data
N0 = 'press';

for i = 1:4
    N2 = horzcat(N0,num2str(i),'.txt');
    press(:,i) = readmatrix(fullfile(sharename,ExpName,TrialN,N2));             
end

%Read Load Cell Data
N0 = 'load';

for i = 1:4
    N2 = horzcat(N0,num2str(i),'.txt');
    LoadC(:,i) = readmatrix(fullfile(sharename,ExpName,TrialN,N2));
end

% Read Qualysis Data
X = readmatrix(fullfile(sharename,ExpName,TrialN,'sway.txt'));              % Sway
Y = readmatrix(fullfile(sharename,ExpName,TrialN,'surge.txt'));             % Surge
Z = readmatrix(fullfile(sharename,ExpName,TrialN,'heave.txt'));             % Heave
Pitch = readmatrix(fullfile(sharename,ExpName,TrialN,'pitch.txt'));         
Roll = readmatrix(fullfile(sharename,ExpName,TrialN,'roll.txt'));
Yaw = readmatrix(fullfile(sharename,ExpName,TrialN,'yaw.txt'));


n = 1;

% Define Wave Gauge Data
for i = 1:15
    VarRos(:,n) = wg(t0:tf,i);
    n=n+1;
end

% Define Pressure Data
for i = 1:4
    VarRos(:,n) = press(t0:tf,i);
    n = n+1;
end

% Define Load Cell Data
for i = 1:4
    VarRos(:,n) = LoadC(t0:tf,i);
    n = n+1;
end

% Define Time
VarRos(:,24) = [t0:tf]./100';

% Define Translational Motion
VarRos(:,25) = X(t0:tf);
VarRos(:,26) = Y(t0:tf);
VarRos(:,27) = Z(t0:tf);

% Define Rotational Motion
VarRos(:,28) = Pitch(t0:tf);
VarRos(:,29) = Roll(t0:tf);
VarRos(:,30) = Yaw(t0:tf);
end





