source: trunk/src/get_file_info.m @ 1089

Last change on this file since 1089 was 1089, checked in by sommeria, 3 years ago

cleaning of civ files, ima2vol updated

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