| 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 |
|---|
| 12 | function [FileType,FileInfo,Object]=get_file_type(fileinput) |
|---|
| 13 | FileType=''; |
|---|
| 14 | FileInfo=[]; |
|---|
| 15 | Object=[]; |
|---|
| 16 | [tild,tild,FileExt]=fileparts(fileinput); |
|---|
| 17 | |
|---|
| 18 | switch 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','file')%recent version of Matlab |
|---|
| 73 | Object=VideoReader(fileinput); |
|---|
| 74 | else |
|---|
| 75 | Object=mmreader(fileinput);%older Matlab function for movies |
|---|
| 76 | end |
|---|
| 77 | FileType='video'; |
|---|
| 78 | FileInfo.NbFrame=get(Object,'NumberOfFrames'); |
|---|
| 79 | end |
|---|
| 80 | end |
|---|
| 81 | end |
|---|
| 82 | end |
|---|