source: trunk/src/update_imadoc.m @ 764

Last change on this file since 764 was 745, checked in by sommeria, 11 years ago

set_slice installed

File size: 2.6 KB
Line 
1%'update_imadoc': update an xml file with geometric calibration parameters
2%--------------------------------------------------------------------------
3%  function update_imadoc(Struct,outputfile)
4%
5%INPUT:
6% Struct: structure containing the calibration parameters
7% outputfile: xml file to modify
8% StructName : Name of the field in the xml file
9%-------------------------------------------------------------
10function errormsg=update_imadoc(Struct,outputfile,StructName)
11errormsg='';
12testappend=0;
13%% backup the output file if it already exist, and read it
14if exist(outputfile,'file');%=1 if the output file already exists, 0 else
15    testappend=1;
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~=1
24        errormsg=['errror in xml file backup: ' message];
25        return
26    end
27    t=xmltree(outputfile); %read the file
28    title=get(t,1,'name');
29    if strcmp(title,'ImaDoc')
30        testappend=1;
31        %if the xml file is  ImaDoc
32        uid_calib=find(t,['ImaDoc/' StructName]);
33        if isempty(uid_calib)  %if Struct does not already exists, create it
34            [t,uid_calib]=add(t,1,'element',StructName);
35        else %if Struct already exists, delete its content
36            uid_child=children(t,uid_calib);
37            t=delete(t,uid_child);
38        end
39    end
40end
41
42%% create a new xml file
43if ~testappend
44    t=xmltree;
45    t=set(t,1,'name','ImaDoc');
46    % in case of movie (avi file), copy timing info in the new xml file
47    [pp,outputroot]=fileparts(outputfile);
48    %     imainfo=[];
49    if exist(fullfile(pp,[outputroot '.avi']),'file')
50        FileName=fullfile(pp,[outputroot '.avi']);
51        hhh=which('videoreader');
52        if isempty(hhh)%use old video function of matlab
53            imainfo=aviinfo(FileName);
54            imainfo.FrameRate=imainfo.FramesPerSecond;
55            imainfo.NumberOfFrames=imainfo.NumFrames;
56        else %use video function videoreader of matlab
57            imainfo=get(videoreader(FileName));
58        end
59        if ~isempty(imainfo)
60            [t,uid_camera]=add(t,1,'element','Camera');
61            Camera.TimeUnit='s';
62            Camera.BurstTiming.Time=0;
63            Camera.BurstTiming.Dti=1/imainfo.FrameRate;
64            Camera.BurstTiming.NbDti=imainfo.NumberOfFrames-1;
65            t=struct2xml(Camera,t,uid_camera);
66        end
67    end
68    [t,uid_calib]=add(t,1,'element',StructName);
69end
70
71%% save the output file
72t=struct2xml(Struct,t,uid_calib);
73try
74save(t,outputfile);
75catch ME
76    errormsg=['error in update_imadoc' ME.message];
77end
Note: See TracBrowser for help on using the repository browser.