source: trunk/src/find_file_series.m @ 334

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

bugs corrected in fileparts_uvmat and find_file_series
name2dispaly replaced by fileparts_uvmat in uvmat, but not in other functions
bug corrected in plot_field, introduction of FileType? in read_field

File size: 5.7 KB
Line 
1%'find_file_series': check the content onf an input field 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=[];%default
39i2=[];%default
40j1=[];%default
41j2=[];%default
42
43%% get input root name and nomenclature type
44% [RootPath,RootFile,~,~,~,~,FileExt,NomType,SubDir]=name2display(fileinput);
45[RootPath,SubDir,RootFile,~,~,~,~,FileExt,NomType]=fileparts_uvmat(fileinput);
46
47%% check for particular file types: images, movies, civ data
48FileType='';
49Object=[];
50switch 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
75        else
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
95end
96if strcmp(NomType,'')||strcmp(NomType,'*')
97    [RootPath,RootFile]=fileparts(fileinput);% case of constant name (no indexing)
98%% get the list of existing files
99else
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)
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)
125            i2(ifile)=i1(ifile);
126        else
127            i2(ifile)=i2_ifile;
128        end
129        end
130        if isempty(j1_ifile)
131            j1(ifile)=1;
132        else
133            j1(ifile)=j1_ifile;
134        end
135        if isempty(j2_ifile)
136            j2(ifile)=j1(ifile);
137        else
138            j2(ifile)=j2_ifile;
139        end
140    end 
141    % TODO : sort by reference index
142    % update the NomType from the minimal index detected (to deal with number strings beginning by 0)
143    [~,ifile]=min(i1);
144    %[~,~,~,~,~,~,~,NomType]=name2display(dirpair(ifile).name);
145    if ~isempty(i1)
146           [~,ifile]=min(i1);
147    [~,~,~,~,~,~,~,~,NomType]=fileparts_uvmat(dirpair(ifile).name);
148    end
149end
Note: See TracBrowser for help on using the repository browser.