-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlistfileread.m
64 lines (52 loc) · 1.57 KB
/
listfileread.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function [L,N] = listfileread(F)
% [L,N] = listfileread(F) Read a list of per-line items
% F is a file containing a list of items, one per line.
% Return L as a cell array, with one item per line, N as the
% number of items.
% If F is not found, return empty L and N == -1 (instead of 0).
% 2006-08-06 dpwe@ee.columbia.edu for MIREX 06
% 2008-08-11 Dan Ellis dpwe@ee.columbia.edu updated with "@include" syntax
% 2011-08-02 Modified to skip blank lines and lines starting with '#'
% disp(['listfileread: ',F]);
N = -1;
L = [];
inckey = '@include';
commentchar = '#'; % hash in first column means line is ignored
if fexist(F) == 1
fid = fopen(F);
nitems = 0;
while 1
tline = fgetl(fid);
if ~ischar(tline), break, end
if strncmp(tline, inckey, length(inckey))
% Special syntax to embed another list
pdir = fileparts(F);
% read in the specified file
subfname = tline((length(inckey)+2):end);
sdir = fileparts(subfname);
if length(sdir) == 0 | sdir(1) == '.'
subfname = fullfile(pdir,subfname);
end
[LL,NN] = listfileread(subfname);
for i = 1:NN
nitems = nitems+1;
L{nitems} = LL{i};
end
else
if length(tline) > 0
if tline(1) ~= commentchar
nitems = nitems+1;
L{nitems} = tline;
end
end
end
end
fclose(fid);
N = nitems;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function E = fexist(F)
% E = fexist(F) returns 1 if file F exists, else 0
% 2006-08-06 dpwe@ee.columbia.edu
x = dir(F);
E = length(x);