source: trunk/src/name2display.m @ 140

Last change on this file since 140 was 138, checked in by sommeria, 13 years ago

bug repair for name generation in case of constant name (no indexing)

File size: 7.3 KB
Line 
1%'name2display': extracts the root name and field numbers from an input filename
2%--------------------------------------------------------------------
3%[RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput)
4%
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='_i1-i2': from pairs from a single index (e.g. 'aa_45-47.nc')
21%   nom_type='_i_j1-j2': pairs of j indices (e.g. 'aa_45_2-3.nc')
22%   nom_type='_i1-i2_j': pairs of i indices (e.g. 'aa_45-46_2.nc')
23%   nom_type='_1_ab','1_ab','01_ab'..., from pairs of '#' images (e.g.'aa045bc.nc'), ext='.nc'
24%subdir: name of the subdirectory for netcdf files
25%
26%INPUT:
27%fileinput: complete name of the file, including path
28
29function [RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput)
30% siz=length(fileinput);
31% indcur=siz;
32% default values:
33% test_=0;
34field_count='';%character string
35str2='';
36str_a='';
37str_b='';
38% ext='';
39nom_type='';
40subdir='';
41        %select file extension
42[RootPath,RootFile,ext]=fileparts(fileinput);
43indcur=length(RootFile);% nbre of characters in fileraw
44
45        %recognize the name form
46% filerawascii=double(RootFile);%ascci code
47% val=(48>filerawascii)|(filerawascii>57); % test for the non-numerical characters
48indsel=regexp(RootFile,'\D');% character indices of non numerical characters
49filelit=RootFile(indsel);% fileraw name with numbers removed
50nbchar=length(indsel);
51if nbchar<4% put '*' before the name (remove at the end)
52   prefilelit(1:4-nbchar)='*';%insert 3_nbchar '*' in the file name
53   filelit=[prefilelit filelit];
54   indsel=[1:4-nbchar indsel+4-nbchar];
55   RootFile=[prefilelit RootFile];
56   indcur=indcur+4-nbchar;
57end
58separ3=indsel(end);% index of last non numerical character in fileraw
59separ2=indsel(end-1);% index of previous non numerical character
60separ1=indsel(end-2);
61separ0=indsel(end-3);
62num1='';num2='';num3='';
63if separ1>=separ0+1,num0=RootFile(separ0+1:separ1-1);end
64if separ2>=separ1+1,num1=RootFile(separ1+1:separ2-1);end
65if separ3>=separ2+1,num2=RootFile(separ2+1:separ3-1);end
66if indcur>=separ3+1,num3=RootFile(separ3+1:indcur);end
67last_str=RootFile(indcur);%last character in fileraw
68last=double(last_str);%corresponding ascii code
69penult=double(RootFile(indcur-1));%ascii code of the penultimate character
70testsub=0; %default
71% case of an indexed series in a single file
72if strcmpi(ext,'.avi')
73     nom_type='*';
74%case of a numerical index follewed by a lower case letter (e.g. a,b,c):
75%the penultimate character is a number and the last one a letter (lower case: last >= 97 && last <= 122
76%                                                                 capital
77%                                                                 letter:  last >= 65 && last <= 90) 
78elseif  penult >= 48 && penult <= 57 && ((last >= 65 && last <= 90)||(last >= 97 && last <= 122))
79    str_a=last_str; %extract appendix a,b,c... or A,B,C... as output.
80    ind_end=indcur-1; %current index just before the suffix letter
81    indices_root=regexp(RootFile(1:indcur-1),'\D');%detect non digit characters
82    indcur=max(indices_root);
83    field_count=RootFile(indcur+1:ind_end);
84    charstring=['%0' num2str(length(field_count)) 'd'];
85    nom_type=num2str(1,charstring);
86    if strcmp(RootFile(indcur),'_')
87       nom_type=['_' nom_type];
88       indcur=indcur-1;
89    end
90    if (last >= 65 && last <= 90)
91        nom_type=[nom_type 'A'];
92    else
93        nom_type=[nom_type 'a'];
94    end   
95elseif strcmp(filelit(end-2:end),'-_-_')%new  nomenclature appendix num1-num2_num_a-num_b
96    field_count=num0;
97    str2=num1;
98    str_a=num2;
99    str_b=num3;
100    nom_type='_i1-i2_j1-j2';
101    testsub=1;
102    indcur=separ0-1;
103elseif strcmp(filelit(end-2:end),'_-_')%new  nomenclature appendix num1-num2_num_a
104    field_count=num1;
105    str2=num2;
106    str_a=num3;
107    nom_type='_i1-i2_j';
108    testsub=1;
109    indcur=separ1-1;
110elseif strcmp(filelit(end-2:end),'__-')%new  nomenclature appendix num1_num2-num2
111    indcur=separ1-1;
112    field_count=num1;
113    str_a=num2;
114    str_b=num3;
115    nom_type='_i_j1-j2';
116    testsub=1;
117elseif strcmp(filelit(end-1:end),'_-')
118    indcur=separ2-1;
119    field_count=num2;
120    str2=num3;
121    str_a='';
122    nom_type='_i1-i2';
123    testsub=1;
124elseif strcmp(filelit(end-1:end),'__')
125    indcur=separ2-1;
126    field_count=num2;
127    str2='';
128    str_a=num3;
129    nom_type='_1_1';
130elseif strcmp(filelit(end),'_')
131    indcur=separ3-1;
132    str2='';
133    str_a='';
134    %detect zeros before the number
135    field_count=RootFile(separ3+1:end);% set the selected field number'%03d'
136    charstring=['%0' num2str(length(field_count)) 'd'];
137    nom_type=['_' num2str(1,charstring)];
138elseif RootFile(indcur-2)=='_'% search appendix a,b,c,d
139    lasts=RootFile(indcur-1:indcur);
140%     if isequal(length(last),2)
141        str_a=lasts(1);%put appendix a,b,c, ou d
142        str_b=lasts(2);%put appendix a,b,c, ou d
143        separ0=indsel(end-3);
144        field_count=RootFile(separ0+1:separ1-1);
145        indcur=separ0;
146        if double(lasts) >= 97 & double(lasts)<= 122
147            nom_type='_ab';
148            testsub=1;
149        elseif double(lasts) >= 65 & double(lasts) <= 90
150            nom_type='_AB';
151            testsub=1;
152        end
153        charstring=['%0' num2str(length(field_count)) 'd'];
154        nom_type=[num2str(1,charstring) nom_type];
155%     end
156%search for other names with counter
157else
158    if length(ext)>1     
159            num=1;count=0; % extract the numerical appendix
160            while num==1;
161                filascii=double(RootFile(indcur));
162                if (48>filascii)||(filascii>57); % select the non-numerical characters
163                    num=0;
164                else
165                    indcur=indcur-1; count=count+1;
166                end
167            end
168            if count~=0   
169                field_count=RootFile(indcur+1:indcur+count);% set the selected field number'%03d'
170                charstring=['%0' num2str(length(field_count)) 'd'];
171                nom_type=num2str(1,charstring);
172            end
173    end
174end
175            %select the root name in the file_input window
176RootFile=RootFile(1:indcur);
177if nbchar<4% put '*' before the name (remove at the end)
178   RootFile(1:4-nbchar)=[];
179end
180if testsub
181    [RootPath,subdir,extdir]=fileparts(RootPath);
182    subdir=[subdir extdir];
183end
Note: See TracBrowser for help on using the repository browser.