% pop_saveset() - save a dataset structure
%
% Usage:
%   >> pop_saveset( EEG, filename, filepath);
%
% Inputs:
%   EEG        - data structure
%   filename   - name of the file to save (optional)
%   filepath   - path of the file to save (optional)
%
% Author: Arnaud Delorme, CNL / Salk Institute, 2001
%
% See also: pop_loadset(), eeglab()

%123456789012345678901234567890123456789012345678901234567890123456789012

% Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

% $Log: pop_saveset.m,v $
% Revision 1.1  2002/04/05 17:32:13  jorn
% Initial revision
%

% 01-25-02 reformated help & license -ad 

function com = pop_saveset( EEG, curfilename, curfilepath);

com = '';
if nargin < 1
	help pop_saveset;
	return;
end;
	
if nargin < 3
	[curfilename, curfilepath] = uiputfile('*.set', 'Save dataset with .set extension -- pop_saveset()');
	if curfilename == 0 return; end;
end;

EEG.filename    = curfilename;
EEG.filepath    = curfilepath;
EEG.icaact      = [];

disp('Saving dataset...');
command = sprintf('save -MAT %s EEG', [ curfilepath curfilename ]);
try, eval(command);
catch, error('Pop_saveset: saving error, check permission on file or directory');
end;

com = sprintf('pop_saveset( %s, ''%s'', ''%s'');', inputname(1), curfilename, curfilepath);

return;
