source: trunk/src/find_file_series.m @ 332

Last change on this file since 332 was 332, checked in by sommeria, 12 years ago

NomType? changed from _i1-i2 ... to _1-2 ... (bugs to be expected!)
bug corrected in geometry_calib
series changed by introducing a from FileIndices?, introduction of find_file_series to detect the file series corresponding to an input file

File size: 5.1 KB
Line 
1%'find_file_series': check the content onf an input fiel and find the corresponding file series
2%--------------------------------------------------------------------------
3% function [i1,i2,j1,j2,NomType,FileType,Object]=find_file_series(fileinput)
4%
5% OUTPUT:
6% i1,i2,j1,j2: set of i1 indices, respectively i2,j1,j2,  of the detected files
7% NomType: nomenclature type corrected after checking the first file (problem of 0 before the number string)
8% FileType: type of file, =
9%       = 'image', usual image as recognised by Matlab
10%       = 'multimage', image series stored in a single file
11%       = 'civx', netcdf file with civx convention
12%       = 'civdata', civ data with new convention
13%       = 'netcdf' other netcdf files
14%       = 'video': movie recognised by VideoReader (e;g. avi)
15% Object: video object (=[] otherwise)
16%
17%INPUT
18% fileinput: name (including path)  of the input file
19%
20%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
21%  Copyright  2011, LEGI / CNRS-UJF-INPG, joel.sommeria@legi.grenoble-inp.fr
22%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
23%     This file is part of the toolbox UVMAT.
24%
25%     UVMAT is free software; you can redistribute it and/or modify
26%     it under the terms of the GNU General Public License as published by
27%     the Free Software Foundation; either version 2 of the License, or
28%     (at your option) any later version.
29%
30%     UVMAT is distributed in the hope that it will be useful,
31%     but WITHOUT ANY WARRANTY; without even the implied warranty of
32%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
34%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
35
36function [i1,i2,j1,j2,NomType,FileType,Object]=find_file_series(fileinput)
37%------------------------------------------------------------------------
38i1=NaN;%default
39i2=NaN;%default
40j1=NaN;%default
41j2=NaN;%default
42
43%% get input root name and nomenclature type
44[RootPath,RootFile,~,~,~,~,FileExt,NomType,SubDir]=name2display(fileinput);
45
46%% check for particular file types: images, movies, civ data
47FileType='';
48Object=[];
49if ~isempty(FileExt)&& ~isempty(imformats(FileExt(2:end)))
50    imainfo=imfinfo(fileinput);
51    FileType='image';
52    if length(imainfo) >1 %case of image with multiple frames
53        NomType='*';
54        FileType='multimage';
55        i1=1;
56        i2=length(imainfo);
57        [RootPath,RootFile]=fileparts(fileinput);
58    end
59else
60    try
61        Data=nc2struct(fileinput,'ListGlobalAttribute',{'absolut_time_T0','Conventions'});
62        if ~isempty(Data,'absolut_time_T0')
63            FileType='civx'; % test for civx velocity fields
64        elseif strcmp(Data.Conventions','uvmat/civdata')
65            FileType='civdata'; % test for civx velocity fields
66        else
67            FileType='netcdf';
68        end     
69    end
70    try
71        Object=VideoReader(fileinput);
72        NomType='*';
73        FileType='video';
74        i1=1;
75        i2=get(Object,'NumberOfFrames');
76        [RootPath,RootFile]=fileparts(fileinput);
77    end
78end
79
80%% get the list of existing files
81if ~strcmp(NomType,'*')
82    if strcmp(SubDir,'')
83        filebasesub=fullfile(RootPath,RootFile);
84    else
85        filebasesub=fullfile(RootPath,SubDir,RootFile);
86    end
87    detect_string=regexprep(NomType,'\d','*');%replace numbers by '*'
88    old_string='';
89    detect_string=regexprep(detect_string,'[ab]$','*');%suppress the possible letter ab at the end
90    detect_string=regexprep(detect_string,'[AB]$','*');%suppress the possible letter ab at the end
91    detect_string=regexprep(detect_string,'[a|A]$','*');%suppress a possible second letter a,A at the end
92    while ~strcmp(detect_string,old_string)%removes multiple '*'
93        old_string=detect_string;
94        detect_string=regexprep(detect_string,'**','*');
95    end
96    dirpair=dir([filebasesub detect_string FileExt]);
97    % switch NomType %TODO: complement for other cases
98    %     case '_0001'
99    %         dirpair=dir([filebasesub '_*' FileExt]);
100    %     case '_1'
101    %         dirpair=dir([filebasesub '_*' FileExt]);
102    %     case '_1_1'
103    %         dirpair=dir([filebasesub '_*_*' FileExt]);
104    %     case '_i1-i2'
105    %         dirpair=dir([filebasesub '_*-*' FileExt]);
106    %     case '1_ab'
107    %         dirpair=dir([filebasesub '*_*' FileExt]);
108    %     case '_i_j1-j2'
109    %         dirpair=dir([filebasesub '*_*-*' FileExt]);
110    %     case '_i1-i2_j'
111    %         dirpair=dir([filebasesub '*-*_*' FileExt]);
112    % end
113    for ifile=1:length(dirpair)
114        [~,~,str_1,str_2,str_a,str_b]=name2display(dirpair(ifile).name);
115        i1(ifile)=str2double(str_1);
116        i2(ifile)=str2double(str_2);
117        if isnan(i2(ifile))
118            i2(ifile)=i1(ifile);
119        end
120        j1(ifile)=stra2num(str_a);
121        if isnan(j1(ifile))
122            j1(ifile)=1;
123        end
124        j2(ifile)=stra2num(str_b);
125        if isnan(j2(ifile))
126            j2(ifile)=j1(ifile);
127        end
128    end
129   
130    % update the NomType from the minimal index detected (to deal with number strings beginning by 0)
131    [~,ifile]=min(i1);
132    [~,~,~,~,~,~,~,NomType]=name2display(dirpair(ifile).name);
133end
Note: See TracBrowser for help on using the repository browser.