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=''; |
---|
20 | FileInfo=[]; |
---|
21 | VideoObject=[]; |
---|
22 | [tild,tild,FileExt]=fileparts(fileinput); |
---|
23 | |
---|
24 | switch FileExt |
---|
25 | case {'.civ','.log','.cmx','.cmx2','.txt','.bat','.m','.sh'} |
---|
26 | FileType='txt'; |
---|
27 | case '.fig' |
---|
28 | FileType='figure'; |
---|
29 | case '.xml' |
---|
30 | FileType='xml'; |
---|
31 | case '.xls' |
---|
32 | FileType='xls'; |
---|
33 | otherwise |
---|
34 | if ~isempty(FileExt) && ~isempty(imformats(regexprep(FileExt,'^.',''))) |
---|
35 | try |
---|
36 | imainfo=imfinfo(fileinput); |
---|
37 | if length(imainfo) >1 %case of image with multiple frames |
---|
38 | FileType='multimage'; |
---|
39 | FileInfo=imainfo(1);%take info from the first frame |
---|
40 | FileInfo.NumberOfFrames=length(imainfo); |
---|
41 | else |
---|
42 | FileType='image'; |
---|
43 | FileInfo=imainfo; |
---|
44 | FileInfo.NumberOfFrames=1; |
---|
45 | end |
---|
46 | end |
---|
47 | else |
---|
48 | error_nc=0; |
---|
49 | try |
---|
50 | Data=nc2struct(fileinput,'ListGlobalAttribute','absolut_time_T0','Conventions',... |
---|
51 | 'CivStage','patch2','fix2','civ2','patch','fix'); |
---|
52 | if isfield(Data,'Txt') && ~isempty(Data.Txt) |
---|
53 | error_nc=1; |
---|
54 | else |
---|
55 | if ~isempty(Data.absolut_time_T0') |
---|
56 | FileType='civx'; % test for civx velocity fields |
---|
57 | if ~isempty(Data.patch2) && isequal(Data.patch2,1) |
---|
58 | FileInfo.CivStage=6; |
---|
59 | elseif ~isempty(Data.fix2) && isequal(Data.fix2,1) |
---|
60 | FileInfo.CivStage=5; |
---|
61 | elseif ~isempty(Data.civ2) && isequal(Data.civ2,1); |
---|
62 | FileInfo.CivStage=4; |
---|
63 | elseif ~isempty(Data.patch) && isequal(Data.patch,1); |
---|
64 | FileInfo.CivStage=3; |
---|
65 | elseif ~isempty(Data.fix) && isequal(Data.fix,1); |
---|
66 | FileInfo.CivStage=2; |
---|
67 | elseif ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart) |
---|
68 | FileInfo.CivStage=1; |
---|
69 | end |
---|
70 | elseif strcmp(Data.Conventions,'uvmat/civdata') |
---|
71 | FileType='civdata'; % test for civx velocity fields |
---|
72 | FileInfo.CivStage=Data.CivStage; |
---|
73 | else |
---|
74 | FileType='netcdf'; |
---|
75 | end |
---|
76 | end |
---|
77 | catch ME |
---|
78 | error_nc=1; |
---|
79 | end |
---|
80 | if error_nc |
---|
81 | try |
---|
82 | if exist('VideoReader.m','file')%recent version of Matlab |
---|
83 | VideoObject=VideoReader(fileinput); |
---|
84 | FileInfo=get(VideoObject); |
---|
85 | FileType='video'; |
---|
86 | elseif exist('mmreader.m','file')% Matlab 2009a |
---|
87 | VideoObject=mmreader(fileinput); |
---|
88 | FileInfo=get(VideoObject); |
---|
89 | FileType='mmreader'; |
---|
90 | end |
---|
91 | FileInfo.BitDepth=FileInfo.BitsPerPixel/3; |
---|
92 | end |
---|
93 | end |
---|
94 | end |
---|
95 | end |
---|