Changeset 1152 for trunk/src/update_imadoc.m
- Timestamp:
- Jul 4, 2024, 4:23:43 PM (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/update_imadoc.m
r1151 r1152 1 1 %'update_imadoc': update an xml file with geometric calibration parameters 2 2 %-------------------------------------------------------------------------- 3 % function update_imadoc(Struct,outputfile)3 % function [checkcreate,xmlfile,errormsg]=update_imadoc(Struct,RootPath,SubDir,StructName) 4 4 % 5 %INPUT: 6 % Struct: structure containing the calibration parameters 7 % outputfile: xml file to modify 5 % OUTPUT: 6 % checkupdate= 1 if the xml file (containing timing)already exist, =0 when it has to be created 7 % xmlfile: name of the xmlfile containing the the calibration data 8 % errormsg: error message, ='' if OK 9 10 % INPUT: 11 12 % RootPath: path to the folder containing the image series to calibrate 13 % SubDir: folder contaiting the image series to calibrate 8 14 % StructName : Name of the field in the xml file 15 % Struct: Matlab structure containing the calibration parameters 16 % checkbackup=1 (default): backup of existing xml file as .xml~, 9 17 %------------------------------------------------------------- 10 18 … … 27 35 %======================================================================= 28 36 29 function errormsg=update_imadoc(Struct,outputfile,StructName) 37 function [checkupdate,xmlfile,errormsg]=update_imadoc(RootPath,SubDir,StructName,Struct,checkbackup) 38 30 39 errormsg=''; 31 testappend=0; 40 if ~exist('checkbackup','var') 41 checkbackup=1; 42 end 32 43 33 44 %% set the output xml file at the root, hide other existing xml files 34 dotchar=regexp(outputfile,'\.'); 35 for idot=1:numel(dotchar) 36 outputfile=[outputfile(1:dotchar(end-idot+1)-1) '.xml']; 37 if exist(outputfile,'file') 38 backupfile=outputfile; 39 testexist=2; 45 xmlfile=find_imadoc(RootPath,SubDir); 46 if isempty(xmlfile) 47 checkupdate=0; 48 else 49 checkupdate=1; 50 end 51 52 %% backup the existing xml file, adding a ~ to its name 53 if checkupdate 54 if checkbackup 55 backupfile=xmlfile; 56 testexist=2; 40 57 while testexist==2 41 58 backupfile=[backupfile '~']; 42 59 testexist=exist(backupfile,'file'); 43 60 end 44 [success,message]= movefile(outputfile,backupfile);%make backup61 [success,message]=copyfile(xmlfile,backupfile);%make backup 45 62 if success~=1 46 63 errormsg=['errror in xml file backup: ' message]; … … 48 65 end 49 66 end 50 end 51 52 53 %% backup the output file if it already exist, and read it 54 if exist(outputfile,'file')%=1 if the output file already exists, 0 else 55 testappend=1; 56 t=xmltree(outputfile); %read the file 67 t=xmltree(xmlfile); %read the file 57 68 title=get(t,1,'name'); 58 69 if ~strcmp(title,'ImaDoc') 59 errormsg=[ outputfile ' not appropriate for calibration'];70 errormsg=[xmlfile ' not appropriate for calibration']; 60 71 return 61 72 end … … 67 78 t=delete(t,uid_child); 68 79 end 69 end 70 71 %% create a new xml file 72 if ~testappend 80 else % create a new xml file 73 81 t=xmltree; 74 82 t=set(t,1,'name','ImaDoc'); 75 % in case of movie (avi file), copy timing info in the new xml file76 [pp,outputroot]=fileparts(outputfile);77 % imainfo=[];78 if exist(fullfile(pp,[outputroot '.avi']),'file')79 FileName=fullfile(pp,[outputroot '.avi']);80 hhh=which('videoreader');81 if isempty(hhh)%use old video function of matlab82 imainfo=aviinfo(FileName);83 imainfo.FrameRate=imainfo.FramesPerSecond;84 imainfo.NumberOfFrames=imainfo.NumFrames;85 else %use video function videoreader of matlab86 imainfo=get(videoreader(FileName));87 end88 if ~isempty(imainfo)89 [t,uid_camera]=add(t,1,'element','Camera');90 Camera.TimeUnit='s';91 Camera.BurstTiming.Time=0;92 Camera.BurstTiming.Dti=1/imainfo.FrameRate;93 Camera.BurstTiming.NbDti=imainfo.NumberOfFrames-1;94 t=struct2xml(Camera,t,uid_camera);95 end96 end97 83 [t,uid_calib]=add(t,1,'element',StructName); 98 84 end … … 101 87 t=struct2xml(Struct,t,uid_calib); 102 88 try 103 save(t, outputfile);89 save(t,xmlfile); 104 90 catch ME 105 errormsg=['error in saving ' outputfile ': ' ME.message];91 errormsg=['error in saving ' xmlfile ': ' ME.message]; 106 92 end
Note: See TracChangeset
for help on using the changeset viewer.