%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
%~~~~~~~~~~   The file is used to import simulation data   ~~~~~~~~~~~~~~~%
%~~~~~~~~~~~~~~~~   from both Unisim and D-spice   ~~~~~~~~~~~~~~~~~~~~~~~%
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
%~~~~~~~~~~~~~~~~~~~~ Procedure:  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
% Run D-spice for 15 minutes, do a 1% negativ step in MV, run for 2 hours %
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%

clc
clf
clear all;
close all;


data_uni=importfile_unisim('U_Fitting_butanesplitter_fullrate.csv');
data= importfile('D_Fitting_butanesplitter_fullrate.txt');
D_time_min=data(:,1)/60;
D_time_hr=data(:,1)/60/60;




%%
%Generate plot
figure (1)
subplot (2,2,1)
plot(time_min, TC_CV)
grid on
xlabel('time [min]')
ylabel('Temperature [^{0}C]')


subplot(2,2,2)
plot(time_min, TC_MV)
grid on
xlabel('time [min]')
ylabel('Output in Temperature controller')

subplot(2,2,3)
plot(time_min, Comp_B)
grid on
xlabel('time [min]')
ylabel('Impurity in bottom product')

subplot(2,2,4)
plot(time_min, Comp_D)
grid on
xlabel('time [min]')
ylabel('Impurity in top product')

%Ploter Unisim

figure(2)
[AX,H1,H2]=plotyy(time_min, TC_CV, time_min, TC_MV);
set(get(AX(1),'Ylabel'),'String','Measured value in TC (CV)');
set(get(AX(2),'Ylabel'),'String','Output in TC (MV)');
grid on
legend('Step respons', 'Step')
%title('Open loop Step response in temperature controller','BackgroundColor',[.99 .99 .99])
% set(get(AX(1)),axis([0 120 52.9 53.2 ]))
axis(AX(1), [0 116 52.2 52.7])
axis(AX(2), [0 116 58 60])


figure(3)
plot(time_min, Comp_B, time_min, Comp_D)
grid on
xlabel('time [min]')
ylabel('x_{i} [mol%]')
legend('x_{B,ic4}','x_{D,c4}')
axis([0 116 0 3])


%Ploter D-spice

figure(4)
[AX1,H3,H4]=plotyy(D_time_min, data(:,3), D_time_min, data(:,5));
set(get(AX1(1),'Ylabel'),'String','Measured value in TC (CV)');
set(get(AX1(2),'Ylabel'),'String','Output in TC (MV)');
grid on
legend('Step respons', 'Step')
%title('Open loop Step response in temperature controller','BackgroundColor',[.99 .99 .99])
% set(get(AX(1)),axis([0 120 52.9 53.2 ]))
axis(AX1(1), [0 116 48.9 49.4])
axis(AX1(2), [0 116 54.5 56.5])


figure(5)
plot(D_time_min, data(:,9), D_time_min, data(:,7))
grid on
xlabel('time [min]')
ylabel('x_{i} [mol%]')
legend('x_{B,ic4}','x_{D,c4}', 'Location','East')
axis([0 116 0 3])







