source: trunk/src/update_imadoc.m @ 965

Last change on this file since 965 was 954, checked in by sommeria, 8 years ago

update calib modfied + various updates

File size: 3.6 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    t=xmltree(outputfile); %read the file
37    title=get(t,1,'name');
38    if strcmp(title,'ImaDoc')
39        %         testappend=1;
40        %rename the existing file for backup
41        testexist=2;
42        while testexist==2
43            backupfile=[backupfile '~'];
44            testexist=exist(backupfile,'file');
45        end
46        [success,message]=movefile(outputfile,backupfile);%make backup
47        if success~=1
48            errormsg=['errror in xml file backup: ' message];
49            return
50        end
51        %if the xml file is  ImaDoc
52        uid_calib=find(t,['ImaDoc/' StructName]);
53        if isempty(uid_calib)  %if Struct does not already exists, create it
54            [t,uid_calib]=add(t,1,'element',StructName);
55        else %if Struct already exists, delete its content
56            uid_child=children(t,uid_calib);
57            t=delete(t,uid_child);
58        end
59    end
60end
61
62%% create a new xml file
63if ~testappend
64    t=xmltree;
65    t=set(t,1,'name','ImaDoc');
66    % in case of movie (avi file), copy timing info in the new xml file
67    [pp,outputroot]=fileparts(outputfile);
68    %     imainfo=[];
69    if exist(fullfile(pp,[outputroot '.avi']),'file')
70        FileName=fullfile(pp,[outputroot '.avi']);
71        hhh=which('videoreader');
72        if isempty(hhh)%use old video function of matlab
73            imainfo=aviinfo(FileName);
74            imainfo.FrameRate=imainfo.FramesPerSecond;
75            imainfo.NumberOfFrames=imainfo.NumFrames;
76        else %use video function videoreader of matlab
77            imainfo=get(videoreader(FileName));
78        end
79        if ~isempty(imainfo)
80            [t,uid_camera]=add(t,1,'element','Camera');
81            Camera.TimeUnit='s';
82            Camera.BurstTiming.Time=0;
83            Camera.BurstTiming.Dti=1/imainfo.FrameRate;
84            Camera.BurstTiming.NbDti=imainfo.NumberOfFrames-1;
85            t=struct2xml(Camera,t,uid_camera);
86        end
87    end
88    [t,uid_calib]=add(t,1,'element',StructName);
89end
90
91%% save the output file
92t=struct2xml(Struct,t,uid_calib);
93try
94save(t,outputfile);
95catch ME
96    errormsg=['error in update_imadoc' ME.message];
97end
Note: See TracBrowser for help on using the repository browser.