source: trunk/src/get_file_type.m @ 432

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

civ_matlab and patch improved, changes in the management of interpolation (still in progress).
adapatation to movies (use of VideoReader?)

File size: 3.1 KB
Line 
1%'get_file_type': determine info about a file (image, multimage, civdata,...) .
2%------------------------------------------------------------------------
3% [FileType,FileInfo,Object]=get_file_type(fileinput)
4%
5% OUTPUT:
6% FileType: type of file
7% FileInfo: structure containing info on the file (case of images)
8% Object: in case of video
9%
10% INPUT:
11% fileinput: name, including path, of the file to analyse
12function [FileType,FileInfo,VideoObject]=get_file_type(fileinput)
13FileType='';
14FileInfo=[];
15VideoObject=[];
16[tild,tild,FileExt]=fileparts(fileinput);
17
18switch FileExt
19    case {'.civ','.log','.cmx','.cmx2','.txt','.bat'}
20        FileType='txt';
21    case '.fig'
22        FileType='figure';
23    case '.xml'
24        FileType='xml';
25    case '.xls'
26        FileType='xls';
27    otherwise
28        if ~isempty(FileExt)&& ~isempty(imformats(FileExt(2:end)))
29            try
30                FileType='image';
31                imainfo=imfinfo(fileinput);
32                if length(imainfo) >1 %case of image with multiple frames
33                    FileType='multimage';
34                    FileInfo.NbFrame=length(imainfo);
35                end
36            end
37        else
38            error_nc=0;
39            try
40                Data=nc2struct(fileinput,'ListGlobalAttribute','absolut_time_T0','Conventions',...
41                    'CivStage','patch2','fix2','civ2','patch','fix');
42                if isfield(Data,'Txt') && ~isempty(Data.Txt)
43                    error_nc=1;
44                else
45                    if ~isempty(Data.absolut_time_T0')
46                        FileType='civx'; % test for civx velocity fields
47                        if ~isempty(Data.patch2) && isequal(Data.patch2,1)
48                            FileInfo.CivStage=6;
49                        elseif ~isempty(Data.fix2) && isequal(Data.fix2,1)
50                            FileInfo.CivStage=5;
51                        elseif ~isempty(Data.civ2) && isequal(Data.civ2,1);
52                            FileInfo.CivStage=4;
53                        elseif ~isempty(Data.patch) && isequal(Data.patch,1);
54                            FileInfo.CivStage=3;
55                        elseif ~isempty(Data.fix) && isequal(Data.fix,1);
56                            FileInfo.CivStage=2;
57                        elseif ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart)
58                            FileInfo.CivStage=1;
59                        end
60                    elseif strcmp(Data.Conventions,'uvmat/civdata')
61                        FileType='civdata'; % test for civx velocity fields
62                        FileInfo.CivStage=Data.CivStage;
63                    else
64                        FileType='netcdf';
65                    end
66                end
67            catch ME
68                error_nc=1;
69            end
70            if error_nc
71                try
72                    if exist('VideoReader.m','file')%recent version of Matlab
73                        VideoObject=VideoReader(fileinput);
74                        FileInfo.NumberOfFrames=get(VideoObject,'NumberOfFrames');
75                        FileType='video';
76                    end             
77                end
78            end
79        end
80end
Note: See TracBrowser for help on using the repository browser.