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