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