Changeset 1009 for trunk/src/find_file_series.m
- Timestamp:
- Jul 22, 2017, 7:20:02 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/find_file_series.m
r977 r1009 11 11 % NomType: nomenclature type corrected after checking the first file (problem of 0 before the number string) 12 12 % FileInfo: structure containing info on the input files (assumed identical on the whole series) 13 14 15 16 17 18 19 13 % FileInfo.FileType: type of file, = 14 % = 'image', usual image as recognised by Matlab 15 % = 'multimage', image series stored in a single file 16 % = 'civx', netcdf file with civx convention 17 % = 'civdata', civ data with new convention 18 % = 'netcdf' other netcdf files 19 % = 'video': movie recognised by VideoReader (e;g. avi) 20 20 % MovieObject: video object (=[] otherwise 21 21 % i1_input,i2_input,j1_input,j2_input: indices of the input file, or of the first file in the series if the input file does not exist … … 23 23 %INPUT 24 24 % FilePath: path to the directory to be scanned 25 % fileinput: name (without path) of the input file sample 25 % fileinput: name (without path) of the input file sample 26 26 % checkxml: =1(default) take into account xml file existence to possibly include indexes in RootFile 27 27 % =0: do not take into account xml file existence … … 53 53 54 54 %% check for particular file types: images, movies, civ data 55 checkfileindexing=0;56 55 if isfield(FileInfo,'FileIndexing') && strcmp(FileInfo.FileIndexing,'on') 57 56 [RootPath,SubDir,RootFile,i1_input,i2_input,j1_input,j2_input,FileExt,NomType]=fileparts_uvmat(fullfileinput); 58 if ~isempty(regexp(SubDir,'^level\d+$')) && exist([RootPath '.xml'],'file')59 NomType='level';60 end57 % if ~isempty(regexp(SubDir,'^level\d+$')) && exist([RootPath '.xml'],'file') 58 % NomType='level'; 59 % end 61 60 i1_series=zeros(1,1,1); 62 61 i2_series=zeros(1,1,1); … … 75 74 return 76 75 end 76 checkfileindexing=0; 77 77 end 78 78 if ~exist(FilePath,'dir') … … 173 173 end 174 174 end 175 if strcmp(NomType,'level') 176 star_string=[RootFile '*' FileExt]; 177 detect_string=['^' RootFile '(?<i1>\d+)' FileExt '$'];%string used in regexp to detect file indices 178 wd=pwd;%current working directory 179 cd (FilePath)% move to the local dir to save time in the operation dir. 180 dirpair=dir(star_string);% look for relevant files in the file directory 181 cd(wd)% back to the working directory 182 nbpair=numel(dirpair); 183 i1_series=zeros(1,nbpair); 184 if nbpair==0% no detected file 185 RootFile=''; 186 end 187 % scan the list of relevant files, extract the indices 188 for ifile=1:nbpair 189 rr=regexp(dirpair(ifile).name,detect_string,'names'); 190 if ~isempty(rr) 191 i1_series(ifile)=str2num(rr.i1); 192 end 193 end 194 % look for the list of subfolders level# 195 cd (RootPath)% move to the local dir to save time in the operation dir. 196 dirpair=dir('level*');% look for relevant subfolders named with leve# 197 cd(wd) 198 [RootPath,SubDir]=fileparts(RootPath); 199 nbpair=numel(dirpair); 200 jfile=0; 201 for ifile=1:nbpair 202 rr=regexp(dirpair(ifile).name,'^level(?<i1>\d+)$','names'); 203 if ~isempty(rr) 204 jfile=jfile+1; 205 j1_series(jfile)=str2num(rr.i1); 206 end 207 end 208 [j1_series,i1_series]=meshgrid(j1_series,i1_series); 209 % i1_series=reshape(i1_series,1,[]); 210 % j1_series=reshape(j1_series,1,[]); 175 % if strcmp(NomType,'level') 176 % star_string=[RootFile '*' FileExt]; 177 % detect_string=['^' RootFile '(?<i1>\d+)' FileExt '$'];%string used in regexp to detect file indices 178 % wd=pwd;%current working directory 179 % cd (FilePath)% move to the local dir to save time in the operation dir. 180 % dirpair=dir(star_string);% look for relevant files in the file directory 181 % cd(wd)% back to the working directory 182 % nbpair=numel(dirpair); 183 % i1_series=zeros(1,nbpair); 184 % if nbpair==0% no detected file 185 % RootFile=''; 186 % end 187 % % scan the list of relevant files, extract the indices 188 % for ifile=1:nbpair 189 % rr=regexp(dirpair(ifile).name,detect_string,'names'); 190 % if ~isempty(rr) 191 % i1_series(ifile)=str2num(rr.i1); 192 % end 193 % end 194 % % look for the list of subfolders level# 195 % cd (RootPath)% move to the local dir to save time in the operation dir. 196 % dirpair=dir('level*');% look for relevant subfolders named with leve# 197 % cd(wd) 198 % [RootPath,SubDir]=fileparts(RootPath); 199 % nbpair=numel(dirpair); 200 % jfile=0; 201 % for ifile=1:nbpair 202 % rr=regexp(dirpair(ifile).name,'^level(?<i1>\d+)$','names'); 203 % if ~isempty(rr) 204 % jfile=jfile+1; 205 % j1_series(jfile)=str2num(rr.i1); 206 % end 207 % end 208 % [j1_series,i1_series]=meshgrid(j1_series,i1_series); 209 % else 210 detect_string=['^' RootFile sep1 i1_str i2_str sep2 j1_str j2_str FileExt '$'];%string used in regexp to detect file indices 211 %find the string used to extract the relevant files with the command dir 212 star_string=[RootFile sep1 i1_star i2_star sep2 j1_star j2_star FileExt]; 213 wd=pwd;%current working directory 214 cd (FilePath)% move to the local dir to save time in the operation dir. 215 dirpair=dir(star_string);% look for relevant files in the file directory 216 cd(wd) 217 nbpair=numel(dirpair); 218 ref_i_list=zeros(1,nbpair); 219 ref_j_list=zeros(1,nbpair); 220 if nbpair==0% no detected file 221 RootFile=''; 222 end 223 % scan the list of relevant files, extract the indices 224 for ifile=1:nbpair 225 rr=regexp(dirpair(ifile).name,detect_string,'names'); 226 if ~isempty(rr) 227 i1=str2num(rr.i1); 228 i2=str2num(regexprep(rr.i2,'^-','')); 229 j1=stra2num(regexprep(rr.j1,'^_','')); 230 j2=stra2num(regexprep(rr.j2,'^-','')); 231 ref_i=i1; 232 if isempty(i2_input) 233 if ~isempty(i2)% invalid file name if i2 does not exist in the input file 234 break 235 end 236 else 237 ref_i=floor((i1+i2)/2); 238 end 239 ref_j=1; 240 if isempty(j1_input) 241 if ~isempty(j1)% invalid file name if j1 does not exist in the input file 242 break 243 end 244 else %j1_input is not empty 245 if isempty(j1)% the detected name does not fit with the input 246 break 247 else 248 ref_j=j1; 249 if isempty(j2_input) 250 if ~isempty(j2)% invalid file name if j2 does not exist in the input file 251 break 252 end 253 else 254 ref_j=floor((j1+j2)/2); 255 end 256 end 257 end 258 % update the detected index series 259 if ~isempty(ref_i)&&~isempty(ref_j) 260 ref_i_list(ifile)=ref_i; 261 ref_j_list(ifile)=ref_j; 262 nb_pairs=0; 263 if ~isempty(i2_input)|| ~isempty(j2_input) %deals with pairs 264 if size(i1_series,1)>=ref_i+1 && size(i1_series,2)>=ref_j+1 265 nb_pairs=numel(find(i1_series(ref_i+1,ref_j+1,:)~=0)); 266 end 267 end 268 if i1==0 269 i1=-1;% set index 0 to -1 to distinguish from the absent index (set to 0) 270 end 271 if j1==0 272 j1=-1;% set index 0 to -1 to distinguish from the absent index (set to 0) 273 end 274 i1_series(ref_i+1,ref_j+1,nb_pairs+1)=i1; 275 if ~isempty(i2_input) 276 i2_series(ref_i+1,ref_j+1,nb_pairs+1)=i2; 277 end 278 if ~isempty(j1_input) 279 j1_series(ref_i+1,ref_j+1,nb_pairs+1)=j1; 280 end 281 if ~isempty(j2_input) 282 j1_series(ref_i+1,ref_j+1,nb_pairs+1)=j1; 283 j2_series(ref_i+1,ref_j+1,nb_pairs+1)=j2; 284 end 285 end 286 end 287 end 288 % look for the numerical string of the first files to update the NomType (take into account the 0 before the number) 289 max_j=max(ref_j_list); 290 if isempty(max_j) 291 ref_ij=ref_i_list; 211 292 else 212 detect_string=['^' RootFile sep1 i1_str i2_str sep2 j1_str j2_str FileExt '$'];%string used in regexp to detect file indices 213 %find the string used to extract the relevant files with the command dir 214 star_string=[RootFile sep1 i1_star i2_star sep2 j1_star j2_star FileExt]; 215 wd=pwd;%current working directory 216 cd (FilePath)% move to the local dir to save time in the operation dir. 217 dirpair=dir(star_string);% look for relevant files in the file directory 218 cd(wd) 219 nbpair=numel(dirpair); 220 ref_i_list=zeros(1,nbpair); 221 ref_j_list=zeros(1,nbpair); 222 if nbpair==0% no detected file 223 RootFile=''; 224 end 225 % scan the list of relevant files, extract the indices 226 for ifile=1:nbpair 227 rr=regexp(dirpair(ifile).name,detect_string,'names'); 228 if ~isempty(rr) 229 i1=str2num(rr.i1); 230 i2=str2num(regexprep(rr.i2,'^-','')); 231 j1=stra2num(regexprep(rr.j1,'^_','')); 232 j2=stra2num(regexprep(rr.j2,'^-','')); 233 ref_i=i1; 234 if isempty(i2_input) 235 if ~isempty(i2)% invalid file name if i2 does not exist in the input file 236 break 237 end 238 else 239 ref_i=floor((i1+i2)/2); 240 end 241 ref_j=1; 242 if isempty(j1_input) 243 if ~isempty(j1)% invalid file name if j1 does not exist in the input file 244 break 245 end 246 else %j1_input is not empty 247 if isempty(j1)% the detected name does not fit with the input 248 break 249 else 250 ref_j=j1; 251 if isempty(j2_input) 252 if ~isempty(j2)% invalid file name if j2 does not exist in the input file 253 break 254 end 255 else 256 ref_j=floor((j1+j2)/2); 257 end 258 end 259 end 260 % update the detected index series 261 if ~isempty(ref_i)&&~isempty(ref_j) 262 ref_i_list(ifile)=ref_i; 263 ref_j_list(ifile)=ref_j; 264 nb_pairs=0; 265 if ~isempty(i2_input)|| ~isempty(j2_input) %deals with pairs 266 if size(i1_series,1)>=ref_i+1 && size(i1_series,2)>=ref_j+1 267 nb_pairs=numel(find(i1_series(ref_i+1,ref_j+1,:)~=0)); 268 end 269 end 270 if i1==0 271 i1=-1;% set index 0 to -1 to distinguish from the absent index (set to 0) 272 end 273 if j1==0 274 j1=-1;% set index 0 to -1 to distinguish from the absent index (set to 0) 275 end 276 i1_series(ref_i+1,ref_j+1,nb_pairs+1)=i1; 277 if ~isempty(i2_input) 278 i2_series(ref_i+1,ref_j+1,nb_pairs+1)=i2; 279 end 280 if ~isempty(j1_input) 281 j1_series(ref_i+1,ref_j+1,nb_pairs+1)=j1; 282 end 283 if ~isempty(j2_input) 284 j1_series(ref_i+1,ref_j+1,nb_pairs+1)=j1; 285 j2_series(ref_i+1,ref_j+1,nb_pairs+1)=j2; 286 end 287 end 288 end 289 end 290 % look for the numerical string of the first files to update the NomType (take into account the 0 before the number) 291 max_j=max(ref_j_list); 292 if isempty(max_j) 293 ref_ij=ref_i_list; 294 else 295 ref_ij=ref_i_list*max_j+ref_j_list; % ordered by index i, then by j for a given i. 296 end 297 ind_select=find(ref_ij>0); 298 299 if ~isempty(ind_select) 300 [tild,ifile_min]=min(ref_ij(ind_select)); 301 [tild,tild,tild,tild,tild,tild,tild,tild,NomType]=fileparts_uvmat(dirpair(ind_select(ifile_min)).name);% update the representation of indices (number of 0 before the number) 302 NomType=regexprep(NomType,['^' NomTypePref],''); 303 %% update the file type if the input file does not exist (pb of 0001) 304 if isempty(FileInfo.FileType) 305 [FileInfo,MovieObject]=get_file_info(fullfile(FilePath,dirpair(ifile_min).name)); 306 end 307 end 308 end 309 end 310 311 %% set to empty array the irrelevant index series 312 if isequal(i1_series,0), i1_series=[]; end 313 if isequal(i2_series,0), i2_series=[]; end 314 if isequal(j1_series,0), j1_series=[]; end 315 if isequal(j2_series,0), j2_series=[]; end 293 ref_ij=ref_i_list*max_j+ref_j_list; % ordered by index i, then by j for a given i. 294 end 295 ind_select=find(ref_ij>0); 296 297 if ~isempty(ind_select) 298 [tild,ifile_min]=min(ref_ij(ind_select)); 299 [tild,tild,tild,tild,tild,tild,tild,tild,NomType]=fileparts_uvmat(dirpair(ind_select(ifile_min)).name);% update the representation of indices (number of 0 before the number) 300 NomType=regexprep(NomType,['^' NomTypePref],''); 301 %% update the file type if the input file does not exist (pb of 0001) 302 if isempty(FileInfo.FileType) 303 [FileInfo,MovieObject]=get_file_info(fullfile(FilePath,dirpair(ifile_min).name)); 304 end 305 end 306 % end 307 end 308 309 %% set to empty array the irrelevant index series 310 if isequal(i1_series,0), i1_series=[]; end 311 if isequal(i2_series,0), i2_series=[]; end 312 if isequal(j1_series,0), j1_series=[]; end 313 if isequal(j2_series,0), j2_series=[]; end 314 315 %% case of isolated input file, not member of an indexed series 316 if isempty(i1_series) 317 [PathDir,RootFile]=fileparts(fullfileinput); 318 [RootPath,SubDir,DirExt]=fileparts(PathDir); 319 SubDir=[SubDir DirExt];% include part after . in the name (considered as a file extension) 320 NomType='*'; 321 i2_series=[];j1_series=[];j2_series=[]; 322 % i1_input=1;i2_input=[];j1_input=[];j2_input=[]; 323 if ~exist(fullfileinput,'file') 324 RootFile=''; 325 return 326 end 327 end 316 328 end 317 329 % %% detect rdvision format … … 332 344 else % if there is a file index, j denotes the frame index while i denotes the file index 333 345 if ~isempty(regexp(NomType,'ab$', 'once'))% recognized as a pair 334 RootFile=fullfile_uvmat('','',RootFile,'',NomType,i1_input,i2_input,j1_input,j2_input);% restitute the root name without the detected indices 346 RootFile=fullfile_uvmat('','',RootFile,'',NomType,i1_input,i2_input,j1_input,j2_input);% restitute the root name without the detected indices 335 347 i1_series=zeros(FileInfo.NumberOfFrames+1,2);% first column =0 336 348 i1_series(:,2)=(0:FileInfo.NumberOfFrames)'; % second column=frame index -1 … … 388 400 end 389 401 end 390 i1_series=permute(i1_series,[3 2 1]);% permute dimensions 402 i1_series=permute(i1_series,[3 2 1]);% permute dimensions 391 403 i2_series=permute(i2_series,[3 2 1]);% permute dimensions 392 j1_series=permute(j1_series,[3 2 1]);% permute dimensions 404 j1_series=permute(j1_series,[3 2 1]);% permute dimensions 393 405 j2_series=permute(j2_series,[3 2 1]);% permute dimensions
Note: See TracChangeset
for help on using the changeset viewer.