source: trunk/src/read_multimadoc.m @ 622

Last change on this file since 622 was 620, checked in by sommeria, 11 years ago

bugs repaired in series + cleaning.
Introducing of a demo program (test stage)

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