source: trunk/src/update_imadoc.m @ 622

Last change on this file since 622 was 499, checked in by sommeria, 9 years ago

various bugs corrected. PARAM.xml complemented to provide info for 'RUN' mode

File size: 2.6 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;
12%% backup the output file if it already exist, and read it
13if exist(outputfile,'file');%=1 if the output file already exists, 0 else
14    testappend=1;
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~=1
23        errormsg=['errror in xml file backup: ' message];
24        return
25    end
26    t=xmltree(outputfile); %read the file
27    title=get(t,1,'name');
28    if strcmp(title,'ImaDoc')
29        testappend=1;
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            uid_child=children(t,uid_calib);
36            t=delete(t,uid_child);
37        end
38    end
39end
40
41%% create a new xml file
42if ~testappend
43    t=xmltree;
44    t=set(t,1,'name','ImaDoc');
45    % in case of movie (avi file), copy timing info in the new xml file
46    [pp,outputroot]=fileparts(outputfile);
47    %     imainfo=[];
48    if exist(fullfile(pp,[outputroot '.avi']),'file')
49        FileName=fullfile(pp,[outputroot '.avi']);
50        hhh=which('videoreader');
51        if isempty(hhh)%use old video function of matlab
52            imainfo=aviinfo(FileName);
53            imainfo.FrameRate=imainfo.FramesPerSecond;
54            imainfo.NumberOfFrames=imainfo.NumFrames;
55        else %use video function videoreader of matlab
56            imainfo=get(videoreader(FileName));
57        end
58        if ~isempty(imainfo)
59            [t,uid_camera]=add(t,1,'element','Camera');
60            Camera.TimeUnit='s';
61            Camera.BurstTiming.Time=0;
62            Camera.BurstTiming.Dti=1/imainfo.FrameRate;
63            Camera.BurstTiming.NbDti=imainfo.NumberOfFrames-1;
64            t=struct2xml(Camera,t,uid_camera);
65        end
66    end
67    [t,uid_calib]=add(t,1,'element','GeometryCalib');
68end
69
70%% save the output file
71t=struct2xml(GeometryCalib,t,uid_calib);
72save(t,outputfile);
Note: See TracBrowser for help on using the repository browser.