- Timestamp:
- Dec 8, 2011, 4:32:31 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/fileparts_uvmat.m
r318 r327 1 %' name2display': extracts the root name and field numbers from an input filename1 %'fileparts_uvmat': Splits a file name and recognize file naming convention 2 2 %-------------------------------------------------------------------- 3 %[RootPath, RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput)3 %[RootPath,SubDir,RootFile,i1,i2,j1,j2,Ext,NomType]=fileparts_uvmat(FileInput) 4 4 % 5 5 %OUTPUT: 6 %filebasesub: filename without appendix 7 %field_count: string for the first number i 8 %str2: string for the second number i (only for .nc files) 9 %str_a: string for the first number j 10 %str_b:string for the second number j (only for .nc files) 11 %ext: file extension 12 %nom_type: char chain characterizing the file nomenclature: with values 13 % nom_type='': constant name [filebase ext] (default output if 'nom_type' is undefined) 14 % nom_type='*':constant name for a file representing a series (e.g. avi movie) 15 % nom_type='1','01',or '001'...': series of files with a single index i without separator(e.g. 'aa045.png'). 16 % nom_type='_1','_01','_001'...': series of files with a single index i with separator '_'(e.g. 'aa_045.png'). 17 % nom_type='1a','1A','01a','01A',... with a numerical index and an index letter(e.g.'aa45b.png') (lower or upper case) 18 % nom_type='_1a','_1A','_01a','_01A',...: idem, with a separator '_' before the index 19 % nom_type='_1_1','_01_1',...: matrix of files with two indices i and j separated by '_'(e.g. 'aa_45_2.png') 20 % nom_type='1_1','01_1',...: matrix of files with two indices i and j separated by '_'(e.g. 'aa45_2.png') 21 % nom_type='_i1-i2': from pairs from a single index (e.g. 'aa_45-47.nc') 22 % nom_type='_i_j1-j2': pairs of j indices (e.g. 'aa_45_2-3.nc') 23 % nom_type='_i1-i2_j': pairs of i indices (e.g. 'aa_45-46_2.nc') 24 % nom_type='_1_ab','1_ab','01_ab'..., from pairs of '#' images (e.g.'aa045bc.nc'), ext='.nc' 25 %subdir: name of the subdirectory for netcdf files 6 %RootFile: FileName without appendix 7 %i1: first number i 8 %i2: second number i (only for .nc files) 9 %j1: first number j 10 %j2: second number j (only for .nc files) 11 %Ext: file Extension 12 %NomType: char chain characterizing the file nomenclature: with values 13 % NomType='': constant name [filebase Ext] (default output if 'NomType' is undefined) 14 % NomType='*':constant name for a file representing a series (e.g. avi movie) 15 % NomType='1','01',or '001'...': series of files with a single index i without separator(e.g. 'aa045.png'). 16 % NomType='1a','1A','01a','01A','1_a','01_A',... with a numerical index and an index letter(e.g.'aa45b.png') (lower or upper case) 17 % NomType='1_1','01_1',...: matrix of files with two indices i and j separated by '_'(e.g. 'aa45_2.png') 18 % 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' 22 %SubDir: name of the SubDirectory for netcdf files 23 24 % OLD TYPES, not supported anymore 25 % 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 index 27 % 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 26 33 % 27 34 %INPUT: 28 %fileinput: complete name of the file, including path 29 30 function [RootPath,RootFile,i1,i2,j1,j2,ext,nom_type,subdir]=name2display2(fileinput) 31 % siz=length(fileinput); 32 % indcur=siz; 33 % default values: 34 % test_=0; 35 i1=[];%character string 35 %FileInput: complete name of the file, including path 36 37 function [RootPath,SubDir,RootFile,i1,i2,j1,j2,Ext,NomType]=fileparts_uvmat(FileInput) 38 39 i1=[]; 36 40 i2=[]; 37 41 j1=[]; 38 42 j2=[]; 39 nom_type='';40 subdir='';43 NomType=''; 44 SubDir=''; 41 45 RootFile=''; 42 46 43 %select file extension 44 [RootPath,filename,ext]=fileparts(fileinput); 47 if ~exist('FileInput','var') 48 help fileparts_uvmat; 49 test(); 50 return 51 end 52 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 45 69 46 70 % \D not a digit … … 48 72 49 73 50 %% recursive test on filename stqrting from the end51 52 % test whether filename ends with a number or not53 r=regexp( filename,'.*\D(?<num1>\d+)\>','names');54 55 if ~isempty(r)% filename end matches num174 %% recursive test on FileName stqrting from the end 75 76 % test whether FileName ends with a number or not 77 r=regexp(FileName,'.*\D(?<num1>\d+)\>','names'); 78 79 if ~isempty(r)% FileName end matches num1 56 80 num1=r.num1; 57 r=regexp( filename,['.*\D(?<num2>\d+)(?<delim1>[-_])' num1 '\>'],'names');58 if ~isempty(r)% filename end matches num2+delim1+num181 r=regexp(FileName,['.*\D(?<num2>\d+)(?<delim1>[-_])' num1 '\>'],'names'); 82 if ~isempty(r)% FileName end matches num2+delim1+num1 59 83 delim1=r.delim1; 60 84 num2=r.num2; 61 r=regexp( filename,['.*\D(?<num3>\d+)(?<delim2>[-_])' num2 delim1 num1 '\>'],'names');62 if ~isempty(r) % filename end matches delim2 num2 delim1 num185 r=regexp(FileName,['.*\D(?<num3>\d+)(?<delim2>[-_])' num2 delim1 num1 '\>'],'names'); 86 if ~isempty(r) % FileName end matches delim2 num2 delim1 num1 63 87 delim2=r.delim2; 64 88 num3=r.num3; 65 89 switch delim1 66 90 case '_' 67 j1=str2 num(num1);91 j1=str2double(num1); 68 92 switch delim2 69 93 case '-' 70 i1=str2 num(num3);71 i2=str2 num(num2);94 i1=str2double(num3); 95 i2=str2double(num2); 72 96 end 73 97 case '-' 74 j1=str2 num(num2);75 j2=str2 num(num1);98 j1=str2double(num2); 99 j2=str2double(num1); 76 100 switch delim2 77 101 case '_' 78 i1=str2 num(num3);102 i1=str2double(num3); 79 103 end 80 104 end 81 nom_type=[get_type(num3) delim2 get_type(num2) delim1 get_type(num1)];82 RootFile=regexprep( filename,[num3 delim2 num2 delim1 num1],'');105 NomType=[get_type(num3) delim2 get_type(num2) delim1 get_type(num1)]; 106 RootFile=regexprep(FileName,[num3 delim2 num2 delim1 num1],''); 83 107 else 84 108 switch delim1 85 109 case '_' 86 i1=str2 num(num2);87 j1=str2 num(num1);110 i1=str2double(num2); 111 j1=str2double(num1); 88 112 case '-' 89 i1=str2 num(num2);90 i2=str2 num(num1);91 end 92 nom_type=[get_type(num2) delim1 get_type(num1)];93 RootFile=regexprep( filename,[num2 delim1 num1],'');113 i1=str2double(num2); 114 i2=str2double(num1); 115 end 116 NomType=[get_type(num2) delim1 get_type(num1)]; 117 RootFile=regexprep(FileName,[num2 delim1 num1],''); 94 118 end 95 119 else% only one number at the end 96 i1=str2 num(num1);97 nom_type=get_type(num1);98 RootFile=regexprep( filename,num1,'');120 i1=str2double(num1); 121 NomType=get_type(num1); 122 RootFile=regexprep(FileName,num1,''); 99 123 end 100 else% filename ends with a letter101 r=regexp( filename,'.*[^a^b^A^B](?<end_string>ab|AB|[abAB])\>','names');124 else% FileName ends with a letter 125 r=regexp(FileName,'.*[^a^b^A^B](?<end_string>ab|AB|[abAB])\>','names'); 102 126 if ~isempty(r) 103 127 end_string=r.end_string; 104 r=regexp( filename,['.+(?<delim1>[_-])' end_string '\>'],'names');128 r=regexp(FileName,['.+(?<delim1>[_-])' end_string '\>'],'names'); 105 129 if ~isempty(r) 106 130 delim1=r.delim1; 107 r=regexp( filename,['.*\D(?<num1>\d+)' delim1 end_string '\>'],'names');131 r=regexp(FileName,['.*\D(?<num1>\d+)' delim1 end_string '\>'],'names'); 108 132 if ~isempty(r) 109 133 num1=r.num1; 110 nom_type=[get_type(num1) delim1 get_type(end_string)];111 i1=str2 num(num1);134 NomType=[get_type(num1) delim1 get_type(end_string)]; 135 i1=str2double(num1); 112 136 [j1,j2]=get_value(end_string); 113 RootFile=regexprep( filename,[num1 delim1 end_string],'');137 RootFile=regexprep(FileName,[num1 delim1 end_string],''); 114 138 115 139 else 116 nom_type=get_type(end_string);140 NomType=get_type(end_string); 117 141 [j1,j2]=get_value(end_string); 118 RootFile=regexprep( filename,[end_string],'');142 RootFile=regexprep(FileName,end_string,''); 119 143 120 144 end 121 145 else 122 r=regexp( filename,['.*\D(?<num1>\d+)' end_string '\>'],'names');146 r=regexp(FileName,['.*\D(?<num1>\d+)' end_string '\>'],'names'); 123 147 if ~isempty(r) 124 148 num1=r.num1; 125 % r=regexp( filename,['.+(?<delim1>[-_])' num1 end_string '\>'],'names');149 % r=regexp(FileName,['.+(?<delim1>[-_])' num1 end_string '\>'],'names'); 126 150 % if ~isempty(r) 127 151 % delim1=r.delim1; 128 152 % i1=num1; 129 153 % str_a=end_string; 130 % nom_type=[delim1 get_type(num1) get_type(end_string)];131 % RootFile=regexprep( filename,[delim1 num1 end_string],'');154 % NomType=[delim1 get_type(num1) get_type(end_string)]; 155 % RootFile=regexprep(FileName,[delim1 num1 end_string],''); 132 156 % else 133 i1=str2 num(num1);157 i1=str2double(num1); 134 158 [j1,j2]=get_value(end_string); 135 nom_type=[get_type(num1) get_type(end_string)];136 RootFile=regexprep( filename,[num1 end_string],'');159 NomType=[get_type(num1) get_type(end_string)]; 160 RootFile=regexprep(FileName,[num1 end_string],''); 137 161 % end 138 162 else … … 167 191 otherwise 168 192 if ~isempty(regexp(s,'\<\d+\>','ONCE')) 169 switch s(1)170 case '0'193 % switch s(1) 194 % case '0' 171 195 type=num2str(1,['%0' num2str(length(s)) 'd']); 172 otherwise173 type='1';174 end196 % otherwise 197 % type='1'; 198 % end 175 199 else 176 200 type=''; … … 199 223 200 224 225 226 function test(name) 227 fprintf([... 228 '######################################################\n'... 229 ' Test for fileparts_uvmat \n'... 230 '######################################################\n'... 231 ]); 232 233 if exist('name','var') 234 FileName_list={name}; 235 else 236 FileName_list={... 237 'Image1a.png'... 238 'toto'... 239 'B011_1.png'... 240 'B001.png'... 241 'B55a.tif'... 242 'B002B.tiff'... 243 'B_001.png'... 244 'B_3331AB.png'... 245 'aa45_2.png'... 246 'B005.png'... 247 'Image_3.jpg'... 248 'Image_3-4.jpg'... 249 'Image_3-4_2.jpg'... 250 'Image_5_3-4.jpg'... 251 'Image_3_ab.jpg'... 252 'Image005AB.jpg'... 253 'Image_3_ab.jpg'... 254 'Image_3a-b.jpg'... 255 'Image3_a.jpg'... 256 'movie57.avi'... 257 }; 258 end 259 260 for FileName=FileName_list 261 % [RootPath,RootFile,i1,i2,str_a,str_b,Ext,NomType,SubDir]=name2display(FileName{1}); 262 [~,RootFile_bis,i1_bis,i2_bis,j1_bis,j2_bis,~,NomType_bis,SubDir_bis]=... 263 fileparts_uvmat(FileName{1}); 264 fprintf([... 265 'File name : ' FileName{1} '\n'... 266 ' NomType : ' NomType_bis '\n'... 267 ' RootFile : ' RootFile_bis '\n'... 268 ' i1 / i2 : ' num2str(i1_bis) ' / ' num2str(i2_bis) '\n'... 269 ' j1 / j2 : ' num2str(j1_bis) ' / ' num2str(j2_bis) '\n'... 270 ]); 271 end 272 273
Note: See TracChangeset
for help on using the changeset viewer.