source: trunk/src/get_file_info.m @ 1040

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

get_field improved to select variables, uvmat rationalized with respect to input file types

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