2 % FEFOPEN opens and reads FEF file
10 % [1] <A HREF=
"ftp://sigftp.cs.tut.fi/pub/eeg-data/standards/cenf060.zip ">About CEN/TC251</A>
14 % $Id:
tlvread.m 2205 2009-10-27 12:18:15Z schloegl $
15 % Copyright (C) 2004 Alois Schloegl <a.schloegl@ieee.org>
16 % This is part of the BIOSIG-toolbox http:
18 % This library is free software; you can redistribute it and/or
19 % modify it under the terms of the GNU Library General Public
20 % License as published by the Free Software Foundation; either
21 % Version 2 of the License, or (at your option) any later version.
23 % This library is distributed in the hope that it will be useful,
24 % but WITHOUT ANY WARRANTY; without even the implied warranty of
25 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 % Library General Public License
for more details.
28 % You should have received a copy of the GNU Library General Public
29 % License along with
this library;
if not, write to the
30 % Free Software Foundation, Inc., 59 Temple Place - Suite 330,
31 % Boston, MA 02111-1307, USA.
33 if feof(fid), TLV =[];
return; end;
35 tag=fread(fid,1,
'uint8');
36 if bitand(tag,31)==31,
37 t = fread(fid,1,
'uint8');
40 t = fread(fid,1,
'uint8');
41 ac = [ac*128 + bitand(t,127)];
48 LEN = fread(fid,1,
'uint8');
50 len = bitand(LEN,127);
56 len = fread(fid,len,
'uint8');
57 LEN = sum(len.*256.^[length(len)-1:-1:0]
');
62 class = bitand(tag,192)/64; % get class
63 FLAG.Primitive = ~bitand(tag,32); % check P/C bit
66 if (tag == 0) & (LEN==0)
73 TLV.PC = FLAG.Primitive;
78 if class == 0, % Universal
79 classtag = bitand(tag,31);
81 TLV.reservedBER = fread(fid,LEN,'uchar
');
83 TLV.Boolean = fread(fid,LEN,'uchar
');
85 TLV.Integer = fread(fid,LEN,'int8
');
87 TLV.Bitstring = fread(fid,LEN,'uchar
');
89 TLV.OctetString = dec2hex(fread(fid,LEN,'uchar
'));
91 TLV.Null = fread(fid,LEN,'uchar
');
93 TLV.OID = fread(fid,LEN,'uchar
');
95 TLV.ObjectDesc = fread(fid,LEN,'uchar
');
97 TLV.external = fread(fid,LEN,'uchar
');
99 TLV.real = fread(fid,LEN,'uchar
');
101 TLV.enum = fread(fid,LEN,'uchar
');
103 TLV.UTF8String = fread(fid,LEN,'uchar
');
105 TLV.relativeOID = fread(fid,LEN,'uchar
');
107 TLV.OID = fread(fid,LEN,'uchar
');
110 TLV.reserved14 = fread(fid,LEN,'uchar
');
112 TLV.reserved15 = fread(fid,LEN,'uchar
');
114 TLV.sequenceof = fread(fid,LEN,'uchar
');
116 TLV.setof = fread(fid,LEN,'uchar
');
118 TLV.numericString = fread(fid,LEN,'uchar
');
120 TLV.PrintableString = fread(fid,LEN,'uchar
');
122 TLV.TeletexStringT61 = fread(fid,LEN,'uchar
');
124 TLV.VALUE = fread(fid,LEN,'uchar
');
126 TLV.IA5String = fread(fid,LEN,'uchar
');
128 TLV.UTCtime = fread(fid,LEN,'uchar
');
130 TLV.generalizedTime = fread(fid,LEN,'uchar
');
132 TLV.GraphicString = fread(fid,LEN,'uchar
');
134 TLV.VisibleStringISO646String = fread(fid,LEN,'uchar
');
136 TLV.GeneralString = fread(fid,LEN,'uchar
');
138 TLV.UniversalString = fread(fid,LEN,'uchar
');
140 TLV.CharacterString = fread(fid,LEN,'uchar
');
142 TLV.BMPString = fread(fid,LEN,'uchar
');
144 TLV.VALUE = fread(fid,LEN,'uchar
');
146 TLV.VALUE = fread(fid,LEN,'uchar
');
149 elseif class == 1, % Application
150 %TLV.VALUE = fread(fid,LEN,'uchar
');
151 [TLV.VALUE] = tlvread(fid);
153 elseif class == 2, % Context-Specific
154 TLV.VALUE = fread(fid,LEN,'uchar
');
156 elseif class == 3, % Private
157 TLV.VALUE = fread(fid,LEN,'uchar
');
161 warning('unspecified length %i
',ftell(fid));
163 tmp = fread(fid,256,'uint8
');
165 while ~any((tmp==0) & ([accu;tmp(1:end-1)]==0)) & ~feof(fid)
166 TLV.VALUE = [TLV.VALUE,tmp'];
168 tmp = fread(fid,256,
'uint8');
170 x = find((tmp==0) & ([accu;tmp(1:end-1)]==0));
171 TLV.VALUE = [TLV.VALUE, tmp(end-min(x))
'];
172 status = fseek(fid,min(x)-length(tmp),0);