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

Last change on this file since 1147 was 1143, checked in by sommeria, 5 months ago

new display of false vectors

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