-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathread_eyelink_asc.m
108 lines (80 loc) · 2.59 KB
/
read_eyelink_asc.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
function asc = read_eyelink_asc(filename)
% READ_EYELINK_ASC reads the header information, input triggers, messages
% and all data points from an Eyelink *.asc file
%
% Use as
% asc = read_eyelink_asc(filename)
% Copyright (C) 2010, Robert Oostenveld
%
% This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip
% for the documentation and details.
%
% FieldTrip 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.
%
% FieldTrip 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 FieldTrip. If not, see <http://www.gnu.org/licenses/>.
%
% $Id: read_eyelink_asc.m 7123 2012-12-06 21:21:38Z roboos $
fid = fopen(filename, 'rt');
asc.header = {};
asc.msg = {};
asc.input = [];
asc.sfix = {};
asc.efix = {};
asc.ssacc = {};
asc.esacc = {};
asc.dat = [];
current = 0;
while ~feof(fid)
tline = fgetl(fid);
if regexp(tline, '^[0-9]');
tmp = sscanf(tline, '%f');
nchan = numel(tmp);
current = current + 1;
if size(asc.dat,1)<nchan
% increase the allocated number of channels
asc.dat(nchan,:) = 0;
end
if size(asc.dat, 2)<current
% increase the allocated number of samples
asc.dat(:,end+10000) = 0;
end
% add the current sample to the data matrix
asc.dat(1:nchan, current) = tmp;
elseif regexp(tline, '^INPUT')
[val, num] = sscanf(tline, 'INPUT %d %d');
this.timestamp = val(1);
this.value = val(2);
if isempty(asc.input)
asc.input = this;
else
asc.input = cat(1, asc.input, this);
end
elseif regexp(tline, '\*\*.*')
asc.header = cat(1, asc.header, {tline});
elseif regexp(tline, '^MSG')
asc.msg = cat(1, asc.msg, {tline});
elseif regexp(tline, '^SFIX')
asc.sfix = cat(1, asc.sfix, {tline});
elseif regexp(tline, '^EFIX')
asc.efix = cat(1, asc.efix, {tline});
elseif regexp(tline, '^SSACC')
asc.ssacc = cat(1, asc.ssacc, {tline});
elseif regexp(tline, '^ESACC')
asc.esacc = cat(1, asc.esacc, {tline});
else
% all other lines are not parsed
end
end
% close the file?
fclose(fid);
% remove the samples that were not filled with real data
asc.dat = asc.dat(:,1:current);