Changeset 334 for trunk/src/fileparts_uvmat.m
- Timestamp:
- Dec 14, 2011, 1:33:18 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/fileparts_uvmat.m
r333 r334 4 4 % 5 5 %OUTPUT: 6 %RootPath: path to the base file 7 %SubDir: name of the SubDirectory for netcdf files (NomTypes with index pairs 1-2 or ab ) 6 8 %RootFile: FileName without appendix 7 9 %i1: first number i … … 9 11 %j1: first number j 10 12 %j2: second number j (only for .nc files) 11 % Ext: file Extension13 %FileExt: file Extension 12 14 %NomType: char chain characterizing the file nomenclature: with values 13 % NomType='': constant name [filebase Ext] (default output if 'NomType' is undefined)15 % NomType='': constant name [filebase FileExt] (default output if 'NomType' is undefined) 14 16 % NomType='*':constant name for a file representing a series (e.g. avi movie) 15 17 % NomType='1','01',or '001'...': series of files with a single index i without separator(e.g. 'aa045.png'). … … 17 19 % NomType='1_1','01_1',...: matrix of files with two indices i and j separated by '_'(e.g. 'aa45_2.png') 18 20 % NomType='1-1': from pairs from a single index (e.g. 'aa_45-47.nc') 19 % NomType='1_1- 1': pairs of j indices (e.g. 'aa_45_2-3.nc')20 % NomType='1- 1_1': pairs of i indices (e.g. 'aa_45-46_2.nc')21 % NomType='1_ab','01_ab','01 _a-b'..., from pairs of '#' images (e.g.'aa045bc.nc'),Ext='.nc'21 % NomType='1_1-2': pairs of j indices (e.g. 'aa_45_2-3.nc') 22 % NomType='1-2_1': pairs of i indices (e.g. 'aa_45-46_2.nc') 23 % NomType='1_ab','01_ab','01ab'..., from pairs of '#' images (e.g.'aa045bc.nc'), FileExt='.nc' 22 24 %SubDir: name of the SubDirectory for netcdf files 23 24 % OLD TYPES, not supported anymore25 % NomType='_1','_01','_001'...': series of files with a single index i with separator '_'(e.g. 'aa_045.png').26 % NomType='_1a','_1A','_01a','_01A',...: idem, with a separator '_' before the index27 % NomType='_1_1','_01_1',...: matrix of files with two indices i and j separated by '_'(e.g. 'aa_45_2.png')28 % NomType='_i1-i2': from pairs from a single index (e.g. 'aa_45-47.nc')29 % NomType='_i_j1-j2': pairs of j indices (e.g. 'aa_45_2-3.nc')30 % NomType='_i1-i2_j': pairs of i indices (e.g. 'aa_45-46_2.nc')31 % NomType='_1_ab','1_ab','01_ab'..., from pairs of '#' images (e.g.'aa045bc.nc'), Ext='.nc'32 33 25 % 34 26 %INPUT: 35 27 %FileInput: complete name of the file, including path 36 28 37 function [RootPath,SubDir,RootFile,i1,i2,j1,j2,Ext,NomType]=fileparts_uvmat(FileInput) 38 29 function [RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomType]=fileparts_uvmat(FileInput) 30 RootPath=''; 31 SubDir=''; 32 RootFile=''; 39 33 i1=[]; 40 34 i2=[]; 41 35 j1=[]; 42 36 j2=[]; 37 FileExt=''; 43 38 NomType=''; 44 SubDir=''; 45 RootFile=''; 46 39 40 41 42 %% display help and test function in the absence of input arument 47 43 if ~exist('FileInput','var') 48 44 help fileparts_uvmat; … … 51 47 end 52 48 53 54 [RootPath,FileName,Ext]=fileparts(FileInput); 55 56 switch Ext 57 case '.avi' 58 NomType='*'; 59 return 60 case {'.tif','.tiff'} 61 if exist(FileInput,'file') 62 info=iminfo(FileInput); 63 if length(info)>1 64 NomType='*'; 65 return 66 end 67 end 68 end 49 [RootPath,FileName,FileExt]=fileparts(FileInput); 50 RootFile=FileName;%default 51 % switch FileExt 52 % case '.avi' 53 % NomType='*'; 54 % return 55 % case {'.tif','.tiff'} 56 % if exist(FileInput,'file') 57 % info=iminfo(FileInput); 58 % if length(info)>1 59 % NomType='*'; 60 % return 61 % end 62 % end 63 % end 69 64 70 65 % \D not a digit … … 72 67 73 68 74 %% recursive test on FileName stqrting from the end 75 69 %% recursive test on FileName starting from the end 70 % case of pure number 71 if ~isnan(str2double(FileName)) 72 RootFile=''; 73 i1=str2double(FileName); 74 return 75 end 76 76 % test whether FileName ends with a number or not 77 r=regexp(FileName,'.*\D(?<num1>\d+) \>','names');77 r=regexp(FileName,'.*\D(?<num1>\d+)$','names');% \D = not a digit, \d =digit 78 78 79 79 if ~isempty(r)% FileName end matches num1 80 80 num1=r.num1; 81 r=regexp(FileName,['.*\D(?<num2>\d+)(?<delim1>[-_])' num1 ' \>'],'names');81 r=regexp(FileName,['.*\D(?<num2>\d+)(?<delim1>[-_])' num1 '$'],'names'); 82 82 if ~isempty(r)% FileName end matches num2+delim1+num1 83 83 delim1=r.delim1; 84 84 num2=r.num2; 85 r=regexp(FileName,['.*\D(?<num3>\d+)(?<delim2>[-_])' num2 delim1 num1 ' \>'],'names');85 r=regexp(FileName,['.*\D(?<num3>\d+)(?<delim2>[-_])' num2 delim1 num1 '$'],'names'); 86 86 if ~isempty(r) % FileName end matches delim2 num2 delim1 num1 87 87 delim2=r.delim2; … … 117 117 RootFile=regexprep(FileName,[num2 delim1 num1],''); 118 118 end 119 NomType=regexprep(NomType,'-1','-2'); %set 1-2 instead of 1-1 119 120 else% only one number at the end 120 121 i1=str2double(num1); … … 123 124 end 124 125 else% FileName ends with a letter 125 r=regexp(FileName,'.*[^a^b^A^B](?<end_string>ab|AB|[abAB])\>','names'); 126 %r=regexp(FileName,'.*[^a^b^A^B](?<end_string>ab|AB|[abAB])\>','names'); 127 NomType=''; 128 r=regexp(RootFile,'\D(?<num1>\d+)(?<end_string>[a-z]|[A-Z]|[a-z][a-z]|[A-Z][A-Z])$','names'); 126 129 if ~isempty(r) 127 end_string=r.end_string; 128 r=regexp(FileName,['.+(?<delim1>[_-])' end_string '\>'],'names'); 130 NomType=get_type(r.end_string); 131 RootFile=regexprep(RootFile,[r.num1 r.end_string '$'],''); 132 else % case with separator '_' 133 r=regexp(RootFile,'\D(?<num1>\d+)_(?<end_string>[a-z]|[A-Z]|[a-z][a-z]|[A-Z][A-Z])$','names'); 129 134 if ~isempty(r) 130 delim1=r.delim1; 131 r=regexp(FileName,['.*\D(?<num1>\d+)' delim1 end_string '\>'],'names'); 132 if ~isempty(r) 133 num1=r.num1; 134 NomType=[get_type(num1) delim1 get_type(end_string)]; 135 i1=str2double(num1); 136 [j1,j2]=get_value(end_string); 137 RootFile=regexprep(FileName,[num1 delim1 end_string],''); 138 139 else 140 NomType=get_type(end_string); 141 [j1,j2]=get_value(end_string); 142 RootFile=regexprep(FileName,end_string,''); 143 144 end 145 else 146 r=regexp(FileName,['.*\D(?<num1>\d+)' end_string '\>'],'names'); 147 if ~isempty(r) 148 num1=r.num1; 149 % r=regexp(FileName,['.+(?<delim1>[-_])' num1 end_string '\>'],'names'); 150 % if ~isempty(r) 151 % delim1=r.delim1; 152 % i1=num1; 153 % str_a=end_string; 154 % NomType=[delim1 get_type(num1) get_type(end_string)]; 155 % RootFile=regexprep(FileName,[delim1 num1 end_string],''); 156 % else 157 i1=str2double(num1); 158 [j1,j2]=get_value(end_string); 159 NomType=[get_type(num1) get_type(end_string)]; 160 RootFile=regexprep(FileName,[num1 end_string],''); 161 % end 162 else 163 end 164 165 166 167 end 168 else 169 end 170 end 171 172 if ~isempty(regexp(NomType,'-|ab|AB')) 173 r=regexp(RootPath,'\<(?<newrootpath>.+)(\\|/)(?<subdir>[^\\^/]+)(\\|/)*\>','names'); 174 if ~isempty(r) 175 SubDir=r.subdir; 176 RootPath=r.newrootpath; 177 end 178 end 135 NomType=['_' get_type(r.end_string)]; 136 RootFile=regexprep(RootFile,[r.num1 '_' r.end_string '$'],''); 137 end 138 end 139 if ~isempty(NomType) 140 [j1,j2]=get_value(r.end_string); 141 i1=str2double(r.num1); 142 NomType=[get_type(r.num1) NomType]; 143 r=regexp(RootPath,'\<(?<newrootpath>.+)(\\|/)(?<subdir>[^\\^/]+)(\\|/)*\>','names'); 144 if ~isempty(r) 145 SubDir=r.subdir; 146 RootPath=r.newrootpath; 147 end 148 end 149 end 150 151 %% suppress '_' at the end of RootFile, put it on NomType 152 if strcmp(RootFile(end),'_') 153 RootFile(end)=[]; 154 NomType=['_' NomType]; 155 end 156 157 % if ~isempty(regexp(NomType,'-|ab|AB')) 158 % r=regexp(RootPath,'\<(?<newrootpath>.+)(\\|/)(?<subdir>[^\\^/]+)(\\|/)*\>','names'); 159 % if ~isempty(r) 160 % SubDir=r.subdir; 161 % RootPath=r.newrootpath; 162 % end 163 % end 179 164 180 165 … … 184 169 % returns the type of a label string: 185 170 % for numbers, whether filled with 0 or not. 186 % for letters, either a, A or ab, AB. 187 188 switch s 189 case {'a','b'} 190 type='a'; 191 case {'A','B'} 192 type='A'; 193 case 'ab' 194 type='ab'; 195 case 'AB' 196 type='AB'; 197 otherwise 198 if ~isempty(regexp(s,'\<\d+\>','ONCE')) 199 % switch s(1) 200 % case '0' 201 type=num2str(1,['%0' num2str(length(s)) 'd']); 202 % otherwise 203 % type='1'; 204 % end 205 else 206 type=''; 207 return 208 end 209 end 171 type='';%default 172 173 if ~isempty(regexp(s,'\<\d+\>','ONCE')) 174 type=num2str(1,['%0' num2str(length(s)) 'd']); 175 else 176 code=double(s); % ascii code of the input string 177 if code >= 65 & code <= 90 % test on ascii code for capital letters 178 if length(s)==1 179 type='A'; 180 elseif length(s)==2 181 type='AB'; 182 end 183 elseif code >= 97 & code <= 122 % test on ascii code for small letters 184 if length(s)==1 185 type='a'; 186 elseif length(s)==2 187 type='ab'; 188 end 189 end 190 end 191 210 192 211 193 212 194 function [j1,j2]=get_value(s) 213 % returns the type of a label string:195 % returns the value of a label string: 214 196 % for numbers, whether filled with 0 or not. 215 197 % for letters, either a, A or ab, AB. 216 198 j1=[]; 217 199 j2=[]; 218 219 switch lower(s) 220 case {'a'} 221 j1=1; 222 case {'b','B'} 223 j1=2; 224 case 'ab' 225 j1=1;j2=2; 226 otherwise 227 return 228 end 229 200 code=double(s); % ascii code of the input string 201 if code >= 65 & code <= 90 % test on ascii code for capital letters 202 index=double(s)-64; %change capital letters to corresponding number in the alphabet 203 elseif code >= 97 & code <= 122 % test on ascii code for small letters 204 index=double(s)-96; %change small letters to corresponding number in the alphabet 205 else 206 index=str2num(s); 207 end 208 if ~isempty(index) 209 j1=index(1); 210 if length(index)==2 211 j2=index(2); 212 end 213 end 230 214 231 215 … … 256 240 'Image_5_3-4.jpg'... 257 241 'Image_3_ab.jpg'... 258 'Image005A B.jpg'...259 'Image_3_a b.jpg'...242 'Image005AD.jpg'... 243 'Image_3_ac.jpg'... 260 244 'Image_3a-b.jpg'... 261 245 'Image3_a.jpg'... … … 265 249 266 250 for FileName=FileName_list 267 % [RootPath,RootFile,i1,i2,str_a,str_b, Ext,NomType,SubDir]=name2display(FileName{1});268 [~, RootFile,i1,i2,j1,j2,~,NomType,SubDir]=...251 % [RootPath,RootFile,i1,i2,str_a,str_b,FileExt,NomType,SubDir]=name2display(FileName{1}); 252 [~,SubDir,RootFile,i1,i2,j1,j2,~,NomType]=... 269 253 fileparts_uvmat(FileName{1}); 270 254 fprintf([...
Note: See TracChangeset
for help on using the changeset viewer.