source: trunk/src/get_file_type.m @ 784

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

adpat uvmat to reading data from rdvision

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