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

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

extract_rdvision corrected

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