%Plot process measurement and prediction
close all
clear all
 aux=open('solOPT.mat');
 sol=aux.solOPT;



Timevec=sol.t;
qhf=sol.qhf;
qhr=sol.qhr;
mr=sol.mr;
qair=sol.qair;
Tf=sol.Tf-273;
Tr=sol.Tr-273;
co2=sol.co2;
J=sol.J;
price=sol.price;
To=sol.To;
time=Timevec/3600;
t_f=time(end);


yrange1=[15 31];
yrange2=[15 31];
yrange3=[0 0.2];

urange1=[0 3.6];
urange2=[0 0.6];
urange3=[0 0.006];
Linewidth=1.5;


%green: optimal
color1=[102, 194, 165]/256;
%orange: open loop
color3=[252, 141, 98]/256;
%blue: SOC
color2=[141, 160, 203]/256;
%pink: disturbance
color4=[231, 138, 195]/256;
%light green: simple feedback
color5=[ 166, 216, 84]/256;
%yellow
color6=[255, 217, 47]/256;
%light brown
color7=[229, 196, 148 ]/256;
%black
color8=[0 0 0];

colordist=color8;


ppicky='C:\Users\viniciud\Documents\Vinicius\PhD NTNU\my papers\NTNU\DYCOPS2013\pics\';


figure(20)
subplot(211)
p1=plot(time,qhf,'LineWidth',Linewidth)
set(p1(1),'color',color1)
% set(p1(2),'color',color2)
set(gca,'FontSize',14)
ylabel('$Q_f$, kW','interpreter','latex')
 ylim([0 4])
xlim([0 24])

subplot(212)
p1=plot(time,qhr,'LineWidth',Linewidth)
set(p1(1),'color',color1)
set(gca,'FontSize',14)
ylabel('$Q_r$, kW','interpreter','latex')
ylim([0 .5])
xlim([0 24])

%  
%  subplot(313)
% % p1=plot(time,J,'LineWidth',Linewidth)
% % set(p1(1),'color',color1)
% % set(gca,'FontSize',14)
% % ylabel('Cost, \$','interpreter','latex')
% % xlabel('Time, h','interpreter','latex')
% % xlim([0 24])
% p1=plot(time,qair*3600,'LineWidth',Linewidth)
% set(p1(1),'color',color1)
% set(gca,'FontSize',14)
% ylabel('Air inflow, Kg/h','interpreter','latex')
% xlabel('Time, h','interpreter','latex')
% xlim([0 24])
% axis tight


return
%%
% axis tight
% subplot(313)
% p1=plot(time,qair,'LineWidth',Linewidth)
% set(p1(1),'color',color1)
% set(gca,'FontSize',14)
% xlabel('Time, h','interpreter','latex')
% ylabel('$q_{in}$, Kg/s','interpreter','latex')
% ylim(urange3)
% xlim([0 24])
% axis tight

figure(10)
subplot(312)
p1=plot(time,Tr,[0 t_f],[17 17],'--',[0 t_f],[30 30],'--','LineWidth',Linewidth)
set(p1(1),'color',color1)
set(p1(2),'color',rgb('gray'))
set(p1(3),'color',rgb('gray'))

set(gca,'FontSize',14)
ylabel('$T_r$, $^{\circ}C$','interpreter','latex')
ylim(yrange1)
xlim([0 24])
xlabel('Time, h','interpreter','latex')
subplot(311)
p1=plot(time,Tf,[0 t_f],[17 17],'--',[0 t_f],[30 30],'--','LineWidth',Linewidth)
set(p1(1),'color',color1)
set(p1(2),'color',rgb('gray'))
set(p1(3),'color',rgb('gray'))
set(gca,'FontSize',14)
% xlabel('Time, h','interpreter','latex')
ylabel('$T_f$, $^{\circ}C$','interpreter','latex')
% axis tight
ylim(yrange2)
 
xlim([0 24])



 subplot(313)
 ylim(yrange3)
 p1= plot(time,100*co2,[0 t_f],[0.1538 0.1538],'--','color',color1,'LineWidth',Linewidth)
set(p1(1),'color',color1)
set(p1(2),'color',rgb('gray'))
 
 %  plot(time,100*Yvec(:,4),'LineWidth',Linewidth)
  set(gca,'FontSize',14)
  xlabel('Time, h','interpreter','latex')
  ylabel('$CO_2$, \%','interpreter','latex')
 % axis tight
 ylim([0 0.2])
 xlim([0 24])
 
 

%%


figure(30)
subplot(211)
Topred=0*273+[-1.2 -1.1 -2.2 -1.7 -2.9 -3.6 -3.3 -4.2 -3.4 -1.9 -2.3 -3.5 -2.2 0.9 1.1 1.1 1.0 1.4 1.2 1.9 2.9 3.5 3.1 3.3];
hours=linspace(0,24,24);
p1=plot(time,To-273,'b','LineWidth',Linewidth)
set(p1(1),'color',colordist)
set(gca,'FontSize',14)
ylabel('$T_o$, $^{\circ}C$','interpreter','latex')
ylim([-5 +5])
xlim([0 24])

subplot(212)
p1=plot(time,price,'-','LineWidth',Linewidth)
set(p1(1),'color',colordist)
set(gca,'FontSize',14)
ylabel('Price, \$/kWh','interpreter','latex')
 xlabel('Time, h','interpreter','latex')
xlim([0 24])
ylim([0.9 3.1])

% saveas(gcf, 'C:\Users\viniciud\Documents\Vinicius\PhD NTNU\my papers\NTNU\DYCOPS2013\pics\nom_disturbances', 'epsc') 
% matlab2tikz([ppicky, 'nom_disturbances.tikz' ] );


 tilefigs

 
 
 %%============= test simple feedback
 
 simFeedback; 
%  ppicky='C:\Users\viniciud\Documents\Vinicius\PhD NTNU\my papers\NTNU\DYCOPS2013\pics\';

%%  
 figure(21)
 subplot(211)
 hold on
 p1=plot(timefeedback/3600,Qrfeedback,'LineWidth',Linewidth);
 set(p1(1),'color',color4)
set(gca,'FontSize',14)
 ylim(urange2)  
 ylabel('$Q_r$, kW','interpreter','latex')

 subplot(212)

 hold on
 p1=plot(timefeedback/3600,Tf_feedback,'LineWidth',Linewidth)
 set(gca,'FontSize',14)
 set(p1(1),'color',color4)
 ylim(yrange2)
 ylabel('$T_r$, $^{\circ}C$','interpreter','latex')
xlabel('Time, h')
 %%
 figure(20)
 subplot(3,1,3)
 hold on
 p1=plot(timefeedback/3600,costfeedback,'LineWidth',Linewidth);
 set(p1(1),'color',color4)
 ylim([0 max(costfeedback)+1])
 
 subplot(3,1,2)
 hold on
 p1=plot(timefeedback/3600,Qrfeedback,'LineWidth',Linewidth);
 set(p1(1),'color',color4)
%  ylim([0 max(Qrfeedback)])
 ylim(urange2) 
 
 subplot(3,1,1)
  hold on
 p1=plot(timefeedback/3600,zeros(size(timefeedback)),'LineWidth',Linewidth)
 set(p1(1),'color',color4)
ylim(urange1)
% saveas(gcf, 'C:\Users\viniciud\Documents\Vinicius\PhD NTNU\my papers\NTNU\DYCOPS2013\pics\nom_inputs', 'epsc') 
%  matlab2tikz([ppicky, 'nom_inputs.tikz' ] );



  figure(10)
 subplot(2,1,2)
 hold on
 p1=plot(timefeedback/3600,Tf_feedback,'LineWidth',Linewidth)
 set(p1(1),'color',color4)

 subplot(2,1,1)
 hold on
 p1=plot(timefeedback/3600,zeros(size(timefeedback))+17,'m','LineWidth',Linewidth)
 set(p1(1),'color',color4)

  
% saveas(gcf, 'C:\Users\viniciud\Documents\Vinicius\PhD NTNU\my papers\NTNU\DYCOPS2013\pics\nom_outputs', 'epsc') 
% matlab2tikz([ppicky, 'nom_outputs.tikz' ]);

 
 
 
 
 
 
 
 
 
 