source: trunk/src/get_file_type.m @ 644

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

steps further to use series with cluster. Some bsolete functions removed

File size: 3.8 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
[472]32        if ~isempty(FileExt) && ~isempty(imformats(regexprep(FileExt,'^.','')))
[376]33            try
34                imainfo=imfinfo(fileinput);
35                if length(imainfo) >1 %case of image with multiple frames
36                    FileType='multimage';
[469]37                    FileInfo=imainfo(1);%take info from the first frame
38                    FileInfo.NumberOfFrames=length(imainfo);
[446]39                else
[469]40                    FileType='image';
[446]41                    FileInfo=imainfo;
[469]42                    FileInfo.NumberOfFrames=1;
[376]43                end
44            end
45        else
[386]46            error_nc=0;
[376]47            try
48                Data=nc2struct(fileinput,'ListGlobalAttribute','absolut_time_T0','Conventions',...
49                    'CivStage','patch2','fix2','civ2','patch','fix');
[387]50                if isfield(Data,'Txt') && ~isempty(Data.Txt)
[386]51                    error_nc=1;
52                else
53                    if ~isempty(Data.absolut_time_T0')
54                        FileType='civx'; % test for civx velocity fields
55                        if ~isempty(Data.patch2) && isequal(Data.patch2,1)
56                            FileInfo.CivStage=6;
57                        elseif ~isempty(Data.fix2) && isequal(Data.fix2,1)
58                            FileInfo.CivStage=5;
59                        elseif ~isempty(Data.civ2) && isequal(Data.civ2,1);
60                            FileInfo.CivStage=4;
61                        elseif ~isempty(Data.patch) && isequal(Data.patch,1);
62                            FileInfo.CivStage=3;
63                        elseif ~isempty(Data.fix) && isequal(Data.fix,1);
64                            FileInfo.CivStage=2;
65                        elseif ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart)
66                            FileInfo.CivStage=1;
67                        end
68                    elseif strcmp(Data.Conventions,'uvmat/civdata')
69                        FileType='civdata'; % test for civx velocity fields
70                        FileInfo.CivStage=Data.CivStage;
71                    else
72                        FileType='netcdf';
[376]73                    end
74                end
[386]75            catch ME
76                error_nc=1;
[376]77            end
[386]78            if error_nc
[387]79                try
[397]80                    if exist('VideoReader.m','file')%recent version of Matlab
81                        VideoObject=VideoReader(fileinput);
[469]82                        FileInfo=get(VideoObject);
[397]83                        FileType='video';
[435]84                    elseif exist('mmreader.m','file')% Matlab 2009a
85                        VideoObject=mmreader(fileinput);
[469]86                        FileInfo=get(VideoObject);
[435]87                        FileType='mmreader';
[469]88                    end 
89                    FileInfo.BitDepth=FileInfo.BitsPerPixel/3;
[387]90                end
[376]91            end
92        end
93end
Note: See TracBrowser for help on using the repository browser.