clc;clear;close all
%% Plotting options
set(0,'DefaultTextFontName','Times',...
     'DefaultTextFontSize',14,...
     'DefaultAxesFontName','Times',...
     'DefaultAxesFontSize',14,...
     'DefaultLineLineWidth',4,...
     'DefaultLineMarkerSize',4,...
     'DefaultStairLineWidth',4)
orange  = [1 0.5 0];
green   = [0 0.5 0];
greencg = [83,188,102]/256;

teal    = [67 183 176]/256;
maroon  = [192 0 0]/256;
gold    = [255 192 0]/256;
skyblue = [39 141 251]/256;
indigo   = [0.2930 0 0.5078];
lilac    = [0.7383    0.5898    0.7930];
hotpink  = [0.8945    0.4102    0.5898];
cerulean = [0.1094    0.6641    0.8359];
plum     = [194, 147, 141]/256;
purple   = [176 27 129]/256;

pos     = [100 100 400 300]; % figure position on screen
poslgd  = [0.5888    0.6268    0.377    0.1963];
Vmax    = 5000; % [m3] maximum tank volume
Vmin    = 0;    % [m3] minimum tank volume
qmax    = 1000; % [m3/h] maximum flowrate
qmin    = 0;    % [m3/h] minimum flowrate
tend    = 30;   % [h] plot end time
%% Plot open loop step responses
filename = {'ResultsOL_qS','ResultsOL_qSP','ResultsOL_z'};
for i = 1:3
load(filename{i})

figure(i); % supply
figname = strcat(filename{i},'qS','.eps');
plot(tOL,dOL(:,1),'Color',orange)
xlabel('Time [h]');ylabel('Available supply [m^3/h]')
xlim([0 tend]); ylim([-100; 1100;])
legend('qS');legend boxoff
set(gcf,'Position',pos);print('-depsc2','-r600',figname)

figure(i+10); % hot water demand
figname = strcat(filename{i},'q','.eps');
plot(tOL,algOL(:,4),'Color',skyblue)
xlabel('Time [h]');ylabel('Hot water demand [m^3/h]')
xlim([0 tend]); ylim([-100; 1100;])
legend('q','Location','East');legend boxoff
set(gcf,'Position',pos); print('-depsc2','-r600',figname)

figure(i+20); % hot water tank volume
figname = strcat(filename{i},'V','.eps');
plot(tOL,ySRC(:,1),'red')
hold on
plot(tOL, Vmax-ySRC(:,1),'blue')
h = plot([tOL(1);tOL(end)],[Vmax;Vmax],'k--');
h.Annotation.LegendInformation.IconDisplayStyle = 'off';
h = plot([tOL(1);tOL(end)],[Vmin;Vmin],'k--');
xlabel('Time [h]'); ylabel('Hot water volume [m^3]')
xlim([0 tend]); ylim([-100; 5100])
legend('V_h','V_c','Location','East');  legend boxoff
set(gcf,'Position',pos); print('-depsc2','-r600',figname)

figure(i+30); % network pressure
figname = strcat(filename{i},'p','.eps');
plot(tOL,yOL(:,4),'Color',greencg)
legend('p'); legend boxoff
xlabel('Time [h]');ylabel('Network pressure [bar]')
xlim([0 tend]); ylim([3; 6;])
set(gcf,'Position',pos);print('-depsc2','-r600',figname)

figure(i+40); %MVs: qSP, qD, qTP, qEB
figname = strcat(filename{i},'u','.eps');
plot(tOL,uOL(:,1),'Color',gold)
hold on
plot(tOL,uOL(:,2),'Color',purple)
plot(tOL,uOL(:,3),'Color',teal)
plot(tOL,u(:,4),'Color',maroon)
h = plot([tOL(1);tOL(end)],[qmax;qmax],'k--');
h.Annotation.LegendInformation.IconDisplayStyle = 'off';
h = plot([tOL(1);tOL(end)],[qmin;qmin],'k:');
h.Annotation.LegendInformation.IconDisplayStyle = 'off';
lgd=legend('q_{SP}','q_D','q_{TP}','q_{EP}','Location','best'); legend boxoff
lgd.NumColumns=2; %lgd.Position=poslgd;
xlabel('Time [h]');ylabel('Manipulated variables [m^3/h]')
xlim([0 tend]); ylim([-100; 1100;])
set(gcf,'Position',pos);print('-depsc2','-r600',figname)

figure(i+50)
figname = strcat(filename{i},'z','.eps');
plot(tOL,uOL(:,5),'Color','k')
legend('z_C')
xlabel('Time [h]');ylabel('Valve opening [-]')
xlim([0 tend]); ylim([-0.05; 1.05;])
set(gcf,'Position',pos);print('-depsc2','-r600',figname)

end
