-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNIMSreadHeader.m
More file actions
58 lines (48 loc) · 1.28 KB
/
NIMSreadHeader.m
File metadata and controls
58 lines (48 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function [Header,nHeader,HZ] = NIMSreadHeader(fname,index)
% [Header,nHeader,HZ] = NIMSreadHeader(fname,index)
%
% Reads the header from a raw NIMS binary file
% and outputs the length of the header and the header.
% Uses the optional array 'index' of possible block lengths
% that might follow the 01 byte at the end of the header.
% Currently these are 25 for 1 Hz data, 131 for 8 Hz.
% Outputs HZ=1 or HZ=8, respectively.
if nargin < 2
index = 1:1:255;
end
fid = fopen(fname,'r');
nHeader = 0;
Header = zeros(1,1000);
fseek(fid,nHeader,'bof')
Header(1) = fread(fid,1,'uchar');
Header(2) = fread(fid,1,'uchar');
i = 2;
while ~ (Header(i-1)==1 && max(index==Header(i)))
i = i + 1;
[temp,count] = fread(fid,1,'uchar');
if count == 0
i=i-1
break
end
Header(i) = temp;
end
nBlk = Header(i);
if isstrprop(char(Header(i-1)),'alphanum')
% usually true for hdr.fix
nHeader = i-1;
else
% usually true for reading from DATA.BIN
nHeader = i-2;
end
Header = Header(1:nHeader);
fclose(fid)
switch nBlk
case 8*16+3 % 8 hz (83h)
HZ = 8;
case 1*16+9 % 1 hz (19h)
HZ = 1;
otherwise
fprintf(1,'Error: unknown length of block %d',nBlk);
fprintf(1,'Error: assume 1 HZ data by default');
HZ = 1;
end