[380] | 1 | %'get_file_type': determine info about a file (image, multimage, civdata,...) . |
---|
[376] | 2 | %------------------------------------------------------------------------ |
---|
[380] | 3 | % [FileType,FileInfo,Object]=get_file_type(fileinput) |
---|
[376] | 4 | % |
---|
| 5 | % OUTPUT: |
---|
| 6 | % FileType: type of file |
---|
[469] | 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 |
---|
[376] | 14 | % Object: in case of video |
---|
| 15 | % |
---|
| 16 | % INPUT: |
---|
| 17 | % fileinput: name, including path, of the file to analyse |
---|
[397] | 18 | function [FileType,FileInfo,VideoObject]=get_file_type(fileinput) |
---|
[376] | 19 | FileType=''; |
---|
| 20 | FileInfo=[]; |
---|
[397] | 21 | VideoObject=[]; |
---|
[376] | 22 | [tild,tild,FileExt]=fileparts(fileinput); |
---|
| 23 | |
---|
| 24 | switch FileExt |
---|
| 25 | case {'.civ','.log','.cmx','.cmx2','.txt','.bat'} |
---|
| 26 | FileType='txt'; |
---|
| 27 | case '.fig' |
---|
| 28 | FileType='figure'; |
---|
| 29 | case '.xml' |
---|
| 30 | FileType='xml'; |
---|
| 31 | case '.xls' |
---|
| 32 | FileType='xls'; |
---|
| 33 | otherwise |
---|
[472] | 34 | if ~isempty(FileExt) && ~isempty(imformats(regexprep(FileExt,'^.',''))) |
---|
[376] | 35 | try |
---|
| 36 | imainfo=imfinfo(fileinput); |
---|
| 37 | if length(imainfo) >1 %case of image with multiple frames |
---|
| 38 | FileType='multimage'; |
---|
[469] | 39 | FileInfo=imainfo(1);%take info from the first frame |
---|
| 40 | FileInfo.NumberOfFrames=length(imainfo); |
---|
[446] | 41 | else |
---|
[469] | 42 | FileType='image'; |
---|
[446] | 43 | FileInfo=imainfo; |
---|
[469] | 44 | FileInfo.NumberOfFrames=1; |
---|
[376] | 45 | end |
---|
| 46 | end |
---|
| 47 | else |
---|
[386] | 48 | error_nc=0; |
---|
[376] | 49 | try |
---|
| 50 | Data=nc2struct(fileinput,'ListGlobalAttribute','absolut_time_T0','Conventions',... |
---|
| 51 | 'CivStage','patch2','fix2','civ2','patch','fix'); |
---|
[387] | 52 | if isfield(Data,'Txt') && ~isempty(Data.Txt) |
---|
[386] | 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'; |
---|
[376] | 75 | end |
---|
| 76 | end |
---|
[386] | 77 | catch ME |
---|
| 78 | error_nc=1; |
---|
[376] | 79 | end |
---|
[386] | 80 | if error_nc |
---|
[387] | 81 | try |
---|
[397] | 82 | if exist('VideoReader.m','file')%recent version of Matlab |
---|
| 83 | VideoObject=VideoReader(fileinput); |
---|
[469] | 84 | FileInfo=get(VideoObject); |
---|
[397] | 85 | FileType='video'; |
---|
[435] | 86 | elseif exist('mmreader.m','file')% Matlab 2009a |
---|
| 87 | VideoObject=mmreader(fileinput); |
---|
[469] | 88 | FileInfo=get(VideoObject); |
---|
[435] | 89 | FileType='mmreader'; |
---|
[469] | 90 | end |
---|
| 91 | FileInfo.BitDepth=FileInfo.BitsPerPixel/3; |
---|
[387] | 92 | end |
---|
[376] | 93 | end |
---|
| 94 | end |
---|
| 95 | end |
---|