2 % GETFILETYPE get file type
7 % HDR is the Header
struct and contains stuff used by SOPEN.
8 % HDR.TYPE identifies the type of the file [1,2].
17 % This program is free software; you can redistribute it and/or
18 % modify it under the terms of the GNU General Public License
19 % as published by the Free Software Foundation; either version 3
20 % of the License, or (at your option) any later version.
22 % $Id:
getfiletype.m 3057 2012-08-24 15:04:16Z schloegl $
23 % (C) 2004,2005,2007,2008 by Alois Schloegl <a.schloegl@ieee.org>
24 % This is part of the BIOSIG-toolbox http:
29 elseif isfield(arg1,
'name')
30 HDR.FileName = arg1.name;
32 elseif isfield(arg1,'FileName')
35 error('input argument not supported');
37 if ~isfield(HDR,'FILE')
38 HDR.FILE.PERMISSION='r';
40 if ~isfield(HDR.FILE,'PERMISSION')
41 HDR.FILE.PERMISSION='r';
49 if ~isfield(HDR.FILE,'stderr'),
52 if ~isfield(HDR.FILE,'stdout'),
56 if exist(HDR.FileName,'dir')
57 [pfad,file,FileExt] = fileparts(HDR.FileName);
60 HDR.FILE.Ext = FileExt(2:end);
61 if strcmpi(FileExt,'.ds'), % .. & isdir(HDR.FileName)
62 f1 = fullfile(HDR.FileName,[file,'.meg4']);
63 f2 = fullfile(HDR.FileName,[file,'.res4']);
64 if (exist(f1,'file') && exist(f2,'file')), % && (exist(f3)==2)
66 % HDR.TYPE = 'MEG4'; % will be checked below
68 elseif exist(fullfile(HDR.FileName,'alpha.alp'),'file')
69 HDR.FileName = fullfile(HDR.FileName,'rawhead');
71 elseif exist(fullfile(HDR.FileName,'patient.txt'),'file') && exist(fullfile(HDR.FileName,'datafiles.txt'),'file')
72 % Freiburg Prediction Contest
74 HDR.FILE.Path = HDR.FileName;
75 HDR.FILE.Name = 'patient.txt';
76 HDR.FileName = fullfile(HDR.FILE.Path,'patient.txt');
84 %fid = fopen(HDR.FileName,PERMISSION,'ieee-le');
85 fid = fopen(HDR.FileName,HDR.FILE.PERMISSION);
88 HDR.ErrMsg = sprintf('Error GETFILETYPE: file %s not found.\n',HDR.FileName);
91 [pfad,file,FileExt] = fileparts(HDR.FileName);
98 HDR.FILE.Ext =
char(FileExt(2:length(FileExt)));
100 if ~any(HDR.FILE.PERMISSION=='z')
103 fseek(fid,2^32,'bof');
105 HDR.FILE.size = ftell(fid);
108 [s,c] = fread(fid,min(HDR.FILE.size,1024),'uint8');
112 s = [s', repmat(NaN,1,1024-c)];
119 HDR.keycode = s(1:34);
121 %%%% file type check based on magic numbers %%%
122 tmp = 256.^[0:3]*reshape(s(1:20),4,5);
123 mat4.flag = (c>20) && (tmp(5)<256) && (tmp(5)>1) && (tmp(1)<4053) && any(s(13)==[0,1]) && any(tmp(4)==[0,1]);
125 mat4.matrixname = lower(
char(s(21:20+tmp(5)-1)));
126 mat4.type = sprintf('%04i',tmp(1))-48;
127 mat4.size = tmp(2:3);
129 mat4.flag = mat4.flag && s(20+tmp(5));
130 mat4.flag = all((mat4.matrixname>='0' && mat4.matrixname<='9') || (mat4.matrixname>='_' && mat4.matrixname<='z'));
131 mat4.flag = mat4.flag && all(any(mat4.type(ones(6,1),:)==[0,0:4;zeros(1,6);0:5;0:2,0,0,0]'));
133 MAGIC.ePrime = 'ExperimentName Subject Session Clock.Information Display.RefreshRate Group RandomSeed SessionDate SessionTime Block Blocklist Blocklist.Cycle';
135 pos1_ascii10 = min(find(s==10));
136 FLAG.FS3 = any(s==10);
138 FLAG.FS3=all((s(4:pos1_ascii10)>=32) & (s(4:pos1_ascii10)<128)); % FREESURVER TRIANGLE_FILE_MAGIC_NUMBER
141 FLAG.IS_UFF = strncmp(ss,[' -1',repmat(' ',1,80-6)],80);
143 K = strfind(ss(81:161),' '); K = min(K);
144 FLAG.IS_UFF = (K<4) && any(s(81)==[10,13]) && any(s(79+K)==[10,13]);
148 elseif all(s([1:2,155:156])==[207,0,0,0]);
150 elseif strncmp(ss,'Version 3.0',11); % Neuroscan
152 elseif strncmp(ss,'NSI TFF',7); % Neuroscan
154 elseif strncmp(ss,'Brain Vision Data Exchange Header File',38);
155 HDR.TYPE = 'BrainVision';
156 elseif strncmp(ss,'Brain Vision V-Amp Data Header File Version',38);
157 HDR.TYPE = 'BrainVisionVAmp';
158 elseif strncmp(ss,[239,187,191,'Brain Vision Data Exchange Header File'],38);
159 HDR.TYPE = 'BrainVision';
160 elseif strncmp(ss,'Brain Vision Data Exchange Marker File',38);
161 HDR.TYPE = 'BrainVision_MarkerFile';
162 elseif strncmp(ss,'[Header]',8);
164 elseif all(256.^[0:3]*reshape(s(1:80),[4,20])==[0,16,32,32,512,536,1,1,1048,412,1,1,1460,80,32,1,4020,76,128,128]);
165 HDR.TYPE='ET-MEG:SQD';
166 HDR.Endianity = 'ieee-le';
167 elseif all(s(1:4)==0) && strcmp(HDR.FILE.Ext,'raw') && exist(fullfile(HDR.FILE.Path,[HDR.FILE.Name,'.ainf']),'file');
169 elseif strncmp(ss,'[BioSig Header]',13);
171 elseif strncmp(ss,'
#BIOSIG BINARY]',14);
173 elseif strncmp(ss,
'0 ',8);
175 elseif all(s(1:8)==[255,abs(
'BIOSEMI')]);
177 elseif strncmp(ss,
'GDF',3);
179 elseif strncmp(ss,
'EBS',3);
181 %elseif all(s(1:4) == [hex2dec([
'5f';
'09';
'a7';
'82'])]
');
183 elseif (c>31) && strncmp(ss,'CEN
',3) && all(s(6:8)==hex2dec(['1A
';'04
';'84
'])') && (all(s(4:5)==hex2dec([
'13';
'10'])
') || all(s(4:5)==hex2dec(['0D
';'0A
'])'));
188 HDR.Endianity =
'ieee-be';
190 HDR.Endianity =
'ieee-le';
192 if any(s(4:5)~=[13,10])
193 % fprintf(2,
'Warning GETFILETYPE (FEF): incorrect preamble in file %s\n',HDR.FileName);
196 elseif strncmp(ss,
'CEDFILE"',8);
198 elseif strncmp(ss,
'MEG41CP',7);
200 elseif strncmp(ss,
'MEG41RS',7) || strncmp(ss,
'MEG4RES',7);
202 elseif strncmp(ss,
'MEG4',4);
204 elseif (c>21) && strncmp(ss,
'CTF_MRI_FORMAT VER 2.2',22);
206 elseif 0, strncmp(ss,
'PATH OF DATASET:',16);
209 elseif strcmp(ss(1:10),
'EEG-1100C ') && strcmp(ss(16+(1:length(HDR.FILE.Name))),HDR.FILE.Name); % Nihon-Kohden
211 HDR.VERSION = ss(11:16);
212 elseif strcmp(ss(1:10),
'EEG-1100C ') && strcmp(ss(32+(1:length(HDR.FILE.Name))),HDR.FILE.Name); % Nihon-Kohden
213 HDR.TYPE=
'EEG-1100+';
214 HDR.VERSION = ss(11:16);
215 elseif strcmp(ss([1:8,10]),
'EEG-1100 ') && any(ss(9)==
'ABC') % Nihon-Kohden
216 HDR.TYPE=
'EEG-1100-';
217 HDR.VERSION = ss(11:16);
218 elseif strcmp(ss(1:10),
'QI-403A ') % Nihon-Kohden
219 HDR.TYPE=
'EEG-1100-';
220 HDR.VERSION = ss(11:16);
221 elseif strcmp(ss(1:10),
'EEG-2100 ') % Nihon-Kohden
222 HDR.TYPE=
'EEG-1100-';
223 HDR.VERSION = ss(11:16);
224 elseif strcmp(ss(1:10),
'DAE-2100D ') % Nihon-Kohden
225 HDR.TYPE=
'EEG-1100-';
226 HDR.VERSION = ss(11:16);
228 elseif (c>278) && strncmp(ss,
'Embla data file',15) && strcmp(HDR.FILE.Name,ss(279:278+length(HDR.FILE.Name))),
230 elseif strcmp(ss(1:20),[
'Header',13,10,
'File Version'])
232 elseif strncmp(ss, MAGIC.ePrime, length(MAGIC.ePrime))
235 elseif strncmp(ss,'GALILEO EEG TRACE FILE',22) % Galilea EEG (from ESAOTE, EBNeuro spa)
237 elseif strcmp(ss(3:11),'COHERENCE') && strcmp(ss(43+[1:length(HDR.FILE.Name)]),HDR.FILE.Name);
240 elseif strcmp(ss(1:8),'@ MFER ');
242 elseif (c>27) && strcmp(ss(1:28),'FileFormat = BNI-1-BALTIMORE');
243 HDR.TYPE='Nicolet'; %%% see also Nicolet
244 elseif strcmp(ss(1:6),'@ MFR ');
246 elseif all(s([4:7,14:19])==[232,3,12,0,0,0,0,0,0,0]);
247 HDR.TYPE='PathFinder710_HighResolutionECG';
250 elseif (c>33) && all(s([9,10,12:14,17:24,26:34])==[0,0,0,0,0,abs('SCPECG'),0,0,0,0,0,7,0,0,0,1,0]) && (s(11)==s(25));
252 HDR.VERSION = s(15)/10;
253 elseif (c>33) && all(s([9,10,12:14,17:24,26:34])==[0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,7,0,0,0,1,0]) && (s(11)==s(25));
255 HDR.VERSION = s(15)/10;
258 elseif (c>23) && all(s([9:23])==[0,0,136,0,0,0, 13,13, 6,abs('SCPECG')]);
261 elseif (c>33) && all(s([9:34])==[0,0,136,0,0,0, 10,205,205,205,205,205,205,205,0,0, 136,0,0,0,7,0,0,0,1,0]);
264 elseif (c>33) && all(s([9:34])==[0,0,136,0,0,0, 10,11, 0,0,0,0,0,0,0,0, 0,0,0,0, 0,0,0,0, 1,0]);
267 elseif (c>33) && all(s([9:34])==[0,0,136,0,0,0, 13,13, abs('SCPEGC'),0,0, 136,0,0,0, 7,0,0,0, 1,0]);
270 elseif (c>33) && all(s([9:34])==[0,0,136,0,0,0, 10,0, 144,128,0,0,120,128,0,0, 136,0,0,0, 7,0,0,0, 1,0]);
273 elseif (c>33) && all(s([9:34])==[0,0,136,0,0,0, 10,11, 37,1,153,1,231,73 ,0,0, 136,0,0,0, 7,0,0,0, 1,0]);
277 elseif strncmp(ss,'
# EN1064 Lead Identification Table of the SCP-ECG format',6);
278 HDR.TYPE=
'EN1064:LeadId';
279 tmp = fread(fid,[1,inf],
'uint8');
280 s = char([s(:);tmp(:)])
';
284 [t,s] = strtok(s,[10,13]);
286 elseif ~strncmp(t,'#
',1)
287 ix3 = strfind(t,'MDC_ECG_LEAD_
');
288 [t1,t2] = strtok(t(1:ix3-1),[9,32]);
289 [t2,t3] = strtok(t2,[9,32]);
292 HDR.EN1064.SCP_Name{k} = t1;
293 HDR.EN1064.Code(k) = id;
294 HDR.EN1064.Description{k} = deblank(t3);
295 HDR.EN1064.MDC_ECG_LEAD{k}= t(ix3+13:end);
299 elseif (c>41) && strncmp(ss,'ATES MEDICA SOFT. EEG
for Windows
',32); % ATES MEDICA SOFTWARE, NeuroTravel
301 HDR.VERSION = ss(35:42);
302 elseif (c>40) && strncmp(ss,'V3.0
',16) && strncmp(ss(33:41),'[PatInfo]
',9);
303 HDR.TYPE='Sigma
'; %% SigmaPLpro
304 HDR.HeadLen = s(17:20)*(256.^[0:3]');
305 elseif all(s([1:24,29:31])==[abs(
'POLY SAMPLE FILEversion '),13,10,26]) && (
str2double(ss(25:28))==(s([32:33])*[1;256]/100)); % Poly5/TMS32 sample file format.
307 elseif strncmp(ss,[
'FileId=TMSi PortiLab sample log file'],36); %
309 HDR.H1 = [ss(1:c),fread(fid,[1,inf],
'uint8=>char')]; %% read whole file
310 elseif strncmp(ss,
'"Snap-Master Data File"',23); % Snap-Master Data File .
312 elseif 0, all(s([1:2,20])==[1,0,0]) && any(s(19)==[2,4]);
313 HDR.TYPE=
'TEAM'; % Nicolet TEAM file format
314 elseif strncmp(ss,HDR.FILE.Name,length(HDR.FILE.Name)) && strcmpi(HDR.FILE.Ext,
'HEA');
316 elseif strncmp(ss,
'DEMG',4); % www.Delsys.com
318 elseif (c>37) && strcmp(ss(35:38),
'BLSC') % CeeGraph, Bio-Logic Systems Corp.
319 if strcmpi(ss(44+[0:length(HDR.FILE.Name)+length(HDR.FILE.Ext)]),[HDR.FILE.Name,
'.',HDR.FILE.Ext]);
321 warning(
'BLSC: ????');
325 elseif all(s([1:2,4:8])==[3,17,0,8,9,176,2]) && any(s(3)==[240:249]) % v2.40 - v2.49
327 elseif (c>317) && all(ss(308:318)==[
'E',zeros(1,7),
'DAT']) % CeeGraph, Bio-Logic Systems Corp.
329 elseif all(s([129,130,132:136])==[3,17,0,8,9,176,2]) && any(s(3)==[240:249]) % v2.40 - v2.49
330 HDR.TYPE=
'BLSC2-128';
331 elseif (c>445) && strncmp(ss(436:446),[HDR.FILE.Name,0,HDR.FILE.Ext],length(HDR.FILE.Name)+length(HDR.FILE.Ext)+1) % CeeGraph, Bio-Logic Systems Corp.
333 elseif (c>445) && strncmp(ss(436:446),[HDR.FILE.Name,0,HDR.FILE.Ext],length(HDR.FILE.Name)+length(HDR.FILE.Ext)+1) % CeeGraph, Bio-Logic Systems Corp.
335 elseif (c>445) && strncmp(ss(436:446),[HDR.FILE.Name,0,0,0,0],length(HDR.FILE.Name)+4) % CeeGraph, Bio-Logic Systems Corp.
338 elseif any(s(1)==[100:103]) && all(s([2:8])==[0,0,0,176,1,0,0]) && strcmpi(HDR.FILE.Ext,
'DDT');
340 elseif all(s([1:32])==[0,0,0,0,0,0,58,1,58,1,58,1,105,0,4,0,128,0,4,0,0,0,0,0,2,0,0,0,0,0,0,0]);
342 elseif all(s([1:4])==abs(
'NEX1'));
344 elseif all(s([1:6])==abs(
'Neuron'));
346 elseif all(strcmp(ss([1:10]),
'[FileInfo]'));
348 elseif all(s([1:4])==abs(
'SXDF'));
350 elseif all(s([1:4,6:132])==[abs(
'PLEX'),zeros(1,127)]); % http:
353 elseif strcmp(ss([1:4]),
'fLaC');
355 elseif strcmp(ss([1:4]),
'OggS');
357 elseif strcmp(ss([1:4]),
'.RMF');
360 elseif strncmp(ss,
'AON4',4);
362 elseif all(s(3:7)==abs(
'-lh5-'));
364 elseif (c>117) && strncmp(ss,
'PSID',4);
366 HDR.Title = ss(23:54);
367 HDR.Author = ss(55:86);
368 HDR.Copyright = ss(87:118);
370 elseif strncmp(ss,
'.snd',4);
372 HDR.Endianity =
'ieee-be';
373 elseif strncmp(ss,
'dns.',4);
375 HDR.Endianity =
'ieee-le';
376 elseif (c>11) && strcmp(ss([1:4,9:12]),
'RIFFWAVE');
378 HDR.Endianity =
'ieee-le';
379 elseif (c>10) && strcmp(ss([1:4,9:11]),
'FORMAIF');
381 HDR.Endianity =
'ieee-be';
382 elseif (c>11) && strcmp(ss([1:4,9:12]),
'RIFFAVI ');
384 HDR.Endianity =
'ieee-le';
385 elseif (c>20) && all(s([1:4,9:21])==[abs(
'RIFFRMIDMThd'),0,0,0,6,0]);
387 HDR.Endianity =
'ieee-be';
388 elseif all(s(1:9)==[abs(
'MThd'),0,0,0,6,0]) && any(s(10)==[0:2]);
390 HDR.Endianity =
'ieee-be';
391 elseif (c>15) && ~isempty(findstr(ss(1:16),
'8SVXVHDR'));
393 elseif strcmp(ss([1:4,9:12]),
'RIFFILBM');
395 elseif strcmp(ss([1:4]),
'2BIT');
397 elseif all(s([1:4])==[26,106,0,0]);
399 HDR.Endianity =
'ieee-le';
400 elseif all(s([1:4])==[0,0,106,26]);
402 HDR.Endianity =
'ieee-le';
403 elseif strncmp(ss,
'|CF,',4)
405 elseif strcmp(ss([1:15]),'IMA_ADPCM_Sound');
406 HDR.TYPE='IMA ADPCM';
407 elseif all(s([1:8])==[abs('NIST_1A'),0]);
409 elseif (c>77) && strcmp(ss(1:78),'HEADER RECORD*******LIBRARY HEADER RECORD!!!!!!!000000000000000000000000000000');
410 HDR.TYPE='SAS_XPORT';
411 elseif (c>22) && strncmp(ss(1:23),'$FL2@(
#) SPSS DATA FILE',8);
413 if all(s(66:68)==0) HDR.Endianity = 'ieee-le';
414 elseif all(s(65:67)==0) HDR.Endianity = 'ieee-be';
416 elseif (c>15) && strcmp(ss(1:16),['SQLite format 3',
char(0)]) && s(22)==64 && s(23)==32 && all(s(69:92)==0),
418 elseif all(s(3:4)==[1,0]) && any(s(1)==[113,114]) && any(s(2)==[1:2]),
421 elseif all(s([1:7])==[abs('SOUND'),0,13]);
423 elseif (c>17) && strcmp(ss([1:18]),'SOUND SAMPLE DATA ');
425 elseif (c>18) && strcmp(ss([1:19]),'Creative Voice File');
427 elseif strcmp(ss([5:8]),'moov'); % QuickTime movie
429 elseif strncmp(ss,'FWS',3) || strncmp(ss,'CWS',3); % Macromedia
432 HDR.SWF.size = s(5:8)*256.^[0:3]';
433 elseif all(s(1:16)==hex2dec(reshape('3026b2758e66cf11a6d900aa0062ce6c',2,16)')')
434 %'75B22630668e11cfa6d900aa0062ce6c'
437 elseif strncmp(ss,'MPv4',4);
439 HDR.Date = ss(65:87);
440 elseif strncmp(ss,'RG64',4);
442 elseif strncmp(ss,'DTDF',4);
444 elseif strncmp(ss,'RSRC',4);
446 elseif strncmp(ss,'IAvSFo',6);
448 elseif any(s(4)==(2:7)) && all(s([1:3,6:2:14,26])==0) ; % [int32] 2...7
449 %% high
byte of month, day, hour, min, sec and bits must be zero.
452 elseif (c>160) && FLAG.IS_UFF,
453 K = strfind(ss(81:161),' ')+80; K = K(1);
454 HDR.TYPE=['UFF',deblank(ss(K+[0:6]))];
456 elseif all(s(1:4)==hex2dec(reshape('AFFEDADA',2,4)')'); % Walter Graphtek
458 HDR.Endianity = 'ieee-le';
459 elseif all(s(1:4)==hex2dec(reshape('DADAFEAF',2,4)')');
461 HDR.Endianity = 'ieee-le';
462 elseif all(s(1:4)==hex2dec(reshape('5555FEAF',2,4)')');
464 HDR.Endianity = 'ieee-le';
465 elseif all(s(1:4)==[14,15,23,0]);
468 elseif strncmp(ss,'HeaderLen=',10);
469 HDR.TYPE = 'BCI2000';
471 elseif strncmp(ss,'BCI2000',7);
472 HDR.TYPE = 'BCI2000';
475 elseif (c>11) && strcmp(ss([1:4,9:12]),'RIFFCNT ')
476 HDR.TYPE='EEProbe-CNT'; % continuous EEG in EEProbe format, ANT Software (NL) and MPI Leipzig (DE)
477 elseif all(s(1:4)==[38 0 16 0])
478 HDR.TYPE='EEProbe-AVR'; % averaged EEG in EEProbe format, ANT Software (NL) and MPI Leipzig (DE)
480 elseif strncmp(ss,'eerT',4);
481 HDR.TYPE='HEKA PatchMaster';
482 elseif strncmp(ss,'IGOR',4);
484 elseif strncmp(ss,'ISHNE1.0',8); % ISHNE Holter standard output file.
486 elseif strncmp(ss,'rhdE',4); % Holter Excel 2 file, not supported yet.
489 elseif strncmp(ss,'RRI',3); % R-R interval format % Holter Excel 2 file, not supported yet.
491 elseif strncmp(ss,'Repo',4); % Repo Holter Excel 2 file, not supported yet.
493 elseif strncmp(ss,'Beat',4); % Beat file % Holter Excel 2 file, not supported yet.
495 elseif strncmp(ss,'Evnt',4); % Event file % Holter Excel 2 file, not supported yet.
498 elseif strncmp(ss,'CFWB',4); % Chart For Windows Binary data, defined by ADInstruments.
500 elseif strncmp(ss,'FILE FORMAT=RigSys',18); % RigSys file format
503 elseif any(s(3:6)*(2.^[0;8;16;24]) == (30:42))
504 HDR.VERSION = s(3:6)*(2.^[0;8;16;24]);
505 offset2 = s(7:10)*(2.^[0;8;16;24]);
507 if HDR.VERSION < 34, offset = 150;
508 elseif HDR.VERSION < 35, offset = 164;
509 elseif HDR.VERSION < 36, offset = 326;
510 elseif HDR.VERSION < 38, offset = 886;
511 elseif HDR.VERSION < 39, offset = 1894;
512 elseif HDR.VERSION < 41, offset = 1896;
513 elseif HDR.VERSION ==41, offset = 1944;
515 fprintf(2,'Warning: Version %i of ACQ format not supported (yet).\n',HDR.VERSION);
517 if (offset==offset2),
521 elseif (s(1) == 253) && (HDR.FILE.size==(s(6:7)*[1;256]+7));
523 elseif all(s(1:4) == [253, 174, 45, 5]);
525 elseif all(s(1:8) == [1,16,137,0,0,225,165,4]);
528 elseif strfind(ss,'ALPHA-TRACE-MEDICAL');
531 elseif strncmp(ss,'SamplingRate=',13) && strcmp(HDR.FILE.Name,'patient'),
532 % Freiburg Prediction Contest
534 HDR.FEPI.PatientFile = fullfile(HDR.FILE.Path,'patient.txt');
535 fid2 = fopen(fullfile(HDR.FILE.Path,'datafiles.txt'),'r');
543 HDR.FEPI.ListOfDataFiles{k,1} = tmp;
548 elseif all(s(5:18)==[40,0,4,1,44,1,102,2,146,3,44,0,190,3])
549 %HDR.FILE.size == (s(37:40)*256.^[0:3]
')
551 tmp=repmat(',
',1,19);
552 tmp([1:4,6:7,9:10,12:13,15:16,18:19])=s([153:160,162:167]);
553 HDR.T0 = str2double(char(tmp));
554 tmp([1:4,6:7,9:10])=s([128:135]);
555 HDR.Patient.Birthday = str2double(char(tmp));
557 HDR.s8=fread(fid,[1,inf],'uint8
');
559 HDR.s16=fread(fid,[1,inf],'uint16
');
561 elseif strfind(ss,'W1N10936.
');
564 elseif all(s(1:4) == [27,153,153,153]);
567 elseif all(s(1:4) == [28,153,153,153]);
571 elseif all(s(1:2)==[hex2dec('55
'),hex2dec('AA
')]);
572 HDR.TYPE='RDF
'; % UCSD ERPSS aquisition system
573 elseif ( (c>107) && all(reshape(s(1:32),1,[])==[abs('Synergy
'),0,abs('012.003.000.000
'),0,28,0,0,0,2,0,0,0]) && strcmp(ss(64:78),'CRawDataElement
') && strcmp(ss(86:99),'CRawDataBuffer
') ),
575 HDR.SampleRate = 50000;
577 elseif strncmp(ss,'Stamp
',5)
578 HDR.TYPE='XLTEK-EVENT
';
580 elseif all(s(1:2)==[hex2dec('55
'),hex2dec('3A
')]); % little endian
582 HDR.Endianity = 'ieee-le
';
583 elseif all(s(1:2)==[hex2dec('3A
'),hex2dec('55
')]); % big endian
585 HDR.Endianity = 'ieee-be
';
587 elseif strncmp(ss,'MATLAB Data Acquisition File.
',29); % Matlab Data Acquisition File
589 elseif strncmp(ss,'MATLAB 5.0 MAT-file
',19);
591 if (s(127:128)==abs('MI
')),
592 HDR.Endianity = 'ieee-le
';
593 elseif (s(127:128)==abs('IM
')),
594 HDR.Endianity = 'ieee-be
';
596 elseif strncmp(ss,'Model {
',7);
598 elseif all(s(85:92)==abs('SAS FILE
')); % FREESURVER TRIANGLE_FILE_MAGIC_NUMBER
601 elseif all(s(1:16)==[15 195 123 28 207 45 109 75 138 234 31 100 206 210 185 23])
602 HDR.TYPE='no spec (nicolet?)
';
604 elseif any(s(1)==[49:51]) && all(s([2:4,6])==[0,50,0,0]) && any(s(5)==[49:50]),
605 HDR.TYPE = 'WFT
'; % nicolet
607 elseif all(s(1:3)==[255,255,254]) && FLAG.FS3,
608 %any(s==10) && all((s(4:pos1_ascii10)>=32) & (s(4:pos1_ascii10)<128)); % FREESURVER TRIANGLE_FILE_MAGIC_NUMBER
610 elseif all(s(1:3)==[255,255,255]); % FREESURVER QUAD_FILE_MAGIC_NUMBER or CURVATURE
612 elseif all(s(2:6)==[134,1,0,2,0]) && any(s(1)==[162:164]); % SCAN *.TRI file
615 elseif strncmp(ss,'3D Geometry File Format
',24); % Rhino Model file
617 elseif strncmp(ss,'Iges
',5);
619 elseif strncmp(ss,'solid
',5);
620 HDR.TYPE='GEO:STL:ASCII
';
621 elseif strncmp(ss,'STL binary file
',15) && (HDR.FILE.size==(s(81:84)*256.^[3:-1:0]')*50+84);
622 HDR.TYPE=
'GEO:STL:BIN';
623 HDR.Endianity=
'ieee-be';
624 elseif strncmp(ss,
'STL binary file',15) && (HDR.FILE.size==(s(81:84)*256.^[0:3]
')*50+84);
625 HDR.TYPE='GEO:STL:BIN
';
626 HDR.Endianity='ieee-le
';
627 elseif strncmp(ss,'PLY
',3); % Polygon file format
628 % http://local.wasp.uwa.edu.au/~pbourke/dataformats/ply/
629 % http://en.wikipedia.org/wiki/PLY_%28file_format%29
632 elseif all(s(1:16)==[162 134 1 0 0 0 1 0 205 204 76 63 0 0 192 63]);
635 elseif all((s(1:4)*(2.^[24;16;8;1]))==1229801286); % GE 5.X format image
638 elseif all(s(1:2)==[105,102]);
640 elseif all(s(1:2)==[234,96]);
644 elseif 0, any(s(1)==[3,131]);
646 elseif strncmp(ss,'DDMF
',4);
648 elseif strncmp(ss,'DMS
',4);
650 elseif strncmp(ss,'FAR
',3);
652 elseif all(ss(5:6)==[175,18]);
654 elseif strncmp(ss,'GF1PATCH110
',12);
656 elseif strcmp(ss([1:6,12]),'(DWF V)
');
657 HDR.VERSION = str2double(ss(7:11));
658 if ~isnan(HDR.VERSION),
659 HDR.TYPE='IMAGE:DWF
'; % Design Web Format from Autodesk
661 elseif strncmp(ss,'GIF87a
',6);
662 HDR.TYPE='IMAGE:GIF
';
663 elseif strncmp(ss,'GIF89a
',6);
664 HDR.TYPE='IMAGE:GIF
';
665 elseif strncmp(ss,'CPT9FILE
',8); % Corel PhotoPaint Format
668 elseif all(s(21:28)==abs('ACR-NEMA
'));
671 elseif all(s(129:132)==abs('DICM
'));
673 elseif all(s([2,4,6:8])==0) && all(s([1,3,5])); % DICOM candidate
675 elseif all(s(1:18)==[8,0,5,0,10,0,0,0,abs('ISO_IR 100
')]) % DICOM candidate
677 elseif all(s(12+[1:18])==[8,0,5,0,10,0,0,0,abs('ISO_IR 100
')]) % DICOM candidate
679 elseif all(s([1:8,13:20])==[8,0,0,0,4,0,0,0,8,0,5,0,10,0,0,0]) % DICOM candidate
681 % more about the heuristics to identify DICOM files at
682 % http://groups.google.com/groups?hl=fr&lr=&frame=right&th=cb048de7b4459bd3&seekm=9h9jrs%247jf%40news.Informatik.Uni-Oldenburg.DE#link1
683 % http://fixunix.com/dicom/545185-dicom-file-without-file-meta-information-size-preamble.html
685 elseif strncmp(ss,'*3DSMAX_ASCIIEXPORT
',19)
687 elseif strncmp(ss,'999
',3)
688 HDR.TYPE='DXF-Ascii
';
689 elseif all(s([1:4])==[32,32,48,10])
691 elseif all(s([1:4])==[103,23,208,113])
693 elseif strncmp(ss,'AutoCAD Binary DXF
',18)
694 HDR.TYPE='DXF-Binary
';
696 elseif all(s(1:24)==[0,0,39,10,zeros(1,20)])
699 elseif strncmp(ss,'%!PS-Adobe
',10)
701 elseif strncmp(ss,'HRCH: Softimage 4D Creative Environment
',38)
703 elseif strncmp(ss,'#Inventor V2.0 ascii
',11)
705 HDR.VERSION = ss(12:14);
706 elseif strncmp(ss,'HRCH: Softimage 4D Creative Environment
',38)
708 elseif all(s([1:2])==[1,218])
710 elseif strncmp(ss,'#$SMF
',5)
712 HDR.VERSION = str2double(ss(7:10));
713 elseif strncmp(ss,'#SMF
',4)
715 HDR.VERSION = str2double(ss(5:8));
717 elseif all(s([1:4])==[127,abs('ELF
')])
719 elseif all(s([1:4])==[77,90,192,0])
721 elseif all(s([1:4])==[77,90,80,0])
723 elseif all(s([1:4])==[77,90,128,0])
725 elseif all(s([1:4])==[77,90,144,0])
727 elseif all(s(1:4)==hex2dec(['CA
';'FE
';'BA
';'BE
'])')
729 elseif all(s([1:8])==[254,237,250,206,0,0,0,18])
732 elseif all(s(1:33)==[208 207 17 224 161 177 26 225 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 62 00 03 00 254 255 09 00 06]);
734 elseif all(s(1:24)==[208,207,17,224,161,177,26,225,zeros(1,16)]); % MS-EXCEL candidate
737 elseif strncmp(lower(ss),'<?php',5)
739 elseif ~isempty(findstr(ss,'<AnnotatedECG xmlns="urn:hl7-org:v3" xmlns:voc="urn:hl7-org:v3/voc"'))
741 elseif strncmp(ss,'<WORLD>',7)
743 elseif all(s(1:2)==[255,254]) && all(s(4:2:end)==0)
744 HDR.TYPE='XML-UTF16';
745 elseif ~isempty(findstr(ss,'?xml version'))
747 elseif ~isempty(findstr(ss,'Serial number'))
748 HDR.TYPE='ASCII:IBI';
750 elseif strncmp(ss,'ABF',3)
752 elseif strncmp(ss,'CLPX',3)
754 elseif strncmp(ss,'FTCX',3)
756 elseif all(s(1:4)==[0,0,128,63]) %
float(1)
758 elseif all(s(1:4)==[0,0,32,65]) %
float(10)
761 elseif all(s(1:4)==abs(['ATF',9]))
762 HDR.TYPE='ATF'; % axon text file
763 [tmp,t]=strtok(ss,[9,10,13,32]);
764 [tmp,t]=strtok(t,[9,10,13,32]);
767 elseif strncmp(ss,'binterr1.3',10)
769 elseif all(s([1:2,7:10])==[abs('BM'),zeros(1,4)])
770 HDR.TYPE='IMAGE:BMP';
771 HDR.Endianity = 'ieee-le';
772 elseif strncmp(ss,'
#FIG',4)
774 HDR.VERSION = strtok(ss(6:end),[10,13]);
775 elseif strncmp(ss,
'SIMPLE = T / Standard FITS format',30)
776 HDR.TYPE='IMAGE:FITS';
777 elseif all(s(1:40)==[137,abs('HDF'),13,10,26,10,0,0,0,0,0,8,8,0,4,0,16,0,3,zeros(1,11),repmat(255,1,8)]) && (HDR.FILE.size==s(41:44)*2.^[0:8:24]')
779 elseif strncmp(ss,'CDF',3)
781 elseif strncmp(ss,'%%MatrixMarket matrix coordinate',32)
782 HDR.TYPE='MatrixMarket';
783 elseif s(1:4)*2.^[0:8:24]'==5965600, % Kodac ICC format
785 HDR.HeadLen = s(5:8)*2.^[0:8:24];
786 HDR.T0 = s([20,19,18,17,24,23]);
787 elseif strncmp(ss,'IFS',3)
788 HDR.TYPE='IMAGE:IFS';
789 elseif strncmp(ss,'OFF',3)
792 elseif strncmp(ss,'4OFF',4)
795 elseif strncmp(ss,'.PBF',4)
797 elseif all(s([1,3])==[10,1]) && any(s(2)==[0,2,3,5]) && any(s(4)==[1,4,8,24]) && any(s(59)==[4,3])
799 tmp = [2.5, 0, 2.8, 2.8, 0, 3];
800 HDR.VERSION=tmp(s(2)+1);
802 HDR.BitsPerPixel = s(4);
804 elseif all(s(1:20)==[ 99,253,45,1,3,0,1,0,1,zeros(1,11)])
806 HDR.T0 = [1,256]*reshape(s(21:32),2,6);
808 elseif all(s(1:8)==[139,74,78,71,13,10,26,10])
809 HDR.TYPE='IMAGE:JNG';
810 elseif all(s(1:8)==[137,80,78,71,13,10,26,10])
811 HDR.TYPE='IMAGE:PNG';
812 elseif (ss(1)=='P') && any(ss(2)=='123') % PBMA, PGMA, PPMA
813 HDR.TYPE='IMAGE:PBMA';
815 HDR.TYPE(8)=
id(s(2)-48);
817 elseif (ss(1)=='P') && any(ss(2)=='456') % PBMB, PGMB, PPMB
818 HDR.TYPE='IMAGE:PBMB';
820 HDR.TYPE(8) =
id(s(2)-abs('3'));
821 [t,ss] = strtok(ss,[10,13]);
823 [t,ss] = strtok(ss,[10,13]);
824 lt = lt + length(t) + 1;
825 while strncmp(t,'
#',1)
826 [t,ss] = strtok(ss,[10,13]);
827 lt = lt + length(t) + 1;
830 [t,ss] = strtok(ss,[10,13]);
831 lt = lt + length(t) + 1;
835 elseif strcmpi(HDR.FILE.Ext,
'XBM') && ~isempty(strfind(ss,
'bits[]')) && ~isempty(strfind(ss,
'width')) && ~isempty(strfind(ss,
'height'))
836 HDR.TYPE='IMAGE:XBM';
843 HDR.TYPE='IMAGE:XPM';
845 elseif strncmp(ss,['
# ',HDR.FILE.Name,'.poly'],8+length(HDR.FILE.Name))
847 elseif all(s([1,3,7:12])==[255,255,abs(
'Exif'),0,0]) && any(s(2)==[216:217]) && any(s(4)==[224:225]);
848 HDR.TYPE=
'IMAGE:EXIF';
849 HDR.Endianity =
'ieee-be';
850 elseif all(s([1:4,7:12])==[255,216,255,225,abs(
'Exif'),0,0]);
851 HDR.TYPE=
'IMAGE:EXIF';
852 HDR.Endianity =
'ieee-be';
853 elseif all(s([1:3])==[255,216,255])
854 HDR.TYPE='IMAGE:JPG-';
855 HDR.Endianity = 'ieee-be';
856 elseif all(s([1:4,7:11])==[255,217,255,224,abs('JFIF'),0])
857 HDR.TYPE='IMAGE:JPG1';
858 HDR.Endianity = 'ieee-be';
859 elseif all(s([1:4,7:11])==[255,216,255,224,abs('JFIF'),0])
860 HDR.TYPE='IMAGE:JPG2';
861 HDR.Endianity = 'ieee-be';
862 elseif all(s(1:4)==[216,255,224,255])
863 HDR.TYPE='IMAGE:JPG3';
864 HDR.Endianity = 'ieee-le';
865 elseif all(s([1,3,65])==[10,1,0]) && any(s(2)==[0,2,3,4,5]) && any(s(4)==[1,2,4,8]) && any(s(66)==[1:4]) && any(s(69)==[1:2])
866 HDR.TYPE='IMAGE:PCX';
867 HDR.Endianity = 'ieee-le';
868 elseif all(s(1:4)==[149, 106, 166, 89])
869 HDR.TYPE='IMAGE:SunRasterfile';
870 HDR.Endianity = 'ieee-be';
871 elseif all(s(1:20)==['L',0,0,0,1,20,2,0,0,0,0,0,192,0,0,0,0,0,0,70])
873 tmp = fread(fid,inf,'uint8');
875 elseif all(s(1:111)==[0,0,1,186,68,0,4,0,4,1,1,137,195,248,0,0,1,187,0,18,128,196,225,0,225,127,185,224,232,184,192,32,189,224,58,191,224,2,0,0,1,191,7,212,80,0,0,0,0,84,47,0,0,0,0,0,255,255,255,255,255,0,0,0,0,0,64,16,0,0,0,0,74,86,67,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
876 HDR.TYPE='MOVIE:MOD';
877 elseif all(s(1:3)==[0,0,1])
878 HDR.TYPE='MOVIE:MPG2MOV';
879 elseif strcmp(ss([3:5,7]),'-lh-');
881 elseif strcmp(ss([3:5,7]),'-lz-');
883 elseif strcmp(ss(1:3),'MMD');
885 elseif 0, % conflict with some WFDB-data
886 %(s(1)==255) && any(s(2)>=224);
888 elseif strncmp(ss(5:8),'mdat',4);
891 elseif all(s(1:2)==[26,63]);
893 elseif strncmp(ss,'%PDF',4);
895 elseif strncmp(ss,'QLIIFAX',7);
897 elseif strncmp(ss,'.RMF',4);
899 elseif strncmp(ss,'IREZ',4);
901 elseif strncmp(ss,'{\rtf
',5);
903 elseif all(s(1:4)==[73,73,42,0]);
904 HDR.TYPE='IMAGE:TIFF
';
905 HDR.Endianity = 'ieee-le
';
906 HDR.FLAG.BigTIFF = 0;
907 elseif all(s(1:4)==[77,77,0,42]);
908 HDR.TYPE='IMAGE:TIFF
';
909 HDR.Endianity = 'ieee-be
';
910 HDR.FLAG.BigTIFF = 0;
911 elseif all(s(1:8)==[73,73,43,0,8,0,0,0]);
912 HDR.TYPE='IMAGE:TIFF
';
913 HDR.Endianity = 'ieee-le
';
914 HDR.FLAG.BigTIFF = 1;
915 elseif all(s(1:8)==[77,77,0,43,0,8,0,0]);
916 HDR.TYPE='IMAGE:TIFF
';
917 HDR.Endianity = 'ieee-be
';
918 HDR.FLAG.BigTIFF = 1;
919 elseif strncmp(ss,'StockChartX
',11);
921 elseif all(ss(1:2)==[25,149]);
923 elseif strncmp(ss,'TVF 1.1A
',7);
925 elseif all(s(1:12)==[abs('TVF 1.1B
'),1,0,0,0]);
927 HDR.Endianity = 'ieee-le
';
928 elseif all(s(1:12)==[abs('TVF 1.1B
'),0,0,0,1]);
930 HDR.Endianity = 'ieee-be
';
931 elseif strncmp(ss,'#VRML
',5);
933 elseif strncmp(ss,'# vtk DataFile Version
',23);
935 HDR.VERSION = ss(24:26);
936 elseif all(ss(1:5)==[0,0,2,0,4]);
938 elseif all(ss(1:5)==[0,0,2,0,abs('Q
')]);
940 elseif all(s(1:8)==hex2dec(['30
';'26
';'B2
';'75
';'8E
';'66
';'CF
';'11
'])');
943 % compression formats
944 elseif strncmp(ss,
'BZh91AH&SY',10);
946 elseif all(s(1:3)==[66,90,104]);
948 elseif strncmp(ss,
'MSCF',4);
950 elseif all(s(1:3)==[31,139,8]);
952 if exist(
'OCTAVE_VERSION',
'builtin')
954 HDR.FILE.PERMISSION = [HDR.FILE.PERMISSION ,'z'];
958 elseif all(s(1:3)==[31,157,144]);
960 elseif all(s([1:4])==[80,75,3,4]) && (c>=30)
962 HDR.VERSION = s(5:6)*[1;256];
963 HDR.ZIP.FLAG = s(7:8);
964 HDR.ZIP.CompressionMethod = s(9:10);
966 % converting MS-Dos Date*Time format
967 tmp = s(11:14)*2.^[0:8:31]';
968 HDR.T0(6) = rem(tmp,2^5)*2; tmp=floor(tmp/2^5);
969 HDR.T0(5) = rem(tmp,2^6); tmp=floor(tmp/2^6);
970 HDR.T0(4) = rem(tmp,2^5); tmp=floor(tmp/2^5);
971 HDR.T0(3) = rem(tmp,2^5); tmp=floor(tmp/2^5);
972 HDR.T0(2) = rem(tmp,2^4); tmp=floor(tmp/2^4);
973 HDR.T0(1) = 1980+tmp;
975 HDR.ZIP.CRC = s(15:18)*2.^[0:8:31]';
976 HDR.ZIP.size2 = s(19:22)*2.^[0:8:31]';
977 HDR.ZIP.size1 = s(23:26)*2.^[0:8:31]';
978 HDR.ZIP.LengthFileName = s(27:28)*[1;256];
979 HDR.ZIP.filename =
char(s(31:min(c,30+HDR.ZIP.LengthFileName)));
980 HDR.ZIP.LengthExtra = s(29:30)*[1;256];
981 HDR.HeadLen = 30 + HDR.ZIP.LengthFileName + HDR.ZIP.LengthExtra;
982 HDR.ZIP.tmp =
char(s);
983 HDR.ZIP.Extra = s(31+HDR.ZIP.LengthFileName:min(c,HDR.HeadLen));
985 elseif strncmp(ss(31:end),'mimetypeapplication/vnd.sun.xml.writer',38)
987 elseif strncmp(ss(31:end),'mimetypeapplication/vnd.oasis.opendocument.spreadsheet',38)
990 elseif strncmp(ss,'ZYXEL',5);
992 elseif strcmpi([HDR.FILE.Name,' '],ss(1:length(HDR.FILE.Name)+1)) && any(ss(length(HDR.FILE.Name)+2)==' 0123456789');
994 elseif strcmpi(HDR.FILE.Name,ss(1:length(HDR.FILE.Name)))
996 elseif strncmp(ss,['
# ',HDR.FILE.Name],length(HDR.FILE.Name)+2);
1000 %(c>20) && (s(1:4)*256.^[0:3]
'<4053) && any(s(13)==[0,1]) && all(s(14:16)==0) && any(s(17:20)>0) && all(mat4.matrixname>='0
' && mat4.matrixname<='z
') && ~mat4.matrixname(20+mat4.matrixname_len) && all(any(mat4.type(ones(6,1),:)==[0,0:4;zeros(1,6);0:5;0:2,0,0,0]')),
1001 %& (type_mat4(1)==(0:4)) && (type_mat4(2)==0) && (type_mat4(3)==(0:5)) && (type_mat4(4)==(0:2))
1002 % should be last, otherwise to many
false detections
1005 if mat4.type(1)==
'0'
1006 HDR.MAT4.opentyp =
'ieee-le';
1007 elseif mat4.type(1)==
'1'
1008 HDR.MAT4.opentyp =
'ieee-be';
1009 elseif mat4.type(1)==
'2'
1010 HDR.MAT4.opentyp =
'vaxd';
1011 elseif mat4.type(1)==
'3'
1012 HDR.MAT4.opentyp =
'vaxg';
1013 elseif mat4.type(1)==
'4'
1014 HDR.MAT4.opentyp =
'cray';
1017 elseif ~isempty(findstr(ss,
'### Table of event codes.'))
1021 while ~feof(fid),%length(line),
1023 elseif strncmp(line,'0x',2),
1025 [ix,desc] = strtok(line,
char([9,32,13,10]));
1026 ix = hex2dec(ix(3:end));
1027 HDR.EVENT.CodeDesc{N1,1} = desc(2:end);
1028 HDR.EVENT.CodeIndex(N1,1) = ix;
1029 elseif strncmp(line,
'### 0x',6)
1031 HDR.EVENT.GroupDesc{N2,1} = line(12:end);
1033 HDR.EVENT.GroupIndex{N2,1} = tmp;
1034 tmp1 = tmp; tmp1(tmp~=
'_') =
'F'; tmp1(tmp==
'_')=
'0';
1035 HDR.EVENT.GroupMask(N2,1) = bitand(hex2dec(tmp1),hex2dec(
'7FFF'));
1036 tmp1 = tmp; tmp1(tmp==
'_') =
'0';
1037 HDR.EVENT.GroupValue(N2,1) = hex2dec(tmp1);
1041 HDR.TYPE =
'EVENTCODES';
1042 global BIOSIG_GLOBAL
1043 BIOSIG_GLOBAL.EVENT = HDR.EVENT;
1044 BIOSIG_GLOBAL.ISLOADED_EVENTCODES = 1;
1046 elseif strcmp(HDR.FILE.Ext,
'Markers') && strcmp(ss(1:14),
'Sampling rate:'),
1047 HDR.EVENT.SampleRate =
str2double(ss(15:strfind(ss,
'Hz')-1));
1048 [t,r]=strtok(ss,
char([10,13]));
1049 [t,r]=strtok(r,
char([10,13]));
1050 [t,r]=strtok(r,
char([10,13]));
1052 while sum(t==
',')>3,
1055 HDR.EVENT.POS(k,1) = n(3);
1056 HDR.EVENT.DUR(k,1) = n(4);
1058 HDR.EVENT.CHN(k,1) = 0;
1060 HDR.EVENT.CHN(k,1) = n(5);
1063 [t,r]=strtok(r,
char([10,13]));
1065 [HDR.EVENT.CodeDesc,ix,HDR.EVENT.TYP]=unique(Desc);
1068 elseif ~strcmp(version,'3.5') %% exclude FreeMat v3.5
1071 status = fseek(fid,3228,-1);
1072 [s0,c]=fread(fid,[1,4],'uint8');
1073 if (status && (c==4))
1074 if all((s0(1:4)*(2.^[24;16;8;1]))==1229801286); % GE LX2 format image
1079 elseif (c>176) && any(s(176)==[0:4])
1080 HDR.TYPE='MicroMed TRC';
1086 if strcmp(HDR.TYPE,'unknown')
1088 [s,len] = fread(fid,[1,min(1e5,HDR.FILE.size)],'uint8');
1089 HDR.FLAG.ASCII = all((s>=32) | (s==9) | (s==10) | (s==13));
1095 if all((s==32) | ((s>='0') & (s<='9'))) && strcmpi(HDR.FILE.Ext,'DCD') && (len>=3000);
1098 HDR.TYPE = 'CSE-database';
1105 if strcmpi(HDR.TYPE,'unknown'),
1106 % alpha-TRACE Medical software
1107 if exist(fullfile(HDR.FILE.Path,'alpha.alp'),'file')
1108 %HDR.TYPE = 'alpha'; %alpha trace medical software
1109 HDR =
getfiletype(fullfile(HDR.FILE.Path,'alpha.alp'));
1110 if strcmp(HDR.TYPE,'alpha')
1115 %%% this is the file type check based on the file extionsion, only.
1118 elseif exist(fullfile(HDR.FILE.Path,[HDR.FILE.Name,'.dm6']),'file') && exist(fullfile(HDR.FILE.Path,[HDR.FILE.Name,'.chn']),'file') && exist(fullfile(HDR.FILE.Path,[HDR.FILE.Name,'.log']),'file'),
1119 % Nakamura dataset from S. Bressler
1120 HDR.TYPE='nakamura';
1123 elseif strcmpi(HDR.FILE.Ext,'HEA'),
1124 % MIT-ECG / Physiobank format
1127 elseif length(HDR.FILE.Ext) && ~isempty(strmatch(HDR.FILE.Ext,{
'16a',
'abp',
'al',
'apn',
'ari',
'atr',
'atr-',
'ecg',
'pap',
'ple',
'qrs',
'qrsc',
'sta',
'stb',
'stc'},
'exact')),
1128 % Physiobank annotation files
1131 elseif strcmpi(HDR.FILE.Ext,
'DAT')
1133 ix = find(HDR.s(1:120)==10);
1134 ix1 = strfind(HDR.s(1:120),'Andrews & Herzberg (1985)');
1137 HDR.TYPE = 'AndrewsHerzberg1985';
1138 elseif (length(ix) > 3)
1139 line = HDR.s(1:ix(1)-1);
1141 HDR.SampleRate = 1000/n(1);
1142 %HDR.EVENT.POS = n([2,4])/1000*HDR.SampleRate;
1143 %HDR.EVENT.DUR = (n([3,5])-n([2,4]))/1000*HDR.SampleRate;
1144 %HDR.EVENT.TYP = [hex2dec('502');hex2dec('503');hex2dec('506')];
1145 line = HDR.s(ix(1)+1:ix(2)-1);
1147 HDR.Patient.Sex = strncmpi(sa{3},
'M',1) + strncmpi(sa{3},
'F',1)*2;
1148 HDR.Patient.Age = n(4);
1149 line = HDR.s(ix(2)+1:ix(3)-1);
1151 line = HDR.s(ix(3)+1:ix(4)-1);
1153 HDR.HeadLen = ix(4);
1154 fid = fopen(HDR.FileName,
'r');
1155 [HDR.data,len] = fread(fid,[1,1e7],
'uint8');
1157 HDR.TYPE =
'CinC2007Challenge';
1162 tmp = dir(fullfile(HDR.FILE.Path,[HDR.FILE.Name,
'.hea']));
1164 tmp = dir(fullfile(HDR.FILE.Path,[HDR.FILE.Name,
'.HEA']));
1168 [tmp,tmp1,tmp2] = fileparts(tmp.name);
1169 HDR.FILE.Ext = tmp2(2:end);
1172 tmp = dir(fullfile(HDR.FILE.Path,[HDR.FILE.Name,
'.set'])); % EEGLAB file
1175 tmp = dir(fullfile(HDR.FILE.Path,[HDR.FILE.Name,
'.vhdr']));
1178 tmp = dir(fullfile(HDR.FILE.Path,[HDR.FILE.Name,
'.VHDR']));
1181 HDR =
getfiletype(fullfile(HDR.FILE.Path,tmp.name));
1184 elseif strcmpi(HDR.FILE.Ext,
'flt') && exist([HDR.FileName,
'.hdr'],
'file');
1185 HDR.TYPE =
'ET-MEG'; % ET-MEG format
1186 HDR.FileName = [HDR.FileName,
'.hdr'];
1187 elseif strcmpi(HDR.FILE.Ext,
'bin') && exist([HDR.FileName,
'.hdr'],
'file');
1188 HDR.TYPE =
'ET-MEG'; % ET-MEG format
1189 HDR.FileName = [HDR.FileName,
'.hdr'];
1190 elseif strcmpi(HDR.FILE.Ext,
'int') && exist([HDR.FileName,
'.hdr'],
'file');
1191 HDR.TYPE =
'ET-MEG'; % ET-MEG format
1192 HDR.FileName = [HDR.FileName,
'.hdr'];
1193 elseif strcmpi(HDR.FILE.Ext,
'hdr') && exist(fullfile(HDR.FILE.Path,HDR.FILE.Name),
'file');
1194 HDR.TYPE =
'ET-MEG'; % ET-MEG format
1195 %HDR.FileName = fullfile(HDR.FILE.Path,HDR.FILE.Name);
1197 elseif strcmpi(HDR.FILE.Ext,
'rhf'),
1198 HDR.FileName=fullfile(HDR.FILE.Path,[HDR.FILE.Name,
'.',HDR.FILE.Ext]);
1200 elseif strcmp(HDR.FILE.Ext,
'rdf'),
1201 HDR.FileName=fullfile(HDR.FILE.Path,[HDR.FILE.Name,
'.',HDR.FILE.Ext(1),
'h',HDR.FILE.Ext(3)]);
1203 elseif strcmp(HDR.FILE.Ext,
'RDF'),
1204 HDR.FileName=fullfile(HDR.FILE.Path,[HDR.FILE.Name,
'.',HDR.FILE.Ext(1),
'H',HDR.FILE.Ext(3)]);
1207 elseif strcmpi([HDR.FILE.Name,
'.',HDR.FILE.Ext],
'alldata.bin')
1208 if exist(fullfile(HDR.FILE.Path,'alldata.bin'),'file')
1209 if exist(fullfile(HDR.FILE.Path,'lefttrain.events'),'file')
1210 if exist(fullfile(HDR.FILE.Path,'righttrain.events'),'file')
1211 if exist(fullfile(HDR.FILE.Path,'test.events'),'file')
1212 HDR.TYPE = 'BCI2002b';
1215 elseif strcmpi(HDR.FILE.Ext,'txt') && (any(strfind(HDR.FILE.Path,'a34lkt')) || any(strfind(HDR.FILE.Path,'egl2ln'))) && any(strmatch(HDR.FILE.Name,{
'Traindata_0',
'Traindata_1',
'Testdata'}))
1216 HDR.TYPE = 'BCI2003_Ia+b';
1218 elseif any(strmatch(HDR.FILE.Name,{
'x_train',
'x_test'}))
1219 HDR.TYPE = 'BCI2003_III';
1221 elseif strcmpi(HDR.FILE.Ext,'hdm')
1223 elseif strcmpi(HDR.FILE.Ext,'hc')
1225 elseif strcmpi(HDR.FILE.Ext,'shape')
1227 elseif strcmpi(HDR.FILE.Ext,'shape_info')
1229 elseif strcmpi(HDR.FILE.Ext,'trg') && HDR.FLAG.ASCII
1230 HDR.TYPE = 'EEProbe-TRG';
1232 elseif strcmpi(HDR.FILE.Ext,'ainf') && HDR.FLAG.ASCII && exist(fullfile(HDR.FILE.Path,[HDR.FILE.Name,'.raw']),'file')
1235 elseif strcmpi(HDR.FILE.Ext,'rej')
1237 elseif strcmpi(HDR.FILE.Ext,'vol')
1239 elseif strcmpi(HDR.FILE.Ext,'bnd')
1241 elseif strcmpi(HDR.FILE.Ext,'msm')
1243 elseif strcmpi(HDR.FILE.Ext,'msr')
1244 HDR.TYPE = 'ASA2'; % ASA version 2.x, see http:
1246 elseif strcmpi(HDR.FILE.Ext,'dip')
1248 elseif strcmpi(HDR.FILE.Ext,'mri')
1250 elseif strcmpi(HDR.FILE.Ext,'iso')
1252 elseif strcmpi(HDR.FILE.Ext,'hdr')
1254 elseif strcmpi(HDR.FILE.Ext,'img')
1256 elseif strcmpi(HDR.FILE.Ext,'ddt')
1258 elseif strcmpi(HDR.FILE.Ext,'sx')
1260 elseif strcmpi(HDR.FILE.Ext,'sxi')
1262 elseif strcmpi(HDR.FILE.Ext,'nxa')
1264 elseif strcmpi(HDR.FILE.Ext,'nxe')
1267 elseif strcmpi(HDR.FILE.Ext,'ent')
1268 HDR.TYPE = 'XLTEK-EVENT';
1269 elseif strcmpi(HDR.FILE.Ext,'erd')
1272 elseif strcmpi(HDR.FILE.Ext,'etc')
1273 HDR.TYPE = 'XLTEK-ETC';
1274 fid = fopen(HDR.FileName,'r');
1275 fseek(fid,355,'bof');
1276 HDR.TIMESTAMP = fread(fid,1,'int32');
1279 % the following are Brainvision format, see http:
1280 elseif strcmpi(HDR.FILE.Ext,'seg') || strcmpi(HDR.FILE.Ext,'vmrk')
1281 % If this is really a BrainVision file, there should also be a
1282 % header with the same name and extension *.vhdr.
1283 tmp = fullfile(HDR.FILE.Path, [HDR.FILE.Name '.vhdr']);
1284 if exist(tmp, 'file')
1285 tmp = fullfile(HDR.FILE.Path, [HDR.FILE.Name '.VHDR']);
1287 if exist(tmp, 'file')
1291 elseif strcmpi(HDR.FILE.Ext,'vabs')
1293 elseif strcmpi(HDR.FILE.Ext,'bni') %%% Nicolet files
1294 tmp = fullfile(HDR.FILE.Path,[HDR.FILE.Name,'.eeg']); % nicolet
1295 if exist(tmp,'file'), % Nicolet
1299 elseif strcmpi(HDR.FILE.Ext,'eeg')
1300 tmp = fullfile(HDR.FILE.Path,[HDR.FILE.Name,'.vhdr']); % brainvision header file
1301 if ~exist(tmp,'file'), % brain vision
1302 tmp = fullfile(HDR.FILE.Path, [HDR.FILE.Name '.bni']); % nicolet
1304 if exist(tmp,'file')
1308 elseif strcmpi(HDR.FILE.Ext,'fif')
1309 HDR.TYPE = 'FIF'; % Neuromag MEG data (company is now part of 4D Neuroimaging)
1311 elseif strcmpi(HDR.FILE.Ext,'bdip')
1313 elseif strcmpi(HDR.FILE.Ext,'ela')
1315 elseif strcmpi(HDR.FILE.Ext,'trl')
1317 elseif (length(HDR.FILE.Ext)>2) && all(s>31),
1318 if all(HDR.FILE.Ext(1:2)=='0') && any(abs(HDR.FILE.Ext(3))==abs([48:57])), % WSCORE scoring file
1319 x = load('-ascii',HDR.FileName);
1320 HDR.EVENT.POS = x(:,1);
1321 HDR.EVENT.WSCORETYP = x(:,2);
1322 HDR.TYPE = 'WCORE_EVENT';
1325 elseif strcmpi(HDR.FILE.Ext,'hgt') && (rem(sqrt(HDR.FILE.size/2),1)==0)
1326 HDR.TYPE = 'IMAGE:HGT';
1331 if 0, strcmpi(HDR.TYPE,'unknown'),
1333 [status, HDR.XLS.sheetNames] = xlsfinfo(HDR.FileName)