[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:
|
---|
[811] | 9 | % filename: string representing the full file name (including path)
|
---|
| 10 | %
|
---|
[353] | 11 | % INPUT:
|
---|
[811] | 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
|
---|
[353] | 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'
|
---|
[811] | 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.
|
---|
[353] | 36 |
|
---|
[809] | 37 | %=======================================================================
|
---|
[1107] | 38 | % Copyright 2008-2022, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
[809] | 39 | % http://www.legi.grenoble-inp.fr
|
---|
| 40 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
|
---|
| 41 | %
|
---|
| 42 | % This file is part of the toolbox UVMAT.
|
---|
| 43 | %
|
---|
| 44 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
| 45 | % it under the terms of the GNU General Public License as published
|
---|
| 46 | % by the Free Software Foundation; either version 2 of the license,
|
---|
| 47 | % or (at your option) any later version.
|
---|
| 48 | %
|
---|
| 49 | % UVMAT is distributed in the hope that it will be useful,
|
---|
| 50 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 51 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 52 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
| 53 | %=======================================================================
|
---|
| 54 |
|
---|
[353] | 55 | function filename=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,i1,i2,j1,j2)
|
---|
| 56 |
|
---|
[714] | 57 | %% display help and test function in the absence of input argument
|
---|
[353] | 58 | if ~exist('RootPath','var')
|
---|
| 59 | help fullfile_uvmat;
|
---|
| 60 | test;
|
---|
| 61 | return
|
---|
| 62 | end
|
---|
| 63 |
|
---|
| 64 | %% default input
|
---|
| 65 | if ~exist('j2','var')
|
---|
| 66 | j2=[];
|
---|
| 67 | end
|
---|
[372] | 68 | if ~exist('j1','var')
|
---|
| 69 | j1=[];
|
---|
| 70 | end
|
---|
[353] | 71 | if isequal(j1,j2)
|
---|
[360] | 72 | j2=[];% suppress the secodn index if equal to the first
|
---|
[353] | 73 | end
|
---|
| 74 | if ~exist('i2','var')
|
---|
| 75 | i2=[];
|
---|
| 76 | end
|
---|
| 77 | if isequal(i1,i2)
|
---|
[961] | 78 | i2=[];% suppress the second index if equal to the first
|
---|
[353] | 79 | end
|
---|
| 80 | if ~exist('i1','var')
|
---|
| 81 | i1=1;
|
---|
| 82 | end
|
---|
| 83 |
|
---|
| 84 | %% default output
|
---|
| 85 | sep1='';
|
---|
| 86 | i1_str='';
|
---|
| 87 | sep2='';
|
---|
| 88 | i2_str='';
|
---|
| 89 | sep3='';
|
---|
| 90 | j1_str='';
|
---|
| 91 | sep4='';
|
---|
| 92 | j2_str='';
|
---|
| 93 |
|
---|
| 94 | %% look for NomType with pairs (separator '-' or terminasion ab or AB
|
---|
[1022] | 95 | % if strcmp(NomType,'level')% organisation with a sub-folder for the files of each index i
|
---|
| 96 | % filename=fullfile(RootPath,SubDir,['level' num2str(j1)],[RootFile num2str(i1) FileExt]);
|
---|
| 97 | % else
|
---|
[961] | 98 | if ~isempty(regexp(NomType,'^_\d'))
|
---|
| 99 | sep1='_';
|
---|
[353] | 100 | NomType(1)=[];%remove '_' from the beginning of NomType
|
---|
| 101 | end
|
---|
[961] | 102 | r=regexp(NomType,'^(?<num1>\d+)','names');%look for a number at the beginning of NomType
|
---|
| 103 | if ~isempty(r)
|
---|
| 104 | i1_str=num2str(i1,['%0' num2str(length(r.num1)) 'd']);
|
---|
| 105 | NomType=regexprep(NomType,['^' r.num1],'');
|
---|
| 106 | r=regexp(NomType,'^-(?<num2>\d+)','names');%look for a pair i1-i2
|
---|
[353] | 107 | if ~isempty(r)
|
---|
[961] | 108 | if ~isempty(i2)
|
---|
| 109 | sep2='-';
|
---|
| 110 | i2_str=num2str(i2,['%0' num2str(length(r.num2)) 'd']);
|
---|
| 111 | end
|
---|
| 112 | NomType=regexprep(NomType,['^-' r.num2],'');
|
---|
[353] | 113 | end
|
---|
[961] | 114 | if ~isempty(regexp(NomType,'^_'));
|
---|
| 115 | sep3='_';
|
---|
| 116 | NomType(1)=[];%remove '_' from the beginning of NomType
|
---|
[353] | 117 | end
|
---|
[961] | 118 | if ~isempty(regexp(NomType,'^[a|A]'));
|
---|
| 119 | j1_str=num2stra(j1,NomType);
|
---|
| 120 | if ~isempty(regexp(NomType,'[b|B]$'))&& ~isempty(j2);
|
---|
| 121 | j2_str=num2stra(j2,NomType);
|
---|
| 122 | end
|
---|
| 123 | else
|
---|
| 124 | r=regexp(NomType,'^(?<num3>\d+)','names');
|
---|
| 125 | if ~isempty(r)
|
---|
| 126 | j1_str=num2str(j1,['%0' num2str(length(r.num3)) 'd']);
|
---|
| 127 | NomType=regexprep(NomType,['^' r.num3],'');
|
---|
| 128 | end
|
---|
| 129 | if ~isempty(j2)
|
---|
| 130 | r=regexp(NomType,'-(?<num4>\d+)','names');
|
---|
| 131 | if ~isempty(r)
|
---|
| 132 | sep4='-';
|
---|
| 133 | j2_str=num2str(j2,['%0' num2str(length(r.num4)) 'd']);
|
---|
| 134 | end
|
---|
| 135 | end
|
---|
[360] | 136 | end
|
---|
[353] | 137 | end
|
---|
[1022] | 138 | if isempty(regexp(RootPath,'^http://'))
|
---|
[961] | 139 | filename=fullfile(RootPath,SubDir,RootFile);
|
---|
[1022] | 140 | else
|
---|
| 141 | filename=[RootPath '/' SubDir '/' RootFile];
|
---|
| 142 | end
|
---|
[961] | 143 | filename=[filename sep1 i1_str sep2 i2_str sep3 j1_str sep4 j2_str];
|
---|
| 144 | filename=[regexprep(filename,'_$','') FileExt];%suppress possible '_' at the end of the string and add the extension
|
---|
[1022] | 145 | % end
|
---|
[353] | 146 |
|
---|
| 147 | function test
|
---|
| 148 | fprintf([...
|
---|
| 149 | '######################################################\n'...
|
---|
| 150 | ' Test for fullfile_uvmat \n'...
|
---|
| 151 | '######################################################\n'...
|
---|
| 152 | ]);
|
---|
| 153 |
|
---|
| 154 | FileName_list={...
|
---|
| 155 | 'Image1a.png'...
|
---|
| 156 | 'toto'...
|
---|
| 157 | 'B011_1.png'...
|
---|
| 158 | 'B001.png'...
|
---|
| 159 | 'B55a.tif'...
|
---|
| 160 | 'B002B.tiff'...
|
---|
| 161 | 'B_001.png'...
|
---|
| 162 | 'B_3331AB.png'...
|
---|
| 163 | 'aa45_2.png'...
|
---|
| 164 | 'B005.png'...
|
---|
| 165 | 'Image_3.jpg'...
|
---|
| 166 | 'Image_3-4.jpg'...
|
---|
| 167 | 'Image_3-4_2.jpg'...
|
---|
| 168 | 'Image_5_3-4.jpg'...
|
---|
| 169 | 'Image_3_ab.jpg'...
|
---|
| 170 | 'Image005AD.jpg'...
|
---|
| 171 | 'Image_3_ac.jpg'...
|
---|
| 172 | 'Image_3a-b.jpg'...
|
---|
| 173 | 'Image3_a.jpg'...
|
---|
| 174 | 'movie57.avi'...
|
---|
| 175 | 'merged_20_12_1.png'...
|
---|
| 176 | };
|
---|
| 177 | size(FileName_list)
|
---|
| 178 | for ilist=1:numel(FileName_list)
|
---|
| 179 | [RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomType]=...
|
---|
| 180 | fileparts_uvmat(FileName_list{1,ilist});
|
---|
| 181 | FileName_list{2,ilist}=['NomType=' NomType];
|
---|
| 182 | FileName_list{3,ilist}=['i+1,j+1->' fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,i1+1,i2+1,j1+1,j2+1)];
|
---|
| 183 | % fprintf(['File name : ' FileName{1} '\n FileName_rebuilt : ' FileName_rebuilt '\n'])
|
---|
| 184 | end
|
---|
| 185 | Tabchar=cell2tab(FileName_list',' ');
|
---|
| 186 | display(Tabchar)
|
---|
| 187 | % fprintf(Tabchar);
|
---|
| 188 |
|
---|
| 189 |
|
---|
| 190 |
|
---|