1 | %'read_multimadoc': read a set of Imadoc files and compare their timing of different file series |
---|
2 | %------------------------------------------------------------------------ |
---|
3 | % [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series) |
---|
4 | % |
---|
5 | % OUTPUT: |
---|
6 | % XmlData: cell array of structure representing the contents of the xml files |
---|
7 | % NbSlice_calib: nbre of slices detected in the geometric calibration data |
---|
8 | % mtrix of times |
---|
9 | % errormsg: error message, ='' if reading OK |
---|
10 | % |
---|
11 | % INPUT: |
---|
12 | % RootPath,SubDir,RootFile,FileExt: cell arrays characterizing the input file series |
---|
13 | % i1_series,i2_series,j1_series,j2_series: cell arrays of file index |
---|
14 | % arrays, as given by the fct uvmat/get_file_series |
---|
15 | % |
---|
16 | function [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series) |
---|
17 | errormsg=''; |
---|
18 | if ischar(RootPath) |
---|
19 | RootPath={RootPath};SubDir={SubDir};RootFile={RootFile};FileExt={FileExt}; |
---|
20 | end |
---|
21 | nbview=numel(RootPath); |
---|
22 | XmlData=cell(1,nbview);%initiate the structures containing the data from the xml file (calibration and timing) |
---|
23 | NbSlice_calib=cell(1,nbview); |
---|
24 | timecell=cell(1,nbview); |
---|
25 | for iview=1:nbview%Loop on views |
---|
26 | XmlFileName=find_imadoc(RootPath{iview},SubDir{iview},RootFile{iview},FileExt{iview}); |
---|
27 | if ~isempty(XmlFileName) |
---|
28 | [XmlData{iview},errormsg]=imadoc2struct(XmlFileName);% read the ImaDoc xml file |
---|
29 | if ~isempty(errormsg) |
---|
30 | return |
---|
31 | end |
---|
32 | end |
---|
33 | if isfield(XmlData{iview},'Time') |
---|
34 | timecell{iview}=XmlData{iview}.Time; |
---|
35 | end |
---|
36 | if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord') |
---|
37 | NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform |
---|
38 | if ~isequal(NbSlice_calib{iview},NbSlice_calib{1}) |
---|
39 | msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series'); |
---|
40 | end |
---|
41 | end |
---|
42 | end |
---|
43 | |
---|
44 | %% check coincidence in time for several input file series |
---|
45 | if isempty(timecell) |
---|
46 | time=[]; |
---|
47 | else |
---|
48 | time=get_time(timecell{1},i1_series{1},i2_series{1},j1_series{1},j2_series{1}); |
---|
49 | end |
---|
50 | if nbview>1 |
---|
51 | time=shiftdim(time,-1); % add a singleton dimension for nbview |
---|
52 | for icell=2:nbview |
---|
53 | if isequal(size(timecell{icell}),size(timecell{1})) |
---|
54 | time_line=get_time(timecell{icell},i1_series{icell},i2_series{icell},j1_series{icell},j2_series{icell}); |
---|
55 | time=cat(1,time,shiftdim(time_line,-1)); |
---|
56 | else |
---|
57 | msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used') |
---|
58 | time=cat(1,time,time(icell-1,:,:)); |
---|
59 | break |
---|
60 | end |
---|
61 | end |
---|
62 | end |
---|
63 | |
---|
64 | function time=get_time(timeimadoc,i1_series,i2_series,j1_series,j2_series) |
---|
65 | if isempty(i2_series)||size(timeimadoc,1) < i2_series(end) ||( ~isempty(j2_series) && size(timeimadoc,2) < j2_series(end))% time array absent or too short in ImaDoc xml file' |
---|
66 | time=[]; |
---|
67 | else |
---|
68 | timevect=timeimadoc'; |
---|
69 | if ~isempty(j1_series) |
---|
70 | vect_index=reshape(j1_series+(i1_series-1)*size(timevect,1),1,[]); |
---|
71 | time=timevect(vect_index); |
---|
72 | if ~isempty(j2_series) |
---|
73 | vect_index=reshape(j2_series+(i1_series-1)*size(timevect,1),1,[]); |
---|
74 | time=(time+timevect(vect_index))/2; |
---|
75 | end |
---|
76 | else |
---|
77 | time=timevect(i1_series); |
---|
78 | if ~isempty(i2_series) |
---|
79 | time=(time+timevect(i2_series))/2; |
---|
80 | end |
---|
81 | end |
---|
82 | end |
---|