[13] | 1 | %'update_imadoc': update an xml file with geometric calibration parameters |
---|
| 2 | %-------------------------------------------------------------------------- |
---|
| 3 | % function update_imadoc(GeometryCalib,outputfile) |
---|
| 4 | % |
---|
| 5 | %INPUT: |
---|
| 6 | % GeometryCalib: structure containing the calibration parameters |
---|
| 7 | % outputfile: xml file to modify |
---|
| 8 | %------------------------------------------------------------- |
---|
| 9 | function update_imadoc(GeometryCalib,outputfile) |
---|
| 10 | testappend=0; |
---|
| 11 | if exist(outputfile,'file');%=1 if the output file already exists, 0 else |
---|
| 12 | t=xmltree(outputfile); %read the file |
---|
[17] | 13 | backupfile=outputfile; |
---|
| 14 | testexist=2; |
---|
| 15 | while testexist==2 |
---|
| 16 | backupfile=[backupfile '~']; |
---|
| 17 | testexist=exist(backupfile,'file'); |
---|
| 18 | end |
---|
| 19 | [success,message]=copyfile(outputfile,backupfile);%make backup |
---|
[13] | 20 | uid=find(t,'ImaDoc'); |
---|
| 21 | if ~isequal(uid,1) |
---|
| 22 | return |
---|
| 23 | end |
---|
| 24 | |
---|
| 25 | %if the xml file is ImaDoc |
---|
| 26 | uid_calib=find(t,'ImaDoc/GeometryCalib'); |
---|
| 27 | if isempty(uid_calib) %if GeometryCalib does not already exists, create it |
---|
| 28 | [t,uid_calib]=add(t,1,'element','GeometryCalib'); |
---|
| 29 | else %if GeometryCalib already exists, delete its content |
---|
[17] | 30 | % backupfile=outputfile; |
---|
| 31 | % testexist=2; |
---|
| 32 | % while testexist==2 |
---|
| 33 | % backupfile=[backupfile '~']; |
---|
| 34 | % testexist=exist(backupfile,'file'); |
---|
| 35 | % end |
---|
| 36 | % [success,message]=copyfile(outputfile,backupfile);%make backup |
---|
[13] | 37 | if isequal(success,1) |
---|
| 38 | delete(outputfile) |
---|
| 39 | else |
---|
| 40 | return |
---|
| 41 | end |
---|
| 42 | uid_child=children(t,uid_calib); |
---|
| 43 | t=delete(t,uid_child); |
---|
| 44 | testappend=1; |
---|
| 45 | end |
---|
| 46 | end |
---|
| 47 | if ~testappend |
---|
| 48 | t=xmltree; |
---|
| 49 | t=set(t,1,'name','ImaDoc'); |
---|
| 50 | [t,uid_calib]=add(t,1,'element','GeometryCalib'); |
---|
| 51 | % t=struct2xml(GeometryCalib,t,uid_calib); |
---|
| 52 | end |
---|
| 53 | t=struct2xml(GeometryCalib,t,uid_calib); |
---|
| 54 | save(t,outputfile); |
---|