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 or video), in particular |
---|
8 | % .Height: image height in pixels |
---|
9 | % .Width: image width in pixels |
---|
10 | % .BitDepth: nbre of bits per pixel (8 of 16) |
---|
11 | % .ColorType: 'greyscale' or 'color' |
---|
12 | % .NumberOfFrames |
---|
13 | % .FrameRate: nbre of frames per second, =[] for images |
---|
14 | % Object: in case of video |
---|
15 | % |
---|
16 | % INPUT: |
---|
17 | % fileinput: name, including path, of the file to analyse |
---|
18 | function [FileType,FileInfo,VideoObject]=get_file_type(fileinput) |
---|
19 | FileType='txt';%default, text file |
---|
20 | FileInfo=[]; |
---|
21 | VideoObject=[]; |
---|
22 | [tild,tild,FileExt]=fileparts(fileinput); |
---|
23 | |
---|
24 | switch FileExt |
---|
25 | case '.fig' |
---|
26 | FileType='figure'; |
---|
27 | case '.xml' |
---|
28 | FileType='xml'; |
---|
29 | case '.xls' |
---|
30 | FileType='xls'; |
---|
31 | otherwise |
---|
32 | if ~isempty(FileExt) && ~isempty(imformats(regexprep(FileExt,'^.',''))) |
---|
33 | try |
---|
34 | imainfo=imfinfo(fileinput); |
---|
35 | if length(imainfo) >1 %case of image with multiple frames |
---|
36 | FileType='multimage'; |
---|
37 | FileInfo=imainfo(1);%take info from the first frame |
---|
38 | FileInfo.NumberOfFrames=length(imainfo); |
---|
39 | else |
---|
40 | FileType='image'; |
---|
41 | FileInfo=imainfo; |
---|
42 | FileInfo.NumberOfFrames=1; |
---|
43 | end |
---|
44 | end |
---|
45 | else |
---|
46 | error_nc=0; |
---|
47 | try |
---|
48 | Data=nc2struct(fileinput,'ListGlobalAttribute','absolut_time_T0','Conventions',... |
---|
49 | 'CivStage','patch2','fix2','civ2','patch','fix'); |
---|
50 | if isfield(Data,'Txt') && ~isempty(Data.Txt) |
---|
51 | error_nc=1; |
---|
52 | else |
---|
53 | if ~isempty(Data.absolut_time_T0') |
---|
54 | FileType='civx'; % test for civx velocity fields |
---|
55 | if ~isempty(Data.patch2) && isequal(Data.patch2,1) |
---|
56 | FileInfo.CivStage=6; |
---|
57 | elseif ~isempty(Data.fix2) && isequal(Data.fix2,1) |
---|
58 | FileInfo.CivStage=5; |
---|
59 | elseif ~isempty(Data.civ2) && isequal(Data.civ2,1); |
---|
60 | FileInfo.CivStage=4; |
---|
61 | elseif ~isempty(Data.patch) && isequal(Data.patch,1); |
---|
62 | FileInfo.CivStage=3; |
---|
63 | elseif ~isempty(Data.fix) && isequal(Data.fix,1); |
---|
64 | FileInfo.CivStage=2; |
---|
65 | elseif ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart) |
---|
66 | FileInfo.CivStage=1; |
---|
67 | end |
---|
68 | elseif strcmp(Data.Conventions,'uvmat/civdata') |
---|
69 | FileType='civdata'; % test for civx velocity fields |
---|
70 | FileInfo.CivStage=Data.CivStage; |
---|
71 | else |
---|
72 | FileType='netcdf'; |
---|
73 | end |
---|
74 | end |
---|
75 | catch ME |
---|
76 | error_nc=1; |
---|
77 | end |
---|
78 | if error_nc |
---|
79 | try |
---|
80 | if exist('VideoReader.m','file')%recent version of Matlab |
---|
81 | VideoObject=VideoReader(fileinput); |
---|
82 | FileInfo=get(VideoObject); |
---|
83 | FileType='video'; |
---|
84 | elseif exist('mmreader.m','file')% Matlab 2009a |
---|
85 | VideoObject=mmreader(fileinput); |
---|
86 | FileInfo=get(VideoObject); |
---|
87 | FileType='mmreader'; |
---|
88 | end |
---|
89 | FileInfo.BitDepth=FileInfo.BitsPerPixel/3; |
---|
90 | end |
---|
91 | end |
---|
92 | end |
---|
93 | end |
---|