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