source: trunk/src/fullfile_uvmat.m @ 644

Last change on this file since 644 was 589, checked in by sommeria, 8 years ago

various minor corrections made

File size: 6.0 KB
RevLine 
[353]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   
39%% display help and test function in the absence of input arument
40if ~exist('RootPath','var')
41    help fullfile_uvmat;
42    test;
43    return
44end
45
46%% default input
47if ~exist('j2','var')
48    j2=[];
49end
[372]50if ~exist('j1','var')
51    j1=[];
52end
[353]53if isequal(j1,j2)
[360]54    j2=[];% suppress the secodn index if equal to the first
[353]55end
56if ~exist('i2','var')
57    i2=[];
58end
59if isequal(i1,i2)
[360]60    i2=[];% suppress the secodn index if equal to the first
[353]61end
62if ~exist('i1','var')
63    i1=1;
64end
65
66%% default output
67sep1='';
68i1_str='';
69sep2='';
70i2_str='';
71sep3='';
72j1_str='';
73sep4='';
74j2_str='';
75
76%% look for NomType with pairs (separator '-' or terminasion ab or AB
77if ~isempty(regexp(NomType,'^_\d'))
78    sep1='_';
79    NomType(1)=[];%remove '_' from the beginning of NomType
80end
81r=regexp(NomType,'^(?<num1>\d+)','names');%look for a number at the beginning of NomType
82if ~isempty(r)
83    i1_str=num2str(i1,['%0' num2str(length(r.num1)) 'd']);
[360]84    NomType=regexprep(NomType,['^' r.num1],'');   
[353]85    r=regexp(NomType,'^-(?<num2>\d+)','names');%look for a pair i1-i2
86    if ~isempty(r)
[360]87         if ~isempty(i2)
[353]88        sep2='-';
89         i2_str=num2str(i2,['%0' num2str(length(r.num2)) 'd']);
[360]90         end
[353]91         NomType=regexprep(NomType,['^-' r.num2],'');
92    end
93    if ~isempty(regexp(NomType,'^_'));
94        sep3='_';
95        NomType(1)=[];%remove '_' from the beginning of NomType
96    end
97    if ~isempty(regexp(NomType,'^[a|A]'));
98        j1_str=num2stra(j1,NomType);
[360]99        if ~isempty(regexp(NomType,'[b|B]$'))&& ~isempty(j2);
[353]100            j2_str=num2stra(j2,NomType);
101        end
102    else
103        r=regexp(NomType,'^(?<num3>\d+)','names');
104        if ~isempty(r)
105            j1_str=num2str(j1,['%0' num2str(length(r.num3)) 'd']);
106            NomType=regexprep(NomType,['^' r.num3],'');
107        end
[360]108        if ~isempty(j2)
[353]109        r=regexp(NomType,'-(?<num4>\d+)','names');
[360]110        if ~isempty(r)
[353]111            sep4='-';
[354]112            j2_str=num2str(j2,['%0' num2str(length(r.num4)) 'd']);
[353]113        end
[360]114        end
[353]115    end
116end
[371]117% if ~isempty(i2_str)||~isempty(j2_str)
[353]118    filename=fullfile(RootPath,SubDir,RootFile);
[371]119% else
120%     filename=fullfile(RootPath,RootFile);
121% end
[589]122filename=[filename sep1 i1_str sep2 i2_str sep3 j1_str sep4 j2_str];
123filename=[regexprep(filename,'_$','') FileExt];%suppress possible '_' at the end of the string and add the extension
[353]124
125
126function test
127fprintf([...
128    '######################################################\n'...
129    '               Test for fullfile_uvmat                  \n'...
130    '######################################################\n'...
131    ]);
132
133    FileName_list={...
134        'Image1a.png'...
135        'toto'...
136        'B011_1.png'...
137        'B001.png'...
138        'B55a.tif'...
139        'B002B.tiff'...
140        'B_001.png'...
141        'B_3331AB.png'...
142        'aa45_2.png'...
143        'B005.png'...
144        'Image_3.jpg'...
145        'Image_3-4.jpg'...
146        'Image_3-4_2.jpg'...
147        'Image_5_3-4.jpg'...
148        'Image_3_ab.jpg'...
149        'Image005AD.jpg'...
150        'Image_3_ac.jpg'...
151        'Image_3a-b.jpg'...
152        'Image3_a.jpg'...
153        'movie57.avi'...
154        'merged_20_12_1.png'...
155        };
156size(FileName_list)
157for ilist=1:numel(FileName_list)
158    [RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomType]=...
159        fileparts_uvmat(FileName_list{1,ilist});
160    FileName_list{2,ilist}=['NomType=' NomType];
161    FileName_list{3,ilist}=['i+1,j+1->' fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,i1+1,i2+1,j1+1,j2+1)];
162%     fprintf(['File name  : ' FileName{1} '\n FileName_rebuilt  : '    FileName_rebuilt '\n'])
163end
164  Tabchar=cell2tab(FileName_list',' ');
165  display(Tabchar)
166 % fprintf(Tabchar);
167
168
169
Note: See TracBrowser for help on using the repository browser.