function uisave(variables, filename)
%UISAVE GUI Helper function for SAVE
%
%   See also SAVE, LOAD, UILOAD

% Copyright 1984-2000 The MathWorks, Inc.
% $Revision: 1.9 $  $Date: 2000/08/26 02:13:34 $

whooutput = evalin('caller','who','');
if isempty(whooutput)
    errordlg('No variables to save')
    return;
end

if nargin == 0
    variables = whooutput;
end

if nargin < 2
    if length(whooutput) > 1
        seed = {'*.mat','MAT-files (*.mat)'};
    else
        seed = {'*.mat','MAT-files (*.mat)'
                '*.txt','ASCII-files (*.*)'};
    end
else
    seed = filename;
end

if ~iscellstr(variables) & ~ischar(whooutput) 
    error('VARIABLES argument must be a string or cell array of strings');
end

if iscell(variables)
    variables = sprintf('''%s'',',variables{:});
    variables = variables(1:end - 1);
end
    
[fn,pn] = uiputfile(seed, 'Save Workspace Variables');

if ~all(pn == 0) & ~all(fn == 0)
    try
        fn = strrep(fullfile(pn,fn), '''', '''''');
        evalin('caller',['save(''' fn  ''', ' variables ');'], 'error(lasterr)');
    catch
        errordlg(lasterr)
    end
end

