function [Td,total_dur,xnew,tnew] = Duration (Lconc,Rconc,dur,calcium)
% this function is used to simulate the continuous duration of TRAIL exposure with death
% receptor for 3D binding kinetics

% Lconc is the concentration of ligand binding receptor [#/cc]
% Rconc is the concentration of receptor binding ligand [#/cc]
% dur_vec is the duration of on and off times, in seconds. The first value
% is on time, then off time, then on... etc.
% end_time is an end value of off time
% pert determines whether or not to use a perterbed mitochondrial pathway.
% if pert == 1 the mitochondrial pathway will be inhibited.
% Diffusion is the rate of calcium influx due to stimuli

% Td is the time until apoptosis
% total_dur is the total on time
% xnew is the matrix of reagents (each collumn is a different reagent, and
% each row is a given time.
% tnew is the vector of time corresponding to xnew.

xnew = [];
tnew = [];
%Threshold for calcium because model does not include other binding...
%partners for calcium that would compete with calpain activation.
%Calpain activation normally requires 1uM calcium.
if calcium >=1
[t_col,x_col] = TRAIL_init_calcium(Lconc,Rconc,dur,calcium);

xnew = [xnew;x_col];
tnew = [tnew;t_col];

else
   % Truncate calcium concentration to 0 to inhibit pathway.
   [t_col,x_col] = TRAIL_init_calcium(Lconc,Rconc,dur,0);
 
   xnew = [xnew;x_col];
tnew = [tnew;t_col];
end
clear t_col x_col

end