function OLGA_new_plotting(t,y0,y,U,ControlStart,estimationON,Y_est,U_inner,X,X_est,noise)
titleSize=18;
labelSize=15;
gcaSize=15;
linewidth=1;

wmix_r_out=y(:,2);
p_at=y(:,5);
p_tt=y(:,6);
p_bh=y(:,7);
p_bh_est=Y_est(:,5);


t=t/60;
%% Pressure Bottom Hole Control, plot w-out and u1
if (1)
figure()
set(gcf,'Color',[1,1,1])
    
% Bottom Hole Pressure
if estimationON
    subplot(3,1,1)
    plot(t,p_bh_est,'-r','linewidth',1)
    hold on;
    plot(t,p_bh,'--b','linewidth',1)
    hold on;
    setpoint=linspace(1,1,length(t))*p_bh(1);
    plot(t,setpoint,'--k','linewidth',1);
    hold on;
    plot(ControlStart/60,setpoint(1) , 'rx','MarkerSize',15,'Linewidt',2);
    legend('estimated','real value','setpoint','Control Start');
    set(gca,'FontSize',gcaSize);
    title('Bottom Hole Pressure ','FontSize',titleSize,'FontWeight','bold')
    xlabel('[minutes]','FontSize',labelSize)
    ylabel('[bara]','FontSize',labelSize)
else
    subplot(3,1,1)
    plot(t,p_bh,'k','linewidth',1)
    hold on;
    setpoint=linspace(1,1,length(t))*p_bh(1);
    plot(t,setpoint,'--b','linewidth',1);
    hold on;
    plot(ControlStart/60,setpoint(1) , 'rx','MarkerSize',15,'Linewidt',2);
    legend('measurement','setpoint','Control Start');
    set(gca,'FontSize',gcaSize);
    title('Bottom Hole Pressure ','FontSize',titleSize,'FontWeight','bold')
    xlabel('[minutes]','FontSize',labelSize)
    ylabel('[bara]','FontSize',labelSize)
end
    

% Mass Production Flow
subplot(3,1,2)
set(gca,'FontSize',gcaSize);
plot(t,wmix_r_out,'k','linewidth',1);
title('Mass Production Flow','FontSize',titleSize,'FontWeight','bold')
xlabel('[minutes]','FontSize',labelSize)
ylabel('[kg/s]','FontSize',labelSize)
set(gca,'FontSize',gcaSize);


% Valve Opening
subplot(3,1,3)
set(gca,'FontSize',gcaSize);
plot(t,U*100,'k','linewidt',1);
title('Control Signal: Production Choke Opening (z1)','FontSize',titleSize,'FontWeight','bold')
xlabel('[minutes]','FontSize',15)
ylabel('[Percent]','FontSize',15)
ylim([-10 110]);
set(gca,'FontSize',gcaSize);

figure()
set(gcf,'Color',[1,1,1])
grey = [0.4,0.4,0.4];
plot(t,p_bh+noise,'Color',grey)
hold on;
plot(t,p_bh_est,'-r','linewidth',1);
hold on;
plot(t,p_bh,'--y','linewidth',1);
set(gca,'FontSize',gcaSize);
title('Bottom Hole Pressure ','FontSize',titleSize,'FontWeight','bold')
legend('Noisy Measurement','Estimate','Real')
xlabel('[minutes]','FontSize',labelSize)
ylabel('[bara]','FontSize',labelSize)

end

%% Plotting Cascade Control
if (0)
figure()
set(gcf,'Color',[1,1,1])

subplot(4,1,1)
plot(t,p_at,'k','linewidth',1);
hold on;
setpoint= linspace(1,1,length(t))*p_at(1);
plot(t,setpoint,'--b','linewidth',1);
hold on;
plot(ControlStart/60,setpoint(1) , 'rx','MarkerSize',15,'Linewidt',2);
title('Annulus Top Pressure (outer loop)','FontSize',titleSize,'FontWeight','bold')
xlabel('[minutes]','FontSize',labelSize)
ylabel('[bara]','FontSize',labelSize)
legend('measurement','setpoint','Control Start');
set(gca,'FontSize',gcaSize);

subplot(4,1,2)
plot(t,p_tt,'k','linewidth',1);
hold on;
setpoint=[p_tt(1:ControlStart);U_inner];
plot(t,setpoint,'--b','linewidth',1);
hold on;
plot(ControlStart/60,setpoint(floor(ControlStart/60)) , 'rx','MarkerSize',15,'Linewidt',2);
title('Tubing Top Pressure (inner loop)','FontSize',titleSize,'FontWeight','bold')
xlabel('[minutes]','FontSize',labelSize)
ylabel('[bara]','FontSize',labelSize)
%legend('measurement','setpoint','Control Start','Disturbance Start');
legend('measurement','setpoint','Control Start');
set(gca,'FontSize',gcaSize);
ylim([0 100]);

subplot(4,1,3)
plot(t,wmix_r_out,'k','linewidth',1);
title('Mass Production Flow','FontSize',titleSize,'FontWeight','bold')
xlabel('[minutes]','FontSize',labelSize)
ylabel('[kg/s]','FontSize',labelSize)
set(gca,'FontSize',gcaSize);

subplot(4,1,4)
plot(t,U*100,'k','linewidt',1);
title('Control Signal: Production Choke Opening (z1)','FontSize',titleSize,'FontWeight','bold')
xlabel('[minutes]','FontSize',labelSize)
ylabel('[Percent]','FontSize',labelSize)
ylim([-10 110]);
set(gca,'FontSize',gcaSize);
end


%% LQR State Feedback
if (0)
figure()
set(gcf,'Color',[1,1,1])

subplot(3,1,1)
plot(t,p_at,'k','linewidth',1);
hold on;
setpoint= linspace(1,1,length(t))*p_at(1);
plot(t,setpoint,'--b','linewidth',1);
hold on;
plot(ControlStart/60,setpoint(1) , 'rx','MarkerSize',15,'Linewidt',2);
title('Annulus Top Pressure (outer loop)','FontSize',titleSize,'FontWeight','bold')
xlabel('[minutes]','FontSize',labelSize)
ylabel('[bara]','FontSize',labelSize)
legend('measurement','setpoint','Control Start');
set(gca,'FontSize',gcaSize);

subplot(3,1,2)
plot(t,wmix_r_out,'k','linewidth',1);
title('Mass Production Flow','FontSize',titleSize,'FontWeight','bold')
xlabel('[minutes]','FontSize',labelSize)
ylabel('[kg/s]','FontSize',labelSize)
set(gca,'FontSize',gcaSize);

subplot(3,1,3)
plot(t,U*100,'k','linewidt',1);
title('Control Signal: Production Choke Opening (z1)','FontSize',titleSize,'FontWeight','bold')
xlabel('[minutes]','FontSize',labelSize)
ylabel('[Percent]','FontSize',labelSize)
ylim([-10 110]);
set(gca,'FontSize',gcaSize);


figure()
set(gcf,'Color',[1,1,1])
subplot(3,1,1)
setpoint=linspace(1,1,length(t))*X(1,1);
plot(t,setpoint,'--b','linewidth',linewidth);
hold on;
plot(t,X(:,1),'-k','linewidth',linewidth);
title('Mass of Gas in Annulus (x1) ','FontSize',titleSize,'FontWeight','bold');
xlabel('[minutes]','FontSize',labelSize);
ylabel('[Kg]','FontSize',labelSize);
legend('setpoint','measurement')
set(gca,'FontSize',gcaSize);

subplot(3,1,2)
setpoint=linspace(1,1,length(t))*X(1,2);
plot(t,setpoint,'--b','linewidth',linewidth);
hold on;
plot(t,X(:,2),'-k','linewidth',linewidth);
title('Mass of Gas in Tubing (x2) ','FontSize',titleSize,'FontWeight','bold');
xlabel('[minutes]','FontSize',labelSize);
ylabel('[Kg]','FontSize',labelSize);
legend('setpoint','measurement')
set(gca,'FontSize',gcaSize);

subplot(3,1,3)
setpoint=linspace(1,1,length(t))*X(1,3);
plot(t,setpoint,'--b','linewidth',linewidth);
hold on;
plot(t,X(:,3),'-k','linewidth',linewidth);
legend('setpoint','measurement')
title('Mass of Liquid in Tubing (x3) ','FontSize',titleSize,'FontWeight','bold');
xlabel('[minutes]','FontSize',labelSize);
ylabel('[Kg]','FontSize',labelSize);
set(gca,'FontSize',gcaSize);

end

%% LQG Controller
if (0)
figure()
set(gcf,'Color',[1,1,1])

subplot(3,1,1)
plot(t,p_at,'k','linewidth',1);
hold on;
setpoint= linspace(1,1,length(t))*p_at(1);
plot(t,setpoint,'--b','linewidth',1);
hold on;
plot(ControlStart/60,setpoint(1) , 'rx','MarkerSize',15,'Linewidt',2);
title('Annulus Top Pressure (outer loop)','FontSize',titleSize,'FontWeight','bold')
xlabel('[minutes]','FontSize',labelSize)
ylabel('[bara]','FontSize',labelSize)
legend('measurement','setpoint','Control Start');
set(gca,'FontSize',gcaSize);

subplot(3,1,2)
plot(t,wmix_r_out,'k','linewidth',1);
title('Mass Production Flow','FontSize',titleSize,'FontWeight','bold')
xlabel('[minutes]','FontSize',labelSize)
ylabel('[kg/s]','FontSize',labelSize)
set(gca,'FontSize',gcaSize);

subplot(3,1,3)
plot(t,U*100,'k','linewidt',1);
title('Control Signal: Production Choke Opening (z1)','FontSize',titleSize,'FontWeight','bold')
xlabel('[minutes]','FontSize',labelSize)
ylabel('[Percent]','FontSize',labelSize)
ylim([-10 110]);
set(gca,'FontSize',gcaSize);

figure()
set(gcf,'Color',[1,1,1])
subplot(3,1,1)
setpoint=linspace(1,1,length(t))*X(1,1);
plot(t,setpoint,'--k','linewidth',linewidth);
hold on;
plot(t,X_est(:,1),'-r','linewidth',linewidth);
hold on;
plot(t,X(:,1),'--b','linewidth',linewidth);
title('Mass of Gas in Annulus (x1) ','FontSize',titleSize,'FontWeight','bold');
xlabel('[minutes]','FontSize',labelSize);
ylabel('[Kg]','FontSize',labelSize);
legend('setpoint','estimate','real')
set(gca,'FontSize',gcaSize);

subplot(3,1,2)
setpoint=linspace(1,1,length(t))*X(1,2);
plot(t,setpoint,'--k','linewidth',linewidth);
hold on;
plot(t,X_est(:,2),'-r','linewidth',linewidth);
hold on;
plot(t,X(:,2),'--b','linewidth',linewidth);
title('Mass of Gas in Tubing (x2) ','FontSize',titleSize,'FontWeight','bold');
xlabel('[minutes]','FontSize',labelSize);
ylabel('[Kg]','FontSize',labelSize);
legend('setpoint','estimate','real')
set(gca,'FontSize',gcaSize);

subplot(3,1,3)
setpoint=linspace(1,1,length(t))*X(1,3);
plot(t,setpoint,'--k','linewidth',linewidth);
hold on;
plot(t,X_est(:,3),'-r','linewidth',linewidth);
hold on;
plot(t,X(:,3),'--b','linewidth',linewidth);
legend('setpoint','estimate','real')
title('Mass of Liquid in Tubing (x3) ','FontSize',titleSize,'FontWeight','bold');
xlabel('[minutes]','FontSize',labelSize);
ylabel('[Kg]','FontSize',labelSize);
set(gca,'FontSize',gcaSize);

figure()
set(gcf,'Color',[1,1,1])
grey = [0.4,0.4,0.4];
plot(t,p_bh+noise,'Color',grey)
hold on;
plot(t,p_bh_est,'-r','linewidth',1);
hold on;
plot(t,p_bh,'--y','linewidth',2);
set(gca,'FontSize',gcaSize);
title('Bottom Hole Pressure ','FontSize',titleSize,'FontWeight','bold')
legend('Noisy Measurement','Estimate','Real')
xlabel('[minutes]','FontSize',labelSize)
ylabel('[bara]','FontSize',labelSize)
end
