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

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

adapted to reading hdf5 data from fluidimage, extract_rdvision improved

File size: 25.5 KB
RevLine 
[1112]1%'extunningact_rdvision': relabel an image series with two indices, and correct errors from the RDvision transfer program
[907]2%------------------------------------------------------------------------
3% function ParamOut=extract_rdvision(Param)
4%------------------------------------------------------------------------
5%
[931]6%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %
7%%%%%%%%%%%%%%%%%%%%%%%%%%
[907]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
[1065]28%             .RunMode='local','background', 'cluster': type of function  extract_rdvision.muse
[907]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%=======================================================================
[1126]44% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
[907]45%   http://www.legi.grenoble-inp.fr
[1127]46%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
[907]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
[1065]58%     GNU General Public License (see LICENSE.txt) for more details.extract_rdvision.m
[907]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)
[991]66        ParamOut.WholeIndexRange='on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
[1065]67        ParamOut.NbSlice='off';%1; ...%nbre of slices, 1 prevents splitting in several processes, ('off' by default)
[1134]68    ParamOut.VelType='off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
[991]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)
[1065]73        ParamOut.CPUTime=0.1;% expected time for writting one image ( in minute)
[1134]74    ParamOut.OutputDirExt='.extract';%set the output dir extension
[929]75    ParamOut.OutputSubDirMode='one'; %output folder given by the folder name of the first input line
[991]76    % detect the set of image folder
[907]77    RootPath=Param.InputTable{1,1};
[991]78    ListStruct=dir(RootPath);
[907]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)
[991]91            isel=isel+1;
92            InputTable{isel,1}=RootPath;
93            InputTable{isel,2}=ListDir{ilist};
[907]94            RootFile=regexprep(ListCellSub{1,seq_index},'.seq$','');
95            InputTable{isel,3}=RootFile;
[991]96            InputTable{isel,4}='*';
[1066]97            InputTable{isel,5}='.seq';
[991]98        end
[907]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 ....
[1134]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
[991]161    return
[907]162end
163
[1134]164
165%%%%%%%%%%%% STANDARD PART  %%%%%%%%%%%%
[907]166ParamOut=[];
167%% read input parameters from an xml file if input is a file name (batch mode)
[1051]168
[907]169if ischar(Param)
170    Param=xml2struct(Param);% read Param as input file (batch case)
171end
[1051]172disp(Param)
173checkrun=strcmp(Param.RunMode,'local')
[907]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')
[1134]197
[907]198    %% interactive input of specific parameters (for RDvision system)
199    display('converting images from RDvision system...')
200else
[969]201    disp_uvmat('ERROR','the input is not from rdvision: a .seq or .sqb file must be opened',checkrun)
[907]202    return
203end
204t=xmltree;
[930]205
[907]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)
[1059]221    check_xml=0;
[928]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')
[1059]225            check_xml=1;
[928]226            break
227        end
[922]228    end
[928]229    newxml=fullfile(RootPath,Param.InputTable{iview,3});
[1066]230    newxml=regexprep(newxml,'_Master_Dalsa_4M180$','');%suppress '_Master_Dalsa_4M180'extract_rdvision.m
[928]231    newxml=[newxml '.xml'];
[907]232   
[1134]233    %% get the names of .seq and .sqb files and save them to the log output folder .extract
[907]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']);
[1065]238            errormsg='';
[1134]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
[1065]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
[1113]243                if ~success
244                    disp(errormsg)
245                end
[1065]246                [success,errormsg] = copyfile(filename_sqb,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.sqb']); %copy the sqb file in the upper folder
[1113]247                if ~success
248                    disp(errormsg)
249                end
[1065]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
[1134]252                    if ~success
253                        disp(errormsg)
254                    end
[1110]255                else
[1113]256                    disp(['error:' filexml ' missing']);
[1110]257                    return
[1065]258                end
[1059]259            end
[907]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,'\','/');
[991]282        [tild,SeqData.binrepertoire,DirExt]=fileparts(SeqData.binrepertoire);
[907]283    end
[930]284   
[907]285   
[931]286   
[907]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
[991]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;
[907]309    %%%%%%%
[1065]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,'');
[907]335    end
[930]336    if nbfield2>1
337        NomTypeNew='_1_1';
[909]338    else
[930]339        NomTypeNew='_1';
[907]340    end
[930]341
[1065]342    [BinList,errormsg]=binread_rdv_series(RootPath,SeqData,m.Data,nbfield2,NomTypeNew,Param.IndexRange.first_i,Param.IndexRange.last_i);
[907]343    if ~isempty(errormsg)
344        disp_uvmat('ERROR',errormsg,checkrun)
345        return
346    end
[1134]347
[907]348end
[928]349
350%% remove binary files if transfer OK
[1018]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
[922]358delete(fullfile(RootPath,'Running.xml'))%delete the  xml file to indicate that processing is finished
[907]359
360%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361%--------- reads a series of bin files
[930]362
[907]363%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[1065]364function [BinList,errormsg]=binread_rdv_series(PathDir,SeqData,SqbData,nbfield2,NomTypeNew,first,last)
[939]365% BINREAD_RDV Permet de lire les fichiers bin g???n???r???s par Hiris ??? partir du
366% fichier seq associ???.
[907]367%   [IMGS,TIMESTAMPS,NB_FRAMES] = BINREAD_RDV(FILENAME,FRAME_IDX) lit
[939]368%   l'image d'indice FRAME_IDX de la s???quence FILENAME.
[907]369%
[939]370%   Entr???es
[907]371%   -------
[939]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
[907]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
[939]377%   d'images et tous les timestamps sont renvoy???s. Les indices commencent ???
378%   1 et se termines ??? NB_FRAMES.
[907]379%
380%   Sorties
381%   -------
382%   IMGS        : Images de sortie.
383%   TIMESTAMPS  : Timestaps des images lues.
[939]384%   NB_FRAMES   : Nombres d'images dans la s???quence.
[907]385NbBinFile=0;
386BinSize=0;
387fid=0;
388errormsg='';
[930]389BinList={};
390
[907]391classname=sprintf('uint%d',SeqData.bytesperpixel*8);
392
393classname=['*' classname];
394BitDepth=8*SeqData.bytesperpixel;%needed to write images (8 or 16 bits)
[991]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%%%%
[907]402binrepertoire=fullfile(PathDir,SeqData.binrepertoire);
[928]403FileDir=SeqData.sequencename;
404FileDir=regexprep(FileDir,'_Master_Dalsa_4M180$','');%suppress '_Master_Dalsa_4M180'
405OutputDir=fullfile(PathDir,FileDir);
[907]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;
[1065]418%for ii=1:SeqData.nb_frames
419for ii=first:last
[907]420    j1=[];
421    if ~isequal(nbfield2,1)
422        j1=mod(ii-1,nbfield2)+1;
423    end
424    i1=floor((ii-1)/nbfield2)+1;
[928]425    OutputFile=fullfile_uvmat(PathDir,FileDir,'img','.png',NomTypeNew,i1,[],j1);% TODO: set NomTypeNew from SeqData.mode
[907]426    fname=fullfile(binrepertoire,sprintf('%s%.5d.bin',SeqData.binfile,SqbData(ii).file_idx));
[931]427    if exist(OutputFile,'file')% do not recreate existing image file
[907]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
[1065]454            tic
[907]455            imwrite(A,OutputFile,'BitDepth',BitDepth) % case of 16 bit images
456            disp([OutputFile ' written']);
[1065]457            toc
[907]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
[1018]476function [nbfield1,nbfield2,msg]=copyfile_modif(filexml,timestamp,newxml)
[930]477msg='';
478t=xmltree(filexml);
[907]479
[1018]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
[907]493
[1018]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
[930]511uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
[1018]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)
[1068]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
[1018]531
532if isempty(Dtj)% case of simple series
[932]533    timestamp=timestamp';
[1018]534    t=set(t,uid_content_NbDti,'value',num2str(numel(timestamp)-1));% correct NbDti in the xml file
[1047]535    nbfield1=numel(timestamp);
536    nbfield2=1;
[930]537else
[1018]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;
[1068]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
[907]565end
566
[930]567%% adjust Dti
[1068]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
[907]579
[930]580%% adjust Dtk
581if ~isempty(uid_Dtk)
[1018]582    Dtk_stamp=(timestamp((NbDti+1)*NbDtk+1,1)-timestamp(1,1))/NbDtk;
583    t=set(t,uid_content_Dtk,'value',num2str(Dtk_stamp));
[949]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));
[907]590end
591
[1018]592%% save the new xml file
[1065]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
[949]600end
[907]601
602
Note: See TracBrowser for help on using the repository browser.