
clear all
clc
close all

lineno1=['1            ';'1            ';'1            ';'1            ';'1            ';'1            ';'1            ';'1            ';'1            ';'1            ';'2            ';'2            ';'2            ';'2            ';'2            ';'2            ';'2            ';'2            ';'2            ';'2            ';'3            ';'3            ';'3            ';'3            ';'3            ';'3            ';'3            ';'3            ';'3            ';'3            ';'4            ';'4            ';'4            ';'4            ';'4            ';'4            ';'4            ';'4            ';'4            ';'4            '];
lineno1_1=char(lineno1);
lineno1_1_1=str2num(lineno1_1);
a=unique(lineno1_1_1);
for i=1:length(a);
    
    indices{i}=find(lineno1_1_1==a(i));
end
f1=figure(1);
mdot_corr=[0.0165051114046817;0.0198195313570090;0.0231066955246014;0.0263982196353207;0.0296771421159110;0.0330382879140461;0.0366881958856233;0.0399044463860129;0.0435598674820184;0.0468509979175988;0.0303646266244953;0.0369367681111455;0.0437878625848069;0.0504815789797121;0.0574334648882575;0.0640534356015511;0.0709726469680214;0.0775073673445395;0.0844325756772315;0.0910360157101119;0.0524542354489117;0.0618142313386623;0.0713785406878966;0.0809459791610706;0.0905680266388385;0.100120703370532;0.109787297448452;0.119474256038762;0.129179314390702;0.138725004107848;0.116618705741608;0.123041439612427;0.129557517449978;0.136142164653332;0.142435145937898;0.148847032112062;0.155396698811118;0.161666585264291;0.168665441308280;0.175357539664693];
eta_c_tt_is=[0.486548835415014;0.521303314244957;0.545986385849840;0.572675937059292;0.597081302025177;0.600369722799215;0.602382896797768;0.599945518797015;0.597125208707969;0.559383298644058;0.573450264431837;0.621755712616694;0.667939601372804;0.699041496810296;0.713235985225421;0.722693989697990;0.724352653460005;0.707052317449907;0.664215290355016;0.597470541409840;0.610974327417206;0.656323171615731;0.688281097873679;0.713450906085277;0.733728009644685;0.755724013869039;0.761433320127458;0.746587466276478;0.712319568490408;0.643582162232389;0.701992056880703;0.713168815726820;0.725687747868561;0.740013193061654;0.748824172161316;0.756304063322899;0.758418423811440;0.754193854305642;0.744904012059932;0.725515524230018];
PI_C_tt=[1.17653639857645;1.17361760967084;1.17116963984125;1.16625689013502;1.15858633827387;1.15210928579497;1.14500735237383;1.13682174829588;1.12662641414154;1.11426109112172;1.52505312839389;1.52117305092963;1.50925573443762;1.49162451256202;1.47585084954404;1.45677211274433;1.43191135011733;1.39733031423461;1.34882402936100;1.29138397559055;2.10252927488075;2.08484923700351;2.07925329749713;2.08009461130324;2.06977987964624;2.04292268582172;1.99874629695558;1.92108424285240;1.82143606083863;1.68304358137636;2.98803315460131;3.00484485918550;3.02640862000431;3.09114299824215;3.07458055935623;3.04082506613848;2.97377741771165;2.91757230678782;2.82735514511069;2.69746001557365];

for i=1:length(a);
    
    indices{i}=find(lineno1_1_1==a(i));
end
%%Wirkungsgrad
eta_c_tt_is_hun=ceil(eta_c_tt_is*100);

    %% Compressor

    for i=1:length(indices)
        [Max_mdot_corr(i),k(i)]=max(mdot_corr(indices{1,i}));
        [Min_mdot_corr(i),k1(i)]=min(mdot_corr(indices{1,i}));
    end
    for s=1:length(k)
        zeilenum_max(s)=indices{1,s}(k(1,s));
        PI_C_tt_comp_max(s)=PI_C_tt(zeilenum_max(1,s));
        %x=Min_Min_mdot_corr ===> y=PI_C_tt_comp_min
        zeilenum_min(s)=indices{1,s}(k1(1,s));
        PI_C_tt_comp_min(s)=PI_C_tt(zeilenum_min(1,s));
    end
  
    %% Vector
    mdot_corr_vec=mdot_corr(:);
    PI_C_tt_vec=PI_C_tt(:);
    eta_c_tt_is_vec=eta_c_tt_is(:);

    %% Pumpgrenze/Stopfgrenze/Drehzahlinien
    hold on
    %% Drehzahllinien
    for j=1:length(indices)
    plot3(mdot_corr(indices{1,j}(1:end)),PI_C_tt(indices{1,j}(1:end)),eta_c_tt_is_hun(indices{1,j}(1:end)),'-bs','Linewidth',1.5,...
    'MarkerEdgeColor','b');

    %%Stopfgrenze
    plot(Max_mdot_corr(1,:),PI_C_tt_comp_max(1,:),'linewidth',2)


    %% Pumpgrenze
   plot(Min_mdot_corr(1,:),PI_C_tt_comp_min(1,:),'linewidth',2)

   %% Wirkungsgradlinien
    Wnodes=length(mdot_corr);
    PRnodes=length(mdot_corr);
    smooth=1.5;
    [eff_grid,M_grid,P_grid]=gridfit(mdot_corr_vec,PI_C_tt_vec,eta_c_tt_is_vec,Wnodes,PRnodes,'smoothness',smooth);
    tx=linspace(min(mdot_corr),max(mdot_corr),40);
% tx=tx(:);
    ty=linspace(min(PI_C_tt),max(PI_C_tt),40);
% ty=ty(:);
%  ausserhalb_verdichter=~inpolygon(M_grid,P_grid,mdot_corr_vec,PI_C_tt_vec);
%  eff_grid(ausserhalb_verdichter)=nan;
% 
eff_grid_text=ceil(eff_grid*100);
Min_mdot_corr_vec=Min_mdot_corr(:);
PI_C_tt_comp_min_vec=PI_C_tt_comp_min(:);
[C,h]=contour(M_grid,P_grid,eff_grid,11);
%     
% dt=DelaunayTri(Min_mdot_corr_vec,PI_C_tt_comp_min_vec)
% 
% patch(dt(:,1),dt(:,2),dt(:,3))
x1=[0;Min_mdot_corr(1);Min_mdot_corr(1)]
y1=[0;0;PI_C_tt_comp_min(1)]
p1=patch(x1,y1,'w')
set(p1,'Edgecolor','w','Facecolor','w')
x2=[Min_mdot_corr(1);Min_mdot_corr(2);0];
y2=[PI_C_tt_comp_min(1);PI_C_tt_comp_min(2);PI_C_tt_comp_min(2)]
p2=patch(x2,y2,'w')
set(p2,'Edgecolor','w','Facecolor','w')
x12=[0;0;Min_mdot_corr(1)];
y12=[0;PI_C_tt_comp_min(2);PI_C_tt_comp_min(1)]
p12=patch(x12,y12,'w')
set(p12,'Edgecolor','w','Facecolor','w')
x3=[Min_mdot_corr(2);Min_mdot_corr(3);0]
y3=[PI_C_tt_comp_min(2);PI_C_tt_comp_min(3);PI_C_tt_comp_min(3)]
p3=patch(x3,y3,'w')
set(p3,'Edgecolor','w','Facecolor','w')
x23=[0;0;Min_mdot_corr(2)];
y23=[0;PI_C_tt_comp_min(3);PI_C_tt_comp_min(2)]
p23=patch(x23,y23,'w')
set(p23,'Edgecolor','w','Facecolor','w')
x4=[Min_mdot_corr(3);Min_mdot_corr(4);0]
y4=[PI_C_tt_comp_min(3);PI_C_tt_comp_min(4);PI_C_tt_comp_min(4)]
p4=patch(x4,y4,'w')
set(p4,'Edgecolor','w','Facecolor','w')
x34=[0;0;Min_mdot_corr(3)];
y34=[0;PI_C_tt_comp_min(4);PI_C_tt_comp_min(3)]
p34=patch(x34,y34,'w')
set(p34,'Edgecolor','w','Facecolor','w')
%     sc=poly2tri(mdot_corr,PI_C_tt)
%    h=patch(mdot_corr,PI_C_tt,eta_c_tt_is,'none')
% [m_grid,p_grid]=meshgrid(linspace(min(mdot_corr),max(mdot_corr)),linspace(min(PI_C_tt),max(PI_C_TT)))
% Vq=griddata(mdot_corr,PI_C_tt,eta_c_tt_is

   
%     %% textH%%
%     texth=clabel(C,h,'fontsize',10);
%     for a=1:length(texth)
%         textstr=get(texth(a),'String');
%         textnum=str2num(textstr);
%         textnum=100*textnum;
%         textstrnew=num2str(textnum,2);
%         set(texth(a),'String',textstrnew);
%     end
%    
%     
%     
%     [C,h]=contour(tx,ty,eff_grid_text,11);
%     set(h,'ShowText','on','TextStep',get(h,'LevelStep')*2);
%     set(h,'ShowText','on');
% 
%     grid on
     end
 
    
% figure(2)
% 
%     %% Compressor
% 
%     for i=1:length(indices)
%         [Max_mdot_corr(i),k(i)]=max(mdot_corr(indices{1,i}));
%         [Min_mdot_corr(i),k1(i)]=min(mdot_corr(indices{1,i}));
%     end
% 
% 
%     for s=1:length(k)
%         zeilenum_max(s)=indices{1,s}(k(1,s));
%         PI_C_tt_comp_max(s)=PI_C_tt(zeilenum_max(1,s));
%         zeilenum_min(s)=indices{1,s}(k1(1,s));
%         PI_C_tt_comp_min(s)=PI_C_tt(zeilenum_min(1,s));
%     end
% 
%     %% Vector                                                                                                                       
%     mdot_corr_vec=mdot_corr(:);
%     PI_C_tt_vec=PI_C_tt(:);
%     eta_c_tt_is_vec=eta_c_tt_is(:);
% 
%     %% Pumpgrenze/Stopfgrenze/Drehzahlinien
%     hold on
%     %% Drehzahllinien
%     for j=1:length(indices)
%     plot3(mdot_corr(indices{1,j}(1:end)),PI_C_tt(indices{1,j}(1:end)),eta_c_tt_is_hun(indices{1,j}(1:end)),'-bs','Linewidth',1.5,...
%     'MarkerEdgeColor','b');
% 
%     %%Stopfgrenze
%     plot(Max_mdot_corr(1,:),PI_C_tt_comp_max(1,:),'linewidth',2);
% 
% 
%     %% Pumpgrenze
%     plot(Min_mdot_corr(1,:),PI_C_tt_comp_min(1,:),'linewidth',2);
%     
%     [C,h]=contour(tx,ty,eff_grid,11);
%     
%     end
%     
    
    hold off

