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

Last change on this file since 1047 was 1047, checked in by sommeria, 6 years ago

read 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%
9%OUTPUT
10% ParamOut: sets options in the GUI series.fig needed for the function
11%
12%INPUT:
13% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
14% In batch mode, Param is the name of the corresponding xml file containing the same information
15% when Param.Action.RUN=0 (as activated when the current Action is selected
16% in series), the function ouput paramOut set the activation of the needed GUI elements
17%
18% Param contains the elements:(use the menu bar command 'export/GUI config' in series to
19% see the current structure Param)
20%    .InputTable: cell of input file names, (several lines for multiple input)
21%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
22%    .OutputSubDir: name of the subdirectory for data outputs
23%    .OutputDirExt: directory extension for data outputs
24%    .Action: .ActionName: name of the current activated function
25%             .ActionPath:   path of the current activated function
26%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
27%             .RUN =0 for GUI input, =1 for function activation
28%             .RunMode='local','background', 'cluster': type of function  use
29%             
30%    .IndexRange: set the file or frame indices on which the action must be performed
31%    .FieldTransform: .TransformName: name of the selected transform function
32%                     .TransformPath:   path  of the selected transform function
33%    .InputFields: sub structure describing the input fields withfields
34%              .FieldName: name(s) of the field
35%              .VelType: velocity type
36%              .FieldName_1: name of the second field in case of two input series
37%              .VelType_1: velocity type of the second field in case of two input series
38%              .Coord_y: name of y coordinate variable
39%              .Coord_x: name of x coordinate variable
40%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
41%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42
43%=======================================================================
44% Copyright 2008-2018, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
45%   http://www.legi.grenoble-inp.fr
46%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
47%
48%     This file is part of the toolbox UVMAT.
49%
50%     UVMAT is free software; you can redistribute it and/or modify
51%     it under the terms of the GNU General Public License as published
52%     by the Free Software Foundation; either version 2 of the license,
53%     or (at your option) any later version.
54%
55%     UVMAT is distributed in the hope that it will be useful,
56%     but WITHOUT ANY WARRANTY; without even the implied warranty of
57%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
58%     GNU General Public License (see LICENSE.txt) for more details.
59%=======================================================================
60
61function ParamOut=extract_rdvision(Param) %default output=relabel_i_j(Param)
62
63%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
64if isstruct(Param) && isequal(Param.Action.RUN,0)
65    ParamOut.AllowInputSort='off';...% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
66        ParamOut.WholeIndexRange='on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
67        ParamOut.NbSlice=1; ...%nbre of slices, 1 prevents splitting in several processes, ('off' by default)
68        ParamOut.VelType='off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
69        ParamOut.FieldName='off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
70        ParamOut.FieldTransform = 'off';...%can use a transform function
71        ParamOut.ProjObject='off';...%can use projection object(option 'off'/'on',
72        ParamOut.Mask='off';...%can use mask option   (option 'off'/'on', 'off' by default)
73        ParamOut.OutputDirExt='.extract';%set the output dir extension
74    ParamOut.OutputSubDirMode='one'; %output folder given by the folder name of the first input line
75    % detect the set of image folder
76    RootPath=Param.InputTable{1,1};
77    ListStruct=dir(RootPath);
78    ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
79    check_bad=strcmp('.',ListCells(1,:))|strcmp('..',ListCells(1,:));%detect the dir '.' to exclude it
80    check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
81    ListDir=ListCells(1,find(check_dir & ~check_bad));
82    %     InputTable=cell(numel(ListDir),5);
83    %     InputTable(:,2)=ListDir';
84    isel=0;
85    InputTable=Param.InputTable;
86    for ilist=1:numel(ListDir)
87        ListStructSub=dir(fullfile(RootPath,ListDir{ilist}));
88        ListCellSub=struct2cell(ListStructSub);% transform dir struct to a cell arrray
89        detect_seq=regexp(ListCellSub(1,:),'.seq$');
90        seq_index=find(~cellfun('isempty',detect_seq),1);
91        if ~isempty(seq_index)
92            %             msgbox_uvmat('ERROR',['not seq file in ' ListDir{ilist} ': please check the input folders'])
93            %         else
94            isel=isel+1;
95            InputTable{isel,1}=RootPath;
96            InputTable{isel,2}=ListDir{ilist};
97            RootFile=regexprep(ListCellSub{1,seq_index},'.seq$','');
98            InputTable{isel,3}=RootFile;
99            InputTable{isel,4}='*';
100            InputTable{isel,5}='.seq';
101        end
102    end
103    hseries=findobj(allchild(0),'Tag','series');% find the parent GUI 'series'
104    hhseries=guidata(hseries); %handles of the elements in 'series'
105    set(hhseries.InputTable,'Data',InputTable)
106    ParamOut.ActionInput.LogPath=RootPath;% indicate the path for the output info: 0_LOG ....
107    return
108end
109
110ParamOut=[];
111%%%%%%%%%%%% STANDARD PART  %%%%%%%%%%%%
112%% read input parameters from an xml file if input is a file name (batch mode)
113checkrun=1;
114if ischar(Param)
115    Param=xml2struct(Param);% read Param as input file (batch case)
116    checkrun=0;
117end
118hseries=findobj(allchild(0),'Tag','series');
119RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
120WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
121
122%% root input file(s) and type
123RootPath=Param.InputTable{1,1};
124if ~isempty(find(~strcmp(RootPath,Param.InputTable(:,1))))% if the Rootpath for each camera are not identical
125    disp_uvmat('ERROR','Rootpath for all cameras must be identical',checkrun)
126    return
127end
128
129% get the set of input file names (cell array filecell), and the lists of
130% input file or frame indices i1_series,i2_series,j1_series,j2_series
131[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
132
133%OutputDir=[Param.OutputSubDir Param.OutputDirExt];
134 
135% numbers of slices and file indices
136nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
137nbfield_i=size(i1_series{1},2); %nb of fields for the i index
138nbfield=nbfield_j*nbfield_i; %total number of fields
139
140%determine the file type on each line from the first input file
141
142FileInfo=get_file_info(filecell{1,1});
143if strcmp(FileInfo.FileType,'rdvision')
144    if ~isequal(FileInfo.NumberOfFrames,nbfield)
145        disp_uvmat('WARNING',['the whole series of ' num2str(FileInfo.NumberOfFrames) ' images must be extracted at once'],checkrun)
146        %rmfield(OutputDir)
147%         return
148    end
149    %% interactive input of specific parameters (for RDvision system)
150    display('converting images from RDvision system...')
151else
152    disp_uvmat('ERROR','the input is not from rdvision: a .seq or .sqb file must be opened',checkrun)
153    return
154end
155t=xmltree;
156
157save(t,fullfile(RootPath,'Running.xml'))%create an xml file to indicate that processing takes place
158
159%% calibration data and timing: read the ImaDoc files
160mode=''; %default
161timecell={};
162itime=0;
163NbSlice_calib={};
164
165%SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
166
167%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168%%%  loop on the cameras ( #iview)
169%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170% RootPath=Param.InputTable(:,1);
171% RootFile=Param.InputTable(:,3);
172% SubDir=Param.InputTable(:,2);
173% NomType=Param.InputTable(:,4);
174% FileExt=Param.InputTable(:,5);
175
176% [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
177% if size(time,1)>1
178%     diff_time=max(max(diff(time)));
179%     if diff_time>0
180%         disp_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)],checkrun)
181%     end
182% end
183%
184%      nbfield2=size(time,1);
185checkpreserve=0;% if =1, will npreserve the original images, else it erases them at the end
186for iview=1:size(Param.InputTable,1)
187    for iview_xml=1:size(Param.InputTable,1)% look for the xml files in the different data directories
188        filexml=[fullfile(RootPath,Param.InputTable{iview_xml,2},Param.InputTable{iview,3}) '.xml'];%new convention: xml at the level of the image folder
189        if exist(filexml,'file')
190            break
191        end
192    end
193    if ~exist(filexml,'file')
194        disp_uvmat('ERROR',[filexml ' missing'],checkrun)
195        return
196    end
197 
198    newxml=fullfile(RootPath,Param.InputTable{iview,3});
199    newxml=regexprep(newxml,'_Master_Dalsa_4M180$','');%suppress '_Master_Dalsa_4M180'
200    newxml=[newxml '.xml'];
201   
202    %% get the names of .seq and .sqb files
203    switch Param.InputTable{iview,5}
204        case {'.seq','.sqb'}
205            filename_seq=fullfile(RootPath,Param.InputTable{iview,2},[Param.InputTable{iview,3} '.seq']);
206            filename_sqb=fullfile(RootPath,Param.InputTable{iview,2},[Param.InputTable{iview,3} '.sqb']);
207           
208            logdir=[Param.OutputSubDir Param.OutputDirExt];
209            [success,errormsg] = copyfile(filename_seq,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.seq']); %copy the seq file in the upper folder
210            [success,errormsg] = copyfile(filename_sqb,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.sqb']); %copy the sqb file in the upper folder
211            [success,errormsg] = copyfile(filexml,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.xml']); %copy the original xml file in the upper folder
212        otherwise
213            errormsg='input file extension must be .seq or .sqb';
214    end
215    if ~exist(filename_seq,'file')
216        errormsg=[filename_seq ' does not exist'];
217    end
218    if ~isempty(errormsg)
219        disp_uvmat('ERRROR',errormsg,checkrun);
220        return
221    end
222   
223
224    %% get data from .seq file
225    s=ini2struct(filename_seq);
226    SeqData=s.sequenceSettings;
227    SeqData.width=str2double(SeqData.width);
228    SeqData.height=str2double(SeqData.height);
229    SeqData.bytesperpixel=str2double(SeqData.bytesperpixel);
230    SeqData.nb_frames=str2double(s.sequenceSettings.numberoffiles);
231    if isempty(SeqData.binrepertoire)%used when binrepertoire empty, strange feature of rdvision
232        SeqData.binrepertoire=regexprep(s.sequenceSettings.bindirectory,'\\$','');%tranform Windows notation to Linux
233        SeqData.binrepertoire=regexprep(SeqData.binrepertoire,'\','/');
234        [tild,SeqData.binrepertoire,DirExt]=fileparts(SeqData.binrepertoire);
235    end
236   
237   
238   
239    %% reading the .sqb file
240    m = memmapfile(filename_sqb,'Format', { 'uint32' [1 1] 'offset'; ...
241        'uint32' [1 1] 'garbage1';...
242        'double' [1 1] 'timestamp';...
243        'uint32' [1 1] 'file_idx';...
244        'uint32' [1 1] 'garbage2' },'Repeat',SeqData.nb_frames);
245   
246    %%%%%%%BRICOLAGE in case of unreadable .sqb file: remplace lecture du fichier
247%             ind=[8356 8356:8672];%indices of bin files
248%             w=2432;%w=width of images in pixels
249%             h=864;%h=height of images in pixels
250%             bpp=2;% nbre of bytes per pixel
251%             lengthimage=w*h*bpp;% lengthof an image record on the binary file
252%             nbimages=15; %nbre of images of each camera in a bin file
253%             for ii=1:15*numel(ind)
254%                 %data(ii).offset=mod(ii-1,32)*2*lengthimage+lengthimage;%Dalsa_2
255%                 %data(ii).offset=mod(ii-1,32)*2*lengthimage;%Dalsa_1
256%                 %data(ii).file_idx=ind(ceil(ii/32));
257%                 data(ii).file_idx=ind(ceil(ii/15));
258%                 data(ii).timestamp=0.005*(ii-1);
259%             end
260%             m.Data=data;
261    %%%%%%%
262    timestamp=zeros(1,numel(m.Data));
263    for ii=1: numel(m.Data)
264        timestamp(ii)=m.Data(ii).timestamp;
265    end
266    [nbfield1,nbfield2,msg]=copyfile_modif(filexml,timestamp,newxml); %copy the xml file in the upper folder
267    [XmlData,errormsg]=imadoc2struct(newxml);% check reading of the new xml file
268    if ~isempty(errormsg)
269        disp(errormsg)
270        return
271    end
272    timestamp=timestamp(1:nbfield1*nbfield2);
273    timestamp=reshape(timestamp,nbfield2,nbfield1);
274    difftime=XmlData.Time(2:end,2:end)'-timestamp;
275    disp(['time from xml and timestamp differ by ' num2str(max(max(abs(difftime))))])
276    if max(abs(difftime))>0.01
277        checkpreserve=1;% will not erase the initial files, possibility of error
278    end
279   
280        %% checking consistency with the xml file
281%     if ~isequal(SeqData.nb_frames,numel(timestamp))
282%         disp_uvmat('ERRROR',['inconsistent number of images ' num2str(SeqData.nb_frames) ' with respect to the xml file: ' num2str(numel(timestamp))] ,checkrun);
283%         return
284%     end   
285   
286    if nbfield2>1
287        NomTypeNew='_1_1';
288    else
289        NomTypeNew='_1';
290    end
291
292    [BinList,errormsg]=binread_rdv_series(RootPath,SeqData,m.Data,nbfield2,NomTypeNew);
293    if ~isempty(errormsg)
294        disp_uvmat('ERROR',errormsg,checkrun)
295        return
296    end
297   
298    % check the existence of the expected output image files (from the xml)
299    FileDir=SeqData.sequencename;
300     FileDir=regexprep(FileDir,'_Master_Dalsa_4M180$','');%suppress '_Master_Dalsa_4M180'
301    for i1=1:numel(timestamp)/nbfield2
302        for j1=1:nbfield2
303            OutputFile=fullfile_uvmat(RootPath,FileDir,'img','.png',NomTypeNew,i1,[],j1);% TODO: set NomTypeNew from SeqData.mode
304            try
305            A=imread(OutputFile);% check image reading (stop if error)
306            catch ME
307                disp(['checking ' OutputFile])
308                disp(ME.message)
309            end
310        end
311    end
312end
313
314%% remove binary files if transfer OK
315%     if ~checkpreserve
316%         for iview=1:size(Param.InputTable,1)
317%          fullfile(RootPath,Param.InputTable{iview,2})
318%          source_dir=fullfile(RootPath,Param.InputTable{iview,2});
319%         [SUCCESS,MESSAGE]=rmdir(source_dir,'s')
320%         end
321%     end
322delete(fullfile(RootPath,'Running.xml'))%delete the  xml file to indicate that processing is finished
323
324%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325%--------- reads a series of bin files
326
327%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328function [BinList,errormsg]=binread_rdv_series(PathDir,SeqData,SqbData,nbfield2,NomTypeNew)
329% BINREAD_RDV Permet de lire les fichiers bin g???n???r???s par Hiris ??? partir du
330% fichier seq associ???.
331%   [IMGS,TIMESTAMPS,NB_FRAMES] = BINREAD_RDV(FILENAME,FRAME_IDX) lit
332%   l'image d'indice FRAME_IDX de la s???quence FILENAME.
333%
334%   Entr???es
335%   -------
336%   FILENAME  : Nom du fichier s???quence (.seq).
337%   FRAME_IDX : Indice de l'image ??? lire. Si FRAME_IDX vaut -1 alors la
338%   s???quence est enti???rement lue. Si FRAME_IDX est un tableau d'indices
339%   alors toutes les images d'incides correspondant sont lues. Si FRAME_IDX
340%   est un tableau vide alors aucune image n'est lue mais le nombre
341%   d'images et tous les timestamps sont renvoy???s. Les indices commencent ???
342%   1 et se termines ??? NB_FRAMES.
343%
344%   Sorties
345%   -------
346%   IMGS        : Images de sortie.
347%   TIMESTAMPS  : Timestaps des images lues.
348%   NB_FRAMES   : Nombres d'images dans la s???quence.
349NbBinFile=0;
350BinSize=0;
351fid=0;
352errormsg='';
353BinList={};
354
355classname=sprintf('uint%d',SeqData.bytesperpixel*8);
356
357classname=['*' classname];
358BitDepth=8*SeqData.bytesperpixel;%needed to write images (8 or 16 bits)
359%%%%
360% SeqData.binrepertoire='2017-01-26T11.59.57';
361%SeqData.binrepertoire='2017-01-26T16.57.27';
362%SeqData.binrepertoire='2017-01-26T19.28.05';
363%SeqData.binrepertoire='2017-01-27T09.51.34';
364%SeqData.binrepertoire='2017-01-27T14.21.47'
365%%%%
366binrepertoire=fullfile(PathDir,SeqData.binrepertoire);
367FileDir=SeqData.sequencename;
368FileDir=regexprep(FileDir,'_Master_Dalsa_4M180$','');%suppress '_Master_Dalsa_4M180'
369OutputDir=fullfile(PathDir,FileDir);
370if ~exist(OutputDir,'dir')
371    %     errormsg=[OutputDir ' already exist, delete it first'];
372    %     return
373    % end
374    [s,errormsg]=mkdir(OutputDir);
375   
376    if s==0
377        disp(errormsg)
378        return%not able to create new image dir
379    end
380end
381bin_file_counter=0;
382for ii=1:SeqData.nb_frames
383    j1=[];
384    if ~isequal(nbfield2,1)
385        j1=mod(ii-1,nbfield2)+1;
386    end
387    i1=floor((ii-1)/nbfield2)+1;
388    OutputFile=fullfile_uvmat(PathDir,FileDir,'img','.png',NomTypeNew,i1,[],j1);% TODO: set NomTypeNew from SeqData.mode
389    fname=fullfile(binrepertoire,sprintf('%s%.5d.bin',SeqData.binfile,SqbData(ii).file_idx));
390    if exist(OutputFile,'file')% do not recreate existing image file
391        fid=0;
392    else
393        if fid==0 || ~strcmp(fname,fname_prev) % open the bin file if not in use
394            if fid~=0
395                fclose(fid);%close the previous bin file if relevant
396            end
397            [fid,msg]=fopen(fname,'rb');
398            if isequal(fid,-1)
399                errormsg=['error in opening ' fname ': ' msg];
400                return
401            else
402                disp([fname ' opened for reading'])
403                bin_file_counter=bin_file_counter+1;
404                BinList{bin_file_counter}=fname;
405            end
406            fseek(fid,SqbData(ii).offset,-1);%look at the right starting place in the bin file
407            NbBinFile=NbBinFile+1;%counter of binary files (for checking purpose)
408            BinSize(NbBinFile)=0;% strat counter for new bin file
409        else
410            fseek(fid,SqbData(ii).offset,-1);%look at the right starting place in the bin file
411        end
412        fname_prev=fname;
413        A=reshape(fread(fid,SeqData.width*SeqData.height,classname),SeqData.width,SeqData.height);%read the current image
414        A=A';
415        BinSize(NbBinFile)=BinSize(NbBinFile)+SeqData.width*SeqData.height*SeqData.bytesperpixel*8; %record bits read
416        try
417            imwrite(A,OutputFile,'BitDepth',BitDepth) % case of 16 bit images
418            disp([OutputFile ' written']);
419            % [s,errormsg] = fileattrib(OutputFile,'-w','a'); %set images to read only '-w' for all users ('a')
420            %         if ~s
421            % %             disp_uvmat('ERROR',errormsg,checkrun);
422            %             return
423            %         end
424        catch ME
425            errormsg=ME.message;
426            return
427        end
428    end
429end
430if fid~=0
431fclose(fid)
432end
433
434
435
436
437function [nbfield1,nbfield2,msg]=copyfile_modif(filexml,timestamp,newxml)
438msg='';
439t=xmltree(filexml);
440
441%% read Dtk and NbDtk
442NbDtk=1; %default
443Dtk=[]; % default
444uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk');
445uid_content_Dtk=get(t,uid_Dtk,'contents');
446if ~isempty(uid_content_Dtk)
447    Dtk=str2num(get(t,uid_content_Dtk,'value'));
448    uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
449    uid_content_NbDtk=get(t,uid_NbDtk,'contents');
450    if ~isempty(uid_content_NbDtk)
451    NbDtk=str2num(get(t,uid_content_NbDtk,'value'));
452    end
453end
454
455%% read Dti and NbDti
456NbDti=1; %default
457Dti=[]; % default
458uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
459uid_content_Dti=get(t,uid_Dti,'contents');
460if ~isempty(uid_content_Dti)
461    Dti=str2num(get(t,uid_content_Dti,'value'));
462    uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
463    uid_content_NbDti=get(t,uid_NbDti,'contents');
464    if ~isempty(uid_content_NbDti)
465    NbDti=str2num(get(t,uid_content_NbDti,'value'));
466    end
467end
468
469%% read Dtj and NbDtj
470NbDtj=1; %default
471Dtj=[]; % default
472uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
473uid_content_Dtj=get(t,uid_Dtj,'contents');
474if ~isempty(uid_content_Dtj)
475    Dtj=str2num(get(t,uid_content_Dtj,'value'));
476    uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
477    uid_content_NbDtj=get(t,uid_NbDtj,'contents');
478    if ~isempty(uid_content_NbDtj)
479    NbDtj=str2num(get(t,uid_content_NbDtj,'value'));
480    end
481end
482
483%% correct NbDtj and NbDti (error from RDvision)
484if NbDtj==numel(Dtj)% case of bursts
485    NbDtj=1;
486    uid_motor_nbslice=find(t,'ImaDoc/TranslationMotor/Nbslice');
487    if ~isempty(uid_motor_nbslice)&& ~isempty(uid_Dtk)% case of multilevel
488        NbSlice=str2num(get(t,get(t,uid_motor_nbslice,'contents'),'value'));
489        NbDti=NbSlice-1;
490    end
491end
492
493if isempty(Dtj)% case of simple series
494    timestamp=timestamp';
495    t=set(t,uid_content_NbDti,'value',num2str(numel(timestamp)-1));% correct NbDti in the xml file
496    nbfield1=numel(timestamp);
497    nbfield2=1;
498else
499    nbfieldi=(NbDti*numel(Dti)+1);
500    nbfieldk=(NbDtk*numel(Dtk)+1);
501    nbfield1=nbfieldi*nbfieldk;
502    nbfield2=NbDtj*numel(Dtj)+1;
503    NbFrames_xml=nbfield1*nbfield2;
504   if NbFrames_xml<numel(timestamp)
505       disp(['ERROR: size from xml ' num2str(NbFrame_xml) ' smaller than timestamp size ' num2str(numel(timestamp))])
506       return
507   end
508   if NbFrames_xml>numel(timestamp)
509       nbfield1=floor(numel(timestamp)/nbfield2);
510       nbfieldk=floor(nbfield1/nbfieldi);
511       nbfield1=nbfieldi*nbfieldk;
512       NbDtk=nbfieldk-1;
513       t=set(t,uid_content_NbDtk,'value',num2str(NbDtk));% correct NbDtk in the xml file (in practice numel(Dtk)=1;
514       timestamp=timestamp(1:nbfield1*nbfield2);
515       disp(['image record stopped before end: max index i= ' num2str(nbfield1)]);
516       timestamp=reshape(timestamp,nbfield2,nbfield1);
517   end
518   % check Dtj with respect to timestamp
519    timestamp=(reshape(timestamp,nbfield2,[]))';
520    diff_Dtj=diff(timestamp(1,:))-Dtj;
521    if max(abs(diff_Dtj))>min(Dtj)/1000
522        disp(['Dtj from xml file differs from time stamp by ' num2str(max(abs(diff_Dtj))) ', '])%'
523    else
524        disp('Dtj OK');
525    end
526end
527
528%% adjust Dti
529Dti_stamp=(timestamp(1+NbDti,1)-timestamp(1,1))/NbDti;
530t=set(t,uid_content_Dti,'value',num2str(Dti_stamp));%corret Dti
531if abs(Dti_stamp-Dti)>Dti/1000
532    disp([msg 'Dti from xml file corrected by ' num2str(Dti_stamp-Dti) ', ']);%'
533else
534    disp('Dti OK')
535end
536
537%% adjust Dtk
538if ~isempty(uid_Dtk)
539    Dtk_stamp=(timestamp((NbDti+1)*NbDtk+1,1)-timestamp(1,1))/NbDtk;
540    t=set(t,uid_content_Dtk,'value',num2str(Dtk_stamp));
541    if abs(Dtk_stamp-Dtk)>Dtk/1000
542        disp(['Dtk from xml file corrected by ' num2str(Dtk_stamp-Dtk)]);
543    else
544        disp('Dtk OK')
545    end
546    t=set(t,uid_content_Dtk,'value',num2str(Dtk_stamp));
547end
548
549%% save the new xml file
550save(t,newxml)
551[success,errormsg] = fileattrib(newxml,'+w','g');% allow writing access for the group of users
552if success==0
553    disp({['warning: unable to set group write access to ' newxml ':']; errormsg});%error message for directory creation
554    msg=errormsg;
555end
556
557
558
Note: See TracBrowser for help on using the repository browser.