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