Index: unk/src/series/clean_civ_cmx.m
===================================================================
--- /trunk/src/series/clean_civ_cmx.m	(revision 828)
+++ 	(revision )
@@ -1,86 +1,0 @@
-%'clean_civ_cmx': suppress all ancillary files used for PIV: ;cmx,log,.bat...
-%------------------------------------------------------------------------
-% function GUI_input=clean_civ_cmx(num_i1,num_i2,num_j1,num_j2,Series)
-%
-%OUTPUT
-% GUI_input=list of options in the GUI series.fig needed for the function
-%
-%INPUT:
-%num_i1: (not used) series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
-%num_i2: (not used) series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
-%num_j1: (not used) series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
-%num_j2: (not used) series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
-%Series: Matlab structure containing information set by the series interface
-
-%=======================================================================
-% Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
-%   http://www.legi.grenoble-inp.fr
-%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
-%
-%     This file is part of the toolbox UVMAT.
-%
-%     UVMAT is free software; you can redistribute it and/or modify
-%     it under the terms of the GNU General Public License as published
-%     by the Free Software Foundation; either version 2 of the license,
-%     or (at your option) any later version.
-%
-%     UVMAT is distributed in the hope that it will be useful,
-%     but WITHOUT ANY WARRANTY; without even the implied warranty of
-%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-%     GNU General Public License (see LICENSE.txt) for more details.
-%=======================================================================
-
-function GUI_input=clean_civ_cmx(num_i1,num_i2,num_j1,num_j2,Series) %(filecell,filecell_1,num_i,num_j,vel_type,field,param);
-
-%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
-if ~exist('num_i1','var')
-    GUI_input={'RootPath';'many';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
-        'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
-        %'RootFile';'on';... %root input file name ('on' by default)
-        %'FileExt';'on';... %input file extension ('on' by default)
-        %'NomType';'on';...%type of file indexing ('on' by default)
-        %'NbSlice';'on'; ...%nbre of slices ('off' by default)
-        %'VelTypeMenu';'one';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default)
-        %'FieldMenu';'one';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
-        %'CoordType';'on'...%can use a transform function 'off' by default
-        %'GetObject';'on'...%can use projection object ,'off' by default
-        %'GetMask';'on'...%can use mask option   ,'off' by default
-        %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter 
-               ''};
-    return %exit the function 
-end
-%---------------------------------------------------------
-hseries=guidata(Series.hseries);%handles of the GUI series
-WaitbarPos=get(hseries.waitbar_frame,'Position');
-
-%%%%%%%%%%%%%%%%%%%%%%%%
-message='this function will delete all files with extensions .log, .bat, .cmx,.cmx2,.errors in the input directory(ies)';
-answer=msgbox_uvmat('INPUT_Y-N',message);
-if ~isequal(answer,'Yes')
-    return
-end
-nbdelete=0;
-testcell=iscell(Series.RootFile);
-if ~testcell
-    Series.RootPath={Series.RootPath};
-    Series.RootFile={Series.RootFile};
-    Series.SubDir={Series.SubDir};
-    Series.FileExt={Series.FileExt};
-    Series.NomType={Series.NomType};
-end 
-for iview=1:length(Series.RootFile)
-    hdir=dir(fullfile(Series.RootPath{iview},Series.SubDir{iview}));%list files
-    for ilist=1:length(hdir)
-%         update_waitbar(hseries.waitbar,WaitbarPos,ilist/length(hdir))
-        FileName=hdir(ilist).name;
-        [dd,ff,Ext]=fileparts(FileName);
-        if isequal(Ext,'.log')||isequal(Ext,'.bat')||isequal(Ext,'.cmx')||isequal(Ext,'.cmx2')|| isequal(Ext,'.errors')
-            delete(fullfile(Series.RootPath{iview},Series.SubDir{iview},FileName))
-            nbdelete=nbdelete+1;
-        end
-    end
-end
-msgbox_uvmat('CONFIRMATION',['END: ' num2str(nbdelete) ' files deleted by clean_civ_cmx'])
-
-
-
Index: /trunk/src/series/merge_proj.m
===================================================================
--- /trunk/src/series/merge_proj.m	(revision 828)
+++ /trunk/src/series/merge_proj.m	(revision 829)
@@ -163,5 +163,5 @@
 end
 if ~isempty(errormsg)
-    disp_uvmat('WARNING',erromsg,checkrun)
+    disp_uvmat('WARNING',errormsg,checkrun)
 end
 time=mean(time,1); %averaged time taken for the merged field
Index: unk/src/series/merge_proj_special.m
===================================================================
--- /trunk/src/series/merge_proj_special.m	(revision 828)
+++ 	(revision )
@@ -1,467 +1,0 @@
-%'merge_proj': concatene several fields from series, can project them on a regular grid in phys coordinates
-%------------------------------------------------------------------------
-% function ParamOut=merge_proj(Param)
-%------------------------------------------------------------------------
-%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%OUTPUT
-% ParamOut: sets options in the GUI series.fig needed for the function
-%
-%INPUT:
-% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
-% In batch mode, Param is the name of the corresponding xml file containing the same information
-% when Param.Action.RUN=0 (as activated when the current Action is selected
-% in series), the function ouput paramOut set the activation of the needed GUI elements
-%
-% Param contains the elements:(use the menu bar command 'export/GUI config' in series to 
-% see the current structure Param)
-%    .InputTable: cell of input file names, (several lines for multiple input)
-%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
-%    .OutputSubDir: name of the subdirectory for data outputs
-%    .OutputDirExt: directory extension for data outputs
-%    .Action: .ActionName: name of the current activated function
-%             .ActionPath:   path of the current activated function
-%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
-%             .RUN =0 for GUI input, =1 for function activation
-%             .RunMode='local','background', 'cluster': type of function  use
-%             
-%    .IndexRange: set the file or frame indices on which the action must be performed
-%    .FieldTransform: .TransformName: name of the selected transform function
-%                     .TransformPath:   path  of the selected transform function
-%    .InputFields: sub structure describing the input fields withfields
-%              .FieldName: name(s) of the field
-%              .VelType: velocity type
-%              .FieldName_1: name of the second field in case of two input series
-%              .VelType_1: velocity type of the second field in case of two input series
-%              .Coord_y: name of y coordinate variable
-%              .Coord_x: name of x coordinate variable
-%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%=======================================================================
-% Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
-%   http://www.legi.grenoble-inp.fr
-%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
-%
-%     This file is part of the toolbox UVMAT.
-%
-%     UVMAT is free software; you can redistribute it and/or modify
-%     it under the terms of the GNU General Public License as published
-%     by the Free Software Foundation; either version 2 of the license,
-%     or (at your option) any later version.
-%
-%     UVMAT is distributed in the hope that it will be useful,
-%     but WITHOUT ANY WARRANTY; without even the implied warranty of
-%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-%     GNU General Public License (see LICENSE.txt) for more details.
-%=======================================================================
-
-function ParamOut=merge_proj(Param)
-
-%% set the input elements needed on the GUI series when the function is selected in the menu ActionName or InputTable refreshed
-if isstruct(Param) && isequal(Param.Action.RUN,0)
-    ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
-    ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
-    ParamOut.NbSlice='off'; %nbre of slices ('off' by default)
-    ParamOut.VelType='one';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
-    ParamOut.FieldName='one';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
-    ParamOut.FieldTransform = 'on';%can use a transform function
-    ParamOut.TransformPath=fullfile(fileparts(which('uvmat')),'transform_field');% path to transform functions (needed for compilation only)
-    ParamOut.ProjObject='on';%can use projection object(option 'off'/'on',
-    ParamOut.Mask='on';%can use mask option   (option 'off'/'on', 'off' by default)
-    ParamOut.OutputDirExt='.mproj';%set the output dir extension
-    ParamOut.OutputFileMode='NbInput';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
-    filecell=get_file_series(Param);%check existence of the first input file
-    if ~exist(filecell{1,1},'file')
-        msgbox_uvmat('WARNING','the first input file does not exist')
-    elseif isequal(size(Param.InputTable,1),1) && ~isfield(Param,'ProjObject')
-        msgbox_uvmat('WARNING','You may need a projection object of type plane for merge_proj')
-    end
-    return
-end
-
-%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
-ParamOut=[]; %default output
-%% read input parameters from an xml file if input is a file name (batch mode)
-checkrun=1;
-if ischar(Param)
-    Param=xml2struct(Param);% read Param as input file (batch case)
-    checkrun=0;
-end
-hseries=findobj(allchild(0),'Tag','series');
-RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
-WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
-
-%% define the directory for result file (with path=RootPath{1})
-OutputDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files
-
-if ~isfield(Param,'InputFields')
-    Param.InputFields.FieldName='';
-end
-
-%% root input file type
-RootPath=Param.InputTable(:,1);
-RootFile=Param.InputTable(:,3);
-SubDir=Param.InputTable(:,2);
-NomType=Param.InputTable(:,4);
-FileExt=Param.InputTable(:,5);
-[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
-%%%%%%%%%%%%
-% The cell array filecell is the list of input file names, while
-% filecell{iview,fileindex}:
-%        iview: line in the table corresponding to a given file series
-%        fileindex: file index within  the file series, 
-% i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j 
-% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
-%%%%%%%%%%%%
-% NbSlice=1;%default
-% if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
-%     NbSlice=Param.IndexRange.NbSlice;
-% end
-NbView=numel(i1_series);%number of input file series (lines in InputTable)
-NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
-NbField_i=size(i1_series{1},2); %nb of fields for the i index
-NbField=NbField_j*NbField_i; %total number of fields
-
-%% determine the file type on each line from the first input file 
-ImageTypeOptions={'image','multimage','mmreader','video'};
-NcTypeOptions={'netcdf','civx','civdata'};
-for iview=1:NbView
-    if ~exist(filecell{iview,1}','file')
-        disp_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'],checkrun)
-        return
-    end
-    [FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1});
-    FileType{iview}=FileInfo{iview}.FileType;
-    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
-    CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
-    if ~isempty(j1_series{iview})
-        frame_index{iview}=j1_series{iview};
-    else
-        frame_index{iview}=i1_series{iview};
-    end
-end
-
-%% calibration data and timing: read the ImaDoc files
-[XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
-if size(time,1)>1
-    diff_time=max(max(diff(time)));
-    if diff_time>0 
-        disp_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time) ': the mean time is chosen in result'],checkrun)
-    end   
-end
-if ~isempty(errormsg)
-    disp_uvmat('WARNING',erromsg,checkrun)
-end
-time=mean(time,1); %averaged time taken for the merged field
-
-%% coordinate transform or other user defined transform
-transform_fct='';%default fct handle
-if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
-        currentdir=pwd;
-        cd(Param.FieldTransform.TransformPath)
-        transform_fct=str2func(Param.FieldTransform.TransformName);
-        cd (currentdir)
-end
-%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
- % EDIT FROM HERE
-
-%% check the validity of  input file types
-for iview=1:NbView
-    if ~isequal(CheckImage{iview},1)&&~isequal(CheckNc{iview},1)
-        disp_uvmat('ERROR','input set of input series: need  either netcdf either image series',checkrun)
-        return
-    end
-end
-
-%% output file type
-if min(cell2mat(CheckImage))==1 && (~Param.CheckObject || strcmp(Param.ProjObject.Type,'plane'))
-    FileExtOut='.png'; %image output (input and proj result = image)
-    for iview=1:NbView
-        BitDepth(iview)=FileInfo{iview}.BitDepth;
-    end
-    BitDepth=max(BitDepth);
-else
-    FileExtOut='.nc'; %netcdf output
-end
-NomTypeOut=NomType;% output file index will indicate the first and last ref index in the series
-RootFileOut=RootFile{1};
-for iview=2:NbView
-    if ~strcmp(RootFile{iview},RootFile{1})
-        RootFileOut='mproj';
-        break
-    end
-end
-
-%% mask (TODO: case of multilevels)
-MaskData=cell(NbView,1);
-if Param.CheckMask
-    if ischar(Param.MaskTable)% case of a single mask (char chain)
-        Param.MaskTable={Param.MaskTable};
-    end
-    for iview=1:numel(Param.MaskTable)
-        if exist(Param.MaskTable{iview},'file')
-            [MaskData{iview},tild,errormsg] = read_field(Param.MaskTable{iview},'image');
-            if ~isempty(transform_fct) && nargin(transform_fct)>=2
-                MaskData{iview}=transform_fct(MaskData{iview},XmlData{iview});
-            end
-        end
-    end
-end
-
-%% Set field names and velocity types
-%use Param.InputFields for all views
-
-%% MAIN LOOP ON FIELDS
-%%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
-% for i_slice=1:NbSlice
-%     index_slice=i_slice:NbSlice:NbField;% select file indices of the slice
-%     NbFiles=0;
-%     nbmissing=0;
-
-    %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
-for index=1:NbField
-        update_waitbar(WaitbarHandle,index/NbField)
-    if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
-        disp('program stopped by user')
-        return
-    end
-    
-    %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
-    Data=cell(1,NbView);%initiate the set Data
-    timeread=zeros(1,NbView);
-    for iview=1:NbView
-        %% reading input file(s)
-        [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},Param.InputFields,frame_index{iview}(index));
-        if ~isempty(errormsg)
-            disp(['ERROR in merge_proj/read_field/' errormsg])
-            return
-        end
-        % get the time defined in the current file if not already defined from the xml file
-        if ~isempty(time) && isfield(Data{iview},'Time')
-            timeread(iview)=Data{iview}.Time;
-        end
-        if ~isempty(NbSlice_calib)
-            Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform
-        end
-        
-        %% transform the input field (e.g; phys) if requested (no transform involving two input fields)
-        if ~isempty(transform_fct)
-            if nargin(transform_fct)>=2
-                Data{iview}=transform_fct(Data{iview},XmlData{iview});
-            else
-                Data{iview}=transform_fct(Data{iview});
-            end
-        end
-        
-        %% calculate tps coefficients if needed
-        check_proj_tps= isfield(Param,'ProjObject')&&~isempty(Param.ProjObject)&& strcmp(Param.ProjObject.ProjMode,'interp_tps')&&~isfield(Data{iview},'Coord_tps');
-        Data{iview}=tps_coeff_field(Data{iview},check_proj_tps);
-        
-        %% projection on object (gridded plane)
-        if Param.CheckObject
-            [Data{iview},errormsg]=proj_field_special(Data{iview},Param.ProjObject);
-            if ~isempty(errormsg)
-                disp(['ERROR in merge_proge/proj_field: ' errormsg])
-                return
-            end
-        end
-        
-        %% mask
-        if Param.CheckMask && ~isempty(MaskData{iview})
-             [Data{iview},errormsg]=mask_proj(Data{iview},MaskData{iview});
-        end
-    end
-    %%%%%%%%%%%%%%%% END LOOP ON VIEWS %%%%%%%%%%%%%%%%
-
-    %% merge the NbView fields
-    MergeData=merge_field(Data);
-    if isfield(MergeData,'Txt')
-        disp(MergeData.Txt);
-        return
-    end
-
-    %% time of the merged field: take the average of the different views
-    if ~isempty(time)
-        timeread=time(index);   
-    elseif ~isempty(find(timeread))% time defined from ImaDoc
-        timeread=mean(timeread(timeread~=0));% take average over times form the files (when defined)
-    else
-        timeread=index;% take time=file index 
-    end
-
-    %% generating the name of the merged field
-    i1=i1_series{1}(index);
-    if ~isempty(i2_series{end})
-        i2=i2_series{end}(index);
-    else
-        i2=i1;
-    end
-    j1=1;
-    j2=1;
-    if ~isempty(j1_series{1})
-        j1=j1_series{1}(index);
-        if ~isempty(j2_series{end})
-            j2=j2_series{end}(index);
-        else
-            j2=j1;
-        end
-    end
-    OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFileOut,FileExtOut,NomType{1},i1,i2,j1,j2);
-
-    %% recording the merged field
-    if strcmp(FileExtOut,'.png')    %output as image
-        if BitDepth==8
-            imwrite(uint8(MergeData.A),OutputFile,'BitDepth',8)
-        else
-            imwrite(uint16(MergeData.A),OutputFile,'BitDepth',16)
-        end
-        if index==1
-            %write xml calibration file, using the first file
-            siz=size(MergeData.A);
-            npy=siz(1);
-            npx=siz(2);
-            if isfield(MergeData,'coord_x') && isfield(MergeData,'coord_y')
-                Rangx=MergeData.coord_x;
-                Rangy=MergeData.coord_y;
-            elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY')
-                Rangx=[MergeData.AX(1) MergeData.AX(end)];
-                Rangy=[MergeData.AY(1) MergeData.AY(end)];
-            else
-                Rangx=[0.5 npx-0.5];
-                Rangy=[npy-0.5 0.5];%default
-            end
-            pxcmx=(npx-1)/(Rangx(2)-Rangx(1));
-            pxcmy=(npy-1)/(Rangy(1)-Rangy(2));
-            T_x=-pxcmx*Rangx(1)+0.5;
-            T_y=-pxcmy*Rangy(2)+0.5;
-            GeometryCal.CalibrationType='rescale';
-            GeometryCal.CoordUnit=MergeData.CoordUnit;
-            GeometryCal.focal=1;
-            GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1];
-            GeometryCal.Tx_Ty_Tz=[T_x T_y 1];
-            ImaDoc.GeometryCalib=GeometryCal;
-            t=struct2xml(ImaDoc);
-            t=set(t,1,'name','ImaDoc');
-            save(t,[fileparts(OutputFile) '.xml'])
-        end
-        
-    else
-        MergeData.ListGlobalAttribute={'Conventions','Project','InputFile_1','InputFile_end','nb_coord','nb_dim'};
-        MergeData.Conventions='uvmat';
-        MergeData.nb_coord=2;
-        MergeData.nb_dim=2;
-        dt=[];
-        if isfield(Data{1},'dt')&& isnumeric(Data{1}.dt)
-            dt=Data{1}.dt;
-        end
-        for iview =2:numel(Data)
-            if ~(isfield(Data{iview},'dt')&& isequal(Data{iview}.dt,dt))
-                dt=[];%dt not the same for all fields
-            end
-        end
-        if ~isempty(timeread)
-            MergeData.ListGlobalAttribute=[MergeData.ListGlobalAttribute {'Time'}];
-            MergeData.Time=timeread;
-        end
-        if ~isempty(dt)
-            MergeData.ListGlobalAttribute=[MergeData.ListGlobalAttribute {'dt'}];
-            MergeData.dt=dt;
-        end
-        error=struct2nc(OutputFile,MergeData);%save result file
-        if isempty(error)
-            display(['output file ' OutputFile ' written'])
-        else
-            display(error)
-        end
-    end
-end
-
-
-%'merge_field': concatene fields
-%------------------------------------------------------------------------
-function MergeData=merge_field(Data)
-%% default output
-if isempty(Data)||~iscell(Data)
-    MergeData=[];
-    return
-end
-error=0;
-MergeData=Data{1};% merged field= first field by default, reproduces the glabal attributes of the first field
-NbView=length(Data);
-if NbView==1
-    return
-end
-
-%% group the variables (fields of 'Data') in cells of variables with the same dimensions
-[CellInfo,NbDim,errormsg]=find_field_cells(Data{1});
-
-%LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
-for icell=1:length(CellInfo)
-    if NbDim(icell)~=1 % skip field cells which are of dim 1
-        switch CellInfo{icell}.CoordType
-            case 'scattered'  %case of input fields with unstructured coordinates: just concacene data
-                for ivar=CellInfo{icell}.VarIndex %  indices of the selected variables in the list FieldData.ListVarName
-                    VarName=Data{1}.ListVarName{ivar};
-                    %MergeData=Data{1};% merged field= first field by default, reproduces the glabal attributes of the first field
-                    for iview=2:NbView
-                        MergeData.(VarName)=[MergeData.(VarName); Data{iview}.(VarName)];
-                    end
-                end
-            case 'grid'        %case of fields defined on a structured  grid
-                FFName='';
-                if isfield(CellInfo{icell},'VarIndex_errorflag') && ~isempty(CellInfo{icell}.VarIndex_errorflag)
-                    FFName=Data{1}.ListVarName{CellInfo{icell}.VarIndex_errorflag};% name of errorflag variable
-                end
-                % select good data on each view
-                for ivar=CellInfo{icell}.VarIndex  %  indices of the selected variables in the list FieldData.ListVarName
-                    VarName=Data{1}.ListVarName{ivar};
-                    for iview=1:NbView
-                        if isempty(FFName)
-                            check_bad=isnan(Data{iview}.(VarName));%=0 for NaN data values, 1 else
-                        else
-                            check_bad=isnan(Data{iview}.(VarName)) | Data{iview}.(FFName)~=0;%=0 for NaN or error flagged data values, 1 else
-                        end
-                        Data{iview}.(VarName)(check_bad)=0; %set to zero NaN or masked data
-                        if iview==1
-                            MergeData.(VarName)=Data{1}.(VarName);% correct the field of MergeData
-                            NbAver=~check_bad;% initiate NbAver: the nbre of good data for each point
-                        else
-                            MergeData.(VarName)=MergeData.(VarName) + Data{iview}.(VarName);%add data
-                            NbAver=NbAver + ~check_bad;% add 1 for good data, 0 else
-                        end
-                    end
-                    MergeData.(VarName)(NbAver~=0)=MergeData.(VarName)(NbAver~=0)./NbAver(NbAver~=0);% take average of defined data at each point
-                end
-        end
-        if isempty(FFName)
-            FFName='FF';
-        end
-        MergeData.(FFName)(NbAver~=0)=0;% flag to 1 undefined summed data
-        MergeData.(FFName)(NbAver==0)=1;% flag to 1 undefined summed data
-    end
-end
-
-function  [DataOut,errormsg]=proj_field_special(Data,Param,ProjObject)
-errormsg='';
-DataOut.ListVarName={'coord_x','coord_y','U','V'};
-DataOut.VarDimName={'coord_x','coord_y',{'coord_y','coord_x'},{'coord_y','coord_x'}};
-DataOut.coord_x=Param.RangeX(1):Param.DX:Param.RangeX(2);
-DataOut.coord_y=Param.RangeY(1):Param.DY:Param.RangeY(2);
-[XI,YI]=meshgrid(DataOut.coord_x,DataOut.coord_y);%grid in the new coordinates
-ind_select=find(Data.FF==0 & Data.C>0.5);
-Data.X=Data.X(ind_select);
-Data.Y=Data.Y(ind_select);
-Data.U=Data.U(ind_select);
-Data.V=Data.V(ind_select);
-Coord=[Data.X Data.Y];
-F=TriScatteredInterp(Coord,Data.U);
-DataOut.U=F(XI,YI);
-F=TriScatteredInterp(Coord,Data.V);
-DataOut.V=F(XI,YI);
-F=TriScatteredInterp(Coord,Data.X,'nearest');
-Xinterp=F(XI,YI);
-F=TriScatteredInterp(Coord,Data.Y,'nearest');
-Yinterp=F(XI,YI);
-
-    
Index: unk/src/series/relabel_i_j.m
===================================================================
--- /trunk/src/series/relabel_i_j.m	(revision 828)
+++ 	(revision )
@@ -1,587 +1,0 @@
-%'relabel_i_j': relabel an image series with two indices, and correct errors from the RDvision transfer program
-%------------------------------------------------------------------------
-% function ParamOut=relabel_i_j(Param)
-%------------------------------------------------------------------------
-%
-%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%OUTPUT
-% ParamOut: sets options in the GUI series.fig needed for the function
-%
-%INPUT:
-% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
-% In batch mode, Param is the name of the corresponding xml file containing the same information
-% when Param.Action.RUN=0 (as activated when the current Action is selected
-% in series), the function ouput paramOut set the activation of the needed GUI elements
-%
-% Param contains the elements:(use the menu bar command 'export/GUI config' in series to 
-% see the current structure Param)
-%    .InputTable: cell of input file names, (several lines for multiple input)
-%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
-%    .OutputSubDir: name of the subdirectory for data outputs
-%    .OutputDirExt: directory extension for data outputs
-%    .Action: .ActionName: name of the current activated function
-%             .ActionPath:   path of the current activated function
-%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
-%             .RUN =0 for GUI input, =1 for function activation
-%             .RunMode='local','background', 'cluster': type of function  use
-%             
-%    .IndexRange: set the file or frame indices on which the action must be performed
-%    .FieldTransform: .TransformName: name of the selected transform function
-%                     .TransformPath:   path  of the selected transform function
-%    .InputFields: sub structure describing the input fields withfields
-%              .FieldName: name(s) of the field
-%              .VelType: velocity type
-%              .FieldName_1: name of the second field in case of two input series
-%              .VelType_1: velocity type of the second field in case of two input series
-%              .Coord_y: name of y coordinate variable
-%              .Coord_x: name of x coordinate variable
-%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%=======================================================================
-% Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
-%   http://www.legi.grenoble-inp.fr
-%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
-%
-%     This file is part of the toolbox UVMAT.
-%
-%     UVMAT is free software; you can redistribute it and/or modify
-%     it under the terms of the GNU General Public License as published
-%     by the Free Software Foundation; either version 2 of the license,
-%     or (at your option) any later version.
-%
-%     UVMAT is distributed in the hope that it will be useful,
-%     but WITHOUT ANY WARRANTY; without even the implied warranty of
-%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-%     GNU General Public License (see LICENSE.txt) for more details.
-%=======================================================================
-
-function ParamOut=relabel_i_j(Param) %default output=relabel_i_j(Param)
-
-%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
-if isstruct(Param) && isequal(Param.Action.RUN,0)
-    ParamOut.AllowInputSort='off';...% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
-    ParamOut.WholeIndexRange='on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
-    ParamOut.NbSlice='one'; ...%nbre of slices, 'one' prevents splitting in several processes, ('off' by default)
-    ParamOut.VelType='off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
-    ParamOut.FieldName='off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
-    ParamOut.FieldTransform = 'off';...%can use a transform function
-    ParamOut.ProjObject='off';...%can use projection object(option 'off'/'on',
-    ParamOut.Mask='off';...%can use mask option   (option 'off'/'on', 'off' by default)
-    ParamOut.OutputDirExt='';%set the output dir extension
-    if size(Param.InputTable,1)>1
-        msgbox_uvmat('WARNING', 'this function acts only on the first input file line')
-    end
-return
-end
-
-ParamOut=[];
-%%%%%%%%%%%% STANDARD PART  %%%%%%%%%%%%
-%% read input parameters from an xml file if input is a file name (batch mode)
-checkrun=1;
-if ischar(Param)
-    Param=xml2struct(Param);% read Param as input file (batch case)
-    checkrun=0;
-end
-hseries=findobj(allchild(0),'Tag','series');
-RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
-WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
-
-%% root input file(s) and type
-RootPath=Param.InputTable(:,1);
-RootFile=Param.InputTable(:,3);
-SubDir=Param.InputTable(:,2);
-NomType=Param.InputTable(:,4);
-FileExt=Param.InputTable(:,5);
-
-% get the set of input file names (cell array filecell), and the lists of
-% input file or frame indices i1_series,i2_series,j1_series,j2_series
-[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
- 
-% numbers of slices and file indices
-
-nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
-nbfield_i=size(i1_series{1},2); %nb of fields for the i index
-nbfield=nbfield_j*nbfield_i; %total number of fields
-
-%determine the file type on each line from the first input file 
-ImageTypeOptions={'image','multimage','mmreader','video'};
-
-if ~exist(filecell{1,1}','file')
-    msgbox_uvmat('ERROR',['the first input file ' filecell{1,1} ' does not exist'])
-    return
-end
-[FileInfo{1},MovieObject{1}]=get_file_info(filecell{1,1});
-FileType{1}=FileInfo{1}.FileType;
-CheckImage=~isempty(find(strcmp(FileType{1},ImageTypeOptions)));% =1 for images
-
-
-%% calibration data and timing: read the ImaDoc files
-mode=''; %default
-timecell={};
-itime=0;
-NbSlice_calib={};
-
-SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
-filexml=[fullfile(RootPath{1},SubDirBase) '.xml'];%new convention: xml at the level of the image folder
-if ~exist(filexml,'file')
-    filexml=[fullfile(RootPath{1},SubDir{1},RootFile{1}) '.xml']; % old convention: xml inside the image folder
-    if ~exist(filexml,'file')
-        filexml=[fullfile(RootPath{1},SubDir{1},RootFile{1}) '.civ']; % very old convention: .civ file
-        if ~exist(filexml,'file')
-            filexml='';
-        end
-    end
-end
-XmlData=[];
-if ~isempty(filexml)
-    [XmlData,error]=imadoc2struct_special(filexml);
-end
-if isfield(XmlData,'Time')
-    itime=itime+1;
-    timecell{itime}=XmlData.Time;
-end
-if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
-    NbSlice_calib{1}=size(XmlData.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
-    if ~isequal(NbSlice_calib{1},NbSlice_calib{1})
-        msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
-    end
-end
-
-%% check coincidence in time for several input file series
-% not relevant
-
-%% coordinate transform or other user defined transform
-%not relevant
-%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
- % EDIT FROM HERE
-
-
-%% Set field names and velocity types
-% not relevant here
-
-%% Initiate output fields
-% not relevant here
-
-%% interactive input of specific parameters (for RDvision system)
-display('RDvision system')
-first_label=0; %image numbers start from 0
-if ~CheckImage || ~strcmp(NomType{1},'_000001')
-    msgbox_uvmat('WARNING','the input is not a file from RDvision: this function relabel_i_j has no action');%error message for directory creation
-    return
-else
-    answer=msgbox_uvmat('','this function will relabel the file series from RDvision from  and correct the xml file');%error message for directory creation
-    if ~strcmp(answer,'Yes')
-        return
-    end
-end
-
-%% copy and adapt the xml file
-NomTypeNew='_1_1';
-if ~isempty(XmlData)
-        t=xmltree(filexml);
-        
-        %update information on the first image name in the series
-        uid_Heading=find(t,'ImaDoc/Heading');
-        if isempty(uid_Heading)
-            [t,uid_Heading]=add(t,1,'element','Heading');
-        end
-        uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
-        j1=[];
-        if ~isempty(j1_series{1})
-            j1=j1_series{1};
-        end
-        ImageName=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},'_1_1',i1_series{1}(1),[],j1);
-        [pth,ImageName]=fileparts(ImageName);
-        ImageName=[ImageName '.png'];
-        if isempty(uid_ImageName)
-            [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
-        end
-        uid_value=children(t,uid_ImageName);
-        if isempty(uid_value)
-            t=add(t,uid_ImageName,'chardata',ImageName);%indicate  name of the first image, with ;png extension
-        else
-            t=set(t,uid_value(1),'value',ImageName);%indicate  name of the first image, with ;png extension
-        end
-        
-        %%%% correction RDvision %%%%
-        if isfield(XmlData,'NbDtj')
-            uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
-            uid_value=children(t,uid_NbDtj);
-            if ~isempty(uid_value)
-                t=set(t,uid_value(1),'value',num2str(XmlData.NbDtj));
-            end
-        end
-        if isfield(XmlData,'NbDtk')
-            uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
-            uid_value=children(t,uid_NbDtk);
-            if ~isempty(uid_value)
-                t=set(t,uid_value(1),'value',num2str(XmlData.NbDtk));
-            end
-        end
-        if isempty(j1_series{1}) && isfield(XmlData,'NbDti')
-            uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
-            t=add(t,uid_Dti,'chardata',num2str(XmlData.Dti));
-            uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
-            t=add(t,uid_NbDti,'chardata',num2str(XmlData.NbDti));
-            uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
-            uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
-            t=delete(t,uid_NbDtj);
-            t=delete(t,uid_NbDtk);
-            uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
-            uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk');
-            t=delete(t,uid_Dtj);
-            t=delete(t,uid_Dtk);
-            NomTypeNew='_1';
-        end
-            SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
-    filexml_new=[fullfile(RootPath{1},SubDirBase) '.xml'];
-        save(t,filexml_new)
-end
-
-%% main loop on images
-%j1=[];%default
-nbfield2=1;
-if isfield(XmlData,'Time')
-nbfield2=size(XmlData.Time,2);
-end
-for ifile=1:nbfield
-            update_waitbar(WaitbarHandle,ifile/nbfield)
-    if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
-        disp('program stopped by user')
-        break
-    end
-    filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile));
-    j1=[];
-    if ~isequal(nbfield2,1)
-    j1=mod(ifile-1+first_label,nbfield2)+1;
-    end
-    i1=floor((ifile-1+first_label)/nbfield2)+1;
-    filename_new=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomTypeNew,i1,[],j1);
-    try
-        movefile(filename,filename_new);
-        [s,errormsg] = fileattrib(filename_new,'-w','a'); %set images to read only '-w' for all users ('a')
-        if ~s
-            msgbox_uvmat('ERROR',errormsg);
-            return
-        end
-    catch ME
-        msgbox_uvmat('ERROR',ME.message);
-        return
-    end
-    
-end
-
-%'imadoc2struct_special': reads the xml file for image documentation 
-%------------------------------------------------------------------------
-% function [s,errormsg]=imadoc2struct_special(ImaDoc,option) 
-%
-% OUTPUT:
-% s: structure representing ImaDoc
-%   s.Heading: information about the data hierarchical structure
-%   s.Time: matrix of times
-%   s.TimeUnit
-%  s.GeometryCalib: substructure containing the parameters for geometric calibration
-% errormsg: error message
-%
-% INPUT:
-% ImaDoc: full name of the xml input file with head key ImaDoc
-% option: ='GeometryCalib': read  the data of GeometryCalib, including source point coordinates
-
-function [s,errormsg]=imadoc2struct_special(ImaDoc,option) 
-
-%% default input and output
-if ~exist('option','var')
-    option='*';
-end
-errormsg=[];%default
-s.Heading=[];%default
-s.Time=[]; %default
-s.TimeUnit=[]; %default
-s.GeometryCalib=[];
-tsai=[];%default
-
-%% opening the xml file
-if exist(ImaDoc,'file')~=2, errormsg=[ ImaDoc ' does not exist']; return;end;%input file does not exist
-try
-    t=xmltree(ImaDoc);
-catch
-    errormsg={[ImaDoc ' is not a valid xml file']; lasterr};
-    display(errormsg);
-    return
-end
-uid_root=find(t,'/ImaDoc');
-if isempty(uid_root), errormsg=[ImaDoc ' is not an image documentation file ImaDoc']; return; end;%not an ImaDoc .xml file
-
-
-%% Heading
-uid_Heading=find(t,'/ImaDoc/Heading');
-if ~isempty(uid_Heading), 
-    uid_Campaign=find(t,'/ImaDoc/Heading/Campaign');
-    uid_Exp=find(t,'/ImaDoc/Heading/Experiment');
-    uid_Device=find(t,'/ImaDoc/Heading/Device');
-    uid_Record=find(t,'/ImaDoc/Heading/Record');
-    uid_FirstImage=find(t,'/ImaDoc/Heading/ImageName');
-    s.Heading.Campaign=get(t,children(t,uid_Campaign),'value');
-    s.Heading.Experiment=get(t,children(t,uid_Exp),'value');
-    s.Heading.Device=get(t,children(t,uid_Device),'value');
-    if ~isempty(uid_Record)
-        s.Heading.Record=get(t,children(t,uid_Record),'value');
-    end
-    s.Heading.ImageName=get(t,children(t,uid_FirstImage),'value');
-end
-
-%% Camera  and timing
-if strcmp(option,'*') || strcmp(option,'Camera')
-    uid_Camera=find(t,'/ImaDoc/Camera');
-    if ~isempty(uid_Camera)
-        uid_ImageSize=find(t,'/ImaDoc/Camera/ImageSize');
-        if ~isempty(uid_ImageSize);
-            ImageSize=get(t,children(t,uid_ImageSize),'value');
-            xindex=findstr(ImageSize,'x');
-            if length(xindex)>=2
-                s.Npx=str2double(ImageSize(1:xindex(1)-1));
-                s.Npy=str2double(ImageSize(xindex(1)+1:xindex(2)-1));
-            end
-        end
-        uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit');
-        if ~isempty(uid_TimeUnit)
-            s.TimeUnit=get(t,children(t,uid_TimeUnit),'value');
-        end
-        uid_BurstTiming=find(t,'/ImaDoc/Camera/BurstTiming');
-        if ~isempty(uid_BurstTiming)
-            for k=1:length(uid_BurstTiming)
-                subt=branch(t,uid_BurstTiming(k));%subtree under BurstTiming
-                % reading Dtk
-                Frequency=get_value(subt,'/BurstTiming/FrameFrequency',1);
-                Dtj=get_value(subt,'/BurstTiming/Dtj',[]);
-                Dtj=Dtj/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
-                NbDtj=get_value(subt,'/BurstTiming/NbDtj',[]);
-                %%%% correction RDvision %%%%
-%                 NbDtj=NbDtj/numel(Dtj);
-%                 s.NbDtj=NbDtj;
-%                 %%%%
-                Dti=get_value(subt,'/BurstTiming/Dti',[]);
-                NbDti=get_value(subt,'/BurstTiming/NbDti',1);
-                 %%%% correction RDvision %%%%
-                if isempty(Dti)% series 
-                     Dti=Dtj;
-                      NbDti=NbDtj;
-                     Dtj=[];
-                     s.Dti=Dti;
-                     s.NbDti=NbDti;
-                else
-                    % NbDtj=NbDtj/numel(Dtj);%bursts
-                    if ~isempty(NbDtj)
-                    s.NbDtj=NbDtj/numel(Dtj);%bursts;
-                    else
-                        s.NbDtj=1;
-                    end
-                end
-                %%%% %%%%
-                Dti=Dti/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
-
-                Time_val=get_value(subt,'/BurstTiming/Time',0);%time in TimeUnit
-                if ~isempty(Dti)
-                    Dti=reshape(Dti'*ones(1,NbDti),NbDti*numel(Dti),1); %concatene Dti vector NbDti times
-                    Time_val=[Time_val;Time_val(end)+cumsum(Dti)];%append the times defined by the intervals  Dti
-                end
-                if ~isempty(Dtj)
-                    Dtj=reshape(Dtj'*ones(1,s.NbDtj),1,s.NbDtj*numel(Dtj)); %concatene Dtj vector NbDtj times
-                    Dtj=[0 Dtj];
-                    Time_val=Time_val*ones(1,numel(Dtj))+ones(numel(Time_val),1)*cumsum(Dtj);% produce a time matrix with Dtj
-                end
-                % reading Dtk
-                Dtk=get_value(subt,'/BurstTiming/Dtk',[]);
-                NbDtk=get_value(subt,'/BurstTiming/NbDtk',1);
-                %%%% correction RDvision %%%%
-                if ~isequal(NbDtk,1)
-                    NbDtk=-1+(NbDtk+1)/(NbDti+1);
-                end
-                s.NbDtk=NbDtk;
-                %%%%%
-                if isempty(Dtk)
-                    s.Time=[s.Time;Time_val];
-                else
-                    for kblock=1:NbDtk+1
-                        Time_val_k=Time_val+(kblock-1)*Dtk;
-                        s.Time=[s.Time;Time_val_k];
-                    end
-                end
-            end
-        end
-    end
-end
-
-%% motor
-if strcmp(option,'*') || strcmp(option,'GeometryCalib')
-    uid_subtree=find(t,'/ImaDoc/TranslationMotor');
-    if length(uid_subtree)==1
-        subt=branch(t,uid_subtree);%subtree under GeometryCalib
-       [s.TranslationMotor,errormsg]=read_subtree(subt,{'Nbslice','ZStart','ZEnd'},[1 1 1],[1 1 1]);
-    end 
-end
-%%  geometric calibration
-if strcmp(option,'*') || strcmp(option,'GeometryCalib')
-    uid_GeometryCalib=find(t,'/ImaDoc/GeometryCalib');
-    if ~isempty(uid_GeometryCalib)
-        if length(uid_GeometryCalib)>1
-            errormsg=['More than one GeometryCalib in ' filecivxml];
-            return
-        end
-        subt=branch(t,uid_GeometryCalib);%subtree under GeometryCalib
-        cont=get(subt,1,'contents');
-        if ~isempty(cont)
-            uid_CalibrationType=find(subt,'/GeometryCalib/CalibrationType');
-            if isequal(length(uid_CalibrationType),1)
-                tsai.CalibrationType=get(subt,children(subt,uid_CalibrationType),'value');
-            end
-            uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit');
-            if isequal(length(uid_CoordUnit),1)
-                tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value');
-            end
-            uid_fx_fy=find(subt,'/GeometryCalib/fx_fy');
-            focal=[];%default fro old convention (Reg Wilson)
-            if isequal(length(uid_fx_fy),1)
-                tsai.fx_fy=str2num(get(subt,children(subt,uid_fx_fy),'value'));
-            else %old convention (Reg Wilson)
-                uid_focal=find(subt,'/GeometryCalib/focal');
-                uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy');
-                uid_sx=find(subt,'/GeometryCalib/sx');
-                if ~isempty(uid_focal) && ~isempty(uid_dpx_dpy) && ~isempty(uid_sx)
-                    dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value'));
-                    sx=str2num(get(subt,children(subt,uid_sx),'value'));
-                    focal=str2num(get(subt,children(subt,uid_focal),'value'));
-                    tsai.fx_fy(1)=sx*focal/dpx_dpy(1);
-                    tsai.fx_fy(2)=focal/dpx_dpy(2);
-                end
-            end
-            uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy');
-            if ~isempty(uid_Cx_Cy)
-                tsai.Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value'));
-            end
-            uid_kc=find(subt,'/GeometryCalib/kc');
-            if ~isempty(uid_kc)
-                tsai.kc=str2double(get(subt,children(subt,uid_kc),'value'));
-            else %old convention (Reg Wilson)
-                uid_kappa1=find(subt,'/GeometryCalib/kappa1');
-                if ~isempty(uid_kappa1)&& ~isempty(focal)
-                    kappa1=str2double(get(subt,children(subt,uid_kappa1),'value'));
-                    tsai.kc=-kappa1*focal*focal;
-                end
-            end
-            uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz');
-            if ~isempty(uid_Tx_Ty_Tz)
-                tsai.Tx_Ty_Tz=str2num(get(subt,children(subt,uid_Tx_Ty_Tz),'value'));
-            end
-            uid_R=find(subt,'/GeometryCalib/R');
-            if ~isempty(uid_R)
-                RR=get(subt,children(subt,uid_R),'value');
-                if length(RR)==3
-                    tsai.R=[str2num(RR{1});str2num(RR{2});str2num(RR{3})];
-                end
-            end
-            
-            %look for laser plane definitions
-            uid_Angle=find(subt,'/GeometryCalib/PlaneAngle');
-            uid_Pos=find(subt,'/GeometryCalib/SliceCoord');
-            if isempty(uid_Pos)
-                uid_Pos=find(subt,'/GeometryCalib/PlanePos');%old convention
-            end
-            if ~isempty(uid_Angle)
-                tsai.PlaneAngle=str2num(get(subt,children(subt,uid_Angle),'value'));
-            end
-            if ~isempty(uid_Pos)
-                for j=1:length(uid_Pos)
-                    tsai.SliceCoord(j,:)=str2num(get(subt,children(subt,uid_Pos(j)),'value'));
-                end
-                uid_DZ=find(subt,'/GeometryCalib/SliceDZ');
-                uid_NbSlice=find(subt,'/GeometryCalib/NbSlice');
-                if ~isempty(uid_DZ) && ~isempty(uid_NbSlice)
-                    DZ=str2double(get(subt,children(subt,uid_DZ),'value'));
-                    NbSlice=get(subt,children(subt,uid_NbSlice),'value');
-                    if isequal(NbSlice,'volume')
-                        tsai.NbSlice='volume';
-                        NbSlice=NbDtj+1;
-                    else
-                        tsai.NbSlice=str2double(NbSlice);
-                    end
-                    tsai.SliceCoord=ones(NbSlice,1)*tsai.SliceCoord+DZ*(0:NbSlice-1)'*[0 0 1];
-                end
-            end   
-            tsai.SliceAngle=get_value(subt,'/GeometryCalib/SliceAngle',[0 0 0]);
-            tsai.VolumeScan=get_value(subt,'/GeometryCalib/VolumeScan','n');
-            tsai.InterfaceCoord=get_value(subt,'/GeometryCalib/InterfaceCoord',[0 0 0]);
-            tsai.RefractionIndex=get_value(subt,'/GeometryCalib/RefractionIndex',1);
-            
-            if strcmp(option,'GeometryCalib')
-                tsai.PointCoord=get_value(subt,'/GeometryCalib/SourceCalib/PointCoord',[0 0 0 0 0]);
-            end
-            s.GeometryCalib=tsai;
-        end
-    end
-end
-
-%--------------------------------------------------
-%  read a subtree
-% INPUT: 
-% t: xltree
-% head_element: head elelemnt of the subtree
-% Data, structure containing 
-%    .Key: element name
-%    .Type: type of element ('charg', 'float'....)
-%    .NbOccur: nbre of occurrence, NaN for un specified number 
-function [s,errormsg]=read_subtree(subt,Data,NbOccur,NumTest)
-%--------------------------------------------------
-s=[];%default
-errormsg='';
-head_element=get(subt,1,'name');
-    cont=get(subt,1,'contents');
-    if ~isempty(cont)
-        for ilist=1:length(Data)
-            uid_key=find(subt,[head_element '/' Data{ilist}]);
-            if ~isequal(length(uid_key),NbOccur(ilist))
-                errormsg=['wrong number of occurence for ' Data{ilist}];
-                return
-            end
-            for ival=1:length(uid_key)
-                val=get(subt,children(subt,uid_key(ival)),'value');
-                if ~NumTest(ilist)
-                    eval(['s.' Data{ilist} '=val;']);
-                else
-                    eval(['s.' Data{ilist} '=str2double(val);'])
-                end
-            end
-        end
-    end
-
-
-%--------------------------------------------------
-%  read an xml element
-function val=get_value(t,label,default)
-%--------------------------------------------------
-val=default;
-uid=find(t,label);%find the element iud(s)
-if ~isempty(uid) %if the element named label exists
-   uid_child=children(t,uid);%find the children 
-   if ~isempty(uid_child)
-       data=get(t,uid_child,'type');%get the type of child
-       if iscell(data)% case of multiple element
-           for icell=1:numel(data)
-               val_read=str2num(get(t,uid_child(icell),'value'));
-               if ~isempty(val_read)
-                   val(icell,:)=val_read;
-               end
-           end
-%           val=val';
-       else % case of unique element value
-           val_read=str2num(get(t,uid_child,'value'));
-           if ~isempty(val_read)
-               val=val_read;
-           else
-              val=get(t,uid_child,'value');%char string data
-           end
-       end
-   end
-end
Index: /trunk/src/series/usr_fct/clean_civ_cmx.m
===================================================================
--- /trunk/src/series/usr_fct/clean_civ_cmx.m	(revision 829)
+++ /trunk/src/series/usr_fct/clean_civ_cmx.m	(revision 829)
@@ -0,0 +1,86 @@
+%'clean_civ_cmx': suppress all ancillary files used for PIV: ;cmx,log,.bat...
+%------------------------------------------------------------------------
+% function GUI_input=clean_civ_cmx(num_i1,num_i2,num_j1,num_j2,Series)
+%
+%OUTPUT
+% GUI_input=list of options in the GUI series.fig needed for the function
+%
+%INPUT:
+%num_i1: (not used) series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_i2: (not used) series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_j1: (not used) series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
+%num_j2: (not used) series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
+%Series: Matlab structure containing information set by the series interface
+
+%=======================================================================
+% Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
+%   http://www.legi.grenoble-inp.fr
+%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
+%
+%     This file is part of the toolbox UVMAT.
+%
+%     UVMAT is free software; you can redistribute it and/or modify
+%     it under the terms of the GNU General Public License as published
+%     by the Free Software Foundation; either version 2 of the license,
+%     or (at your option) any later version.
+%
+%     UVMAT is distributed in the hope that it will be useful,
+%     but WITHOUT ANY WARRANTY; without even the implied warranty of
+%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%     GNU General Public License (see LICENSE.txt) for more details.
+%=======================================================================
+
+function GUI_input=clean_civ_cmx(num_i1,num_i2,num_j1,num_j2,Series) %(filecell,filecell_1,num_i,num_j,vel_type,field,param);
+
+%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
+if ~exist('num_i1','var')
+    GUI_input={'RootPath';'many';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
+        'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
+        %'RootFile';'on';... %root input file name ('on' by default)
+        %'FileExt';'on';... %input file extension ('on' by default)
+        %'NomType';'on';...%type of file indexing ('on' by default)
+        %'NbSlice';'on'; ...%nbre of slices ('off' by default)
+        %'VelTypeMenu';'one';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default)
+        %'FieldMenu';'one';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+        %'CoordType';'on'...%can use a transform function 'off' by default
+        %'GetObject';'on'...%can use projection object ,'off' by default
+        %'GetMask';'on'...%can use mask option   ,'off' by default
+        %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter 
+               ''};
+    return %exit the function 
+end
+%---------------------------------------------------------
+hseries=guidata(Series.hseries);%handles of the GUI series
+WaitbarPos=get(hseries.waitbar_frame,'Position');
+
+%%%%%%%%%%%%%%%%%%%%%%%%
+message='this function will delete all files with extensions .log, .bat, .cmx,.cmx2,.errors in the input directory(ies)';
+answer=msgbox_uvmat('INPUT_Y-N',message);
+if ~isequal(answer,'Yes')
+    return
+end
+nbdelete=0;
+testcell=iscell(Series.RootFile);
+if ~testcell
+    Series.RootPath={Series.RootPath};
+    Series.RootFile={Series.RootFile};
+    Series.SubDir={Series.SubDir};
+    Series.FileExt={Series.FileExt};
+    Series.NomType={Series.NomType};
+end 
+for iview=1:length(Series.RootFile)
+    hdir=dir(fullfile(Series.RootPath{iview},Series.SubDir{iview}));%list files
+    for ilist=1:length(hdir)
+%         update_waitbar(hseries.waitbar,WaitbarPos,ilist/length(hdir))
+        FileName=hdir(ilist).name;
+        [dd,ff,Ext]=fileparts(FileName);
+        if isequal(Ext,'.log')||isequal(Ext,'.bat')||isequal(Ext,'.cmx')||isequal(Ext,'.cmx2')|| isequal(Ext,'.errors')
+            delete(fullfile(Series.RootPath{iview},Series.SubDir{iview},FileName))
+            nbdelete=nbdelete+1;
+        end
+    end
+end
+msgbox_uvmat('CONFIRMATION',['END: ' num2str(nbdelete) ' files deleted by clean_civ_cmx'])
+
+
+
Index: /trunk/src/series/usr_fct/merge_proj_images.m
===================================================================
--- /trunk/src/series/usr_fct/merge_proj_images.m	(revision 829)
+++ /trunk/src/series/usr_fct/merge_proj_images.m	(revision 829)
@@ -0,0 +1,434 @@
+%'merge_proj': concatene several images from series, adjust their luminosity, can project them on a regular grid in phys coordinates
+%------------------------------------------------------------------------
+% function ParamOut=merge_proj(Param)
+%------------------------------------------------------------------------
+%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%OUTPUT
+% ParamOut: sets options in the GUI series.fig needed for the function
+%
+%INPUT:
+% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
+% In batch mode, Param is the name of the corresponding xml file containing the same information
+% when Param.Action.RUN=0 (as activated when the current Action is selected
+% in series), the function ouput paramOut set the activation of the needed GUI elements
+%
+% Param contains the elements:(use the menu bar command 'export/GUI config' in series to 
+% see the current structure Param)
+%    .InputTable: cell of input file names, (several lines for multiple input)
+%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
+%    .OutputSubDir: name of the subdirectory for data outputs
+%    .OutputDirExt: directory extension for data outputs
+%    .Action: .ActionName: name of the current activated function
+%             .ActionPath:   path of the current activated function
+%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
+%             .RUN =0 for GUI input, =1 for function activation
+%             .RunMode='local','background', 'cluster': type of function  use
+%             
+%    .IndexRange: set the file or frame indices on which the action must be performed
+%    .FieldTransform: .TransformName: name of the selected transform function
+%                     .TransformPath:   path  of the selected transform function
+%    .InputFields: sub structure describing the input fields withfields
+%              .FieldName: name(s) of the field
+%              .VelType: velocity type
+%              .FieldName_1: name of the second field in case of two input series
+%              .VelType_1: velocity type of the second field in case of two input series
+%              .Coord_y: name of y coordinate variable
+%              .Coord_x: name of x coordinate variable
+%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%=======================================================================
+% Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
+%   http://www.legi.grenoble-inp.fr
+%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
+%
+%     This file is part of the toolbox UVMAT.
+%
+%     UVMAT is free software; you can redistribute it and/or modify
+%     it under the terms of the GNU General Public License as published
+%     by the Free Software Foundation; either version 2 of the license,
+%     or (at your option) any later version.
+%
+%     UVMAT is distributed in the hope that it will be useful,
+%     but WITHOUT ANY WARRANTY; without even the implied warranty of
+%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%     GNU General Public License (see LICENSE.txt) for more details.
+%=======================================================================
+
+function ParamOut=merge_proj(Param)
+
+%% set the input elements needed on the GUI series when the function is selected in the menu ActionName or InputTable refreshed
+ImageTypeOptions={'image','multimage','mmreader','video'};
+if isstruct(Param) && isequal(Param.Action.RUN,0)
+    ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
+    ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
+    ParamOut.NbSlice='off'; %nbre of slices ('off' by default)
+    ParamOut.VelType='one';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
+    ParamOut.FieldName='one';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+    ParamOut.FieldTransform = 'on';%can use a transform function
+    ParamOut.TransformPath=fullfile(fileparts(which('uvmat')),'transform_field');% path to transform functions (needed for compilation only)
+    ParamOut.ProjObject='on';%can use projection object(option 'off'/'on',
+    ParamOut.Mask='on';%can use mask option   (option 'off'/'on', 'off' by default)
+    ParamOut.OutputDirExt='.mproj';%set the output dir extension
+    ParamOut.OutputFileMode='NbInput';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
+    first_j=[];
+    if isequal(size(Param.InputTable,1),1) && ~isfield(Param,'ProjObject')
+        msgbox_uvmat('WARNING','You need a projection object of type plane for merge_proj')
+    end
+    if isfield(Param.IndexRange,'first_j'); first_j=Param.IndexRange.first_j; end
+    PairString='';
+    if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end
+    [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString);
+    
+    for iview=1:size(Param.InputTable,1)
+        FirstFileName=fullfile_uvmat(Param.InputTable{iview,1},Param.InputTable{iview,2},Param.InputTable{iview,3},...
+            Param.InputTable{iview,5},Param.InputTable{iview,4},i1,i2,j1,j2);
+        if ~exist(FirstFileName,'file')
+            msgbox_uvmat('WARNING',['the first input file ' FirstFileName ' does not exist'])
+        end
+        FileInfo=get_file_info(FirstFileName);
+        CheckImage=~isempty(find(strcmp(FileInfo.FileType,ImageTypeOptions)));% =1 for images
+        if ~CheckImage
+            msgbox_uvmat('WARNING',['the input file ' FirstFileName ' is not an image'])
+        end
+    end
+    return
+end
+
+%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
+ParamOut=[]; %default output
+%% read input parameters from an xml file if input is a file name (batch mode)
+checkrun=1;
+if ischar(Param)
+    Param=xml2struct(Param);% read Param as input file (batch case)
+    checkrun=0;
+end
+hseries=findobj(allchild(0),'Tag','series');
+RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
+WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
+
+%% define the directory for result file (with path=RootPath{1})
+OutputDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files
+
+if ~isfield(Param,'InputFields')
+    Param.InputFields.FieldName='';
+end
+
+%% root input file type
+RootPath=Param.InputTable(:,1);
+RootFile=Param.InputTable(:,3);
+SubDir=Param.InputTable(:,2);
+NomType=Param.InputTable(:,4);
+FileExt=Param.InputTable(:,5);
+[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
+%%%%%%%%%%%%
+% The cell array filecell is the list of input file names, while
+% filecell{iview,fileindex}:
+%        iview: line in the table corresponding to a given file series
+%        fileindex: file index within  the file series, 
+% i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j 
+% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
+%%%%%%%%%%%%
+% NbSlice=1;%default
+% if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
+%     NbSlice=Param.IndexRange.NbSlice;
+% end
+NbView=numel(i1_series);%number of input file series (lines in InputTable)
+NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
+NbField_i=size(i1_series{1},2); %nb of fields for the i index
+NbField=NbField_j*NbField_i; %total number of fields
+
+%% determine the file type on each line from the first input file 
+ImageTypeOptions={'image','multimage','mmreader','video'};
+NcTypeOptions={'netcdf','civx','civdata'};
+for iview=1:NbView
+    if ~exist(filecell{iview,1}','file')
+        disp_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'],checkrun)
+        return
+    end
+    [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});
+    FileType{iview}=FileInfo{iview}.FileType;
+    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
+    
+    if ~isempty(j1_series{iview})
+        frame_index{iview}=j1_series{iview};
+    else
+        frame_index{iview}=i1_series{iview};
+    end
+end
+
+%% calibration data and timing: read the ImaDoc files
+[XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
+if size(time,1)>1
+    diff_time=max(max(diff(time)));
+    if diff_time>0
+        disp_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time) ': the mean time is chosen in result'],checkrun)
+    end
+end
+if ~isempty(errormsg)
+    disp_uvmat('WARNING',errormsg,checkrun)
+end
+time=mean(time,1); %averaged time taken for the merged field
+
+%% coordinate transform or other user defined transform
+transform_fct='';%default fct handle
+if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
+    currentdir=pwd;
+    cd(Param.FieldTransform.TransformPath)
+    transform_fct=str2func(Param.FieldTransform.TransformName);
+    cd (currentdir)
+end
+
+%% output file type (8 bits)
+
+FileExtOut='.png'; %image output (input and proj result = image)
+% for iview=1:NbView
+%     BitDepth(iview)=FileInfo{iview}.BitDepth;
+% end
+% BitDepth=max(BitDepth);
+BitDepth=8;
+
+NomTypeOut=NomType;% output file index will indicate the first and last ref index in the series
+RootFileOut=RootFile{1};
+for iview=2:NbView
+    if ~strcmp(RootFile{iview},RootFile{1})
+        RootFileOut='mproj';
+        break
+    end
+end
+
+%% mask 
+MaskData=cell(NbView,1);
+if Param.CheckMask
+    if ischar(Param.MaskTable)% case of a single mask (char chain)
+        Param.MaskTable={Param.MaskTable};
+    end
+    for iview=1:numel(Param.MaskTable)
+        if exist(Param.MaskTable{iview},'file')
+            [MaskData{iview},tild,errormsg] = read_field(Param.MaskTable{iview},'image');
+            if ~isempty(transform_fct) && nargin(transform_fct)>=2
+                MaskData{iview}=transform_fct(MaskData{iview},XmlData{iview});
+            end
+        end
+    end
+end
+
+%% Set field names and velocity types
+%use Param.InputFields for all views
+
+%% MAIN LOOP ON FIELDS
+%%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
+% for i_slice=1:NbSlice
+%     index_slice=i_slice:NbSlice:NbField;% select file indices of the slice
+%     NbFiles=0;
+%     nbmissing=0;
+
+%%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
+for index=1:NbField
+    update_waitbar(WaitbarHandle,index/NbField)
+    if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
+        disp('program stopped by user')
+        return
+    end
+    
+    %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
+    Data=cell(1,NbView);%initiate the set Data
+    timeread=zeros(1,NbView);
+    for iview=1:NbView
+        %% reading input file(s)
+        [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},Param.InputFields,frame_index{iview}(index));
+        if ~isempty(errormsg)
+            disp(['ERROR in merge_proj/read_field/' errormsg])
+            return
+        end
+        % get the time defined in the current file if not already defined from the xml file
+        if ~isempty(time) && isfield(Data{iview},'Time')
+            timeread(iview)=Data{iview}.Time;
+        end
+        if ~isempty(NbSlice_calib)
+            Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform
+        end
+        
+        %% transform the input field (e.g; phys) if requested (no transform involving two input fields)
+        if ~isempty(transform_fct)
+            if nargin(transform_fct)>=2
+                Data{iview}=transform_fct(Data{iview},XmlData{iview});
+            else
+                Data{iview}=transform_fct(Data{iview});
+            end
+        end
+        
+        %% CUSTOM ADJUSTMENT OF LUMINOSITY ANDCONTRAST%%%%%%%%%%%
+        if iview==1
+        Data{iview}.A=Data{iview}.A-100; %remove offset on Dalsa1
+        else
+        Data{iview}.A=Data{iview}.A-60; %remove offset on Dalsa2
+        Data{iview}.A=Data{iview}.A*3;%adjust luminosity of Dalsa2
+        Data{iview}.A=filter2(ones(2,2)/4,Data{iview}.A); %filter image Dalsa2 to fit with the projection grid resolution
+        end
+        
+        %% projection on object (gridded plane)
+        if Param.CheckObject
+            [Data{iview},errormsg]=proj_field(Data{iview},Param.ProjObject);
+            if ~isempty(errormsg)
+                disp(['ERROR in merge_proge/proj_field: ' errormsg])
+                return
+            end
+        end
+        
+        %% mask
+        if Param.CheckMask && ~isempty(MaskData{iview})
+            [Data{iview},errormsg]=mask_proj(Data{iview},MaskData{iview});
+        end
+    end
+    %%%%%%%%%%%%%%%% END LOOP ON VIEWS %%%%%%%%%%%%%%%%
+    
+    %% merge the NbView fields
+    MergeData=merge_field(Data);
+    if isfield(MergeData,'Txt')
+        disp(MergeData.Txt);
+        return
+    end
+    
+    %% time of the merged field: take the average of the different views
+    if ~isempty(time)
+        timeread=time(index);
+    elseif ~isempty(find(timeread))% time defined from ImaDoc
+        timeread=mean(timeread(timeread~=0));% take average over times form the files (when defined)
+    else
+        timeread=index;% take time=file index
+    end
+    
+    %% generating the name of the merged field
+    i1=i1_series{1}(index);
+    if ~isempty(i2_series{end})
+        i2=i2_series{end}(index);
+    else
+        i2=i1;
+    end
+    j1=1;
+    j2=1;
+    if ~isempty(j1_series{1})
+        j1=j1_series{1}(index);
+        if ~isempty(j2_series{end})
+            j2=j2_series{end}(index);
+        else
+            j2=j1;
+        end
+    end
+    OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFileOut,FileExtOut,NomType{1},i1,i2,j1,j2);
+    
+    %% recording the merged field
+    
+    if BitDepth==8
+        imwrite(uint8(MergeData.A),OutputFile,'BitDepth',8)
+    else
+        imwrite(uint16(MergeData.A),OutputFile,'BitDepth',16)
+    end
+    if index==1
+        %write xml calibration file, using the first file
+        siz=size(MergeData.A);
+        npy=siz(1);
+        npx=siz(2);
+        if isfield(MergeData,'coord_x') && isfield(MergeData,'coord_y')
+            Rangx=MergeData.coord_x;
+            Rangy=MergeData.coord_y;
+        elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY')
+            Rangx=[MergeData.AX(1) MergeData.AX(end)];
+            Rangy=[MergeData.AY(1) MergeData.AY(end)];
+        else
+            Rangx=[0.5 npx-0.5];
+            Rangy=[npy-0.5 0.5];%default
+        end
+        pxcmx=(npx-1)/(Rangx(2)-Rangx(1));
+        pxcmy=(npy-1)/(Rangy(1)-Rangy(2));
+        T_x=-pxcmx*Rangx(1)+0.5;
+        T_y=-pxcmy*Rangy(2)+0.5;
+        GeometryCal.CalibrationType='rescale';
+        GeometryCal.CoordUnit=MergeData.CoordUnit;
+        GeometryCal.focal=1;
+        GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1];
+        GeometryCal.Tx_Ty_Tz=[T_x T_y 1];
+        ImaDoc.GeometryCalib=GeometryCal;
+        t=struct2xml(ImaDoc);
+        t=set(t,1,'name','ImaDoc');
+        save(t,[fileparts(OutputFile) '.xml'])
+    end
+end   
+
+
+
+%'merge_field': concatene fields
+%------------------------------------------------------------------------
+function [MergeData,errormsg]=merge_field(Data)
+%% default output
+if isempty(Data)||~iscell(Data)
+    MergeData=[];
+    return
+end
+errormsg='';
+MergeData=Data{1};% merged field= first field by default, reproduces the glabal attributes of the first field
+NbView=length(Data);
+if NbView==1
+    return
+end
+
+%% group the variables (fields of 'Data') in cells of variables with the same dimensions
+[CellInfo,NbDim,errormsg]=find_field_cells(Data{1});
+if ~isempty(errormsg)
+    return
+end
+
+%LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
+for icell=1:length(CellInfo)
+    if NbDim(icell)~=1 % skip field cells which are of dim 1
+        switch CellInfo{icell}.CoordType
+            case 'scattered'  %case of input fields with unstructured coordinates: just concacene data
+                for ivar=CellInfo{icell}.VarIndex %  indices of the selected variables in the list FieldData.ListVarName
+                    VarName=Data{1}.ListVarName{ivar};
+                    %MergeData=Data{1};% merged field= first field by default, reproduces the glabal attributes of the first field
+                    for iview=2:NbView
+                        MergeData.(VarName)=[MergeData.(VarName); Data{iview}.(VarName)];
+                    end
+                end
+            case 'grid'        %case of fields defined on a structured  grid
+                FFName='';
+                if isfield(CellInfo{icell},'VarIndex_errorflag') && ~isempty(CellInfo{icell}.VarIndex_errorflag)
+                    FFName=Data{1}.ListVarName{CellInfo{icell}.VarIndex_errorflag};% name of errorflag variable
+                end
+                % select good data on each view
+                for ivar=CellInfo{icell}.VarIndex  %  indices of the selected variables in the list FieldData.ListVarName
+                    VarName=Data{1}.ListVarName{ivar};
+                    for iview=1:NbView
+                        if isempty(FFName)
+                            check_bad=isnan(Data{iview}.(VarName));%=0 for NaN data values, 1 else
+                        else
+                            check_bad=isnan(Data{iview}.(VarName)) | Data{iview}.(FFName)~=0;%=0 for NaN or error flagged data values, 1 else
+                        end
+                        Data{iview}.(VarName)(check_bad)=0; %set to zero NaN or masked data
+                        if iview==1
+                            MergeData.(VarName)=Data{1}.(VarName);% correct the field of MergeData
+                            NbAver=~check_bad;% initiate NbAver: the nbre of good data for each point
+                        elseif size(Data{iview}.(VarName))~=size(MergeData.(VarName))
+                            errormsg='sizes of the input matrices do not agree, need to interpolate on a common grid using a projection object';
+                            return
+                        else                     
+                            MergeData.(VarName)=MergeData.(VarName) + Data{iview}.(VarName);%add data
+                            NbAver=NbAver + ~check_bad;% add 1 for good data, 0 else
+                        end
+                    end
+                    MergeData.(VarName)(NbAver~=0)=MergeData.(VarName)(NbAver~=0)./NbAver(NbAver~=0);% take average of defined data at each point
+                end
+        end
+        if isempty(FFName)
+            FFName='FF';
+        end
+        MergeData.(FFName)(NbAver~=0)=0;% flag to 1 undefined summed data
+        MergeData.(FFName)(NbAver==0)=1;% flag to 1 undefined summed data
+    end
+end
+
+
+
+    
Index: /trunk/src/series/usr_fct/merge_proj_special.m
===================================================================
--- /trunk/src/series/usr_fct/merge_proj_special.m	(revision 829)
+++ /trunk/src/series/usr_fct/merge_proj_special.m	(revision 829)
@@ -0,0 +1,467 @@
+%'merge_proj': concatene several fields from series, can project them on a regular grid in phys coordinates
+%------------------------------------------------------------------------
+% function ParamOut=merge_proj(Param)
+%------------------------------------------------------------------------
+%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%OUTPUT
+% ParamOut: sets options in the GUI series.fig needed for the function
+%
+%INPUT:
+% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
+% In batch mode, Param is the name of the corresponding xml file containing the same information
+% when Param.Action.RUN=0 (as activated when the current Action is selected
+% in series), the function ouput paramOut set the activation of the needed GUI elements
+%
+% Param contains the elements:(use the menu bar command 'export/GUI config' in series to 
+% see the current structure Param)
+%    .InputTable: cell of input file names, (several lines for multiple input)
+%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
+%    .OutputSubDir: name of the subdirectory for data outputs
+%    .OutputDirExt: directory extension for data outputs
+%    .Action: .ActionName: name of the current activated function
+%             .ActionPath:   path of the current activated function
+%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
+%             .RUN =0 for GUI input, =1 for function activation
+%             .RunMode='local','background', 'cluster': type of function  use
+%             
+%    .IndexRange: set the file or frame indices on which the action must be performed
+%    .FieldTransform: .TransformName: name of the selected transform function
+%                     .TransformPath:   path  of the selected transform function
+%    .InputFields: sub structure describing the input fields withfields
+%              .FieldName: name(s) of the field
+%              .VelType: velocity type
+%              .FieldName_1: name of the second field in case of two input series
+%              .VelType_1: velocity type of the second field in case of two input series
+%              .Coord_y: name of y coordinate variable
+%              .Coord_x: name of x coordinate variable
+%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%=======================================================================
+% Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
+%   http://www.legi.grenoble-inp.fr
+%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
+%
+%     This file is part of the toolbox UVMAT.
+%
+%     UVMAT is free software; you can redistribute it and/or modify
+%     it under the terms of the GNU General Public License as published
+%     by the Free Software Foundation; either version 2 of the license,
+%     or (at your option) any later version.
+%
+%     UVMAT is distributed in the hope that it will be useful,
+%     but WITHOUT ANY WARRANTY; without even the implied warranty of
+%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%     GNU General Public License (see LICENSE.txt) for more details.
+%=======================================================================
+
+function ParamOut=merge_proj(Param)
+
+%% set the input elements needed on the GUI series when the function is selected in the menu ActionName or InputTable refreshed
+if isstruct(Param) && isequal(Param.Action.RUN,0)
+    ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
+    ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
+    ParamOut.NbSlice='off'; %nbre of slices ('off' by default)
+    ParamOut.VelType='one';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
+    ParamOut.FieldName='one';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+    ParamOut.FieldTransform = 'on';%can use a transform function
+    ParamOut.TransformPath=fullfile(fileparts(which('uvmat')),'transform_field');% path to transform functions (needed for compilation only)
+    ParamOut.ProjObject='on';%can use projection object(option 'off'/'on',
+    ParamOut.Mask='on';%can use mask option   (option 'off'/'on', 'off' by default)
+    ParamOut.OutputDirExt='.mproj';%set the output dir extension
+    ParamOut.OutputFileMode='NbInput';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
+    filecell=get_file_series(Param);%check existence of the first input file
+    if ~exist(filecell{1,1},'file')
+        msgbox_uvmat('WARNING','the first input file does not exist')
+    elseif isequal(size(Param.InputTable,1),1) && ~isfield(Param,'ProjObject')
+        msgbox_uvmat('WARNING','You may need a projection object of type plane for merge_proj')
+    end
+    return
+end
+
+%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
+ParamOut=[]; %default output
+%% read input parameters from an xml file if input is a file name (batch mode)
+checkrun=1;
+if ischar(Param)
+    Param=xml2struct(Param);% read Param as input file (batch case)
+    checkrun=0;
+end
+hseries=findobj(allchild(0),'Tag','series');
+RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
+WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
+
+%% define the directory for result file (with path=RootPath{1})
+OutputDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files
+
+if ~isfield(Param,'InputFields')
+    Param.InputFields.FieldName='';
+end
+
+%% root input file type
+RootPath=Param.InputTable(:,1);
+RootFile=Param.InputTable(:,3);
+SubDir=Param.InputTable(:,2);
+NomType=Param.InputTable(:,4);
+FileExt=Param.InputTable(:,5);
+[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
+%%%%%%%%%%%%
+% The cell array filecell is the list of input file names, while
+% filecell{iview,fileindex}:
+%        iview: line in the table corresponding to a given file series
+%        fileindex: file index within  the file series, 
+% i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j 
+% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
+%%%%%%%%%%%%
+% NbSlice=1;%default
+% if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
+%     NbSlice=Param.IndexRange.NbSlice;
+% end
+NbView=numel(i1_series);%number of input file series (lines in InputTable)
+NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
+NbField_i=size(i1_series{1},2); %nb of fields for the i index
+NbField=NbField_j*NbField_i; %total number of fields
+
+%% determine the file type on each line from the first input file 
+ImageTypeOptions={'image','multimage','mmreader','video'};
+NcTypeOptions={'netcdf','civx','civdata'};
+for iview=1:NbView
+    if ~exist(filecell{iview,1}','file')
+        disp_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'],checkrun)
+        return
+    end
+    [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});
+    FileType{iview}=FileInfo{iview}.FileType;
+    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
+    CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
+    if ~isempty(j1_series{iview})
+        frame_index{iview}=j1_series{iview};
+    else
+        frame_index{iview}=i1_series{iview};
+    end
+end
+
+%% calibration data and timing: read the ImaDoc files
+[XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
+if size(time,1)>1
+    diff_time=max(max(diff(time)));
+    if diff_time>0 
+        disp_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time) ': the mean time is chosen in result'],checkrun)
+    end   
+end
+if ~isempty(errormsg)
+    disp_uvmat('WARNING',erromsg,checkrun)
+end
+time=mean(time,1); %averaged time taken for the merged field
+
+%% coordinate transform or other user defined transform
+transform_fct='';%default fct handle
+if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
+        currentdir=pwd;
+        cd(Param.FieldTransform.TransformPath)
+        transform_fct=str2func(Param.FieldTransform.TransformName);
+        cd (currentdir)
+end
+%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
+ % EDIT FROM HERE
+
+%% check the validity of  input file types
+for iview=1:NbView
+    if ~isequal(CheckImage{iview},1)&&~isequal(CheckNc{iview},1)
+        disp_uvmat('ERROR','input set of input series: need  either netcdf either image series',checkrun)
+        return
+    end
+end
+
+%% output file type
+if min(cell2mat(CheckImage))==1 && (~Param.CheckObject || strcmp(Param.ProjObject.Type,'plane'))
+    FileExtOut='.png'; %image output (input and proj result = image)
+    for iview=1:NbView
+        BitDepth(iview)=FileInfo{iview}.BitDepth;
+    end
+    BitDepth=max(BitDepth);
+else
+    FileExtOut='.nc'; %netcdf output
+end
+NomTypeOut=NomType;% output file index will indicate the first and last ref index in the series
+RootFileOut=RootFile{1};
+for iview=2:NbView
+    if ~strcmp(RootFile{iview},RootFile{1})
+        RootFileOut='mproj';
+        break
+    end
+end
+
+%% mask (TODO: case of multilevels)
+MaskData=cell(NbView,1);
+if Param.CheckMask
+    if ischar(Param.MaskTable)% case of a single mask (char chain)
+        Param.MaskTable={Param.MaskTable};
+    end
+    for iview=1:numel(Param.MaskTable)
+        if exist(Param.MaskTable{iview},'file')
+            [MaskData{iview},tild,errormsg] = read_field(Param.MaskTable{iview},'image');
+            if ~isempty(transform_fct) && nargin(transform_fct)>=2
+                MaskData{iview}=transform_fct(MaskData{iview},XmlData{iview});
+            end
+        end
+    end
+end
+
+%% Set field names and velocity types
+%use Param.InputFields for all views
+
+%% MAIN LOOP ON FIELDS
+%%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
+% for i_slice=1:NbSlice
+%     index_slice=i_slice:NbSlice:NbField;% select file indices of the slice
+%     NbFiles=0;
+%     nbmissing=0;
+
+    %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
+for index=1:NbField
+        update_waitbar(WaitbarHandle,index/NbField)
+    if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
+        disp('program stopped by user')
+        return
+    end
+    
+    %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
+    Data=cell(1,NbView);%initiate the set Data
+    timeread=zeros(1,NbView);
+    for iview=1:NbView
+        %% reading input file(s)
+        [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},Param.InputFields,frame_index{iview}(index));
+        if ~isempty(errormsg)
+            disp(['ERROR in merge_proj/read_field/' errormsg])
+            return
+        end
+        % get the time defined in the current file if not already defined from the xml file
+        if ~isempty(time) && isfield(Data{iview},'Time')
+            timeread(iview)=Data{iview}.Time;
+        end
+        if ~isempty(NbSlice_calib)
+            Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform
+        end
+        
+        %% transform the input field (e.g; phys) if requested (no transform involving two input fields)
+        if ~isempty(transform_fct)
+            if nargin(transform_fct)>=2
+                Data{iview}=transform_fct(Data{iview},XmlData{iview});
+            else
+                Data{iview}=transform_fct(Data{iview});
+            end
+        end
+        
+        %% calculate tps coefficients if needed
+        check_proj_tps= isfield(Param,'ProjObject')&&~isempty(Param.ProjObject)&& strcmp(Param.ProjObject.ProjMode,'interp_tps')&&~isfield(Data{iview},'Coord_tps');
+        Data{iview}=tps_coeff_field(Data{iview},check_proj_tps);
+        
+        %% projection on object (gridded plane)
+        if Param.CheckObject
+            [Data{iview},errormsg]=proj_field_special(Data{iview},Param.ProjObject);
+            if ~isempty(errormsg)
+                disp(['ERROR in merge_proge/proj_field: ' errormsg])
+                return
+            end
+        end
+        
+        %% mask
+        if Param.CheckMask && ~isempty(MaskData{iview})
+             [Data{iview},errormsg]=mask_proj(Data{iview},MaskData{iview});
+        end
+    end
+    %%%%%%%%%%%%%%%% END LOOP ON VIEWS %%%%%%%%%%%%%%%%
+
+    %% merge the NbView fields
+    MergeData=merge_field(Data);
+    if isfield(MergeData,'Txt')
+        disp(MergeData.Txt);
+        return
+    end
+
+    %% time of the merged field: take the average of the different views
+    if ~isempty(time)
+        timeread=time(index);   
+    elseif ~isempty(find(timeread))% time defined from ImaDoc
+        timeread=mean(timeread(timeread~=0));% take average over times form the files (when defined)
+    else
+        timeread=index;% take time=file index 
+    end
+
+    %% generating the name of the merged field
+    i1=i1_series{1}(index);
+    if ~isempty(i2_series{end})
+        i2=i2_series{end}(index);
+    else
+        i2=i1;
+    end
+    j1=1;
+    j2=1;
+    if ~isempty(j1_series{1})
+        j1=j1_series{1}(index);
+        if ~isempty(j2_series{end})
+            j2=j2_series{end}(index);
+        else
+            j2=j1;
+        end
+    end
+    OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFileOut,FileExtOut,NomType{1},i1,i2,j1,j2);
+
+    %% recording the merged field
+    if strcmp(FileExtOut,'.png')    %output as image
+        if BitDepth==8
+            imwrite(uint8(MergeData.A),OutputFile,'BitDepth',8)
+        else
+            imwrite(uint16(MergeData.A),OutputFile,'BitDepth',16)
+        end
+        if index==1
+            %write xml calibration file, using the first file
+            siz=size(MergeData.A);
+            npy=siz(1);
+            npx=siz(2);
+            if isfield(MergeData,'coord_x') && isfield(MergeData,'coord_y')
+                Rangx=MergeData.coord_x;
+                Rangy=MergeData.coord_y;
+            elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY')
+                Rangx=[MergeData.AX(1) MergeData.AX(end)];
+                Rangy=[MergeData.AY(1) MergeData.AY(end)];
+            else
+                Rangx=[0.5 npx-0.5];
+                Rangy=[npy-0.5 0.5];%default
+            end
+            pxcmx=(npx-1)/(Rangx(2)-Rangx(1));
+            pxcmy=(npy-1)/(Rangy(1)-Rangy(2));
+            T_x=-pxcmx*Rangx(1)+0.5;
+            T_y=-pxcmy*Rangy(2)+0.5;
+            GeometryCal.CalibrationType='rescale';
+            GeometryCal.CoordUnit=MergeData.CoordUnit;
+            GeometryCal.focal=1;
+            GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1];
+            GeometryCal.Tx_Ty_Tz=[T_x T_y 1];
+            ImaDoc.GeometryCalib=GeometryCal;
+            t=struct2xml(ImaDoc);
+            t=set(t,1,'name','ImaDoc');
+            save(t,[fileparts(OutputFile) '.xml'])
+        end
+        
+    else
+        MergeData.ListGlobalAttribute={'Conventions','Project','InputFile_1','InputFile_end','nb_coord','nb_dim'};
+        MergeData.Conventions='uvmat';
+        MergeData.nb_coord=2;
+        MergeData.nb_dim=2;
+        dt=[];
+        if isfield(Data{1},'dt')&& isnumeric(Data{1}.dt)
+            dt=Data{1}.dt;
+        end
+        for iview =2:numel(Data)
+            if ~(isfield(Data{iview},'dt')&& isequal(Data{iview}.dt,dt))
+                dt=[];%dt not the same for all fields
+            end
+        end
+        if ~isempty(timeread)
+            MergeData.ListGlobalAttribute=[MergeData.ListGlobalAttribute {'Time'}];
+            MergeData.Time=timeread;
+        end
+        if ~isempty(dt)
+            MergeData.ListGlobalAttribute=[MergeData.ListGlobalAttribute {'dt'}];
+            MergeData.dt=dt;
+        end
+        error=struct2nc(OutputFile,MergeData);%save result file
+        if isempty(error)
+            display(['output file ' OutputFile ' written'])
+        else
+            display(error)
+        end
+    end
+end
+
+
+%'merge_field': concatene fields
+%------------------------------------------------------------------------
+function MergeData=merge_field(Data)
+%% default output
+if isempty(Data)||~iscell(Data)
+    MergeData=[];
+    return
+end
+error=0;
+MergeData=Data{1};% merged field= first field by default, reproduces the glabal attributes of the first field
+NbView=length(Data);
+if NbView==1
+    return
+end
+
+%% group the variables (fields of 'Data') in cells of variables with the same dimensions
+[CellInfo,NbDim,errormsg]=find_field_cells(Data{1});
+
+%LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
+for icell=1:length(CellInfo)
+    if NbDim(icell)~=1 % skip field cells which are of dim 1
+        switch CellInfo{icell}.CoordType
+            case 'scattered'  %case of input fields with unstructured coordinates: just concacene data
+                for ivar=CellInfo{icell}.VarIndex %  indices of the selected variables in the list FieldData.ListVarName
+                    VarName=Data{1}.ListVarName{ivar};
+                    %MergeData=Data{1};% merged field= first field by default, reproduces the glabal attributes of the first field
+                    for iview=2:NbView
+                        MergeData.(VarName)=[MergeData.(VarName); Data{iview}.(VarName)];
+                    end
+                end
+            case 'grid'        %case of fields defined on a structured  grid
+                FFName='';
+                if isfield(CellInfo{icell},'VarIndex_errorflag') && ~isempty(CellInfo{icell}.VarIndex_errorflag)
+                    FFName=Data{1}.ListVarName{CellInfo{icell}.VarIndex_errorflag};% name of errorflag variable
+                end
+                % select good data on each view
+                for ivar=CellInfo{icell}.VarIndex  %  indices of the selected variables in the list FieldData.ListVarName
+                    VarName=Data{1}.ListVarName{ivar};
+                    for iview=1:NbView
+                        if isempty(FFName)
+                            check_bad=isnan(Data{iview}.(VarName));%=0 for NaN data values, 1 else
+                        else
+                            check_bad=isnan(Data{iview}.(VarName)) | Data{iview}.(FFName)~=0;%=0 for NaN or error flagged data values, 1 else
+                        end
+                        Data{iview}.(VarName)(check_bad)=0; %set to zero NaN or masked data
+                        if iview==1
+                            MergeData.(VarName)=Data{1}.(VarName);% correct the field of MergeData
+                            NbAver=~check_bad;% initiate NbAver: the nbre of good data for each point
+                        else
+                            MergeData.(VarName)=MergeData.(VarName) + Data{iview}.(VarName);%add data
+                            NbAver=NbAver + ~check_bad;% add 1 for good data, 0 else
+                        end
+                    end
+                    MergeData.(VarName)(NbAver~=0)=MergeData.(VarName)(NbAver~=0)./NbAver(NbAver~=0);% take average of defined data at each point
+                end
+        end
+        if isempty(FFName)
+            FFName='FF';
+        end
+        MergeData.(FFName)(NbAver~=0)=0;% flag to 1 undefined summed data
+        MergeData.(FFName)(NbAver==0)=1;% flag to 1 undefined summed data
+    end
+end
+
+function  [DataOut,errormsg]=proj_field_special(Data,Param,ProjObject)
+errormsg='';
+DataOut.ListVarName={'coord_x','coord_y','U','V'};
+DataOut.VarDimName={'coord_x','coord_y',{'coord_y','coord_x'},{'coord_y','coord_x'}};
+DataOut.coord_x=Param.RangeX(1):Param.DX:Param.RangeX(2);
+DataOut.coord_y=Param.RangeY(1):Param.DY:Param.RangeY(2);
+[XI,YI]=meshgrid(DataOut.coord_x,DataOut.coord_y);%grid in the new coordinates
+ind_select=find(Data.FF==0 & Data.C>0.5);
+Data.X=Data.X(ind_select);
+Data.Y=Data.Y(ind_select);
+Data.U=Data.U(ind_select);
+Data.V=Data.V(ind_select);
+Coord=[Data.X Data.Y];
+F=TriScatteredInterp(Coord,Data.U);
+DataOut.U=F(XI,YI);
+F=TriScatteredInterp(Coord,Data.V);
+DataOut.V=F(XI,YI);
+F=TriScatteredInterp(Coord,Data.X,'nearest');
+Xinterp=F(XI,YI);
+F=TriScatteredInterp(Coord,Data.Y,'nearest');
+Yinterp=F(XI,YI);
+
+    
Index: /trunk/src/series/usr_fct/relabel_i_j.m
===================================================================
--- /trunk/src/series/usr_fct/relabel_i_j.m	(revision 829)
+++ /trunk/src/series/usr_fct/relabel_i_j.m	(revision 829)
@@ -0,0 +1,587 @@
+%'relabel_i_j': relabel an image series with two indices, and correct errors from the RDvision transfer program
+%------------------------------------------------------------------------
+% function ParamOut=relabel_i_j(Param)
+%------------------------------------------------------------------------
+%
+%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%OUTPUT
+% ParamOut: sets options in the GUI series.fig needed for the function
+%
+%INPUT:
+% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
+% In batch mode, Param is the name of the corresponding xml file containing the same information
+% when Param.Action.RUN=0 (as activated when the current Action is selected
+% in series), the function ouput paramOut set the activation of the needed GUI elements
+%
+% Param contains the elements:(use the menu bar command 'export/GUI config' in series to 
+% see the current structure Param)
+%    .InputTable: cell of input file names, (several lines for multiple input)
+%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
+%    .OutputSubDir: name of the subdirectory for data outputs
+%    .OutputDirExt: directory extension for data outputs
+%    .Action: .ActionName: name of the current activated function
+%             .ActionPath:   path of the current activated function
+%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
+%             .RUN =0 for GUI input, =1 for function activation
+%             .RunMode='local','background', 'cluster': type of function  use
+%             
+%    .IndexRange: set the file or frame indices on which the action must be performed
+%    .FieldTransform: .TransformName: name of the selected transform function
+%                     .TransformPath:   path  of the selected transform function
+%    .InputFields: sub structure describing the input fields withfields
+%              .FieldName: name(s) of the field
+%              .VelType: velocity type
+%              .FieldName_1: name of the second field in case of two input series
+%              .VelType_1: velocity type of the second field in case of two input series
+%              .Coord_y: name of y coordinate variable
+%              .Coord_x: name of x coordinate variable
+%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%=======================================================================
+% Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
+%   http://www.legi.grenoble-inp.fr
+%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
+%
+%     This file is part of the toolbox UVMAT.
+%
+%     UVMAT is free software; you can redistribute it and/or modify
+%     it under the terms of the GNU General Public License as published
+%     by the Free Software Foundation; either version 2 of the license,
+%     or (at your option) any later version.
+%
+%     UVMAT is distributed in the hope that it will be useful,
+%     but WITHOUT ANY WARRANTY; without even the implied warranty of
+%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%     GNU General Public License (see LICENSE.txt) for more details.
+%=======================================================================
+
+function ParamOut=relabel_i_j(Param) %default output=relabel_i_j(Param)
+
+%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
+if isstruct(Param) && isequal(Param.Action.RUN,0)
+    ParamOut.AllowInputSort='off';...% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
+    ParamOut.WholeIndexRange='on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
+    ParamOut.NbSlice='one'; ...%nbre of slices, 'one' prevents splitting in several processes, ('off' by default)
+    ParamOut.VelType='off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
+    ParamOut.FieldName='off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+    ParamOut.FieldTransform = 'off';...%can use a transform function
+    ParamOut.ProjObject='off';...%can use projection object(option 'off'/'on',
+    ParamOut.Mask='off';...%can use mask option   (option 'off'/'on', 'off' by default)
+    ParamOut.OutputDirExt='';%set the output dir extension
+    if size(Param.InputTable,1)>1
+        msgbox_uvmat('WARNING', 'this function acts only on the first input file line')
+    end
+return
+end
+
+ParamOut=[];
+%%%%%%%%%%%% STANDARD PART  %%%%%%%%%%%%
+%% read input parameters from an xml file if input is a file name (batch mode)
+checkrun=1;
+if ischar(Param)
+    Param=xml2struct(Param);% read Param as input file (batch case)
+    checkrun=0;
+end
+hseries=findobj(allchild(0),'Tag','series');
+RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
+WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
+
+%% root input file(s) and type
+RootPath=Param.InputTable(:,1);
+RootFile=Param.InputTable(:,3);
+SubDir=Param.InputTable(:,2);
+NomType=Param.InputTable(:,4);
+FileExt=Param.InputTable(:,5);
+
+% get the set of input file names (cell array filecell), and the lists of
+% input file or frame indices i1_series,i2_series,j1_series,j2_series
+[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
+ 
+% numbers of slices and file indices
+
+nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
+nbfield_i=size(i1_series{1},2); %nb of fields for the i index
+nbfield=nbfield_j*nbfield_i; %total number of fields
+
+%determine the file type on each line from the first input file 
+ImageTypeOptions={'image','multimage','mmreader','video'};
+
+if ~exist(filecell{1,1}','file')
+    msgbox_uvmat('ERROR',['the first input file ' filecell{1,1} ' does not exist'])
+    return
+end
+[FileInfo{1},MovieObject{1}]=get_file_info(filecell{1,1});
+FileType{1}=FileInfo{1}.FileType;
+CheckImage=~isempty(find(strcmp(FileType{1},ImageTypeOptions)));% =1 for images
+
+
+%% calibration data and timing: read the ImaDoc files
+mode=''; %default
+timecell={};
+itime=0;
+NbSlice_calib={};
+
+SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
+filexml=[fullfile(RootPath{1},SubDirBase) '.xml'];%new convention: xml at the level of the image folder
+if ~exist(filexml,'file')
+    filexml=[fullfile(RootPath{1},SubDir{1},RootFile{1}) '.xml']; % old convention: xml inside the image folder
+    if ~exist(filexml,'file')
+        filexml=[fullfile(RootPath{1},SubDir{1},RootFile{1}) '.civ']; % very old convention: .civ file
+        if ~exist(filexml,'file')
+            filexml='';
+        end
+    end
+end
+XmlData=[];
+if ~isempty(filexml)
+    [XmlData,error]=imadoc2struct_special(filexml);
+end
+if isfield(XmlData,'Time')
+    itime=itime+1;
+    timecell{itime}=XmlData.Time;
+end
+if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
+    NbSlice_calib{1}=size(XmlData.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
+    if ~isequal(NbSlice_calib{1},NbSlice_calib{1})
+        msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
+    end
+end
+
+%% check coincidence in time for several input file series
+% not relevant
+
+%% coordinate transform or other user defined transform
+%not relevant
+%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
+ % EDIT FROM HERE
+
+
+%% Set field names and velocity types
+% not relevant here
+
+%% Initiate output fields
+% not relevant here
+
+%% interactive input of specific parameters (for RDvision system)
+display('RDvision system')
+first_label=0; %image numbers start from 0
+if ~CheckImage || ~strcmp(NomType{1},'_000001')
+    msgbox_uvmat('WARNING','the input is not a file from RDvision: this function relabel_i_j has no action');%error message for directory creation
+    return
+else
+    answer=msgbox_uvmat('','this function will relabel the file series from RDvision from  and correct the xml file');%error message for directory creation
+    if ~strcmp(answer,'Yes')
+        return
+    end
+end
+
+%% copy and adapt the xml file
+NomTypeNew='_1_1';
+if ~isempty(XmlData)
+        t=xmltree(filexml);
+        
+        %update information on the first image name in the series
+        uid_Heading=find(t,'ImaDoc/Heading');
+        if isempty(uid_Heading)
+            [t,uid_Heading]=add(t,1,'element','Heading');
+        end
+        uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
+        j1=[];
+        if ~isempty(j1_series{1})
+            j1=j1_series{1};
+        end
+        ImageName=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},'_1_1',i1_series{1}(1),[],j1);
+        [pth,ImageName]=fileparts(ImageName);
+        ImageName=[ImageName '.png'];
+        if isempty(uid_ImageName)
+            [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
+        end
+        uid_value=children(t,uid_ImageName);
+        if isempty(uid_value)
+            t=add(t,uid_ImageName,'chardata',ImageName);%indicate  name of the first image, with ;png extension
+        else
+            t=set(t,uid_value(1),'value',ImageName);%indicate  name of the first image, with ;png extension
+        end
+        
+        %%%% correction RDvision %%%%
+        if isfield(XmlData,'NbDtj')
+            uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
+            uid_value=children(t,uid_NbDtj);
+            if ~isempty(uid_value)
+                t=set(t,uid_value(1),'value',num2str(XmlData.NbDtj));
+            end
+        end
+        if isfield(XmlData,'NbDtk')
+            uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
+            uid_value=children(t,uid_NbDtk);
+            if ~isempty(uid_value)
+                t=set(t,uid_value(1),'value',num2str(XmlData.NbDtk));
+            end
+        end
+        if isempty(j1_series{1}) && isfield(XmlData,'NbDti')
+            uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
+            t=add(t,uid_Dti,'chardata',num2str(XmlData.Dti));
+            uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
+            t=add(t,uid_NbDti,'chardata',num2str(XmlData.NbDti));
+            uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
+            uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
+            t=delete(t,uid_NbDtj);
+            t=delete(t,uid_NbDtk);
+            uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
+            uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk');
+            t=delete(t,uid_Dtj);
+            t=delete(t,uid_Dtk);
+            NomTypeNew='_1';
+        end
+            SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
+    filexml_new=[fullfile(RootPath{1},SubDirBase) '.xml'];
+        save(t,filexml_new)
+end
+
+%% main loop on images
+%j1=[];%default
+nbfield2=1;
+if isfield(XmlData,'Time')
+nbfield2=size(XmlData.Time,2);
+end
+for ifile=1:nbfield
+            update_waitbar(WaitbarHandle,ifile/nbfield)
+    if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
+        disp('program stopped by user')
+        break
+    end
+    filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile));
+    j1=[];
+    if ~isequal(nbfield2,1)
+    j1=mod(ifile-1+first_label,nbfield2)+1;
+    end
+    i1=floor((ifile-1+first_label)/nbfield2)+1;
+    filename_new=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomTypeNew,i1,[],j1);
+    try
+        movefile(filename,filename_new);
+        [s,errormsg] = fileattrib(filename_new,'-w','a'); %set images to read only '-w' for all users ('a')
+        if ~s
+            msgbox_uvmat('ERROR',errormsg);
+            return
+        end
+    catch ME
+        msgbox_uvmat('ERROR',ME.message);
+        return
+    end
+    
+end
+
+%'imadoc2struct_special': reads the xml file for image documentation 
+%------------------------------------------------------------------------
+% function [s,errormsg]=imadoc2struct_special(ImaDoc,option) 
+%
+% OUTPUT:
+% s: structure representing ImaDoc
+%   s.Heading: information about the data hierarchical structure
+%   s.Time: matrix of times
+%   s.TimeUnit
+%  s.GeometryCalib: substructure containing the parameters for geometric calibration
+% errormsg: error message
+%
+% INPUT:
+% ImaDoc: full name of the xml input file with head key ImaDoc
+% option: ='GeometryCalib': read  the data of GeometryCalib, including source point coordinates
+
+function [s,errormsg]=imadoc2struct_special(ImaDoc,option) 
+
+%% default input and output
+if ~exist('option','var')
+    option='*';
+end
+errormsg=[];%default
+s.Heading=[];%default
+s.Time=[]; %default
+s.TimeUnit=[]; %default
+s.GeometryCalib=[];
+tsai=[];%default
+
+%% opening the xml file
+if exist(ImaDoc,'file')~=2, errormsg=[ ImaDoc ' does not exist']; return;end;%input file does not exist
+try
+    t=xmltree(ImaDoc);
+catch
+    errormsg={[ImaDoc ' is not a valid xml file']; lasterr};
+    display(errormsg);
+    return
+end
+uid_root=find(t,'/ImaDoc');
+if isempty(uid_root), errormsg=[ImaDoc ' is not an image documentation file ImaDoc']; return; end;%not an ImaDoc .xml file
+
+
+%% Heading
+uid_Heading=find(t,'/ImaDoc/Heading');
+if ~isempty(uid_Heading), 
+    uid_Campaign=find(t,'/ImaDoc/Heading/Campaign');
+    uid_Exp=find(t,'/ImaDoc/Heading/Experiment');
+    uid_Device=find(t,'/ImaDoc/Heading/Device');
+    uid_Record=find(t,'/ImaDoc/Heading/Record');
+    uid_FirstImage=find(t,'/ImaDoc/Heading/ImageName');
+    s.Heading.Campaign=get(t,children(t,uid_Campaign),'value');
+    s.Heading.Experiment=get(t,children(t,uid_Exp),'value');
+    s.Heading.Device=get(t,children(t,uid_Device),'value');
+    if ~isempty(uid_Record)
+        s.Heading.Record=get(t,children(t,uid_Record),'value');
+    end
+    s.Heading.ImageName=get(t,children(t,uid_FirstImage),'value');
+end
+
+%% Camera  and timing
+if strcmp(option,'*') || strcmp(option,'Camera')
+    uid_Camera=find(t,'/ImaDoc/Camera');
+    if ~isempty(uid_Camera)
+        uid_ImageSize=find(t,'/ImaDoc/Camera/ImageSize');
+        if ~isempty(uid_ImageSize);
+            ImageSize=get(t,children(t,uid_ImageSize),'value');
+            xindex=findstr(ImageSize,'x');
+            if length(xindex)>=2
+                s.Npx=str2double(ImageSize(1:xindex(1)-1));
+                s.Npy=str2double(ImageSize(xindex(1)+1:xindex(2)-1));
+            end
+        end
+        uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit');
+        if ~isempty(uid_TimeUnit)
+            s.TimeUnit=get(t,children(t,uid_TimeUnit),'value');
+        end
+        uid_BurstTiming=find(t,'/ImaDoc/Camera/BurstTiming');
+        if ~isempty(uid_BurstTiming)
+            for k=1:length(uid_BurstTiming)
+                subt=branch(t,uid_BurstTiming(k));%subtree under BurstTiming
+                % reading Dtk
+                Frequency=get_value(subt,'/BurstTiming/FrameFrequency',1);
+                Dtj=get_value(subt,'/BurstTiming/Dtj',[]);
+                Dtj=Dtj/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
+                NbDtj=get_value(subt,'/BurstTiming/NbDtj',[]);
+                %%%% correction RDvision %%%%
+%                 NbDtj=NbDtj/numel(Dtj);
+%                 s.NbDtj=NbDtj;
+%                 %%%%
+                Dti=get_value(subt,'/BurstTiming/Dti',[]);
+                NbDti=get_value(subt,'/BurstTiming/NbDti',1);
+                 %%%% correction RDvision %%%%
+                if isempty(Dti)% series 
+                     Dti=Dtj;
+                      NbDti=NbDtj;
+                     Dtj=[];
+                     s.Dti=Dti;
+                     s.NbDti=NbDti;
+                else
+                    % NbDtj=NbDtj/numel(Dtj);%bursts
+                    if ~isempty(NbDtj)
+                    s.NbDtj=NbDtj/numel(Dtj);%bursts;
+                    else
+                        s.NbDtj=1;
+                    end
+                end
+                %%%% %%%%
+                Dti=Dti/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
+
+                Time_val=get_value(subt,'/BurstTiming/Time',0);%time in TimeUnit
+                if ~isempty(Dti)
+                    Dti=reshape(Dti'*ones(1,NbDti),NbDti*numel(Dti),1); %concatene Dti vector NbDti times
+                    Time_val=[Time_val;Time_val(end)+cumsum(Dti)];%append the times defined by the intervals  Dti
+                end
+                if ~isempty(Dtj)
+                    Dtj=reshape(Dtj'*ones(1,s.NbDtj),1,s.NbDtj*numel(Dtj)); %concatene Dtj vector NbDtj times
+                    Dtj=[0 Dtj];
+                    Time_val=Time_val*ones(1,numel(Dtj))+ones(numel(Time_val),1)*cumsum(Dtj);% produce a time matrix with Dtj
+                end
+                % reading Dtk
+                Dtk=get_value(subt,'/BurstTiming/Dtk',[]);
+                NbDtk=get_value(subt,'/BurstTiming/NbDtk',1);
+                %%%% correction RDvision %%%%
+                if ~isequal(NbDtk,1)
+                    NbDtk=-1+(NbDtk+1)/(NbDti+1);
+                end
+                s.NbDtk=NbDtk;
+                %%%%%
+                if isempty(Dtk)
+                    s.Time=[s.Time;Time_val];
+                else
+                    for kblock=1:NbDtk+1
+                        Time_val_k=Time_val+(kblock-1)*Dtk;
+                        s.Time=[s.Time;Time_val_k];
+                    end
+                end
+            end
+        end
+    end
+end
+
+%% motor
+if strcmp(option,'*') || strcmp(option,'GeometryCalib')
+    uid_subtree=find(t,'/ImaDoc/TranslationMotor');
+    if length(uid_subtree)==1
+        subt=branch(t,uid_subtree);%subtree under GeometryCalib
+       [s.TranslationMotor,errormsg]=read_subtree(subt,{'Nbslice','ZStart','ZEnd'},[1 1 1],[1 1 1]);
+    end 
+end
+%%  geometric calibration
+if strcmp(option,'*') || strcmp(option,'GeometryCalib')
+    uid_GeometryCalib=find(t,'/ImaDoc/GeometryCalib');
+    if ~isempty(uid_GeometryCalib)
+        if length(uid_GeometryCalib)>1
+            errormsg=['More than one GeometryCalib in ' filecivxml];
+            return
+        end
+        subt=branch(t,uid_GeometryCalib);%subtree under GeometryCalib
+        cont=get(subt,1,'contents');
+        if ~isempty(cont)
+            uid_CalibrationType=find(subt,'/GeometryCalib/CalibrationType');
+            if isequal(length(uid_CalibrationType),1)
+                tsai.CalibrationType=get(subt,children(subt,uid_CalibrationType),'value');
+            end
+            uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit');
+            if isequal(length(uid_CoordUnit),1)
+                tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value');
+            end
+            uid_fx_fy=find(subt,'/GeometryCalib/fx_fy');
+            focal=[];%default fro old convention (Reg Wilson)
+            if isequal(length(uid_fx_fy),1)
+                tsai.fx_fy=str2num(get(subt,children(subt,uid_fx_fy),'value'));
+            else %old convention (Reg Wilson)
+                uid_focal=find(subt,'/GeometryCalib/focal');
+                uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy');
+                uid_sx=find(subt,'/GeometryCalib/sx');
+                if ~isempty(uid_focal) && ~isempty(uid_dpx_dpy) && ~isempty(uid_sx)
+                    dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value'));
+                    sx=str2num(get(subt,children(subt,uid_sx),'value'));
+                    focal=str2num(get(subt,children(subt,uid_focal),'value'));
+                    tsai.fx_fy(1)=sx*focal/dpx_dpy(1);
+                    tsai.fx_fy(2)=focal/dpx_dpy(2);
+                end
+            end
+            uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy');
+            if ~isempty(uid_Cx_Cy)
+                tsai.Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value'));
+            end
+            uid_kc=find(subt,'/GeometryCalib/kc');
+            if ~isempty(uid_kc)
+                tsai.kc=str2double(get(subt,children(subt,uid_kc),'value'));
+            else %old convention (Reg Wilson)
+                uid_kappa1=find(subt,'/GeometryCalib/kappa1');
+                if ~isempty(uid_kappa1)&& ~isempty(focal)
+                    kappa1=str2double(get(subt,children(subt,uid_kappa1),'value'));
+                    tsai.kc=-kappa1*focal*focal;
+                end
+            end
+            uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz');
+            if ~isempty(uid_Tx_Ty_Tz)
+                tsai.Tx_Ty_Tz=str2num(get(subt,children(subt,uid_Tx_Ty_Tz),'value'));
+            end
+            uid_R=find(subt,'/GeometryCalib/R');
+            if ~isempty(uid_R)
+                RR=get(subt,children(subt,uid_R),'value');
+                if length(RR)==3
+                    tsai.R=[str2num(RR{1});str2num(RR{2});str2num(RR{3})];
+                end
+            end
+            
+            %look for laser plane definitions
+            uid_Angle=find(subt,'/GeometryCalib/PlaneAngle');
+            uid_Pos=find(subt,'/GeometryCalib/SliceCoord');
+            if isempty(uid_Pos)
+                uid_Pos=find(subt,'/GeometryCalib/PlanePos');%old convention
+            end
+            if ~isempty(uid_Angle)
+                tsai.PlaneAngle=str2num(get(subt,children(subt,uid_Angle),'value'));
+            end
+            if ~isempty(uid_Pos)
+                for j=1:length(uid_Pos)
+                    tsai.SliceCoord(j,:)=str2num(get(subt,children(subt,uid_Pos(j)),'value'));
+                end
+                uid_DZ=find(subt,'/GeometryCalib/SliceDZ');
+                uid_NbSlice=find(subt,'/GeometryCalib/NbSlice');
+                if ~isempty(uid_DZ) && ~isempty(uid_NbSlice)
+                    DZ=str2double(get(subt,children(subt,uid_DZ),'value'));
+                    NbSlice=get(subt,children(subt,uid_NbSlice),'value');
+                    if isequal(NbSlice,'volume')
+                        tsai.NbSlice='volume';
+                        NbSlice=NbDtj+1;
+                    else
+                        tsai.NbSlice=str2double(NbSlice);
+                    end
+                    tsai.SliceCoord=ones(NbSlice,1)*tsai.SliceCoord+DZ*(0:NbSlice-1)'*[0 0 1];
+                end
+            end   
+            tsai.SliceAngle=get_value(subt,'/GeometryCalib/SliceAngle',[0 0 0]);
+            tsai.VolumeScan=get_value(subt,'/GeometryCalib/VolumeScan','n');
+            tsai.InterfaceCoord=get_value(subt,'/GeometryCalib/InterfaceCoord',[0 0 0]);
+            tsai.RefractionIndex=get_value(subt,'/GeometryCalib/RefractionIndex',1);
+            
+            if strcmp(option,'GeometryCalib')
+                tsai.PointCoord=get_value(subt,'/GeometryCalib/SourceCalib/PointCoord',[0 0 0 0 0]);
+            end
+            s.GeometryCalib=tsai;
+        end
+    end
+end
+
+%--------------------------------------------------
+%  read a subtree
+% INPUT: 
+% t: xltree
+% head_element: head elelemnt of the subtree
+% Data, structure containing 
+%    .Key: element name
+%    .Type: type of element ('charg', 'float'....)
+%    .NbOccur: nbre of occurrence, NaN for un specified number 
+function [s,errormsg]=read_subtree(subt,Data,NbOccur,NumTest)
+%--------------------------------------------------
+s=[];%default
+errormsg='';
+head_element=get(subt,1,'name');
+    cont=get(subt,1,'contents');
+    if ~isempty(cont)
+        for ilist=1:length(Data)
+            uid_key=find(subt,[head_element '/' Data{ilist}]);
+            if ~isequal(length(uid_key),NbOccur(ilist))
+                errormsg=['wrong number of occurence for ' Data{ilist}];
+                return
+            end
+            for ival=1:length(uid_key)
+                val=get(subt,children(subt,uid_key(ival)),'value');
+                if ~NumTest(ilist)
+                    eval(['s.' Data{ilist} '=val;']);
+                else
+                    eval(['s.' Data{ilist} '=str2double(val);'])
+                end
+            end
+        end
+    end
+
+
+%--------------------------------------------------
+%  read an xml element
+function val=get_value(t,label,default)
+%--------------------------------------------------
+val=default;
+uid=find(t,label);%find the element iud(s)
+if ~isempty(uid) %if the element named label exists
+   uid_child=children(t,uid);%find the children 
+   if ~isempty(uid_child)
+       data=get(t,uid_child,'type');%get the type of child
+       if iscell(data)% case of multiple element
+           for icell=1:numel(data)
+               val_read=str2num(get(t,uid_child(icell),'value'));
+               if ~isempty(val_read)
+                   val(icell,:)=val_read;
+               end
+           end
+%           val=val';
+       else % case of unique element value
+           val_read=str2num(get(t,uid_child,'value'));
+           if ~isempty(val_read)
+               val=val_read;
+           else
+              val=get(t,uid_child,'value');%char string data
+           end
+       end
+   end
+end
