ET_PDToolkit/PDToolkit/@PDSession/read_gazedata.m~

95 lines
2.5 KiB
Mathematica

function[obj] = readASC(obj)
%% low level function to read in asc data from Tobii eyetracker data
datafile = obj.datafile;
samples=[];
events ={};
load_processed_data = 0;
[base file ext] = fileparts(datafile);
target_dir = [base filesep file '.matlab'];
if (exist(target_dir, 'dir') == 0)
mkdir(target_dir);
end
cd(target_dir);
display(['Parsing file : ' file]);
%display_and_log(['Parsing file : ' file], 1);
%display_and_log(['Date : ' datestr(now)], 0);
target_raw = [target_dir filesep file '_raw.mat'];
target_processed = [target_dir filesep file '_processed.mat'];
settings.target_raw = target_raw;
settings.target_processed = target_processed;
if exist([target_dir filesep file '_processed.mat'], 'file');
display(sprintf('*) Loading data from file : %s', target_processed));
file_contents = load(target_processed);
data = file_contents.data;
load_processed_data = 1;
elseif exist([target_dir filesep file '_raw.mat'], 'file');
display(sprintf('*) Loading data from file : %s', target_raw));
file_contents= load(target_raw);
data = file_contents.data;
else
lc=0;
fp = fopen(datafile,'r');
i=1; j=1; m=1;
data_flag = 0;
if (isunix)
[status lines_txt] = system(['wc ' regexprep(datafile,' ', '\\ ') '|awk ''{print $1''}']);
[status events_txt] = system(['grep -c "^[0-9*" ' regexprep(datafile,' ', '\\ ') '|awk ''{print $1''}']);
else
[status lines_txt] = system(['find /c ' datafile]);
end
lines = str2num(lines_txt);
nevents = str2num(events_txt);
progressbar = waitbar(0, 'Reading data file...');
samples = nan(lines, 4);
events = cell(1, nevents);
header =fgetl(fp);
params = strsplit(header, '\t');
pupil_params = strfind(param
while(~feof(fp))
if(mod(lc, 1000) ==0)
% display(sprintf('working on line %d', lc));
waitbar(lc / lines, progressbar, sprintf('Reading data file ... : (%f)', round(100*(lc / lines))));
end
line=fgetl(fp);
if (data_flag & regexp(line, '^[0-9]*'))
samples(i,:) = sscanf(line, '%d %f %f %f %*s');
i=i+1;
else
events{j} = line;
j=j+1;
end
if regexp(line,'^SAMPLES')
data_flag = 1;
end
lc=lc+1;
end
fclose(fp)
data.samples = samples;
data.events = events;
save(target_raw, 'data');
close(progressbar);
end