%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
%~~~~~~~~~~~~   The file is used to define constraints,   ~~~~~~~~~~~~~~~~%
%~~~~~~~~~  import data with "importfile.m" (from D-spice) and  ~~~~~~~~~~%
%~~~~~~~~~~~~~~~  "importfile_unisim.m" (from Unisim)  ~~~~~~~~~~~~~~~~~~~%
%~~~~~~~~~~~~~~~~~~~  and plot the simulation data   ~~~~~~~~~~~~~~~~~~~~~%
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%

clc
clf
clear all;
close all;


%Import '.csv' files from Unisim and '.txt' from D-Spice:

%Operation point 1
data_uni=importfile_unisim('Data_Unisim_fullrate.csv');
data= importfile('Data_D-Spice_fullrate.txt');

%Operation point 2
%data_uni=importfile_unisim('Data_Unisim_halfrate_prof.csv');
%data= importfile('Data_D-Spice_halfrate_prof.txt');

%Operation point 3
%data_uni=importfile_unisim('Data_Unisim_halfrate_nonprof.csv');
%data= importfile('Data_D-Spice_halfrate_nonprof.txt');

%Operation point 3, retuned
%data_uni=importfile_unisim('Data_Unisim_halfrate_nonprof_retuned.csv');
%data= importfile('Data_D-Spice_halfrate_nonprof_retuned.txt');


% Define time from D-spice
D_time_min=data(:,1)/60;
D_time_hr=data(:,1)/60/60;


%%
%Define limits

%TC
TC_CV=[80 90;
       78 86;
       48 53]; %from Unisim
TC_MV=[4.6865e7 1.1716e8;
       1.7763E+07 4.4407E+07;
       3.9933E+07 9.9834E+07]; %Self defined

%Product streams
Comp_limit_D=[0 2;
              0 1.5
              0 4];
Comp_set_D=[0.95; 0.518; 2];
Comp_limit_B=[0 2;
              0 4;
              0 2.5];
Comp_set_B=[0.2; 1; 1.25];

%PC
PC1_set= [13.5; 4.7; 4.6];

%FC
FC_limit= 10^5*[1.3 2.0; %min--> Septic ~= Unisim
           0.572 0.956;  %min--> Septic(4.5e4) < Unisim(5.72e4)
           1.675 2.808]; %min--> Septic(1.5e5) < Unisim(1.675e5)

%LC
LC_limit=[30 70;
          30 70;
          30 70];
LC_set=[50; 50; 50];

%First and last time measure
t=[time_hr(1) time_hr(end)];
tl=t(1):0.05:t(2); %used to draw constraints for TC
tl2=t(1):0.1:t(2); %used to draw constraints for all of the other controllers


%%
%Generate the plots
Ploter

%Save the plots
Saver



