source: trunk/src/get_file_type.m @ 664

Last change on this file since 664 was 664, checked in by sommeria, 11 years ago

a few bugs corrected: import and retrival of parameters in series. mask in civ_series

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