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='_i': series of files with a single index i preceded by '_'(e.g. 'aa_45.png').
|
---|
16 | % nom_type='#', series of indexed images wich is not series_i [filebase index ext], e.g. 'aa045.jpg' or 'aa45.tif'
|
---|
17 | % nom_type='_i_j': matrix of files with two indices i and j separated by '_'(e.g. 'aa_45_2.png')
|
---|
18 | % nom_type='_i1-i2': from pairs from a single index (e.g. 'aa_45-47.nc')
|
---|
19 | % nom_type='_i_j1-j2': pairs of j indices (e.g. 'aa_45_2-3.nc')
|
---|
20 | % nom_type='_i1-i2_j': pairs of i indices (e.g. 'aa_45-46_2.nc')
|
---|
21 | % nom_type='#a','#A", with a numerical index and an index letter(e.g.'aa045b.png') (lower or upper case)
|
---|
22 | % nom_type='raw_SMD', same as '#' but with no extension ext='', OBSOLETE
|
---|
23 | % nom_type='#_ab', from pairs of '#' images (e.g. 'aa045bc.nc'), ext='.nc', OBSOLETE (replaced by '_i_j1-j2')
|
---|
24 | %subdir: name of the subdirectory for netcdf files
|
---|
25 | %
|
---|
26 | %INPUT:
|
---|
27 | %fileinput: complete name of the file, including path
|
---|
28 |
|
---|
29 | function [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;
|
---|
34 | field_count='';%character string
|
---|
35 | str2='';
|
---|
36 | str_a='';
|
---|
37 | str_b='';
|
---|
38 | % ext='';
|
---|
39 | nom_type='';
|
---|
40 | subdir='';
|
---|
41 | %select file extension
|
---|
42 | [RootPath,RootFile,ext]=fileparts(fileinput);
|
---|
43 | indcur=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
|
---|
48 | indsel=find(val);% character indices of non numerical characters
|
---|
49 | filelit=RootFile(indsel);% fileraw name with numbers removed
|
---|
50 | nbchar=length(indsel);
|
---|
51 | if 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;
|
---|
57 | end
|
---|
58 | separ3=indsel(end);% index of last non numerical character in fileraw
|
---|
59 | separ2=indsel(end-1);% index of previous non numerical character
|
---|
60 | separ1=indsel(end-2);
|
---|
61 | separ0=indsel(end-3);
|
---|
62 | num1='';num2='';num3='';
|
---|
63 | if separ1>=separ0+1,num0=RootFile(separ0+1:separ1-1);end
|
---|
64 | if separ2>=separ1+1,num1=RootFile(separ1+1:separ2-1);end
|
---|
65 | if separ3>=separ2+1,num2=RootFile(separ2+1:separ3-1);end
|
---|
66 | if indcur>=separ3+1,num3=RootFile(separ3+1:indcur);end
|
---|
67 | last_str=RootFile(indcur);%last character in fileraw
|
---|
68 | last=double(last_str);%corresponding ascii code
|
---|
69 | penult=double(RootFile(indcur-1));%ascii code of the penultimate character
|
---|
70 | testsub=0; %default
|
---|
71 | if strcmpi(ext,'.avi')
|
---|
72 | nom_type='*';
|
---|
73 | %case of old image nomenclature
|
---|
74 | elseif (strcmp(ext,'.png') || strcmp(ext,'')) && penult >= 48 && penult <= 57 && (last < 48 || last > 57)
|
---|
75 | % if the penultimate character is a number and the last a letter
|
---|
76 | % search the appendix a,b,c,
|
---|
77 | str_a=last_str; %put appendix a,b,c....
|
---|
78 | indcur=indcur-1;
|
---|
79 | if strcmp(ext,'.png'), nom_type='#a'; end
|
---|
80 | if strcmp(ext,''), nom_type='raw_SMD'; end
|
---|
81 | num=1;count=0; % extract the numerical appendix
|
---|
82 | while num==1;
|
---|
83 | filascii=double(RootFile(indcur));
|
---|
84 | if (48>filascii)||(filascii>57); % select the non-numerical characters
|
---|
85 | num=0;
|
---|
86 | else
|
---|
87 | indcur=indcur-1; count=count+1;
|
---|
88 | end
|
---|
89 | end
|
---|
90 | if count~=0
|
---|
91 | field_count=RootFile(indcur+1:indcur+count);% set the selected field number
|
---|
92 | end
|
---|
93 | elseif penult >= 48 && penult <= 57 && (last <= 66 && last >= 65)% PCO camera Toulouse, end with A or B (NEW)
|
---|
94 | % if the penultimate character is a number and the last a letter
|
---|
95 | % search the appendix a,b,c,
|
---|
96 | str_a=last_str; %put appendix a,b,c....
|
---|
97 | indcur=indcur-1;
|
---|
98 | nom_type='#A';
|
---|
99 | num=1;count=0; % extract the numerical appendix
|
---|
100 | while num==1;
|
---|
101 | filascii=double(RootFile(indcur));
|
---|
102 | if (48>filascii)||(filascii>57); % select the non-numerical characters
|
---|
103 | num=0;
|
---|
104 | else
|
---|
105 | indcur=indcur-1; count=count+1;
|
---|
106 | end
|
---|
107 | end
|
---|
108 | if count~=0
|
---|
109 | field_count=RootFile(indcur+1:indcur+count);% set the selected field number
|
---|
110 | end
|
---|
111 | indcur=indcur-1;
|
---|
112 | elseif strcmp(filelit(end-2:end),'-_-_')%new nomenclature appendix num1-num2_num_a-num_b
|
---|
113 | field_count=num0;
|
---|
114 | str2=num1;
|
---|
115 | str_a=num2;
|
---|
116 | str_b=num3;
|
---|
117 | nom_type='_i1-i2_j1-j2';
|
---|
118 | testsub=1;
|
---|
119 | indcur=separ0-1;
|
---|
120 | elseif strcmp(filelit(end-2:end),'_-_')%new nomenclature appendix num1-num2_num_a
|
---|
121 | field_count=num1;
|
---|
122 | str2=num2;
|
---|
123 | str_a=num3;
|
---|
124 | nom_type='_i1-i2_j';
|
---|
125 | testsub=1;
|
---|
126 | indcur=separ1-1;
|
---|
127 | elseif strcmp(filelit(end-2:end),'__-')%new nomenclature appendix num1_num2-num2
|
---|
128 | indcur=separ1-1;
|
---|
129 | field_count=num1;
|
---|
130 | str_a=num2;
|
---|
131 | str_b=num3;
|
---|
132 | nom_type='_i_j1-j2';
|
---|
133 | testsub=1;
|
---|
134 | elseif strcmp(filelit(end-1:end),'_-')
|
---|
135 | indcur=separ2-1;
|
---|
136 | field_count=num2;
|
---|
137 | str2=num3;
|
---|
138 | str_a='';
|
---|
139 | nom_type='_i1-i2';
|
---|
140 | testsub=1;
|
---|
141 | elseif strcmp(filelit(end-1:end),'__')
|
---|
142 | indcur=separ2-1;
|
---|
143 | field_count=num2;
|
---|
144 | str2='';
|
---|
145 | str_a=num3;
|
---|
146 | nom_type='_i_j';
|
---|
147 | elseif strcmp(filelit(end),'_')
|
---|
148 | indcur=separ3-1;
|
---|
149 | % field_count=num3;
|
---|
150 | str2='';
|
---|
151 | str_a='';
|
---|
152 | %detect zeros before the number
|
---|
153 | % count=0; % extract the numerical appendix
|
---|
154 | if strcmp('0',RootFile(separ3+1)); % select the non-numerical characters
|
---|
155 | nom_type=['_%0' num2str(length(RootFile(separ3+1:end))) 'd'];
|
---|
156 | else
|
---|
157 | nom_type='_i';
|
---|
158 | end
|
---|
159 | field_count=RootFile(separ3+1:end);% set the selected field number'%03d'
|
---|
160 | elseif RootFile(indcur-2)=='_'% search appendix a,b,c,d
|
---|
161 | last=RootFile(indcur-1:indcur);
|
---|
162 | if isequal(length(last),2) && double(last(1)) >= 97 && double(last(1)) <= 122 ...% = 1 for letters
|
---|
163 | && double(last(2)) >= 97 && double(last(2)) <= 122
|
---|
164 | str_a=last(1);%put appendix a,b,c, ou d
|
---|
165 | str_b=last(2);%put appendix a,b,c, ou d
|
---|
166 | % indcur=indcur-3;
|
---|
167 | separ0=indsel(end-3);
|
---|
168 | num0=RootFile(separ0+1:separ1-1);
|
---|
169 | field_count=num0;
|
---|
170 | indcur=separ0;
|
---|
171 | nom_type='#_ab';
|
---|
172 | testsub=1;
|
---|
173 | end
|
---|
174 | %search for other names with counter
|
---|
175 | else
|
---|
176 | if length(ext)>1
|
---|
177 | num=1;count=0; % extract the numerical appendix
|
---|
178 | while num==1;
|
---|
179 | filascii=double(RootFile(indcur));
|
---|
180 | if (48>filascii)||(filascii>57); % select the non-numerical characters
|
---|
181 | num=0;
|
---|
182 | else
|
---|
183 | indcur=indcur-1; count=count+1;
|
---|
184 | end
|
---|
185 | end
|
---|
186 | if count~=0
|
---|
187 | field_count=RootFile(indcur+1:indcur+count);% set the selected field number'%03d'
|
---|
188 | if isequal(field_count(1),'0')
|
---|
189 | nbfigures=length(field_count);
|
---|
190 | nom_type=['%0' num2str(nbfigures) 'd'];
|
---|
191 | else
|
---|
192 | nom_type='#';
|
---|
193 | end
|
---|
194 | end
|
---|
195 | end
|
---|
196 | end
|
---|
197 | %select the root name in the file_input window
|
---|
198 | RootFile=RootFile(1:indcur);
|
---|
199 | if nbchar<4% put '*' before the name (remove at the end)
|
---|
200 | RootFile(1:4-nbchar)=[];
|
---|
201 | end
|
---|
202 | if testsub
|
---|
203 | [RootPath,subdir,extdir]=fileparts(RootPath);
|
---|
204 | subdir=[subdir extdir];
|
---|
205 | end
|
---|