diff options
| author | leochanj105 <leochanj@live.unc.edu> | 2020-10-19 23:09:30 -0400 |
|---|---|---|
| committer | leochanj105 <leochanj@live.unc.edu> | 2020-10-20 02:40:39 -0400 |
| commit | f618466c25d43f3bae9e40920273bf77de1e1149 (patch) | |
| tree | 460e739e2165b8a9c37a9c7ab1b60f5874903543 /SD-VBS/common/toolbox/toolbox_basic/stella/ncutcheckin.m | |
| parent | 47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 (diff) | |
initial sd-vbs
initial sd-vbs
add sd-vbs
sd-vbs
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/stella/ncutcheckin.m')
| -rwxr-xr-x | SD-VBS/common/toolbox/toolbox_basic/stella/ncutcheckin.m | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/ncutcheckin.m b/SD-VBS/common/toolbox/toolbox_basic/stella/ncutcheckin.m new file mode 100755 index 0000000..cd82ee5 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/stella/ncutcheckin.m | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | % function rec_num = ncutcheckin(fn,sdir,tdir) | ||
| 2 | % Input: | ||
| 3 | % fn = parameter file name, default = 'command_ncut.tex' | ||
| 4 | % sdir = source dir for fn as well as data files | ||
| 5 | % tdir = target dir to check in, both default = IMAGE_DIR | ||
| 6 | % Output: | ||
| 7 | % rec_num = the number of current parameter records | ||
| 8 | % The imagefile_par.m is updated if fn contains a new | ||
| 9 | % parameter set. Data files are tagged and copied over to | ||
| 10 | % a subdir under tdir. | ||
| 11 | % Example: ncutcheckin; | ||
| 12 | % Set IS_PC, IMAGE_DIR according to your platform in globalenvar.m | ||
| 13 | |||
| 14 | % Stella X. Yu, 2000. | ||
| 15 | |||
| 16 | function rec_num = ncutcheckin(fn,sdir,tdir) | ||
| 17 | |||
| 18 | globalenvar; | ||
| 19 | |||
| 20 | cur_dir = pwd; | ||
| 21 | |||
| 22 | if nargin<1 | isempty(fn), | ||
| 23 | fn = 'command_ncut.tex'; | ||
| 24 | end | ||
| 25 | |||
| 26 | if nargin<2 | isempty(sdir), | ||
| 27 | sdir = IMAGE_DIR; | ||
| 28 | end | ||
| 29 | |||
| 30 | if nargin<3 | isempty(tdir), | ||
| 31 | tdir = IMAGE_DIR; | ||
| 32 | end | ||
| 33 | |||
| 34 | rec = jshincutdefpar; | ||
| 35 | |||
| 36 | % first, generate a parameter record from fn | ||
| 37 | cd(sdir); | ||
| 38 | [names,values] = textread(fn,'%s %s','commentstyle','shell'); | ||
| 39 | n = length(names); | ||
| 40 | s = rec; | ||
| 41 | for i=1:n, | ||
| 42 | j = str2num(values{i}); | ||
| 43 | if isempty(j), | ||
| 44 | s = setfield(s,names{i},values{i}); | ||
| 45 | else | ||
| 46 | s = setfield(s,names{i},j); | ||
| 47 | end | ||
| 48 | end | ||
| 49 | cd(cur_dir); | ||
| 50 | |||
| 51 | % special care to extract the image file name | ||
| 52 | imagename = getfield(s,names{1}); | ||
| 53 | catchar = {'/','\'}; | ||
| 54 | catchar = catchar{IS_PC + 1}; | ||
| 55 | k = max([0,findstr(imagename,catchar)]); | ||
| 56 | imagename = imagename(k+1:end); | ||
| 57 | s = setfield(s,names{1},imagename); | ||
| 58 | |||
| 59 | % second, check if the target dir contains a profile for the image | ||
| 60 | cd(tdir); | ||
| 61 | if not(exist(imagename,'dir')), | ||
| 62 | mkdir(imagename); | ||
| 63 | cd(cur_dir); | ||
| 64 | j = [catchar,imagename,'.',getfield(s,names{2})]; | ||
| 65 | copyfile([sdir,j],[tdir,catchar,imagename,j]); | ||
| 66 | cd(tdir); | ||
| 67 | end | ||
| 68 | cd(imagename); | ||
| 69 | j = [imagename,'_par']; | ||
| 70 | if not(exist(j)), | ||
| 71 | rec_num = 1; | ||
| 72 | p = s; | ||
| 73 | else | ||
| 74 | % load par file | ||
| 75 | feval(j); | ||
| 76 | rec_num = length(p); | ||
| 77 | i = 1; | ||
| 78 | while (i<=rec_num), | ||
| 79 | k = 0; | ||
| 80 | for j=1:n, | ||
| 81 | k = k + sum(getfield(s,names{j})-getfield(p(i),names{j})); | ||
| 82 | end | ||
| 83 | if k==0, | ||
| 84 | if not(isempty(input(['Data already existed as record # ',num2str(i),... | ||
| 85 | '\nPress any non-return key to Overwrite'],'s'))), | ||
| 86 | break; | ||
| 87 | else | ||
| 88 | rec_num = i; % have checked in already, no update | ||
| 89 | cd(cur_dir); | ||
| 90 | return; | ||
| 91 | end | ||
| 92 | else | ||
| 93 | i = i + 1; | ||
| 94 | end | ||
| 95 | end | ||
| 96 | rec_num = i; % new parameter setting | ||
| 97 | p(rec_num)=s; | ||
| 98 | end | ||
| 99 | tdir = [tdir,catchar,imagename]; | ||
| 100 | cd(cur_dir); | ||
| 101 | |||
| 102 | % third, check in data files | ||
| 103 | % leave .ppm and _edgecon, _phase files | ||
| 104 | % if not(exist([tdir,catchar,imagename,'.ppm'])), | ||
| 105 | % copyfile([sdir,catchar,imagename,'.ppm'],[tdir,catchar,imagename,'.ppm']); | ||
| 106 | % end | ||
| 107 | |||
| 108 | % IC files only | ||
| 109 | dn = getfnames(sdir,[imagename,'*_IC*.*']); | ||
| 110 | header = sprintf('%s%c%s_%d_',tdir,catchar,imagename,rec_num); | ||
| 111 | j = length(imagename)+2; | ||
| 112 | k = length(dn); | ||
| 113 | for i=1:k, | ||
| 114 | copyfile([sdir,catchar,dn{i}],[header,dn{i}(j:end)]); | ||
| 115 | delete([sdir,catchar,dn{i}]); | ||
| 116 | end | ||
| 117 | disp(sprintf('%d files checked in as record #%d',k,rec_num)); | ||
| 118 | |||
| 119 | |||
| 120 | % finally, update parameter file | ||
| 121 | cd(tdir); | ||
| 122 | fid = fopen([imagename,'_par.m'],'w'); | ||
| 123 | fprintf(fid,'%% Last checked in at %s\n\n',datestr(now)); | ||
| 124 | for i=1:rec_num, | ||
| 125 | for j=1:n, | ||
| 126 | k = getfield(p(i),names{j}); | ||
| 127 | if ischar(k), | ||
| 128 | fprintf(fid,'p(%d).%s=\''%s\'';\n',i,names{j},k); | ||
| 129 | else | ||
| 130 | fprintf(fid,'p(%d).%s=%s;\n',i,names{j},num2str(k)); | ||
| 131 | end | ||
| 132 | end | ||
| 133 | fprintf(fid,'\n'); | ||
| 134 | end | ||
| 135 | fclose(fid); | ||
| 136 | cd(cur_dir); \ No newline at end of file | ||
