[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 |
---|
| 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 |
---|
[397] | 12 | function [FileType,FileInfo,VideoObject]=get_file_type(fileinput) |
---|
[376] | 13 | FileType=''; |
---|
| 14 | FileInfo=[]; |
---|
[397] | 15 | VideoObject=[]; |
---|
[376] | 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 |
---|
[386] | 38 | error_nc=0; |
---|
[376] | 39 | try |
---|
| 40 | Data=nc2struct(fileinput,'ListGlobalAttribute','absolut_time_T0','Conventions',... |
---|
| 41 | 'CivStage','patch2','fix2','civ2','patch','fix'); |
---|
[387] | 42 | if isfield(Data,'Txt') && ~isempty(Data.Txt) |
---|
[386] | 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'; |
---|
[376] | 65 | end |
---|
| 66 | end |
---|
[386] | 67 | catch ME |
---|
| 68 | error_nc=1; |
---|
[376] | 69 | end |
---|
[386] | 70 | if error_nc |
---|
[387] | 71 | try |
---|
[397] | 72 | if exist('VideoReader.m','file')%recent version of Matlab |
---|
| 73 | VideoObject=VideoReader(fileinput); |
---|
| 74 | FileInfo.NumberOfFrames=get(VideoObject,'NumberOfFrames'); |
---|
| 75 | FileType='video'; |
---|
| 76 | end |
---|
[387] | 77 | end |
---|
[376] | 78 | end |
---|
| 79 | end |
---|
| 80 | end |
---|