source: trunk/src/get_file_info.m @ 1164

Last change on this file since 1164 was 1164, checked in by sommeria, 2 months ago

civ3D updated

File size: 13.1 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-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
40%   http://www.legi.grenoble-inp.fr
41%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.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)
57
58VideoObject=[];
59FileInfo.FileType='';% input file does not exist
60FileInfo.FieldType=''; %default output
61if ~ischar(fileinput)
62    return
63end
64% check the existence (not possible for OpenDAP data)
65if ~isempty(regexp(fileinput,'^http://','once'))|| exist(fileinput,'file')
66    FileInfo.FileName=fileinput;
67    FileInfo.FileType='txt'; %default
68else
69    return %input file does not exist.
70end
71[tild,tild,FileExt]=fileparts(fileinput);%get the file extension FileExt
72
73switch FileExt
74    case '.fig'
75        FileInfo.FileType='figure';
76    case '.mat'
77        FileInfo.FileType='mat';
78    case {'.xml','.xls','.dat','.bin'}
79        FileInfo.FileType=regexprep(FileExt,'^.','');% eliminate the dot of the extension;
80    case {'.seq','.sqb'}
81        [~,FileInfo,timestamps,errormsg]=read_rdvision(fileinput,[]);
82    case '.im7'
83        try
84            Input=readimx(fileinput);
85            Image=Input.Frames{1}.Components{1}.Planes{1};
86            FileInfo.FileType='image_DaVis';
87            FileInfo.NumberOfFrames=numel(Input.Frames);
88            FileInfo.Height=size(Image,2);
89            FileInfo.Width=size(Image,1);
90            FileInfo.TimeName='timestamp';
91            for ilist=1:numel(Input.Attributes)
92                % if strcmp(Input.Attributes{ilist}.Name,'_Date')
93                %     DateString=Input.Attributes{ilist}.Value;
94                % end
95                % if strcmp(Input.Attributes{ilist}.Name,'_Time')
96                %     TimeString=Input.Attributes{ilist}.Value;
97                % end
98            end
99        catch ME
100            msgbox_uvmat('ERROR',{ME.message;'reading image from DaVis is possible only with Matlab version 2013 or earlier'})
101            return
102        end
103    case '.h5'
104        hinfo=h5info(fileinput);
105        FileInfo.CivStage=0;
106        for igroup=1:numel(hinfo.Groups)
107            if strcmp(hinfo.Groups(igroup).Name,'/piv0')
108                FileInfo.CivStage=3;
109            end
110            if strcmp(hinfo.Groups(igroup).Name,'/piv1')
111                FileInfo.CivStage=6;
112                break
113            end
114        end
115        if FileInfo.CivStage~=0
116            FileInfo.FileType='pivdata_fluidimage';
117        else
118            FileInfo.FileType='h5';
119        end
120    case '.cine'
121        [FileInfo,BitmapInfoHeader, CameraSetup]=readCineHeader(fileinput);
122        FileInfo.FileType='cine_phantom';
123        FileInfo.NumberOfFrames=FileInfo.ImageCount;
124        FileInfo.FrameRate=CameraSetup.FrameRate;
125        FileInfo.Height=BitmapInfoHeader.biHeight;
126        FileInfo.Width=BitmapInfoHeader.biWidth;
127        FileInfo.BitDepth=BitmapInfoHeader.biBitCount;
128        FileInfo.TimeName='video';
129    otherwise
130        if ~isempty(FileExt)% exclude empty extension
131            FileExt=regexprep(FileExt,'^.','');% eliminate the dot of the extension
132            if ~isempty(FileExt)
133                if ~isempty(imformats(FileExt))%case of images
134                    FileInfo.FileType='image';
135                    try
136                        imainfo=imfinfo(fileinput);
137                        if length(imainfo) >1 %case of image with multiple frames
138                            FileInfo=imainfo(1);%take info from the first frame
139                            FileInfo.NumberOfFrames=length(imainfo);
140                            FileInfo.FileType='multimage';
141                        else
142                            FileInfo=imainfo;
143                            FileInfo.NumberOfFrames=1;
144                            FileInfo.FileType='image';
145                        end
146                        FileInfo.FileName=FileInfo.Filename; %correct the info given by imfinfo
147                        nbfield=numel(fieldnames(FileInfo));
148                        FileInfo=orderfields(FileInfo,[nbfield nbfield-1 nbfield-2 (1:nbfield-3)]); %reorder the fields of fileInfo for clarity
149                    end
150                else
151                    error_nc=0;
152                    try %try netcdf file
153                        [Data,tild,tild,errormsg]=nc2struct(fileinput,[]);
154                        if isempty(errormsg)
155                            %                             if isfield(Data,'absolut_time_T0') && isfield(Data,'hart') && ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart)
156                            %                                 FileInfo.FileType='civx';%old civ data from the Fortran program
157                            %                                 if isfield(Data,'patch2') && isequal(Data.patch2,1)
158                            %                                     FileInfo.CivStage=6;
159                            %                                 elseif isfield(Data,'fix2') && isequal(Data.fix2,1)
160                            %                                     FileInfo.CivStage=5;
161                            %                                 elseif  isfield(Data,'civ2')&& isequal(Data.civ2,1)
162                            %                                     FileInfo.CivStage=4;
163                            %                                 elseif isfield(Data,'patch')&&isequal(Data.patch,1)
164                            %                                     FileInfo.CivStage=3;
165                            %                                 elseif isfield(Data,'fix')&&isequal(Data.fix,1)
166                            %                                     FileInfo.CivStage=2;
167                            %                                 else
168                            %                                     FileInfo.CivStage=1;
169                            %                                 end
170                            %                             else
171                            if isfield(Data,'Conventions') && strcmp(Data.Conventions,'uvmat/civdata')
172                                FileInfo.FileType='civdata'; % test for civ velocity fields
173                                FileInfo.CivStage=Data.CivStage;
174                                MaskFile='';
175                                if isfield(Data,'Civ2_Mask')
176                                    MaskFile=Data.Civ2_Mask;
177                                    if isfield(Data,'Civ2_NbSlice')
178                                        FileInfo.MaskNbSlice=Data.Civ2_NbSlice;
179                                    end
180                                elseif isfield(Data,'Civ1_Mask')
181                                    MaskFile=Data.Civ1_Mask;
182                                    if isfield(Data,'Civ1_NbSlice')
183                                        FileInfo.MaskNbSlice=Data.Civ1_NbSlice;
184                                    end
185                                end
186                                if isfield(Data,'VolumeScan')
187                                    FileInfo.VolumeScan=Data.VolumeScan;
188                                end
189                                if ~isempty(MaskFile)
190                                    [RootPath,SubDir,RootFile,~,~,~,~,FileExt,NomType]=fileparts_uvmat(MaskFile);
191                                    if strcmp(NomType,'_1')&& isfield(FileInfo,'MaskNbSlice')
192                                        FileInfo.MaskFile=fullfile(RootPath,SubDir,RootFile);
193                                    else
194                                        FileInfo.MaskFile=MaskFile;% single mask for the series (no indexing)
195                                    end
196                                    FileInfo.MaskExt=FileExt;
197                                end
198                            elseif isfield(Data,'Conventions') && strcmp(Data.Conventions,'uvmat/civdata_3D')
199                                FileInfo.FileType='civdata_3D'; % test for 3D volume civ velocity fields
200                                FileInfo.CivStage=Data.CivStage;
201                                z_dim_index=find(strcmp(Data.ListDimName,'npz'));
202                                FileInfo.NumberOfFrames=Data.DimValue(z_dim_index);
203                            else
204                                FileInfo.FileType='netcdf';
205                                FileInfo.ListVarName=Data.ListVarName;
206                                FileInfo.VarAttribute={};
207                                if isfield(Data,'VarAttribute')
208                                    FileInfo.VarAttribute=Data.VarAttribute;
209                                end
210                                FileInfo.ListDimName=Data.ListDimName;
211                                FileInfo.NumberOfFrames=Data.DimValue;
212                            end
213                        else
214                            error_nc=1;
215                        end
216                    catch ME
217                        error_nc=1;
218                    end
219                    if error_nc
220                        try
221                            if exist('mmreader.m','file')% Matlab 2009a
222                                INFO=mmfileinfo (fileinput);
223                                if  ~isempty(INFO.Video.Format)
224                                   
225                                    VideoObject=mmreader(fileinput);
226                                    FileInfo=get(VideoObject);
227                                    FileInfo.FileType='mmreader';
228                                end
229                            end
230                            FileInfo.BitDepth=FileInfo.BitsPerPixel/3;
231                            FileInfo.ColorType='truecolor';
232                            FileInfo.TimeName='video';
233                            FileInfo.FileName=fileinput;
234                            nbfield=numel(fieldnames(FileInfo));
235                            FileInfo=orderfields(FileInfo,[nbfield nbfield-4 nbfield-3 nbfield-1 nbfield-2 (1:nbfield-5)]); %reorder the fields of fileInfo for clarity
236                            if ~isfield(FileInfo,'NumberOfFrames')
237                                FileInfo.NumberOfFrames=floor(FileInfo.Duration*FileInfo.FrameRate);
238                            end
239                        end
240                    end
241                end
242            end
243        end
244end
245
246if ismember (FileInfo.FileType,{'mat','image','image_DaVis','multimage','mmreader','cine_phantom','video','netcdf','civdata'})
247    FileInfo.FileIndexing='on'; % allow to detect file index for scanning series
248else
249    FileInfo.FileIndexing='off';
250end
251FileInfo.FieldType=FileInfo.FileType;%default
252switch FileInfo.FileType
253    case {'image','multimage','video','mmreader','rdvision','image_DaVis','cine_phantom'}
254        FileInfo.FieldType='image';
255    case {'civx','civdata','pivdata_fluidimage'}
256        FileInfo.FieldType='civdata';
257end
258
Note: See TracBrowser for help on using the repository browser.