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

Last change on this file since 1135 was 1134, checked in by sommeria, 7 months ago

adapted to reading hdf5 data from fluidimage, extract_rdvision improved

File size: 25.5 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        timestamp=timestamp(1:nbfield1*nbfield2);
322        timestamp=reshape(timestamp,nbfield2,nbfield1);
323        difftime=XmlData.Time(2:end,2:end)'-timestamp;
324        disp(['time from xml and timestamp differ by ' num2str(max(max(abs(difftime))))])
325        if max(abs(difftime))>0.01
326            checkpreserve=1;% will not erase the initial files, possibility of error
327        end     
328        % checking consistency with the xml file
329        %     if ~isequal(SeqData.nb_frames,numel(timestamp))
330        %         disp_uvmat('ERRROR',['inconsistent number of images ' num2str(SeqData.nb_frames) ' with respect to the xml file: ' num2str(numel(timestamp))] ,checkrun);
331        %         return
332        %     end
333    else
334       [nbfield1,nbfield2,msg]=copyfile_modif(filexml,timestamp,'');
335    end
336    if nbfield2>1
337        NomTypeNew='_1_1';
338    else
339        NomTypeNew='_1';
340    end
341
342    [BinList,errormsg]=binread_rdv_series(RootPath,SeqData,m.Data,nbfield2,NomTypeNew,Param.IndexRange.first_i,Param.IndexRange.last_i);
343    if ~isempty(errormsg)
344        disp_uvmat('ERROR',errormsg,checkrun)
345        return
346    end
347
348end
349
350%% remove binary files if transfer OK
351%     if ~checkpreserve
352%         for iview=1:size(Param.InputTable,1)
353%          fullfile(RootPath,Param.InputTable{iview,2})
354%          source_dir=fullfile(RootPath,Param.InputTable{iview,2});
355%         [SUCCESS,MESSAGE]=rmdir(source_dir,'s')
356%         end
357%     end
358delete(fullfile(RootPath,'Running.xml'))%delete the  xml file to indicate that processing is finished
359
360%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361%--------- reads a series of bin files
362
363%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
364function [BinList,errormsg]=binread_rdv_series(PathDir,SeqData,SqbData,nbfield2,NomTypeNew,first,last)
365% BINREAD_RDV Permet de lire les fichiers bin g???n???r???s par Hiris ??? partir du
366% fichier seq associ???.
367%   [IMGS,TIMESTAMPS,NB_FRAMES] = BINREAD_RDV(FILENAME,FRAME_IDX) lit
368%   l'image d'indice FRAME_IDX de la s???quence FILENAME.
369%
370%   Entr???es
371%   -------
372%   FILENAME  : Nom du fichier s???quence (.seq).
373%   FRAME_IDX : Indice de l'image ??? lire. Si FRAME_IDX vaut -1 alors la
374%   s???quence est enti???rement lue. Si FRAME_IDX est un tableau d'indices
375%   alors toutes les images d'incides correspondant sont lues. Si FRAME_IDX
376%   est un tableau vide alors aucune image n'est lue mais le nombre
377%   d'images et tous les timestamps sont renvoy???s. Les indices commencent ???
378%   1 et se termines ??? NB_FRAMES.
379%
380%   Sorties
381%   -------
382%   IMGS        : Images de sortie.
383%   TIMESTAMPS  : Timestaps des images lues.
384%   NB_FRAMES   : Nombres d'images dans la s???quence.
385NbBinFile=0;
386BinSize=0;
387fid=0;
388errormsg='';
389BinList={};
390
391classname=sprintf('uint%d',SeqData.bytesperpixel*8);
392
393classname=['*' classname];
394BitDepth=8*SeqData.bytesperpixel;%needed to write images (8 or 16 bits)
395%%%%
396% SeqData.binrepertoire='2017-01-26T11.59.57';
397%SeqData.binrepertoire='2017-01-26T16.57.27';
398%SeqData.binrepertoire='2017-01-26T19.28.05';
399%SeqData.binrepertoire='2017-01-27T09.51.34';
400%SeqData.binrepertoire='2017-01-27T14.21.47'
401%%%%
402binrepertoire=fullfile(PathDir,SeqData.binrepertoire);
403FileDir=SeqData.sequencename;
404FileDir=regexprep(FileDir,'_Master_Dalsa_4M180$','');%suppress '_Master_Dalsa_4M180'
405OutputDir=fullfile(PathDir,FileDir);
406if ~exist(OutputDir,'dir')
407    %     errormsg=[OutputDir ' already exist, delete it first'];
408    %     return
409    % end
410    [s,errormsg]=mkdir(OutputDir);
411   
412    if s==0
413        disp(errormsg)
414        return%not able to create new image dir
415    end
416end
417bin_file_counter=0;
418%for ii=1:SeqData.nb_frames
419for ii=first:last
420    j1=[];
421    if ~isequal(nbfield2,1)
422        j1=mod(ii-1,nbfield2)+1;
423    end
424    i1=floor((ii-1)/nbfield2)+1;
425    OutputFile=fullfile_uvmat(PathDir,FileDir,'img','.png',NomTypeNew,i1,[],j1);% TODO: set NomTypeNew from SeqData.mode
426    fname=fullfile(binrepertoire,sprintf('%s%.5d.bin',SeqData.binfile,SqbData(ii).file_idx));
427    if exist(OutputFile,'file')% do not recreate existing image file
428        fid=0;
429    else
430        if fid==0 || ~strcmp(fname,fname_prev) % open the bin file if not in use
431            if fid~=0
432                fclose(fid);%close the previous bin file if relevant
433            end
434            [fid,msg]=fopen(fname,'rb');
435            if isequal(fid,-1)
436                errormsg=['error in opening ' fname ': ' msg];
437                return
438            else
439                disp([fname ' opened for reading'])
440                bin_file_counter=bin_file_counter+1;
441                BinList{bin_file_counter}=fname;
442            end
443            fseek(fid,SqbData(ii).offset,-1);%look at the right starting place in the bin file
444            NbBinFile=NbBinFile+1;%counter of binary files (for checking purpose)
445            BinSize(NbBinFile)=0;% strat counter for new bin file
446        else
447            fseek(fid,SqbData(ii).offset,-1);%look at the right starting place in the bin file
448        end
449        fname_prev=fname;
450        A=reshape(fread(fid,SeqData.width*SeqData.height,classname),SeqData.width,SeqData.height);%read the current image
451        A=A';
452        BinSize(NbBinFile)=BinSize(NbBinFile)+SeqData.width*SeqData.height*SeqData.bytesperpixel*8; %record bits read
453        try
454            tic
455            imwrite(A,OutputFile,'BitDepth',BitDepth) % case of 16 bit images
456            disp([OutputFile ' written']);
457            toc
458            % [s,errormsg] = fileattrib(OutputFile,'-w','a'); %set images to read only '-w' for all users ('a')
459            %         if ~s
460            % %             disp_uvmat('ERROR',errormsg,checkrun);
461            %             return
462            %         end
463        catch ME
464            errormsg=ME.message;
465            return
466        end
467    end
468end
469if fid~=0
470fclose(fid)
471end
472
473
474
475
476function [nbfield1,nbfield2,msg]=copyfile_modif(filexml,timestamp,newxml)
477msg='';
478t=xmltree(filexml);
479
480%% read Dtk and NbDtk
481NbDtk=1; %default
482Dtk=[]; % default
483uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk');
484uid_content_Dtk=get(t,uid_Dtk,'contents');
485if ~isempty(uid_content_Dtk)
486    Dtk=str2num(get(t,uid_content_Dtk,'value'));
487    uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
488    uid_content_NbDtk=get(t,uid_NbDtk,'contents');
489    if ~isempty(uid_content_NbDtk)
490    NbDtk=str2num(get(t,uid_content_NbDtk,'value'));
491    end
492end
493
494%% read Dti and NbDti
495NbDti=1; %default
496Dti=[]; % default
497uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
498uid_content_Dti=get(t,uid_Dti,'contents');
499if ~isempty(uid_content_Dti)
500    Dti=str2num(get(t,uid_content_Dti,'value'));
501    uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
502    uid_content_NbDti=get(t,uid_NbDti,'contents');
503    if ~isempty(uid_content_NbDti)
504    NbDti=str2num(get(t,uid_content_NbDti,'value'));
505    end
506end
507
508%% read Dtj and NbDtj
509NbDtj=1; %default
510Dtj=[]; % default
511uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
512uid_content_Dtj=get(t,uid_Dtj,'contents');
513if ~isempty(uid_content_Dtj)
514    Dtj=str2num(get(t,uid_content_Dtj,'value'));
515    uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
516    uid_content_NbDtj=get(t,uid_NbDtj,'contents');
517    if ~isempty(uid_content_NbDtj)
518    NbDtj=str2num(get(t,uid_content_NbDtj,'value'));
519    end
520end
521
522%% correct NbDtj and NbDti (error from RDvision)
523% if NbDtj==numel(Dtj)% case of bursts
524%     NbDtj=1;
525%     uid_motor_nbslice=find(t,'ImaDoc/TranslationMotor/Nbslice');
526%     if ~isempty(uid_motor_nbslice)&& ~isempty(uid_Dtk)% case of multilevel
527%         NbSlice=str2num(get(t,get(t,uid_motor_nbslice,'contents'),'value'));
528%         NbDti=NbSlice-1;
529%     end
530% end
531
532if isempty(Dtj)% case of simple series
533    timestamp=timestamp';
534    t=set(t,uid_content_NbDti,'value',num2str(numel(timestamp)-1));% correct NbDti in the xml file
535    nbfield1=numel(timestamp);
536    nbfield2=1;
537else
538    nbfieldi=(NbDti*numel(Dti)+1);
539    nbfieldk=(NbDtk*numel(Dtk)+1);
540    nbfield1=nbfieldi*nbfieldk;
541    nbfield2=NbDtj*numel(Dtj)+1;
542    NbFrames_xml=nbfield1*nbfield2;
543%    if NbFrames_xml<numel(timestamp)
544%        disp(['ERROR: size from xml ' num2str(NbFrame_xml) ' smaller than timestamp size ' num2str(numel(timestamp))])
545%        return
546%    end
547%    if NbFrames_xml>numel(timestamp)
548%        nbfield1=floor(numel(timestamp)/nbfield2);
549%        nbfieldk=floor(nbfield1/nbfieldi);
550%        nbfield1=nbfieldi*nbfieldk;
551%        NbDtk=nbfieldk-1;
552%        t=set(t,uid_content_NbDtk,'value',num2str(NbDtk));% correct NbDtk in the xml file (in practice numel(Dtk)=1;
553%        timestamp=timestamp(1:nbfield1*nbfield2);
554%        disp(['image record stopped before end: max index i= ' num2str(nbfield1)]);
555%        timestamp=reshape(timestamp,nbfield2,nbfield1);
556%    end
557%    % check Dtj with respect to timestamp
558%     timestamp=(reshape(timestamp,nbfield2,[]))';
559%     diff_Dtj=diff(timestamp(1,:))-Dtj;
560%     if max(abs(diff_Dtj))>min(Dtj)/1000
561%         disp(['Dtj from xml file differs from time stamp by ' num2str(max(abs(diff_Dtj))) ', '])%'
562%     else
563%         disp('Dtj OK');
564%     end
565end
566
567%% adjust Dti
568% if NbDti+1>size(timestamp,1)
569%     NbDti=size(timestamp,1)-1;
570% end
571% Dti_stamp=(timestamp(1+NbDti,1)-timestamp(1,1))/NbDti;
572% Dti_stamp=(timestamp(1+NbDti,1)-timestamp(2,1))/(NbDti-1);
573% t=set(t,uid_content_Dti,'value',num2str(Dti_stamp));%corret Dti
574% if abs(Dti_stamp-Dti)>Dti/1000
575%     disp([msg 'Dti from xml file corrected by ' num2str(Dti_stamp-Dti) ', ']);%'
576% else
577%     disp('Dti OK')
578% end
579
580%% adjust Dtk
581if ~isempty(uid_Dtk)
582    Dtk_stamp=(timestamp((NbDti+1)*NbDtk+1,1)-timestamp(1,1))/NbDtk;
583    t=set(t,uid_content_Dtk,'value',num2str(Dtk_stamp));
584    if abs(Dtk_stamp-Dtk)>Dtk/1000
585        disp(['Dtk from xml file corrected by ' num2str(Dtk_stamp-Dtk)]);
586    else
587        disp('Dtk OK')
588    end
589    t=set(t,uid_content_Dtk,'value',num2str(Dtk_stamp));
590end
591
592%% save the new xml file
593if ~isempty(newxml)
594    save(t,newxml)
595    [success,errormsg] = fileattrib(newxml,'+w','g');% allow writing access for the group of users
596    if success==0
597        disp({['warning: unable to set group write access to ' newxml ':']; errormsg});%error message for directory creation
598        msg=errormsg;
599    end
600end
601
602
Note: See TracBrowser for help on using the repository browser.