source: trunk/src/series/extract_rdvision.m @ 786

Last change on this file since 786 was 786, checked in by sommeria, 10 years ago

add extract_rdviisionn to transform into png images

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