% Please rename the file run_cccMatlab.m
% Matlab script to batch run the cell cycle model cccMatlab.ode with XPPAUT

% XPPAUT needs to be installed. Modify the path to XPPAUT according to the configuration of the machine used (here it is the default path on Windows).

% The XPP-Matlab interface by Rob Clewley can be downloaded from http://www.math.pitt.edu/~bard/xpp/xpp.html

% The outpout is a set of text files created with XPPAUT and renamed with the command 'movefile'
% Each file corresponds to one run of cccMatlab.ode. There are 17 columns. Each column represents a variable:
% 1    2 3 4 5 6       7   8  9   10 11  12   13 14  15 16    17
% time N S P M sigma_S TOT LI G1I MI G2I G2MI SF TG2 TR CLOCK BT

% To import the data into Matlab, set the directory where the data in loadalldat.m are and run the script loadalldat.m

% 

% contact: S Bernard, samubernard@gmail.com

k=1 % 1: normal 2: fast growing tumor 3: slow growing tumor
typ={'BM','CF','CS'};

PARset(1).type='PAR';
PARset(1).name='tS';
ts=[15 7 20]; %ts=[15 7];
PARset(1).val=ts(k); 
PARset(2).type='PAR';
PARset(2).name='tP0';
PARset(2).val=2;
PARset(3).type='PAR';
PARset(3).name='tM';
PARset(3).val=3;
PARset(4).type='PAR';
PARset(4).name='beta0';
beta0=[0.04 0.06 0.06];
PARset(4).val=beta0(k);
PARset(5).type='PAR';
PARset(5).name='alpha';
alpha=[0.5 0.4 0.4]; % [0.5 0 0]; %
PARset(5).val=alpha(k);
PARset(6).type='PAR';
PARset(6).name='theta';
PARset(6).val=5.75; 
PARset(7).type='PAR';
PARset(7).name='theta2';
PARset(7).val=20;
PARset(8).type='PAR';
PARset(8).name='gS0';
gs0=[0.01 0.04 0.005];
PARset(8).val=gs0(k);
PARset(9).type='PAR';
PARset(9).name='gP0';
PARset(9).val=0.01;
PARset(10).type='PAR';
PARset(10).name='gM0';
gm0=[0.01 0 0];
PARset(10).val=gm0(k);
PARset(11).type='PAR';
PARset(11).name='delta0';
delta0=[0.004 0.006 0.006];
PARset(11).val=delta0(k);
PARset(12).type='PAR';
PARset(12).name='sensty';
PARset(12).val=2; % 3;
PARset(13).type='PAR';
PARset(13).name='killing';
PARset(13).val=0; %8; %1.0138; % 8; 0; %
PARset(14).type='PAR';
PARset(14).name='ton';
PARset(14).val=16;
PARset(15).type='PAR';
PARset(15).name='period';
PARset(15).val=24;
PARset(16).type='PAR';
PARset(16).name='duration';
PARset(16).val=5; % 5;
PARset(17).type='PAR';
PARset(17).name='tdur';
PARset(17).val=4; % 4;

% Change parameters and ranges as needed
tons=0;
periods=24;
tauS=15;
alpha1=0:0.1:1;
for i=1:length(alpha1),
    for j=1:length(tauS),
        PARset(5).val=alpha1(j);
%        PARset(14).val=tons(i);
%        PARset(15).val=periods(j);
        PARset(1).val=tauS(j);
        s=ChangeXPPodeFile('cccMatlab.ode',PARset);
%         !xppaut -silent cccMatlab.ode
        success = RunXPP('cccMatlab.ode',[],[],'C:\xppall\xppaut')
        disp(['ton = ' num2str(tons(i)) ' and tauS = ' num2str(tauS(j))])
        movefile('output.dat',['noclock/output_' typ{k} '_' num2str(i) '_' num2str(j)])
    end
end