% Delivered to the Government in Accordance with Contract FA8650-10-C-7080
% 
%  (c) 2011 United Technologies Corp.
% Developed with the sponsorship of the Defense Advanced Research Projects Agency (DARPA).
%  
% Permission is hereby granted, free of charge, to any person obtaining a copy of this data, including any software or models in source or binary form, as well as any drawings, specifications, and documentation (collectively "the Data"), to deal in the Data without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Data, and to permit persons to whom the Data is furnished to do so, subject to the following conditions:
%  
% The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Data.
%  
% THE DATA IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, SPONSORS, DEVELOPERS, CONTRIBUTORS, OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE DATA OR THE USE OR OTHER DEALINGS IN THE DATA.
% 

% This script edits data so that it can be used in the surface fitting tool
h = 0;

beta = linspace(0, 1, 111);
speed = linspace(0.5, 1.05, 111);

for count1 = 1:111
Mass_nd = 0;
PR_nd = 0;
Efficiency_nd = 0;
Speed = speed(count1);
for count2 = 1:111
    
Beta = beta(count2);

% Relative Corrected Mass Flow
       m00 =      0.5771;
       m10 =     -0.4857;
       m01 =      -3.875;
       m20 =     -0.4813;
       m11 =       2.004;
       m02 =       16.49;
       m30 =      0.4974;
       m21 =      0.7979;
       m12 =      -4.546;
       m03 =      -26.12;
       m40 =     -0.4024;
       m31 =      0.8925;
       m22 =      -3.408;
       m13 =       5.792;
       m04 =        19.9;
       m50 =    -0.02339;
       m41 =      0.5763;
       m32 =      -1.743;
       m23 =        3.21;
       m14 =      -2.771;
       m05 =      -5.962;


Mass_nd(count2) = (m00 + m10*Beta + m01*Speed + m20*Beta^2 + m11*Beta*Speed + m02*Speed^2 + m30*Beta^3 + m21*Beta^2*Speed ...
                    + m12*Beta*Speed^2 + m03*Speed^3 + m40*Beta^4 + m31*Beta^3*Speed + m22*Beta^2*Speed^2 ...
                    + m13*Beta*Speed^3 + m04*Speed^4 + m50*Beta^5 + m41*Beta^4*Speed + m32*Beta^3*Speed^2 ...
                    + m23*Beta^2*Speed^3 + m14*Beta*Speed^4 + m05*Speed^5);
                
       p00 =       1.015;
       p10 =      0.1416;
       p01 =      -4.129;
       p20 =     -0.3486;
       p11 =    -0.06972;
       p02 =       14.06;
       p30 =     -0.1199;
       p21 =       1.862;
       p12 =     -0.6549;
       p03 =      -22.09;
       p40 =     -0.1201;
       p31 =        1.15;
       p22 =      -4.947;
       p13 =       2.851;
       p04 =       17.18;
       p50 =    0.004072;
       p41 =      0.1846;
       p32 =      -1.278;
       p23 =       3.529;
       p14 =      -1.892;
       p05 =      -5.224;

                
PR_nd(count2) = p00 + p10*Beta + p01*Speed + p20*Beta^2 + p11*Beta*Speed + p02*Speed^2 + p30*Beta^3 + p21*Beta^2*Speed ...
                    + p12*Beta*Speed^2 + p03*Speed^3 + p40*Beta^4 + p31*Beta^3*Speed + p22*Beta^2*Speed^2 ...
                    + p13*Beta*Speed^3 + p04*Speed^4 + p50*Beta^5 + p41*Beta^4*Speed + p32*Beta^3*Speed^2 ... 
                    + p23*Beta^2*Speed^3 + p14*Beta*Speed^4 + p05*Speed^5;

       e00 =     -0.2422;
       e10 =      -3.346;
       e01 =       9.833;
       e20 =       1.707;
       e11 =       16.84;
       e02 =      -35.44;
       e30 =       1.818;
       e21 =      -11.81;
       e12 =      -25.88;
       e03 =       58.45;
       e40 =     -0.7842;
       e31 =      -1.915;
       e22 =       16.56;
       e13 =       15.53;
       e04 =      -43.53;
       e50 =      0.1999;
       e41 =      0.2284;
       e32 =      0.6619;
       e23 =      -6.843;
       e14 =      -2.925;
       e05 =       11.87;
                

Efficiency_nd(count2) = e00 + e10*Beta + e01*Speed + e20*Beta^2 + e11*Beta*Speed + e02*Speed^2 + e30*Beta^3 + e21*Beta^2*Speed... 
                    + e12*Beta*Speed^2 + e03*Speed^3 + e40*Beta^4 + e31*Beta^3*Speed + e22*Beta^2*Speed^2 ...
                    + e13*Beta*Speed^3 + e04*Speed^4 + e50*Beta^5 + e41*Beta^4*Speed + e32*Beta^3*Speed^2 ...
                    + e23*Beta^2*Speed^3 + e14*Beta*Speed^4 + e05*Speed^5;


end


if abs(Speed- 1) < 0.001
hold on
plot(Mass_nd, PR_nd,'b');

elseif abs(Speed - 1.05)< 0.001 
plot(Mass_nd, PR_nd,'r');
hold on

else
    
plot(Mass_nd, PR_nd,'k');
hold on
end

end

