[784] | 1 | %'get_file_info': determine info about a file (image, multimage, civdata,...) . |
---|
| 2 | %------------------------------------------------------------------------ |
---|
| 3 | % [FileInfo,VideoObject]=get_file_info(fileinput) |
---|
| 4 | % |
---|
| 5 | % OUTPUT: |
---|
| 6 | % FileInfo: structure containing info on the file (case of images or video), in particular |
---|
| 7 | % .FileType: type of file, needed as input of read_field.m |
---|
| 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 | % VideoObject: in case of video |
---|
| 15 | % |
---|
| 16 | % INPUT: |
---|
| 17 | % fileinput: name, including path, of the file to analyse |
---|
| 18 | function [FileInfo,VideoObject]=get_file_info(fileinput) |
---|
| 19 | VideoObject=[]; |
---|
| 20 | if exist(fileinput,'file') |
---|
| 21 | FileInfo.FileName=fileinput; |
---|
| 22 | FileInfo.FileType='txt'; %default |
---|
| 23 | else |
---|
| 24 | FileInfo.FileType=''; |
---|
| 25 | return |
---|
| 26 | end |
---|
| 27 | [tild,tild,FileExt]=fileparts(fileinput);%get the file extension FileExt |
---|
| 28 | |
---|
| 29 | switch FileExt |
---|
| 30 | case '.fig' |
---|
| 31 | FileInfo.FileType='figure'; |
---|
| 32 | case {'.xml','.xls','.dat','.bin'} |
---|
| 33 | FileInfo.FileType=regexprep(FileExt,'^.','');% eliminate the dot of the extension; |
---|
[790] | 34 | case {'.seq','.sqb'} |
---|
| 35 | [A,FileInfo,timestamps,errormsg]=read_rdvision(fileinput,[]); |
---|
| 36 | |
---|
[784] | 37 | otherwise |
---|
| 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 | FileInfo=imainfo(1);%take info from the first frame |
---|
| 46 | FileInfo.NumberOfFrames=length(imainfo); |
---|
| 47 | FileInfo.FileType='multimage'; |
---|
| 48 | else |
---|
| 49 | FileInfo=imainfo; |
---|
| 50 | FileInfo.NumberOfFrames=1; |
---|
| 51 | FileInfo.FileType='image'; |
---|
| 52 | end |
---|
| 53 | FileInfo.FileName=FileInfo.Filename; %correct the info given by imfinfo |
---|
| 54 | nbfield=numel(fieldnames(FileInfo)); |
---|
| 55 | FileInfo=orderfields(FileInfo,[nbfield nbfield-1 nbfield-2 (1:nbfield-3)]); %reorder the fields of fileInfo for clarity |
---|
| 56 | end |
---|
| 57 | else |
---|
| 58 | error_nc=0; |
---|
| 59 | try |
---|
| 60 | [Data,tild,tild,errormsg]=nc2struct(fileinput,[]); |
---|
| 61 | if ~isempty(errormsg) |
---|
| 62 | error_nc=1; |
---|
| 63 | else |
---|
| 64 | if isfield(Data,'absolut_time_T0') && isfield(Data,'hart') && ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart) |
---|
| 65 | FileInfo.FileType='civx'; |
---|
| 66 | if isfield(Data,'patch2') && isequal(Data.patch2,1) |
---|
| 67 | FileInfo.CivStage=6; |
---|
| 68 | elseif isfield(Data,'fix2') && isequal(Data.fix2,1) |
---|
| 69 | FileInfo.CivStage=5; |
---|
| 70 | elseif isfield(Data,'civ2')&& isequal(Data.civ2,1) |
---|
| 71 | FileInfo.CivStage=4; |
---|
| 72 | elseif isfield(Data,'patch')&&isequal(Data.patch,1) |
---|
| 73 | FileInfo.CivStage=3; |
---|
| 74 | elseif isfield(Data,'fix')&&isequal(Data.fix,1) |
---|
| 75 | FileInfo.CivStage=2; |
---|
| 76 | else |
---|
| 77 | FileInfo.CivStage=1; |
---|
| 78 | end |
---|
| 79 | elseif isfield(Data,'Conventions') && strcmp(Data.Conventions,'uvmat/civdata') |
---|
| 80 | FileInfo.FileType='civdata'; % test for civx velocity fields |
---|
| 81 | FileInfo.CivStage=Data.CivStage; |
---|
| 82 | else |
---|
| 83 | FileInfo.FileType='netcdf'; |
---|
| 84 | FileInfo.ListVarName=Data.ListVarName; |
---|
| 85 | end |
---|
| 86 | end |
---|
| 87 | catch ME |
---|
| 88 | error_nc=1; |
---|
| 89 | end |
---|
| 90 | if error_nc |
---|
| 91 | try |
---|
| 92 | if exist('VideoReader.m','file')%recent version of Matlab |
---|
| 93 | VideoObject=VideoReader(fileinput); |
---|
| 94 | FileInfo=get(VideoObject); |
---|
| 95 | FileInfo.FileType='video'; |
---|
| 96 | elseif exist('mmreader.m','file')% Matlab 2009a |
---|
| 97 | VideoObject=mmreader(fileinput); |
---|
| 98 | FileInfo=get(VideoObject); |
---|
| 99 | FileInfo.FileType='mmreader'; |
---|
| 100 | end |
---|
| 101 | FileInfo.BitDepth=FileInfo.BitsPerPixel/3; |
---|
| 102 | FileInfo.ColorType='truecolor'; |
---|
| 103 | FileInfo.FileName=fileinput; |
---|
| 104 | nbfield=numel(fieldnames(FileInfo)); |
---|
| 105 | FileInfo=orderfields(FileInfo,[nbfield nbfield-3 nbfield-1 nbfield-2 (1:nbfield-4)]); %reorder the fields of fileInfo for clarity |
---|
| 106 | end |
---|
| 107 | end |
---|
| 108 | end |
---|
| 109 | end |
---|
| 110 | end |
---|
[790] | 111 | end |
---|
| 112 | switch FileInfo.FileType |
---|
| 113 | case {'image','multimage','mmreader','video','netcdf','civdata'} |
---|
| 114 | FileInfo.FileIndexing='on'; % allow to detect file index for scanning series |
---|
[784] | 115 | end |
---|