function [epsilon1, ND1, epsilon2, ND2] = NonDim(A,M)
% [epsilon1, ND1, epsilon2, ND2] = NonDim(A,M)
%
% This function plots the extraction efficiency of the model vs. wave
% length and height normalized by the diameter of the OWC chamber
%
% Inputs:
% A - Opening Ratio in %
% M - Fixed or Floating (1 or 0)
% 
% Outputs:
% epsilon2 - Extraction Efficiency relative to Wave Height Sensitivity
% epsilon1 - Extraction Efficiency relative to Wave Period Sensitivity
% ND1 - Normalized Wavelength
% ND2 - Normalized Wave Height

% Global Variables initialized.
i=1;
j=1;
O = 0;                                                                      % Fix for zero degree incident waves

% Set range of wave periods tested for use in ND1
T = [1.25 1.5 1.75 2 2.25 2.5 3];
omega = 2*pi./T;
ostar = omega./sqrt(9.81/0.225);
% Determine Extraction Efficiency for each orifice and wave period. 
% Wave height is fixed at 8 cm. For loop excludes data from the 0.5 opening
% ratio when the wave period is 1.25 seconds.
for k = 1:length(A)
    for i = 1:length(T)
        if A(k) == 0.5 && T(i) == 1.25                                      % Exclude Test Data for 1.25 second waves for the 0.5% opening ratio
        epsilon1(i,k) = NaN;
        else
        [epsilon1(i,k)] = TrialEff(8,T(i),A(k),O,M);                        % Determine Extraction Efficiency
        end
        L = SolveDispersionEquation(1.36,T(i),1);                           % Solve for wave length via dispersion
        ND1(i) = L/0.225;                                                   % Define dimensionless wave length
    end
end

% Set range of wave heights tested for use in ND2
H = [5 6.5 8 9.5 11 14];

% Determine Extraction Efficiency for each orifice and wave height. 
% Wave period is fixed at 2 seconds. 
for k = 1:length(A)
    for i = 1:length(H)
        [epsilon2(i,k)] = TrialEff(H(i),2,A(k),O,M);                        % Determine Extraction Efficiency
        ND2(i) = (H(i)/100)/0.225;                                          % Define dimensionless wave height
    end
end

%% Plotting
acon = aconfig('LineWidth',2,'Colormap',[0 0 0],'MarkerSize',10,'LineStyles','o:|x:|s:|d:|+:','FontSize',20,'fontWeight','bold','Grid',1);
afigure(acon, 1)
% subplot(2,1,1)
aplot(ND2,epsilon2)

if M ==1
axis([0.2 0.7 0 0.3])
else
axis([0.2 0.7 0 0.4])
end

ylabel('$\varepsilon$','Interpreter','latex')
xlabel('H/D','Interpreter','latex')
ax = gca;
set(ax,'FontSize',20,'fontWeight','bold','ticklabelinterpreter','latex');

lab1 = '$\alpha = 0.5 \%$';
lab2 = '$\alpha = 0.7 \%$';
lab3 = '$\alpha = 1.0 \%$';
lab4 = '$\alpha = 1.5 \%$';
lab5 = '$\alpha = 2.0 \%$';

% legend(lab1,lab2,lab3,lab4,lab5,'Interpreter','latex')
%

% legend('boxoff')

% if M ==1
%     title('Normalized Fixed Model Efficiency')
% else
%     title('Normalized Floating Model Efficiency')
% end

% subplot(2,1,2)
afigure(acon,2)
aplot(ND1,epsilon1)
if M ==1
axis([10 50 0 0.3])
else
axis([10 50 0 0.4])
end
ylabel('$\varepsilon$','Interpreter','latex')
xlabel('L/D','Interpreter','latex')
ax = gca;
set(ax,'FontSize',20,'fontWeight','bold','ticklabelinterpreter','latex');

lab1 = '$\alpha = 0.5 \%$';
lab2 = '$\alpha = 0.7 \%$';
lab3 = '$\alpha = 1.0 \%$';
lab4 = '$\alpha = 1.5 \%$';
lab5 = '$\alpha = 2.0 \%$';

legend(lab1,lab2,lab3,lab4,lab5,'Interpreter','latex')
% legend('boxoff')
cd('C:\Users\ulmn\Documents\MATLAB\projects\2021\TEAMERUHOWC\sw\Plots\Floating\Efficiency\')
% saveas(figure(1),'Reg_Eff_AmplitudeDependence.fig')
% saveas(figure(1),'Reg_Eff_AmplitudeDependence.png')
% 
% saveas(figure(2),'Reg_Eff_FDependence.fig')
% saveas(figure(2),'Reg_Eff_FDependence.png')
cd('C:\Users\ulmn\Documents\MATLAB\projects\2021\TEAMERUHOWC\sw\')