[8] | 1 | %'name_generator': creates a file name from a root name and indices.
|
---|
[89] | 2 | %------------------------------------------------------------------------
|
---|
[122] | 3 | % [filename,num_i1_out,num_j1_out,num_i2_out,num_j2_out,subdir_out]=...
|
---|
[85] | 4 | % name_generator(filebase,num_i1,num_j1,ext,nom_type,comp_input,num_i2,num_j2,subdir);
|
---|
[89] | 5 | %------------------------------------------------------------------------
|
---|
[8] | 6 | % This function detects the existence the constructed file name and it can
|
---|
| 7 | % find indices according to file existence if they are not specified
|
---|
[85] | 8 | % rmq: this function is related to the reverse functions display2name and name2diplay
|
---|
[89] | 9 | %------------------------------------------------------------------------
|
---|
[8] | 10 | % OUTPUT:
|
---|
[85] | 11 | % filename: string representing the file name (including path)
|
---|
| 12 | % num_i1_out,num_j1_out,num_i2_out,num_j2_out,subdir_out: index numbers and subdirectory detected
|
---|
| 13 | % for free input (= to the corresponding input indices when comp_input=1)
|
---|
[89] | 14 | %------------------------------------------------------------------------
|
---|
[8] | 15 | % INPUT:
|
---|
| 16 | % 'filebase': the root name,
|
---|
| 17 | % 'num_i1: first labelling index i
|
---|
| 18 | % 'num_j1', first labelling index j
|
---|
| 19 | % 'ext': file name extension (e.g. '.png' or '.nc')
|
---|
[122] | 20 | %nom_type: char chain characterizing the file nomenclature: with values
|
---|
| 21 | % nom_type='': constant name [filebase ext] (default output if 'nom_type' is undefined)
|
---|
| 22 | % nom_type='*':constant name for a file representing a series (e.g. avi movie)
|
---|
| 23 | % nom_type='1','01',or '001'...': series of files with a single index i without separator(e.g. 'aa045.png').
|
---|
| 24 | % nom_type='_1','_01','_001'...': series of files with a single index i with separator '_'(e.g. 'aa_045.png').
|
---|
| 25 | % nom_type='1a','1A','01a','01A',... with a numerical index and an index letter(e.g.'aa45b.png') (lower or upper case)
|
---|
| 26 | % nom_type='_1a','_1A','_01a','_01A',...: idem, with a separator '_' before the index
|
---|
| 27 | % nom_type='_1_1','_01_1',...: matrix of files with two indices i and j separated by '_'(e.g. 'aa_45_2.png')
|
---|
| 28 | % nom_type='_i1-i2': from pairs from a single index (e.g. 'aa_45-47.nc')
|
---|
| 29 | % nom_type='_i_j1-j2': pairs of j indices (e.g. 'aa_45_2-3.nc')
|
---|
| 30 | % nom_type='_i1-i2_j': pairs of i indices (e.g. 'aa_45-46_2.nc')
|
---|
| 31 | % nom_type='_1_ab','1_ab','01_ab'..., from pairs of '#' images (e.g.'aa045bc.nc'), ext='.nc'
|
---|
[85] | 32 | %'comp_input' (for nom_type involving index pairs (e.g. netc))
|
---|
| 33 | % comp_input=1: the index pair is imposed,
|
---|
| 34 | % comp_input=0: the index pair is automatically searched, choosing the most recent file in case of multiple choice
|
---|
[8] | 35 | % 'num_i2': second index i (for nom_type involving index pairs (e.g. netc))
|
---|
| 36 | % 'num_j2': second index j (for nom_type involving index pairs (e.g. netc))
|
---|
| 37 | % 'subdir': (used for nom_type=netc...) string representing the name of the subdirectory 'subdir' containing file.
|
---|
[85] | 38 | % subdir='': no subdirectory,
|
---|
| 39 | % subdir='?', the file is first searched with no subdirectory, then in the most recently modified subdirectory if not detected.
|
---|
[8] | 40 |
|
---|
| 41 | % A FAIRE: si comp_inpu=0, si _i_j n'existe pas, chercher _i,
|
---|
| 42 | function [filename,num_i1_out,num_j1_out,num_i2_out,num_j2_out,subdir_out]=...
|
---|
[122] | 43 | name_generator(filebase,num_i1,num_j1,ext,nom_type,comp_input,num_i2,num_j2,subdir)
|
---|
[8] | 44 | sizf=size(filebase);
|
---|
| 45 | if (~ischar(filebase)||~isequal(sizf(1),1)),filebase='';end
|
---|
[89] | 46 | if ~exist('ext','var')
|
---|
| 47 | ext='';
|
---|
| 48 | end
|
---|
| 49 | if ~exist('nom_type','var')
|
---|
| 50 | nom_type='';
|
---|
| 51 | end
|
---|
[8] | 52 | if ~ischar(ext),ext='';end
|
---|
| 53 | idetect=0;
|
---|
[89] | 54 | if ~exist('num_i1','var') || isempty(num_i1) || isnan(num_i1)
|
---|
[8] | 55 | num_i1=1; %default
|
---|
| 56 | end
|
---|
[89] | 57 | if ~exist('num_j1','var') || isempty(num_j1) || isnan(num_j1)
|
---|
[8] | 58 | num_j1=1; %default
|
---|
| 59 | end
|
---|
[89] | 60 | if ~exist('num_i2','var') || isempty(num_i2) || isnan(num_i2)
|
---|
[8] | 61 | num_i2=num_i1; %default
|
---|
| 62 | end
|
---|
[89] | 63 | if ~exist('num_j2','var') || isempty(num_j2) || isnan(num_j2)
|
---|
[65] | 64 | num_j2=num_j1; %default
|
---|
| 65 | end
|
---|
[8] | 66 | if ~exist('subdir','var')|| isempty(subdir)
|
---|
| 67 | subdir='' ; %default
|
---|
| 68 | end
|
---|
[65] | 69 | num_i1_out=num_i1;%default output
|
---|
| 70 | num_j1_out=num_j1;%default output
|
---|
| 71 | num_i2_out=num_i2;%default output
|
---|
| 72 | num_j2_out=num_j2;%default output
|
---|
[122] | 73 | test_pairs=numel(nom_type)>=2 &&(strcmp(nom_type,'_i1-i2_j1-j2')|| strcmp(nom_type(end-1:end),'ab')|| strcmp(nom_type(end-1:end),'AB')||...
|
---|
| 74 | strcmp(nom_type,'_i_j1-j2')|| strcmp(nom_type,'_i1-i2_j')||strcmp(nom_type,'_i1-i2'));
|
---|
| 75 | %test_2D= strcmp(nom_type(end-1:end),'ab')|| strcmp(nom_type(end-1:end),'AB') ||strcmp(nom_type,'_i_j1-j2');
|
---|
| 76 | %test_3D=strcmp(nom_type,'_i1-i2_j')|| strcmp(nom_type,'_i1-i2');
|
---|
| 77 | if ~isequal(subdir,'') && ~isequal(subdir,'?')
|
---|
| 78 | [Path,Name]=fileparts(filebase);
|
---|
| 79 | filename=fullfile(Path,subdir,Name);
|
---|
| 80 | else
|
---|
| 81 | filename=filebase;%default
|
---|
| 82 | end
|
---|
| 83 | if ~test_pairs%case of a single index i, and possibly j
|
---|
| 84 | numlength=numel(nom_type);
|
---|
| 85 | num_j_str='';
|
---|
| 86 | if strcmp(nom_type(1),'_')
|
---|
| 87 | filename=[filename '_'];
|
---|
| 88 | nom_type(1)=[];
|
---|
| 89 | end
|
---|
| 90 | if strcmp(nom_type(end),'a')
|
---|
| 91 | nom_type(end)=[];
|
---|
| 92 | num_j_str=char(num_j1+96);% lower letter corresponding to the index
|
---|
| 93 | elseif strcmp(nom_type(end),'A')
|
---|
| 94 | nom_type(end)=[];
|
---|
| 95 | num_j_str=char(num_j1+64);% lower letter corresponding to the index
|
---|
| 96 | elseif isequal(numel(regexp(nom_type(2:end),'_')),1)%if a separator '_' exists in nom_type
|
---|
| 97 | num_j_str=['_' num2str(num_j1)];
|
---|
| 98 | nom_type(regexp(nom_type(2:end),'_'):end)=[];
|
---|
| 99 | else
|
---|
| 100 | num_j1_out=[];%no index j
|
---|
| 101 | end
|
---|
| 102 | if ~isempty(str2num(nom_type))
|
---|
| 103 | numtype=['%0' num2str(length(nom_type)) 'd'];%indicate the number of digits (0 before the number)
|
---|
| 104 | filename=[filename num2str(num_i1,numtype) num_j_str ext];
|
---|
| 105 | num_i2_out=num_i1_out;
|
---|
| 106 | num_j2_out=num_j1_out;
|
---|
| 107 | else %fixed name , no indexing, for instance '*'
|
---|
| 108 | % filebasesub=filebase;
|
---|
| 109 | filename=[filename ext];
|
---|
| 110 | end
|
---|
| 111 | % if strcmp(nom_type,'_i');
|
---|
| 112 | % filename=[filebase '_' num2str(num_i1) ext];
|
---|
| 113 | % num_i2_out=num_i1;
|
---|
| 114 | % num_j1_out=[];
|
---|
| 115 | % num_j2_out=[];
|
---|
| 116 | % elseif length(nom_type)==5 && strcmp(nom_type(1:3),'_%0')&& strcmp(nom_type(5),'d');
|
---|
| 117 | % filename=[filebase '_' num2str(num_i1,nom_type(2:5)) ext];
|
---|
| 118 | % num_i2_out=num_i1;
|
---|
| 119 | % num_j2_out=num_j1;
|
---|
| 120 | % elseif strcmp(nom_type,'_i_j')
|
---|
| 121 | % filename=[filebase '_' num2str(num_i1) '_' num2str(num_j1) ext];
|
---|
| 122 | % num_i2_out=num_i1;
|
---|
| 123 | % num_j2_out=num_j1;
|
---|
| 124 | % elseif strcmp(nom_type,'#a')| strcmp(nom_type,'#A')
|
---|
| 125 | % filename=[filebase num2str(num_i1,'%03d') num2stra(num_j1,nom_type) ext];
|
---|
| 126 | % num_i2_out=num_i1;
|
---|
| 127 | % num_j2_out=num_j1;
|
---|
| 128 | % elseif length(nom_type)>=5 & strcmp(nom_type(2:3),'%0') & strcmp(nom_type(5),'d') %strcmp(nom_type,'_%04dA') %camera PCO Toulouse
|
---|
| 129 | % filename=[filebase nom_type(1) num2str(num_i1,nom_type(2:4)) num2stra(num_j1,nom_type) ext];
|
---|
| 130 | % num_i2_out=num_i1;
|
---|
| 131 | % num_j2_out=num_j1;
|
---|
| 132 | % elseif strcmp(nom_type,'#')
|
---|
| 133 | % filename=[filebase num2str(num_i1) ext];
|
---|
| 134 | % num_i2_out=num_i1;
|
---|
| 135 | % num_j1_out=[];
|
---|
| 136 | % num_j2_out=[];
|
---|
| 137 | % elseif length(nom_type)>=4 & strcmp(nom_type(1:2),'%0') & strcmp(nom_type(end),'d')
|
---|
| 138 | % filename=[filebase num2str(num_i1,nom_type) ext]; %test number with a 0 before
|
---|
| 139 | % num_i2_out=num_i1;
|
---|
| 140 | % num_j1_out=[];
|
---|
| 141 | % num_j2_out=[];
|
---|
| 142 | % elseif length(nom_type)>=4 & strcmp(nom_type(1:2),'%0') & strcmp(nom_type(end-1:end),'dA')
|
---|
| 143 | % filename=[filebase num2str(num_i1,nom_type(1:end-1)) num2stra(num_j1,'#A') ext]; %test number with a 0 before
|
---|
| 144 | % num_i2_out=num_i1;
|
---|
| 145 | % num_j1_out=[];
|
---|
| 146 | % num_j2_out=[];
|
---|
| 147 | % end
|
---|
[8] | 148 | %case of derived file indexing (e.g. netcdf files)
|
---|
[122] | 149 | else
|
---|
[8] | 150 | %inexistant pair if num_i2=0 or num_j2=0
|
---|
[89] | 151 | % if strcmp(num_i2,0)
|
---|
[65] | 152 | % filename=[filebasesub '*-*_' num2str(num_i1) ext];
|
---|
| 153 | % return
|
---|
| 154 | % end
|
---|
[89] | 155 | % if strcmp(num_j2,0)
|
---|
[65] | 156 | % filename=[filebasesub '_' num2str(num_i1) '_*-*' ext];
|
---|
| 157 | % return
|
---|
| 158 | % end
|
---|
[8] | 159 | % case of an imposed image pair (comp_input=1)
|
---|
[122] | 160 | if (exist('comp_input','var') && isequal(comp_input,1))
|
---|
| 161 | if strcmp(nom_type(1),'_')
|
---|
| 162 | filename=[filename '_'];
|
---|
| 163 | nom_type(1)=[];
|
---|
| 164 | end
|
---|
| 165 | if strcmp(nom_type(end-1:end),'AB')||strcmp(nom_type(end-1:end),'ab')
|
---|
| 166 | if strcmp(nom_type(end-1:end),'AB')
|
---|
| 167 | nchar=64;
|
---|
[8] | 168 | else
|
---|
[122] | 169 | nchar=96;
|
---|
[8] | 170 | end
|
---|
[122] | 171 | if isequal(num_j1,num_j2)% case of displacements at the same time
|
---|
| 172 | num_j_str=char(num_j1+nchar);
|
---|
| 173 | else
|
---|
| 174 | num_j_str=[char(num_j1+nchar) char(num_j2+nchar)];
|
---|
| 175 | end
|
---|
| 176 | if strcmp(nom_type(end-2),'_')
|
---|
| 177 | numstr=['%0' num2str(numel(nom_type)-3) 'd'];
|
---|
| 178 | num_j_str=['_' num_j_str];
|
---|
| 179 | else
|
---|
| 180 | numstr=['%0' num2str(numel(nom_type)-2) 'd'];
|
---|
| 181 | end
|
---|
| 182 | filename=[filename num2str(num_i1,numstr) num_j_str ext];
|
---|
[65] | 183 | num_i2_out=num_i1;
|
---|
[122] | 184 | elseif isequal(nom_type,'i_j1-j2')
|
---|
[8] | 185 | if isequal(num2str(num_j1),num2str(num_j2))% case of displacements at the same time
|
---|
[122] | 186 | filename=[filename num2str(num_i1) '_' num2str(num_j1) ext];
|
---|
[8] | 187 | else
|
---|
[122] | 188 | filename=[filename num2str(num_i1) '_' num2str(num_j1) '-' num2str(num_j2) ext];
|
---|
[8] | 189 | end
|
---|
[65] | 190 | num_i2_out=num_i1;
|
---|
[122] | 191 | elseif isequal(nom_type,'i1-i2_j')
|
---|
[8] | 192 | if isequal(num2str(num_i1),num2str(num_i2))% case of displacements at the same time
|
---|
[122] | 193 | filename=[filename num2str(num_i1) '_' num2str(num_j1) ext];
|
---|
[8] | 194 | else
|
---|
[122] | 195 | filename=[filename num2str(num_i1) '-' num2str(num_i2) '_' num2str(num_j1) ext];
|
---|
[8] | 196 | end
|
---|
[65] | 197 | num_j2_out=num_j1;
|
---|
[122] | 198 | elseif isequal(nom_type,'i1-i2')
|
---|
[8] | 199 | if isequal(num2str(num_i1),num2str(num_i2))% case of displacements at the same time
|
---|
[122] | 200 | filename=[filename num2str(num_i1) ext];
|
---|
[8] | 201 | else
|
---|
[122] | 202 | filename=[filename num2str(num_i1) '-' num2str(num_i2) ext];
|
---|
[8] | 203 | end
|
---|
[65] | 204 | num_j2_out=num_j1;
|
---|
[122] | 205 | elseif isequal(nom_type,'i1-i2_j1-j2')
|
---|
[8] | 206 | if isequal(num2str(num_i1),num2str(num_i2))% case of displacements at the same time
|
---|
| 207 | app1= [num2str(num_i1)];
|
---|
| 208 | else
|
---|
| 209 | app1= [num2str(num_i1) '-' num2str(num_i2)];
|
---|
| 210 | end
|
---|
| 211 | if isequal(num2str(num_j1),num2str(num_j2))% case of displacements at the same time
|
---|
| 212 | app2= [num2str(num_j1)];
|
---|
| 213 | else
|
---|
| 214 | app2= [num2str(num_j1) '-' num2str(num_j2)];
|
---|
| 215 | end
|
---|
[122] | 216 | filename=[filename app1 '_' app2 ext];
|
---|
[8] | 217 | end
|
---|
| 218 | idetect=1;
|
---|
| 219 | % idetect=(exist(filename,'file')==2);
|
---|
| 220 | % case of an image pair to determine (comp_input=0)
|
---|
| 221 | else
|
---|
[122] | 222 | [filename,num_i1_out,num_j1_out,num_i2_out,num_j2_out,idetect]=search_pair(filename,num_i1,num_j1,num_i2,nom_type);
|
---|
[8] | 223 | end
|
---|
| 224 |
|
---|
| 225 | %look for sub-directories containing netcdf files
|
---|
| 226 | if idetect==0 && isequal(subdir,'?')
|
---|
| 227 | [pathfile,name]=fileparts(filebase);
|
---|
| 228 | direct=dir(pathfile);%directory containing filebase
|
---|
| 229 | datedir=[];%default
|
---|
| 230 | idir=0;
|
---|
| 231 | indir=find(cell2mat({direct.isdir}));% find indices of subdirectories
|
---|
| 232 | direct=direct(indir([3:end]));% keep only the subdirectories,eliminating the two first terms '.' and '..'
|
---|
| 233 | lengthdir=length(direct);
|
---|
| 234 | if lengthdir==0
|
---|
| 235 | subdir='';% no subdirectory found
|
---|
| 236 | else
|
---|
| 237 | for idir=1:lengthdir
|
---|
| 238 | date_str=direct(idir).date;%string of the date of last modification
|
---|
| 239 | datedir(idir)=0;%default
|
---|
| 240 | char_code=double(date_str);% code of the date characters
|
---|
| 241 | special_char=(char_code>127); %non standard Ascii character (e.g. date in french)
|
---|
| 242 | if isempty(find(special_char))% standard Ascii character
|
---|
| 243 | datedir(idir)=datenum(date_str);
|
---|
| 244 | end
|
---|
| 245 | % datedir(idir)=datenum(direct(idir).date); %absolute date of last directory modification
|
---|
| 246 | end
|
---|
| 247 | [mostrec,indrec]=max(datedir);% most recently modified subdir chosen by default
|
---|
| 248 | subdir=direct(indrec).name; %chosen directory
|
---|
| 249 | end
|
---|
| 250 | filebasesub=fullfile(pathfile,subdir,name);
|
---|
| 251 | %if the image pair is imposed
|
---|
| 252 | if (exist('comp_input','var') & isequal(comp_input,1))
|
---|
| 253 | if isequal(nom_type,'netc_old')|isequal(nom_type,'#_ab')
|
---|
| 254 | filename=[filebasesub num2str(num_i1,'%03d') '_' num2stra(num_j1,nom_type) num2stra(num_j2,nom_type) ext];
|
---|
| 255 | elseif isequal(nom_type,'netc_2D')|isequal(nom_type,'_i1_j1-j2')
|
---|
| 256 | filename=[filebasesub '_' num2str(num_i1) '_' num2str(num_j1) '-' num2str(num_i2) ext];
|
---|
| 257 | elseif isequal(nom_type,'netc_3D')|isequal(nom_type,'_i1-i2_j')
|
---|
| 258 | filename=[filebasesub '_' num2str(num_i1) '-' num2str(num_i2) '_' num2str(num_j1) ext];
|
---|
| 259 | elseif isequal(nom_type,'netc_series')|isequal(nom_type,'_i1-i2')
|
---|
| 260 | filename=[filebasesub '_' num2str(num_i1) '-' num2str(num_i2) ext];
|
---|
| 261 | end
|
---|
| 262 | idetect=(exist(filename,'file')==2);
|
---|
| 263 | else
|
---|
[65] | 264 | [filename,num_i1_out,num_j1_out,num_i2_out,num_j2_out,idetect]=search_pair(filebasesub,num_i1,num_j1,num_i2,nom_type);
|
---|
[8] | 265 | end
|
---|
| 266 | end
|
---|
| 267 | end
|
---|
| 268 | if ~isequal(subdir,'?'), subdir_out=subdir; else, subdir_out='';end;
|
---|
| 269 |
|
---|
[89] | 270 | %------------------------------------------------------------------------
|
---|
| 271 | % --- search the appropriate image pair (netcdf file) corresponding to a given image number
|
---|
[8] | 272 | function [filename,num_i1,num_j1,num_i2,num_j2,idetect]=search_pair(filebasesub,num_i1,num_j1,num_i2,nom_type)
|
---|
[89] | 273 | %------------------------------------------------------------------------
|
---|
[8] | 274 | % for nom_type=netc_2D or netc_old, it searches all the pairs corresponding
|
---|
| 275 | % to num_i1, and chooses the most recent file.
|
---|
| 276 | %for nom_type=netc_3D or netc_series, it searches all the pairs (num_i1
|
---|
| 277 | %num_i2), with num_i1 as the first index, and chooses the most recent file.
|
---|
| 278 |
|
---|
| 279 | filename=[];num_j2=[];idetect=0;%default values
|
---|
| 280 | if isequal(nom_type,'netc_old')|isequal(nom_type,'#_ab')
|
---|
| 281 | dirpair=dir([filebasesub num2str(num_i1,'%03d') '_*.nc']);
|
---|
| 282 | elseif isequal(nom_type,'netc_2D')|isequal(nom_type,'_i_j1-j2')
|
---|
| 283 | dirpair=dir([filebasesub '_' num2str(num_i1) '_*-*.nc']);
|
---|
| 284 | elseif isequal(nom_type,'netc_3D')|isequal(nom_type,'_i1-i2_j')
|
---|
| 285 | dirpair=dir([filebasesub '_' num2str(num_i1) '-*_' num2str(num_j1) '.nc']);
|
---|
| 286 | elseif isequal(nom_type,'netc_series')|isequal(nom_type,'_i1-i2')
|
---|
| 287 | dirpair=dir([filebasesub '_' num2str(num_i1) '-*.nc']);
|
---|
| 288 | if isempty(dirpair)
|
---|
| 289 | dirpair=dir([filebasesub '_*-' num2str(num_i2) '.nc']);
|
---|
| 290 | end
|
---|
| 291 | end
|
---|
| 292 | nbpair=length(dirpair);
|
---|
| 293 | if nbpair >= 1 %choose the most recent file if several are found
|
---|
| 294 | idetect=1; %detected pair
|
---|
| 295 | for ipair=1:nbpair
|
---|
| 296 | date_str=dirpair(ipair).date;%string of the date of last modification
|
---|
| 297 | datepair(ipair)=0;%default
|
---|
| 298 | char_code=double(date_str);% code of the date characters
|
---|
| 299 | special_char=(char_code>127); %non standard Ascii character (e.g. date in french)
|
---|
| 300 | if isempty(find(special_char))% standard Ascii character
|
---|
| 301 | datepair(ipair)=datenum(date_str);
|
---|
| 302 | end
|
---|
| 303 | % datepair(ipair)=datenum(dirpair(ipair).date);
|
---|
| 304 | end
|
---|
| 305 | [choice,indpair]=max(datepair);
|
---|
| 306 | % [filebase,field_count,str2,str_a,str_b,ext,nom_type]=name2display(dirpair(indpair).name);
|
---|
| 307 | [pathname,file,field_count,str2,str_a,str_b,ext,nom_type]=name2display(dirpair(indpair).name);
|
---|
| 308 | num_i1=str2num(field_count);
|
---|
| 309 | num_i2=str2num(str2);
|
---|
| 310 | num_j1=stra2num(str_a);
|
---|
| 311 | num_j2=stra2num(str_b);
|
---|
| 312 | pathname=fileparts(filebasesub);% CORRIGE LE 6 JUIN (ETAIT DESACTIVE)
|
---|
| 313 | filename=fullfile(pathname,dirpair(indpair).name);
|
---|
| 314 | end
|
---|
| 315 |
|
---|
| 316 |
|
---|