1function [HDR]=openxlt(fn)
2% OPENXLT is an auxillary function to SOPEN for
3% opening of XLTEK files
4%
5% Use SOPEN instead of OPENXLT
6%
7% See also: fopen, SOPEN,
8%
9% References:
10
11% This program is free software; you can redistribute it and/or
12% modify it under the terms of the GNU General Public License
13% as published by the Free Software Foundation; either version 3
14% of the License, or (at your option) any later version.
15
16% Copyright (C) 2004,2008,2020 by Alois Schloegl <alois.schloegl@gmail.com>
17%       Thanks to Andrey Vankov for his support.
18%    This is part of the BIOSIG-toolbox https://biosig.sourceforge.io/
19
20fprintf(2,'Warning: OPENXLT is in an experimental state and is most likely not useful to you.\n');
21fprintf(2,'\t Do not use it unless you are sure know what you do. At least you are warned!\n');
22
23if ischar(fn)
24        HDR.FileName = fn;
25        [pfad,file,FileExt] = fileparts(HDR.FileName);
26        HDR.FILE.Name = file;
27        HDR.FILE.Path = pfad;
28        HDR.FILE.Ext  = char(FileExt(2:length(FileExt)));
29end;
30
31% read etc file
32fid = fopen(fullfile(HDR.FILE.Path,[HDR.FILE.Name,'.etc']),'r');
33if fid<0,
34        fid = fopen(fullfile(HDR.FILE.Path,[HDR.FILE.Name,'.ETC']),'r');
35end
36if fid>0,
37        status = fseek(fid,hex2dec(164),'bof');
38        HDR.XLT.timebase = fread(fid,1,'int32');
39        fclose(fid);
40end;
41
42% read ent file
43fid = fopen(fullfile(HDR.FILE.Path,[HDR.FILE.Name,'.ent']),'r');
44if fid<0,
45        fid = fopen(fullfile(HDR.FILE.Path,[HDR.FILE.Name,'.ENT']),'r');
46end
47if fid>0,
48        while ~feof(fid)
49                tline = fgetl(fid);
50                if strncmp(tline,'Stamp',5),
51                        [t,r] = strtok(tline,' ');
52                        [t,r] = strtok(r,' ');
53                        [HDR.XLT.timebase2,c] = biosig_str2double(t);
54                        ix = strfind(tline,'patient');
55                else
56
57                end
58        end;
59        fclose(fid);
60end;
61
62
63% read erd file
64fid = fopen(HDR.FileName);
65if fid>0,
66        HDR.H1 = fread(fid,352,'uchar');
67        HDR.SampleRate = fread(fid,1,'uchar');
68        tmp = fread(fid,2,'int32');
69        HDR.NS = tmp(1);
70        HDR.bits = tmp(2); % ???? ###
71        HDR.XLT.PhysChan = fread(fid,1024,'int32');
72        HDR.XLT.HeadBoxType = fread(fid,4,'int32');
73        HDR.XLT.HeadBoxSN = fread(fid,4,'int32');
74        HDR.XLT.HeadBoxSoftwareVersion = fread(fid,[4,16],'uint8');
75        HDR.XLT.DSP_HW_Version = fread(fid,[16],'uint8');
76        HDR.XLT.DSP_SW_Version = fread(fid,[16],'uint8');
77        HDR.XLT.DiscardBits = fread(fid,4,'int32');
78
79        HDR.XLT.shorted = fread(fid,1024,'int16');
80        HDR.XLT.FrequencyFactor = fread(fid,1024,'int16');
81
82        HDR.HeadLen = hex2dec('21D0');
83        status = fseek(fid,HDR.HeadLen,'bof');
84
85
86
87
88        fclose(fid);
89
90end;
91
92