1function [POS,HDR] = stell(HDR)
2% STELL returns file position of signal data files
3% HDR = stell(HDR)
4% returns the location of the HDR-signal file position indicator in the specified file.
5% Position is indicated in Blocks from the beginning of the file.  If -1 is returned,
6% it indicates that the query was unsuccessful;
7% HDR-struct is a struct obtained by SOPEN.
8%
9% HDR.FILE.POS contains the position of the HDR-Identifier in Blocks
10%
11% See also: SOPEN, SREAD, SWRITE, SCLOSE, SSEEK, SREWIND, STELL, SEOF
12
13
14%	$Id$
15%	(C) 1997-2005,2007 by Alois Schloegl <alois.schloegl@gmail.com>
16%    	This is part of the BIOSIG-toolbox http://biosig.sf.net/
17
18
19POS = ftell(HDR.FILE.FID);
20if POS<0,
21        [HDR.ERROR,HDR.ErrNo] = ferror(HDR.FILE.FID);
22        return;
23end;
24POS = (POS-HDR.HeadLen)/HDR.AS.bpb;
25if (POS<0) || (POS>HDR.NRec*HDR.SPR)
26        fprintf(2,'Warning STELL: %s File - invalid file position %i  %i\n', HDR.FileName, POS, HDR.FILE.POS);
27elseif ~isfield(HDR.FILE,'POS')
28    	fprintf(2,'Error STELL: format %s not supported',HDR.TYPE);
29elseif HDR.FILE.POS~=POS,
30        fprintf(2,'Warning STELL: %s File position error  %i  %i\n', HDR.FileName, POS, HDR.FILE.POS);
31else
32	HDR.FILE.POS=POS;
33end;
34
35return;
36
37% the code below is obsolete
38
39if strmatch(HDR.TYPE,{'CTF'}),
40	POS = (POS-HDR.HeadLen)/HDR.AS.bpb;
41	HDR.ERROR = [];
42	HDR.ErrNo = 0;
43
44	if (HDR.AS.startrec+HDR.AS.numrec)~=POS,
45        	fprintf(2,'Warning STELL: File postion error in EDF/GDF/BDF-toolbox.\n')
46                HDR.AS.startrec = POS;
47        end;
48
49elseif strmatch(HDR.TYPE,{'AINF','BKR','ISHNE','CNT','EEG','AVG','MIT','RG64','LABVIEW','Nicolet','EGI','SMA','SND','WAV','AIF','CFWB','DEMG','alpha','BCI2000','ET-MEG','Sigma'}),
50	POS = (POS-HDR.HeadLen)/HDR.AS.bpb;
51
52elseif strmatch(HDR.TYPE,{'ACQ','AINF','EDF','BDF','EPL','GDF','RDF','SIGIF','BrainVision','EEProbe-CNT','EEProbe-AVR','FIF','native','MFER','TMS32','WG1'}),
53	POS = HDR.FILE.POS;
54
55else
56    	fprintf(2,'Error STELL: format %s not supported',HDR.TYPE);
57end;
58
59if HDR.FILE.POS~=POS,
60        fprintf(2,'Warning STELL: %s File position error  %i  %i\n', HDR.FileName, POS, HDR.FILE.POS);
61end;
62HDR.FILE.POS=POS;
63