-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNPX_ReadMeta.m
48 lines (43 loc) · 1.66 KB
/
NPX_ReadMeta.m
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
% =========================================================
% Parse ini file returning a structure whose field names
% are the metadata left-hand-side tags, and whose right-
% hand-side values are MATLAB strings. We remove any
% leading '~' characters from tags because MATLAB uses
% '~' as an operator.
%
% If you're unfamiliar with structures, the benefit
% is that after calling this function you can refer
% to metafile items by name. For example:
%
% meta.fileCreateTime // file create date and time
% meta.nSavedChans // channels per timepoint
%
% All of the values are MATLAB strings, but you can
% obtain a numeric value using str2double(meta.nSavedChans).
% More complicated parsing of values is demonstrated in the
% utility functions below.
%
function [meta] = NPX_ReadMeta(binName, path)
% Create the matching metafile name
[dumPath,name,dumExt] = fileparts(binName);
metaName = strcat(name, '.meta');
% Parse ini file into cell entries C{1}{i} = C{2}{i}
fid = fopen(fullfile(path, metaName), 'r');
% -------------------------------------------------------------
% Need 'BufSize' adjustment for MATLAB earlier than 2014
% C = textscan(fid, '%[^=] = %[^\r\n]', 'BufSize', 32768);
C = textscan(fid, '%[^=] = %[^\r\n]');
% -------------------------------------------------------------
fclose(fid);
% New empty struct
meta = struct();
% Convert each cell entry into a struct entry
for i = 1:length(C{1})
tag = C{1}{i};
if tag(1) == '~'
% remake tag excluding first character
tag = sprintf('%s', tag(2:end));
end
meta = setfield(meta, tag, C{2}{i});
end
end % ReadMeta