function [H,p,h,pP,bod]=dga_csn(t,X_CH4,X_C2H2,X_C2H4,X_H2,X_C2H6,X_CO,X_CO2,tau,out,k,mezeC1,mezeC2,mezeC3,mezeC4)

% t     ...casovy vektor
% X_*   ...vektory jednotlivych plynu (mohou obsahovat prazdna mereni)
% tau   ...cas, ve kterem pocitame predpoved
% out   ...vyradit/nevyradit odlehle hodnoty, out=1 - vyradit
% H     ...vysledky testu dobre shody (analyza chyby) z funkce pravd_prekroceni, 1-normalni rozdeleni
%          nezamitnuto, celkem 7 hodnot, predikuje se 7 ruznych rad
% p     ...pravdepodobnost, ze alespon jedna velicina prekroci svou mez v
%          case tau
% pP    ...pravdepodobnosti, ze "stav transformatoru" bude v case tau v
%          jednotlivych zonach v CSN, postupne PD, T1, T2, T3, D1/D2, D1,
%          D2, nelze rozhodnout
% bod   ...nejpravdepodobnejsi "stav transformatoru" v case tau
% meze  ...kriterialni hodnoty

[t_CH4,CH4,l]=vyhazet_radky(t,X_CH4);
[t_C2H2,C2H2,l]=vyhazet_radky(t,X_C2H2);
[t_C2H4,C2H4,l]=vyhazet_radky(t,X_C2H4);
[t_H2,H2,l]=vyhazet_radky(t,X_H2);
[t_C2H6,C2H6,l]=vyhazet_radky(t,X_C2H6);
[t_CO,CO,l]=vyhazet_radky(t,X_CO);
[t_CO2,CO2,l]=vyhazet_radky(t,X_CO2);

[H,p]=pravd_prekroceni_nove(mezeC1,mezeC2,mezeC3,mezeC4,t_CH4,t_C2H2,t_C2H4,t_H2,t_C2H6,t_CO,t_CO2,CH4,C2H2,C2H4,H2,C2H6,CO,CO2,tau,out,k);

[t_x,X3,Y3,l]=vyhazet_radky2(t,X_C2H4,X_C2H6);
x=X3./Y3;

[t_y,X2,Y2,l]=vyhazet_radky2(t,X_CH4,X_H2);
y=X2./Y2;

[t_z,X1,Y1,l]=vyhazet_radky2(t,X_C2H2,X_C2H4);
z=X1./Y1;
%---------------------------------------------------
%PD:

[h,p_x,bod]=pred_int2(t_x,x,tau,0,0.2,out,k);

[h,p_y,bod]=pred_int2(t_y,y,tau,0,0.1,out,k);

[h,p_z,bod]=pred_int2(t_z,z,tau,0,0.01,out,k);

p_PD=p_x*p_y*p_z;
%--------------------------------------------------
%T1:

[h,p_x,bod]=pred_int2(t_x,x,tau,0,1,out,k);

[h,p_y,bod]=pred_int2(t_y,y,tau,1,inf,out,k);

[h,p_z,bod]=pred_int2(t_z,z,tau,0,0.01,out,k);


p_T1=p_x*p_y*p_z;
%--------------------------------------------------
%T2:

[h,p_x,bod]=pred_int2(t_x,x,tau,1,4,out,k);

[h,p_y,bod]=pred_int2(t_y,y,tau,1,inf,out,k);

[h,p_z,bod]=pred_int2(t_z,z,tau,0,0.1,out,k);

p_T2=p_x*p_y*p_z;
%--------------------------------------------------
%T3:

[h,p_x,bod]=pred_int2(t_x,x,tau,4,inf,out,k);

[h,p_y,bod]=pred_int2(t_y,y,tau,1,inf,out,k);

[h,p_z,bod]=pred_int2(t_z,z,tau,0,0.2,out,k);

p_T3=p_x*p_y*p_z;
%--------------------------------------------------
%D1D2:

[h,p_x,bod]=pred_int2(t_x,x,tau,2,inf,out,k);

[h,p_y,bod]=pred_int2(t_y,y,tau,0.1,0.5,out,k);

[h,p_z,bod]=pred_int2(t_z,z,tau,1,2.5,out,k);

p_D1D2=p_x*p_y*p_z;
%--------------------------------------------------
%D1: nejprve pocitam D1+D1D2

[h,p_x,bod]=pred_int2(t_x,x,tau,1,inf,out,k);

[h,p_y,bod]=pred_int2(t_y,y,tau,0.1,0.5,out,k);

[h,p_z,bod]=pred_int2(t_z,z,tau,1,inf,out,k);

p_D1_D1D2=p_x*p_y*p_z;
p_D1=p_D1_D1D2-p_D1D2;
%--------------------------------------------------
%D2: nejprve pocitam D2+D1D2

[h(1),p_x,bod(1)]=pred_int2(t_x,x,tau,2,inf,out,k);

[h(2),p_y,bod(2)]=pred_int2(t_y,y,tau,0.1,1,out,k);

[h(3),p_z,bod(3)]=pred_int2(t_z,z,tau,0.6,2.5,out,k);

p_D2_D1D2=p_x*p_y*p_z;
p_D2=p_D2_D1D2-p_D1D2;
%--------------------------------------------------
%ostatni
p_ost=1-p_PD-p_T1-p_T2-p_T3-p_D1D2-p_D1-p_D2;
%--------------------------------------------------

% P=[p_PD;p_T1;p_T2;p_T3;p_D1D2;p_D1;p_D2;p_ost];
% pP=P.*p;

for i=1:4
ppPD(i)=p_PD*p(i);
end

for i=1:4
ppT1(i)=p_T1*p(i);
end

for i=1:4
ppT2(i)=p_T2*p(i);
end

for i=1:4
ppT3(i)=p_T3*p(i);
end

for i=1:4
ppD1D2(i)=p_D1D2*p(i);
end

for i=1:4
ppD1(i)=p_D1*p(i);
end

for i=1:4
ppD2(i)=p_D2*p(i);
end

for i=1:4
ppost(i)=p_ost*p(i);
end

pP=[ppPD;ppT1;ppT2;ppT3;ppD1D2;ppD1;ppD2;ppost]';
dga_csn_plot(bod);
clc







