1 | %PRTOOLS_EXPORT creates and stores PRTools export
|
---|
2 | %
|
---|
3 | % PRTOOLS_EXPORT(FLAG,EXPORTDIR)
|
---|
4 | %
|
---|
5 | % Creates, if FLAG is true an export version of PRTools in
|
---|
6 | % http://prtools.tudelft.org/files/prtools.zip.
|
---|
7 | %
|
---|
8 | % If FLAG is false (default) just zip-files in EXPORTDIR are created for
|
---|
9 | % inspection and the website is not attached.
|
---|
10 | %
|
---|
11 | % EXPORTDIR should be the Matlab/prtools_export dir in the PRLab group
|
---|
12 | % directory. Default is K:\insy\PRLab\Matlab\prtools_export
|
---|
13 | %
|
---|
14 | % The intention is that this routine works on the PC as well as on the Unix
|
---|
15 | % platform. The latter, however, has not yet been tested.
|
---|
16 | %
|
---|
17 | % Save trials are prtools_export, prtools_export(0), prtools_export(0,dir)
|
---|
18 | % and inspect the prtools_export directory.
|
---|
19 | %
|
---|
20 | % This m-file should be located in PREXTRA, which should be in the path,
|
---|
21 | % as it needs the overruled FTP commands located in PREXTRA
|
---|
22 | %
|
---|
23 | % Bob Duin 31 Aug 2016
|
---|
24 |
|
---|
25 | function prtools_export(doit,exportdir)
|
---|
26 |
|
---|
27 | if nargin < 2, exportdir = 'K:\insy\PRLab\Matlab\prtools_export'; end
|
---|
28 | if nargin < 1, doit = false; end
|
---|
29 |
|
---|
30 | prdir = fileparts(which(mfilename));
|
---|
31 | %exportdir = fullfile(prdir,'prtools_export'); % maybe to be located elsewwhere
|
---|
32 | curdir = pwd;
|
---|
33 | [~,prdirdir] = fileparts(prdir);
|
---|
34 | if ~strcmp(prdirdir,'prextra')
|
---|
35 | error('prtools_export should be located in the prextra directory')
|
---|
36 | end
|
---|
37 |
|
---|
38 | % create temp dir
|
---|
39 | prtmp = fullfile(prdir,'tmp');
|
---|
40 | if exist(prtmp,'dir') ~= 7
|
---|
41 | mkdir(prtmp);
|
---|
42 | end
|
---|
43 |
|
---|
44 | % get rid of prtools in the path
|
---|
45 | r = which('fisherc');
|
---|
46 | if ~isempty(r)
|
---|
47 | rmpath(r);
|
---|
48 | end
|
---|
49 |
|
---|
50 | cd(prtmp);
|
---|
51 | dd = dir;
|
---|
52 | n=strmatch('prtools',{dd.name},'exact');
|
---|
53 | if ~isempty(n)
|
---|
54 | rmdir('prtools','s');
|
---|
55 | end
|
---|
56 |
|
---|
57 | % checkout present PRTools version
|
---|
58 | if isunix
|
---|
59 | s = unix('svn co https://svn-mede.ewi.tudelft.nl/MM-ICT/PRTOOLS prtools');
|
---|
60 | elseif ispc
|
---|
61 | fprintf(1,' Tortoise will pop up, find it and click OK 2x');
|
---|
62 | s = dos('TortoiseProc.exe /command:checkout /url:"https://svn-mede.ewi.tudelft.nl/MM-ICT/PRTOOLS" /path:prtools');
|
---|
63 | fprintf(1,'\n');
|
---|
64 | input(' Ready to continue?');
|
---|
65 | else
|
---|
66 | error('svn checkout not implemented for Mac')
|
---|
67 | end
|
---|
68 | if (s~=0)
|
---|
69 | error('Error in running svn: could not checkout prtools')
|
---|
70 | end
|
---|
71 |
|
---|
72 | % adjust version number
|
---|
73 | addpath(fullfile(pwd,'prtools'))
|
---|
74 | pver = prtver;
|
---|
75 | fprintf(1,' Present PRTools version is %s\n',pver{1}.Version);
|
---|
76 | pver_new = input([' Give new version number: [' pver{1}.Version '] '],'s');
|
---|
77 | if isempty(pver_new)
|
---|
78 | pver_new = pver{1}.Version;
|
---|
79 | end
|
---|
80 | set_version_in_Contents(pver_new);
|
---|
81 | % Commit version change
|
---|
82 | if isunix
|
---|
83 | s = unix(['svn ci ' fullfile('prtools','Contents.m')]);
|
---|
84 | elseif ispc
|
---|
85 | fprintf(1,' Tortoise will pop up to commit change version number in Contents, find it and click OK 2x')
|
---|
86 | s = dos(['TortoiseProc.exe /command:commit /path:' fullfile('prtools','Contents.m')]);
|
---|
87 | fprintf(1,'\n');
|
---|
88 | input(' Ready to continue?');
|
---|
89 | else
|
---|
90 | error(['svn commit not implemented for Mac'])
|
---|
91 | end
|
---|
92 |
|
---|
93 | % Delete all svn files
|
---|
94 | fprintf(1,' Removing all svn files ... \n');
|
---|
95 | if isunix
|
---|
96 | unix('chmod -R +w prtools');
|
---|
97 | unix('\rm -rf prtools/.svn prtools/*/.svn');
|
---|
98 | elseif ispc
|
---|
99 | dos('rmdir /S /Q prtools\.svn');
|
---|
100 | dos('rmdir /S /Q prtools\@prdataset\.svn');
|
---|
101 | dos('rmdir /S /Q prtools\@prdatafile\.svn');
|
---|
102 | dos('rmdir /S /Q prtools\@prmapping\.svn');
|
---|
103 | dos('rmdir /S /Q prtools\private\.svn');
|
---|
104 | end
|
---|
105 |
|
---|
106 | % Create export version in dir2
|
---|
107 | today = datestr(date,'ddmmmyy');
|
---|
108 | exporttemp = fullfile(prtmp,['prtex' pver_new '.' today]);
|
---|
109 | mkdir(exporttemp);
|
---|
110 | dir1 = fileparts(which('fisherc'));
|
---|
111 | dir2 = fullfile(exporttemp,'prtools');
|
---|
112 | mkdir(dir2);
|
---|
113 | copydirm(dir1,dir2); % copy main dir
|
---|
114 | copydirm(fullfile(dir1,'private'),fullfile(dir2,'private'),'all'); % copy private as it is
|
---|
115 | copydirm(fullfile(dir1,'@prdataset'),fullfile(dir2,'@prdataset'),'%'); % copy headers only
|
---|
116 | copydirm(fullfile(dir1,'@prdatafile'),fullfile(dir2,'@prdatafile'),'%'); % copy headers only
|
---|
117 | copydirm(fullfile(dir1,'@prmapping'),fullfile(dir2,'@prmapping'),'%'); % copy headers only
|
---|
118 |
|
---|
119 | % Generate pcodes
|
---|
120 | fprintf(1,' Generating pcodes ... \n');
|
---|
121 | cd(fullfile(dir2,'@prdataset')); pcode(fullfile(dir1,'@prdataset')); % generate pcode in dir2/@dataset
|
---|
122 | cd(fullfile(dir2,'@prdatafile')); pcode(fullfile(dir1,'@prdatafile')); % generate pcode in dir2/@datafile
|
---|
123 | cd(fullfile(dir2,'@prmapping')); pcode(fullfile(dir1,'@prmapping')); % generate pcode in dir2/@mapping
|
---|
124 |
|
---|
125 | % Create zip-files
|
---|
126 | fprintf(1,' Creating zip files ... \n');
|
---|
127 | cd(exportdir);
|
---|
128 | copyfile('License.txt',exporttemp,'f');
|
---|
129 | copyfile('Install_notes.txt',exporttemp,'f');
|
---|
130 | copyfile('Release_notes.txt',exporttemp,'f');
|
---|
131 | pfiles = ['prtex' pver_new '.' today '.zip'];
|
---|
132 | mfiles = ['prtools' pver_new '.' today '.zip'];
|
---|
133 | zip(pfiles,{'prtools','License.txt','Install_notes.txt','Release_notes.txt'},exporttemp);
|
---|
134 | zip(mfiles,[fullfile(prtmp,'prtools') '/*']);
|
---|
135 | rmdir(prtmp,'s');
|
---|
136 |
|
---|
137 | if doit
|
---|
138 | fprintf(1,' FTP PRTools zip-file to website ... \n');
|
---|
139 | % store p-files on website
|
---|
140 | ftpsite = ftp('prtools.tudelft.nl','prtools','pvG4z1!1');
|
---|
141 | cd(ftpsite,'httpdocs/files');
|
---|
142 | mput(ftpsite,pfiles);
|
---|
143 | rename(ftpsite,pfiles,'prtools.zip');
|
---|
144 | disp('p-files have been stored on the website.')
|
---|
145 | disp('Please check and adjust release notes and known problems on website')
|
---|
146 | close(ftpsite)
|
---|
147 |
|
---|
148 | % backup p-files and m-files
|
---|
149 | fprintf(1,' Storing backups of mfiles and p-files ... \n');
|
---|
150 | [s,mess] = copyfile(pfiles,fullfile(exportdir,'prtools_old_p'));
|
---|
151 | if s
|
---|
152 | delete(pfiles);
|
---|
153 | disp(['p-files have been backed-up in ' exportdir])
|
---|
154 | else
|
---|
155 | disp(mess);
|
---|
156 | end
|
---|
157 | [s,mess] = copyfile(mfiles,fullfile(exportdir,'prtools_old_m'));
|
---|
158 | if s
|
---|
159 | delete(mfiles);
|
---|
160 | disp(['m-files have been backed-up in ' exportdir])
|
---|
161 | else
|
---|
162 | disp(mess);
|
---|
163 | end
|
---|
164 | end
|
---|
165 |
|
---|
166 | cd(curdir)
|
---|
167 |
|
---|
168 |
|
---|
169 | %COPYDIRM Copy mfiles from dir to dir
|
---|
170 | function copydirm(dir1,dir2,type)
|
---|
171 | if nargin < 3
|
---|
172 | type = 'm';
|
---|
173 | end
|
---|
174 | if exist(dir2) ~= 7
|
---|
175 | [parentdir,subdir] = fileparts(dir2);
|
---|
176 | mkdir(parentdir,subdir);
|
---|
177 | end
|
---|
178 | [f1,f2] = fileparts(dir2);
|
---|
179 | %disp(['Copying ' f2]);
|
---|
180 | switch type
|
---|
181 | case {'m','%'}
|
---|
182 | if isunix
|
---|
183 | unix(['cp ' dir1 '/*.m ' dir2]);
|
---|
184 | else
|
---|
185 | list = dir([dir1 '/*.m']);
|
---|
186 | end
|
---|
187 | case {'p'}
|
---|
188 | if isunix
|
---|
189 | unix(['cp ' dir1 '/*.p ' dir2]);
|
---|
190 | else
|
---|
191 | list = dir([dir1 '/*.p']);
|
---|
192 | end
|
---|
193 | case {'qld'}
|
---|
194 | if isunix
|
---|
195 | unix(['cp ' dir1 '/qld.dl* ' dir2]);
|
---|
196 | unix(['cp ' dir1 '/qld.mex* ' dir2]);
|
---|
197 | else
|
---|
198 | list = dir([dir1 '/qld.dl*']);
|
---|
199 | list = [list; dir([dir1 '/qld.mex*'])];
|
---|
200 | end
|
---|
201 | otherwise
|
---|
202 | if isunix
|
---|
203 | unix(['cp ' dir1 '/* ' dir2]);
|
---|
204 | else
|
---|
205 | list = dir([dir1 '/*']);
|
---|
206 | end
|
---|
207 |
|
---|
208 | end
|
---|
209 | if ~isunix
|
---|
210 | k = length(list);
|
---|
211 | for i = 1:k
|
---|
212 | %disp(['File copy ' list(i).name]);
|
---|
213 | if ~list(i).isdir
|
---|
214 | copyfile(fullfile(dir1,list(i).name),fullfile(dir2,list(i).name));
|
---|
215 | end
|
---|
216 | end
|
---|
217 | end
|
---|
218 |
|
---|
219 | if strcmp(type,'%')
|
---|
220 | list = dir(dir2);
|
---|
221 | k = length(list);
|
---|
222 | for i=1:k
|
---|
223 | %disp(['File reduce ' list(i).name]);
|
---|
224 | if ~list(i).isdir
|
---|
225 | r = gethf(fullfile(dir2,list(i).name));
|
---|
226 | writf(fullfile(dir2,list(i).name),r);
|
---|
227 | end
|
---|
228 | end
|
---|
229 | end
|
---|
230 |
|
---|
231 | %LISTN List lines specified by their line number
|
---|
232 | %
|
---|
233 | % t = listn(r,n)
|
---|
234 | % Get the lines in r given by the line numbers in n.
|
---|
235 | function t = listn(r,n)
|
---|
236 | nlchar = setstr(10); % use Windows / Unix newline char
|
---|
237 | k = [0,find(r==nlchar)];
|
---|
238 | t = [];
|
---|
239 | for j = n
|
---|
240 | t = [t,r(k(j)+1:k(j+1))];
|
---|
241 | end
|
---|
242 | return
|
---|
243 |
|
---|
244 | %GETHFT Create heading file from m-file
|
---|
245 | %
|
---|
246 | % s = gethf(file)
|
---|
247 | %
|
---|
248 | % The heading of the given m-file consisting of all starting % lines
|
---|
249 | % is isolated and returned in s.
|
---|
250 |
|
---|
251 | function s = gethf(file)
|
---|
252 | [s,ns] = readf(file);
|
---|
253 | p=grep(s,'%');
|
---|
254 | if isempty(p), p = 0; end
|
---|
255 | I = find(p - [0,p(1:length(p)-1)] ~= 1);
|
---|
256 | if p(1) == 1 & isempty(I), I = length(p) + 1; end
|
---|
257 | if length(I) > 0 & I(1) > 1
|
---|
258 | n = I(1) - 1;
|
---|
259 | s = listn(s,1:n);
|
---|
260 | else
|
---|
261 | s = '';
|
---|
262 | end
|
---|
263 |
|
---|
264 | %GREP Get line specific lines
|
---|
265 | %
|
---|
266 | % n = grep(r,s)
|
---|
267 | % Get the numbers of all lines in the set of lines r
|
---|
268 | % that contain s.
|
---|
269 |
|
---|
270 | function k = grep(r,s)
|
---|
271 | n = [0,find(r==newline)];
|
---|
272 | m = findstr(r,s);
|
---|
273 | [i,j] = sort([n,m]);;
|
---|
274 | q = [0,j(1:length(j)-1)]-j;
|
---|
275 | k = j(find(q>0))-1;
|
---|
276 | return
|
---|
277 |
|
---|
278 | function [s,n] = readf(file)
|
---|
279 | fid = fopen(file);
|
---|
280 | if fid < 0
|
---|
281 | error(['File ' file ' not found, probably wrong directory'])
|
---|
282 | end
|
---|
283 | [s,n] = fread(fid);
|
---|
284 | if isempty(s)
|
---|
285 | error(['File ' file ' could not be read'])
|
---|
286 | end
|
---|
287 | s = s(:)';
|
---|
288 | fclose(fid);
|
---|
289 |
|
---|
290 | function writf(file,s)
|
---|
291 | filedir = fileparts(which(file));
|
---|
292 | fid = fopen(fullfile(filedir,file),'w');
|
---|
293 | if fid < 0
|
---|
294 | error(['File ' file ' could not be opened for writing'])
|
---|
295 | end
|
---|
296 | fwrite(fid,s);
|
---|
297 | fclose(fid);
|
---|
298 |
|
---|
299 | function set_version_in_Contents(prtv)
|
---|
300 | if ~isstr(prtv)
|
---|
301 | error('Version should be given as string, e.g. ''3.2.7''')
|
---|
302 | end
|
---|
303 | s = readf('Contents.m');
|
---|
304 | n = findstr(s,newline);
|
---|
305 | r = [s(1:n(1)), '% Version ' prtv ' ' date s(n(2):end)];
|
---|
306 | writf('Contents.m',r);
|
---|
307 | disp(' Contents.m rewritten with new version number')
|
---|
308 |
|
---|
309 | function myedit(file)
|
---|
310 |
|
---|
311 | try
|
---|
312 | edit(file);
|
---|
313 | catch
|
---|
314 | if isunix
|
---|
315 | s = input(' Could not find editor, OK to open vi? [yes]/no: ','s');
|
---|
316 | if isempty(s) | strcmp(s,'yes')
|
---|
317 | unix(['vi ' file]);
|
---|
318 | else
|
---|
319 | disp([' Could not open ' file ' for editing']);
|
---|
320 | end
|
---|
321 | else
|
---|
322 | disp([' Could not open ' file ' for editing']);
|
---|
323 | end
|
---|
324 | end
|
---|