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