NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/util/MakeContents.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 function MakeContents(aString)
2
3 %MAKECONTENTS  makes Contents file in current working directory.
4 %   MAKECONTENTS(STRING) creates a standard "Contents.m" file in the
5 %   current directory by assembling the first comment (H1) line in
6 %   each function found in the current working directory.  If a
7 %   "Contents.m" file exists, it is renamed to "Contents.old", before
8 %   a new "Contents.m" file is created.  STRING is inserted as the
9 %   first line of the "Contents.m" file;  if omitted, a blank line
10 %   is inserted instead.  The function changes permission on the
11 %   resultant "Contents.m" file to rw-r--r-- on Unix systems.
12 %
13 % Updated 29 June 2000.
14 %
15 % See also CONTENTS.
16
17
18 % Author(s): L. Bertuccioli
19 %            A. Prasad
20
21 % Based on mkcontents.m by Denis Gilbert
22
23
24 % Default value of input string
25 if nargin < 1,
26      aString =' ';
27 end
28
29 disp(['Creating "Contents.m" in ' pwd])
30 if exist([pwd filesep 'Contents.m']) ~= 0
31      copyfile('Contents.m','Contents.old');
32      delete Contents.m 
33 end
34
35 % Header lines
36 line1 = ['% ' aString];
37 line2 = ['% Path ->  ' pwd];
38
39 % Structure with fields files.m, files.mat, etc.
40 files = what; 
41 % Note: the field files.m does not include contents.m (IMPORTANT)
42 % Do not displace this line of code above or below its present location
43 % to avoid error messages.
44
45 if length(files.m)==0
46      warning('No m-files found in this directory')
47      return
48 end
49
50 fcontents = fopen('Contents.m','w');
51 fprintf(fcontents,'%s\n',line1);     
52 fprintf(fcontents,'%s\n',line2);     
53 fprintf(fcontents,'%% \n');
54
55 % Write first lines to Contents.m if they exist
56 for i = 1:length(files.m)
57    fid=fopen(files.m{i},'r');
58    aLine = fgetl(fid);
59    if (strcmp(aLine(1:8),'function') == 1),
60         count_percent = 0;
61         while count_percent < 1 & feof(fid)==0;
62              line = fgetl(fid);
63              if length(line) > 0
64                   if ~isempty(findstr(line,'%'))
65                        count_percent = count_percent + 1;
66                        [tt,rr]=strtok(line(2:length(line)));
67                        rr = fliplr(deblank(fliplr(rr)));
68                        fn = strtok(char(files.m(i)),'.');
69                        n = size(char(files.m),2) - length(fn) - 1;
70                        line = ['%   ' fn blanks(n) '- ' rr];
71                        fprintf(fcontents,'%s\n',line);
72                   end % if ~isempty
73              end % if length
74              if feof(fid)==1 
75                   fn = strtok(char(files.m(i)),'.');
76                   n = size(char(files.m),2) - length(fn) - 1;
77                   line = ['%   ' fn blanks(n) '- (No help available)'];
78                   fprintf(fcontents,'%s\n',line);
79              end % if feof
80         end % while
81    end % if strcmp
82    fclose(fid);
83 end
84
85 fclose(fcontents);
86
87 % Change permissions on Contents.m file
88 % only valid for Unix systems, no effect in Win32 systems
89 !chmod go+r Contents.m
Note: See TracBrowser for help on using the browser.