source: trunk/src/get_file_info.m @ 1022

Last change on this file since 1022 was 1022, checked in by sommeria, 6 years ago

opendap reading intreoduced

File size: 7.7 KB
Line 
1%'get_file_info': determine info about a file (image, multimage, civdata,...) .
2%------------------------------------------------------------------------
3% [FileInfo,VideoObject]=get_file_info(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%      .FileIndexing='on' for data files (when series of indexed files are  expected)
9%      .Height: image height in pixels
10%      .Width:  image width in pixels
11%      .BitDepth: nbre of bits per pixel  (8 of 16)
12%      .ColorType: 'greyscale' or 'color'
13%      .NumberOfFrames
14%      .FrameRate: nbre of frames per second, =[] for images
15% VideoObject: in case of video
16%
17% INPUT:
18% fileinput: name, including path, of the file to analyse
19
20%=======================================================================
21% Copyright 2008-2017, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
22%   http://www.legi.grenoble-inp.fr
23%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
24%
25%     This file is part of the toolbox UVMAT.
26%
27%     UVMAT is free software; you can redistribute it and/or modify
28%     it under the terms of the GNU General Public License as published
29%     by the Free Software Foundation; either version 2 of the license,
30%     or (at your option) any later version.
31%
32%     UVMAT is distributed in the hope that it will be useful,
33%     but WITHOUT ANY WARRANTY; without even the implied warranty of
34%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
35%     GNU General Public License (see LICENSE.txt) for more details.
36%=======================================================================
37
38function [FileInfo,VideoObject]=get_file_info(fileinput)
39VideoObject=[];
40if ~isempty(regexp(fileinput,'^http://'))|| exist(fileinput,'file')
41    FileInfo.FileName=fileinput;
42    FileInfo.FileType='txt'; %default
43else
44    FileInfo.FileType='';
45    return
46end
47[tild,tild,FileExt]=fileparts(fileinput);%get the file extension FileExt
48
49switch FileExt
50    case '.fig'
51        FileInfo.FileType='figure';
52    case {'.xml','.xls','.dat','.bin'}
53        FileInfo.FileType=regexprep(FileExt,'^.','');% eliminate the dot of the extension;
54    case {'.seq','.sqb'}
55        [A,FileInfo,timestamps,errormsg]=read_rdvision(fileinput,[]);
56%         %%%%%
57%         FileInfo.NumberOfFrame=24000;
58%         %%%%%%%%
59    case '.im7'
60        try
61             Input=readimx(fileinput);
62             Image=Input.Frames{1}.Components{1}.Planes{1};
63             FileInfo.FileType='image_DaVis';
64             FileInfo.NumberOfFrames=numel(Input.Frames);
65             FileInfo.Height=size(Image,2);
66             FileInfo.Width=size(Image,1);
67        catch ME
68            msgbox_uvmat('ERROR',ME.message)
69            return
70        end
71    case '.h5'
72        hinfo=hdf5info(fileinput);
73        if strcmp(hinfo.GroupHierarchy.Attributes(1).Value.Data,'MultipassPIVResults')
74            FileInfo.FileType='pivdata_fluidimage';
75            FileInfo.CivStage=6; % A MODIFIER
76        end
77    case '.cine'
78        [FileInfo,BitmapInfoHeader, CameraSetup]=readCineHeader(fileinput);
79        FileInfo.FileType='cine_phantom';
80        FileInfo.NumberOfFrames=FileInfo.ImageCount;
81        FileInfo.FrameRate=CameraSetup.FrameRate;
82        FileInfo.Height=BitmapInfoHeader.biHeight;
83        FileInfo.Width=BitmapInfoHeader.biWidth;
84         FileInfo.BitDepth=BitmapInfoHeader.biBitCount;
85    otherwise
86        if ~isempty(FileExt)% exclude empty extension
87            FileExt=regexprep(FileExt,'^.','');% eliminate the dot of the extension
88            if ~isempty(FileExt)
89                if ~isempty(imformats(FileExt))%case of images
90                    try
91                        imainfo=imfinfo(fileinput);
92                        if length(imainfo) >1 %case of image with multiple frames   
93                            FileInfo=imainfo(1);%take info from the first frame
94                            FileInfo.NumberOfFrames=length(imainfo);
95                            FileInfo.FileType='multimage';
96                        else
97                            FileInfo=imainfo;
98                            FileInfo.NumberOfFrames=1;
99                            FileInfo.FileType='image';
100                        end
101                        FileInfo.FileName=FileInfo.Filename; %correct the info given by imfinfo
102                        nbfield=numel(fieldnames(FileInfo));
103                        FileInfo=orderfields(FileInfo,[nbfield nbfield-1 nbfield-2 (1:nbfield-3)]); %reorder the fields of fileInfo for clarity
104                    end
105                else
106                    error_nc=0;
107                    try
108                       [Data,tild,tild,errormsg]=nc2struct(fileinput,[]);
109                        if ~isempty(errormsg)
110                            error_nc=1;
111                        else
112                            if isfield(Data,'absolut_time_T0') && isfield(Data,'hart') && ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart)
113                                FileInfo.FileType='civx';
114                                if isfield(Data,'patch2') && isequal(Data.patch2,1)
115                                    FileInfo.CivStage=6;
116                                elseif isfield(Data,'fix2') && isequal(Data.fix2,1)
117                                    FileInfo.CivStage=5;
118                                elseif  isfield(Data,'civ2')&& isequal(Data.civ2,1)
119                                    FileInfo.CivStage=4;
120                                elseif isfield(Data,'patch')&&isequal(Data.patch,1)
121                                    FileInfo.CivStage=3;
122                                elseif isfield(Data,'fix')&&isequal(Data.fix,1)
123                                    FileInfo.CivStage=2;
124                                else
125                                    FileInfo.CivStage=1;
126                                end
127                            elseif isfield(Data,'Conventions') && strcmp(Data.Conventions,'uvmat/civdata')
128                                FileInfo.FileType='civdata'; % test for civx velocity fields
129                                FileInfo.CivStage=Data.CivStage;
130                            else
131                                FileInfo.FileType='netcdf';
132                                FileInfo.ListVarName=Data.ListVarName;
133                            end
134                        end
135                    catch ME
136                        error_nc=1;
137                    end
138                    if error_nc
139                        try
140                            if exist('VideoReader.m','file')%recent version of Matlab
141                                VideoObject=VideoReader(fileinput);
142                                FileInfo=get(VideoObject);
143                                FileInfo.FileType='video';
144                            elseif exist('mmreader.m','file')% Matlab 2009a
145                                VideoObject=mmreader(fileinput);
146                                FileInfo=get(VideoObject);
147                                FileInfo.FileType='mmreader';
148                            end
149                            FileInfo.BitDepth=FileInfo.BitsPerPixel/3;
150                            FileInfo.ColorType='truecolor';
151                            FileInfo.FileName=fileinput;
152                            nbfield=numel(fieldnames(FileInfo));
153                            FileInfo=orderfields(FileInfo,[nbfield nbfield-3 nbfield-1 nbfield-2 (1:nbfield-4)]); %reorder the fields of fileInfo for clarity
154                        end
155                    end
156                end
157            end
158        end
159end
160switch FileInfo.FileType
161    case {'image','image_DaVis','multimage','mmreader','cine_phantom','video','netcdf','civdata'}
162        FileInfo.FileIndexing='on'; % allow to detect file index for scanning series
163end
Note: See TracBrowser for help on using the repository browser.