Changeset 388 for trunk/src/find_file_series.m
- Timestamp:
- Apr 6, 2012, 4:37:12 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/find_file_series.m
r386 r388 54 54 [FileType,FileInfo,Object]=get_file_type(fullfileinput); 55 55 if strcmp( FileType,'multimage')||strcmp( FileType,'video') 56 57 56 NomType='*'; 57 i1_series=(1:FileInfo.NbFrame)'; 58 58 end 59 59 … … 61 61 if exist(fullfileinput,'file') 62 62 [tild,RootFile]=fileparts(fileinput);% case of constant name (no indexing) 63 else 63 else 64 64 RootFile=''; 65 65 end 66 else 67 %% possibly include the first index in the root name, if there exists a corresponding xml file 66 else 67 %% possibly include the first index in the root name, if there exists a corresponding xml file 68 % RootFileNew=RootFile; 69 % if ~isempty(regexp(NomType,['^_'])) 70 % NomTypePref='_'; 71 % RootFileNew=[RootFileNew '_']; 72 % end RootPath=''; 68 73 NomTypePref=''; 69 RootFileNew=RootFile;70 % if ~isempty(regexp(NomType,['^_']))71 % NomTypePref='_';72 % RootFileNew=[RootFileNew '_'];73 % end RootPath='';74 74 r=regexp(NomType,'^(?<tiretnum>_?\d+)','names');%look for a number or _1 at the beginning of NomType 75 % r=regexp(NomType,['^' NomTypePref '(?<num1>\d+)'],'names');%look for a number at the beginning of NomTypeSt75 % r=regexp(NomType,['^' NomTypePref '(?<num1>\d+)'],'names');%look for a number at the beginning of NomTypeSt 76 76 if ~isempty(r) 77 NomTypePref=r.tiretnum; 78 fileinput_end=regexprep(fileinput,['^' RootFileNew],''); 79 r=regexp(fileinput_end,'^(?<num1>\d+)','names'); 80 if ~isempty(r) 81 RootFileNew=[RootFileNew r.num1]; 82 end 83 if exist(fullfile(RootPath,[RootFileNew '.xml']),'file') 84 RootFile=RootFileNew; 85 NomType=regexprep(NomType,['^' NomTypePref],''); 86 i2_input=j2_input; 87 j1_input=[]; 88 j2_input=[]; 89 else 90 NomTypePref=''; 77 fileinput_end=regexprep(fileinput,['^' RootFile],'');%remove RootFile at the beginning of fileinput 78 if isempty(regexp(r.tiretnum,'^_'))% if a separator '_' is not detected 79 rr=regexp(fileinput_end,'^(?<i1>\d+)','names'); 80 else% if a separator '_' is detected 81 rr=regexp(fileinput_end,'^(?<i1>_\d+)','names'); 82 end 83 if ~isempty(rr) 84 RootFileNew=[RootFile rr.i1]; 85 if exist(fullfile(RootPath,[RootFileNew '.xml']),'file') 86 RootFile=RootFileNew; 87 NomType=regexprep(NomType,['^' NomTypePref],''); 88 NomTypePref=r.tiretnum; 89 i2_input=j2_input; 90 j1_input=[]; 91 j2_input=[]; 92 end 91 93 end 92 94 end 93 95 %% analyse the list of existing files when relevant 94 96 sep1=''; 95 i1_str='(?<i1>)'; 97 i1_str='(?<i1>)';%will set i1=[]; 96 98 i1_star=''; 97 sep2='';98 i2_str='(?<i2>)'; 99 % r.sep2=''; 100 i2_str='(?<i2>)';%will set i2=[]; 99 101 i2_star=''; 100 sep3='';101 j1_str='(?<j1>)'; 102 % sep3=''; 103 j1_str='(?<j1>)';%will set j1=[]; 102 104 j1_star=''; 103 sep4='';104 j2_str='(?<j2>)'; 105 % sep4=''; 106 j2_str='(?<j2>)';%will set j2=[]; 105 107 j2_star=''; 106 NomTypeStr=NomType; 107 if ~isempty(regexp(NomTypeStr,'^_\d')) 108 sep1='_'; 109 NomTypeStr(1)=[];%remove '_' from the beginning of NomTypeStr 110 end 111 r=regexp(NomTypeStr,'^(?<num1>\d+)','names');%look for a number at the beginning of NomTypeStr 108 % NomTypeStr=NomType; 109 %Look for cases with letter indexing for the second index 110 r=regexp(NomType,'^(?<sep1>_?)(?<i1>\d+)(?<j1>[a|A])(?<j2>[b|B]?)$','names'); 112 111 if ~isempty(r) 113 i1_str='(?<i1>\d+)'; 114 i1_star='*'; 115 NomTypeStr=regexprep(NomTypeStr,['^' r.num1],''); 116 r=regexp(NomTypeStr,'^-(?<num2>\d+)','names');%look for a pair i1-i2 112 sep1=r.sep1; 113 if strcmp(lower(r.j1),r.j1) 114 j1_str='(?<j1>[a-z])'; 115 else 116 j1_str='(?<j1>[A-Z])'; 117 end 118 j1_star='*'; 119 if ~isempty(r.j2) 120 if strcmp(lower(r.j1),r.j1) 121 j2_str='(?<j2>[a-z])'; 122 else 123 j2_str='(?<j2>[A-Z])'; 124 end 125 j2_star='*'; 126 end 127 else %numerical indexing 128 r=regexp(NomType,'^(?<sep1>_?)(?<i1>\d+)(?<i2>(-\d+)?)(?<j1>(_\d+)?)(?<j2>(-\d+)?)$','names'); 117 129 if ~isempty(r) 118 sep2='-'; 119 i2_str='(?<i2>\d+)'; 120 i2_star='*'; 121 NomTypeStr=regexprep(NomTypeStr,['^-' r.num2],''); 122 end 123 if ~isempty(regexp(NomTypeStr,'^_')); 124 sep3='_'; 125 NomTypeStr(1)=[];%remove '_' from the beginning of NomTypeStr 126 end 127 if ~isempty(regexp(NomTypeStr,'^[a|A]')); 128 j1_str='(?<j1>[a-z]|[A-Z])'; 129 j1_star='*'; 130 if ~isempty(regexp(NomTypeStr,'[b|B]$')); 131 j2_str='(?<j2>[a-z]|[A-Z])'; 132 j2_star='*'; 133 end 134 else 135 r=regexp(NomTypeStr,'^(?<num3>\d+)','names'); 136 if ~isempty(r) 137 j1_str='(?<j1>\d+)'; 138 j1_star='*'; 139 NomTypeStr=regexprep(NomTypeStr,['^' r.num3],''); 140 end 141 r=regexp(NomTypeStr,'-(?<num4>\d+)','names'); 142 if ~isempty(r) 143 sep4='-'; 144 j2_str='(?<j2>\d+)'; 145 j2_star='*'; 146 end 147 end 148 end 149 detect_string=['^' RootFile sep1 i1_str sep2 i2_str sep3 j1_str sep4 j2_str FileExt '$'];%string used in regexp to detect file indices 130 sep1=r.sep1; 131 i1_str='(?<i1>\d+)'; 132 i1_star='*'; 133 if ~isempty(r.i2) 134 i2_str='(?<i2>-\d+)'; 135 i2_star='-*'; 136 end 137 if ~isempty(r.j1) 138 j1_str='(?<j1>_\d+)'; 139 j1_star='_*'; 140 end 141 if ~isempty(r.j2) 142 j2_str='(?<j2>-\d+)'; 143 j2_star='-*'; 144 end 145 end 146 end 147 detect_string=['^' RootFile sep1 i1_str i2_str j1_str j2_str FileExt '$'];%string used in regexp to detect file indices 150 148 %find the string used to extract the relevant files with the command dir 151 star_string=[RootFile sep1 i1_star sep2 i2_star sep3 j1_star sep4 j2_star '*'];149 star_string=[RootFile sep1 i1_star i2_star j1_star j2_star FileExt]; 152 150 wd=pwd;%current working directory 153 151 cd (RootPath)% move to the local dir to save time in the operation dir. 154 dirpair=dir( [star_string FileExt]);% look for relevant files in the file directory152 dirpair=dir(star_string);% look for relevant files in the file directory 155 153 cd(wd) 156 154 nbpair=numel(dirpair); … … 158 156 ref_j_list=zeros(1,nbpair); 159 157 if nbpair==0% no detected file 160 % RootPath='';158 % RootPath=''; 161 159 RootFile=''; 162 160 end … … 165 163 rr=regexp(dirpair(ifile).name,detect_string,'names'); 166 164 if ~isempty(rr) 167 i1=str2num(rr.i1); 168 i2=str2num(rr.i2); 169 j1=stra2num(rr.j1); 170 j2=stra2num(rr.j2); 171 ref_i=i1; 172 if isempty(i2_input) 173 if ~isempty(i2)% invalid file name if i2 does not exist in the input file 174 break 175 end 176 else 177 ref_i=floor((i1+i2)/2); 178 end 179 ref_j=1; 180 if isempty(j1_input) 181 if ~isempty(j1)% invalid file name if j1 does not exist in the input file 182 break 183 end 184 else %j1_input is not empty 185 if isempty(j1)% the detected name does not fit with the input 186 break 165 i1=str2num(rr.i1); 166 i2=str2num(regexprep(rr.i2,'^-','')); 167 j1=stra2num(regexprep(rr.j1,'^_','')); 168 j2=stra2num(regexprep(rr.j2,'^-','')); 169 ref_i=i1; 170 if isempty(i2_input) 171 if ~isempty(i2)% invalid file name if i2 does not exist in the input file 172 break 173 end 187 174 else 188 ref_j=j1; 189 if isempty(j2_input) 190 if ~isempty(j2)% invalid file name if j2 does not exist in the input file 191 break 175 ref_i=floor((i1+i2)/2); 176 end 177 ref_j=1; 178 if isempty(j1_input) 179 if ~isempty(j1)% invalid file name if j1 does not exist in the input file 180 break 181 end 182 else %j1_input is not empty 183 if isempty(j1)% the detected name does not fit with the input 184 break 185 else 186 ref_j=j1; 187 if isempty(j2_input) 188 if ~isempty(j2)% invalid file name if j2 does not exist in the input file 189 break 190 end 191 else 192 ref_j=floor((j1+j2)/2); 192 193 end 193 else 194 ref_j=floor((j1+j2)/2); 195 end 196 end 197 end 198 % update the detected index series 199 ref_i_list(ifile)=ref_i; 200 ref_j_list(ifile)=ref_j; 201 nb_pairs=0; 202 if ~isempty(i2_input)|| ~isempty(j2_input) %deals with pairs 203 if size(i1_series,1)>=ref_i+1 && size(i1_series,2)>=ref_j+1 204 nb_pairs=numel(find(i1_series(ref_i+1,ref_j+1,:)~=0)); 205 end 206 end 207 i1_series(ref_i+1,ref_j+1,nb_pairs+1)=i1; 208 if ~isempty(i2_input) 209 i2_series(ref_i+1,ref_j+1,nb_pairs+1)=i2; 210 end 211 if ~isempty(j1_input) 212 j1_series(ref_i+1,ref_j+1,nb_pairs+1)=j1; 213 end 214 if ~isempty(j2_input) 215 j1_series(ref_i+1,ref_j+1,nb_pairs+1)=j1; 216 j2_series(ref_i+1,ref_j+1,nb_pairs+1)=j2; 217 end 194 end 195 end 196 % update the detected index series 197 ref_i_list(ifile)=ref_i; 198 ref_j_list(ifile)=ref_j; 199 nb_pairs=0; 200 if ~isempty(i2_input)|| ~isempty(j2_input) %deals with pairs 201 if size(i1_series,1)>=ref_i+1 && size(i1_series,2)>=ref_j+1 202 nb_pairs=numel(find(i1_series(ref_i+1,ref_j+1,:)~=0)); 203 end 204 end 205 i1_series(ref_i+1,ref_j+1,nb_pairs+1)=i1; 206 if ~isempty(i2_input) 207 i2_series(ref_i+1,ref_j+1,nb_pairs+1)=i2; 208 end 209 if ~isempty(j1_input) 210 j1_series(ref_i+1,ref_j+1,nb_pairs+1)=j1; 211 end 212 if ~isempty(j2_input) 213 j1_series(ref_i+1,ref_j+1,nb_pairs+1)=j1; 214 j2_series(ref_i+1,ref_j+1,nb_pairs+1)=j2; 215 end 218 216 end 219 217 end … … 227 225 [tild,ifile_min]=min(ref_ij(ref_ij>0)); 228 226 if isempty(ifile_min) 229 % RootPath='';227 % RootPath=''; 230 228 RootFile=''; 231 229 NomType=''; … … 239 237 end 240 238 end 241 242 243 239 244 240 %% set to empty array the irrelevant index series
Note: See TracChangeset
for help on using the changeset viewer.