[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.
|
---|
| 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 |
|
---|
[133] | 106 | % Create export version in dir2, RD: not needed anymore from 2019
|
---|
[113] | 107 | today = datestr(date,'ddmmmyy');
|
---|
[133] | 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
|
---|
[113] | 118 |
|
---|
[133] | 119 | % Generate pcodes. RD: we stopped this in 2019
|
---|
| 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
|
---|
[113] | 124 |
|
---|
| 125 | % Create zip-files
|
---|
| 126 | fprintf(1,' Creating zip files ... \n');
|
---|
[133] | 127 | exporttemp = prtmp; % RD: starting 2019, no separate exporttemp is needed
|
---|
[113] | 128 | cd(exportdir);
|
---|
| 129 | copyfile('License.txt',exporttemp,'f');
|
---|
| 130 | copyfile('Install_notes.txt',exporttemp,'f');
|
---|
| 131 | copyfile('Release_notes.txt',exporttemp,'f');
|
---|
[133] | 132 | exppfiles = ['prtex' pver_new '.' today '.zip'];
|
---|
[113] | 133 | mfiles = ['prtools' pver_new '.' today '.zip'];
|
---|
[133] | 134 | zip(exppfiles,{'prtools','License.txt','Install_notes.txt','Release_notes.txt'},exporttemp);
|
---|
[113] | 135 | zip(mfiles,[fullfile(prtmp,'prtools') '/*']);
|
---|
| 136 | rmdir(prtmp,'s');
|
---|
| 137 |
|
---|
| 138 | if doit
|
---|
| 139 | fprintf(1,' FTP PRTools zip-file to website ... \n');
|
---|
[133] | 140 | % store export files on website
|
---|
[128] | 141 | ftpsite = ftp('prtools.tudelft.nl','prlab','0iX7&b3c');
|
---|
[113] | 142 | cd(ftpsite,'httpdocs/files');
|
---|
[133] | 143 | mput(ftpsite,exppfiles);
|
---|
| 144 | rename(ftpsite,exppfiles,'prtools.zip');
|
---|
| 145 | disp('export files have been stored on the website.')
|
---|
[113] | 146 | disp('Please check and adjust release notes and known problems on website')
|
---|
| 147 | close(ftpsite)
|
---|
| 148 |
|
---|
| 149 | % backup p-files and m-files
|
---|
[133] | 150 | fprintf(1,' Storing backups of mfiles and export files ... \n');
|
---|
| 151 | [s,mess] = copyfile(exppfiles,fullfile(exportdir,'prtools_old_export'));
|
---|
[113] | 152 | if s
|
---|
[133] | 153 | delete(exppfiles);
|
---|
| 154 | disp(['export files have been backed-up in ' exportdir])
|
---|
[113] | 155 | else
|
---|
| 156 | disp(mess);
|
---|
| 157 | end
|
---|
[128] | 158 | [s,mess] = copyfile(mfiles,fullfile(exportdir,'prtools_old_archive'));
|
---|
[113] | 159 | if s
|
---|
| 160 | delete(mfiles);
|
---|
| 161 | disp(['m-files have been backed-up in ' exportdir])
|
---|
| 162 | else
|
---|
| 163 | disp(mess);
|
---|
| 164 | end
|
---|
| 165 | end
|
---|
| 166 |
|
---|
| 167 | cd(curdir)
|
---|
| 168 |
|
---|
| 169 |
|
---|
| 170 | %COPYDIRM Copy mfiles from dir to dir
|
---|
| 171 | function copydirm(dir1,dir2,type)
|
---|
| 172 | if nargin < 3
|
---|
| 173 | type = 'm';
|
---|
| 174 | end
|
---|
| 175 | if exist(dir2) ~= 7
|
---|
| 176 | [parentdir,subdir] = fileparts(dir2);
|
---|
| 177 | mkdir(parentdir,subdir);
|
---|
| 178 | end
|
---|
| 179 | [f1,f2] = fileparts(dir2);
|
---|
| 180 | %disp(['Copying ' f2]);
|
---|
| 181 | switch type
|
---|
| 182 | case {'m','%'}
|
---|
| 183 | if isunix
|
---|
| 184 | unix(['cp ' dir1 '/*.m ' dir2]);
|
---|
| 185 | else
|
---|
| 186 | list = dir([dir1 '/*.m']);
|
---|
| 187 | end
|
---|
| 188 | case {'p'}
|
---|
| 189 | if isunix
|
---|
| 190 | unix(['cp ' dir1 '/*.p ' dir2]);
|
---|
| 191 | else
|
---|
| 192 | list = dir([dir1 '/*.p']);
|
---|
| 193 | end
|
---|
| 194 | case {'qld'}
|
---|
| 195 | if isunix
|
---|
| 196 | unix(['cp ' dir1 '/qld.dl* ' dir2]);
|
---|
| 197 | unix(['cp ' dir1 '/qld.mex* ' dir2]);
|
---|
| 198 | else
|
---|
| 199 | list = dir([dir1 '/qld.dl*']);
|
---|
| 200 | list = [list; dir([dir1 '/qld.mex*'])];
|
---|
| 201 | end
|
---|
| 202 | otherwise
|
---|
| 203 | if isunix
|
---|
| 204 | unix(['cp ' dir1 '/* ' dir2]);
|
---|
| 205 | else
|
---|
| 206 | list = dir([dir1 '/*']);
|
---|
| 207 | end
|
---|
| 208 |
|
---|
| 209 | end
|
---|
| 210 | if ~isunix
|
---|
| 211 | k = length(list);
|
---|
| 212 | for i = 1:k
|
---|
| 213 | %disp(['File copy ' list(i).name]);
|
---|
| 214 | if ~list(i).isdir
|
---|
| 215 | copyfile(fullfile(dir1,list(i).name),fullfile(dir2,list(i).name));
|
---|
| 216 | end
|
---|
| 217 | end
|
---|
| 218 | end
|
---|
| 219 |
|
---|
| 220 | if strcmp(type,'%')
|
---|
| 221 | list = dir(dir2);
|
---|
| 222 | k = length(list);
|
---|
| 223 | for i=1:k
|
---|
| 224 | %disp(['File reduce ' list(i).name]);
|
---|
| 225 | if ~list(i).isdir
|
---|
| 226 | r = gethf(fullfile(dir2,list(i).name));
|
---|
| 227 | writf(fullfile(dir2,list(i).name),r);
|
---|
| 228 | end
|
---|
| 229 | end
|
---|
| 230 | end
|
---|
| 231 |
|
---|
| 232 | %LISTN List lines specified by their line number
|
---|
| 233 | %
|
---|
| 234 | % t = listn(r,n)
|
---|
| 235 | % Get the lines in r given by the line numbers in n.
|
---|
| 236 | function t = listn(r,n)
|
---|
| 237 | nlchar = setstr(10); % use Windows / Unix newline char
|
---|
| 238 | k = [0,find(r==nlchar)];
|
---|
| 239 | t = [];
|
---|
| 240 | for j = n
|
---|
| 241 | t = [t,r(k(j)+1:k(j+1))];
|
---|
| 242 | end
|
---|
| 243 | return
|
---|
| 244 |
|
---|
| 245 | %GETHFT Create heading file from m-file
|
---|
| 246 | %
|
---|
| 247 | % s = gethf(file)
|
---|
| 248 | %
|
---|
| 249 | % The heading of the given m-file consisting of all starting % lines
|
---|
| 250 | % is isolated and returned in s.
|
---|
| 251 |
|
---|
| 252 | function s = gethf(file)
|
---|
| 253 | [s,ns] = readf(file);
|
---|
| 254 | p=grep(s,'%');
|
---|
| 255 | if isempty(p), p = 0; end
|
---|
| 256 | I = find(p - [0,p(1:length(p)-1)] ~= 1);
|
---|
| 257 | if p(1) == 1 & isempty(I), I = length(p) + 1; end
|
---|
| 258 | if length(I) > 0 & I(1) > 1
|
---|
| 259 | n = I(1) - 1;
|
---|
| 260 | s = listn(s,1:n);
|
---|
| 261 | else
|
---|
| 262 | s = '';
|
---|
| 263 | end
|
---|
| 264 |
|
---|
| 265 | %GREP Get line specific lines
|
---|
| 266 | %
|
---|
| 267 | % n = grep(r,s)
|
---|
| 268 | % Get the numbers of all lines in the set of lines r
|
---|
| 269 | % that contain s.
|
---|
| 270 |
|
---|
| 271 | function k = grep(r,s)
|
---|
| 272 | n = [0,find(r==newline)];
|
---|
| 273 | m = findstr(r,s);
|
---|
| 274 | [i,j] = sort([n,m]);;
|
---|
| 275 | q = [0,j(1:length(j)-1)]-j;
|
---|
| 276 | k = j(find(q>0))-1;
|
---|
| 277 | return
|
---|
| 278 |
|
---|
| 279 | function [s,n] = readf(file)
|
---|
| 280 | fid = fopen(file);
|
---|
| 281 | if fid < 0
|
---|
| 282 | error(['File ' file ' not found, probably wrong directory'])
|
---|
| 283 | end
|
---|
| 284 | [s,n] = fread(fid);
|
---|
| 285 | if isempty(s)
|
---|
| 286 | error(['File ' file ' could not be read'])
|
---|
| 287 | end
|
---|
| 288 | s = s(:)';
|
---|
| 289 | fclose(fid);
|
---|
| 290 |
|
---|
| 291 | function writf(file,s)
|
---|
| 292 | filedir = fileparts(which(file));
|
---|
| 293 | fid = fopen(fullfile(filedir,file),'w');
|
---|
| 294 | if fid < 0
|
---|
| 295 | error(['File ' file ' could not be opened for writing'])
|
---|
| 296 | end
|
---|
| 297 | fwrite(fid,s);
|
---|
| 298 | fclose(fid);
|
---|
| 299 |
|
---|
| 300 | function set_version_in_Contents(prtv)
|
---|
| 301 | if ~isstr(prtv)
|
---|
| 302 | error('Version should be given as string, e.g. ''3.2.7''')
|
---|
| 303 | end
|
---|
| 304 | s = readf('Contents.m');
|
---|
| 305 | n = findstr(s,newline);
|
---|
| 306 | r = [s(1:n(1)), '% Version ' prtv ' ' date s(n(2):end)];
|
---|
| 307 | writf('Contents.m',r);
|
---|
| 308 | disp(' Contents.m rewritten with new version number')
|
---|
| 309 |
|
---|
| 310 | function myedit(file)
|
---|
| 311 |
|
---|
| 312 | try
|
---|
| 313 | edit(file);
|
---|
| 314 | catch
|
---|
| 315 | if isunix
|
---|
| 316 | s = input(' Could not find editor, OK to open vi? [yes]/no: ','s');
|
---|
| 317 | if isempty(s) | strcmp(s,'yes')
|
---|
| 318 | unix(['vi ' file]);
|
---|
| 319 | else
|
---|
| 320 | disp([' Could not open ' file ' for editing']);
|
---|
| 321 | end
|
---|
| 322 | else
|
---|
| 323 | disp([' Could not open ' file ' for editing']);
|
---|
| 324 | end
|
---|
| 325 | end
|
---|