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

Last change on this file since 1109 was 1107, checked in by g7moreau, 3 years ago

Update Copyright to 2022

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