[334] | 1 | %'find_file_series': check the content onf an input field and find the corresponding file series |
---|
[332] | 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 | %------------------------------------------------------------------------ |
---|
[334] | 38 | i1=[];%default |
---|
| 39 | i2=[];%default |
---|
| 40 | j1=[];%default |
---|
| 41 | j2=[];%default |
---|
[332] | 42 | |
---|
| 43 | %% get input root name and nomenclature type |
---|
[334] | 44 | % [RootPath,RootFile,~,~,~,~,FileExt,NomType,SubDir]=name2display(fileinput); |
---|
| 45 | [RootPath,SubDir,RootFile,~,~,~,~,FileExt,NomType]=fileparts_uvmat(fileinput); |
---|
[332] | 46 | |
---|
| 47 | %% check for particular file types: images, movies, civ data |
---|
| 48 | FileType=''; |
---|
| 49 | Object=[]; |
---|
[334] | 50 | switch FileExt |
---|
| 51 | % ancillary files, no field indexing |
---|
| 52 | case {'.civ','.log','.cmx','.cmx2','.txt','.bat'} |
---|
| 53 | FileType='txt'; |
---|
| 54 | NomType=''; |
---|
| 55 | case '.fig' |
---|
| 56 | FileType='figure'; |
---|
| 57 | NomType=''; |
---|
| 58 | case '.xml' |
---|
| 59 | FileType='xml'; |
---|
| 60 | NomType=''; |
---|
| 61 | case '.xls' |
---|
| 62 | FileType='xls'; |
---|
| 63 | NomType=''; |
---|
| 64 | otherwise |
---|
| 65 | if ~isempty(FileExt)&& ~isempty(imformats(FileExt(2:end))) |
---|
| 66 | imainfo=imfinfo(fileinput); |
---|
| 67 | FileType='image'; |
---|
| 68 | if length(imainfo) >1 %case of image with multiple frames |
---|
| 69 | NomType='*'; |
---|
| 70 | FileType='multimage'; |
---|
| 71 | i1=1; |
---|
| 72 | i2=length(imainfo); |
---|
| 73 | [RootPath,RootFile]=fileparts(fileinput); |
---|
| 74 | end |
---|
[332] | 75 | else |
---|
[334] | 76 | try |
---|
| 77 | Data=nc2struct(fileinput,'ListGlobalAttribute','absolut_time_T0','Conventions'); |
---|
| 78 | if ~isempty(Data.absolut_time_T0') |
---|
| 79 | FileType='civx'; % test for civx velocity fields |
---|
| 80 | elseif strcmp(Data.Conventions','uvmat/civdata') |
---|
| 81 | FileType='civdata'; % test for civx velocity fields |
---|
| 82 | else |
---|
| 83 | FileType='netcdf'; |
---|
| 84 | end |
---|
| 85 | end |
---|
| 86 | try |
---|
| 87 | Object=VideoReader(fileinput); |
---|
| 88 | NomType='*'; |
---|
| 89 | FileType='video'; |
---|
| 90 | i1=1; |
---|
| 91 | i2=get(Object,'NumberOfFrames'); |
---|
| 92 | [RootPath,RootFile]=fileparts(fileinput); |
---|
| 93 | end |
---|
| 94 | end |
---|
[332] | 95 | end |
---|
[334] | 96 | if strcmp(NomType,'')||strcmp(NomType,'*') |
---|
| 97 | [RootPath,RootFile]=fileparts(fileinput);% case of constant name (no indexing) |
---|
[332] | 98 | %% get the list of existing files |
---|
[334] | 99 | else |
---|
[332] | 100 | if strcmp(SubDir,'') |
---|
| 101 | filebasesub=fullfile(RootPath,RootFile); |
---|
| 102 | else |
---|
| 103 | filebasesub=fullfile(RootPath,SubDir,RootFile); |
---|
| 104 | end |
---|
| 105 | detect_string=regexprep(NomType,'\d','*');%replace numbers by '*' |
---|
| 106 | old_string=''; |
---|
| 107 | detect_string=regexprep(detect_string,'[ab]$','*');%suppress the possible letter ab at the end |
---|
| 108 | detect_string=regexprep(detect_string,'[AB]$','*');%suppress the possible letter ab at the end |
---|
| 109 | detect_string=regexprep(detect_string,'[a|A]$','*');%suppress a possible second letter a,A at the end |
---|
| 110 | while ~strcmp(detect_string,old_string)%removes multiple '*' |
---|
| 111 | old_string=detect_string; |
---|
| 112 | detect_string=regexprep(detect_string,'**','*'); |
---|
| 113 | end |
---|
| 114 | dirpair=dir([filebasesub detect_string FileExt]); |
---|
| 115 | for ifile=1:length(dirpair) |
---|
[334] | 116 | % [~,~,str_1,str_2,str_a,str_b]=name2display(dirpair(ifile).name); |
---|
| 117 | dirpair(ifile).name |
---|
| 118 | [~,~,~,i1_ifile,i2_ifile,j1_ifile,j2_ifile]=fileparts_uvmat(dirpair(ifile).name); |
---|
| 119 | if isempty(i1_ifile) |
---|
| 120 | i1(ifile)=1; |
---|
| 121 | else |
---|
| 122 | i1(ifile)=i1_ifile; |
---|
| 123 | end |
---|
| 124 | if isempty(i2_ifile) |
---|
[332] | 125 | i2(ifile)=i1(ifile); |
---|
[334] | 126 | else |
---|
| 127 | i2(ifile)=i2_ifile; |
---|
[332] | 128 | end |
---|
[334] | 129 | end |
---|
| 130 | if isempty(j1_ifile) |
---|
[332] | 131 | j1(ifile)=1; |
---|
[334] | 132 | else |
---|
| 133 | j1(ifile)=j1_ifile; |
---|
[332] | 134 | end |
---|
[334] | 135 | if isempty(j2_ifile) |
---|
[332] | 136 | j2(ifile)=j1(ifile); |
---|
[334] | 137 | else |
---|
| 138 | j2(ifile)=j2_ifile; |
---|
[332] | 139 | end |
---|
[334] | 140 | end |
---|
| 141 | % TODO : sort by reference index |
---|
[332] | 142 | % update the NomType from the minimal index detected (to deal with number strings beginning by 0) |
---|
| 143 | [~,ifile]=min(i1); |
---|
[334] | 144 | %[~,~,~,~,~,~,~,NomType]=name2display(dirpair(ifile).name); |
---|
| 145 | if ~isempty(i1) |
---|
| 146 | [~,ifile]=min(i1); |
---|
| 147 | [~,~,~,~,~,~,~,~,NomType]=fileparts_uvmat(dirpair(ifile).name); |
---|
| 148 | end |
---|
[332] | 149 | end |
---|