Index: trunk/src/series/aver_stat.m
===================================================================
--- trunk/src/series/aver_stat.m	(revision 455)
+++ trunk/src/series/aver_stat.m	(revision 457)
@@ -1,7 +1,21 @@
 %'aver_stat': calculate field average, used with series.fig
+% this function can be used as a template for applying a global operation (here averaging) on a series of input fields
 %------------------------------------------------------------------------
-% function GUI_input=aver_stat(Param)
+% function ParamOut=aver_stat(Param)
 %
 %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% This function is used in four modes by the GUI series:
+%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
+%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
+%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced. 
+%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
+%
+% This function is used in four modes by the GUI series:
+%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
+%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
+%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced. 
+%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
+%
 %OUTPUT
 % GUI_input=list of options in the GUI series.fig needed for the function
@@ -32,10 +46,11 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-function GUI_input=aver_stat(Param)
+function ParamOut=aver_stat(Param)
 
 %% set the input elements needed on the GUI series when the action is selected in the menu ActionName
 if ~exist('Param','var') % case with no input parameter 
-    GUI_input={'NbViewMax';2;...% max nbre of input file series (default='' , no limitation)
+    ParamOut={'NbViewMax';2;...% max nbre of input file series (default='' , no limitation)
         'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
+        'WholeIndexRange';'off';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
         'NbSlice';'on'; ...%nbre of slices ('off' by default)
         'VelType';'two';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
@@ -50,20 +65,31 @@
 
 %%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
-%% get input parameters, file names and indices
+%% select different modes,  RUN, parameter input, BATCH
 % BATCH  case: read the xml file for batch case
-if ischar(Param) && ~isempty(find(regexp(Param,'.xml$')))
-    Param=xml2struct(Param);
-    checkrun=0;
-% RUN case: parameters introduced as the input structure Param  
-else 
+ParamOut=Param; %default output
+if ischar(Param)
+    if strcmp(Param,'input?')
+        checkrun=1;% will inly search input parameters (preparation of BATCH mode)
+    else
+        Param=xml2struct(Param);
+        checkrun=0;
+    end
+% RUN case: parameters introduced as the input structure Param
+else
     hseries=guidata(Param.hseries);%handles of the GUI series
     WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
-    checkrun=1; % indicate the RUN option is used
-end
+    checkrun=2; % indicate the RUN option is used
+end
+
+%% 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);
-
 % filecell{iview,fileindex}: cell array representing the list of file names
 %        iview: line in the table corresponding to a given file series
@@ -72,22 +98,14 @@
 % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
 % set of frame indices used for movie or multimage input 
-
-
-%% 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);
-
 % numbers of slices and file indices
+
 NbSlice=1;%default
-if isfield(Param.IndexRange,'NbSlice')
+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 consecutive fields for the j index (bursts or volume slices)
-nbfield_i=size(i1_series{1},2); %nb of consecutive fields for the i index
-nbfield=nbfield_j*nbfield_i; %total number of files or frames
+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
 nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices) 
 nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
@@ -96,5 +114,4 @@
 ImageTypeOptions={'image','multimage','mmreader','video'};
 NcTypeOptions={'netcdf','civx','civdata'};
-    
 for iview=1:nbview
     if ~exist(filecell{iview,1}','file')
@@ -117,39 +134,28 @@
 itime=0;
 NbSlice_calib={};
+XmlData=cell(1,nbview);%initiate the structures containing the data from the xml file (calibration and timing)
 for iview=1:nbview%Loop on views
-    XmlData{iview}=[];%default
-    filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
-    if exist([filebase{iview} '.xml'],'file')
-        [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); 
-        if isfield(XmlData{iview},'Time')
-            itime=itime+1;
-            timecell{itime}=XmlData{iview}.Time;
-        end
-        if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
-            NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
-            if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
-                msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
-            end
-        end 
-    elseif exist([filebase{iview} '.civ'],'file')
-        [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
+    SubDirBase=regexprep(SubDir{iview},'\..*','');%take the root part of SubDir, before the first dot '.'
+    filexml=[fullfile(RootPath{iview},SubDirBase) '.xml'];%new convention: xml at the level of the image folder
+    if ~exist(filexml,'file')
+        filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.xml']; % old convention: xml inside the image folder
+        if ~exist(filexml,'file')
+            filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.civ']; % very old convention: .civ file
+            if ~exist(filexml,'file')
+                filexml='';
+            end
+        end
+    end
+    if ~isempty(filexml)
+        [XmlData{iview},error]=imadoc2struct(filexml);
+    end
+    if isfield(XmlData{iview},'Time')
         itime=itime+1;
-        timecell{itime}=time;
-        XmlData{iview}.Time=time;
-        GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
-        GeometryCalib.Tx=0;
-        GeometryCalib.Ty=0;
-        GeometryCalib.Tz=1;
-        GeometryCalib.dpx=1;
-        GeometryCalib.dpy=1;
-        GeometryCalib.sx=1;
-        GeometryCalib.Cx=0;
-        GeometryCalib.Cy=0;
-        GeometryCalib.f=1;
-        GeometryCalib.kappa1=0;
-        GeometryCalib.CoordUnit='cm';
-        XmlData{iview}.GeometryCalib=GeometryCalib;
-        if error==1
-            msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
+        timecell{itime}=XmlData{iview}.Time;
+    end
+    if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
+        NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
+        if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
+            msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
         end
     end
@@ -182,5 +188,5 @@
     end   
 end
-if size(time,2) < i2_series{1}(end) || size(time,3) < j2_series{1}(end)% time array absent or too short in ImaDoc xml file' 
+if size(time,2) < i2_series{1}(end) ||( ~isempty(j2_series{1}) && size(time,3) < j2_series{1}(end))% time array absent or too short in ImaDoc xml file' 
     time=[];
 end
@@ -283,5 +289,4 @@
         
         %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
-        index
         for iview=1:nbview
             % reading input file(s)
@@ -369,5 +374,5 @@
         msgbox_uvmat('WARNING',[num2str(nbmissing) ' input files are missing or skipted'])
     end
-    if isempty(time) % time read from files  prevails
+    if isempty(time) % time is read from files  
         if isfield(Field,'Time')
             time_end=Field.Time(1);%last time read
@@ -377,6 +382,10 @@
             end
         end
-    else  % time from ImaDoc prevails
-        DataOut.Time=time(1,i1_series{1}(1),j1_series{1}(1));
+    else  % time from ImaDoc prevails if it exists
+        j1=1;%default
+        if ~isempty(j1_series{1})
+            j1=j1_series{1};
+        end
+        DataOut.Time=time(1,i1_series{1}(1),j1filexml);
         DataOut.Time_end=time(end,i1_series{end}(end),j1_series{end}(end));
     end
Index: trunk/src/series/check_data_files.m
===================================================================
--- trunk/src/series/check_data_files.m	(revision 455)
+++ trunk/src/series/check_data_files.m	(revision 457)
@@ -32,9 +32,9 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-function GUI_input=check_data_files(Param)
+function ParamOut=check_data_files(Param)
 
 %% set the input elements needed on the GUI series when the action is selected in the menu ActionName
 if ~exist('Param','var') % case with no input parameter 
-    GUI_input={'NbViewMax';'';...% max nbre of input file series (default='' , no limitation)
+    ParamOut={'NbViewMax';'';...% max nbre of input file series (default='' , no limitation)
         'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
         'NbSlice';'on'; ...%nbre of slices ('off' by default)
@@ -51,4 +51,5 @@
 %% get input parameters, file names and indices
 % BATCH  case: read the xml file for batch case
+ParamOut=Param; %default output
 if ischar(Param) && ~isempty(find(regexp('Param','.xml$')))
     Param=xml2struct(Param);
Index: trunk/src/series/ima_levels.m
===================================================================
--- trunk/src/series/ima_levels.m	(revision 455)
+++ trunk/src/series/ima_levels.m	(revision 457)
@@ -1,8 +1,15 @@
 %'ima_levels': rescale the image intensity to reduce strong luminosity peaks (their blinking effects often perturbs PIV))
-% this function can be used as a template for applying a transform (here 'levels.m') on each image of a series
+% this function can be used as a template for applying a transform (here 'levels.m') to each image of a series
 %------------------------------------------------------------------------
 % function GUI_input=ima_levels(Param)
 %
 %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% This function is used in four modes by the GUI series:
+%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
+%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
+%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced. 
+%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
+%
 %OUTPUT
 % GUI_input=list of options in the GUI series.fig needed for the function
@@ -50,18 +57,20 @@
 end
 
-%% get input parameters, file names and indices
+%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
+%% select different modes,  RUN, parameter input, BATCH
 % BATCH  case: read the xml file for batch case
-if ischar(Param) && ~isempty(find(regexp(Param,'.xml$')))
-    Param=xml2struct(Param);
-    checkrun=0;
-% RUN case: parameters introduced as the input structure Param  
-else 
+if ischar(Param)
+    if strcmp(Param,'input?')
+        checkrun=1;% will inly search input parameters (preparation of BATCH mode)
+    else
+        Param=xml2struct(Param);
+        checkrun=0;
+    end
+% RUN case: parameters introduced as the input structure Param
+else
     hseries=guidata(Param.hseries);%handles of the GUI series
     WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
-    checkrun=1; % indicate the RUN option is used
-end
-
-% get the set of input file names (cell array filecell), and the lists of
-[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
+    checkrun=2; % indicate the RUN option is used
+end
 
 %% root input file(s) and type
@@ -72,5 +81,15 @@
 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);
+% filecell{iview,fileindex}: cell array representing the list of file names
+%        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
+% set of frame indices used for movie or multimage input 
 % numbers of slices and file indices
+
 NbSlice=1;%default
 if isfield(Param.IndexRange,'NbSlice')
@@ -78,7 +97,7 @@
 end
 nbview=numel(i1_series);%number of input file series (lines in InputTable)
-nbfield_j=size(i1_series{1},1); %nb of consecutive fields for the j index (bursts or volume slices)
-nbfield_i=size(i1_series{1},2); %nb of consecutive fields for the i index
-nbfield=nbfield_j*nbfield_i; %total number of files or frames
+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
 nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices) 
 nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
@@ -86,4 +105,5 @@
 %determine the file type on each line from the first input file 
 ImageTypeOptions={'image','multimage','mmreader','video'};%allowed input file types(images)
+
 [FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1});
 CheckImage{1}=~isempty(find(strcmp(FileType,ImageTypeOptions)));% =1 for images
Index: trunk/src/series/merge_proj.m
===================================================================
--- trunk/src/series/merge_proj.m	(revision 455)
+++ trunk/src/series/merge_proj.m	(revision 457)
@@ -1,11 +1,293 @@
-
-
-
-
-
-%'merge_proj': project and concatene fields, used with series.fig
+%'merge_proj': project and concatene fieldsmerge_proj
+% can be used as a template for applying an operation (here projection and concateantion) on each field of an input series
 %------------------------------------------------------------------------
-% function GUI_input=merge_proj(Param)
+% function GUI_config=merge_proj(Param)
+%------------------------------------------------------------------------
+
+%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
+% This function is used in four modes by the GUI series:
+%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
+%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
+%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced. 
+%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
+%
+% This function is used in four modes by the GUI series:
+%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
+%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
+%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced. 
+%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
+%
+%OUTPUT
+% GUI_input=list of 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
+% In the absence of input (as activated when the current Action is selected
+% in series), the function ouput GUI_input 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
+%    .OutputDir: directory for data outputs, including path
+%    .Action: .ActionName: name of the current activated function
+%             .ActionPath:   path of the current activated function
+%    .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
+%                     .TransformHandle: corresponding function handle
+%    .InputFields: sub structure describing the input fields withfields
+%              .FieldName: name 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
+%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function GUI_input=merge_proj(Param)
+
+%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
+if ~exist('Param','var') % case with no input parameter 
+    GUI_input={'NbViewMax';2;...% max nbre of input file series (default='' , no limitation)
+        'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
+        'NbSlice';'on'; ...%nbre of slices ('off' by default)
+        'VelType';'two';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
+        'FieldName';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+        'FieldTransform'; 'on';...%can use a transform function
+        'ProjObject';'on';...%can use projection object(option 'off'/'on',
+        'Mask';'on';...%can use mask option   (option 'off'/'on', 'off' by default)
+        'OutputDirExt';'.proj';...%set the output dir extension
+               ''};
+        return
+end
+
+%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
+%% select different modes,  RUN, parameter input, BATCH
+% BATCH  case: read the xml file for batch case
+if ischar(Param)
+    if strcmp(Param,'input?')
+        checkrun=1;% will inly search input parameters (preparation of BATCH mode)
+    else
+        Param=xml2struct(Param);
+        checkrun=0;
+    end
+% RUN case: parameters introduced as the input structure Param
+else
+    hseries=guidata(Param.hseries);%handles of the GUI series
+    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
+    checkrun=2; % indicate the RUN option is used
+end
+
+%% 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);
+% filecell{iview,fileindex}: cell array representing the list of file names
+%        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
+% set of frame indices used for movie or multimage input 
+% numbers of slices and file indices
+
+NbSlice=1;%default
+if isfield(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
+nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices) 
+nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
+
+%determine the file type on each line from the first input file 
+ImageTypeOptions={'image','multimage','mmreader','video'};%allowed input file types(images)
+
+[FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1});
+CheckImage{1}=~isempty(find(strcmp(FileType,ImageTypeOptions)));% =1 for images
+if ~isempty(j1_series{1})
+    frame_index{1}=j1_series{1};
+else
+    frame_index{1}=i1_series{1};
+end
+
+%% calibration data and timing: read the ImaDoc files
+mode=''; %default
+timecell={};
+itime=0;
+NbSlice_calib={};
+for iview=1:nbview%Loop on views
+    XmlData{iview}=[];%default
+    filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
+    if exist([filebase{iview} '.xml'],'file')
+        [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); 
+        if isfield(XmlData{iview},'Time')
+            itime=itime+1;
+            timecell{itime}=XmlData{iview}.Time;
+        end
+        if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
+            NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
+            if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
+                msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
+            end
+        end 
+    elseif exist([filebase{iview} '.civ'],'file')
+        [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
+        itime=itime+1;
+        timecell{itime}=time;
+        XmlData{iview}.Time=time;
+        GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
+        GeometryCalib.Tx=0;
+        GeometryCalib.Ty=0;
+        GeometryCalib.Tz=1;
+        GeometryCalib.dpx=1;
+        GeometryCalib.dpy=1;
+        GeometryCalib.sx=1;
+        GeometryCalib.Cx=0;
+        GeometryCalib.Cy=0;
+        GeometryCalib.f=1;
+        GeometryCalib.kappa1=0;
+        GeometryCalib.CoordUnit='cm';
+        XmlData{iview}.GeometryCalib=GeometryCalib;
+        if error==1
+            msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
+        end
+    end
+end
+
+%% check coincidence in time for several input file series
+multitime=0;
+if isempty(timecell)
+    time=[];
+elseif length(timecell)==1
+    time=timecell{1};
+elseif length(timecell)>1
+    multitime=1;
+    for icell=1:length(timecell)
+        if ~isequal(size(timecell{icell}),size(timecell{1}))
+            msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used')
+            time=timecell{1};
+            multitime=0;
+            break
+        end
+    end
+end
+if multitime
+    for icell=1:length(timecell)
+        time(icell,:,:)=timecell{icell};
+    end
+    diff_time=max(max(diff(time)));
+    if diff_time>0
+        msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)])
+    end   
+end
+if size(time,2) < i2_series{1}(end) || size(time,3) < j2_series{1}(end)% time array absent or too short in ImaDoc xml file' 
+    time=[];
+end
+
+%% coordinate transform or other user defined transform
+transform_fct='';%default
+if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'TransformHandle')
+    transform_fct=Param.FieldTransform.TransformHandle;
+end
+%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
+ % EDIT FROM HERE
+
+%% check the validity of  input file types
+if CheckImage{1}
+    FileExtOut='.png'; % write result as .png images for image inputs
+elseif CheckNc{1}
+    FileExtOut='.nc';% write result as .nc files for netcdf inputs
+else 
+    msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
+    return
+end
+if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
+        msgbox_uvmat('ERROR','input must be two image series or two netcdf file series')
+    return
+end
+NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series
+if NbSlice~=nbfield_j
+    answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);
+    if ~strcmp(answer,'Yes')
+        return
+    end
+end
+
+%% Set field names and velocity types
+InputFields{1}=[];%default (case of images)
+if isfield(Param,'InputFields')
+    InputFields{1}=Param.InputFields;
+end
+if nbview==2
+    InputFields{2}=[];%default (case of images)
+    if isfield(Param,'InputFields')
+        InputFields{2}=Param.InputFields{1};%default
+        if isfield(Param.InputFields,'FieldName_1')
+            InputFields{2}.FieldName=Param.InputFields.FieldName_1;
+            if isfield(Param.InputFields,'VelType_1')
+                InputFields{2}.VelType=Param.InputFields.VelType_1;
+            end
+        end
+    end
+end
+
+%% Initiate output fields
+%initiate the output structure as a copy of the first input one (reproduce fields)
+[DataOut,ParamOut,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1);
+if ~isempty(errormsg)
+    msgbox_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg])
+    return
+end
+time_1=[];
+if isfield(DataOut,'Time')
+    time_1=DataOut.Time(1);
+end
+if CheckNc{iview}
+    if isempty(strcmp('Conventions',DataOut.ListGlobalAttribute))
+        DataOut.ListGlobalAttribute=['Conventions' DataOut.ListGlobalAttribute];
+    end
+    DataOut.Conventions='uvmat';
+    DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {Param.Action}];
+    ActionKey='Action';
+    while isfield(DataOut,ActionKey)
+        ActionKey=[ActionKey '_1'];
+    end
+    DataOut.(ActionKey)=Param.Action;
+    DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {ActionKey}];
+    if isfield(DataOut,'Time')
+        DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {'Time','Time_end'}];
+    end
+end
+
+%% MAIN LOOP ON SLICES
+%%%%%%%%%%%%% 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;
+    
+   %initiate result fields
+   for ivar=1:length(DataOut.ListVarName)
+       DataOut.(DataOut.ListVarName{ivar})=0; % initialise all fields to zero
+   end
+
+    %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
+    for index=index_slice
+        if checkrun
+            update_waitbar(hseries.waitbar_frame,WaitbarPos,index/(nbfield))
+            stopstate=get(hseries.RUN,'BusyAction');
+        else
+            stopstate='queue';
+        end
 %OUTPUT
 % GUI_input=list of options in the GUI series.fig needed for the function
@@ -15,40 +297,5 @@
 %  or name of the xml file containing these parameters (BATCH case)
 %
-function GUI_input=merge_proj(Param)
-
-%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
-if ~exist('Param','var')
-    GUI_input={'RootPath';'two';...%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
-        'OutputDirExt';'.proj';...
-        %'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
-
-%% input parameters: 
-% read the xml file for batch case
-if ischar(Param) && ~isempty(find(regexp('Param','.xml$')))
-    Param=xml2struct(Param);
-else % RUN case : parameters introduced as the input structure Param
-    hseries=guidata(Param.hseries);%handles of the GUI series
-    WaitbarPos=get(hseries.waitbar_frame,'Position');% info for the waitbar
-end
-[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
-
-%% coordinate transform or other user defined transform
-transform_fct='';%default
-if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'fct_handle')
-    transform_fct=Param.FieldTransform.fct_handle;
-end
+
 
 %% projection object
Index: trunk/src/series/relabel_i_j.m
===================================================================
--- trunk/src/series/relabel_i_j.m	(revision 455)
+++ trunk/src/series/relabel_i_j.m	(revision 457)
@@ -1,43 +1,208 @@
 %'relabel_i_j': relabel an image series with two indices, and correct errors from the RDvision transfer program
-%----------------------------------------------------------------------
-function GUI_input=relabel_i_j(num_i1,num_i2,num_j1,num_j2,Series)
-%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
-
-GUI_input={};
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%enable waitbar
-hGUI=findobj(allchild(0),'name','series');
-hseries=guidata(hGUI);%handles of the GUI series
-WaitbarPos=get(hseries.waitbar_frame,'Position');
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%% PARAMETERS (for RDvision system)
+%------------------------------------------------------------------------
+% function GUI_config=relabel_i_j(Param)
+%------------------------------------------------------------------------
+
+%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% This function is used in four modes by the GUI series:
+%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
+%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
+%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced. 
+%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
+%
+% This function is used in four modes by the GUI series:
+%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
+%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
+%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced. 
+%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
+%
+%OUTPUT
+% GUI_input=list of 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
+% In the absence of input (as activated when the current Action is selected
+% in series), the function ouput GUI_input 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
+%    .OutputDir: directory for data outputs, including path
+%    .Action: .ActionName: name of the current activated function
+%             .ActionPath:   path of the current activated function
+%    .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
+%                     .TransformHandle: corresponding function handle
+%    .InputFields: sub structure describing the input fields withfields
+%              .FieldName: name 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
+%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function GUI_config=relabel_i_j(Param)
+
+%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
+if ~exist('Param','var') % case with no input parameter 
+    GUI_config={'NbViewMax';1;...% max nbre of input file series (default='' , no limitation)
+        'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
+        'WholeIndexRange';'on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
+        'NbSlice';'off'; ...%nbre of slices ('off' by default)
+        'VelType';'off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
+        'FieldName';'off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+        'FieldTransform'; 'off';...%can use a transform function
+        'ProjObject';'off';...%can use projection object(option 'off'/'on',
+        'Mask';'off';...%can use mask option   (option 'off'/'on', 'off' by default)
+        'OutputDirExt';'';...%set the output dir extension
+               ''};
+        return
+end
+
+%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
+%% select different modes,  RUN, parameter input, BATCH
+% BATCH  case: read the xml file for batch case
+GUI_config=Param;%reproduce the input parameters, no interactive input
+if ischar(Param)
+    if strcmp(Param,'input?')
+        checkrun=1;% will inly search input parameters (preparation of BATCH mode)
+    else
+        Param=xml2struct(Param);
+        checkrun=0;
+    end
+% RUN case: parameters introduced as the input structure Param
+else
+    hseries=guidata(Param.hseries);%handles of the GUI series
+    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
+    checkrun=2; % indicate the RUN option is used
+end
+
+%% 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);
+% filecell{iview,fileindex}: cell array representing the list of file names
+%        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
+% set of frame indices used for movie or multimage input 
+% numbers of slices and 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
+nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices) 
+nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
+
+%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')
+        msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])
+        return
+    end
+    [FileType{iview},FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1});
+    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
+mode=''; %default
+timecell={};
+itime=0;
+NbSlice_calib={};
+XmlData=cell(1,nbview);%initiate the structures containing the data from the xml file (calibration and timing)
+for iview=1:nbview%Loop on views
+    SubDirBase=regexprep(SubDir{iview},'\..*','');%take the root part of SubDir, before the first dot '.'
+    filexml=[fullfile(RootPath{iview},SubDirBase) '.xml'];%new convention: xml at the level of the image folder
+    if ~exist(filexml,'file')
+        filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.xml']; % old convention: xml inside the image folder
+        if ~exist(filexml,'file')
+            filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.civ']; % very old convention: .civ file
+            if ~exist(filexml,'file')
+                filexml='';
+            end
+        end
+    end
+    if ~isempty(filexml)
+        [XmlData{iview},error]=imadoc2struct_special(filexml);
+    end
+    if isfield(XmlData{iview},'Time')
+        itime=itime+1;
+        timecell{itime}=XmlData{iview}.Time;
+    end
+    if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
+        NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
+        if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
+            msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
+        end
+    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
+
+%% check the validity of  input file types
+if CheckImage{1}
+    FileExtOut='.png'; % write result as .png images for image inputs
+elseif CheckNc{1}
+    FileExtOut='.nc';% write result as .nc files for netcdf inputs
+else 
+    msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
+    return
+end
+if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
+        msgbox_uvmat('ERROR','input must be two image series or two netcdf file series')
+    return
+end
+NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series
+if NbSlice~=nbfield_j
+    answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);
+    if ~strcmp(answer,'Yes')
+        return
+    end
+end
+
+%% 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
-%errorfactor=1 %correct a factor of 2 in NbDk+1
-
-%% read imadoc
-RootPath=get(hseries.RootPath,'String');
-RootFile=get(hseries.RootFile,'String');
-if ~iscell(RootFile)
-    msgbox_uvmat('ERROR','please enter an input image series from RDVision system')%error message for xml file reading
-    return
-end
-basename=fullfile(RootPath{1},RootFile{1}); 
-[XmlData,warntext]=imadoc2struct([basename '.xml']);% read the xml file appended to the present function (containing bug corrections)
-if ~isempty(warntext)
-    msgbox_uvmat('ERROR',warntext)%error message for xml file reading
-end
-nbfield1=size(XmlData.Time,1);
-nbfield2=size(XmlData.Time,2);
-set(hseries.first_i,'String',num2str(first_label))% display the first image in the process
-set(hseries.last_i,'String',num2str(nbfield1*nbfield2-1+first_label))% display the last image in the process
-set(hseries.nb_field,'String',{num2str(nbfield1*nbfield2-1+first_label)})% display the total nbre of images
-SeriesData=get(hGUI,'UserData');
-if ~strcmp(SeriesData.NomType,'_000001')
+if ~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 and correct the xml file');%error message for directory creation
+    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
@@ -45,111 +210,144 @@
 end
 
-%% stop program ther when it is selected in the menu (no run action)
-if ~exist('num_i1','var')
-    return
-end
-if nbfield2>=2
-answer=msgbox_uvmat('',[num2str(nbfield1) ' bursts containing ' num2str(nbfield2) ' images each']);%error message for directory creation
-nomtype='_i_j';
-else
-    answer=msgbox_uvmat('',['image series with ' num2str(nbfield1) ' images']);%error message for directory creation
-    nomtype='_i';
-end
-if ~strcmp(answer,'Yes')
-    return
-end
+%% read imadoc
+% RootPath=get(hseries.RootPath,'String');
+% RootFile=get(hseries.RootFile,'String');
+% if ~iscell(RootFile)
+%     msgbox_uvmat('ERROR','please enter an input image series from RDVision system')%error message for xml file reading
+%     return
+% end
+% basename=fullfile(RootPath{1},RootFile{1}); 
+% [XmlData,warntext]=imadoc2struct_special([basename '.xml']);% read the xml file appended to the present function (containing bug corrections)
+% if ~isempty(warntext)
+%     msgbox_uvmat('ERROR',warntext)%error message for xml file reading
+% end
+% nbfield1=size(XmlData.Time,1);
+% nbfield2=size(XmlData.Time,2);
+% set(hseries.first_i,'String',num2str(first_label))% display the first image in the process
+% set(hseries.last_i,'String',num2str(nbfield1*nbfield2-1+first_label))% display the last image in the process
+% set(hseries.nb_field,'String',{num2str(nbfield1*nbfield2-1+first_label)})% display the total nbre of images
+% SeriesData=get(hGUI,'UserData');
+
+
+%% stop program there when it is selected in the menu (no run action)
+% if ~exist('num_i1','var')
+%     return
+% end
+% if nbfield2>=2
+% answer=msgbox_uvmat('',[num2str(nbfield1) ' bursts containing ' num2str(nbfield2) ' images each']);%error message for directory creation
+% nomtype='_i_j';
+% else
+%     answer=msgbox_uvmat('',['image series with ' num2str(nbfield1) ' images']);%error message for directory creation
+%     nomtype='_i';
+% end
+% if ~strcmp(answer,'Yes')
+%     return
+% end
 
 %% copy and adapt the xml file
-if exist([basename '.xml'],'file')
-    try
-        copyfile([basename '.xml'],[basename '.xml~']);% backup the xml file
-    catch ME
-        msgbox_uvmat('ERROR',ME.message);
-        return
-    end
-    t=xmltree([basename '.xml']);
-    
-    %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');
-    ImageName=name_generator(basename,1,1,'.png','_i_j');
-    [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
+if ~isempty(XmlData{1})
+
+%     if exist([basename '.xml'],'file')
+%         try
+%             copyfile([basename '.xml'],[basename '.xml~']);% backup the xml file
+%         catch ME
+%             msgbox_uvmat('ERROR',ME.message);
+%             return
+%         end
+%         filexml=[filebase{1} '.xml']
+        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),[],j);
+%         ImageName=name_generator(basename,1,1,'.png','_i_j');
+        [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);
+        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
+end
+
+%% main loop on images
+%j1=[];%default
+nbfield2=size(XmlData{1}.Time,2);
+for ifile=1:nbfield
+    if checkrun
+        update_waitbar(hseries.waitbar_frame,WaitbarPos,ifile/nbfield)
+        stopstate=get(hseries.RUN,'BusyAction');
     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 strcmp(nomtype,'_i') && 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_value=children(t,uid_NbDti);
-%         if ~isempty(uid_value)
-%             t=set(t,uid_value(1),'value',num2str(XmlData.NbDti));
-%         end
-        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);
-    end
-    %%%
-    
-    save(t,[basename '.xml'])
-end
-
-%% main loop
-
-for ifile=1:nbfield1*nbfield2
-    update_waitbar(hseries.waitbar,WaitbarPos,ifile/(nbfield1*nbfield2))
-    filename=name_generator(basename,ifile-1,1,Series.FileExt,Series.NomType);
-    num_j=mod(ifile-1+first_label,nbfield2)+1;
-    num_i=floor((ifile-1+first_label)/nbfield2)+1;
-    filename_new=name_generator(basename,num_i,num_j,'.png',nomtype);
-    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);
+        stopstate='queue';
+    end
+    if isequal(stopstate,'queue') % enable STOP command
+        filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile));
+        j1=mod(ifile-1+first_label,nbfield2)+1;
+        i1=floor((ifile-1+first_label)/nbfield2)+1;
+        %         filename_new=name_generator(basename,num_i,num_j,'.png',nomtype);
+        filename_new=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},'_1_1',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
-    catch ME
-        msgbox_uvmat('ERROR',ME.message);
-        return
-    end
-end
-
-
-%'imadoc2struct': reads the xml file for image documentation 
+    end
+end
+
+%'imadoc2struct_special': reads the xml file for image documentation 
 %------------------------------------------------------------------------
-% function [s,errormsg]=imadoc2struct(ImaDoc,option) 
+% function [s,errormsg]=imadoc2struct_special(ImaDoc,option) 
 %
 % OUTPUT:
@@ -165,5 +363,5 @@
 % option: ='GeometryCalib': read  the data of GeometryCalib, including source point coordinates
 
-function [s,errormsg]=imadoc2struct(ImaDoc,option) 
+function [s,errormsg]=imadoc2struct_special(ImaDoc,option) 
 
 %% default input and output
@@ -247,5 +445,5 @@
                      s.Dti=Dti;
                 else
-                     NbDtj=NbDtj/numel(Dtj);%bursts
+                    % NbDtj=NbDtj/numel(Dtj);%bursts
                     s.NbDtj=NbDtj;
                 end
Index: trunk/src/series/sub_background.m
===================================================================
--- trunk/src/series/sub_background.m	(revision 455)
+++ trunk/src/series/sub_background.m	(revision 457)
@@ -1,3 +1,4 @@
-%'sub_background': substract background to an image series, used with series.fig
+%'sub_background': substract a sliding background to an image series
+% This is an example of action on a series of input images
 %------------------------------------------------------------------------
 % Method: 
@@ -14,7 +15,14 @@
     % Else nbfield2=nbfield_j =nbre of images in a burst (j index)
     
-% function GUI_series_config=sub_background(Param)
+% function GUI_config=sub_background(Param)
 %
 %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% This function is used in four modes by the GUI series:
+%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
+%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
+%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced. 
+%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
+%
 %OUTPUT
 % GUI_series_config=list of options in the GUI series.fig needed for the function
@@ -52,4 +60,5 @@
     GUI_config={'NbViewMax';1;...% max nbre of input file series (default='' , no limitation)
         'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
+        'WholeIndexRange';'on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
         'NbSlice';'on'; ...%nbre of slices ('off' by default)
         'VelType';'off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
@@ -64,15 +73,27 @@
 
 %%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
-%% get input parameters, file names and indices
+%% select different modes,  RUN, parameter input, BATCH
 % BATCH  case: read the xml file for batch case
-if ischar(Param) && ~isempty(find(regexp(Param,'.xml$'))) %batch mode
+if ischar(Param)
+    if strcmp(Param,'input?')
+        checkrun=1;% will inly search input parameters (preparation of BATCH mode)
+    else
         Param=xml2struct(Param);
         checkrun=0;
-    % RUN case: parameters introduced as the input structure Param
+    end
+% RUN case: parameters introduced as the input structure Param
 else
     hseries=guidata(Param.hseries);%handles of the GUI series
     WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
-    checkrun=1; % indicate the RUN option is used
-end
+    checkrun=2; % indicate the RUN option is used
+end
+
+%% 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
@@ -84,16 +105,8 @@
 % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
 % set of frame indices used for movie or multimage input 
-
-
-%% 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);
-
 % numbers of slices and file indices
+
 NbSlice=1;%default
-if isfield(Param.IndexRange,'NbSlice')
+if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
     NbSlice=Param.IndexRange.NbSlice;
 end
@@ -162,6 +175,6 @@
 end
 
-%% set processing parameters
-if ~isfield(Param,'Specific')
+%% input of specific parameters
+if checkrun %get specific parameters interactively
     prompt = {'volume scan mode (Yes/No)';'Number of images for the sliding background (MUST FIT IN COMPUTER MEMORY)';...
         'the luminosity rank chosen to define the background (0.1=for dense particle seeding, 0.5 (median) for sparse particles'};
@@ -200,9 +213,8 @@
     answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m after sub_background');
     GUI_config.CheckLevelTransform=strcmp(answer,'Yes');
-    
-%     % return to BATCH mode
-%     if checkrun==-1
-        return %transfer to BATCH mode
-%     end
+    if checkrun==2
+         return 
+    end
+    %%%%%%%%%%%%%%%%%%%%%%  STOP HERE FOR PAMETER INPUT MODE  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 else
     GUI_config=Param.Specific;
Index: trunk/src/series/time_series.m
===================================================================
--- trunk/src/series/time_series.m	(revision 455)
+++ trunk/src/series/time_series.m	(revision 457)
@@ -1,5 +1,20 @@
 %'time_series': extract a time series, used with series.fig
+% this function can be used as a template for applying a global operation on a series of input fields
 %------------------------------------------------------------------------
 % function GUI_input=time_series(Param)
+%
+%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% This function is used in four modes by the GUI series:
+%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
+%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
+%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced. 
+%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
+%
+% This function is used in four modes by the GUI series:
+%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
+%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
+%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced. 
+%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
 %
 %OUTPUT
@@ -7,15 +22,33 @@
 %
 %INPUT:
-%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
-%i2_series: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
-%num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
-%num_j2: 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
+% 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
+% In the absence of input (as activated when the current Action is selected
+% in series), the function ouput GUI_input set the activation of the needed GUI elements
 %
-function GUI_input=time_series(Param) 
+% 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
+%    .OutputDir: directory for data outputs, including path
+%    .Action: .ActionName: name of the current activated function
+%             .ActionPath:   path of the current activated function
+%    .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
+%                     .TransformHandle: corresponding function handle
+%    .InputFields: sub structure describing the input fields withfields
+%              .FieldName: name 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
+%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+function ParamOut=time_series(Param) 
 
 %% requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
 if ~exist('Param','var')
-    GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
+    ParamOut={'RootPath';'two';...%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)
@@ -34,90 +67,179 @@
 end
 
-%% input parameters
-% read the xml file for batch case
-if ischar(Param) && ~isempty(find(regexp('Param','.xml$')))
-    Param=xml2struct(Param);
-    checkrun=0;
-else %  RUN case: parameters introduced as the input structure Param
+%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
+%% select different modes,  RUN, parameter input, BATCH
+% BATCH  case: read the xml file for batch case
+ParamOut=Param; %default output
+if ischar(Param)
+    if strcmp(Param,'input?')
+        checkrun=1;% will inly search input parameters (preparation of BATCH mode)
+    else
+        Param=xml2struct(Param);
+        checkrun=0;
+    end
+% RUN case: parameters introduced as the input structure Param
+else
     hseries=guidata(Param.hseries);%handles of the GUI series
-    WaitbarPos=get(hseries.waitbar_frame,'Position');
-    checkrun=1;
-end
+    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
+    checkrun=2; % indicate the RUN option is used
+end
+
+%% 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);
+% filecell{iview,fileindex}: cell array representing the list of file names
+%        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
+% set of frame indices used for movie or multimage input 
+% numbers of slices and 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
+nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices) 
+nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
+
+%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')
+        msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])
+        return
+    end
+    [FileType{iview},FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1});
+    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
+mode=''; %default
+timecell={};
+itime=0;
+NbSlice_calib={};
+XmlData=cell(1,nbview);%initiate the structures containing the data from the xml file (calibration and timing)
+for iview=1:nbview%Loop on views
+    SubDirBase=regexprep(SubDir{iview},'\..*','');%take the root part of SubDir, before the first dot '.'
+    filexml=[fullfile(RootPath{iview},SubDirBase) '.xml'];%new convention: xml at the level of the image folder
+    if ~exist(filexml,'file')
+        filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.xml']; % old convention: xml inside the image folder
+        if ~exist(filexml,'file')
+            filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.civ']; % very old convention: .civ file
+            if ~exist(filexml,'file')
+                filexml='';
+            end
+        end
+    end
+    if ~isempty(filexml)
+        [XmlData{iview},error]=imadoc2struct(filexml);
+    end
+    if isfield(XmlData{iview},'Time')
+        itime=itime+1;
+        timecell{itime}=XmlData{iview}.Time;
+    end
+    if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
+        NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
+        if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
+            msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
+        end
+    end
+end
+
+%% check coincidence in time for several input file series
+multitime=0;
+if isempty(timecell)
+    time=[];
+elseif length(timecell)==1
+    time=timecell{1};
+elseif length(timecell)>1
+    multitime=1;
+    for icell=1:length(timecell)
+        if ~isequal(size(timecell{icell}),size(timecell{1}))
+            msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used')
+            time=timecell{1};
+            multitime=0;
+            break
+        end
+    end
+end
+if multitime
+    for icell=1:length(timecell)
+        time(icell,:,:)=timecell{icell};
+    end
+    diff_time=max(max(diff(time)));
+    if diff_time>0
+        msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)])
+    end   
+end
+if size(time,2) < i2_series{1}(end) ||( ~isempty(j2_series{1}) && size(time,3) < j2_series{1}(end))% time array absent or too short in ImaDoc xml file' 
+    time=[];
+end
 
 %% coordinate transform or other user defined transform
 transform_fct='';%default
-if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'fct_handle')
-    transform_fct=Param.FieldTransform.fct_handle;
-end
-
-%% projection object
-test_object=get(hseries.GetObject,'Value');
-if test_object
-    hset_object=findobj(allchild(0),'tag','set_object');
-    ProjObject=read_GUI(hset_object);
-    answeryes=msgbox_uvmat('INPUT_Y-N',['field series projected on ' ProjObject.Type]);
-    if ~isequal(answeryes,'Yes')
+if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'TransformHandle')
+    transform_fct=Param.FieldTransform.TransformHandle;
+end
+%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
+ % EDIT FROM HERE
+
+%% check the validity of  input file types
+if CheckImage{1}
+    FileExtOut='.png'; % write result as .png images for image inputs
+elseif CheckNc{1}
+    FileExtOut='.nc';% write result as .nc files for netcdf inputs
+else 
+    msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
+    return
+end
+if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
+        msgbox_uvmat('ERROR','input must be two image series or two netcdf file series')
+    return
+end
+NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series
+if NbSlice~=nbfield_j
+    answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);
+    if ~strcmp(answer,'Yes')
         return
     end
-else
-    msgbox_uvmat('ERROR','a projection object is needed');
-    return
-end
-
-%% features of the input fields 
-RootPath=Param.InputTable(:,1);
-RootFile=Param.InputTable(:,3);
-% SubDir=Param.InputTable(:,2);
-NomType=Param.InputTable(:,4);
-FileExt=Param.InputTable(:,5);
-% ext=FileExt{1};
-% form=imformats(ext(2:end));%test valid Matlab image formats
-nbfield=size(i1_series{1},1)*size(i1_series{1},2); %number of fields in the time series
-
-%% determine image type
-hhh=which('mmreader');
-testnetcdf=0;
-nbview=length(RootPath);%Number of input series: this function  accepts only one or two input file series (sub_field is used in the latter case)
-for iview=1:nbview
-    if isequal(FileExt{iview},'.nc')||isequal(FileExt{iview},'.cdf')
-        FileType{iview}='netcdf';
-        testnetcdf=1;
-    elseif isequal(lower(FileExt{iview}),'.avi')
-        if ~isequal(hhh,'')%&& mmreader.isPlatformSupported()
-            MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
-            FileType{iview}='movie';
-        else
-            FileType{iview}='avi';
-        end
-    elseif isequal(lower(FileExt{iview}),'.vol')
-        FileType{iview}='vol';
-    else 
-       form=imformats(FileExt{iview}(2:end));
-       if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
-           if isequal(NomType{iview},'*');
-               FileType{iview}='multimage';
-           else
-               FileType{iview}='image';
-           end
-       end
-    end
-end
-filebase{1}=fullfile(RootPath{1},RootFile{1});
-
-%% number of slices
-NbSlice=Param.NbSlice;
-
-%% Field and velocity type (the same for the two views)
-FieldName={''};
-
-if isfield(Param,'InputFields')&&isfield(Param.InputFields,'FieldMenu')  
-    FieldName=Param.InputFields.FieldMenu;%the same set of fields for all views
-    VelType{1}=Param.InputFields.VelTypeMenu;
-end
-if isempty(FieldName) && testnetcdf
-    msgbox_uvmat('ERROR','A field must be defined as input')
-    return
-end
+end
+
+%% Set field names and velocity types
+InputFields{1}=[];%default (case of images)
+if isfield(Param,'InputFields')
+    InputFields{1}=Param.InputFields;
+end
+if nbview==2
+    InputFields{2}=[];%default (case of images)
+    if isfield(Param,'InputFields')
+        InputFields{2}=Param.InputFields{1};%default
+        if isfield(Param.InputFields,'FieldName_1')
+            InputFields{2}.FieldName=Param.InputFields.FieldName_1;
+            if isfield(Param.InputFields,'VelType_1')
+                InputFields{2}.VelType=Param.InputFields.VelType_1;
+            end
+        end
+    end
+end
+%%% TO UPDATE
 if isequal(FieldName,'get_field...')
     hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
@@ -140,4 +262,36 @@
     end
 end
+%%%%%%%
+
+%% Initiate output fields
+%initiate the output structure as a copy of the first input one (reproduce fields)
+[DataOut,ParamOut,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1);
+if ~isempty(errormsg)
+    msgbox_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg])
+    return
+end
+time_1=[];
+if isfield(DataOut,'Time')
+    time_1=DataOut.Time(1);
+end
+if CheckNc{iview}
+    if isempty(strcmp('Conventions',DataOut.ListGlobalAttribute))
+        DataOut.ListGlobalAttribute=['Conventions' DataOut.ListGlobalAttribute];
+    end
+    DataOut.Conventions='uvmat';
+    DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {Param.Action}];
+    ActionKey='Action';
+    while isfield(DataOut,ActionKey)
+        ActionKey=[ActionKey '_1'];
+    end
+    DataOut.(ActionKey)=Param.Action;
+    DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {ActionKey}];
+    if isfield(DataOut,'Time')
+        DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {'Time','Time_end'}];
+    end
+end
+
+
+
 
 %% detect whether the two files are 'images' or 'netcdf'
@@ -155,117 +309,4 @@
 %     VelType{2}=VelType_str{VelType_val};
 % end
-
-%% Calibration data and timing: read the ImaDoc files
-% mode=''; %default
-timecell={};
-XmlData={};
-itime=0;
-NbSlice_calib={};
-for iview=1:nbview%Loop on views
-    XmlData{iview}=[];%default
-    filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
-    if exist([filebase{iview} '.xml'],'file')
-        [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); 
-        if isfield(XmlData{iview},'Time')
-            itime=itime+1;
-            timecell{itime}=XmlData{iview}.Time;
-        end
-        if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
-            NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
-            if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
-                msgbox_uvmat('WARNING','inconsistent number of Z indices for the field series');
-            end
-        end 
-    elseif exist([filebase{iview} '.civ'],'file')%old convention .civ text file
-        [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
-        itime=itime+1;
-        timecell{itime}=time;
-        XmlData{iview}.Time=time;
-        GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
-        GeometryCalib.Tx=0;
-        GeometryCalib.Ty=0;
-        GeometryCalib.Tz=1;
-        GeometryCalib.dpx=1;
-        GeometryCalib.dpy=1;
-        GeometryCalib.sx=1;
-        GeometryCalib.Cx=0;
-        GeometryCalib.Cy=0;
-        GeometryCalib.f=1;
-        GeometryCalib.kappa1=0;
-        GeometryCalib.CoordUnit='cm';
-        XmlData{iview}.GeometryCalib=GeometryCalib;
-        if error==1
-            msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
-        end
-    end
-end
-time=[];%default
-if ~isempty(timecell)
-    if numel(timecell{1})<nbfield
-       msgbox_uvmat('WARNING','time array from ImaDoc to short')
-    else
-        time=timecell{1}; %time defined from ImaDoc file (image series)
-    end
-end
-
-%% check coincidence in time
-if length(timecell)>1
-    for icell=2:length(timecell)
-        if isequal(size(timecell{icell}),size(time))
-            diff_time=max(abs(timecell{icell}-time));
-            if diff_time>0
-                msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)])
-                break
-            end 
-        else
-            msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used')
-            break
-        end
-    end
-end
-if ~isempty(time)
-    display(['time is read from ' filebase{iview} '.xml'])
-end
-
-%%  Root name of output files (TO GENERALISE FOR TWO INPUT SERIES)
-subdir_result='time_series';
-pathdir=fullfile(RootPath{1},subdir_result);
-while exist(pathdir,'dir')
-    subdir_result=[subdir_result '.0'];
-    pathdir=fullfile(RootPath{1},subdir_result);
-end
-[m1,m2,m3]=mkdir(pathdir);
-if ~isequal(m2,'')
-     msgbox_uvmat('CONFIRMATION',m2);%error message for directory creation
-end
-[xx,msg2] = fileattrib(pathdir,'+w','g'); %yield writing access (+w) to user group (g)
-if ~strcmp(msg2,'')
-    msgbox_uvmat('ERROR',['pb of permission for ' pathdir ': ' msg2])%error message for directory creation
-    return
-end
-filebase_out=filebase{1}; 
- i21=i1_series{end}(end);
- if ~isempty(i2_series{end})
-     i21=i2_series{end}(end)-i1_series{1}(1);
- end
- j21=1;
- if ~isempty(j1_series{1})
-     j21=j1_series{end}(end);
-      if ~isempty(j2_series{end})
-          j21=j2_series{end}(end)-j21;
-      end
- end
-NomTypeOut=nomtype2pair(NomType{1},i21,j21);
-
-
-%% velocity type
-VelType_str=get(hseries.VelTypeMenu,'String');
-VelType_val=get(hseries.VelTypeMenu,'Value');
-VelType{1}=VelType_str{VelType_val};
-if nbview==2
-    VelType_str=get(hseries.VelTypeMenu_1,'String');
-    VelType_val=get(hseries.VelTypeMenu_1,'Value');
-    VelType{2}=VelType_str{VelType_val};
-end
 
 %% LOOP ON SLICES
