[13] | 1 | %'update_imadoc': update an xml file with geometric calibration parameters |
---|
| 2 | %-------------------------------------------------------------------------- |
---|
[1152] | 3 | % function [checkcreate,xmlfile,errormsg]=update_imadoc(Struct,RootPath,SubDir,StructName) |
---|
[13] | 4 | % |
---|
[1152] | 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 |
---|
[630] | 14 | % StructName : Name of the field in the xml file |
---|
[1152] | 15 | % Struct: Matlab structure containing the calibration parameters |
---|
| 16 | % checkbackup=1 (default): backup of existing xml file as .xml~, |
---|
[13] | 17 | %------------------------------------------------------------- |
---|
[809] | 18 | |
---|
| 19 | %======================================================================= |
---|
[1126] | 20 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
[809] | 21 | % http://www.legi.grenoble-inp.fr |
---|
[1127] | 22 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr |
---|
[809] | 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 | |
---|
[1152] | 37 | function [checkupdate,xmlfile,errormsg]=update_imadoc(RootPath,SubDir,StructName,Struct,checkbackup) |
---|
| 38 | |
---|
[114] | 39 | errormsg=''; |
---|
[1152] | 40 | if ~exist('checkbackup','var') |
---|
| 41 | checkbackup=1; |
---|
| 42 | end |
---|
[1151] | 43 | |
---|
| 44 | %% set the output xml file at the root, hide other existing xml files |
---|
[1152] | 45 | xmlfile=find_imadoc(RootPath,SubDir); |
---|
| 46 | if isempty(xmlfile) |
---|
| 47 | checkupdate=0; |
---|
| 48 | else |
---|
| 49 | checkupdate=1; |
---|
| 50 | end |
---|
| 51 | |
---|
| 52 | %% backup the existing xml file, adding a ~ to its name |
---|
| 53 | if checkupdate |
---|
| 54 | if checkbackup |
---|
| 55 | backupfile=xmlfile; |
---|
| 56 | testexist=2; |
---|
[954] | 57 | while testexist==2 |
---|
| 58 | backupfile=[backupfile '~']; |
---|
| 59 | testexist=exist(backupfile,'file'); |
---|
| 60 | end |
---|
[1152] | 61 | [success,message]=copyfile(xmlfile,backupfile);%make backup |
---|
[954] | 62 | if success~=1 |
---|
| 63 | errormsg=['errror in xml file backup: ' message]; |
---|
| 64 | return |
---|
| 65 | end |
---|
[13] | 66 | end |
---|
[1152] | 67 | t=xmltree(xmlfile); %read the file |
---|
[1151] | 68 | title=get(t,1,'name'); |
---|
| 69 | if ~strcmp(title,'ImaDoc') |
---|
[1152] | 70 | errormsg=[xmlfile ' not appropriate for calibration']; |
---|
[1151] | 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 |
---|
[1152] | 80 | else % create a new xml file |
---|
[13] | 81 | t=xmltree; |
---|
| 82 | t=set(t,1,'name','ImaDoc'); |
---|
[630] | 83 | [t,uid_calib]=add(t,1,'element',StructName); |
---|
[13] | 84 | end |
---|
[498] | 85 | |
---|
| 86 | %% save the output file |
---|
[1095] | 87 | t=struct2xml(Struct,t,uid_calib); |
---|
[745] | 88 | try |
---|
[1152] | 89 | save(t,xmlfile); |
---|
[745] | 90 | catch ME |
---|
[1152] | 91 | errormsg=['error in saving ' xmlfile ': ' ME.message]; |
---|
[745] | 92 | end |
---|