%% Plotting Experimental MPC Results

clc
close all

%% 12.05

T = readtable('ExpDataMPC/Data_12.05.xlsx');
T1 = readtable('ExpDataMPC/OilPPM.xlsx');
xSP = 28;

%% Reading data

Zo = T{:,2};
betaIn = T{:,3};
timeElapsed = T{:,4};
t = T{:,6};
betaU = T1{:,2};
Qin = T{:,8};
Qu = T{:,9};
betaUpred = T{:,10};

td=T1{:,1};
t_1=td(1);
t_2=td(length(td));
t11=datevec(datenum(t_1));
t22=datevec(datenum(t_2));
tduration=etime(t22,t11);

tseries1=0:tduration/length(td):tduration-1;

%% Plot


set(groot, 'defaultTextInterpreter','latex');
set(groot, 'defaultAxesTickLabelInterpreter','latex');
set(groot, 'defaultLegendInterpreter','latex');

xL = 22;
figure('visible', 'on')
subplot(4,1,1)
stairs(t,Zo, 'b')
xlim([377 770])
ylim([5.5 7.5])
ylabel('$Z_O$ [\%]')
% title('MV - Overflow Valve Opening')
% 
% subplot(5,1,2)
% plot(betaU)
% hold on
% yline(xSP, 'r')

% title('BetaU Measured')

subplot(4,1,2)
plot(t, betaUpred, 'b')
hold on
plot(tseries1, betaU, 'g')
hold on
yline(xSP, '--r')
hold on
yline(xL, '--r')
xlim([377 770])
ylim([10 35])
legend('Predicted', 'Measured', 'location', 'southeast', 'fontsize', 6)
ylabel('$\beta_{U,o}$ [ppm]')
% title('CV - Underflow Oil Concentration (Prediction)')

subplot(4,1,3)
plot(t,Qin, 'b')
xlim([377 770])
ylim([3.8 4.25])
% title('DV1 - Flowrate Inlet')
ylabel('$Q_{in}$ [m$^3$/h]')

subplot(4,1,4)
plot(t,betaIn, 'b')
xlim([377 770])
ylim([290 355])
ylabel('$\beta_{in,o}$ [ppm]')
xlabel('$t$ [s]')
% title('DV2 - Oil Concentration Inlet')

% figure
% plot(t, betaUpred)
% hold on
% plot(t, betaU)
% hold on
% yline(xSP, 'r')
% xlim([400 762])
% title('BetaU Predicted')

saveas(gcf,[pwd '/Figures/MPC_InletConcentration_12_05'],'epsc')
