clear all;
warning off;

% Load the file data
data=readtable('data_ad.txt');

% Get the columns

text = "\tLC\tKp level\tTi Level\tSP level\tTC\tKp temp\tTi tem\tSP temp\t\NetE\n";

t=table2array(data(:,1));           % time
Fin=table2array(data(:,2));         % Fin
Sbvsin=table2array(data(:,3));      % Sbvsin
Svfain=table2array(data(:,4));      % Svfain
Xacid_in=table2array(data(:,5));    % Xacid_in
Xmeth_in=table2array(data(:,6));    % Xmeth_in
Troom=table2array(data(:,7));       % Troom
Tfeed=table2array(data(:,8));       % Tfeed
Pheat=table2array(data(:,9));       % Pheat
Vtank=table2array(data(:,10));      % Vtank
Fout=table2array(data(:,11));       % Fout
Sbvs=table2array(data(:,12));       % Sbvs
Svfa=table2array(data(:,13));       % Svfa
Xacid=table2array(data(:,14));      % Xacid
Xmeth=table2array(data(:,15));      % Xmeth
Treac=table2array(data(:,16));      % Treac
V=table2array(data(:,17));          % V
Level=table2array(data(:,18));      % Level
Fmeth=table2array(data(:,19));      % Fmeth
Pmeth=table2array(data(:,20));      % Pmeth
LC=table2array(data(:,21));         % LC
KpLC=table2array(data(:,22));       % KpLC
TiLC=table2array(data(:,25));       % TiLC
SPLC=table2array(data(:,24));       % SPLC
TC=table2array(data(:,25));         % TC
KpTC=table2array(data(:,26));       % KpTC
TiTC=table2array(data(:,27));       % TiTC
SPTC=table2array(data(:,28));       % SPTC
NetE=table2array(data(:,29));       % NetE

% Note: the meaning for the columns can be found in the first 
% row of the data table.

%% Show graphical results for concentration variables

figure
subplot(2,2,1)
plot(t,Sbvs);
ylabel('Sbvs [g BVS/L]');xlabel('Time (d)');
subplot(2,2,2)
plot(t,Sbvs);
ylabel('Svfa [g VFA/L]');xlabel('Time (d)');
subplot(2,2,3)
plot(t,Xacid)
ylabel('Xacid [g acidogens/L]');xlabel('Time (d)');
subplot(2,2,4)
plot(t,Xmeth)
ylabel('Xmeth [g methanogens/L]');xlabel('Time (d)');
suptitle('Concentration variables')

%% Show graphical results for controlled variables

figure
subplot(2,2,1)
plot(t,SPTC,'r');hold on;
plot(t,Treac,'b');
ylabel('Treac [ºC]');xlabel('Time (d)');
subplot(2,2,2)
plot(t,Pheat);
ylabel('Pheat [W]');xlabel('Time (d)');
subplot(2,2,3)
plot(t,SPLC,'r');hold on;
plot(t,Level,'b');
ylabel('Level [m]');xlabel('Time (d)');
subplot(2,2,4)
plot(t,Fout)
ylabel('Fout [L/d]');xlabel('Time (d)');
suptitle('Controlled variables')

%% Show graphical results for production variables

figure
subplot(3,1,1)
plot(t,Fmeth);
ylabel('Fmeth [L CH4/d]');xlabel('Time (d)');
subplot(3,1,2)
plot(t,Pmeth);
ylabel('Pmeth [W]');xlabel('Time (d)');
subplot(3,1,3)
plot(t,NetE);
ylabel('NetE [W]');xlabel('Time (d)');
suptitle('Production variables')



