Home > wafo > misc > mkcontents.m

mkcontents

PURPOSE ^

Makes Contents file in current working directory.

SYNOPSIS ^

contstr = mkcontents(h1line,wver,srt, cfile)

DESCRIPTION ^

 MKCONTENTS Makes Contents file in current working directory. 
  
   CALL:  contstr = mkcontents(H1line,version,sort,cfile); 
  
   contstr = character array containing the H1 lines of all the files in 
             the directory. 
   H1line  = string inserted as the first line of the file specified in 
             cfile. (default: same as the old version of cfile if it 
             exists otherwise the directory name is used)  
   version = Version number (default: version number of old cfile 
             incremented by one otherwise '1.0.0') 
   sort    = 0 Do not sort by function name (default) 
             1 Sort by H1 line 
             2 Sort by function name 
             3 Sort by the inverse function name 
   cfile   = string containing the name of the file contstr  should be 
             written to.  (Default 'Contents.m')  
             If ischar(cfile)==0 then  no file is made. 
  
  It is worth noting that any editing done to a previous  
  version of CFILE will be lost. Only the H1 line from the 
  old version are copied to the new version. 
  It is assumed that the 2 first lines of the old Contents file is of the 
  form: 
  
      % Toolbox Description 
      % Version <Number>  <Release>   dd-mm-yyyy 
  
   This form ensures that VER is able to read the version info from the 
   Contents.m file. 
  
  Example 
   mkcontents('Test Toolbox',1.1,2) 
   ver test 
  
  See also  geth1line, ver

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

001 function contstr = mkcontents(h1line,wver,srt, cfile) 
002 %MKCONTENTS Makes Contents file in current working directory. 
003 % 
004 %  CALL:  contstr = mkcontents(H1line,version,sort,cfile); 
005 % 
006 %  contstr = character array containing the H1 lines of all the files in 
007 %            the directory. 
008 %  H1line  = string inserted as the first line of the file specified in 
009 %            cfile. (default: same as the old version of cfile if it 
010 %            exists otherwise the directory name is used)  
011 %  version = Version number (default: version number of old cfile 
012 %            incremented by one otherwise '1.0.0') 
013 %  sort    = 0 Do not sort by function name (default) 
014 %            1 Sort by H1 line 
015 %            2 Sort by function name 
016 %            3 Sort by the inverse function name 
017 %  cfile   = string containing the name of the file contstr  should be 
018 %            written to.  (Default 'Contents.m')  
019 %            If ischar(cfile)==0 then  no file is made. 
020 % 
021 % It is worth noting that any editing done to a previous  
022 % version of CFILE will be lost. Only the H1 line from the 
023 % old version are copied to the new version. 
024 % It is assumed that the 2 first lines of the old Contents file is of the 
025 % form: 
026 % 
027 %     % Toolbox Description 
028 %     % Version <Number>  <Release>   dd-mm-yyyy 
029 % 
030 %  This form ensures that VER is able to read the version info from the 
031 %  Contents.m file. 
032 % 
033 % Example 
034 %  mkcontents('Test Toolbox',1.1,2) 
035 %  ver test 
036 % 
037 % See also  geth1line, ver 
038  
039 % Tested on: Matlab 5.3 
040 % History: 
041 % revised pab 30.10.2003  
042 % renamed from mkcont to mkcontents   
043 % revised pab 7.12.2000 
044 %  - changed name to mkcontents 
045 %  - added H1txt, wver to input 
046 %  - more options for srt. 
047 % Revised by pab 08.10.1999 
048 %  - added sorting 
049 %  - changed call to mkcont 
050 % by jr 27.09.1999 
051  
052 if (nargin<3|isempty(srt)), 
053   srt   = 0; 
054 end 
055 if (nargin<4|isempty(cfile)), 
056   cfile = 'Contents.m';  
057 elseif ischar(cfile) 
058   cfile = [strtok(cfile,'.'),'.m' ]; 
059 end 
060  
061  
062 vinfo = []; 
063 if ischar(cfile) & exist(fullfile(pwd,cfile)) ~= 0,  
064   if isempty(vinfo), 
065     vinfo  = getverinfo(fullfile(pwd,cfile)); 
066   end 
067   disp(['There allready exist a ', cfile , ' in this directory']) 
068   disp(['Copied this file to ', cfile  'old']) 
069   %Make backup copy before overwriting cfile 
070   copyfile(cfile,[cfile 'old']); 
071   delete(cfile) 
072 end 
073 if nargin<1|isempty(h1line), 
074   if ~isempty(vinfo)&~isempty(vinfo.Name) , % Use old H1 line 
075     h1line = vinfo.Name; 
076   else 
077     [tname , dirname] = gettbname; 
078     % Create new H1 line based on directory name 
079     h1line = [ tname    ' Toolbox ' dirname];  
080   end 
081 end 
082  
083 if nargin<2|isempty(wver),  
084   if isempty(vinfo),  
085     wver = '1.0.0'; 
086   else 
087     wver = vinfo.Version; 
088   end 
089   ind  = findstr(wver,'.'); 
090   if isempty(ind), 
091     wver = [wver '.1']; 
092   else 
093     vr   = str2num(wver(ind(end)+1:end))+1; % update version 
094     wver = [wver(1:ind(end)) num2str(vr)]; 
095   end 
096 elseif isnumeric(wver) 
097   wver = num2str(wver); % make sure it is a string 
098 end 
099  
100  
101 contstr = ''; 
102 file    = what; 
103 Nff     = length(file.m); 
104 if (Nff==0), 
105   warning('No m-files found in this directory') 
106   return 
107 end 
108 if strcmpi(computer,'pcwin') 
109   file.m = lower(file.m); 
110 end 
111  
112  
113 Nf     = size(char(file.m),2)-1; % Size of filenames 
114 tmp    = cell(Nff,1); 
115 fn     = tmp; 
116 ind    = zeros(Nff,1); 
117 for ix=1:Nff     
118   disp(['Processing file: ' file.m{ix}]) 
119   tmp{ix} = geth1line(file.m{ix},1,Nf); % Extract a formatted H1 line 
120   if ~isempty(tmp{ix})&~strcmpi(file.m{ix},'contents.m') 
121     ind(ix) = 1; 
122     fn{ix}  = fliplr(file.m{ix}); 
123   end 
124 end 
125 %tmp 
126 ind = find(ind); 
127 switch srt 
128   case 1, % make a sorted character array 
129     contstr1 = sort(tmp(ind));  
130   case 2, % Sort by file name  
131     [t I] = sort(file.m(ind)); 
132     contstr1 = tmp(ind(I)); 
133   case 3, % Sort by the inverse filename 
134     [t I] = sort(fn(ind)); 
135     contstr1 = tmp(ind(I)); 
136   otherwise % No sorting  
137     contstr1 = tmp(ind);       % make character array 
138 end 
139 contstr = char(contstr1); 
140 if ~ischar(cfile),  
141   disp(h1line) 
142   disp(['Version ', wver,'   ',date]) 
143   disp(' ') 
144   disp(' ') 
145   disp(contstr), 
146   return,  
147 end 
148  
149 disp(['Creating ' cfile  ' in ' pwd]) 
150 fid = fopen(cfile,'wt'); % open a text file 
151 % Write Header lines 
152 prstr='%'; 
153 fprintf(fid,'%s \n',['% ', h1line]); 
154 fprintf(fid,'%s \n',['% Version ', wver,'   ',date]); 
155 fprintf(fid,'%s \n',prstr); 
156 fprintf(fid,'%s \n',prstr); 
157  
158 % Write contents lines 
159 if 1, 
160   fprintf(fid,['%% %s \n'],contstr1{:}); 
161 else 
162   for ix=1:size(contstr,1), 
163     fprintf(fid,['%s \n'],['% ', deblank(contstr(ix,:)) ] ); 
164   end 
165 end 
166 fclose(fid); 
167 % Change permissions on cfile  
168 % only valid for Unix systems, no effect in Win32 systems 
169 [s,msg] = dos(['chmod go+r ' cfile]); 
170  
171 return 
172  
173    
174  
175 function [tname, dirname] = gettbname; 
176      
177 wafop     = waforoot; 
178 ind       = find(wafop==filesep); 
179 wafodname =  wafop(ind(end)+1:end);  
180 pwdstr    = pwd; 
181  
182 ind = findstr(pwdstr,wafodname); 
183   
184 if isempty(ind) 
185   % name of directory is the name of the toolbox 
186   [parentDir,tname] = fileparts(pwdstr); 
187   tname           = upper(tname); 
188   dirname         = '';                    
189 else 
190   tname   = upper(wafodname); 
191   Nwf     = length(wafodname);  
192   dirname = pwdstr(ind(1)+Nwf:end) ; % name of sub directory of toolbox 
193 end 
194 return 
195  
196 function s = getverinfo(cfile) 
197 s =  struct('Name','','Version',{},'Release',{},'Date',{}); 
198  
199 fid = fopen([strtok(cfile,'.'),'.m'],'rt'); 
200 if fid==-1, 
201   disp(['Unable to open ' cfile  ]) 
202   disp('Version unknown') 
203   return 
204 end 
205  
206 h1line = deblank(fgetl(fid));       % H1 line 
207 vline  = deblank(fgetl(fid));       % version line 
208 fclose(fid); 
209  
210 [r,c] = find(h1line ~= '%' & ~isspace(h1line)); 
211 if ~isempty(c),  
212   % remove leading percent signs and trailing blanks 
213   [r,c2] = find(~isspace(h1line)); 
214   h1line = h1line(:,min(c):max(c2));  
215 end  
216 s(1).Name = h1line; 
217 %h1line = geth1line(cfile); 
218  
219 % Look for Version 
220 k = findstr('version',lower(vline)); 
221 if isempty(k), 
222   disp(['Not correct format of ' cfile ]) 
223   disp('version number unknown') 
224   return 
225 end 
226 ind          = diff(~isspace(vline)); 
227 blancstrtstp = find([0 abs(ind)] > 0.5);  
228 indbl        = blancstrtstp( blancstrtstp > k);  
229  
230 s.Version = vline(indbl(2):indbl(3)-1); 
231  
232 Nbl = length(indbl); 
233 if (Nbl>=3), 
234   s.Date = vline(indbl(Nbl):end); 
235 end 
236  
237 if (Nbl-1>=3), 
238   s.Release = vline(indbl(Nbl-1):indbl(Nbl)-1); 
239 end 
240  
241 return 
242  
243

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group


Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003