function addbuffer(T,str,varargin)



%% If a new timeseries variable has been introduced, add it to the list of
%% time series names in the recorder
if nargin>=3
    recorder = tsguis.recorder;
    if isa(varargin{1},'tsdata.timeseries') 
        recorder.Tsnames = [recorder.Tsnames(:); {varargin{1}.Name}];
    elseif iscell(varargin{1}) % Cell array of time series have been provided
        tscellarray = varargin{1};
        for k=1:length(tscellarray)
            recorder.Tsnames = [recorder.Tsnames(:); {tscellarray{k}.Name}];
        end
    end 
    recorder.Tsnames = unique(recorder.Tsnames);

    %% If a new output timeseries variable has been introduced, add it to the list of
    %% output time series names in the recorder
    if nargin>=4
        if isa(varargin{2},'tsdata.timeseries') 
            recorder.Tsoutnames = [recorder.Tsoutnames(:); {varargin{2}.Name}];
        elseif  iscell(varargin{2}) % Cell array of time series have been provided   
            tscellarray = varargin{2};
            for k=1:length(tscellarray)
                recorder.Tsoutnames = [recorder.Tsoutnames(:); {tscellarray{k}.Name}];
            end
        end    
        recorder.Tsoutnames = unique(recorder.Tsoutnames);
    end

    % If one of the input timeseries was previously built by a logged
    % operation it cannot appear in the list of function inputs   
    recorder.Tsnames = setdiff(recorder.Tsnames,recorder.Tsoutnames);
end

%% Add a new M recorder string to the buffer
T.Buffer = [T.Buffer; {str}];
