%Plot simulation results from MPC
clc
clear all
close all

s1='MPC';
s3='_newsim';
num=3; %case: 1, 2, 3, 4
name=strcat(s1,num2str(num),s3);

load(name,'-mat')
hinit = 0.5;
uinit = 0.5;
par.tf=0.1;
par.simtime=200;
Linewidth=1.3;
%a=ones(2000);
hmin=[0.1,0.1];
hmax=[0.9,0.9];
hminmin=[0,0];
hmaxmax=[1,1];
hsp=[0.5,0.5];
tim=[0,par.simtime];
%%
figure(1);
clf
subplot(211)
plot(0:par.tf:par.simtime,[vertcat(hinit,sim.x(:,1))],'k','LineWidth',Linewidth)
title('MPC')
hold on
% line([0 par.simtime],[0.9 0.9],'Color',[255/255 165/255 0/255])
% line([0 par.simtime],[0.1 0.1],'Color',[255/255 165/255 0/255])
% line([0 par.simtime],[0.5 0.5],'Color',[0 165/255 115/255])
plot(tim,hmin,'--','Color',[255/255 165/255 0/255])
plot(tim,hmax,'--','Color',[255/255 165/255 0/255])
plot(tim,hminmin,'--r')
plot(tim,hmaxmax,'--r')
plot(tim,hsp,'--','Color',[0 165/255 115/255])
ylim([-0.1 1.1]); grid on; grid minor; ylabel('Level [m]')

subplot(212)
%plot(0:par.tf:par.simtime,[horzcat(0.5,qin)],'b')
%hold on
%stairs(0:par.tf:par.simtime,[horzcat(uinit,sim.u)],'r')
%stairs(0:par.tf:par.simtime,[horzcat(uinit,sim.u)],'Color', [50/255 205/255 50/255],'LineWidth',1.5)
stairs(0:par.tf:par.simtime,[horzcat(uinit,sim.u)],':k','LineWidth',2)
ylim([-0.1 1.1]); grid on; grid minor
xlabel('time [s]');ylabel('Outflow [m^3/s]')

%save figure
fig = figure (1);
fig.PaperUnits = 'inches';
fig.PaperPosition = [0 0 8 5];
namefile=strcat('figures/MPC',num2str(num));
saveas (figure (1), namefile,'eps2c');

