source: trunk/src/update_imadoc.m @ 177

Last change on this file since 177 was 156, checked in by sommeria, 14 years ago

many bug repairs and corrections for mouse action
create_grid: option for black marjkers for grid detection

File size: 2.2 KB
RevLine 
[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%-------------------------------------------------------------
[114]9function errormsg=update_imadoc(GeometryCalib,outputfile)
[156]10tic
[114]11errormsg='';
[13]12testappend=0;
13if exist(outputfile,'file');%=1 if the output file already exists, 0 else 
[29]14    testappend=1;
[13]15    t=xmltree(outputfile); %read the file
[17]16    backupfile=outputfile;
17    testexist=2;
18    while testexist==2
19       backupfile=[backupfile '~'];
20       testexist=exist(backupfile,'file');
21    end
22    [success,message]=copyfile(outputfile,backupfile);%make backup
[114]23    if success==0
[156]24        errormsg=message;
[114]25    end
[13]26    uid=find(t,'ImaDoc');
27    if ~isequal(uid,1)
28        return
[114]29    end       
[13]30    %if the xml file is  ImaDoc
31    uid_calib=find(t,'ImaDoc/GeometryCalib');
32    if isempty(uid_calib)  %if GeometryCalib does not already exists, create it
33        [t,uid_calib]=add(t,1,'element','GeometryCalib');
34    else %if GeometryCalib already exists, delete its content
35        if isequal(success,1)
36            delete(outputfile)
37        else
38            return
39        end
40        uid_child=children(t,uid_calib);
41        t=delete(t,uid_child);
42    end
43end
[84]44%create a new xml file
[13]45if ~testappend
46    t=xmltree;
47    t=set(t,1,'name','ImaDoc');
[84]48    % in case of movie (avi file), copy timing info in the new xml file
49    [pp,outputroot]=fileparts(outputfile);
50    info=[];
51    if exist(fullfile(pp,[outputroot '.avi']),'file')
52        info=aviinfo(fullfile(pp,[outputroot '.avi']));
53    elseif exist(fullfile(pp,[outputroot '.AVI']),'file')
54        info=fullfile(pp,[outputroot '.AVI']);
55    end
56    if ~isempty(info)
57        [t,uid_camera]=add(t,1,'element','Camera');
58        Camera.TimeUnit='s';
59        Camera.BurstTiming.Time=0;
60        Camera.BurstTiming.Dti=1/info.FramesPerSecond;
61        Camera.BurstTiming.NbDti=info.NumFrames-1;
[156]62        t=struct2xml(Camera,t,uid_camera);
[84]63    end
64   [t,uid_calib]=add(t,1,'element','GeometryCalib');
[13]65end
66t=struct2xml(GeometryCalib,t,uid_calib);
67save(t,outputfile);
[156]68toc
Note: See TracBrowser for help on using the repository browser.