Ignore:
Timestamp:
Jul 4, 2024, 4:23:43 PM (3 months ago)
Author:
sommeria
Message:

update_xml simlified, bug on civ_series corrected

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/update_imadoc.m

    r1151 r1152  
    11%'update_imadoc': update an xml file with geometric calibration parameters
    22%--------------------------------------------------------------------------
    3 %  function update_imadoc(Struct,outputfile)
     3%  function [checkcreate,xmlfile,errormsg]=update_imadoc(Struct,RootPath,SubDir,StructName)
    44%
    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
    814% 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~,
    917%-------------------------------------------------------------
    1018
     
    2735%=======================================================================
    2836
    29 function errormsg=update_imadoc(Struct,outputfile,StructName)
     37function [checkupdate,xmlfile,errormsg]=update_imadoc(RootPath,SubDir,StructName,Struct,checkbackup)
     38
    3039errormsg='';
    31 testappend=0;
     40if ~exist('checkbackup','var')
     41    checkbackup=1;
     42end
    3243
    3344%% 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;
     45xmlfile=find_imadoc(RootPath,SubDir);
     46if isempty(xmlfile)
     47    checkupdate=0;
     48else
     49    checkupdate=1;
     50end
     51
     52%% backup the existing xml file, adding a ~ to its name
     53if checkupdate
     54    if checkbackup
     55        backupfile=xmlfile;
     56        testexist=2;
    4057        while testexist==2
    4158            backupfile=[backupfile '~'];
    4259            testexist=exist(backupfile,'file');
    4360        end
    44         [success,message]=movefile(outputfile,backupfile);%make backup
     61        [success,message]=copyfile(xmlfile,backupfile);%make backup
    4562        if success~=1
    4663            errormsg=['errror in xml file backup: ' message];
     
    4865        end
    4966    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
    5768    title=get(t,1,'name');
    5869    if ~strcmp(title,'ImaDoc')
    59         errormsg=[outputfile ' not appropriate for calibration'];
     70        errormsg=[xmlfile ' not appropriate for calibration'];
    6071        return
    6172    end
     
    6778        t=delete(t,uid_child);
    6879    end
    69 end
    70 
    71 %% create a new xml file
    72 if ~testappend
     80else   % create a new xml file
    7381    t=xmltree;
    7482    t=set(t,1,'name','ImaDoc');
    75     % in case of movie (avi file), copy timing info in the new xml file
    76     [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 matlab
    82             imainfo=aviinfo(FileName);
    83             imainfo.FrameRate=imainfo.FramesPerSecond;
    84             imainfo.NumberOfFrames=imainfo.NumFrames;
    85         else %use video function videoreader of matlab
    86             imainfo=get(videoreader(FileName));
    87         end
    88         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         end
    96     end
    9783    [t,uid_calib]=add(t,1,'element',StructName);
    9884end
     
    10187t=struct2xml(Struct,t,uid_calib);
    10288try
    103     save(t,outputfile);
     89    save(t,xmlfile);
    10490catch ME
    105     errormsg=['error in saving ' outputfile ': ' ME.message];
     91    errormsg=['error in saving ' xmlfile ': ' ME.message];
    10692end
Note: See TracChangeset for help on using the changeset viewer.