source: trunk/src/update_imadoc.m @ 456

Last change on this file since 456 was 414, checked in by sommeria, 12 years ago

bug corrected in civ (index j)
bug corrected in update_imadoc (geomtetry_calib)

File size: 2.5 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    %     imainfo=[];
50    if exist(fullfile(pp,[outputroot '.avi']),'file')
51        FileName=fullfile(pp,[outputroot '.avi']);
52        hhh=which('videoreader');
53        if isempty(hhh)%use old video function of matlab
54            imainfo=aviinfo(FileName);
55            imainfo.FrameRate=imainfo.FramesPerSecond;
56            imainfo.NumberOfFrames=imainfo.NumFrames;
57        else %use video function videoreader of matlab
58            imainfo=get(videoreader(FileName));
59        end
60        if ~isempty(imainfo)
61            [t,uid_camera]=add(t,1,'element','Camera');
62            Camera.TimeUnit='s';
63            Camera.BurstTiming.Time=0;
64            Camera.BurstTiming.Dti=1/imainfo.FrameRate;
65            Camera.BurstTiming.NbDti=imainfo.NumberOfFrames-1;
66            t=struct2xml(Camera,t,uid_camera);
67        end
68    end
69    [t,uid_calib]=add(t,1,'element','GeometryCalib');
70end
71t=struct2xml(GeometryCalib,t,uid_calib);
72save(t,outputfile);
Note: See TracBrowser for help on using the repository browser.