Changeset 343 for trunk/src/civ_3D.m
- Timestamp:
- Dec 21, 2011, 10:12:13 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/civ_3D.m
r147 r343 3086 3086 % str2double(get(hObject,'String')) returns contents of npx as a double 3087 3087 3088 3089 3090 3088 %TODO: replace name2display by fileparts_uvmat: 3089 3090 3091 %'name2display': extracts the root name and field numbers from an input filename 3092 %-------------------------------------------------------------------- 3093 %[RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput) 3094 % 3095 %OUTPUT: 3096 %filebasesub: filename without appendix 3097 %field_count: string for the first number i 3098 %str2: string for the second number i (only for .nc files) 3099 %str_a: string for the first number j 3100 %str_b:string for the second number j (only for .nc files) 3101 %ext: file extension 3102 %nom_type: char chain characterizing the file nomenclature: with values 3103 % nom_type='': constant name [filebase ext] (default output if 'nom_type' is undefined) 3104 % nom_type='*':constant name for a file representing a series (e.g. avi movie) 3105 % nom_type='1','01',or '001'...': series of files with a single index i without separator(e.g. 'aa045.png'). 3106 % nom_type='_1','_01','_001'...': series of files with a single index i with separator '_'(e.g. 'aa_045.png'). 3107 % nom_type='1a','1A','01a','01A',... with a numerical index and an index letter(e.g.'aa45b.png') (lower or upper case) 3108 % nom_type='_1a','_1A','_01a','_01A',...: idem, with a separator '_' before the index 3109 % nom_type='_1_1','_01_1',...: matrix of files with two indices i and j separated by '_'(e.g. 'aa_45_2.png') 3110 % nom_type='_1-2': from pairs from a single index (e.g. 'aa_45-47.nc') 3111 % nom_type='_1_1-2': pairs of j indices (e.g. 'aa_45_2-3.nc') 3112 % nom_type='_1-2_j': pairs of i indices (e.g. 'aa_45-46_2.nc') 3113 % nom_type='_1_ab','1_ab','01_ab'..., from pairs of '#' images (e.g.'aa045bc.nc'), ext='.nc' 3114 %subdir: name of the subdirectory for netcdf files 3115 % 3116 %INPUT: 3117 %fileinput: complete name of the file, including path 3118 3119 function [RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput) 3120 % siz=length(fileinput); 3121 % indcur=siz; 3122 % default values: 3123 % test_=0; 3124 field_count='';%character string 3125 str2=''; 3126 str_a=''; 3127 str_b=''; 3128 % ext=''; 3129 nom_type=''; 3130 subdir=''; 3131 %select file extension 3132 [RootPath,RootFile,ext]=fileparts(fileinput); 3133 indcur=length(RootFile);% nbre of characters in fileraw 3134 3135 %recognize the name form 3136 % filerawascii=double(RootFile);%ascci code 3137 % val=(48>filerawascii)|(filerawascii>57); % test for the non-numerical characters 3138 indsel=regexp(RootFile,'\D');% character indices of non numerical characters 3139 filelit=RootFile(indsel);% fileraw name with numbers removed 3140 nbchar=length(indsel); 3141 if nbchar<4% put '*' before the name (remove at the end) 3142 prefilelit(1:4-nbchar)='*';%insert 3_nbchar '*' in the file name 3143 filelit=[prefilelit filelit]; 3144 indsel=[1:4-nbchar indsel+4-nbchar]; 3145 RootFile=[prefilelit RootFile]; 3146 indcur=indcur+4-nbchar; 3147 end 3148 separ3=indsel(end);% index of last non numerical character in fileraw 3149 separ2=indsel(end-1);% index of previous non numerical character 3150 separ1=indsel(end-2); 3151 separ0=indsel(end-3); 3152 num1='';num2='';num3=''; 3153 if separ1>=separ0+1,num0=RootFile(separ0+1:separ1-1);end 3154 if separ2>=separ1+1,num1=RootFile(separ1+1:separ2-1);end 3155 if separ3>=separ2+1,num2=RootFile(separ2+1:separ3-1);end 3156 if indcur>=separ3+1,num3=RootFile(separ3+1:indcur);end 3157 last_str=RootFile(indcur);%last character in fileraw 3158 last=double(last_str);%corresponding ascii code 3159 penult=double(RootFile(indcur-1));%ascii code of the penultimate character 3160 testsub=0; %default 3161 % % case of an indexed series in a single file 3162 % if strcmpi(ext,'.avi') 3163 % nom_type='*'; 3164 % %case of a numerical index follewed by a lower case letter (e.g. a,b,c): 3165 % %the penultimate character is a number and the last one a letter (lower case: last >= 97 && last <= 122 3166 % % capital 3167 % % letter: last >= 65 && last <= 90) 3168 if penult >= 48 && penult <= 57 && ((last >= 65 && last <= 90)||(last >= 97 && last <= 122)) 3169 str_a=last_str; %extract appendix a,b,c... or A,B,C... as output. 3170 ind_end=indcur-1; %current index just before the suffix letter 3171 indices_root=regexp(RootFile(1:indcur-1),'\D');%detect non digit characters 3172 indcur=max(indices_root); 3173 field_count=RootFile(indcur+1:ind_end); 3174 charstring=['%0' num2str(length(field_count)) 'd']; 3175 nom_type=num2str(1,charstring); 3176 if strcmp(RootFile(indcur),'_') 3177 nom_type=['_' nom_type]; 3178 indcur=indcur-1; 3179 end 3180 if (last >= 65 && last <= 90) 3181 nom_type=[nom_type 'A']; 3182 else 3183 nom_type=[nom_type 'a']; 3184 end 3185 elseif strcmp(filelit(end-2:end),'-_-_')%new nomenclature appendix num1-num2_num_a-num_b 3186 field_count=num0; 3187 str2=num1; 3188 str_a=num2; 3189 str_b=num3; 3190 nom_type='_1-2_1-2'; 3191 testsub=1; 3192 indcur=separ0-1; 3193 elseif strcmp(filelit(end-2:end),'_-_')%new nomenclature appendix num1-num2_num_a 3194 field_count=num1; 3195 str2=num2; 3196 str_a=num3; 3197 nom_type='_1-2_1'; 3198 testsub=1; 3199 indcur=separ1-1; 3200 elseif strcmp(filelit(end-2:end),'__-')%new nomenclature appendix num1_num2-num2 3201 indcur=separ1-1; 3202 field_count=num1; 3203 str_a=num2; 3204 str_b=num3; 3205 nom_type='_1_1-2'; 3206 testsub=1; 3207 elseif strcmp(filelit(end-1:end),'_-') 3208 indcur=separ2-1; 3209 field_count=num2; 3210 str2=num3; 3211 str_a=''; 3212 nom_type='_1-2'; 3213 testsub=1; 3214 elseif strcmp(filelit(end-1:end),'__') 3215 indcur=separ2-1; 3216 field_count=num2; 3217 str2=''; 3218 str_a=num3; 3219 nom_type='_1_1'; 3220 elseif strcmp(filelit(end),'_') 3221 indcur=separ3-1; 3222 str2=''; 3223 str_a=''; 3224 %detect zeros before the number 3225 field_count=RootFile(separ3+1:end);% set the selected field number'%03d' 3226 charstring=['%0' num2str(length(field_count)) 'd']; 3227 nom_type=['_' num2str(1,charstring)]; 3228 elseif RootFile(indcur-2)=='_'% search appendix a,b,c,d 3229 lasts=RootFile(indcur-1:indcur); 3230 % if isequal(length(last),2) 3231 str_a=lasts(1);%put appendix a,b,c, ou d 3232 str_b=lasts(2);%put appendix a,b,c, ou d 3233 separ0=indsel(end-3); 3234 field_count=RootFile(separ0+1:separ1-1); 3235 indcur=separ0; 3236 if double(lasts) >= 97 & double(lasts)<= 122 3237 nom_type='_ab'; 3238 testsub=1; 3239 elseif double(lasts) >= 65 & double(lasts) <= 90 3240 nom_type='_AB'; 3241 testsub=1; 3242 end 3243 charstring=['%0' num2str(length(field_count)) 'd']; 3244 nom_type=[num2str(1,charstring) nom_type]; 3245 % end 3246 %search for other names with counter 3247 else 3248 if length(ext)>1 3249 num=1;count=0; % extract the numerical appendix 3250 while num==1; 3251 filascii=double(RootFile(indcur)); 3252 if (48>filascii)||(filascii>57); % select the non-numerical characters 3253 num=0; 3254 else 3255 indcur=indcur-1; count=count+1; 3256 end 3257 end 3258 if count~=0 3259 field_count=RootFile(indcur+1:indcur+count);% set the selected field number'%03d' 3260 charstring=['%0' num2str(length(field_count)) 'd']; 3261 nom_type=num2str(1,charstring); 3262 end 3263 end 3264 end 3265 %select the root name in the file_input window 3266 RootFile=RootFile(1:indcur); 3267 if nbchar<4% put '*' before the name (remove at the end) 3268 RootFile(1:4-nbchar)=[]; 3269 end 3270 if testsub 3271 [RootPath,subdir,extdir]=fileparts(RootPath); 3272 subdir=[subdir extdir]; 3273 end 3274
Note: See TracChangeset
for help on using the changeset viewer.