source: trunk/src/fullfile_uvmat.m @ 356

Last change on this file since 356 was 354, checked in by sommeria, 9 years ago
File size: 6.3 KB
Line 
1%'fullfile_uvmat': creates a file name from a root name and indices.
2%------------------------------------------------------------------------
3% filename=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,i1,i2,j1,j2)
4%------------------------------------------------------------------------           
5% In the absence of input argument this function tests itself on a set of
6% examples
7%------------------------------------------------------------------------
8% OUTPUT:
9% filename: string representing the full file name (including path)
10%------------------------------------------------------------------------
11% INPUT:
12%RootPath: path to the base file
13%SubDir: name of the SubDirectory for netcdf files (relevant for NomTypes with index pairs 1-2 or ab )
14%RootFile: FileName without appendix
15%FileExt: file extension
16%NomType: char chain characterizing the file nomenclature, made as
17%   nom_type='': constant name [filebase ext] (default output if 'nom_type' is undefined)
18%   nom_type='*':constant name for a file representing a series (e.g. avi movie)
19%   nom_type='1','01',or '001'...': series of files with a single index i without separator(e.g. 'aa045.png').
20%   nom_type='_1','_01','_001'...':  series of files with a single index i with separator '_'(e.g. 'aa_045.png').
21%   nom_type='1a','1A','01a','01A',... with a numerical index and an index letter(e.g.'aa45b.png') (lower or upper case)
22%   nom_type='_1a','_1A','_01a','_01A',...: idem, with a separator '_' before the index
23%   nom_type='_1_1','_01_1',...: matrix of files with two indices i and j separated by '_'(e.g. 'aa_45_2.png')
24%   nom_type='_1-2': from pairs from a single index (e.g. 'aa_45-47.nc')
25%   nom_type='_1_1-2': pairs of j indices (e.g. 'aa_45_2-3.nc')
26%   nom_type='_1-2_1': pairs of i indices (e.g. 'aa_45-46_2.nc')
27%   nom_type='_1_ab','1_ab','01_ab'..., from pairs of '#' images
28%   (e.g.'aa045bc.nc'), ext='.nc'
29%i1: first number i
30%i2: second number i (only for .nc files)
31%j1: first number j
32%j2: second number j (only for .nc files)
33%------------------------------------------------------------------------
34%related functions:
35% fileparts_uvmat, num2stra, stra2num.
36
37function filename=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,i1,i2,j1,j2)
38% sizf=size(filebase);
39% if (~ischar(filebase)||~isequal(sizf(1),1)),filebase='';end
40% if ~exist('ext','var')
41%     ext='';
42% end
43% if ~exist('nom_type','var')
44%     nom_type='';
45% end
46% if ~ischar(ext),ext='';end
47% % idetect=0;
48% if ~exist('i1','var') || isempty(i1) || isnan(i1)
49%     i1=1; %default
50% end
51% if ~exist('j1','var') ||  isempty(j1) || isnan(j1)
52%     j1=1; %default
53% end
54% if ~exist('i2','var') ||  isempty(i2) || isnan(i2)
55%     i2=i1; %default
56% end
57% if ~exist('j2','var') || isempty(j2) || isnan(j2)
58%     j2=j1; %default
59% end
60% if ~exist('subdir','var')|| isempty(subdir)
61%     subdir='' ; %default
62% end
63
64   
65%% display help and test function in the absence of input arument
66if ~exist('RootPath','var')
67    help fullfile_uvmat;
68    test;
69    return
70end
71
72%% default input
73if ~exist('j2','var')
74    j2=[];
75end
76if isequal(j1,j2)
77    j2=[];
78end
79if ~exist('j1','var')
80    j1=1;
81end
82if ~exist('i2','var')
83    i2=[];
84end
85if isequal(i1,i2)
86    i2=[];
87end
88if ~exist('i1','var')
89    i1=1;
90end
91
92%% default output
93sep1='';
94i1_str='';
95sep2='';
96i2_str='';
97sep3='';
98j1_str='';
99sep4='';
100j2_str='';
101
102%% look for NomType with pairs (separator '-' or terminasion ab or AB
103if ~isempty(regexp(NomType,'^_\d'))
104    sep1='_';
105    NomType(1)=[];%remove '_' from the beginning of NomType
106end
107r=regexp(NomType,'^(?<num1>\d+)','names');%look for a number at the beginning of NomType
108if ~isempty(r)
109    i1_str=num2str(i1,['%0' num2str(length(r.num1)) 'd']);
110    NomType=regexprep(NomType,['^' r.num1],'');
111    r=regexp(NomType,'^-(?<num2>\d+)','names');%look for a pair i1-i2
112    if ~isempty(r)
113        sep2='-';
114         i2_str=num2str(i2,['%0' num2str(length(r.num2)) 'd']);
115         NomType=regexprep(NomType,['^-' r.num2],'');
116    end
117    if ~isempty(regexp(NomType,'^_'));
118        sep3='_';
119        NomType(1)=[];%remove '_' from the beginning of NomType
120    end
121    if ~isempty(regexp(NomType,'^[a|A]'));
122        j1_str=num2stra(j1,NomType);
123        if ~isempty(regexp(NomType,'[b|B]$'));
124            j2_str=num2stra(j2,NomType);
125        end
126    else
127        r=regexp(NomType,'^(?<num3>\d+)','names');
128        if ~isempty(r)
129            j1_str=num2str(j1,['%0' num2str(length(r.num3)) 'd']);
130            NomType=regexprep(NomType,['^' r.num3],'');
131        end
132        r=regexp(NomType,'-(?<num4>\d+)','names');
133        if ~isempty(r)&& ~isempty(j2)
134            sep4='-';
135            j2_str=num2str(j2,['%0' num2str(length(r.num4)) 'd']);
136        end
137    end
138end
139if ~isempty(i2_str)||~isempty(j2_str)
140    filename=fullfile(RootPath,SubDir,RootFile);
141else
142    filename=fullfile(RootPath,RootFile);
143end
144filename=[filename sep1 i1_str sep2 i2_str sep3 j1_str sep4 j2_str FileExt];
145
146
147
148function test
149fprintf([...
150    '######################################################\n'...
151    '               Test for fullfile_uvmat                  \n'...
152    '######################################################\n'...
153    ]);
154
155    FileName_list={...
156        'Image1a.png'...
157        'toto'...
158        'B011_1.png'...
159        'B001.png'...
160        'B55a.tif'...
161        'B002B.tiff'...
162        'B_001.png'...
163        'B_3331AB.png'...
164        'aa45_2.png'...
165        'B005.png'...
166        'Image_3.jpg'...
167        'Image_3-4.jpg'...
168        'Image_3-4_2.jpg'...
169        'Image_5_3-4.jpg'...
170        'Image_3_ab.jpg'...
171        'Image005AD.jpg'...
172        'Image_3_ac.jpg'...
173        'Image_3a-b.jpg'...
174        'Image3_a.jpg'...
175        'movie57.avi'...
176        'merged_20_12_1.png'...
177        };
178size(FileName_list)
179for ilist=1:numel(FileName_list)
180    [RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomType]=...
181        fileparts_uvmat(FileName_list{1,ilist});
182    FileName_list{2,ilist}=['NomType=' NomType];
183    FileName_list{3,ilist}=['i+1,j+1->' fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,i1+1,i2+1,j1+1,j2+1)];
184%     fprintf(['File name  : ' FileName{1} '\n FileName_rebuilt  : '    FileName_rebuilt '\n'])
185end
186  Tabchar=cell2tab(FileName_list',' ');
187  display(Tabchar)
188 % fprintf(Tabchar);
189
190
191
Note: See TracBrowser for help on using the repository browser.