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

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