1 function [CNT,h,e]=
cntopen(arg1,arg2,arg3,arg4,arg5,arg6)
2 % CNTOPEN opens neuroscan files (but does not read the data).
3 % However, it is recommended to use SOPEN instead of CNTOPEN.
4 % For loading whole Neuroscan data files, use SLOAD.
6 % see also: SLOAD, SOPEN, SREAD, SCLOSE, SEOF, STELL, SSEEK.
8 % $Id:
cntopen.m 2974 2012-05-23 22:52:23Z schloegl $
9 % Copyright (c) 1997-2006,2007,2008,2009,2012 by Alois Schloegl <alois.schloegl@gmail.com>
10 % This is part of the BIOSIG-toolbox http:
12 % BioSig is free software; you can redistribute it and/or
13 % modify it under the terms of the GNU General Public License
14 % as published by the Free Software Foundation; either version 3
15 % of the License, or (at your option) any later version.
17 if nargin<2, arg2=
''; end;
21 status=fseek(CNT.FILE.FID,0,
'bof');
23 fprintf(CNT.FILE.stderr,
'Warning CNTOPEN: I/O error in file %s\n',CNT.FileName);
26 CNT.FILE.FID = fopen(CNT.FileName,CNT.FILE.PERMISSION,
'ieee-le');
31 [CNT.FILE.Path,CNT.FILE.Name,ext]=fileparts(arg1);
32 CNT.FILE.Ext = ext(2:end);
33 CNT.FILE.FID = fopen(CNT.FileName,CNT.FILE.PERMISSION,
'ieee-le');
35 fprintf(2,
'Error CNTOPEN: file %s not found.\n',CNT.FileName);
45 %h.rev = fread(fid,12,
'uint8');
46 %h.nextfile = fread(fid,1,
'long');
47 %h.prevfile = fread(fid,1,
'long');
48 h.type = fread(fid,1,
'uint8');
49 h.id = fread(fid,20,
'uint8');
50 h.oper = fread(fid,20,
'uint8');
51 h.doctor = fread(fid,20,
'uint8');
52 h.referral = fread(fid,20,
'uint8');
53 h.hospital = fread(fid,20,
'uint8');
54 h.patient = fread(fid,20,
'uint8');
55 h.age = fread(fid,1,
'short');
56 h.sex = fread(fid,1,
'uint8');
57 h.hand = fread(fid,1,
'uint8');
58 h.med = fread(fid,20,
'uint8');
59 h.category = fread(fid,20,
'uint8');
60 h.state = fread(fid,20,
'uint8');
61 h.label = fread(fid,20,
'uint8');
62 h.date = fread(fid,10,
'uint8');
63 h.time = fread(fid,12,
'uint8');
64 h.avgmode = fread(fid,1,
'uint8');
65 h.review = fread(fid,1,
'uint8');
66 h.nsweeps = fread(fid,1,
'ushort');
67 h.compsweeps = fread(fid,1,
'ushort');
68 h.pnts = fread(fid,1,
'ushort');
69 h.nchannels = fread(fid,1,
'short');
70 h.avgupdate = fread(fid,1,
'short');
71 h.domain = fread(fid,1,
'uint8');
72 h.rate = fread(fid,1,
'ushort');
73 h.scale = fread(fid,1,
'double');
74 h.veogcorrect = fread(fid,1,
'uint8');
75 h.veogtrig = fread(fid,1,
'float');
76 h.veogchnl = fread(fid,1,
'short');
77 h.heogcorrect = fread(fid,1,
'uint8');
78 h.heogtrig = fread(fid,1,
'float');
79 h.heogchnl = fread(fid,1,
'short');
80 h.baseline = fread(fid,1,
'uint8');
81 h.offstart = fread(fid,1,
'float');
82 h.offstop = fread(fid,1,
'float');
83 h.reject = fread(fid,1,
'uint8');
84 h.rejchnl1 = fread(fid,1,
'uint8');
85 h.rejchnl2 = fread(fid,1,
'uint8');
86 h.rejchnl3 = fread(fid,1,
'uint8');
87 h.rejchnl4 = fread(fid,1,
'uint8');
88 h.rejstart = fread(fid,1,
'float');
89 h.rejstop = fread(fid,1,
'float');
90 h.rejmin = fread(fid,1,
'float');
91 h.rejmax = fread(fid,1,
'float');
92 h.trigtype = fread(fid,1,
'uint8');
93 h.trigval = fread(fid,1,
'float');
94 h.trigchnl = fread(fid,1,
'uint8');
95 h.trigisi = fread(fid,1,
'float');
96 h.trigmin = fread(fid,1,
'float');
97 h.trigmax = fread(fid,1,
'float');
98 h.trigdur = fread(fid,1,
'float');
99 h.dir = fread(fid,1,
'uint8');
100 h.dispmin = fread(fid,1,
'float');
101 h.dispmax = fread(fid,1,
'float');
102 h.xmin = fread(fid,1,
'float');
103 h.xmax = fread(fid,1,
'float');
104 h.ymin = fread(fid,1,
'float');
105 h.ymax = fread(fid,1,
'float');
106 h.zmin = fread(fid,1,
'float');
107 h.zmax = fread(fid,1,
'float');
108 h.lowcut = fread(fid,1,
'float');
109 h.highcut = fread(fid,1,
'float');
110 h.common = fread(fid,1,
'uint8');
111 h.savemode = fread(fid,1,
'uint8');
112 h.manmode = fread(fid,1,
'uint8');
113 h.ref = fread(fid,20,
'uint8');
114 h.screen = fread(fid,80,
'uint8');
115 h.seqfile = fread(fid,80,
'uint8');
116 h.montage = fread(fid,80,
'uint8');
117 h.heegcorrect = fread(fid,1,
'uint8');
118 h.variance = fread(fid,1,
'uint8');
119 h.acceptcnt = fread(fid,1,
'ushort');
120 h.rejectcnt = fread(fid,1,
'ushort');
121 h.reserved74 = fread(fid,74,
'uint8');
123 for n = 1:64,%h.nchannels
124 e(n).lab = fread(fid,10,
'uint8');
125 e(n).x_coord = fread(fid,1,
'float');
126 e(n).y_coord = fread(fid,1,
'float');
127 e(n).alpha_wt = fread(fid,1,
'float');
128 e(n).beta_wt = fread(fid,1,
'float');
133 h.rev = fread(fid,12,
'uint8');
134 h.nextfile = fread(fid,1,
'uint32');
135 h.prevfile = fread(fid,1,
'uint32');
136 h.type = fread(fid,1,
'uint8');
137 h.id = fread(fid,20,
'uint8');
138 h.oper = fread(fid,20,
'uint8');
139 h.doctor = fread(fid,20,
'uint8');
140 h.referral = fread(fid,20,
'uint8');
141 h.hospital = fread(fid,20,
'uint8');
142 h.patient = fread(fid,20,
'uint8');
143 h.age = fread(fid,1,
'short');
144 h.sex = fread(fid,1,
'uint8');
145 h.hand = fread(fid,1,
'uint8');
146 h.med = fread(fid,20,
'uint8');
147 h.category = fread(fid,20,
'uint8');
148 h.state = fread(fid,20,
'uint8');
149 h.label = fread(fid,20,
'uint8');
150 h.date = fread(fid,10,
'uint8'); %%%
151 h.time = fread(fid,12,
'uint8'); %%%
152 h.mean_age = fread(fid,1,
'float');
153 h.stdev = fread(fid,1,
'float');
154 h.n = fread(fid,1,
'short');
155 h.compfile = fread(fid,38,
'uint8');
156 h.spectwincomp = fread(fid,1,
'float');
157 h.meanaccuracy = fread(fid,1,
'float');
158 h.meanlatency = fread(fid,1,
'float');
159 h.sortfile = fread(fid,46,
'uint8');
160 h.numevents = fread(fid,1,
'int'); %%%
161 h.compoper = fread(fid,1,
'uint8');
162 h.avgmode = fread(fid,1,
'uint8');
163 h.review = fread(fid,1,
'uint8');
164 h.nsweeps = fread(fid,1,
'ushort');
165 h.compsweeps = fread(fid,1,
'ushort');
166 h.acceptcnt = fread(fid,1,
'ushort');
167 h.rejectcnt = fread(fid,1,
'ushort');
168 h.pnts = fread(fid,1,
'ushort');
169 h.nchannels = fread(fid,1,
'ushort'); %%%
170 h.avgupdate = fread(fid,1,
'ushort');
171 h.domain = fread(fid,1,
'uint8');
172 h.variance = fread(fid,1,
'uint8');
173 h.rate = fread(fid,1,
'ushort'); %%%
174 h.scale = fread(fid,1,
'double');
175 h.veogcorrect = fread(fid,1,
'uint8');
176 h.heogcorrect = fread(fid,1,
'uint8');
177 h.aux1correct = fread(fid,1,
'uint8');
178 h.aux2correct = fread(fid,1,
'uint8');
179 h.veogtrig = fread(fid,1,
'float');
180 h.heogtrig = fread(fid,1,
'float');
181 h.aux1trig = fread(fid,1,
'float');
182 h.aux2trig = fread(fid,1,
'float');
183 h.heogchnl = fread(fid,1,
'short');
184 h.veogchnl = fread(fid,1,
'short');
185 h.aux1chnl = fread(fid,1,
'short');
186 h.aux2chnl = fread(fid,1,
'short');
187 h.veogdir = fread(fid,1,
'uint8');
188 h.heogdir = fread(fid,1,
'uint8');
189 h.aux1dir = fread(fid,1,
'uint8');
190 h.aux2dir = fread(fid,1,
'uint8');
191 h.veog_n = fread(fid,1,
'short');
192 h.heog_n = fread(fid,1,
'short');
193 h.aux1_n = fread(fid,1,
'short');
194 h.aux2_n = fread(fid,1,
'short');
195 h.veogmaxcnt = fread(fid,1,
'short');
196 h.heogmaxcnt = fread(fid,1,
'short');
197 h.aux1maxcnt = fread(fid,1,
'short');
198 h.aux2maxcnt = fread(fid,1,
'short');
199 h.veogmethod = fread(fid,1,
'uint8');
200 h.heogmethod = fread(fid,1,
'uint8');
201 h.aux1method = fread(fid,1,
'uint8');
202 h.aux2method = fread(fid,1,
'uint8');
203 h.ampsensitivity = fread(fid,1,
'float');
204 h.lowpass = fread(fid,1,
'uint8'); %%%
205 h.highpass = fread(fid,1,
'uint8'); %%%
206 h.notch = fread(fid,1,
'uint8'); %%%
207 h.autoclipadd = fread(fid,1,
'uint8');
208 h.baseline = fread(fid,1,
'uint8'); %%%
209 h.offstart = fread(fid,1,
'float');
210 h.offstop = fread(fid,1,
'float');
211 h.reject = fread(fid,1,
'uint8');
212 h.rejstart = fread(fid,1,
'float');
213 h.rejstop = fread(fid,1,
'float');
214 h.rejmin = fread(fid,1,
'float');
215 h.rejmax = fread(fid,1,
'float');
216 h.trigtype = fread(fid,1,
'uint8');
217 h.trigval = fread(fid,1,
'float');
218 h.trigchnl = fread(fid,1,
'uint8'); %%%
219 h.trigmask = fread(fid,1,
'short');
220 h.trigisi = fread(fid,1,
'float');
221 h.trigmin = fread(fid,1,
'float');
222 h.trigmax = fread(fid,1,
'float');
223 h.trigdir = fread(fid,1,
'uint8');
224 h.autoscale = fread(fid,1,
'uint8');
225 h.n2 = fread(fid,1,
'short');
226 h.dir = fread(fid,1,
'uint8');
227 h.dispmin = fread(fid,1,
'float');
228 h.dispmax = fread(fid,1,
'float');
229 h.xmin = fread(fid,1,
'float');
230 h.xmax = fread(fid,1,
'float');
231 h.automin = fread(fid,1,
'float');
232 h.automax = fread(fid,1,
'float');
233 h.zmin = fread(fid,1,
'float');
234 h.zmax = fread(fid,1,
'float');
235 h.lowcut = fread(fid,1,
'float'); %%%
236 h.highcut = fread(fid,1,
'float'); %%%
237 h.common = fread(fid,1,
'uint8');
238 h.savemode = fread(fid,1,
'uint8');
239 h.manmode = fread(fid,1,
'uint8');
240 h.ref = fread(fid,10,
'uint8');
241 h.rectify = fread(fid,1,
'uint8');
242 h.displayxmin = fread(fid,1,
'float');
243 h.displayxmax = fread(fid,1,
'float');
244 h.phase = fread(fid,1,
'uint8');
245 h.screen = fread(fid,16,
'uint8');
246 h.calmode = fread(fid,1,
'short');
247 h.calmethod = fread(fid,1,
'short');
248 h.calupdate = fread(fid,1,
'short');
249 h.calbaseline = fread(fid,1,
'short');
250 h.calsweeps = fread(fid,1,
'short');
251 h.calattenuator = fread(fid,1,
'float');
252 h.calpulsevolt = fread(fid,1,
'float');
253 h.calpulsestart = fread(fid,1,
'float');
254 h.calpulsestop = fread(fid,1,
'float');
255 h.calfreq = fread(fid,1,
'float');
256 h.taskfile = fread(fid,34,
'uint8');
257 h.seqfile = fread(fid,34,
'uint8');
258 h.spectmethod = fread(fid,1,
'uint8');
259 h.spectscaling = fread(fid,1,
'uint8');
260 h.spectwindow = fread(fid,1,
'uint8');
261 h.spectwinlength = fread(fid,1,
'float');
262 h.spectorder = fread(fid,1,
'uint8');
263 h.notchfilter = fread(fid,1,
'uint8'); %%%
264 h.headgain = fread(fid,1,
'short'); %%%
265 h.additionalfiles = fread(fid,1,
'int');
266 h.unused = fread(fid,5,
'uint8');
267 h.fspstopmethod = fread(fid,1,
'short');
268 h.fspstopmode = fread(fid,1,
'short');
269 h.fspfvalue = fread(fid,1,
'float');
270 h.fsppoint = fread(fid,1,
'short');
271 h.fspblocksize = fread(fid,1,
'short');
272 h.fspp1 = fread(fid,1,
'ushort');
273 h.fspp2 = fread(fid,1,
'ushort');
274 h.fspalpha = fread(fid,1,
'float');
275 h.fspnoise = fread(fid,1,
'float');
276 h.fspv1 = fread(fid,1,
'short');
277 h.montage = fread(fid,40,
'uint8');
278 h.eventfile = fread(fid,40,
'uint8');
279 h.fratio = fread(fid,1,
'float');
280 h.minor_rev = fread(fid,1,
'uint8'); %%%
281 h.eegupdate = fread(fid,1,
'short');
282 h.compressed = fread(fid,1,
'uint8');
283 h.xscale = fread(fid,1,
'float');
284 h.yscale = fread(fid,1,
'float');
285 h.xsize = fread(fid,1,
'float');
286 h.ysize = fread(fid,1,
'float');
287 h.acmode = fread(fid,1,
'uint8');
288 h.commonchnl = fread(fid,1,
'uint8');
289 h.xtics = fread(fid,1,
'uint8');
290 h.xrange = fread(fid,1,
'uint8');
291 h.ytics = fread(fid,1,
'uint8');
292 h.yrange = fread(fid,1,
'uint8');
293 h.xscalevalue = fread(fid,1,
'float');
294 h.xscaleinterval = fread(fid,1,
'float');
295 h.yscalevalue = fread(fid,1,
'float');
296 h.yscaleinterval = fread(fid,1,
'float');
297 h.scaletoolx1 = fread(fid,1,
'float');
298 h.scaletooly1 = fread(fid,1,
'float');
299 h.scaletoolx2 = fread(fid,1,
'float');
300 h.scaletooly2 = fread(fid,1,
'float');
301 h.port = fread(fid,1,
'short');
302 % h.numsamples = fread(fid,1,
'uint32'); %%%
303 h.numsamples = fread(fid,1,
'float32'); %%%
305 h.filterflag = fread(fid,1,
'uint8'); %%%
306 h.lowcutoff = fread(fid,1,
'float'); %%%
307 h.lowpoles = fread(fid,1,
'short');
308 h.highcutoff = fread(fid,1,
'float'); %%%
309 h.highpoles = fread(fid,1,
'short');
310 h.filtertype = fread(fid,1,
'uint8');
311 h.filterdomain = fread(fid,1,
'uint8');
312 h.snrflag = fread(fid,1,
'uint8');
313 h.coherenceflag = fread(fid,1,
'uint8');
314 h.continuoustype = fread(fid,1,
'uint8');
315 h.eventtablepos = fread(fid,1,
'int32'); %%%
316 h.continuousseconds = fread(fid,1,
'float');
317 h.channeloffset = fread(fid,1,
'uint32');
318 h.autocorrectflag = fread(fid,1,
'uint8');
319 h.dcthreshold = fread(fid,1,
'uint8');
322 warning([
'supicous Neuroscan file ',FILENAME]);
325 for n = 1:h.nchannels,%h.nchannels
326 e.lab(1:10,n) = fread(fid,10,
'uint8');
327 e.reference(1,n) = fread(fid,1,
'uint8');
328 e.skip(1,n) = fread(fid,1,
'uint8');
329 e.reject(1,n) = fread(fid,1,
'uint8');
330 e.display(1,n) = fread(fid,1,
'uint8');
331 e.bad(1,n) = fread(fid,1,
'uint8');
332 e.n(1,n) = fread(fid,1,
'ushort');
333 e.avg_reference(1,n) = fread(fid,1,
'uint8');
334 e.clipadd(1,n) = fread(fid,1,
'uint8');
335 e.x_coord(1,n) = fread(fid,1,
'float');
336 e.y_coord(1,n) = fread(fid,1,
'float');
337 e.veog_wt(1,n) = fread(fid,1,
'float');
338 e.veog_std(1,n) = fread(fid,1,
'float');
339 e.snr(1,n) = fread(fid,1,
'float');
340 e.heog_wt(1,n) = fread(fid,1,
'float');
341 e.heog_std(1,n) = fread(fid,1,
'float');
342 e.baseline(1,n) = fread(fid,1,
'short');
343 e.filtered(1,n) = fread(fid,1,
'uint8');
344 e.fsp(1,n) = fread(fid,1,
'uint8');
345 e.aux1_wt(1,n) = fread(fid,1,
'float');
346 e.aux1_std(1,n) = fread(fid,1,
'float');
347 e.sensitivity(1,n) = fread(fid,1,
'float');
348 e.gain(1,n) = fread(fid,1,
'uint8');
349 e.hipass(1,n) = fread(fid,1,
'uint8');
350 e.lopass(1,n) = fread(fid,1,
'uint8');
351 e.page(1,n) = fread(fid,1,
'uint8');
352 e.size(1,n) = fread(fid,1,
'uint8');
353 e.impedance(1,n) = fread(fid,1,
'uint8');
354 e.physicalchnl(1,n) = fread(fid,1,
'uint8');
355 e.rectify(1,n) = fread(fid,1,
'uint8');
356 e.calib(1,n) = fread(fid,1,
'float');
359 if ftell(fid)~=(900+h.nchannels*75),
360 %
this check does not work in the currenct CVS-version of Octave
361 warning([
'supicous Neuroscan file ',FILENAME]);
367 CNT.CNT.type = h.type;
369 CNT.ID.Operator = char(h.oper'); %
370 CNT.ID.Doctor = char(h.doctor
'); %
371 CNT.ID.referral = char(h.referral'); %
372 CNT.ID.Hospital = char(h.hospital
'); %
373 CNT.Patient.Name= char(h.patient'); %
374 CNT.Patient.Age = h.age; %
375 CNT.Patient.Sex = char(h.sex
'); %
376 CNT.Patient.Handedness=char(h.hand'); %
377 CNT.Patient.Medication=char(h.med
'); %
378 CNT.Patient.Classification=char(h.category'); %
379 CNT.Patient.State=char(h.state
'); %
380 CNT.Session.Label=char(h.label'); %
381 CNT.Date=char(h.date
'); %
382 CNT.Time=char(h.time'); %
383 if any(CNT.Date==
'/') & ~any(CNT.Date==
'-') & ~any(CNT.Date==
'.'), %% data format MM/DD/YYYY
385 else %
if ~any(CNT.Date==
'/'), %% data format DD-MM-YYYY or DD.MM.YYYY
390 elseif CNT.T0(1) > 80, CNT.T0(1) = CNT.T0(1) + 1900;
391 else CNT.T0(1) = CNT.T0(1) + 2000;
395 fprintf(2,
'Warning CNTOPEN: month and day were mixed up %i-%i-%i-%i-%i-%i \n',CNT.T0);
396 CNT.T0(2:3) = CNT.T0([3,2]);
399 CNT.NS = h.nchannels; %
400 CNT.SampleRate=h.rate; % D-to-A rate
401 CNT.Scale=h.scale; % scale factor
for calibration
402 CNT.Scale2=h.ampsensitivity;
403 CNT.HeadLen = 900 + 75*CNT.NS;
404 %CNT.PhysDim = repmat({
'µV'},CNT.NS,1);
405 CNT.PhysDimCode = repmat(4275,CNT.NS,1); %% uV
407 % Scan4.3->Edit->Overall Setup->Amplifier->Notch->Off/50Hz/60Hz
409 CNT.Filter.Notch = tmp(h.notchfilter+1);
411 % Scan4.3->Edit->Overall Setup->Amplifier->AC/DC
412 CNT.Filter.ACmode = h.acmode;
414 % Scan4.3->Edit->Overall Setup->Amplifier->DC Auto Correction
415 CNT.Filter.DCauto = h.autocorrectflag;
417 % Scan4.3->Edit->Overall Setup->Amplifier->Amplifier Settings->Low Pass
418 tmp = [30, 40, 50, 70, 100, 200, 500, 1000, 1500, 2000, 2500, 3000]; % LOWPASS
419 CNT.Filter.LowPass = tmp(e.lopass+1);
421 CNT.CNT.Filter.LowPass = tmp(h.lowpass+1); % ???
423 % Scan4.3->Edit->Overall Setup->Amplifier->Amplifier Settings->High Pass
424 tmp = [NaN, 0, .05, .1, .15, .3, 1, 5, 10, 30, 100, 150, 300]; %HIGHPASS
425 CNT.Filter.HighPass = tmp(e.hipass+1);
427 CNT.Filter.HighPass(e.hipass==0) = .05;
430 CNT.CNT.Filter.HighPass = tmp(h.highpass+1); % ???
433 CNT.CNT.Filter.LowCutOff = h.lowcutoff;
434 CNT.CNT.Filter.HighCutOff = h.highcutoff;
435 CNT.CNT.Filter.NotchOn = h.filterflag;
436 CNT.CNT.Filter.ON = [e(:).filtered];
437 CNT.CNT.minor_revision = h.minor_rev;
438 CNT.CNT.EventTablePos = h.eventtablepos;
440 CNT.Label = char(e.lab
');
443 if strcmp(upper(CNT.FILE.Ext),'AVG
'),
445 fprintf(2,'Warning CNTOPEN: filetype %i does not match file extension (%s).\n
',h.type,CNT.FILE.Ext);
451 CNT.Cal = e.calib./e.n; % scaling
452 CNT.Calib = sparse(2:CNT.NS+1,1:CNT.NS,CNT.Cal);
453 CNT.AS.bpb = h.pnts*h.nchannels*4+5;
454 CNT.AS.spb = h.pnts*h.nchannels;
455 CNT.Dur = CNT.SPR/CNT.SampleRate;
456 CNT.GDFTYP = 16; %'float32
';
458 elseif strcmp(upper(CNT.FILE.Ext),'COH
')
459 warning('.COH data not supported yet
')
460 CNT.COH.directory = fread(CNT.FILE.FID,[CNT.NS,CNT.NS],'int32
');
462 CNT.GDFTYP = 16; %'float32
';
464 elseif strcmp(upper(CNT.FILE.Ext),'CSA
')
465 warning('.CSA data not supported yet
')
467 CNT.NRec = h.compsweeps;
468 CNT.GDFTYP = 16; %'float32
';
470 elseif strcmp(upper(CNT.FILE.Ext),'EEG
'),
472 fprintf(2,'Warning CNTOPEN: filetype %i does not match file extension (%s).\n
',h.type,CNT.FILE.Ext);
476 CNT.NRec = h.compsweeps;
477 CNT.AS.spb = CNT.NS*CNT.SPR; % Samples per Block
479 % Sometimes h.eventtablepos seems to need a correction, also I've not figured out why.
480 % The Manual SCAN 4.2 Vol II, Page Headers-7 refers to
"286 SCAN manual". Maybe
this could bring a clarification.
481 % Anyway, the following code deals with the problem.
484 if CNT.CNT.minor_revision==12,
485 CNT.AS.bpb = 2*CNT.AS.spb+1+2+2+4+2+2;
486 CNT.GDFTYP = 3; %
'int16';
487 % correct(?) eventtablepos
488 h.eventtablepos = CNT.HeadLen + CNT.NRec*CNT.AS.bpb;
490 if CNT.CNT.minor_revision~=16,
491 fprintf(CNT.FILE.stderr,
'Warning CNTOPEN: EEG-Format Minor-Revision %i not tested.\n',CNT.CNT.minor_revision);
494 tmp = (CNT.AS.spb*2+1+2+2+4+2+2);
495 if (h.eventtablepos-CNT.HeadLen)==(tmp*CNT.NRec),
497 CNT.GDFTYP = 3; %
'int16';
500 tmp = (CNT.AS.spb*4+1+2+2+4+2+2);
501 if (h.eventtablepos-CNT.HeadLen)==(tmp*CNT.NRec),
503 CNT.GDFTYP = 5; %
'int32';
507 fprintf(CNT.FILE.stderr,
'Error CNTOPEN: header information of file %s corrupted.\n',CNT.FileName);
508 fclose(CNT.FILE.FID);
513 CNT.Calib = [-[e.baseline];eye(CNT.NS)]*diag([e.sensitivity].*[e.calib]/204.8);
514 CNT.AS.endpos = CNT.NRec;
515 CNT.FLAG.TRIGGERED = 1;
516 CNT.Dur = CNT.SPR/CNT.SampleRate;
518 elseif strcmp(upper(CNT.FILE.Ext),
'CNT'),
520 CNT.SPR = h.numsamples;
522 CNT.NRec = h.compsweeps;
523 %disp([h.eventtablepos,CNT.HeadLen,CNT.NS,h.pnts,CNT.NRec,CNT.SampleRate,h.type,CNT.CNT.minor_revision])
524 %disp([CNT.NS,h.pnts,h.compsweeps,h.numsamples,h.type,CNT.CNT.minor_revision])
527 CNT.GDFTYP = 3; % int16
528 CNT.AS.bpb = CNT.NS*2; % Bytes per Block
530 status = fseek(CNT.FILE.FID,h.nextfile+52,
'bof');
531 c = fread(CNT.FILE.FID,[1,1],
'uchar');
533 CNT.GDFTYP = 5; % int32;
534 CNT.AS.bpb = CNT.NS*4; % Bytes per Block
538 if h.eventtablepos>CNT.FILE.size,
539 warning(
'CNTOPEN: eventtablepos %i after end of file %i: \n',h.eventtablepos,CNT.FILE.size);
542 CNT.AS.spb = CNT.NS; % Samples per Block
543 CNT.AS.EVENTTABLEPOS = h.eventtablepos;
544 if h.eventtablepos > CNT.FILE.size,
545 fprintf(CNT.FILE.stderr,
'Warning CNTOPEN: %s is corrupted:\n - position of eventtable (%i) past end of file (%i).\n',CNT.FileName,h.eventtablepos,CNT.FILE.size);
546 CNT.SPR = floor((CNT.FILE.size-CNT.HeadLen)/CNT.AS.bpb);
548 CNT.SPR = floor((h.eventtablepos-CNT.HeadLen)/CNT.AS.bpb);
550 CNT.AS.endpos = CNT.SPR;
553 CNT.Calib = [-[e.baseline];eye(CNT.NS)]*diag([e.sensitivity].*[e.calib]/204.8);
554 CNT.FLAG.TRIGGERED = 0;
555 CNT.Dur = 1/CNT.SampleRate;
557 if all(CNT.GDFTYP==3)
558 CNT.DigMax = repmat(32767,1,CNT.NS);
559 CNT.DigMin = repmat(-32768,1,CNT.NS);
561 CNT.DigMax = repmat(2^23-1,1,CNT.NS);
562 CNT.DigMin = repmat(-2^23,1,CNT.NS);
564 CNT.PhysMax = [1,CNT.DigMax]*CNT.Calib;
565 CNT.PhysMin = [1,CNT.DigMin]*CNT.Calib;
567 %%%%% read event table
571 CNT.EVENT.TeegSize = 0;
572 status = fseek(CNT.FILE.FID,h.eventtablepos,
'bof');
574 [CNT.EVENT.TeegType,c1] = fread(fid,1,
'uint8');
575 [CNT.EVENT.TeegSize,c2] = fread(fid,1,
'int32');
576 [CNT.EVENT.TeegOffset,c3] = fread(fid,1,
'int32');
582 while (K < CNT.EVENT.TeegSize),
584 Teeg.Stimtype = fread(fid,1,
'int16');
585 Teeg.Keyboard = fread(fid,1,
'uint8');
586 tmp = fread(fid,1,
'uint8');
588 Teeg.KeyPad = rem(tmp,16); %bitand(tmp,15);
589 Teeg.Accept = (fix(tmp/16))==13; % (bitshift(tmp,-4)==13); % 0xd = accept, 0xc = reject
591 Teeg.Offset = fread(fid,1,
'int32');
593 if any(CNT.EVENT.TeegType==[2:3]),
594 Teeg.Type = fread(fid,1,
'int16');
595 Teeg.Code = fread(fid,1,
'int16');
596 Teeg.Latency = fread(fid,1,
'float32');
597 Teeg.EpochEvent = fread(fid,1,
'uint8');
598 Teeg.Accept2 = fread(fid,1,
'uint8');
599 Teeg.Accuracy = fread(fid,1,
'uint8');
610 CNT.EVENT.TEEG = TEEG
';
611 %CNT.EVENT.TYP = [TEEG(:).Stimtype]';
612 stim = [TEEG(:).Stimtype]
';
613 resp = [TEEG(:).KeyPad]';
614 ix = find((stim>0) & (resp>0));
616 fprintf(CNT.FILE.stderr,
'Warning SOPEN(CNT): in some events, both response and stimulus are non zero. Response code ignored.\n');
620 CNT.EVENT.TYP = stim + (resp+128*(stim==0));
621 if CNT.EVENT.TeegType==3,
622 CNT.EVENT.POS = [TEEG(:).Offset]';
624 CNT.EVENT.POS = ([TEEG(:).Offset]
' - CNT.HeadLen) ./ CNT.AS.bpb;
629 % set file pointer to the beginning of the data block
630 status = fseek(CNT.FILE.FID, CNT.HeadLen, 'bof
');
632 fprintf(CNT.FILE.stderr,'Warning CNTOPEN: I/O error in file %s\n
',CNT.FileName);