function varargout=dopOSCCIgetFileList(folder,varargin)
% dopOSCCI Mark II: dopOSCCIgetFileList ~ 04-Nov-2011 (last edit)
%
% look for TX/TW files and, if empty, look for EXP
%
% [fileList report]=dopOSCCIgetFileList(folder,[comment]);
%
% comment = display function comments/txt on the way through script
%

% -------------------------------------------------------------------------
%     'dopOSCCI' summarises functional transcranial Doppler ultrasonography
%     (fTCD) data.  The primary function of the software is to assess the
%     hemispheric lateralization of cognitive function.
%
%     Copyright (C) 2011 the Chancellor, Masters and Scholars of the
%     University of Oxford.
% 
%     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 3 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, see <http://www.gnu.org/licenses/> 
%     or write to the Free Software Foundation, Inc., 51 Franklin Street,
%     Fifth Floor, Boston, MA 02110-1301, USA.
%
%     Authors: Nic Badcock, Georgina Holt, Anneka Holden, & Dorothy Bishop.
%       contact: nicholas.badcock@gmail.com
%
%     Type 'dopOSCCIlicense' for license details or see dopOSCCIlicense.txt
%
try
    fl.fileList=[];
    fl.report=[];
    fl.fileType='TX';
    fl.comment=1;
    fl.folder=folder;
    if ~isempty(varargin) && isnumeric(varargin{1}) && varargin{1}<=1
        fl.comment=varargin{1};
    end
    if ~strcmp(fl.folder(end),'/')
        fl.folder=[fl.folder,'/'];
    end
    [fl.fileList fl.report]=getTXfileList(fl.folder,fl.comment);
    disp(fl.report)
    if isempty(fl.fileList)
        % EXP check
        fl.fileType='EXP';
        [fl.fileList fl.report]=getEXPfileList(fl.folder,fl.comment);
        disp(fl.report)
    end
    
    varargout{1}=fl.fileList;
    varargout{2}=fl.report;
    varargout{3}=fl.fileType;
catch err
    %% catch dopOSCCI error
    save(dopOSCCIdebug(mfilename));rethrow(err);
end