1 function [HDR]=
sseek(HDR,offset,origin)
2 % SSEEK repositions file position indicator
3 % HDR =
sseek(HDR,offset,origin)
5 % offset number of samples relative to origin
7 % -1,
'bof': begin of file
8 % 0,
'cof': current file position
9 % +1,
'eof': end of file
11 % See also: SOPEN, SREAD, SWRITE, SCLOSE, SSEEK, SREWIND, STELL, SEOF
13 % $Id:
sseek.m 2205 2009-10-27 12:18:15Z schloegl $
14 % (C) 1997-2005,2006,2007 by Alois Schloegl <a.schloegl@ieee.org>
15 % This is part of the BIOSIG-toolbox http:
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 2
20 % of the License, or (at your option) any later version.
22 % This program is distributed in the hope that it will be useful,
23 % but WITHOUT ANY WARRANTY; without even the implied warranty of
24 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 % GNU General Public License
for more details.
27 % You should have received a copy of the GNU General Public License
28 % along with
this program;
if not, write to the Free Software
29 % Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 if strcmp(origin,
'bof')
34 elseif strcmp(origin,'cof')
36 elseif strcmp(origin,'eof')
41 HDR.FILE.POS = offset;
42 if strmatch(HDR.TYPE,{
'ACQ',
'BDF',
'EDF',
'GDF',
'EPL',
'MFER',
'SCP',
'native',
'TMS32',
'WG1'}),
43 elseif HDR.FILE.FID>2,
44 POS = HDR.HeadLen+HDR.AS.bpb*offset;
45 if POS~=ceil(POS), %
for alpha format
46 fprintf(HDR.FILE.stderr,
'Error STELL (alpha): starting position is non-integer\n');
49 HDR.FILE.status = fseek(HDR.FILE.FID,POS,-1);
53 HDR.FILE.POS = HDR.FILE.POS + offset;
54 if strmatch(HDR.TYPE,{
'ACQ',
'BDF',
'EDF',
'GDF',
'EPL',
'MFER',
'SCP',
'native',
'TMS32',
'WG1'}),
55 elseif HDR.FILE.FID>2,
56 POS = HDR.AS.bpb*offset;
57 if POS~=ceil(POS), %
for alpha format
58 fprintf(HDR.FILE.stderr,
'Error STELL (alpha): starting position is non-integer\n');
61 HDR.FILE.status = fseek(HDR.FILE.FID,POS,0);
65 if 0, %strmatch(HDR.TYPE,{}),
66 HDR.FILE.POS = HDR.NRec+offset;
67 HDR.FILE.status = fseek(HDR.FILE.FID,HDR.AS.bpb*offset,1);
68 elseif strmatch(HDR.TYPE,{
'ACQ',
'BDF',
'EDF',
'GDF',
'EPL',
'Sigma'}),
69 HDR.FILE.POS = HDR.NRec*HDR.SPR+offset;
72 elseif HDR.FILE.POS > HDR.NRec*HDR.SPR,
73 HDR.FILE.POS = HDR.NRec*HDR.SPR;
75 HDR.FILE.status = fseek(HDR.FILE.FID,HDR.HeadLen+HDR.FILE.POS*HDR.AS.bpb,-1);
76 elseif strmatch(HDR.TYPE,{
'CTF',
'Nicolet'}),
77 POS = HDR.AS.endpos+offset*HDR.AS.bpb;
78 HDR.FILE.status = fseek(HDR.FILE.FID,POS,-1);
79 HDR.FILE.POS = (POS-HDR.HeadLen)/HDR.AS.bpb;
80 elseif strmatch(HDR.TYPE,{
'AINF',
'BKR',
'ET-MEG',
'ISHNE',
'RG64',
'MIT',
'LABVIEW',
'SMA',
'BVbinmul',
'BCI2000'}),
81 HDR.FILE.POS = HDR.AS.endpos+offset;
82 HDR.FILE.status = fseek(HDR.FILE.FID,HDR.AS.bpb*offset,1);
83 elseif strmatch(HDR.TYPE,{
'CNT',
'EEG',
'AVG',
'EGI',
'SND',
'WAV',
'AIF',
'CFWB',
'DEMG'}),
84 HDR.FILE.POS = HDR.AS.endpos+offset;
85 HDR.FILE.status = fseek(HDR.FILE.FID,HDR.HeadLen+(HDR.AS.endpos+offset)*HDR.AS.bpb,-1);
86 elseif strmatch(HDR.TYPE,{
'alpha'}),
87 POS = HDR.HeadLen+(HDR.AS.endpos+offset)*HDR.AS.bpb;
88 if POS~=ceil(POS), %
for alpha format
89 fprintf(HDR.FILE.stderr,
'Error STELL (alpha): starting position is non-integer\n');
92 HDR.FILE.POS = HDR.AS.endpos+offset;
93 HDR.FILE.status = fseek(HDR.FILE.FID,POS,-1);
94 elseif strmatch(HDR.TYPE,{
'RDF',
'SIGIF'}),
95 HDR.FILE.POS = length(HDR.Block.Pos)+offset;
96 elseif strmatch(HDR.TYPE,{
'BVascii',
'BVbinvec',
'EEProbe-CNT',
'EEProbe-AVR',
'FIF',
'native',
'MFER',
'SCP',
'TMS32',
'WG1'}),
97 HDR.FILE.POS = HDR.AS.endpos+offset;
99 fprintf(HDR.FILE.stderr,
'Warning SSEEK: format %s not supported.\n',HDR.TYPE);
102 fprintf(2,
'error SSEEK: 3rd argument "%s" invalid\n',origin);