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='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
|
---|
26 | %
|
---|
27 | %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
|
---|
36 | i2=[];
|
---|
37 | j1=[];
|
---|
38 | j2=[];
|
---|
39 | nom_type='';
|
---|
40 | subdir='';
|
---|
41 | RootFile='';
|
---|
42 |
|
---|
43 | %select file extension
|
---|
44 | [RootPath,filename,ext]=fileparts(fileinput);
|
---|
45 |
|
---|
46 | % \D not a digit
|
---|
47 | % \d digit
|
---|
48 |
|
---|
49 |
|
---|
50 | %% recursive test on filename stqrting from the end
|
---|
51 |
|
---|
52 | % test whether filename ends with a number or not
|
---|
53 | r=regexp(filename,'.*\D(?<num1>\d+)\>','names');
|
---|
54 |
|
---|
55 | if ~isempty(r)% filename end matches num1
|
---|
56 | num1=r.num1;
|
---|
57 | r=regexp(filename,['.*\D(?<num2>\d+)(?<delim1>[-_])' num1 '\>'],'names');
|
---|
58 | if ~isempty(r)% filename end matches num2+delim1+num1
|
---|
59 | delim1=r.delim1;
|
---|
60 | 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 num1
|
---|
63 | delim2=r.delim2;
|
---|
64 | num3=r.num3;
|
---|
65 | switch delim1
|
---|
66 | case '_'
|
---|
67 | j1=str2num(num1);
|
---|
68 | switch delim2
|
---|
69 | case '-'
|
---|
70 | i1=str2num(num3);
|
---|
71 | i2=str2num(num2);
|
---|
72 | end
|
---|
73 | case '-'
|
---|
74 | j1=str2num(num2);
|
---|
75 | j2=str2num(num1);
|
---|
76 | switch delim2
|
---|
77 | case '_'
|
---|
78 | i1=str2num(num3);
|
---|
79 | end
|
---|
80 | end
|
---|
81 | nom_type=[get_type(num3) delim2 get_type(num2) delim1 get_type(num1)];
|
---|
82 | RootFile=regexprep(filename,[num3 delim2 num2 delim1 num1],'');
|
---|
83 | else
|
---|
84 | switch delim1
|
---|
85 | case '_'
|
---|
86 | i1=str2num(num2);
|
---|
87 | j1=str2num(num1);
|
---|
88 | case '-'
|
---|
89 | i1=str2num(num2);
|
---|
90 | i2=str2num(num1);
|
---|
91 | end
|
---|
92 | nom_type=[get_type(num2) delim1 get_type(num1)];
|
---|
93 | RootFile=regexprep(filename,[num2 delim1 num1],'');
|
---|
94 | end
|
---|
95 | else% only one number at the end
|
---|
96 | i1=str2num(num1);
|
---|
97 | nom_type=get_type(num1);
|
---|
98 | RootFile=regexprep(filename,num1,'');
|
---|
99 | end
|
---|
100 | else% filename ends with a letter
|
---|
101 | r=regexp(filename,'.*[^a^b^A^B](?<end_string>ab|AB|[abAB])\>','names');
|
---|
102 | if ~isempty(r)
|
---|
103 | end_string=r.end_string;
|
---|
104 | r=regexp(filename,['.+(?<delim1>[_-])' end_string '\>'],'names');
|
---|
105 | if ~isempty(r)
|
---|
106 | delim1=r.delim1;
|
---|
107 | r=regexp(filename,['.*\D(?<num1>\d+)' delim1 end_string '\>'],'names');
|
---|
108 | if ~isempty(r)
|
---|
109 | num1=r.num1;
|
---|
110 | nom_type=[get_type(num1) delim1 get_type(end_string)];
|
---|
111 | i1=str2num(num1);
|
---|
112 | [j1,j2]=get_value(end_string);
|
---|
113 | RootFile=regexprep(filename,[num1 delim1 end_string],'');
|
---|
114 |
|
---|
115 | else
|
---|
116 | nom_type=get_type(end_string);
|
---|
117 | [j1,j2]=get_value(end_string);
|
---|
118 | RootFile=regexprep(filename,[end_string],'');
|
---|
119 |
|
---|
120 | end
|
---|
121 | else
|
---|
122 | r=regexp(filename,['.*\D(?<num1>\d+)' end_string '\>'],'names');
|
---|
123 | if ~isempty(r)
|
---|
124 | num1=r.num1;
|
---|
125 | % r=regexp(filename,['.+(?<delim1>[-_])' num1 end_string '\>'],'names');
|
---|
126 | % if ~isempty(r)
|
---|
127 | % delim1=r.delim1;
|
---|
128 | % i1=num1;
|
---|
129 | % str_a=end_string;
|
---|
130 | % nom_type=[delim1 get_type(num1) get_type(end_string)];
|
---|
131 | % RootFile=regexprep(filename,[delim1 num1 end_string],'');
|
---|
132 | % else
|
---|
133 | i1=str2num(num1);
|
---|
134 | [j1,j2]=get_value(end_string);
|
---|
135 | nom_type=[get_type(num1) get_type(end_string)];
|
---|
136 | RootFile=regexprep(filename,[num1 end_string],'');
|
---|
137 | % end
|
---|
138 | else
|
---|
139 | end
|
---|
140 |
|
---|
141 |
|
---|
142 |
|
---|
143 | end
|
---|
144 | else
|
---|
145 | end
|
---|
146 | end
|
---|
147 |
|
---|
148 |
|
---|
149 |
|
---|
150 |
|
---|
151 |
|
---|
152 |
|
---|
153 | function type=get_type(s)
|
---|
154 | % returns the type of a label string:
|
---|
155 | % for numbers, whether filled with 0 or not.
|
---|
156 | % for letters, either a, A or ab, AB.
|
---|
157 |
|
---|
158 | switch s
|
---|
159 | case {'a','b'}
|
---|
160 | type='a';
|
---|
161 | case {'A','B'}
|
---|
162 | type='A';
|
---|
163 | case 'ab'
|
---|
164 | type='ab';
|
---|
165 | case 'AB'
|
---|
166 | type='AB';
|
---|
167 | otherwise
|
---|
168 | if ~isempty(regexp(s,'\<\d+\>','ONCE'))
|
---|
169 | switch s(1)
|
---|
170 | case '0'
|
---|
171 | type=num2str(1,['%0' num2str(length(s)) 'd']);
|
---|
172 | otherwise
|
---|
173 | type='1';
|
---|
174 | end
|
---|
175 | else
|
---|
176 | type='';
|
---|
177 | return
|
---|
178 | end
|
---|
179 | end
|
---|
180 |
|
---|
181 |
|
---|
182 | function [j1,j2]=get_value(s)
|
---|
183 | % returns the type of a label string:
|
---|
184 | % for numbers, whether filled with 0 or not.
|
---|
185 | % for letters, either a, A or ab, AB.
|
---|
186 | j1=[];
|
---|
187 | j2=[];
|
---|
188 |
|
---|
189 | switch lower(s)
|
---|
190 | case {'a'}
|
---|
191 | j1=1;
|
---|
192 | case {'b','B'}
|
---|
193 | j1=2;
|
---|
194 | case 'ab'
|
---|
195 | j1=1;j2=2;
|
---|
196 | otherwise
|
---|
197 | return
|
---|
198 | end
|
---|
199 |
|
---|
200 |
|
---|