%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
%~~~~~~~~~~~~~~~~~~~   The file generates plots   ~~~~~~~~~~~~~~~~~~~~~~~~%
%~~~~~~~~~~~~~~~   Importfile.m should be run first   ~~~~~~~~~~~~~~~~~~~~%
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%


%Merg columns of all threee columns
TIC_X04=[TIC_104; TIC_204; TIC_304];
Comp_D=[Comp1_D; Comp2_D; Comp3_D];
Comp_B=[Comp1_B; Comp2_B; Comp3_B];
PIC_X01=[PIC_101; PIC_201; PIC_301];
FIC_X00=[FIC_100; FIC_200; FIC_300];
LIC_X02= [LIC_102; LIC_202; LIC_302];
LIC_X03= [LIC_103; LIC_203; LIC_203];


n=length(TIC_104);
nr=0;

%Ploting

k=0;
for k=0:2

%TC
nr=nr+1;
f(nr)=figure (nr);
set(f(nr),'WindowStyle','normal') 
subplot(2, 2, [1 2])
plot(time_hr, TIC_X04(k*n+1:k*n+n,1), D_time_hr, data(:,3+16*k))
hold on
p(1)=plot(tl, TC_CV(k+1,2)*ones(length(tl),1), '^');
p(2)=plot(tl, TC_CV(k+1,1)*ones(length(tl),1), 'v');
%title('Depropaniser','BackgroundColor',[.99 .99 .99])
grid on
xlabel('time [hr]')
ylabel('TC (CV) [^oC]')
if k==2
    TC_min= TC_CV(k+1,1)-0.5; TC_max=TC_CV(k+1,2)+0.5;
else
    TC_min= TC_CV(k+1,1)-5; TC_max=TC_CV(k+1,2)+4.5;
end
axis([time_hr(1) time_hr(end) TC_min TC_max])
legend('Unisim', 'D-spice')


subplot(2, 2, [3 4])
plot(time_hr, TIC_X04(k*n+1:k*n+n,2), D_time_hr, data(:,5+16*k)*3600)
hold on
p(3)=plot(tl, TC_MV(k+1,2)*ones(length(tl),1), '^');
p(4)=plot(tl, TC_MV(k+1,1)*ones(length(tl),1), 'v');
grid on
xlabel('time [hr]')
ylabel('TC (MV) [kJ/h]')
axis([time_hr(1) time_hr(end) TC_MV(k+1,1)*0.7 TC_MV(k+1,2)*1.15])
legend('Unisim', 'D-spice')


%Impurity in distillate
nr=nr+1;
f(nr)=figure(nr);
plot(time_hr, Comp_D(k*n+1:k*n+n), D_time_hr, data(:,15+16*k))
hold on
p(5)=plot(tl2, Comp_limit_D(k+1,2)*ones(length(tl2),1), '^');
p(6)=plot(tl2, Comp_limit_D(k+1,1)*ones(length(tl2),1), 'v');
pset(1)=plot(tl2, Comp_set_D(k+1)*ones(length(tl2),1), '-.');
grid on
xlabel('time [hr]')
ylabel('Impurity in D[%]')
axis([time_hr(1) time_hr(end) Comp_limit_D(k+1,1)-0.1  Comp_limit_D(k+1,2)+2])
legend('Unisim', 'D-spice')

%Impurity in bottom product
nr=nr+1;
f(nr)=figure(nr);
plot(time_hr, Comp_B(k*n+1:k*n+n), D_time_hr, data(:,17+16*k))
hold on
p(7)=plot(tl2, Comp_limit_B(k+1,2)*ones(length(tl2),1), '^');
p(8)=plot(tl2, Comp_limit_B(k+1,1)*ones(length(tl2),1), 'v');
pset(2)=plot(tl2, Comp_set_B(k+1)*ones(length(tl2),1), '-.');
grid on
xlabel('time [hr]')
ylabel('Impurity in B [%]')
axis([time_hr(1) time_hr(end) Comp_limit_B(k+1,1)-0.1  Comp_limit_B(k+1,2)+0.5])
legend('Unisim', 'D-spice')

%PC
nr=nr+1;
f(nr)=figure(nr);
%set(f2,'PaperType','A3','PaperSize',[29.681205808 41.948713346])
plot(time_hr, PIC_X01(k*n+1:k*n+n,1)/100, D_time_hr, data(:,13+16*k))
hold on
pset(3)=plot(tl2, PC1_set(k+1)*ones(length(tl2),1), '-.');
grid on
xlabel('time [hr]')
ylabel('PC (CV) [bar]')
axis([time_hr(1) time_hr(end) PC1_set(k+1)-0.2 PC1_set(k+1)+0.2])
legend('Unisim', 'D-spice')

%FIC
nr=nr+1;
f(nr)=figure(nr);
plot(time_hr, FIC_X00(k*n+1:k*n+n,1), D_time_hr, data(:,7+16*k))
hold on
p(9)=plot(tl2, FC_limit(k+1,2)*ones(length(tl2),1), '^');
p(10)=plot(tl2, FC_limit(k+1,1)*ones(length(tl2),1), 'v');
grid on
xlabel('time [hr]')
ylabel('FC (CV) [kg/h]')
axis([time_hr(1) time_hr(end) FC_limit(k+1,1)-2.5e4 FC_limit(k+1,2)+2e3])
legend('Unisim', 'D-spice')

%LC condenser
nr=nr+1;
f(nr)=figure(nr);
plot(time_hr, LIC_X02(k*n+1:k*n+n,1), D_time_hr, data(:,9+16*k))
hold on
p(11)=plot(tl2, LC_limit(k+1,2)*ones(length(tl2),1), '^');
p(12)=plot(tl2, LC_limit(k+1,1)*ones(length(tl2),1), 'v');
pset(4)=plot(tl2, LC_set(k+1)*ones(length(tl2),1), '-.');
grid on
xlabel('time [hr]')
ylabel('LC in condenser (CV) [%]')
axis([time_hr(1) time_hr(end) 20 80 ])
legend('Unisim', 'D-spice')

%LC reboiler
nr=nr+1;
f(nr)=figure(nr);
plot(time_hr, LIC_X03(k*n+1:k*n+n,1), D_time_hr, data(:,11+16*k))
hold on
p(13)=plot(tl2, LC_limit(k+1,2)*ones(length(tl2),1), '^');
p(14)=plot(tl2, LC_limit(k+1,1)*ones(length(tl2),1), 'v');
pset(5)=plot(tl2, LC_set(k+1)*ones(length(tl2),1), '-.');
grid on
xlabel('time [hr]')
ylabel('LC in reboiler (CV) [%]')
axis([time_hr(1) time_hr(end) 20 80 ])
legend('Unisim', 'D-spice')


%
% Div setings

%Visual settings on constraints and setpoints
%p=[p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18];
%pset=[pset1, pset2, pset3, pset4, pset5];
set(p, 'MarkerSize', 1.8, 'color', [0.4 0.4 0.4]);
set(pset,'LineWidth', 0.6, 'color', [0 0 0]);

%Size of the plot (dock/undok is used)

hold off
%reset(gcf)
end
set([f(2:7) f(9:14) f(16:21)], 'WindowStyle','docked')
set([f(2:7) f(9:14) f(16:21)],'PaperPositionMode','auto')

