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 | % |
---|
7 | % |
---|
8 | % INPUT: |
---|
9 | % |
---|
10 | function [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series) |
---|
11 | errormsg=''; |
---|
12 | nbview=numel(RootPath); |
---|
13 | XmlData=cell(1,nbview);%initiate the structures containing the data from the xml file (calibration and timing) |
---|
14 | NbSlice_calib=cell(1,nbview); |
---|
15 | timecell=cell(1,nbview); |
---|
16 | for iview=1:nbview%Loop on views |
---|
17 | XmlFileName=find_imadoc(RootPath{iview},SubDir{iview},RootFile{iview},FileExt{iview}); |
---|
18 | if ~isempty(XmlFileName) |
---|
19 | [XmlData{iview},errormsg]=imadoc2struct(XmlFileName);% read the ImaDoc xml file |
---|
20 | if ~isempty(errormsg) |
---|
21 | return |
---|
22 | end |
---|
23 | end |
---|
24 | if isfield(XmlData{iview},'Time') |
---|
25 | timecell{iview}=XmlData{iview}.Time; |
---|
26 | end |
---|
27 | if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord') |
---|
28 | NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform |
---|
29 | if ~isequal(NbSlice_calib{iview},NbSlice_calib{1}) |
---|
30 | msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series'); |
---|
31 | end |
---|
32 | end |
---|
33 | end |
---|
34 | |
---|
35 | %% check coincidence in time for several input file series |
---|
36 | if isempty(timecell) |
---|
37 | time=[]; |
---|
38 | else |
---|
39 | time=get_time(timecell{1},i1_series{1},i2_series{1},j1_series{1},j2_series{1}); |
---|
40 | end |
---|
41 | if nbview>1 |
---|
42 | time=shiftdim(time,-1); % add a singleton dimension for nbview |
---|
43 | for icell=2:nbview |
---|
44 | if isequal(size(timecell{icell}),size(timecell{1})) |
---|
45 | time_line=get_time(timecell{icell},i1_series{icell},i2_series{icell},j1_series{icell},j2_series{icell}); |
---|
46 | time=cat(1,time,shiftdim(time_line,-1)); |
---|
47 | else |
---|
48 | msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used') |
---|
49 | time=cat(1,time,time(icell-1,:,:)); |
---|
50 | break |
---|
51 | end |
---|
52 | end |
---|
53 | end |
---|
54 | |
---|
55 | function time=get_time(timeimadoc,i1_series,i2_series,j1_series,j2_series) |
---|
56 | if 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' |
---|
57 | time=[]; |
---|
58 | else |
---|
59 | timevect=timeimadoc'; |
---|
60 | if ~isempty(j1_series) |
---|
61 | vect_index=reshape(j1_series+(i1_series-1)*size(timevect,1),1,[]); |
---|
62 | time=timevect(vect_index); |
---|
63 | if ~isempty(j2_series) |
---|
64 | vect_index=reshape(j2_series+(i1_series-1)*size(timevect,1),1,[]); |
---|
65 | time=(time+timevect(vect_index))/2; |
---|
66 | end |
---|
67 | else |
---|
68 | time=timevect(i1_series); |
---|
69 | if ~isempty(i2_series) |
---|
70 | time=(time+timevect(i2_series))/2; |
---|
71 | end |
---|
72 | end |
---|
73 | end |
---|