source: trunk/src/update_imadoc.m @ 173

Last change on this file since 173 was 156, checked in by sommeria, 13 years ago

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

File size: 2.2 KB
Line 
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%-------------------------------------------------------------
9function errormsg=update_imadoc(GeometryCalib,outputfile)
10tic
11errormsg='';
12testappend=0;
13if exist(outputfile,'file');%=1 if the output file already exists, 0 else 
14    testappend=1;
15    t=xmltree(outputfile); %read the file
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
23    if success==0
24        errormsg=message;
25    end
26    uid=find(t,'ImaDoc');
27    if ~isequal(uid,1)
28        return
29    end       
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
44%create a new xml file
45if ~testappend
46    t=xmltree;
47    t=set(t,1,'name','ImaDoc');
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;
62        t=struct2xml(Camera,t,uid_camera);
63    end
64   [t,uid_calib]=add(t,1,'element','GeometryCalib');
65end
66t=struct2xml(GeometryCalib,t,uid_calib);
67save(t,outputfile);
68toc
Note: See TracBrowser for help on using the repository browser.