function varargout=dopScrnFileRead(fileNameLoc)
% dopOSCCI Mark II: dopScrnFileRead ~ 20-11-2010 (last edit)
%
% read dopOSCCI manual screening file
%

% -------------------------------------------------------------------------
%     '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
%
fprintf('%s\n\t%s\n',['Running ',mfilename],...
    'Reading dopOSCCI manual screening file:');
try
    if exist(fileNameLoc,'file')==2
        dmsr.fileNameLoc=fileNameLoc;%dtd.stitchFile;
        dmsr.out.okay=1;
        dmsr.translation='dopOSCCI manual screen read';
        dmsr.abbreviation='dmsr'; % useful for debugging
        
        %% import the stitchFile
        dmsr.im=importdata(dmsr.fileNameLoc); % imported data
        % something like:
        %          data: [8x24 double]
        %     textdata: {9x25 cell}
        dmsr.imSize=size(dmsr.im);
        dmsr.out.n=dmsr.imSize(1)-1; % number of rows (people) minus column header row
        i=1; % don't want the header line - assumes there's a header
        dmsr.out.list=[];
        dmsr.out.scrn=[];
        
        while i<dmsr.imSize(1); i=i+1;
            dmsr.str=dmsr.im{i}; % the string to examine
            [dmsr.token dmsr.remain]=strtok(dmsr.str); % get str token
            if ~isempty(dmsr.token)
                dmsr.out.list{end+1}=dmsr.token;
                [dmsr.tmp.tok dmsr.tmp.rem]=strtok(dmsr.remain,'~'); % get str token
                dmsr.out.scrn{i-1}=[];
                while ~isempty(dmsr.tmp.rem)
                    if isnumeric(str2double(dmsr.tmp.tok))
                        dmsr.out.scrn{i-1}(end+1)=str2double(dmsr.tmp.tok);
                    else
                        dmsr.out.scrn{i-1}(end+1)=0;
                    end
                    [dmsr.tmp.tok dmsr.tmp.rem]=strtok(dmsr.tmp.rem,'~'); % get str token
                end
                if ~isempty(dmsr.tmp.tok)
                    if isnumeric(dmsr.tmp.tok)
                        dmsr.out.scrn{i-1}(end+1)=str2double(dmsr.tmp.tok);
                    elseif strfind(dmsr.tmp.tok,'none')
                        dmsr.out.scrn{i-1}(end+1)=0;
                    end
                    
                end
            end
        end
        %% report
        dmsr.out.report=sprintf('%s\n\t%s\n',...
            ['Manual Screen File Report: ',dmsr.fileNameLoc],...
            ['n = ',num2str(dmsr.out.n),' individual series']);
        dmsr.out.guiReport=sprintf('%s\n',...
            ['n = ',num2str(dmsr.out.n),' individual series']);
        disp(dmsr.out.report);
    else
        fprintf('%s\n\t%s\n\n%s\n','Behavioural file was NOT found:',...
            fileNameLoc,'Therefore, behavioural file can''t be read...');
        dmsr.out.okay=0;
    end
    %% set output
    varargout{1}=dmsr.out;
    clear dsr
catch err
    %% catch dopOSCCI error
    save(dopOSCCIdebug(mfilename));throw(err);
end