function dop=dopGetData(dop)
% dopOSCCI Mark II: dopGetData ~ 10-01-2011 (last edit)
%
% function to import and process raw data file as well as report on the
% content of the TX file and the success of finding event markers.
%

% -------------------------------------------------------------------------
%     '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
    
    %% Import & Process the data
    [dop.inData dop.inLabels dop.data.foundMarkers dop.data.rawInfo dop.raw.data dop.data.isnan_count]=...
        dopProcessRawDataFile(dop.sum.fileNameLoc,...
        'dopChs',dop.def.dopChs,... % doppler left and right channel numbers
        'evChs',dop.def.evChs,... % doppler event channel number/s
        'outSample',dop.def.downHertz,... % desired down sampling rate in hertz
        'epoch',dop.def.epoch,... % lower and upper epoch values for data triming and trial normalisation
        'rawTrim',dop.def.trim,... % request for raw data trimming - yes or no
        'epochNorm',dop.def.epochNorm,... % request for trial normalisation - yes or no
        'markHeight',dop.def.markHeight,...); % height of Multi-dop trigger/marker pulses - look for pulses greater than this (see dopFindRawMarkers)
        'evType',dop.def.evType,...        'evType',2,...% event type: 0 = base, 1 = stim only, 2 = both
        'evMatch',dop.def.evMatch,...); %'evMatch',0,...% if event type = 0 or 1, it needs a match with another 1 or 0 type, only 2 is independent
        'fileName',dop.sum.fileTxt,...% something to id file
        'shortWarn',dop.def.shortWarn);
    %     'evNames',dop.def.evNames); % % event marker channel names
    %% report on import
    fprintf('%s\n\t%s\n','Import Report:','File info - ');
    if dop.data.foundMarkers
        dop.tmp.txLabels=fieldnames(dop.data.rawInfo);
        for i=1:length(dop.tmp.txLabels)
            dop.tmp.txLab=dop.tmp.txLabels{i};
            dop.tmp.txData=dop.data.rawInfo.(dop.tmp.txLab);
            if ~iscell(dop.tmp.txData)
                dop.tmp.info=[dop.tmp.txLab,': ',dop.tmp.txData];
                if isnumeric(dop.tmp.txData)
                    dop.tmp.info=[dop.tmp.txLab,': ',num2str(dop.tmp.txData)];
                end
                fprintf('\t%s\n',dop.tmp.info);
            end
        end
        if dop.data.isnan_count
            fprintf(' *** %u NaN (not a number) samples replaced with 0 (zero)\n',dop.data.isnan_count);
        end
        %% save raw data for graphing?
        % two options here - raw data for external graphing or raw data for
        % import plot
    else
        %% No markers > skip summary
        fprintf('\t%s\n\t\t%s\n',...
            'No event markers found, therefore skipping:',dop.sum.fileName);
        dop.sum.skip=1;
        dop.sum.skipReason='No event markers found';
    end
    if size(dop.inData,3)==1 && sum(sum(isnan(dop.inData)))
        dop.sum.skip=1;
        dop.sum.skipReason='Imported data is problematic - not numeric';
    elseif size(dop.inData,3)==4 && sum(sum(sum(isnan(dop.inData)))) % 4 was previously 2...
        dop.sum.skip=1;
        dop.sum.skipReason='Imported data is problematic - not numeric';
    elseif ~sum(dop.inData)
        dop.sum.skip=1;
        dop.sum.skipReason='Imported data is problematic - empty';
    end
catch err
    %% catch dopOSCCI error
    save(dopOSCCIdebug(mfilename));rethrow(err);
end
