1 function [HDR]=
famosopen(arg1,arg3,arg4,arg5,arg6)
2 % FAMOSOPEN opens FAMOS file
3 % However, it is recommended to use SOPEN instead .
4 % For loading whole data files, use SLOAD.
6 % see also: SOPEN, SREAD, SSEEK, STELL, SCLOSE, SWRITE, SEOF
10 % $Id:
famosopen.m 2702 2011-06-08 11:59:38Z schloegl $
11 % Copyright (c) 2007 by Alois Schloegl <a.schloegl@ieee.org>
12 % This is part of the BIOSIG-toolbox http:
14 % This program is free software; you can redistribute it and/or
15 % modify it under the terms of the GNU General Public License
16 % as published by the Free Software Foundation; either version 2
17 % of the License, or (at your option) any later version.
19 % This program is distributed in the hope that it will be useful,
20 % but WITHOUT ANY WARRANTY; without even the implied warranty of
21 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 % GNU General Public License
for more details.
24 % You should have received a copy of the GNU General Public License
25 % along with
this program;
if not, write to the Free Software
26 % Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 HDR.FileName = FILENAME;
33 [pfad,file,FileExt] = fileparts(HDR.FileName);
36 HDR.FILE.Ext = FileExt(2:length(FileExt));
37 HDR.FILE.PERMISSION =
'r';
43 if any(HDR.FILE.PERMISSION==
'r'),
45 HDR.FILE.FID = fopen(HDR.FileName,
'r');
47 fprintf(
'Error SOPEN: could not open file %s\n',HDR.FileName);
53 HDR.AS.SampleRate =[];
54 while ~feof(HDR.FILE.FID),
55 %POS = ftell(HDR.FILE.FID);
56 [t,count] = fread(HDR.FILE.FID,[1,1024],
'*char');
59 while length(tline)>512
61 ix = find(tline==
'|'); ix1=ix(1);
62 tline = tline(ix1+1:end);
65 % extract key, version, length
66 ix = find(tline==
','); ix = ix(1:3);
70 if ix(3)+1+keylen <= length(tline),
71 param = tline(ix(3)+1:ix(3)+1+keylen);
73 param = tline(ix(1)+1:35);
75 tline = tline(ix(3)+1:end);
78 fprintf(1,
'SOPEN(FAMOS) %i: process "%s %s"\n',POS,s{1},param);
80 elseif strcmp(s{1},
'CF') & (n(2)==2)
81 if ~all(n(2:3)==[1,1])
82 fprintf(HDR.FILE.stdout,'Warning SOPEN(FAMOS): unknown/unsupported(?) version\n');
85 elseif strcmp(s{1},
'CK') & (n(2)==1)
86 if ~all(n(2:3)==[3,1])
87 fprintf(HDR.FILE.stdout,
'Warning SOPEN(FAMOS): file %s was not closed, it is perhaps corrupted\n',HDR.FILE.Name);
90 elseif 0, strcmp(s{1},
'NO') & (n(2)==1)
93 elseif 0, strcmp(s{1},
'CT') & (n(2)==1)
96 elseif 0, strcmp(s{1},
'CB') & (n(2)==1)
99 elseif 0, strcmp(s{1},
'CI') & (n(2)==1)
102 elseif 0, strcmp(s{1},
'CG') & (n(2)==1)
105 elseif 0, strcmp(s{1},
'CD') & (n(2)==1)
108 elseif 0, strcmp(s{1},
'CC') & (n(2)==1)
112 elseif 0, strcmp(s{1},
'NT') & (n(2)==1)
115 elseif 0, strcmp(s{1},
'CZ') & (n(2)==1)
118 elseif 0, strcmp(s{1},
'CC') & (n(2)==1)
121 elseif strcmp(s{1},
'CP') & (n(2)==1)
125 case 1, typ=2; % uint8
126 case 2, typ=1; % int8
127 case {3,9,11}, typ=4; % uint16
128 case 4, typ=3; % int16
129 case 5, typ=6; % uint32
130 case 6, typ=5; % int32
131 case 7, typ=16; %
float
132 case 8, typ=17; %
double
133 case 10,typ=0; %
double
134 case 13,typ=511+48; %
double
136 fprintf(1,
'SOPEN(FAMOS): typ not supported (yet)\n');
139 HDR.GDFTYP(CHAN)=typ;
141 fprintf(1,
'SOPEN(FAMOS): mask %i not supported!\n',n1(5));
143 if n1(5:8)~=[0,0,1,0],
144 fprintf(1,
'SOPEN(FAMOS): mask %i.%i.%i.%i not supported (yet)\n',n1(5:8));
147 elseif strcmp(s{1},
'Cb') & (n(2)==1)
150 sz = n1(2); % bytes per sample
151 HDR.AS.start(ch) = n1(5);
152 HDR.AS.bytes(ch) = n1(6);
154 elseif 0, strcmp(s{1},
'CG') & (n(2)==1)
157 elseif strcmp(s{1},
'CD') & (n(2)==1)
159 HDR.AS.SampleRate(length(HDR.AS.SampleRate)+1) = 1/n1(1);
160 HDR.AS.PhysDimDeltaT = s1{4};
162 elseif strcmp(s{1},
'CR') & (n(2)==1)
165 HDR.PhysDim{CHAN} =
' ';
167 HDR.PhysDim{CHAN} = s1{6};
169 HDR.LeadIdCode(CHAN) = 0;
172 elseif strcmp(s{1},
'CN') & (n(2)==1)
174 HDR.Label{CHAN} = s1{5};
176 elseif strcmp(s{1},
'CS') & (n(2)==1)
177 ix1 = find(tline==','); ix1=min(ix1);
178 HDR.FAMOS.LEN = n(3)- ix1;
179 HDR.FAMOS.POS = POS + ix1;
182 for ch = 1:length(HDR.Label),
183 fseek(HDR.FILE.FID,HDR.FAMOS.POS+HDR.AS.start(ch),'bof');
184 [datatyp,limits,datatypes,numbits,GDFTYP]=
gdfdatatype(HDR.GDFTYP(ch));
185 [d,c] = fread(HDR.FILE.FID,[HDR.AS.bytes(ch)*8/numbits,1],datatyp);
190 POS = HDR.FAMOS.POS+HDR.FAMOS.LEN+1;
191 fseek(HDR.FILE.FID,POS,
'bof');
192 [tline,count] = fread(HDR.FILE.FID,[1,1024],
'*char');
196 fprintf(1,
'SOPEN(FAMOS) %i: key "%s %s" not supported (yet)\n',POS,s{1},param);