Ignore:
Timestamp:
Jan 9, 2012, 1:16:35 AM (12 years ago)
Author:
sommeria
Message:

civ: bugs corrected. Iintroduction of an xm file for parameters read using the new fct fill_GUI (to test and improve)
cleaning in uvmat. Possibility of using blank increment added (go to the next available file)
fullfile_uvmat: case of two equal indices in a pair, bug repair.
find_fileseries: improved speed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/find_file_series.m

    r356 r360  
    8888            try
    8989                if exist('VideoReader','file')%recent version of Matlab
    90                     Object=VideoReader(fileinput);   
     90                    Object=VideoReader(fileinput);
    9191                else
    92                     Object=mmreader(fileinput);%older Matlab function for movies               
     92                    Object=mmreader(fileinput);%older Matlab function for movies
    9393                end
    9494                NomType='*';
    95                 FileType='video'; 
     95                FileType='video';
    9696                i1_series=(1:get(Object,'NumberOfFrames'))';
    9797            end
     
    9999end
    100100
    101 %% get the list of existing files when relevant
    102101if strcmp(NomType,'')||strcmp(NomType,'*')
    103102    if exist(fileinput,'file')
    104     [RootPath,RootFile]=fileparts(fileinput);% case of constant name (no indexing)
     103        [RootPath,RootFile]=fileparts(fileinput);% case of constant name (no indexing)
    105104    else
    106        RootPath='';
    107        RootFile='';
    108     end
    109 else
    110     if strcmp(SubDir,'')
    111         filebasesub=fullfile(RootPath,RootFile);
    112     else
    113         filebasesub=fullfile(RootPath,SubDir,RootFile);
    114     end
    115     detect_string=regexprep(NomType,'\d','*');%replace numbers by '*'
    116     old_string='';
    117     detect_string=regexprep(detect_string,'[ab]$','*');%suppress the possible letter ab at the end
    118     detect_string=regexprep(detect_string,'[AB]$','*');%suppress the possible letter ab at the end
    119     detect_string=regexprep(detect_string,'[a|A]$','*');%suppress a possible second letter a,A at the end
    120     while ~strcmp(detect_string,old_string)%removes multiple '*'
    121         old_string=detect_string;
    122         detect_string=regexprep(detect_string,'**','*');
    123     end
    124     dirpair=dir([filebasesub detect_string FileExt]);
     105        RootPath='';
     106        RootFile='';
     107    end
     108else   
     109    %% analyse the list of existing files when relevant
     110    sep1='';
     111    i1_str='(?<i1>)';
     112    i1_star='';
     113    sep2='';
     114    i2_str='(?<i2>)';
     115    i2_star='';
     116    sep3='';
     117    j1_str='(?<j1>)';
     118    j1_star='';
     119    sep4='';
     120    j2_str='(?<j2>)';
     121    j2_star='';
     122    NomTypeStr=NomType;
     123    if ~isempty(regexp(NomTypeStr,'^_\d'))
     124        sep1='_';
     125        NomTypeStr(1)=[];%remove '_' from the beginning of NomTypeStr
     126    end
     127    r=regexp(NomTypeStr,'^(?<num1>\d+)','names');%look for a number at the beginning of NomTypeStr
     128    if ~isempty(r)
     129        i1_str='(?<i1>\d+)';
     130        i1_star='*';
     131        NomTypeStr=regexprep(NomTypeStr,['^' r.num1],'');
     132        r=regexp(NomTypeStr,'^-(?<num2>\d+)','names');%look for a pair i1-i2
     133        if ~isempty(r)
     134            sep2='-';
     135            i2_str='(?<i2>\d+)';
     136            i2_star='*';
     137            NomTypeStr=regexprep(NomTypeStr,['^-' r.num2],'');
     138        end
     139        if ~isempty(regexp(NomTypeStr,'^_'));
     140            sep3='_';
     141            NomTypeStr(1)=[];%remove '_' from the beginning of NomTypeStr
     142        end
     143        if ~isempty(regexp(NomTypeStr,'^[a|A]'));
     144            j1_str='(?<j1>[a-z]|[A-Z])';
     145            j1_star='*';
     146            if ~isempty(regexp(NomTypeStr,'[b|B]$'));
     147                j2_str='(?<j1>[a-z]|[A-Z])';
     148                j2_star='*';
     149            end
     150        else
     151            r=regexp(NomTypeStr,'^(?<num3>\d+)','names');
     152            if ~isempty(r)
     153                j1_str='(?<j1>\d+)';
     154                 j1_star='*';
     155                NomTypeStr=regexprep(NomTypeStr,['^' r.num3],'');
     156            end
     157            r=regexp(NomTypeStr,'-(?<num4>\d+)','names');
     158            if ~isempty(r)
     159                sep4='-';
     160                j2_str='(?<j2>\d+)';
     161                 j2_star='*';
     162            end
     163        end
     164    end
     165    detect_string=[sep1 i1_str sep2 i2_str sep3 j1_str sep4 j2_str];%string used in regexp to detect file indices
     166    %find the string used to extract the relevant files with the command dir
     167    star_string=['*' sep1 i1_star sep2 i2_star sep3 j1_star sep4 j2_star '*'];
     168    wd=pwd;%current working directory
     169    RR=fullfile(RootPath,SubDir);
     170    cd (RR)% move to the local dir to save time in the operation dir.
     171    dirpair=dir([RootFile star_string FileExt]);% look for relevant files in the file directory
     172    cd(wd)
    125173    nbpair=numel(dirpair);
    126174    ref_i_list=zeros(1,nbpair);
     
    130178        RootFile='';
    131179    end
     180    % scan the list of relevant files, extract the indices
    132181    for ifile=1:nbpair
    133         [tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(dirpair(ifile).name);
     182        rr=regexp(dirpair(ifile).name,detect_string,'names');
     183        i1=str2num(rr.i1);
     184        i2=str2num(rr.i2);
     185        j1=stra2num(rr.j1);
     186        j2=stra2num(rr.j2);
    134187        ref_i=i1;
    135188        if isempty(i2_input)
     
    187240        ref_ij=ref_i_list*max_j+ref_j_list; % ordered by index i, then by j for a given i.
    188241    end
    189     [tild,ifile]=min(ref_ij(ref_ij>0));
    190     if isempty(ifile)
     242    [tild,ifile_min]=min(ref_ij(ref_ij>0));
     243    if isempty(ifile_min)
    191244        RootPath='';
    192245        RootFile='';
    193246        NomType='';
    194247    else
    195     [tild,tild,tild,tild,tild,tild,tild,tild,NomType]=fileparts_uvmat(dirpair(ifile).name);
     248        [tild,tild,tild,tild,tild,tild,tild,tild,NomType]=fileparts_uvmat(dirpair(ifile_min).name);
    196249    end
    197250end
Note: See TracChangeset for help on using the changeset viewer.