source: trunk/src/update_imadoc.m @ 275

Last change on this file since 275 was 200, checked in by sommeria, 14 years ago

bug corrections. Introduction of water wheight in calibration

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