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

Last change on this file since 1162 was 1161, checked in by sommeria, 17 months ago

filter_tps modified to avoid possible bugs in case of few vectors, subpixel interpolation slightly modified in civ

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