% tool
% 
%   INPUT VALUES:
%  
%   RETURN VALUE:
%
% 
% (c) 2003-2008, University of Cambridge, Medical Research Council 
% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
% http://www.pdn.cam.ac.uk/cnbh/aim2006
% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
% $Revision: 585 $

function str=getargument(source,search)
% usage: str=getargument(source,search)
% searchs in the pairs of parameters 'param','value' for the argument and returns the value as string
% source must be a even number of input parameters

% for compatibility with old version
if ~isfield(source,'name')
    nr=size(source,2);  % so many pairs
    for i=1:nr
        param=source(i);
        if strcmp(param,search)
            str= source(i+1);
            return
        end
    end
    str{1}='';
    return
   
else
    
    % new version is much more elegant
    nr=size(source.name,2);  % so many pairs
    for i=1:nr
        param=source.name{i};
        if strcmp(param,search)
            str=source.argument{i};
            
            % if the argument is put into "[]" then remove them
            return
        end
    end
end
str='';
return 


