[784] | 1 | %'get_file_type': OBSOLETE, replaced by get_file_info |
---|
[376] | 2 | %------------------------------------------------------------------------ |
---|
[380] | 3 | % [FileType,FileInfo,Object]=get_file_type(fileinput) |
---|
[376] | 4 | % |
---|
| 5 | % OUTPUT: |
---|
[469] | 6 | % FileInfo: structure containing info on the file (case of images or video), in particular |
---|
[784] | 7 | % .FileType: type of file, needed as input of read_field.m |
---|
[469] | 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 |
---|
[809] | 18 | |
---|
| 19 | %======================================================================= |
---|
| 20 | % Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France |
---|
| 21 | % http://www.legi.grenoble-inp.fr |
---|
| 22 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
| 23 | % |
---|
| 24 | % This file is part of the toolbox UVMAT. |
---|
| 25 | % |
---|
| 26 | % UVMAT is free software; you can redistribute it and/or modify |
---|
| 27 | % it under the terms of the GNU General Public License as published |
---|
| 28 | % by the Free Software Foundation; either version 2 of the license, |
---|
| 29 | % or (at your option) any later version. |
---|
| 30 | % |
---|
| 31 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 32 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 33 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 34 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
| 35 | %======================================================================= |
---|
| 36 | |
---|
[784] | 37 | function [FileType,FileInfo,VideoObject]=get_file_type(fileinput) |
---|
[397] | 38 | VideoObject=[]; |
---|
[675] | 39 | if exist(fileinput,'file') |
---|
[771] | 40 | FileInfo.FileName=fileinput; |
---|
| 41 | FileInfo.FileType='txt'; %default |
---|
[675] | 42 | else |
---|
[783] | 43 | FileInfo.FileType=''; |
---|
[784] | 44 | FileType=FileInfo.FileType; |
---|
[675] | 45 | return |
---|
| 46 | end |
---|
[783] | 47 | [tild,tild,FileExt]=fileparts(fileinput);%get the fiel extension FileExt |
---|
[376] | 48 | |
---|
| 49 | switch FileExt |
---|
| 50 | case '.fig' |
---|
[771] | 51 | FileInfo.FileType='figure'; |
---|
[784] | 52 | case {'.xml','.xls','.dat','.bin'} |
---|
| 53 | FileInfo.FileType=regexprep(FileExt,'^.','');% eliminate the dot of the extension; |
---|
[376] | 54 | otherwise |
---|
[664] | 55 | if ~isempty(FileExt)% exclude empty extension |
---|
| 56 | FileExt=regexprep(FileExt,'^.','');% eliminate the dot of the extension |
---|
| 57 | if ~isempty(FileExt) |
---|
| 58 | if ~isempty(imformats(FileExt))%case of images |
---|
| 59 | try |
---|
| 60 | imainfo=imfinfo(fileinput); |
---|
[783] | 61 | if length(imainfo) >1 %case of image with multiple frames |
---|
[664] | 62 | FileInfo=imainfo(1);%take info from the first frame |
---|
[783] | 63 | FileInfo.FileType='multimage'; |
---|
[664] | 64 | FileInfo.NumberOfFrames=length(imainfo); |
---|
| 65 | else |
---|
| 66 | FileInfo=imainfo; |
---|
[783] | 67 | FileInfo.FileType='image'; |
---|
[664] | 68 | FileInfo.NumberOfFrames=1; |
---|
| 69 | end |
---|
[771] | 70 | FileInfo.FileName=FileInfo.Filename; %correct the info given by imfinfo |
---|
[664] | 71 | end |
---|
[446] | 72 | else |
---|
[664] | 73 | error_nc=0; |
---|
| 74 | try |
---|
[771] | 75 | [Data,tild,tild,errormsg]=nc2struct(fileinput,[]); |
---|
[752] | 76 | if ~isempty(errormsg) |
---|
[664] | 77 | error_nc=1; |
---|
| 78 | else |
---|
[771] | 79 | if isfield(Data,'absolut_time_T0') && isfield(Data,'hart') && ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart) |
---|
| 80 | FileInfo.FileType='civx'; |
---|
[664] | 81 | FileType='civx'; % test for civx velocity fields |
---|
[771] | 82 | if isfield(Data,'patch2') && isequal(Data.patch2,1) |
---|
[664] | 83 | FileInfo.CivStage=6; |
---|
[771] | 84 | elseif isfield(Data,'fix2') && isequal(Data.fix2,1) |
---|
[664] | 85 | FileInfo.CivStage=5; |
---|
[771] | 86 | elseif isfield(Data,'civ2')&& isequal(Data.civ2,1) |
---|
[664] | 87 | FileInfo.CivStage=4; |
---|
[771] | 88 | elseif isfield(Data,'patch')&&isequal(Data.patch,1) |
---|
[664] | 89 | FileInfo.CivStage=3; |
---|
[771] | 90 | elseif isfield(Data,'fix')&&isequal(Data.fix,1) |
---|
[664] | 91 | FileInfo.CivStage=2; |
---|
[752] | 92 | else |
---|
[664] | 93 | FileInfo.CivStage=1; |
---|
| 94 | end |
---|
[771] | 95 | elseif isfield(Data,'Conventions') && strcmp(Data.Conventions,'uvmat/civdata') |
---|
| 96 | FileInfo.FileType='civdata'; % test for civx velocity fields |
---|
[783] | 97 | % FileType='civdata'; % test for civx velocity fields |
---|
[664] | 98 | FileInfo.CivStage=Data.CivStage; |
---|
| 99 | else |
---|
[771] | 100 | FileInfo.FileType='netcdf'; |
---|
[783] | 101 | %FileType='netcdf'; |
---|
[771] | 102 | FileInfo.ListVarName=Data.ListVarName; |
---|
[664] | 103 | end |
---|
[386] | 104 | end |
---|
[664] | 105 | catch ME |
---|
| 106 | error_nc=1; |
---|
[376] | 107 | end |
---|
[664] | 108 | if error_nc |
---|
| 109 | try |
---|
| 110 | if exist('VideoReader.m','file')%recent version of Matlab |
---|
| 111 | VideoObject=VideoReader(fileinput); |
---|
| 112 | FileInfo=get(VideoObject); |
---|
[783] | 113 | FileInfo.FileType='video'; |
---|
[664] | 114 | elseif exist('mmreader.m','file')% Matlab 2009a |
---|
| 115 | VideoObject=mmreader(fileinput); |
---|
| 116 | FileInfo=get(VideoObject); |
---|
[783] | 117 | FileInfo.FileType='mmreader'; |
---|
[664] | 118 | end |
---|
[771] | 119 | FileInfo.FileName=fileinput; |
---|
[664] | 120 | FileInfo.BitDepth=FileInfo.BitsPerPixel/3; |
---|
| 121 | end |
---|
| 122 | end |
---|
[376] | 123 | end |
---|
| 124 | end |
---|
| 125 | end |
---|
[784] | 126 | end |
---|
[809] | 127 | FileType=FileInfo.FileType; |
---|