source: trunk/src/get_file_type.m @ 783

Last change on this file since 783 was 783, checked in by sommeria, 10 years ago

-pb of mulitple tiff reading solved
-modif of output parma in get-file_type and find_file_series

  • introduction of transform/ima_noise_rms
File size: 5.0 KB
Line 
1%'get_file_type': determine info about a file (image, multimage, civdata,...) .
2%------------------------------------------------------------------------
3% [FileType,FileInfo,Object]=get_file_type(fileinput)
4%
5% OUTPUT:
6% FileType: type of file
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
14% Object: in case of video
15%
16% INPUT:
17% fileinput: name, including path, of the file to analyse
18function [FileInfo,VideoObject]=get_file_type(fileinput)
19VideoObject=[];
20if exist(fileinput,'file')
21    FileInfo.FileName=fileinput;
22    FileInfo.FileType='txt'; %default
23else
24    FileInfo.FileType='';
25    return
26end
27[tild,tild,FileExt]=fileparts(fileinput);%get the fiel extension FileExt
28
29switch FileExt
30    case '.fig'
31        FileInfo.FileType='figure';
32    case '.xml'
33        FileInfo.FileType='xml';
34    case '.xls'
35        FileInfo.FileType='xls';
36    case '.dat'
37        FileInfo.FileType='dat';;
38    otherwise
39        if ~isempty(FileExt)% exclude empty extension
40            FileExt=regexprep(FileExt,'^.','');% eliminate the dot of the extension
41            if ~isempty(FileExt)
42                if ~isempty(imformats(FileExt))%case of images
43                    try
44                        imainfo=imfinfo(fileinput);
45                        if length(imainfo) >1 %case of image with multiple frames   
46                            FileInfo=imainfo(1);%take info from the first frame
47                            FileInfo.FileType='multimage';
48                            FileInfo.NumberOfFrames=length(imainfo);
49                        else
50                            FileInfo=imainfo;
51                            FileInfo.FileType='image';
52                            FileInfo.NumberOfFrames=1;
53                        end
54                        FileInfo.FileName=FileInfo.Filename; %correct the info given by imfinfo
55                    end
56                else
57                    error_nc=0;
58                    try
59                       [Data,tild,tild,errormsg]=nc2struct(fileinput,[]);
60                        if ~isempty(errormsg)
61                            error_nc=1;
62                        else
63                            if isfield(Data,'absolut_time_T0') && isfield(Data,'hart') && ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart)
64                                FileInfo.FileType='civx';
65                                FileType='civx'; % test for civx velocity fields
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                               % FileType='civdata'; % test for civx velocity fields
82                                FileInfo.CivStage=Data.CivStage;
83                            else
84                                FileInfo.FileType='netcdf';
85                                %FileType='netcdf';
86                                FileInfo.ListVarName=Data.ListVarName;
87                            end
88                        end
89                    catch ME
90                        error_nc=1;
91                    end
92                    if error_nc
93                        try
94                            if exist('VideoReader.m','file')%recent version of Matlab
95                                VideoObject=VideoReader(fileinput);
96                                FileInfo=get(VideoObject);
97                                FileInfo.FileType='video';
98                            elseif exist('mmreader.m','file')% Matlab 2009a
99                                VideoObject=mmreader(fileinput);
100                                FileInfo=get(VideoObject);
101                                FileInfo.FileType='mmreader';
102                            end
103                            FileInfo.FileName=fileinput;
104                            FileInfo.BitDepth=FileInfo.BitsPerPixel/3;
105                        end
106                    end
107                end
108            end
109        end
110end
Note: See TracBrowser for help on using the repository browser.