| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| function et = parseeyelink(inputFile,outputMatFile,triggerKeyword) |
|
|
| if nargin < 2 |
| help(mfilename); |
| return; |
| end; |
|
|
| |
| fprintf('\n%s(): Parsing Eyelink raw data. This may take a moment...',mfilename) |
| fprintf('\nNote: missing data samples (e.g. due to eye blinks) will be stored as zeros in parsed data.\n') |
| fprintf('\n-- reading txt...') |
|
|
| fid = fopen(inputFile,'r'); |
| if fid == -1 |
| fprintf('\nThe source file ''%s'' was not found.\n',inputFile) |
| return |
| |
| end |
|
|
| B = fread(fid,'*char')'; |
| fclose(fid); |
| fprintf('\n\tDone.') |
| |
| %% file specifications and comments |
| fprintf('\n-- getting comments and column headers...') |
| |
| et.comments = regexp(B,'(^[*#;/]{2}[^\r\n]*\r?\n)','match','lineanchors'); |
| |
| %% build column header |
| triggersAsColumn = false; % flag for INPUT column in data |
| triggersAsMessages = false; % flag for INPUT events |
| |
| edfColHeader = regexp(B,'^SAMPLES\s(GAZE|HREF|RAW)\s([^\r\n]*)','tokens','once','lineanchors'); |
| |
| if ~isempty(edfColHeader) |
| % are all possible keywords in the matchlist? |
| edfColType = regexp(edfColHeader{2},{'LEFT','RIGHT','VEL','RES','INPUT','HTARGET'}, 'once'); |
| |
| % possible to do this with regexprrep? |
| header = cell(1,17); |
| header{1} = 'TIME'; |
| if edfColType{1} |
| header{2} = sprintf('L_ |
| header{3} = sprintf('L_%s_Y',edfColHeader{1}); |
| header{4} = 'L_AREA'; |
| if edfColType{3} |
| header{8} = 'L_VEL_X'; |
| header{9} = 'L_VEL_Y'; |
| end |
| end |
| if edfColType{2} |
| header{5} = sprintf('R_%s_X',edfColHeader{1}); |
| header{6} = sprintf('R_%s_Y',edfColHeader{1}); |
| header{7} = 'R_AREA'; |
| if edfColType{3} |
| header{10} = 'R_VEL_X'; |
| header{11} = 'R_VEL_Y'; |
| end |
| end |
| if edfColType{4} |
| header{12} = 'RES_X'; |
| header{13} = 'RES_Y'; |
| end |
| if edfColType{5} |
| header{14} = 'INPUT'; |
| triggersAsColumn = true; |
| end |
| |
| if edfColType{6} |
| header{15} = 'targetpos_x'; |
| header{16} = 'targetpos_y'; |
| header{17} = 'targetdistance'; |
| end |
| |
| et.colheader = header(~cellfun(@isempty,header)); |
| else |
| et.colheader = {}; |
| end |
| clear edfCol* header |
| fprintf('\n\tDone.') |
|
|
| |
| fprintf('\n-- getting data...') |
| dataLines = regexp(B,'^\d[^\r\n]*','match','lineanchors'); |
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| dataLines = regexprep(dataLines,'(\s)\.(\s)','$10$2'); |
|
|
| |
| |
| |
| dataLines = regexprep(dataLines,'[\D]{2,}',' '); |
| dataChar = char(dataLines); |
| dataChar(:,end+1)= char(32); |
|
|
| |
| nColData = length(sscanf(dataChar(1,:),'%f')); |
|
|
| |
| |
| nColDatAll = arrayfun(@(x) length(sscanf(dataChar(x,:),'%f')), 1:length(dataChar)); |
| dataChar(nColDatAll~=nColData,:)=[]; |
|
|
| |
| |
| et.data = sscanf(dataChar',' |
|
|
| clear dataLines dataChar |
| fprintf('\n\tDone.') |
|
|
| |
| nColh = length(et.colheader); |
|
|
| if nColh ~= nColData |
| warning('\n%s(): The number of column names in the header (%i) differs from the number of actual data columns (%i)',mfilename,nColData,nColh) |
| end |
|
|
| |
| fprintf('\n-- getting messages...') |
|
|
| |
| |
| |
| |
| |
| et.messages = regexp(B,'^[A-Z \t][^\r\n]*\r?\n','match','lineanchors'); |
| |
| if regexp(B,'^INPUT','once','lineanchors') |
| triggersAsMessages = true; |
| end |
| fprintf('\n\tDone.') |
|
|
| |
| eventDataType = regexp(B,'^EVENTS\s(GAZE|HREF|RAW)','tokens','once','lineanchors'); |
| clear B* |
| |
| saccadePattern = '^ESACC\s+([RL])\s+([^\r\n]*)'; |
| tokensSaccade = regexp(et.messages,saccadePattern,'tokens','once')'; |
| |
| tokensSaccade = vertcat(tokensSaccade{:}); |
| if ~isempty(tokensSaccade) |
| % rare case of empty data in eyelink events |
| tokensSaccade(:,2) = regexprep(tokensSaccade(:,2),'(\s)\.(\s)','$10$2'); |
| |
| saccades.eye = [tokensSaccade{:,1}]'; |
| saccades.data = cell2mat(cellfun(@str2num,tokensSaccade(:,2),'UniformOutput',false)); |
| |
| saccades.colheader = {'latency','endtime','duration','sac_startpos_x','sac_startpos_y','sac_endpos_x','sac_endpos_y','sac_amplitude','sac_vmax','resolution_x','resolution_y'}; |
| saccades.colheader = saccades.colheader(1:size(saccades.data,2)); |
| et.eyeevent.saccades = saccades; |
| end |
|
|
| |
| fixationPattern = '^EFIX\s+([RL])\s+([^\r\n]*)'; |
| tokensFixation = regexp(et.messages,fixationPattern,'tokens','once')'; |
| |
| tokensFixation = vertcat(tokensFixation{:}); |
| if ~isempty(tokensFixation) |
| % rare case of empty data in eyelink events |
| tokensFixation(:,2) = regexprep(tokensFixation(:,2),'(\s)\.(\s)','$10$2'); |
| |
| fixations.eye = [tokensFixation{:,1}]'; |
| fixations.data = cell2mat(cellfun(@str2num,tokensFixation(:,2),'UniformOutput',false)); |
| switch char(eventDataType) |
| case {'GAZE','RAW'} |
| fixations.colheader = {'latency','endtime','duration','fix_avgpos_x','fix_avgpos_y','fix_avgpupilsize','resolution_x','resolution_y'}; |
| case 'HREF' |
| fixations.colheader = {'latency','endtime','duration','href_x','href_y','avgpupilsize','displaypos_x','displaypos_y','avgpupilsize','resolution_x','resolution_y'}; |
| end |
| fixations.colheader = fixations.colheader(1:size(fixations.data,2)); |
| et.eyeevent.fixations = fixations; |
| end |
|
|
| |
| blinkPattern = '^EBLINK\s+([RL])\s+([^\r\n]*)'; |
| tokensBlink = regexp(et.messages,blinkPattern,'tokens','once')'; |
| |
| tokensBlink = vertcat(tokensBlink{:}); |
| if ~isempty(tokensBlink) |
| blinks.eye = [tokensBlink{:,1}]'; |
| blinks.data = str2num(char(tokensBlink{:,2})); |
| blinks.colheader = {'latency','endtime','duration'}; |
| et.eyeevent.blinks = blinks; |
| end |
|
|
| |
| clear tokens* saccades fixations blinks *Pattern |
|
|
|
|
| |
|
|
| |
| if exist('triggerKeyword','var') |
| |
| if isempty(triggerKeyword) |
| warning('\n\n%s(): You are using an empty string as the keyword.',mfilename) |
| end |
| |
| |
| |
| test = regexp(et.messages,['MSG\s(\d+)\s+',triggerKeyword,'\s?(\d+)'],'tokens')'; |
| test2 = [test{:}]'; |
| test3 = cellfun(@str2double,test2,'UniformOutput',false); |
| et.event = cell2mat(test3); |
| if isempty(et.event) |
| warning('\n\n%s(): The keyword string you have provided (''%s'') was not found in any messages of the ET file (%s). Please check your messages and make sure they contain the specified keyword.',... |
| mfilename, triggerKeyword, inputFile) |
| end |
| |
| |
| elseif triggersAsMessages |
| test = regexp(et.messages,'INPUT\s+(\d+)\s+(.*)','tokens')'; |
| test2 = [test{:}]'; |
| test3 = cellfun(@str2double,test2,'UniformOutput',false); |
| et.event = cleantriggers(cell2mat(test3)); |
| |
| |
| elseif triggersAsColumn |
| et.event = cleantriggers( [et.data(:,1),et.data(:,strcmp('INPUT',et.colheader))]); |
| |
| |
| else |
| warning('\n%s(): Did not find trigger pulses or special messages that could be used as events for synchronization.',mfilename) |
| if ~exist('triggerKeyword','var') |
| fprintf('\nIf you have sent messages with a special keyword, please provide the keyword when calling this function. See help.') |
| end |
| end |
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| remove_this_msg = zeros(size(et.messages,2),1); |
| contains_keyword = []; |
| for m = 1:size(et.messages,2) |
| |
| contains_msg = strcmp(et.messages{m}(1:3),'MSG'); |
| |
| if exist('triggerKeyword','var') |
| contains_keyword = ~isempty(strfind(et.messages{m},triggerKeyword)); |
| end |
| |
| if ~contains_msg | contains_keyword |
| remove_this_msg(m) = true; |
| end |
| end |
| |
| |
| |
| |
| tmp = et.messages; |
| tmp(:,find(remove_this_msg)') = []; % remove msg marked above |
| |
| % now extract numeric timestamp from these remaining msg |
| timestamps = regexp(tmp,'^-?\D+(\d+)','tokens','once','lineanchors'); |
| timestamps = [timestamps{:}]'; |
| timestamps = cellfun(@str2double,timestamps,'UniformOutput',false); |
| timestamps = cell2mat(timestamps); |
|
|
| |
| for j = 1:size(tmp,2) |
| et.othermessages(j).timestamp = timestamps(j); |
| et.othermessages(j).msg = tmp{j}; |
| end |
| clear tmp test* edfColHeader |
|
|
| |
| fprintf('\n-- saving structure as mat...') |
| save(outputMatFile,'-struct','et') |
| fprintf('\n\tDone.') |
|
|
| fprintf('\n\nFinished parsing eye track.\nSaved .mat file to %s.\n',outputMatFile) |