source: trunk/src/update_imadoc.m @ 941

Last change on this file since 941 was 924, checked in by g7moreau, 5 years ago
  • Update Copyright Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
File size: 3.5 KB
Line 
1%'update_imadoc': update an xml file with geometric calibration parameters
2%--------------------------------------------------------------------------
3%  function update_imadoc(Struct,outputfile)
4%
5%INPUT:
6% Struct: structure containing the calibration parameters
7% outputfile: xml file to modify
8% StructName : Name of the field in the xml file
9%-------------------------------------------------------------
10
11%=======================================================================
12% Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
13%   http://www.legi.grenoble-inp.fr
14%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
15%
16%     This file is part of the toolbox UVMAT.
17%
18%     UVMAT is free software; you can redistribute it and/or modify
19%     it under the terms of the GNU General Public License as published
20%     by the Free Software Foundation; either version 2 of the license,
21%     or (at your option) any later version.
22%
23%     UVMAT is distributed in the hope that it will be useful,
24%     but WITHOUT ANY WARRANTY; without even the implied warranty of
25%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26%     GNU General Public License (see LICENSE.txt) for more details.
27%=======================================================================
28
29function errormsg=update_imadoc(Struct,outputfile,StructName)
30errormsg='';
31testappend=0;
32%% backup the output file if it already exist, and read it
33if exist(outputfile,'file');%=1 if the output file already exists, 0 else
34    testappend=1;
35    backupfile=outputfile;
36    testexist=2;
37    while testexist==2
38        backupfile=[backupfile '~'];
39        testexist=exist(backupfile,'file');
40    end
41    [success,message]=copyfile(outputfile,backupfile);%make backup
42    if success~=1
43        errormsg=['errror in xml file backup: ' message];
44        return
45    end
46    t=xmltree(outputfile); %read the file
47    title=get(t,1,'name');
48    if strcmp(title,'ImaDoc')
49        testappend=1;
50        %if the xml file is  ImaDoc
51        uid_calib=find(t,['ImaDoc/' StructName]);
52        if isempty(uid_calib)  %if Struct does not already exists, create it
53            [t,uid_calib]=add(t,1,'element',StructName);
54        else %if Struct already exists, delete its content
55            uid_child=children(t,uid_calib);
56            t=delete(t,uid_child);
57        end
58    end
59end
60
61%% create a new xml file
62if ~testappend
63    t=xmltree;
64    t=set(t,1,'name','ImaDoc');
65    % in case of movie (avi file), copy timing info in the new xml file
66    [pp,outputroot]=fileparts(outputfile);
67    %     imainfo=[];
68    if exist(fullfile(pp,[outputroot '.avi']),'file')
69        FileName=fullfile(pp,[outputroot '.avi']);
70        hhh=which('videoreader');
71        if isempty(hhh)%use old video function of matlab
72            imainfo=aviinfo(FileName);
73            imainfo.FrameRate=imainfo.FramesPerSecond;
74            imainfo.NumberOfFrames=imainfo.NumFrames;
75        else %use video function videoreader of matlab
76            imainfo=get(videoreader(FileName));
77        end
78        if ~isempty(imainfo)
79            [t,uid_camera]=add(t,1,'element','Camera');
80            Camera.TimeUnit='s';
81            Camera.BurstTiming.Time=0;
82            Camera.BurstTiming.Dti=1/imainfo.FrameRate;
83            Camera.BurstTiming.NbDti=imainfo.NumberOfFrames-1;
84            t=struct2xml(Camera,t,uid_camera);
85        end
86    end
87    [t,uid_calib]=add(t,1,'element',StructName);
88end
89
90%% save the output file
91t=struct2xml(Struct,t,uid_calib);
92try
93save(t,outputfile);
94catch ME
95    errormsg=['error in update_imadoc' ME.message];
96end
Note: See TracBrowser for help on using the repository browser.