source: trunk/src/name2display.m @ 136

Last change on this file since 136 was 122, checked in by sommeria, 14 years ago
File size: 7.9 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 letter:  last >= 65 && last <= 90)                                                             
77elseif  penult >= 48 && penult <= 57 && (last >= 65 && last <= 90)||(last >= 97 && last <= 122)
78    str_a=last_str; %extract appendix a,b,c... or A,B,C... as output.
79    ind_end=indcur-1; %current index just before the suffix letter
80    indices_root=regexp(RootFile(1:indcur-1),'\D');%detect non digit characters
81    indcur=max(indices_root);
82    field_count=RootFile(indcur+1:ind_end);
83    charstring=['%0' num2str(length(field_count)) 'd'];
84    nom_type=num2str(1,charstring);
85    if strcmp(RootFile(indcur),'_')
86       nom_type=['_' nom_type];
87       indcur=indcur-1;
88    end
89    if (last >= 65 && last <= 90)
90        nom_type=[nom_type 'A'];
91    else
92        nom_type=[nom_type 'a'];
93    end   
94elseif strcmp(filelit(end-2:end),'-_-_')%new  nomenclature appendix num1-num2_num_a-num_b
95    field_count=num0;
96    str2=num1;
97    str_a=num2;
98    str_b=num3;
99    nom_type='_i1-i2_j1-j2';
100    testsub=1;
101    indcur=separ0-1;
102elseif strcmp(filelit(end-2:end),'_-_')%new  nomenclature appendix num1-num2_num_a
103    field_count=num1;
104    str2=num2;
105    str_a=num3;
106    nom_type='_i1-i2_j';
107    testsub=1;
108    indcur=separ1-1;
109elseif strcmp(filelit(end-2:end),'__-')%new  nomenclature appendix num1_num2-num2
110    indcur=separ1-1;
111    field_count=num1;
112    str_a=num2;
113    str_b=num3;
114    nom_type='_i_j1-j2';
115    testsub=1;
116elseif strcmp(filelit(end-1:end),'_-')
117    indcur=separ2-1;
118    field_count=num2;
119    str2=num3;
120    str_a='';
121    nom_type='_i1-i2';
122    testsub=1;
123elseif strcmp(filelit(end-1:end),'__')
124    indcur=separ2-1;
125    field_count=num2;
126    str2='';
127    str_a=num3;
128    nom_type='_1_1';
129elseif strcmp(filelit(end),'_')
130    indcur=separ3-1;
131%     field_count=num3;
132    str2='';
133    str_a='';
134    %detect zeros before the number
135%     count=0; % extract the numerical appendix
136    field_count=RootFile(separ3+1:end);% set the selected field number'%03d'
137    charstring=['%0' num2str(length(field_count)) 'd'];
138    nom_type=['_' num2str(1,charstring)];
139%     if strcmp('0',RootFile(separ3+1)); % select the non-numerical characters
140%         nom_type=['_%0' num2str(length(RootFile(separ3+1:end))) 'd'];
141%     else
142%         nom_type='_i';
143%     end 
144     
145elseif RootFile(indcur-2)=='_'% search appendix a,b,c,d
146    last=RootFile(indcur-1:indcur);
147    if isequal(length(last),2)
148          str_a=last(1);%put appendix a,b,c, ou d
149          str_b=last(2);%put appendix a,b,c, ou d
150%           indcur=indcur-3;
151          separ0=indsel(end-3);
152        field_count=RootFile(separ0+1:separ1-1);
153        indcur=separ0;
154        if double(last) >= 97 & double(last)<= 122
155            nom_type='_ab';
156            testsub=1;
157        elseif double(last) >= 65 & double(last) <= 90
158            nom_type='_AB';
159            testsub=1;
160        end
161        charstring=['%0' num2str(length(field_count)) 'd'];
162        nom_type=[num2str(1,charstring) nom_type];
163    end
164%search for other names with counter
165else
166    if length(ext)>1     
167            num=1;count=0; % extract the numerical appendix
168            while num==1;
169                filascii=double(RootFile(indcur));
170                if (48>filascii)||(filascii>57); % select the non-numerical characters
171                    num=0;
172                else
173                    indcur=indcur-1; count=count+1;
174                end
175            end
176            if count~=0   
177                field_count=RootFile(indcur+1:indcur+count);% set the selected field number'%03d'
178                charstring=['%0' num2str(length(field_count)) 'd'];
179                nom_type=num2str(1,charstring);
180%                 if isequal(field_count(1),'0')
181%                     nbfigures=length(field_count);
182%                     nom_type=['%0' num2str(nbfigures) 'd'];
183%                 else
184%                     nom_type='#';
185%                 end
186            end
187    end
188end
189            %select the root name in the file_input window
190RootFile=RootFile(1:indcur);
191if nbchar<4% put '*' before the name (remove at the end)
192   RootFile(1:4-nbchar)=[];
193end
194if testsub
195    [RootPath,subdir,extdir]=fileparts(RootPath);
196    subdir=[subdir extdir];
197end
Note: See TracBrowser for help on using the repository browser.