source: distools/create_short.m @ 100

Last change on this file since 100 was 10, checked in by bduin, 14 years ago
File size: 1.5 KB
RevLine 
[10]1%CREATE_SHORT
2%
3%  Create short Contents.m in distools directory
4
5function create_short
6
7disdir = which('distools_long.m');
8disdir = fileparts(disdir);
9r = readf(fullfile(disdir,'distools_long.m'));
10k = grep(r,'%%');
11s = listn(r,k);
12s = strrep(s,'%%','% ');
13writf(fullfile(disdir,'Contents.m'),s);
14
15return
16
17%WRITF Write file
18%
19% writf(file,r)
20% Write file from string r
21
22function writf(file,r)
23fid = fopen(file,'w');
24if fid < 0
25   error('Cannot open file')
26end
27fprintf(fid,'%c',r);
28fclose(fid);
29return
30
31%READF Readfile
32%
33% [r,n] = readf(file,newline)
34% Reads file into string r. The number of lines
35% is returned in n.
36
37function [r,n] = readf(file,newline)
38if nargin < 2, newline = 13; end
39fid = fopen(deblank(file),'r');
40if fid < 0
41   error(['Cann''t open ' file])
42end
43r = fscanf(fid,'%c');
44fclose(fid);
45n = length(find(r==newline));
46if r(length(r)) ~= newline, n = n + 1; end
47return
48
49%LISTN List lines specified by their line number
50%
51% t = listn(r,n)
52% Get the lines in r given by the line numbers in n.
53function t = listn(r,n)
54k = [0,find(r==newline)];
55t = [];
56for j = n
57    t = [t,r(k(j)+1:k(j+1))];
58end
59return
60
61%GREP Get line specific lines
62%
63% [k,n] = grep(r,s)
64% Get the numbers of all lines in the set of lines r
65% that contain s.
66% n is the total number of lines.
67
68function [k,z] = grep(r,s)
69n = [0,find(r==newline)];
70m = findstr(r,s);
71[i,j] = sort([n,m]);
72q = [0,j(1:length(j)-1)]-j;
73k = j(find(q>0))-1;
74z = length(n)-1; % # of lines
75return
Note: See TracBrowser for help on using the repository browser.