source: trunk/src/series/relabel_i_j.m @ 664

Last change on this file since 664 was 635, checked in by sommeria, 12 years ago
File size: 23.2 KB
RevLine 
[563]1%'relabel_i_j': relabel an image series with two indices, and correct errors from the RDvision transfer program
2%------------------------------------------------------------------------
3% function ParamOut=relabel_i_j(Param)
4%------------------------------------------------------------------------
[599]5%
[563]6%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
7%
8%OUTPUT
[599]9% ParamOut: sets options in the GUI series.fig needed for the function
[563]10%
11%INPUT:
12% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
13% In batch mode, Param is the name of the corresponding xml file containing the same information
[599]14% when Param.Action.RUN=0 (as activated when the current Action is selected
15% in series), the function ouput paramOut set the activation of the needed GUI elements
[563]16%
[599]17% Param contains the elements:(use the menu bar command 'export/GUI config' in series to
18% see the current structure Param)
[563]19%    .InputTable: cell of input file names, (several lines for multiple input)
20%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
21%    .OutputSubDir: name of the subdirectory for data outputs
[599]22%    .OutputDirExt: directory extension for data outputs
[563]23%    .Action: .ActionName: name of the current activated function
24%             .ActionPath:   path of the current activated function
[599]25%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
26%             .RUN =0 for GUI input, =1 for function activation
27%             .RunMode='local','background', 'cluster': type of function  use
28%             
[563]29%    .IndexRange: set the file or frame indices on which the action must be performed
30%    .FieldTransform: .TransformName: name of the selected transform function
31%                     .TransformPath:   path  of the selected transform function
32%    .InputFields: sub structure describing the input fields withfields
[599]33%              .FieldName: name(s) of the field
[563]34%              .VelType: velocity type
35%              .FieldName_1: name of the second field in case of two input series
36%              .VelType_1: velocity type of the second field in case of two input series
[599]37%              .Coord_y: name of y coordinate variable
38%              .Coord_x: name of x coordinate variable
[563]39%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
40%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41
42function ParamOut=relabel_i_j(Param) %default output=relabel_i_j(Param)
43
44%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
[599]45if isstruct(Param) && isequal(Param.Action.RUN,0)
46    ParamOut.AllowInputSort='off';...% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
47    ParamOut.WholeIndexRange='on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
48    ParamOut.NbSlice='one'; ...%nbre of slices, 'one' prevents splitting in several processes, ('off' by default)
49    ParamOut.VelType='off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
50    ParamOut.FieldName='off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
51    ParamOut.FieldTransform = 'off';...%can use a transform function
52    ParamOut.ProjObject='off';...%can use projection object(option 'off'/'on',
53    ParamOut.Mask='off';...%can use mask option   (option 'off'/'on', 'off' by default)
54    ParamOut.OutputDirExt='';%set the output dir extension
55    if size(Param.InputTable,1)>1
56        msgbox_uvmat('WARNING', 'this function acts only on the first input file line')
57    end
58return
[563]59end
60
[599]61ParamOut=[];
62%%%%%%%%%%%% STANDARD PART  %%%%%%%%%%%%
63%% read input parameters from an xml file if input is a file name (batch mode)
64checkrun=1;
[563]65if ischar(Param)
[599]66    Param=xml2struct(Param);% read Param as input file (batch case)
67    checkrun=0;
[563]68end
[624]69hseries=findobj(allchild(0),'Tag','series');
70RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
71WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
[563]72
73%% root input file(s) and type
74RootPath=Param.InputTable(:,1);
75RootFile=Param.InputTable(:,3);
76SubDir=Param.InputTable(:,2);
77NomType=Param.InputTable(:,4);
78FileExt=Param.InputTable(:,5);
79
80% get the set of input file names (cell array filecell), and the lists of
81% input file or frame indices i1_series,i2_series,j1_series,j2_series
82[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
83 
84% numbers of slices and file indices
85
86nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
87nbfield_i=size(i1_series{1},2); %nb of fields for the i index
88nbfield=nbfield_j*nbfield_i; %total number of fields
89
90%determine the file type on each line from the first input file
91ImageTypeOptions={'image','multimage','mmreader','video'};
[599]92
93if ~exist(filecell{1,1}','file')
94    msgbox_uvmat('ERROR',['the first input file ' filecell{1,1} ' does not exist'])
95    return
[563]96end
[599]97[FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1});
98CheckImage=~isempty(find(strcmp(FileType{1},ImageTypeOptions)));% =1 for images
[563]99
[599]100
[563]101%% calibration data and timing: read the ImaDoc files
102mode=''; %default
103timecell={};
104itime=0;
105NbSlice_calib={};
[599]106
107SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
108filexml=[fullfile(RootPath{1},SubDirBase) '.xml'];%new convention: xml at the level of the image folder
109if ~exist(filexml,'file')
110    filexml=[fullfile(RootPath{1},SubDir{1},RootFile{1}) '.xml']; % old convention: xml inside the image folder
[563]111    if ~exist(filexml,'file')
[599]112        filexml=[fullfile(RootPath{1},SubDir{1},RootFile{1}) '.civ']; % very old convention: .civ file
[563]113        if ~exist(filexml,'file')
[599]114            filexml='';
[563]115        end
116    end
[599]117end
118if ~isempty(filexml)
119    [XmlData,error]=imadoc2struct_special(filexml);
120end
121if isfield(XmlData,'Time')
122    itime=itime+1;
123    timecell{itime}=XmlData.Time;
124end
125if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
126    NbSlice_calib{1}=size(XmlData.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
127    if ~isequal(NbSlice_calib{1},NbSlice_calib{1})
128        msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
[563]129    end
130end
131
132%% check coincidence in time for several input file series
133% not relevant
134
135%% coordinate transform or other user defined transform
136%not relevant
137%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
138 % EDIT FROM HERE
139
140
141%% Set field names and velocity types
142% not relevant here
143
144%% Initiate output fields
145% not relevant here
146
147%% interactive input of specific parameters (for RDvision system)
148display('RDvision system')
149first_label=0; %image numbers start from 0
[599]150if ~CheckImage || ~strcmp(NomType{1},'_000001')
[563]151    msgbox_uvmat('WARNING','the input is not a file from RDvision: this function relabel_i_j has no action');%error message for directory creation
152    return
153else
154    answer=msgbox_uvmat('','this function will relabel the file series from RDvision from  and correct the xml file');%error message for directory creation
155    if ~strcmp(answer,'Yes')
156        return
157    end
158end
159
160%% copy and adapt the xml file
161NomTypeNew='_1_1';
[599]162if ~isempty(XmlData)
[563]163        t=xmltree(filexml);
164       
165        %update information on the first image name in the series
166        uid_Heading=find(t,'ImaDoc/Heading');
167        if isempty(uid_Heading)
168            [t,uid_Heading]=add(t,1,'element','Heading');
169        end
170        uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
171        j1=[];
172        if ~isempty(j1_series{1})
173            j1=j1_series{1};
174        end
175        ImageName=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},'_1_1',i1_series{1}(1),[],j1);
176        [pth,ImageName]=fileparts(ImageName);
177        ImageName=[ImageName '.png'];
178        if isempty(uid_ImageName)
179            [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
180        end
181        uid_value=children(t,uid_ImageName);
182        if isempty(uid_value)
183            t=add(t,uid_ImageName,'chardata',ImageName);%indicate  name of the first image, with ;png extension
184        else
185            t=set(t,uid_value(1),'value',ImageName);%indicate  name of the first image, with ;png extension
186        end
187       
188        %%%% correction RDvision %%%%
[599]189        if isfield(XmlData,'NbDtj')
[563]190            uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
191            uid_value=children(t,uid_NbDtj);
192            if ~isempty(uid_value)
[599]193                t=set(t,uid_value(1),'value',num2str(XmlData.NbDtj));
[563]194            end
195        end
[599]196        if isfield(XmlData,'NbDtk')
[563]197            uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
198            uid_value=children(t,uid_NbDtk);
199            if ~isempty(uid_value)
[599]200                t=set(t,uid_value(1),'value',num2str(XmlData.NbDtk));
[563]201            end
202        end
[599]203        if isempty(j1_series{1}) && isfield(XmlData,'NbDti')
[563]204            uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
[599]205            t=add(t,uid_Dti,'chardata',num2str(XmlData.Dti));
[563]206            uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
[599]207            t=add(t,uid_NbDti,'chardata',num2str(XmlData.NbDti));
[563]208            uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
209            uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
210            t=delete(t,uid_NbDtj);
211            t=delete(t,uid_NbDtk);
212            uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
213            uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk');
214            t=delete(t,uid_Dtj);
215            t=delete(t,uid_Dtk);
216            NomTypeNew='_1';
217        end
218            SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
219    filexml_new=[fullfile(RootPath{1},SubDirBase) '.xml'];
[599]220       % save(t,filexml_new)
[563]221end
222
223%% main loop on images
224%j1=[];%default
[624]225nbfield2=size(XmlData.Time,2);
[563]226for ifile=1:nbfield
[624]227            update_waitbar(WaitbarHandle,ifile/nbfield)
[635]228    if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
[624]229        disp('program stopped by user')
[599]230        break
231    end
232    filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile));
233    j1=mod(ifile-1+first_label,nbfield2)+1;
234    i1=floor((ifile-1+first_label)/nbfield2)+1;
235    filename_new=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomTypeNew,i1,[],j1);
236    try
237        movefile(filename,filename_new);
238        [s,errormsg] = fileattrib(filename_new,'-w','a'); %set images to read only '-w' for all users ('a')
239        if ~s
240            msgbox_uvmat('ERROR',errormsg);
[563]241            return
242        end
[599]243    catch ME
244        msgbox_uvmat('ERROR',ME.message);
245        return
[563]246    end
[599]247   
[563]248end
249
250%'imadoc2struct_special': reads the xml file for image documentation
251%------------------------------------------------------------------------
252% function [s,errormsg]=imadoc2struct_special(ImaDoc,option)
253%
254% OUTPUT:
255% s: structure representing ImaDoc
256%   s.Heading: information about the data hierarchical structure
257%   s.Time: matrix of times
258%   s.TimeUnit
259%  s.GeometryCalib: substructure containing the parameters for geometric calibration
260% errormsg: error message
261%
262% INPUT:
263% ImaDoc: full name of the xml input file with head key ImaDoc
264% option: ='GeometryCalib': read  the data of GeometryCalib, including source point coordinates
265
266function [s,errormsg]=imadoc2struct_special(ImaDoc,option)
267
268%% default input and output
269if ~exist('option','var')
270    option='*';
271end
272errormsg=[];%default
273s.Heading=[];%default
274s.Time=[]; %default
275s.TimeUnit=[]; %default
276s.GeometryCalib=[];
277tsai=[];%default
278
279%% opening the xml file
280if exist(ImaDoc,'file')~=2, errormsg=[ ImaDoc ' does not exist']; return;end;%input file does not exist
281try
282    t=xmltree(ImaDoc);
283catch
284    errormsg={[ImaDoc ' is not a valid xml file']; lasterr};
285    display(errormsg);
286    return
287end
288uid_root=find(t,'/ImaDoc');
289if isempty(uid_root), errormsg=[ImaDoc ' is not an image documentation file ImaDoc']; return; end;%not an ImaDoc .xml file
290
291
292%% Heading
293uid_Heading=find(t,'/ImaDoc/Heading');
294if ~isempty(uid_Heading),
295    uid_Campaign=find(t,'/ImaDoc/Heading/Campaign');
296    uid_Exp=find(t,'/ImaDoc/Heading/Experiment');
297    uid_Device=find(t,'/ImaDoc/Heading/Device');
298    uid_Record=find(t,'/ImaDoc/Heading/Record');
299    uid_FirstImage=find(t,'/ImaDoc/Heading/ImageName');
300    s.Heading.Campaign=get(t,children(t,uid_Campaign),'value');
301    s.Heading.Experiment=get(t,children(t,uid_Exp),'value');
302    s.Heading.Device=get(t,children(t,uid_Device),'value');
303    if ~isempty(uid_Record)
304        s.Heading.Record=get(t,children(t,uid_Record),'value');
305    end
306    s.Heading.ImageName=get(t,children(t,uid_FirstImage),'value');
307end
308
309%% Camera  and timing
310if strcmp(option,'*') || strcmp(option,'Camera')
311    uid_Camera=find(t,'/ImaDoc/Camera');
312    if ~isempty(uid_Camera)
313        uid_ImageSize=find(t,'/ImaDoc/Camera/ImageSize');
314        if ~isempty(uid_ImageSize);
315            ImageSize=get(t,children(t,uid_ImageSize),'value');
316            xindex=findstr(ImageSize,'x');
317            if length(xindex)>=2
318                s.Npx=str2double(ImageSize(1:xindex(1)-1));
319                s.Npy=str2double(ImageSize(xindex(1)+1:xindex(2)-1));
320            end
321        end
322        uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit');
323        if ~isempty(uid_TimeUnit)
324            s.TimeUnit=get(t,children(t,uid_TimeUnit),'value');
325        end
326        uid_BurstTiming=find(t,'/ImaDoc/Camera/BurstTiming');
327        if ~isempty(uid_BurstTiming)
328            for k=1:length(uid_BurstTiming)
329                subt=branch(t,uid_BurstTiming(k));%subtree under BurstTiming
330                % reading Dtk
331                Frequency=get_value(subt,'/BurstTiming/FrameFrequency',1);
332                Dtj=get_value(subt,'/BurstTiming/Dtj',[]);
333                Dtj=Dtj/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
334                NbDtj=get_value(subt,'/BurstTiming/NbDtj',[]);
335                %%%% correction RDvision %%%%
336%                 NbDtj=NbDtj/numel(Dtj);
337%                 s.NbDtj=NbDtj;
338%                 %%%%
339                Dti=get_value(subt,'/BurstTiming/Dti',[]);
340                NbDti=get_value(subt,'/BurstTiming/NbDti',1);
341                 %%%% correction RDvision %%%%
342                if isempty(Dti)% series
343                     Dti=Dtj;
344                      NbDti=NbDtj;
345                     Dtj=[];
346                     s.Dti=Dti;
347                     s.NbDti=NbDti;
348                else
349                    % NbDtj=NbDtj/numel(Dtj);%bursts
350                    if ~isempty(NbDtj)
351                    s.NbDtj=NbDtj/numel(Dtj);%bursts;
352                    else
353                        s.NbDtj=1;
354                    end
355                end
356                %%%% %%%%
357                Dti=Dti/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
358
359                Time_val=get_value(subt,'/BurstTiming/Time',0);%time in TimeUnit
360                if ~isempty(Dti)
361                    Dti=reshape(Dti'*ones(1,NbDti),NbDti*numel(Dti),1); %concatene Dti vector NbDti times
362                    Time_val=[Time_val;Time_val(end)+cumsum(Dti)];%append the times defined by the intervals  Dti
363                end
364                if ~isempty(Dtj)
365                    Dtj=reshape(Dtj'*ones(1,s.NbDtj),1,s.NbDtj*numel(Dtj)); %concatene Dtj vector NbDtj times
366                    Dtj=[0 Dtj];
367                    Time_val=Time_val*ones(1,numel(Dtj))+ones(numel(Time_val),1)*cumsum(Dtj);% produce a time matrix with Dtj
368                end
369                % reading Dtk
370                Dtk=get_value(subt,'/BurstTiming/Dtk',[]);
371                NbDtk=get_value(subt,'/BurstTiming/NbDtk',1);
372                %%%% correction RDvision %%%%
373                if ~isequal(NbDtk,1)
374                    NbDtk=-1+(NbDtk+1)/(NbDti+1);
375                end
376                s.NbDtk=NbDtk;
377                %%%%%
378                if isempty(Dtk)
379                    s.Time=[s.Time;Time_val];
380                else
381                    for kblock=1:NbDtk+1
382                        Time_val_k=Time_val+(kblock-1)*Dtk;
383                        s.Time=[s.Time;Time_val_k];
384                    end
385                end
386            end
387        end
388    end
389end
390
391%% motor
392if strcmp(option,'*') || strcmp(option,'GeometryCalib')
393    uid_subtree=find(t,'/ImaDoc/TranslationMotor');
394    if length(uid_subtree)==1
395        subt=branch(t,uid_subtree);%subtree under GeometryCalib
396       [s.TranslationMotor,errormsg]=read_subtree(subt,{'Nbslice','ZStart','ZEnd'},[1 1 1],[1 1 1]);
397    end
398end
399%%  geometric calibration
400if strcmp(option,'*') || strcmp(option,'GeometryCalib')
401    uid_GeometryCalib=find(t,'/ImaDoc/GeometryCalib');
402    if ~isempty(uid_GeometryCalib)
403        if length(uid_GeometryCalib)>1
404            errormsg=['More than one GeometryCalib in ' filecivxml];
405            return
406        end
407        subt=branch(t,uid_GeometryCalib);%subtree under GeometryCalib
408        cont=get(subt,1,'contents');
409        if ~isempty(cont)
410            uid_CalibrationType=find(subt,'/GeometryCalib/CalibrationType');
411            if isequal(length(uid_CalibrationType),1)
412                tsai.CalibrationType=get(subt,children(subt,uid_CalibrationType),'value');
413            end
414            uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit');
415            if isequal(length(uid_CoordUnit),1)
416                tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value');
417            end
418            uid_fx_fy=find(subt,'/GeometryCalib/fx_fy');
419            focal=[];%default fro old convention (Reg Wilson)
420            if isequal(length(uid_fx_fy),1)
421                tsai.fx_fy=str2num(get(subt,children(subt,uid_fx_fy),'value'));
422            else %old convention (Reg Wilson)
423                uid_focal=find(subt,'/GeometryCalib/focal');
424                uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy');
425                uid_sx=find(subt,'/GeometryCalib/sx');
426                if ~isempty(uid_focal) && ~isempty(uid_dpx_dpy) && ~isempty(uid_sx)
427                    dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value'));
428                    sx=str2num(get(subt,children(subt,uid_sx),'value'));
429                    focal=str2num(get(subt,children(subt,uid_focal),'value'));
430                    tsai.fx_fy(1)=sx*focal/dpx_dpy(1);
431                    tsai.fx_fy(2)=focal/dpx_dpy(2);
432                end
433            end
434            uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy');
435            if ~isempty(uid_Cx_Cy)
436                tsai.Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value'));
437            end
438            uid_kc=find(subt,'/GeometryCalib/kc');
439            if ~isempty(uid_kc)
440                tsai.kc=str2double(get(subt,children(subt,uid_kc),'value'));
441            else %old convention (Reg Wilson)
442                uid_kappa1=find(subt,'/GeometryCalib/kappa1');
443                if ~isempty(uid_kappa1)&& ~isempty(focal)
444                    kappa1=str2double(get(subt,children(subt,uid_kappa1),'value'));
445                    tsai.kc=-kappa1*focal*focal;
446                end
447            end
448            uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz');
449            if ~isempty(uid_Tx_Ty_Tz)
450                tsai.Tx_Ty_Tz=str2num(get(subt,children(subt,uid_Tx_Ty_Tz),'value'));
451            end
452            uid_R=find(subt,'/GeometryCalib/R');
453            if ~isempty(uid_R)
454                RR=get(subt,children(subt,uid_R),'value');
455                if length(RR)==3
456                    tsai.R=[str2num(RR{1});str2num(RR{2});str2num(RR{3})];
457                end
458            end
459           
460            %look for laser plane definitions
461            uid_Angle=find(subt,'/GeometryCalib/PlaneAngle');
462            uid_Pos=find(subt,'/GeometryCalib/SliceCoord');
463            if isempty(uid_Pos)
464                uid_Pos=find(subt,'/GeometryCalib/PlanePos');%old convention
465            end
466            if ~isempty(uid_Angle)
467                tsai.PlaneAngle=str2num(get(subt,children(subt,uid_Angle),'value'));
468            end
469            if ~isempty(uid_Pos)
470                for j=1:length(uid_Pos)
471                    tsai.SliceCoord(j,:)=str2num(get(subt,children(subt,uid_Pos(j)),'value'));
472                end
473                uid_DZ=find(subt,'/GeometryCalib/SliceDZ');
474                uid_NbSlice=find(subt,'/GeometryCalib/NbSlice');
475                if ~isempty(uid_DZ) && ~isempty(uid_NbSlice)
476                    DZ=str2double(get(subt,children(subt,uid_DZ),'value'));
477                    NbSlice=get(subt,children(subt,uid_NbSlice),'value');
478                    if isequal(NbSlice,'volume')
479                        tsai.NbSlice='volume';
480                        NbSlice=NbDtj+1;
481                    else
482                        tsai.NbSlice=str2double(NbSlice);
483                    end
484                    tsai.SliceCoord=ones(NbSlice,1)*tsai.SliceCoord+DZ*(0:NbSlice-1)'*[0 0 1];
485                end
486            end   
487            tsai.SliceAngle=get_value(subt,'/GeometryCalib/SliceAngle',[0 0 0]);
488            tsai.VolumeScan=get_value(subt,'/GeometryCalib/VolumeScan','n');
489            tsai.InterfaceCoord=get_value(subt,'/GeometryCalib/InterfaceCoord',[0 0 0]);
490            tsai.RefractionIndex=get_value(subt,'/GeometryCalib/RefractionIndex',1);
491           
492            if strcmp(option,'GeometryCalib')
493                tsai.PointCoord=get_value(subt,'/GeometryCalib/SourceCalib/PointCoord',[0 0 0 0 0]);
494            end
495            s.GeometryCalib=tsai;
496        end
497    end
498end
499
500%--------------------------------------------------
501%  read a subtree
502% INPUT:
503% t: xltree
504% head_element: head elelemnt of the subtree
505% Data, structure containing
506%    .Key: element name
507%    .Type: type of element ('charg', 'float'....)
508%    .NbOccur: nbre of occurrence, NaN for un specified number
509function [s,errormsg]=read_subtree(subt,Data,NbOccur,NumTest)
510%--------------------------------------------------
511s=[];%default
512errormsg='';
513head_element=get(subt,1,'name');
514    cont=get(subt,1,'contents');
515    if ~isempty(cont)
516        for ilist=1:length(Data)
517            uid_key=find(subt,[head_element '/' Data{ilist}]);
518            if ~isequal(length(uid_key),NbOccur(ilist))
519                errormsg=['wrong number of occurence for ' Data{ilist}];
520                return
521            end
522            for ival=1:length(uid_key)
523                val=get(subt,children(subt,uid_key(ival)),'value');
524                if ~NumTest(ilist)
525                    eval(['s.' Data{ilist} '=val;']);
526                else
527                    eval(['s.' Data{ilist} '=str2double(val);'])
528                end
529            end
530        end
531    end
532
533
534%--------------------------------------------------
535%  read an xml element
536function val=get_value(t,label,default)
537%--------------------------------------------------
538val=default;
539uid=find(t,label);%find the element iud(s)
540if ~isempty(uid) %if the element named label exists
541   uid_child=children(t,uid);%find the children
542   if ~isempty(uid_child)
543       data=get(t,uid_child,'type');%get the type of child
544       if iscell(data)% case of multiple element
545           for icell=1:numel(data)
546               val_read=str2num(get(t,uid_child(icell),'value'));
547               if ~isempty(val_read)
548                   val(icell,:)=val_read;
549               end
550           end
551%           val=val';
552       else % case of unique element value
553           val_read=str2num(get(t,uid_child,'value'));
554           if ~isempty(val_read)
555               val=val_read;
556           else
557              val=get(t,uid_child,'value');%char string data
558           end
559       end
560   end
561end
Note: See TracBrowser for help on using the repository browser.