Changeset 122 for trunk/src/name_generator.m
- Timestamp:
- Nov 14, 2010, 9:58:15 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/name_generator.m
r120 r122 1 1 %'name_generator': creates a file name from a root name and indices. 2 2 %------------------------------------------------------------------------ 3 % [filename, idetect,num_i1_out,num_j1_out,num_i2_out,num_j2_out,subdir_out]=...3 % [filename,num_i1_out,num_j1_out,num_i2_out,num_j2_out,subdir_out]=... 4 4 % name_generator(filebase,num_i1,num_j1,ext,nom_type,comp_input,num_i2,num_j2,subdir); 5 5 %------------------------------------------------------------------------ … … 10 10 % OUTPUT: 11 11 % filename: string representing the file name (including path) 12 % idetect: =1 if the file is detected, 0 otherwise13 12 % num_i1_out,num_j1_out,num_i2_out,num_j2_out,subdir_out: index numbers and subdirectory detected 14 13 % for free input (= to the corresponding input indices when comp_input=1) … … 19 18 % 'num_j1', first labelling index j 20 19 % 'ext': file name extension (e.g. '.png' or '.nc') 21 % 'nom_type': string defining the kind of nomenclature used: 22 % nom_type='': constant name [filebase ext] (default output if 'nom_type' is undefined) 23 % nom_type='*': the same file [filebase ext] contains successive fields (ex avi movies) 24 % nom_type='%03d' or '%04d', series of indexed images with numbers completed with zeros to 3 or 4 digits, e.g.'aa045.tif' 25 % nom_type='_i': series of files with a single index i preceded by '_'(e.g. 'aa_45.png'). 26 % nom_type='_%03d', '_%04d', or '_%05d', series of indexed images with _ and numbers completed with zeros to 3, 4 or 5 digits, e.g.'aa_045.tif' 27 % nom_type='#' series of indexed images wich is not series_i [filebase index ext], e.g. 'aa045.jpg' or 'aa45.tif' 28 % nom_type='_i_j' matrix of files with two indices i and j separated by '_'(e.g. 'aa_45_2.png') 29 % nom_type='_i1-i2' from pairs from a single index (e.g. 'aa_45-47.nc') 30 % nom_type='_i_j1-j2'pairs of j indices (e.g. 'aa_45_2-3.nc') 31 % nom_type='_i1-i2_j' pairs of i indices (e.g. 'aa_45-46_2.nc') 32 % nom_type='%3da','%3dA' with a numerical index and an index letter(e.g.'aa045b.png'), 33 % nom_type='#a','#A' with a numerical index and an index letter(e.g.'aa045b.png'), OBSOLETE (replaced by 'series_i_j') 34 % nom_type='#_ab' from pairs of '#a' images (e.g. 'aa045bc.nc'), 35 % nom_type='%3d_ab' from pairs of '%3da' images (e.g. 'aa045bc.nc') 20 %nom_type: char chain characterizing the file nomenclature: with values 21 % nom_type='': constant name [filebase ext] (default output if 'nom_type' is undefined) 22 % nom_type='*':constant name for a file representing a series (e.g. avi movie) 23 % nom_type='1','01',or '001'...': series of files with a single index i without separator(e.g. 'aa045.png'). 24 % nom_type='_1','_01','_001'...': series of files with a single index i with separator '_'(e.g. 'aa_045.png'). 25 % nom_type='1a','1A','01a','01A',... with a numerical index and an index letter(e.g.'aa45b.png') (lower or upper case) 26 % nom_type='_1a','_1A','_01a','_01A',...: idem, with a separator '_' before the index 27 % nom_type='_1_1','_01_1',...: matrix of files with two indices i and j separated by '_'(e.g. 'aa_45_2.png') 28 % nom_type='_i1-i2': from pairs from a single index (e.g. 'aa_45-47.nc') 29 % nom_type='_i_j1-j2': pairs of j indices (e.g. 'aa_45_2-3.nc') 30 % nom_type='_i1-i2_j': pairs of i indices (e.g. 'aa_45-46_2.nc') 31 % nom_type='_1_ab','1_ab','01_ab'..., from pairs of '#' images (e.g.'aa045bc.nc'), ext='.nc' 36 32 %'comp_input' (for nom_type involving index pairs (e.g. netc)) 37 33 % comp_input=1: the index pair is imposed, … … 45 41 % A FAIRE: si comp_inpu=0, si _i_j n'existe pas, chercher _i, 46 42 function [filename,num_i1_out,num_j1_out,num_i2_out,num_j2_out,subdir_out]=... 47 name_generator(filebase,num_i1,num_j1,ext,nom_type,comp_input,num_i2,num_j2,subdir) ;43 name_generator(filebase,num_i1,num_j1,ext,nom_type,comp_input,num_i2,num_j2,subdir) 48 44 sizf=size(filebase); 49 45 if (~ischar(filebase)||~isequal(sizf(1),1)),filebase='';end … … 75 71 num_i2_out=num_i2;%default output 76 72 num_j2_out=num_j2;%default output 77 78 test_pairs=strcmp(nom_type,'netc_old')| strcmp(nom_type,'netc_2D') | strcmp(nom_type,'netc_3D')| strcmp(nom_type,'_i1-i2_j1-j2')| ... 79 strcmp(nom_type,'netc_series')| strcmp(nom_type,'#_ab')| strcmp(nom_type,'_i_j1-j2')| strcmp(nom_type,'_i1-i2_j')| strcmp(nom_type,'_i1-i2'); 80 test_2D= strcmp(nom_type,'netc_old') |strcmp(nom_type,'netc_2D')|strcmp(nom_type,'#_ab') |strcmp(nom_type,'_i_j1-j2'); 81 test_3D=strcmp(nom_type,'netc_3D') |strcmp(nom_type,'netc_series')| strcmp(nom_type,'_i1-i2_j')| strcmp(nom_type,'_i1-i2'); 82 if strcmp(nom_type,'series_i')| strcmp(nom_type,'_i'); 83 filename=[filebase '_' num2str(num_i1) ext]; 84 num_i2_out=num_i1; 85 num_j1_out=[]; 86 num_j2_out=[]; 87 elseif length(nom_type)==5 && strcmp(nom_type(1:3),'_%0')&& strcmp(nom_type(5),'d'); 88 filename=[filebase '_' num2str(num_i1,nom_type(2:5)) ext]; 89 num_i2_out=num_i1; 90 num_j2_out=num_j1; 91 elseif strcmp(nom_type,'series_i_j')| strcmp(nom_type,'_i_j') 92 filename=[filebase '_' num2str(num_i1) '_' num2str(num_j1) ext]; 93 num_i2_out=num_i1; 94 num_j2_out=num_j1; 95 elseif strcmp(nom_type,'png_old')| strcmp(nom_type,'#a')| strcmp(nom_type,'#A') 96 filename=[filebase num2str(num_i1,'%03d') num2stra(num_j1,nom_type) ext]; 97 num_i2_out=num_i1; 98 num_j2_out=num_j1; 99 elseif length(nom_type)>=5 & strcmp(nom_type(2:3),'%0') & strcmp(nom_type(5),'d') %strcmp(nom_type,'_%04dA') %camera PCO Toulouse 100 filename=[filebase nom_type(1) num2str(num_i1,nom_type(2:4)) num2stra(num_j1,nom_type) ext]; 101 num_i2_out=num_i1; 102 num_j2_out=num_j1; 103 elseif strcmp(nom_type,'raw_SMD') %suffix a, b, c without extension 104 filename=[filebase num2str(num_i1,'%03d') num2stra(num_j1,nom_type)]; 105 num_i2_out=num_i1; 106 num_j2_out=num_j1; 107 elseif strcmp(nom_type,'ima_num')| strcmp(nom_type,'#') 108 filename=[filebase num2str(num_i1) ext]; 109 num_i2_out=num_i1; 110 num_j1_out=[]; 111 num_j2_out=[]; 112 elseif length(nom_type)>=4 & strcmp(nom_type(1:2),'%0') & strcmp(nom_type(end),'d') 113 filename=[filebase num2str(num_i1,nom_type) ext]; %test number with a 0 before 114 num_i2_out=num_i1; 115 num_j1_out=[]; 116 num_j2_out=[]; 117 elseif length(nom_type)>=4 & strcmp(nom_type(1:2),'%0') & strcmp(nom_type(end-1:end),'dA') 118 filename=[filebase num2str(num_i1,nom_type(1:end-1)) num2stra(num_j1,'#A') ext]; %test number with a 0 before 119 num_i2_out=num_i1; 120 num_j1_out=[]; 121 num_j2_out=[]; 122 73 test_pairs=numel(nom_type)>=2 &&(strcmp(nom_type,'_i1-i2_j1-j2')|| strcmp(nom_type(end-1:end),'ab')|| strcmp(nom_type(end-1:end),'AB')||... 74 strcmp(nom_type,'_i_j1-j2')|| strcmp(nom_type,'_i1-i2_j')||strcmp(nom_type,'_i1-i2')); 75 %test_2D= strcmp(nom_type(end-1:end),'ab')|| strcmp(nom_type(end-1:end),'AB') ||strcmp(nom_type,'_i_j1-j2'); 76 %test_3D=strcmp(nom_type,'_i1-i2_j')|| strcmp(nom_type,'_i1-i2'); 77 if ~isequal(subdir,'') && ~isequal(subdir,'?') 78 [Path,Name]=fileparts(filebase); 79 filename=fullfile(Path,subdir,Name); 80 else 81 filename=filebase;%default 82 end 83 if ~test_pairs%case of a single index i, and possibly j 84 numlength=numel(nom_type); 85 num_j_str=''; 86 if strcmp(nom_type(1),'_') 87 filename=[filename '_']; 88 nom_type(1)=[]; 89 end 90 if strcmp(nom_type(end),'a') 91 nom_type(end)=[]; 92 num_j_str=char(num_j1+96);% lower letter corresponding to the index 93 elseif strcmp(nom_type(end),'A') 94 nom_type(end)=[]; 95 num_j_str=char(num_j1+64);% lower letter corresponding to the index 96 elseif isequal(numel(regexp(nom_type(2:end),'_')),1)%if a separator '_' exists in nom_type 97 num_j_str=['_' num2str(num_j1)]; 98 nom_type(regexp(nom_type(2:end),'_'):end)=[]; 99 else 100 num_j1_out=[];%no index j 101 end 102 if ~isempty(str2num(nom_type)) 103 numtype=['%0' num2str(length(nom_type)) 'd'];%indicate the number of digits (0 before the number) 104 filename=[filename num2str(num_i1,numtype) num_j_str ext]; 105 num_i2_out=num_i1_out; 106 num_j2_out=num_j1_out; 107 else %fixed name , no indexing, for instance '*' 108 % filebasesub=filebase; 109 filename=[filename ext]; 110 end 111 % if strcmp(nom_type,'_i'); 112 % filename=[filebase '_' num2str(num_i1) ext]; 113 % num_i2_out=num_i1; 114 % num_j1_out=[]; 115 % num_j2_out=[]; 116 % elseif length(nom_type)==5 && strcmp(nom_type(1:3),'_%0')&& strcmp(nom_type(5),'d'); 117 % filename=[filebase '_' num2str(num_i1,nom_type(2:5)) ext]; 118 % num_i2_out=num_i1; 119 % num_j2_out=num_j1; 120 % elseif strcmp(nom_type,'_i_j') 121 % filename=[filebase '_' num2str(num_i1) '_' num2str(num_j1) ext]; 122 % num_i2_out=num_i1; 123 % num_j2_out=num_j1; 124 % elseif strcmp(nom_type,'#a')| strcmp(nom_type,'#A') 125 % filename=[filebase num2str(num_i1,'%03d') num2stra(num_j1,nom_type) ext]; 126 % num_i2_out=num_i1; 127 % num_j2_out=num_j1; 128 % elseif length(nom_type)>=5 & strcmp(nom_type(2:3),'%0') & strcmp(nom_type(5),'d') %strcmp(nom_type,'_%04dA') %camera PCO Toulouse 129 % filename=[filebase nom_type(1) num2str(num_i1,nom_type(2:4)) num2stra(num_j1,nom_type) ext]; 130 % num_i2_out=num_i1; 131 % num_j2_out=num_j1; 132 % elseif strcmp(nom_type,'#') 133 % filename=[filebase num2str(num_i1) ext]; 134 % num_i2_out=num_i1; 135 % num_j1_out=[]; 136 % num_j2_out=[]; 137 % elseif length(nom_type)>=4 & strcmp(nom_type(1:2),'%0') & strcmp(nom_type(end),'d') 138 % filename=[filebase num2str(num_i1,nom_type) ext]; %test number with a 0 before 139 % num_i2_out=num_i1; 140 % num_j1_out=[]; 141 % num_j2_out=[]; 142 % elseif length(nom_type)>=4 & strcmp(nom_type(1:2),'%0') & strcmp(nom_type(end-1:end),'dA') 143 % filename=[filebase num2str(num_i1,nom_type(1:end-1)) num2stra(num_j1,'#A') ext]; %test number with a 0 before 144 % num_i2_out=num_i1; 145 % num_j1_out=[]; 146 % num_j2_out=[]; 147 % end 123 148 %case of derived file indexing (e.g. netcdf files) 124 elseif test_pairs 125 filebasesub=filebase; 126 % get the root name filebasesub for the netcdf files 127 if ~strcmp(subdir,'') && ~strcmp(subdir,'?') 128 [Path,Name]=fileparts(filebase); 129 filebasesub=fullfile(Path,subdir,Name); 130 end 149 else 131 150 %inexistant pair if num_i2=0 or num_j2=0 132 151 % if strcmp(num_i2,0) … … 139 158 % end 140 159 % case of an imposed image pair (comp_input=1) 141 if (exist('comp_input','var') & isequal(comp_input,1)) 142 if isequal(nom_type,'netc_old')|isequal(nom_type,'#_ab') 160 if (exist('comp_input','var') && isequal(comp_input,1)) 161 if strcmp(nom_type(1),'_') 162 filename=[filename '_']; 163 nom_type(1)=[]; 164 end 165 if strcmp(nom_type(end-1:end),'AB')||strcmp(nom_type(end-1:end),'ab') 166 if strcmp(nom_type(end-1:end),'AB') 167 nchar=64; 168 else 169 nchar=96; 170 end 171 if isequal(num_j1,num_j2)% case of displacements at the same time 172 num_j_str=char(num_j1+nchar); 173 else 174 num_j_str=[char(num_j1+nchar) char(num_j2+nchar)]; 175 end 176 if strcmp(nom_type(end-2),'_') 177 numstr=['%0' num2str(numel(nom_type)-3) 'd']; 178 num_j_str=['_' num_j_str]; 179 else 180 numstr=['%0' num2str(numel(nom_type)-2) 'd']; 181 end 182 filename=[filename num2str(num_i1,numstr) num_j_str ext]; 183 num_i2_out=num_i1; 184 elseif isequal(nom_type,'i_j1-j2') 143 185 if isequal(num2str(num_j1),num2str(num_j2))% case of displacements at the same time 144 filename=[file basesub num2str(num_i1,'%03d') '_' num2stra(num_j1,nom_type) ext];145 else 146 filename=[file basesub num2str(num_i1,'%03d') '_' num2stra(num_j1,nom_type) num2stra(num_j2,nom_type) ext];186 filename=[filename num2str(num_i1) '_' num2str(num_j1) ext]; 187 else 188 filename=[filename num2str(num_i1) '_' num2str(num_j1) '-' num2str(num_j2) ext]; 147 189 end 148 190 num_i2_out=num_i1; 149 elseif isequal(nom_type,'netc_2D')|isequal(nom_type,'_i_j1-j2') 150 if isequal(num2str(num_j1),num2str(num_j2))% case of displacements at the same time 151 filename=[filebasesub '_' num2str(num_i1) '_' num2str(num_j1) ext]; 152 else 153 filename=[filebasesub '_' num2str(num_i1) '_' num2str(num_j1) '-' num2str(num_j2) ext]; 154 end 155 num_i2_out=num_i1; 156 elseif isequal(nom_type,'netc_3D') || isequal(nom_type,'_i1-i2_j') 191 elseif isequal(nom_type,'i1-i2_j') 157 192 if isequal(num2str(num_i1),num2str(num_i2))% case of displacements at the same time 158 filename=[file basesub '_'num2str(num_i1) '_' num2str(num_j1) ext];159 else 160 filename=[file basesub '_'num2str(num_i1) '-' num2str(num_i2) '_' num2str(num_j1) ext];193 filename=[filename num2str(num_i1) '_' num2str(num_j1) ext]; 194 else 195 filename=[filename num2str(num_i1) '-' num2str(num_i2) '_' num2str(num_j1) ext]; 161 196 end 162 197 num_j2_out=num_j1; 163 elseif isequal(nom_type,'netc_series') || isequal(nom_type,'_i1-i2')198 elseif isequal(nom_type,'i1-i2') 164 199 if isequal(num2str(num_i1),num2str(num_i2))% case of displacements at the same time 165 filename=[file basesub '_'num2str(num_i1) ext];166 else 167 filename=[file basesub '_'num2str(num_i1) '-' num2str(num_i2) ext];200 filename=[filename num2str(num_i1) ext]; 201 else 202 filename=[filename num2str(num_i1) '-' num2str(num_i2) ext]; 168 203 end 169 204 num_j2_out=num_j1; 170 elseif isequal(nom_type,' _i1-i2_j1-j2')205 elseif isequal(nom_type,'i1-i2_j1-j2') 171 206 if isequal(num2str(num_i1),num2str(num_i2))% case of displacements at the same time 172 207 app1= [num2str(num_i1)]; … … 179 214 app2= [num2str(num_j1) '-' num2str(num_j2)]; 180 215 end 181 filename=[file basesub '_'app1 '_' app2 ext];216 filename=[filename app1 '_' app2 ext]; 182 217 end 183 218 idetect=1; … … 185 220 % case of an image pair to determine (comp_input=0) 186 221 else 187 [filename,num_i1_out,num_j1_out,num_i2_out,num_j2_out,idetect]=search_pair(filebasesub,num_i1,num_j1,num_i2,nom_type);222 [filename,num_i1_out,num_j1_out,num_i2_out,num_j2_out,idetect]=search_pair(filename,num_i1,num_j1,num_i2,nom_type); 188 223 end 189 224 … … 230 265 end 231 266 end 232 % elseif isequal(nom_type,'none')|isequal(nom_type,'')|isequal(nom_type,'*')233 else234 filebasesub=filebase;235 if ~isequal(subdir,'') && ~isequal(subdir,'?')236 [Path,Name]=fileparts(filebase);237 filebasesub=fullfile(Path,subdir,Name);238 end239 filename=[filebasesub ext];240 idetect=(exist(filename,'file')==2);241 267 end 242 268 if ~isequal(subdir,'?'), subdir_out=subdir; else, subdir_out='';end;
Note: See TracChangeset
for help on using the changeset viewer.