source: trunk/src/update_imadoc.m @ 1155

Last change on this file since 1155 was 1152, checked in by sommeria, 5 months ago

update_xml simlified, bug on civ_series corrected

File size: 3.2 KB
Line 
1%'update_imadoc': update an xml file with geometric calibration parameters
2%--------------------------------------------------------------------------
3%  function [checkcreate,xmlfile,errormsg]=update_imadoc(Struct,RootPath,SubDir,StructName)
4%
5% OUTPUT:
6% checkupdate= 1 if the xml file (containing timing)already exist, =0 when it has to be created
7% xmlfile: name of the xmlfile containing the the calibration data
8% errormsg: error message, ='' if OK
9
10% INPUT:
11
12% RootPath: path to the folder containing the image series to calibrate
13% SubDir: folder contaiting the image series to calibrate
14% StructName : Name of the field in the xml file
15% Struct: Matlab structure containing the calibration parameters
16% checkbackup=1 (default): backup of existing xml file as .xml~,
17%-------------------------------------------------------------
18
19%=======================================================================
20% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
21%   http://www.legi.grenoble-inp.fr
22%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
23%
24%     This file is part of the toolbox UVMAT.
25%
26%     UVMAT is free software; you can redistribute it and/or modify
27%     it under the terms of the GNU General Public License as published
28%     by the Free Software Foundation; either version 2 of the license,
29%     or (at your option) any later version.
30%
31%     UVMAT is distributed in the hope that it will be useful,
32%     but WITHOUT ANY WARRANTY; without even the implied warranty of
33%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34%     GNU General Public License (see LICENSE.txt) for more details.
35%=======================================================================
36
37function [checkupdate,xmlfile,errormsg]=update_imadoc(RootPath,SubDir,StructName,Struct,checkbackup)
38
39errormsg='';
40if ~exist('checkbackup','var')
41    checkbackup=1;
42end
43
44%% set the output xml file at the root, hide other existing  xml files
45xmlfile=find_imadoc(RootPath,SubDir);
46if isempty(xmlfile)
47    checkupdate=0;
48else
49    checkupdate=1;
50end
51
52%% backup the existing xml file, adding a ~ to its name
53if checkupdate
54    if checkbackup
55        backupfile=xmlfile;
56        testexist=2;
57        while testexist==2
58            backupfile=[backupfile '~'];
59            testexist=exist(backupfile,'file');
60        end
61        [success,message]=copyfile(xmlfile,backupfile);%make backup
62        if success~=1
63            errormsg=['errror in xml file backup: ' message];
64            return
65        end
66    end
67    t=xmltree(xmlfile); %read the file
68    title=get(t,1,'name');
69    if ~strcmp(title,'ImaDoc')
70        errormsg=[xmlfile ' not appropriate for calibration'];
71        return
72    end
73    uid_calib=find(t,['ImaDoc/' StructName]);
74    if isempty(uid_calib)  %if Struct does not already exists, create it
75        [t,uid_calib]=add(t,1,'element',StructName);
76    else %if Struct already exists, delete its content
77        uid_child=children(t,uid_calib);
78        t=delete(t,uid_child);
79    end
80else   % create a new xml file
81    t=xmltree;
82    t=set(t,1,'name','ImaDoc');
83    [t,uid_calib]=add(t,1,'element',StructName);
84end
85
86%% save the output file
87t=struct2xml(Struct,t,uid_calib);
88try
89    save(t,xmlfile);
90catch ME
91    errormsg=['error in saving ' xmlfile ': ' ME.message];
92end
Note: See TracBrowser for help on using the repository browser.