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