% pop_sample() - description of the function. If less than
%                three arguments are given, a window pops up
%                to ask for the value of the additional 
%                parameters.   
%
% Usage:
%   >>  OUTEEG = pop_sample( INEEG, type, param3 );
%
% Inputs:
%   INEEG   - input EEG dataset
%   type    - type of processing. 1 process the raw
%             data and 0 the ICA components.
%   param3  - additional parameter.
%    
% Outputs:
%   OUTEEG  - output dataset
%
% See also:
%   sample, eeglab

% Copyright (C) <year>  <name of author>
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice,
% this list of conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
% THE POSSIBILITY OF SUCH DAMAGE.

function [EEG, com] = pop_sample( EEG, typeproc, param3 )

% the command output is a hidden output that does not have to
% be described in the header

com = ''; % this initialization ensure that the function will return something
          % if the user press the cancel button            

% display help if not enough arguments
% ------------------------------------
if nargin < 2
	help pop_sample;
	return;
end

% pop up window
% -------------
if nargin < 3
	promptstr    = { 'Enter the parameter:' };
	inistr       = { '0' };
	result       = inputdlg( promptstr, 'Title of window', 1,  inistr);
	if length( result ) == 0 return; end;

	param3   	 = eval( [ '[' result{1} ']' ] ); % the brackets allow to process matlab arrays
end

% call function sample either on raw data or ICA data
% ---------------------------------------------------
if typeproc == 1
	sample( EEG.data );
else
	if ~isempty( EEG.icadata )
		sample( EEG.icadata );
	else
		error('You must run ICA first');
	end	
end

% return the string command
% -------------------------
com = sprintf('pop_sample( %s, %d, [%s] );', inputname(1), typeproc, int2str(param3));

