% 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 reads a turbine map and bisects it into choked and unchoked
% sections.  It does so by finding coordinates at which the speed lines
% become vertical

Res = max(size(Mass_HPT));
tolerance = 0.01;
c = 0;
uc = 0;

for s = 1:Res
    for b = 2:Res
    
        if abs((Mass_HPT(s,b)-Mass_HPT(s,b-1))/(Beta_HPT(b)-Beta_HPT(b-1)))>tolerance
           choke_beta_HPT(s) = Beta_HPT(b);  % Beta coordinate of choke
           choke_speed_HPT(s) = Speed_HPT(s); % Speed coordinat of choke
        end      
        
    end
end


for s = 1:Res
    for b = 1:Res
        
        
        if choke_beta_HPT(s) >= Beta_HPT(b)
            
            uc= uc+1;
            Beta_HPT_uc(uc) = Beta_HPT(b);
            Speed_HPT_uc(uc) = Speed_HPT(s);
            Mass_HPT_uc(uc) = Mass_HPT(s,b);    % Unchoked Section
            PR_HPT_uc(uc) = PR_HPT(s,b);
            Efficiency_HPT_uc(uc) = Efficiency_HPT(s,b);
       
        
        elseif choke_beta_HPT(s) <= Beta_HPT(b)
            
            c= c+1;
            Beta_HPT_c(c) = Beta_HPT(b);
            Speed_HPT_c(c) = Speed_HPT(s);
            Mass_HPT_c(c) = Mass_HPT(s,b);      % Choked Section
            PR_HPT_c(c) = PR_HPT(s,b);
            Efficiency_HPT_c(c) = Efficiency_HPT(s,b);
        
      
        end
        
        
    end
end
