source: trunk/src/update_imadoc.m @ 1027

Last change on this file since 1027 was 1027, checked in by g7moreau, 7 years ago
  • Update Copyright 2017 -> 2018
File size: 3.6 KB
RevLine 
[13]1%'update_imadoc': update an xml file with geometric calibration parameters
2%--------------------------------------------------------------------------
[630]3%  function update_imadoc(Struct,outputfile)
[13]4%
5%INPUT:
[630]6% Struct: structure containing the calibration parameters
[13]7% outputfile: xml file to modify
[630]8% StructName : Name of the field in the xml file
[13]9%-------------------------------------------------------------
[809]10
11%=======================================================================
[1027]12% Copyright 2008-2018, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
[809]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
[630]29function errormsg=update_imadoc(Struct,outputfile,StructName)
[114]30errormsg='';
[13]31testappend=0;
[498]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
[29]34    testappend=1;
[17]35    backupfile=outputfile;
[498]36    t=xmltree(outputfile); %read the file
37    title=get(t,1,'name');
[499]38    if strcmp(title,'ImaDoc')
[954]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
[498]51        %if the xml file is  ImaDoc
[630]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
[498]56            uid_child=children(t,uid_calib);
57            t=delete(t,uid_child);
[13]58        end
59    end
60end
[498]61
62%% create a new xml file
[13]63if ~testappend
64    t=xmltree;
65    t=set(t,1,'name','ImaDoc');
[84]66    % in case of movie (avi file), copy timing info in the new xml file
[634]67    [pp,outputroot]=fileparts(outputfile);
[414]68    %     imainfo=[];
[634]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
[630]88    [t,uid_calib]=add(t,1,'element',StructName);
[13]89end
[498]90
91%% save the output file
[630]92t=struct2xml(Struct,t,uid_calib);
[745]93try
[13]94save(t,outputfile);
[745]95catch ME
96    errormsg=['error in update_imadoc' ME.message];
97end
Note: See TracBrowser for help on using the repository browser.