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 | |
---|
36 | function [i1,i2,j1,j2,NomType,FileType,Object]=find_file_series(fileinput) |
---|
37 | %------------------------------------------------------------------------ |
---|
38 | i1=NaN;%default |
---|
39 | i2=NaN;%default |
---|
40 | j1=NaN;%default |
---|
41 | j2=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 |
---|
47 | FileType=''; |
---|
48 | Object=[]; |
---|
49 | if ~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 |
---|
59 | else |
---|
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 |
---|
78 | end |
---|
79 | |
---|
80 | %% get the list of existing files |
---|
81 | if ~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); |
---|
133 | end |
---|