function Rotor_performance_map(AWA, AWS, SR, D, De, h)
%AWA : Range of Apparent Wing Angle [deg] | ex: 0:10:120
%AWS : Range of Apparent Wind Speed [m/s] | ex: 0:10:30
%SR : Spin Ratio [-] | ex: 0:0.5:4

%D : rotor diameter [m]
%De : End plate diameter [m]
%h : rotor height [m]

%% Pathing
addpath(genpath('RotorSail'));

disp(AWA)


% Atmospheric conditions
rho = 1.225; % kg/m3, air density
mu = 0.0000181; % 


[T,S,P,z_ac] = RotorSail_Calc_wrapper(AWA,AWS,SR,D,De,h,rho,mu);

% The calculated cell arrays are combined into a single export table
numCombinations = length(AWA) * length(AWS) * length(SR);

% Initialize the new variables
AWA_new = zeros(numCombinations, 1);
AWS_new = zeros(numCombinations, 1);
SR_new = zeros(numCombinations, 1);
T_new = zeros(numCombinations, 1);
S_new = zeros(numCombinations, 1);
P_new = zeros(numCombinations, 1);
z_ac_new = zeros(numCombinations, 1);

% Fill the new variables
index = 1;
for i = 1:length(AWA)
    for j = 1:length(AWS)
        for k = 1:length(SR)
            AWA_new(index) = AWA(i);
            AWS_new(index) = AWS(j);
            SR_new(index) = SR(k);
            T_new(index) = T(i,j,k);
            S_new(index) = S(i,j,k);
            P_new(index) = P(j,k);
            index = index + 1;
        end
    end
end
for j = 1:length(AWS)
    if ~isnan(z_ac(j,2)) && AWS(j) > 0
        z_ac_new(:) = z_ac(j,2);
        break;
    end
end

% Create a new table
export = table(AWA_new, AWS_new, SR_new, T_new, S_new, P_new, z_ac_new, 'VariableNames', {'AWA [deg]', 'AWS [m/s]', 'SR', 'T [N]', 'S [N]', 'P_spin [W]', 'z_ac [m]'});

saveDirectory = 'RotorSail\Export\';

fileName = ['RotorSail_D-', num2str(D), '_De-', num2str(De), '_height-', num2str(h)];
writetable(export, [saveDirectory fileName '.csv'], 'WriteVariableNames', true, 'WriteRowNames',false, 'Delimiter', ';');
disp("Exported in " + saveDirectory + fileName +'.csv');

end