clc;
clear all;
close all;

%script for reading and plotting the excel results

%results=xlsread('M:\Diplom\kaibel_test_results_working_prefrac_split.xls',
%'sheet1','b7:bf35');


%Extracting results from the excel worksheet:
reflux=xlsread('M:\Diplom\kaibel_50stages_reflux12.xls','sheet1','b7:b28');
tempprofilecolumn1=xlsread('M:\Diplom\kaibel_50stages_reflux12.xls','sheet1','c7:ai28');
tempprofilecolumn2=xlsread('M:\Diplom\kaibel_50stages_reflux12.xls','sheet1','aj7:az28');
heatduty=xlsread('M:\Diplom\kaibel_50stages_reflux12.xls','sheet1','ba7:ba28');
prodstreamD=xlsread('M:\Diplom\kaibel_50stages_reflux12.xls','sheet1','bb7:be28');
prodstreamS1=xlsread('M:\Diplom\kaibel_50stages_reflux12.xls','sheet1','bf7:bi28');
prodstreamS2=xlsread('M:\Diplom\kaibel_50stages_reflux12.xls','sheet1','bj7:bm28');
prodstreamB=xlsread('M:\Diplom\kaibel_50stages_reflux12.xls','sheet1','bn7:bq28');
nstage=xlsread('M:\Diplom\kaibel_50stages_reflux12.xls','sheet1','bz7:bz7');
prodstream_frac_sum=xlsread('M:\Diplom\kaibel_50stages_reflux12.xls','sheet1','cb7:cb28');


%Defining which variables/runs/results to use:
enter=0;

if enter==1;
x=[2 5 8];
l=length(x);

reflux_original = reflux;
tempprofilecolumn1_original = tempprofilecolumn1;
tempprofilecolumn2_original = tempprofilecolumn2;
heatduty_original = heatduty;
prodstreamD_original = prodstreamD;
prodstreamS1_original = prodstreamS1;
prodstreamS2_original = prodstreamS2;
prodstreamB_original = prodstreamB;
prodstream_frac_sum_original = prodstream_frac_sum;


reflux=[];
tempprofilecolumn1=[];
tempprofilecolumn2=[];
heatduty=[];
prodstreamD=[];
prodstreamS1=[];
prodstreamS2=[];
prodstreamB=[];
prodstream_frac_sum=[];


    for i=1:l;
    
        reflux(i,:) = reflux_original(x(i),:);
        tempprofilecolumn1(i,:) = tempprofilecolumn1_original(x(i),:);
        tempprofilecolumn2(i,:) = tempprofilecolumn2_original(x(i),:);
        heatduty(i,:) = heatduty_original(x(i),:);
        prodstreamD(i,:) = prodstreamD_original(x(i),:);
        prodstreamS1(i,:) = prodstreamS1_original(x(i),:);
        prodstreamS2(i,:) = prodstreamS2_original(x(i),:);
        prodstreamB(i,:) = prodstreamB_original(x(i),:);
        prodstream_frac_sum(i,:) = prodstream_frac_sum_original(x(i),:);
        
    end    
end

    
[runs,nstage1]=size(tempprofilecolumn1);
[runs,nstage2]=size(tempprofilecolumn2);

n1=(1:nstage1);
n2=(1:nstage2);

nsplittop=7;        %the plate where the TOP connect streams are connected (on column 1).
nsplittbottom=27;   %the plate where the BOTTOM connect streams are connected (on column 1).

n2stage_rel_to_1_temp=linspace(nsplittop+1,nsplittbottom-1,length(n2))+.nsplittop;
n2stage_rel_to_1=[(1:nsplittop) n2stage_rel_to_1_temp (nsplittbottom:nstage1)];

tempprofilecolumn2_1=[tempprofilecolumn1(:,1:nsplittop) tempprofilecolumn2 tempprofilecolumn1(:,nsplittbottom:nstage1)];

plotit=0;
if plotit==1
figure

%plot(n1,tempprofilecolumn1,'b',n2stage_rel_to_1,tempprofilecolumn2_1,'y');
hold on;
plot(n1,tempprofilecolumn1(1,:),':b',n2stage_rel_to_1,tempprofilecolumn2_1(1,:),'-.b');
plot(n1,tempprofilecolumn1(2,:),'-y',n2stage_rel_to_1,tempprofilecolumn2_1(2,:),'--y');
plot(n1,tempprofilecolumn1(3,:),'-r',n2stage_rel_to_1,tempprofilecolumn2_1(3,:),'--r');
%legend(['rv=',num2str(rv(1)),', temp profile column 1'],['rv=',num2str(rv(1)),', temp profile column 2'],['rv=',num2str(rv(2)),', temp profile column 1'],['rv=',num2str(rv(2)),', temp profile column 2']);
legend(['rv=',num2str(rv(1)),', temp profile column 1'],['rv=',num2str(rv(1)),', temp profile column 2'],['rv=',num2str(rv(2)),', temp profile column 1'],['rv=',num2str(rv(2)),', temp profile column 2'],['rv=',num2str(rv(3)),', temp profile column 1'],['rv=',num2str(rv(3)),', temp profile column 2']);
hold off;
%title('temp profile of rv',num2str(x(1:i)),'plot')
else
    figure
    plot(reflux,prodstream_frac_sum,'-b'),xlabel('Reflux (L/D)'),ylabel('Sum x')
    figure
    plot(reflux,heatduty,'-b'),xlabel('Reflux (L/D)'),ylabel('Heat duty (V) [W]') %legend('Boil-up');

end
