Index: /trunk/src/browse_data.m
===================================================================
--- /trunk/src/browse_data.m	(revision 1058)
+++ /trunk/src/browse_data.m	(revision 1059)
@@ -24,5 +24,5 @@
 function varargout = browse_data(varargin)
 
-% Last Modified by GUIDE v2.5 24-Jan-2015 16:55:04
+% Last Modified by GUIDE v2.5 08-Sep-2018 19:03:40
 
 % Begin initialization code - DO NOT EDIT
@@ -47,13 +47,14 @@
 %------------------------------------------------------------------------
 % --- Executes just before browse_data is made visible.
-function browse_data_OpeningFcn(hObject, eventdata, handles, DataSeries,EnableMirror,MultiDevices)
+function browse_data_OpeningFcn(hObject, eventdata, handles, InputDir,EnableMirror,MultiDevices)
 %------------------------------------------------------------------------
 
 %% Choose default command line output for browse_data
-handles.output = 'Cancel';
+handles.output =hObject;% 'Cancel';
 
 %% Update handles structure
 guidata(hObject, handles);
 set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display)
+set(hObject,'DeleteFcn',{@closefcn})%
 
 %% Determine the position of the dialog - centered on the screen
@@ -87,11 +88,13 @@
 
 %% initialize the GUI
-if isempty(regexp(DataSeries,'^http:'))&& ~(exist('DataSeries','var') && ischar(DataSeries) && exist(DataSeries,'dir'))
-    DataSeries=pwd;% current dir is the starting data series by default
-end
-[Experiment,DataSeries,Ext]=fileparts(DataSeries);
-DataSeries=[DataSeries Ext];
-[Campaign,Experiment,Ext]=fileparts(Experiment);
-Experiment=[Experiment Ext];
+if isempty(regexp(InputDir,'^http:'))&& ~(exist('InputDir','var') && ischar(InputDir) && exist(InputDir,'dir'))
+    InputDir=pwd;% current dir is the starting data series by default
+end
+% [Experiment,DataSeries,Ext]=fileparts(DataSeries);
+% DataSeries=[DataSeries Ext];
+% [Campaign,Experiment,Ext]=fileparts(Experiment);
+% Experiment=[Experiment Ext];
+[ExpWithPath,DataSeries]=fileparts(InputDir);
+[Campaign,Experiment,Ext]=fileparts(ExpWithPath);
 [tild,CampaignName]=fileparts(Campaign);
 RootXml=fullfile(Campaign,[CampaignName '.xml']);
@@ -111,17 +114,19 @@
     set(handles.CreateMirror,'String','create_mirror')
 end
-errormsg=scan_campaign(handles,Campaign,Experiment,DataSeries);
+errormsg=scan_campaign(handles,Campaign,Experiment,ExpWithPath);
 if ~isempty(errormsg)
     msgbox_uvmat('ERROR',errormsg)
     return
 end
-set(handles.OK,'Visible','on')
-set(handles.Cancel,'Visible','on')
-
-set(handles.browse_data,'WindowStyle','modal')% Make the GUI modal
+% set(handles.OK,'Visible','on')
+% set(handles.Cancel,'Visible','on')
+
+%set(handles.browse_data,'WindowStyle','modal')% Make the GUI
+%modal%%%%%%%%%%%%%%%%%%%%%%%
 set(hObject,'Visible','on')
 drawnow
-% UIWAIT makes GUI wait for user response (see UIRESUME)
-uiwait(handles.browse_data);
+% UIWAIT makes GUI wait for user response (see UIRESUME)%%%%%%%%%%%%%%%%TO
+% CHECK
+%uiwait(handles.browse_data);
 
 
@@ -133,5 +138,5 @@
 % Get default command line output from handles structure
 varargout{1} = handles.output;
-delete(handles.browse_data)
+%%%%%%%%%%%%%%%%%%delete(handles.browse_data)
 
 %------------------------------------------------------------------------
@@ -213,5 +218,5 @@
     ListStruct=dir_uvmat(Campaign); %list files and dirs
     if numel(ListStruct)>1000% A campaign folder must contain maily a list of 'experiment' sub-folders
-        errormsg=[Campaign ' contains too many items (>1000) to be a Campaign folder'];
+        errormsg=[Campaign ' contains too many items (>1000) to be a Project folder'];
         return
     end
@@ -224,7 +229,7 @@
     ListFiles=sort((ListFiles(check_keep))');
     index=find(strcmp(['+/' Experiment],ListFiles));
-    if isempty(index), index=0; end
-    set(handles.ListExperiments,'String',[{'*'};ListFiles])
-    set(handles.ListExperiments,'Value',index+1)% initialise the menu selection with the folder defined by the input
+    if isempty(index), index=1; end
+    set(handles.ListExperiments,'String',ListFiles)
+    set(handles.ListExperiments,'Value',index)% initialise the menu selection with the folder defined by the input
     ListExperiments_Callback([],[], handles)
     ListDevices=get(handles.ListDevices,'String');
@@ -252,10 +257,10 @@
 ListExperiments=get(handles.ListExperiments,'String');
 list_val=get(handles.ListExperiments,'Value');
-if isequal(list_val(1),1)
-    ListExperiments=ListExperiments(2:end); %choose all experiments if the first line '*' is selected
-    set(handles.ListExperiments,'Value',1)
-else
+% if isequal(list_val(1),1)
+%     ListExperiments=ListExperiments(2:end); %choose all experiments if the first line '*' is selected
+%     set(handles.ListExperiments,'Value',1)
+% else
     ListExperiments=ListExperiments(list_val);%choose selected experiments
-end
+% end
 list_dataseries(handles,ListExperiments,MirrorPath)
 
@@ -283,8 +288,8 @@
                 else %update the list of dataSeries
                     [tild,msg]=fileattrib(mirror);
-                    msg.Name=regexprep(msg.Name,'^/.','/');%remove the dot in /. at the beginning of the name
-                    if ~strcmp(msg.Name,mirror)% if it is a link
-                        ListFiles{ilist}=['~' ListFiles{ilist}];%mark link by '@' in the list
-                    end
+%                     msg.Name=regexprep(msg.Name,'^/.','/');%remove the dot in /. at the beginning of the name
+%                     if ~strcmp(msg.Name,mirror)% if it is a link
+%                         ListFiles{ilist}=['~' ListFiles{ilist}];%mark link by '@' in the list
+%                     end
                     if check_dir(ilist)
                         ListFiles{ilist}=['+/' ListFiles{ilist}];%mark dir by '+' in the list
@@ -298,4 +303,5 @@
     end
 end
+set(handles.ListDevices,'Value',1)
 set(handles.ListDevices,'String',sort(ListDevices))
 
@@ -438,170 +444,5 @@
 save(t,outputfile)
 
-% %------------------------------------------------------------------------
-% % --- Executes on button press in CampaignDoc.
-% function edit_xml_Callback(hObject, eventdata, handles)
-% %------------------------------------------------------------------------
-% CurrentPath=get(handles.SourceDir,'String');
-% %[CurrentPath,Name,Ext]=fileparts(CurrentDir);
-% ListExperiments=get(handles.ListExperiments,'String');
-% Value=get(handles.ListExperiments,'Value');
-% if ~isequal(Value,1)
-%     ListExperiments=ListExperiments(Value);
-% end
-% ListDevices=get(handles.ListDevices,'String');
-% Value=get(handles.ListDevices,'Value');
-% if ~isequal(Value,1)
-%     ListDevices=ListDevices(Value);
-% end
-% ListRecords=get(handles.ListRecords,'String');
-% Value=get(handles.ListRecords,'Value');
-% if ~isequal(Value,1)
-%     ListRecords=ListRecords(Value);
-% end
-% [ListDevices,ListRecords,ListXml,List]=dir_scan(CurrentPath,ListExperiments,ListDevices,ListRecords);
-% ListXml=get(handles.ListXml,'String');
-% Value=get(handles.ListXml,'Value');
-% set(handles.ListXml,'Value',Value(1));
-% if isequal(Value(1),1)
-%     msgbox_uvmat('ERROR','an xml file needs to be selected')
-%    return
-% else
-%     XmlName=ListXml{Value(1)};
-% end
-% for iexp=1:length(List.Experiment)
-%     ExpName=List.Experiment{iexp}.name;
-%     if isfield(List.Experiment{iexp},'Device')
-%         for idevice=1:length(List.Experiment{iexp}.Device)
-%             DeviceName=List.Experiment{iexp}.Device{idevice}.name;
-%             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
-%                 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
-%                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
-%                     if isequal(FileName,XmlName)
-%                         editxml(fullfile(CurrentPath,ExpName,DeviceName,FileName));
-%                         return
-%                     end
-%                 end
-%              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
-%                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
-%                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
-%                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
-%                         for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
-%                             FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
-%                             if isequal(FileName,XmlName)
-%                                 editxml(fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName));
-%                                 return
-%                             end                          
-%                         end
-%                     end
-%                 end
-%             end
-%         end
-%     end
-% end
-% 
-% 
-% 
-% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% % CurrentPath/Campaign: root directory 
-% function  [Title,test_mod]=check_heading(Currentpath,Campaign,Experiment,Device,Record,xmlname,testSubCampaign)
-% 
-%  %Shema for Heading:
-% %  Campaign             
-% %  (SubCampaign)
-% % Experiment
-% %  Device
-% %  (Record)
-% %  ImageName
-% %  DateExp
-% %                 old: %Project: suppressed ( changed to Campaign)
-%                        %Exp: suppressed (changed to experiment)
-%                        %ImaNames: changed to ImageName
-% if exist('Record','var') && ~isempty(Record)
-%     xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,Record,xmlname);  
-%     testrecord=1;
-% else
-%     xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,xmlname); 
-%     testrecord=0;
-% end
-% if ~exist('testSubCampaign','var')
-%     testSubCampaign=0;
-% end
-% if testSubCampaign
-%    SubCampaign=Campaign;
-%    [Currentpath,Campaign,DirExt]=fileparts(Currentpath);
-%    Campaign=[Campaign DirExt];
-% end
-% test_mod=0; %test for the modification of the xml file
-% t_device=xmltree(xmlfullname);
-% Title=get(t_device,1,'name');
-% uid_child=children(t_device,1);
-% Heading_old=[];
-% uidheading=0;
-% for ilist=1:length(uid_child)
-%     name=get(t_device,uid_child(ilist),'name');
-%     if isequal(name,'Heading')
-%         uidheading=uid_child(ilist);
-%     end
-% end
-% if uidheading
-%     subt=branch(t_device,uidheading);
-%     Heading_old=convert(subt);
-% else
-%    return % do not edit xml files without element 'Heading'
-% end
-% if ~(isfield(Heading_old,'Campaign')&& isequal(Heading_old.Campaign,Campaign))
-%     test_mod=1;
-% end
-% Heading.Campaign=Campaign;
-% if testSubCampaign
-%     if ~(isfield(Heading_old,'SubCampaign')&& isequal(Heading_old.SubCampaign,SubCampaign))
-%         test_mod=1;
-%     end
-%     Heading.SubCampaign=SubCampaign;
-% end
-% if ~(isfield(Heading_old,'Experiment')&& isequal(Heading_old.Experiment,Experiment))
-%     test_mod=1;
-% end
-% Heading.Experiment=Experiment;
-% if ~(isfield(Heading_old,'Device')&& isequal(Heading_old.Device,Device))
-%     test_mod=1;
-% end
-% Heading.Device=Device;
-% if testrecord
-%     if ~(isfield(Heading_old,'Record')&& isequal(Heading_old.Record,Record))
-%         test_mod=1;
-%     end
-%     Heading.Record=Record;
-% end
-% if isfield(Heading_old,'ImaNames')
-%     test_mod=1;
-%     if  ~isempty(Heading_old.ImaNames)
-%         Heading.ImageName=Heading_old.ImaNames;
-%     end
-% end
-% if isfield(Heading_old,'ImageName')&& ~isempty(Heading_old.ImageName)
-%     Heading.ImageName=Heading_old.ImageName;
-% end
-% if isfield(Heading_old,'DateExp')&& ~isempty(Heading_old.DateExp)
-%     Heading.DateExp=Heading_old.DateExp;
-% end
-% if test_mod && uidheading
-%      uid_child=children(t_device,uidheading);
-%      t_device=delete(t_device,uid_child);
-%     t_device=struct2xml(Heading,t_device,uidheading);
-%     backupfile=xmlfullname;
-%     testexist=2;
-%     while testexist==2
-%        backupfile=[backupfile '~'];
-%        testexist=exist(backupfile,'file');
-%     end
-%     [success,message]=copyfile(xmlfullname,backupfile);%make backup
-%     if isequal(success,1)
-%         delete(xmlfullname)
-%     else
-%         return
-%     end
-%     save(t_device,xmlfullname)
-% end
+
 
 %------------------------------------------------------------------------
@@ -648,23 +489,43 @@
 % --- Executes on button press in Cancel.
 %------------------------------------------------------------------------
-function Cancel_Callback(hObject, eventdata, handles)
-    
-handles.output = get(hObject,'String');
-guidata(hObject, handles); % Update handles structure
-% Use UIRESUME instead of delete because the OutputFcn needs
-uiresume(handles.browse_data);
+% function Cancel_Callback(hObject, eventdata, handles)
+% % hseries=findobj(allchild(0),'Tag','series');
+% % if ~isempty(hseries)
+% %     hhh=guidata(hseries);
+% %     set(hhh.Replicate,'Value',0)
+% % end
+% % delete(get(hObject,'parent'))
+
+% handles.output = get(hObject,'String');
+% guidata(hObject, handles); % Update handles structure
+% % Use UIRESUME instead of delete because the OutputFcn needs
+% uiresume(handles.browse_data);
+
+%------------------------------------------------------------------------
+% --- executes when user attempts to close geometry_calib.
+function browse_data_CloseRequestFcn(hObject, eventdata, handles)
 
 %------------------------------------------------------------------------
 % --- Executes when user attempts to close browse_data.
 %------------------------------------------------------------------------
-function browse_data_CloseRequestFcn(hObject, eventdata, handles)
-if isequal(get(handles.browse_data, 'waitstatus'), 'waiting')
-    % The GUI is still in UIWAIT, us UIRESUME
-    handles.output = get(hObject,'String');
-    guidata(hObject, handles); % Update handles structure
-    uiresume(handles.browse_data);
-else
-    % The GUI is no longer waiting, just close it
-    delete(handles.browse_data);
+function closefcn(gcbo, eventdata)
+% if isequal(get(handles.browse_data, 'waitstatus'), 'waiting')
+%     % The GUI is still in UIWAIT, us UIRESUME
+%     handles.output = get(hObject,'String');
+%     guidata(hObject, handles); % Update handles structure
+%     uiresume(handles.browse_data);
+% else
+%     % The GUI is no longer waiting, just close it
+%     delete(handles.browse_data);
+% end
+hseries=findobj(allchild(0),'Tag','series');
+if ~isempty(hseries)
+    hreplicate=findobj(hseries,'Tag','Replicate');
+    set(hreplicate,'Value',0)
+end
+hcalib=findobj(allchild(0),'Tag','geometry_calib');
+if ~isempty(hcalib)
+    hreplicate=findobj(hcalib,'Tag','Replicate');
+    set(hreplicate,'Value',0)
 end
 
@@ -689,9 +550,30 @@
 
 
-% --- Executes on button press in Browse.
-function Browse_Callback(hObject, eventdata, handles)
+% --- Executes on button press in Up.
+function Up_Callback(hObject, eventdata, handles)
+SourceDir=get(handles.SourceDir,'String');
+% Device=ListDevices{get(handles.ListDevices,'Value')};
+% DataSeries=uigetfile_uvmat('open a data folder',Device,'uigetdir');
+% uiresume(handles.browse_data);
+browse_data(SourceDir)
+
+
+% --- Executes on button press in Down.
+function Down_Callback(hObject, eventdata, handles)
+SourceDir=get(handles.SourceDir,'String');
+ListExperiments=get(handles.ListExperiments,'String');
+list_val=get(handles.ListExperiments,'Value');
+SourceFolder=regexprep(ListExperiments{list_val(1)},'+','');
+set(handles.SourceDir,'String',fullfile(SourceDir,SourceFolder))
 ListDevices=get(handles.ListDevices,'String');
-Device=ListDevices{get(handles.ListDevices,'Value')};
-DataSeries=uigetfile_uvmat('open a data folder',Device,'uigetdir');
-uiresume(handles.browse_data);
-browse_data(DataSeries)
+ValueDevice=get(handles.ListDevices,'Value');
+set(handles.ListExperiments,'String',ListDevices)
+set(handles.ListExperiments,'Value',ValueDevice)
+ListExperiments_Callback(hObject, [], handles)
+% Device=regexprep(ListDevices{get(handles.ListDevices,'Value')},'+','');
+% Device=regexprep(Device,'~','');
+% PathDevice=fullfile(SourceDir,SourceFolder,Device);
+% DirDevice=dir(PathDevice);
+% NewDevice=DirDevice(end).name;
+% % uiresume(handles.browse_data);
+% browse_data(fullfile(PathDevice,NewDevice))
Index: /trunk/src/filter_tps.m
===================================================================
--- /trunk/src/filter_tps.m	(revision 1058)
+++ /trunk/src/filter_tps.m	(revision 1059)
@@ -79,4 +79,5 @@
 %% calculate tps coeff in each subdomain
 for isub=1:NbSubDomain
+    isub
     SubRange(1,:,isub)=[CentreX(isub)-0.55*Siz(1) CentreX(isub)+0.55*Siz(1)];%bounds of subdomain #isub in x coordinate
     SubRange(2,:,isub)=[CentreY(isub)-0.55*Siz(2) CentreY(isub)+0.55*Siz(2)];%bounds of subdomain #isub in y coordinate
@@ -87,4 +88,5 @@
         ind_sel_previous=ind_sel;% record the set of selected vector indices for next iteration
         ind_sel=find(Coord(:,1)>=SubRange(1,1,isub) & Coord(:,1)<=SubRange(1,2,isub) & Coord(:,2)>=SubRange(2,1,isub) & Coord(:,2)<=SubRange(2,2,isub));
+        numel(ind_sel)
         % if no vector in the subdomain  #isub, skip the subdomain
         if isempty(ind_sel)
Index: /trunk/src/geometry_calib.m
===================================================================
--- /trunk/src/geometry_calib.m	(revision 1058)
+++ /trunk/src/geometry_calib.m	(revision 1059)
@@ -52,5 +52,5 @@
 % Edit the above text to modify the response to help geometry_calib
 
-% Last Modified by GUIDE v2.5 16-Apr-2015 17:29:02
+% Last Modified by GUIDE v2.5 20-Sep-2018 19:04:30
 
 % Begin initialization code - DO NOT edit
@@ -108,5 +108,5 @@
 set(handles.calib_type,'Position',[1 Height-40 194 30])%  rank 1
 set(handles.APPLY,'Position',[197 Height-40 110 30])%  rank 1
-set(handles.REPLICATE,'Position',[309 Height-40 110 30])%  rank 1
+set(handles.Replicate,'Position',[309 Height-40 110 30])%  rank 1
 set(handles.Intrinsic,'Position',[1 Height-40-2-92 418 92])%  rank 2
 set(handles.Extrinsic,'Position',[1 Height-40-4-92-75 418 75])%  rank 3
@@ -167,234 +167,239 @@
 %------------------------------------------------------------------------
 % --- Executes on button press APPLY (used to launch the calibration).
-function APPLY_Callback(hObject, eventdata, handles)
+    function APPLY_Callback(hObject, eventdata, handles)
+        set(handles.CheckEnableMouse,'Value',0)% desactivate mouse (to avoid spurious creation of new points)
+        
+        %------------------------------------------------------------------------
+        %% look for the GUI uvmat and check for an image as input
+        set(handles.APPLY,'BackgroundColor',[1 1 0])% paint APPLY button in yellow to show activation
+        huvmat=findobj(allchild(0),'Name','uvmat');% look for the GUI uvmat
+        hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
+        if ~strcmp(get(hhuvmat.Scalar,'Visible'),'on')
+            msgbox_uvmat('ERROR','An image needs to be opened in uvmat for calibration')
+            return
+        end
+        
+        RootPath='';
+        if ~isempty(hhuvmat.RootPath)&& ~isempty(hhuvmat.RootFile)
+            RootPath=get(hhuvmat.RootPath,'String');% path to the currently displayed image
+            SubDirBase=regexprep(get(hhuvmat.SubDir,'String'),'\..+$','');
+            outputfile=[fullfile(RootPath,SubDirBase) '.xml'];%xml file associated with the currently displayed image
+        else
+            question={'save the calibration data and point coordinates in'};
+            def={fullfile(RootPath,'ObjectCalib.xml')};
+            options.Resize='on';
+            answer=inputdlg(question,'',1,def,options);
+            outputfile=answer{1};
+        end
+        
+        %% read coordinates of the calibration poinnts: Coord(:,1-3) in phys, Coord(:,4-5) image
+        Coord=get(handles.ListCoord,'Data');
+        
+        
+        %% read the type of calibration
+        calib_cell=get(handles.calib_type,'String');
+        val=get(handles.calib_type,'Value');
+        CalibFcn=['calib_' calib_cell{val}];
+        
+        %% read the intrinsic parameters
+        Intrinsic.Npx=str2num(get(hhuvmat.num_Npx,'String'));
+        Intrinsic.Npy=str2num(get(hhuvmat.num_Npy,'String'));
+        Intrinsic.coord_files=get(handles.ListCoordFiles,'String');
+        Intrinsic.fx=str2num(get(handles.fx,'String'));
+        Intrinsic.fy=str2num(get(handles.fy,'String'));
+        Intrinsic.kc=str2num(get(handles.kc,'String'));
+        Intrinsic.Cx=str2num(get(handles.Cx,'String'));
+        Intrinsic.Cy=str2num(get(handles.Cy,'String'));
+        if isempty(Intrinsic.kc)
+            Intrinsic.kc=0;
+        end
+        if isempty(Intrinsic.Cx)||isempty(Intrinsic.Cy)
+            Intrinsic.Cx=Intrinsic.Npx/2;
+            Intrinsic.Cy=Intrinsic.Npy/2;
+        end
+        
+        %% apply to cropped images if requested
+        if get(handles.Replicate,'Value')
+            answer=msgbox_uvmat('INPUT_Y-N','apply to full images (not cropped)?');
+            if strcmp(answer,'No')
+                prompt = {'npy_lower'};
+                dlg_title = 'remove image the npy_lower image lines (removal of the upper line does not change calibration)';
+                num_lines= 1;
+                def     = {'0'};
+                answer = inputdlg(prompt,dlg_title,num_lines,def);
+                npy_crop=str2num(answer{1});
+                Intrinsic.Npy=Intrinsic.Npy-npy_crop; %size of the filtering window
+                Coord(:,5)=Coord(:,5)-npy_crop;% shift the image ordinates of the calibration points by removing the lower band
+            end
+        end
+        
+        %% Apply calibration
+        [GeometryCalib,index,ind_removed,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration
+        
+        %% record the coordinate unit
+        unitlist=get(handles.CoordUnit,'String');
+        unit=unitlist{get(handles.CoordUnit,'value')};
+        GeometryCalib.CoordUnit=unit;
+        
+        %% record the coordinates of the calibration points
+        GeometryCalib.SourceCalib.PointCoord=Coord;
+        
+        %% display calibration results on the GUI geometry_calib
+        display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters
+        display_extrinsic(GeometryCalib,handles)%display calibration extrinsic parameters
+        %     (rotation and translation of camera with  respect to the phys coordinates)
+        
+        %% set the defqult plane and display the calibration data errors for validation
+        answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';...
+            ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
+            ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels'];
+            [num2str(numel(ind_removed)) ' points removed']});
+        if strcmp(answer,'Yes') %store the calibration data
+            if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration
+                answer=msgbox_uvmat('INPUT_Y-N',{['Assume that the current image is in the plane of the calib points z=' num2str(Z_plane) ] ; 'can be later modified by MenuSetSlice in the upper bar menu of uvmat'});
+                SliceCoord_ref=Z_plane'*[0 0 1];
+            end
+        else
+            GeometryCalib=[];
+            index=1;
+        end
+        
+        if ~isempty(GeometryCalib) % if calibration is not cancelled
+            if get(handles.Replicate,'Value')
+                %% open the GUI browse_data
+                hbrowse=findobj(allchild(0),'Tag','browse_data');
+                if ~isempty(hbrowse)
+                    BrowseHandles=guidata(hbrowse);
+                    SourceDir=get(BrowseHandles.SourceDir,'String');
+                    ListExperiments=get(BrowseHandles.ListExperiments,'String');
+                    ListValues=get(BrowseHandles.ListExperiments,'Value');
+                    ListExperiments=ListExperiments(ListValues);
+                    ListDevices=get(BrowseHandles.ListDevices,'String');
+                    Val=get(BrowseHandles.ListDevices,'Value');
+                    DataFolder=ListDevices{Val};
+                    nbcalib=0;
+                    for ilist=1:numel(ListExperiments)
+                        SubDirBase=regexprep(DataFolder,'+/','');
+                        ListExperiments{ilist}=regexprep(ListExperiments{ilist},'+/','');
+                        XmlName=fullfile(SourceDir,ListExperiments{ilist},[SubDirBase '.xml']);
+                        % copy the xml file from the old location if appropriate, then update with the calibration parameters
+                        %                 if ~exist(XmlName,'file') && ~isempty(SubDirBase)
+                        %                     oldxml=fullfile(OutPut.Campaign,OutPut.Experiment{ilist},SubDirBase,[get(hhuvmat.RootFile,'String') '.xml']);
+                        GeometryCalib.SliceCoord=SliceCoord_ref;%default input
+                        if exist(XmlName,'file')
+                            %[success,message]=copyfile(oldxml,XmlName);%copy the old xml file to a new one with the new convention
+                            dispmesGeometryCalib=UvData.XmlData{1}.GeometryCalib;
+                        else
+                            msgbox_uvmat('ERROR','3D geometric calibration needed before defining slices')
+                            return
+                        end
+                        SliceCoord=GeometryCalib.SliceCoord;
+                        InterfaceCoord=min(SliceCoord(:,3));
+                        if isfield(GeometryCalib,'InterfaceCoord')
+                            InterfaceCoord=GeometryCalib.InterfaceCoord(1,3);
+                        end
+                        NbSlice=size(SliceCoord,1);
+                        CheckVolumeScan=0;
+                        if isfield(GeometryCalib,'CheckVolumeScan')
+                            CheckVolumeScan=GeometryCalib.CheckVolumeScan;
+                        end
+                        RefractionIndex=1.33;
+                        CheckRefraction=0;% default value of the check box refraction
+                        if isfield(GeometryCalib,'RefractionIndex')
+                            RefractionIndex=GeometryCalib.RefractionIndex;
+                            CheckRefraction=1;
+                        end
+                        SliceAngle=[0 0 0];
+                        if isfield(GeometryCalib,'SliceAngle')
+                            SliceAngle=GeometryCalib.SliceAngle;
+                        end
+                        dispmessage=' updated with calibration parameters';
+                        %                         if ~strcmp(answer,'yes')
+                        [XmlDataOld,warntext]=imadoc2struct(XmlName);
+                        if isfield(XmlDataOld,'GeometryCalib')
+                            if isfield(XmlDataOld.GeometryCalib,'SliceAngle')
+                                GeometryCalib.SliceAngle=XmlDataOld.GeometryCalib.SliceAngle;
+                            end
+                            if isfield(XmlDataOld.GeometryCalib,'CheckRefraction')
+                                GeometryCalib.SliceAngle=XmlDataOld.GeometryCalib.CheckRefraction;
+                            end
+                            if isfield(XmlDataOld.GeometryCalib,'RefractionIndex')
+                                GeometryCalib.SliceAngle=XmlDataOld.GeometryCalib.RefractionIndex;
+                            end
+                            if isfield(XmlDataOld.GeometryCalib,'InterfaceCoord')
+                                GeometryCalib.SliceAngle=XmlDataOld.GeometryCalib.InterfaceCoord;
+                            end
+                        end
+                        
+                        end
+                        
+                        else
+                            dispmessage=' created with calibration parameters';
+                    end
+                    errormsg=update_imadoc(GeometryCalib,XmlName,'GeometryCalib');% introduce the calibration data in the xml file
+                    if ~strcmp(errormsg,'')
+                        msgbox_uvmat('ERROR',errormsg);
+                    else
+                        display([XmlName dispmessage])
+                        nbcalib=nbcalib+1;
+                    end
+                end
+                
+            end
+            msgbox_uvmat('CONFIMATION',[SubDirBase ' calibrated for ' num2str(nbcalib) ' experiments']);
+        else
+            
+            %% copy the xml file from the old location if appropriate, then update with the calibration parameters
+            if ~exist(outputfile,'file') && ~isempty(SubDirBase)
+                oldxml=[fullfile(RootPath,SubDirBase,get(hhuvmat.RootFile,'String')) '.xml'];
+                if exist(oldxml,'file')
+                    [success,message]=copyfile(oldxml,outputfile);%copy the old xml file to a new one with the new convention
+                end
+            end
+            errormsg=update_imadoc(GeometryCalib,outputfile,'GeometryCalib');% introduce the calibration data in the xml file
+            if ~strcmp(errormsg,'')
+                msgbox_uvmat('ERROR',errormsg);
+            end
+            
+            %% display image with new calibration in the currently opened uvmat interface
+            FieldList=get(hhuvmat.FieldName,'String');
+            val=get(hhuvmat.FieldName,'Value');
+            if strcmp(FieldList{val},'image')
+                set(hhuvmat.CheckFixLimits,'Value',0)% put FixedLimits option to 'off' to plot the whole image
+                UserData=get(handles.geometry_calib,'UserData');
+                UserData.XmlInputFile=outputfile;%save the current xml file name
+                set(handles.geometry_calib,'UserData',UserData)
+                uvmat('InputFileREFRESH_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat, show the image in phys coordinates
+                PLOT_Callback(hObject, eventdata, handles)
+                set(handles.CoordLine,'string',num2str(index))
+                Coord=get(handles.ListCoord,'Data');
+                update_calib_marker(Coord(index,:)); %indicate the point with max deviations from phys coord to calibration
+                figure(handles.geometry_calib)% put the GUI geometry_calib in front
+            else
+                msgbox_uvmat('WARNING','open the image to see the effect of the new calibration')
+            end
+        end
+    end
+    set(handles.APPLY,'BackgroundColor',[1 0 0]) % set APPLY button to red color
+
+%------------------------------------------------------------------------
+% --- Executes on button press in Replicate
+function Replicate_Callback(hObject, eventdata, handles)
+% %------------------------------------------------------------------------
 set(handles.CheckEnableMouse,'Value',0)% desactivate mouse (to avoid spurious creation of new points)
 
-%------------------------------------------------------------------------
-%% look for the GUI uvmat and check for an image as input
-set(handles.APPLY,'BackgroundColor',[1 1 0])% paint APPLY button in yellow to show activation
-huvmat=findobj(allchild(0),'Name','uvmat');% look for the GUI uvmat
-hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
-if ~strcmp(get(hhuvmat.Scalar,'Visible'),'on')
-    msgbox_uvmat('ERROR','An image needs to be opened in uvmat for calibration')
-  return
-end
-
-RootPath='';
-if ~isempty(hhuvmat.RootPath)&& ~isempty(hhuvmat.RootFile)
-    RootPath=get(hhuvmat.RootPath,'String');% path to the currently displayed image
-    SubDirBase=regexprep(get(hhuvmat.SubDir,'String'),'\..+$','');
-    outputfile=[fullfile(RootPath,SubDirBase) '.xml'];%xml file associated with the currently displayed image
+if get(handles.Replicate,'Value') %open the GUI browse_data
+    % look for the GUI uvmat and check for an image as input
+    huvmat=findobj(allchild(0),'Name','uvmat');
+    hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
+    RootPath=get(hhuvmat.RootPath,'String');
+    SubDir=get(hhuvmat.SubDir,'String');
+    browse_data(fullfile(RootPath,SubDir))
 else
-    question={'save the calibration data and point coordinates in'};
-    def={fullfile(RootPath,'ObjectCalib.xml')};
-    options.Resize='on';
-    answer=inputdlg(question,'',1,def,options);
-    outputfile=answer{1};
-end
-
-%% read coordinates of the calibration poinnts: Coord(:,1-3) in phys, Coord(:,4-5) image
-Coord=get(handles.ListCoord,'Data');
-
-  
-%% read the type of calibration
-calib_cell=get(handles.calib_type,'String');
-val=get(handles.calib_type,'Value');
-CalibFcn=['calib_' calib_cell{val}];
-
-%% read the intrinsic parameters
-Intrinsic.Npx=str2num(get(hhuvmat.num_Npx,'String')); 
-Intrinsic.Npy=str2num(get(hhuvmat.num_Npy,'String'));
-Intrinsic.coord_files=get(handles.ListCoordFiles,'String');
-Intrinsic.fx=str2num(get(handles.fx,'String'));
-Intrinsic.fy=str2num(get(handles.fy,'String'));
-Intrinsic.kc=str2num(get(handles.kc,'String'));
-Intrinsic.Cx=str2num(get(handles.Cx,'String'));
-Intrinsic.Cy=str2num(get(handles.Cy,'String'));
-if isempty(Intrinsic.kc)
-    Intrinsic.kc=0;
-end
-if isempty(Intrinsic.Cx)||isempty(Intrinsic.Cy)
-    Intrinsic.Cx=Intrinsic.Npx/2;
-    Intrinsic.Cy=Intrinsic.Npy/2;
-end  
-
-%% Apply calibration
-[GeometryCalib,index,ind_removed,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration
-
-%% record the coordinate unit
-unitlist=get(handles.CoordUnit,'String');
-unit=unitlist{get(handles.CoordUnit,'value')};
-GeometryCalib.CoordUnit=unit;
-
-%% record the coordinates of the calibration points
-GeometryCalib.SourceCalib.PointCoord=Coord;
-
-%% display calibration results on the GUI geometry_calib
-display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters
-display_extrinsic(GeometryCalib,handles)%display calibration extrinsic parameters
-%     (rotation and translation of camera with  respect to the phys coordinates)
-
-%% store the calibration data, by default in the xml file of the currently displayed image
-answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';...
-    ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
-    ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels'];
-    [num2str(numel(ind_removed)) ' points removed']});
-if strcmp(answer,'Yes') %store the calibration data
-    if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration
-        msgbox_uvmat('CONFIRMATION',{['The current image series is assumed by default in the plane of the calib points z=' num2str(Z_plane) ] ; 'can be modified by MenuSetSlice in the upper bar menu of uvmat'})
-        GeometryCalib.SliceCoord=Z_plane'*[0 0 1];
-    end   
-else
-    GeometryCalib=[];
-    index=1;
-end
-
-if isempty(GeometryCalib) % if calibration cancelled
-    set(handles.APPLY,'BackgroundColor',[1 0 1])
-else   % if calibration confirmed
-    
-    %% copy the xml file from the old location if appropriate, then update with the calibration parameters
-    if ~exist(outputfile,'file') && ~isempty(SubDirBase)
-        oldxml=[fullfile(RootPath,SubDirBase,get(hhuvmat.RootFile,'String')) '.xml'];
-        if exist(oldxml,'file')
-            [success,message]=copyfile(oldxml,outputfile);%copy the old xml file to a new one with the new convention
-        end
-    end
-    errormsg=update_imadoc(GeometryCalib,outputfile,'GeometryCalib');% introduce the calibration data in the xml file
-    if ~strcmp(errormsg,'')
-        msgbox_uvmat('ERROR',errormsg);
-    end
-    
-    %% display image with new calibration in the currently opened uvmat interface
-    FieldList=get(hhuvmat.FieldName,'String');
-    val=get(hhuvmat.FieldName,'Value');
-    if strcmp(FieldList{val},'image')
-        set(hhuvmat.CheckFixLimits,'Value',0)% put FixedLimits option to 'off' to plot the whole image
-        UserData=get(handles.geometry_calib,'UserData');
-        UserData.XmlInputFile=outputfile;%save the current xml file name
-        set(handles.geometry_calib,'UserData',UserData)
-        uvmat('InputFileREFRESH_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat, show the image in phys coordinates
-        PLOT_Callback(hObject, eventdata, handles)
-        set(handles.CoordLine,'string',num2str(index))
-        Coord=get(handles.ListCoord,'Data');
-        update_calib_marker(Coord(index,:)); %indicate the point with max deviations from phys coord to calibration
-        figure(handles.geometry_calib)% put the GUI geometry_calib in front
-        set(handles.APPLY,'BackgroundColor',[1 0 0]) % set APPLY button to red color
-    else
-        msgbox_uvmat('WARNING','open the image to see the effect of the new calibration')
-    end
-end
-
-%------------------------------------------------------------------------
-% --- Executes on button press in REPLICATE
-function REPLICATE_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------------------
-set(handles.CheckEnableMouse,'Value',0)% desactivate mouse (to avoid spurious creation of new points)
-
-%% look for the GUI uvmat and check for an image as input
-huvmat=findobj(allchild(0),'Name','uvmat');
-hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
-
-%% read coordinates of the calibration poinnts: Coord(:,1-3) in phys, Coord(:,4-5) image
-Coord=get(handles.ListCoord,'Data');
-  
-%% read the type of calibration
-calib_cell=get(handles.calib_type,'String');
-val=get(handles.calib_type,'Value');
-CalibFcn=['calib_' calib_cell{val}];
-
-%% read the intrinsic parameters
-Intrinsic.Npx=str2num(get(hhuvmat.num_Npx,'String'));
-Intrinsic.Npy=str2num(get(hhuvmat.num_Npy,'String'));
-Intrinsic.coord_files=get(handles.ListCoordFiles,'String');
-Intrinsic.fx=str2num(get(handles.fx,'String'));
-Intrinsic.fy=str2num(get(handles.fy,'String'));
-Intrinsic.kc=str2num(get(handles.kc,'String'));
-Intrinsic.Cx=str2num(get(handles.Cx,'String'));
-Intrinsic.Cy=str2num(get(handles.Cy,'String'));
-if isempty(Intrinsic.kc)
-    Intrinsic.kc=0;
-end
-if isempty(Intrinsic.Cx)||isempty(Intrinsic.Cy)
-    Intrinsic.Cx=Intrinsic.Npx/2;
-    Intrinsic.Cy=Intrinsic.Npy/2;
-end
-
-%% apply to cropped images if requested
-answer=msgbox_uvmat('INPUT_Y-N','apply to cropped images?');
-if strcmp(answer,'Yes')
-    prompt = {'npy_lower'};
-    dlg_title = 'remove image the npy_lower image lines (removal of the upper linedoes not change calibration)';
-    num_lines= 1;
-    def     = {'0'};
-    answer = inputdlg(prompt,dlg_title,num_lines,def);
-    npy_crop=str2num(answer{1});
-    Intrinsic.Npy=Intrinsic.Npy-npy_crop; %size of the filtering window
-    Coord(:,5)=Coord(:,5)-npy_crop;% shift the image ordinates of the calibration points by removing the lower band
-end
-
-%% Apply calibration
-[GeometryCalib,index,ind_removed,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration
-
-
-%% record the coordinate unit
-unitlist=get(handles.CoordUnit,'String');
-unit=unitlist{get(handles.CoordUnit,'value')};
-GeometryCalib.CoordUnit=unit;
-
-%% record the coordinates of the calibration points
-GeometryCalib.SourceCalib.PointCoord=Coord;
-
-%% display calibration results on the GUI geometry_calib
-display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters
-display_extrinsic(GeometryCalib,handles)%display calibration extrinsic parameters
-%     (rotation and translation of camera with  respect to the phys coordinates)
-
-%% store the calibration data, by default in the xml file of the currently displayed image
-answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';...
-    ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
-    ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels'];...
-    [num2str(numel(ind_removed)) ' points removed']});
-if strcmp(answer,'Yes') %store the calibration data
-    if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration
-        msgbox_uvmat('CONFIRMATION',{['The current image series is assumed by default in the plane of the calib points z=' num2str(Z_plane) ] ; 'can be modified by MenuSetSlice in the upper bar menu of uvmat'})
-        GeometryCalib.SliceCoord=Z_plane'*[0 0 1];
-    end   
-else
-    GeometryCalib=[];
-    index=1;
-end
-
-%% open the GUI browse_data
-CalibData=get(handles.geometry_calib,'UserData');%read the calibration image source on the interface userdata
-if isfield(CalibData,'XmlInputFile')
-    InputDir=fileparts(fileparts(CalibData.XmlInputFile));
-end
-DataSeries=uigetfile_uvmat('open a folder of images to calibrate',InputDir,'uigetdir');
-%SubProject=uigetfile_uvmat('open folder of subproject to calibrate',InputDir,'uigetdir');
-OutPut=browse_data(DataSeries);
-nbcalib=0;
-for ilist=1:numel(OutPut.Experiment)
-    SubDirBase=regexprep(OutPut.DataSeries{1},'\..+$','');
-    XmlName=fullfile(OutPut.Campaign,OutPut.Experiment{ilist},[SubDirBase '.xml']);
-    dispmessage=' created with calibration parameters';
-    % copy the xml file from the old location if appropriate, then update with the calibration parameters
-    if ~exist(XmlName,'file') && ~isempty(SubDirBase)
-        oldxml=fullfile(OutPut.Campaign,OutPut.Experiment{ilist},SubDirBase,[get(hhuvmat.RootFile,'String') '.xml']);
-        if exist(oldxml,'file')
-            [success,message]=copyfile(oldxml,XmlName);%copy the old xml file to a new one with the new convention
-            dispmessage=' updated with calibration parameters';
-        end
-    end
-    errormsg=update_imadoc(GeometryCalib,XmlName,'GeometryCalib');% introduce the calibration data in the xml file
-    if ~strcmp(errormsg,'')
-        msgbox_uvmat('ERROR',errormsg);
-    else
-        display([XmlName dispmessage])
-        nbcalib=nbcalib+1;
-    end
-end
-msgbox_uvmat('CONFIMATION',[SubDirBase ' calibrated for ' num2str(nbcalib) ' experiments']);
-
+    hbrowse=findobj(allchild(0),'Tag','browse_data');
+    if ~isempty(hbrowse)
+        delete(hbrowse)
+    end
+end
 %------------------------------------------------------------------------
 % --- activate calibration and store parameters in ouputfile .
Index: /trunk/src/phys_XYZ.m
===================================================================
--- /trunk/src/phys_XYZ.m	(revision 1058)
+++ /trunk/src/phys_XYZ.m	(revision 1059)
@@ -30,5 +30,5 @@
 testangle=0;
 test_refraction=0;
-if exist('Zindex','var')&& isequal(Zindex,round(Zindex))&& Zindex>0 && isfield(Calib,'SliceCoord')&&length(Calib.SliceCoord)>=Zindex
+if exist('Zindex','var')&& isequal(Zindex,round(Zindex))&& Zindex>0 && isfield(Calib,'SliceCoord')&&size(Calib.SliceCoord,1)>=Zindex
     if isfield(Calib, 'SliceAngle') && ~isequal(Calib.SliceAngle,[0 0 0]) && ~isequal(Calib.SliceAngle(Zindex,:),[0 0 0])
         testangle=1;
@@ -43,5 +43,5 @@
 %         Z0=norm_plane*Calib.SliceCoord(Zindex,:)'/norm_plane(3);
     end
-        Z0=Calib.SliceCoord(Zindex,3);%horizontal plane z=cte
+    Z0=Calib.SliceCoord(Zindex,3);%horizontal plane z=cte
 %     end
     Z0virt=Z0;
Index: /trunk/src/series.m
===================================================================
--- /trunk/src/series.m	(revision 1058)
+++ /trunk/src/series.m	(revision 1059)
@@ -1,5 +1,2 @@
-
-
-
 %'series': master function associated to the GUI series.m for analysis field series  
 %------------------------------------------------------------------------
@@ -212,9 +209,9 @@
     end
     %get the list of previous campaigns in the upper bar menu Open campaign
-    if isfield(h,'MenuCampaign')
-        for ifile=1:min(length(h.MenuCampaign),5)
-            set(handles.(['MenuCampaign_' num2str(ifile)]),'Label',h.MenuCampaign{ifile});
-        end
-    end
+%     if isfield(h,'MenuCampaign')
+%         for ifile=1:min(length(h.MenuCampaign),5)
+%             set(handles.(['MenuCampaign_' num2str(ifile)]),'Label',h.MenuCampaign{ifile});
+%         end
+%     end
     %get the menu of actions
     if isfield(h,'ActionListUser') && iscell(h.ActionListUser) && isfield(h,'ActionPathListUser') && iscell(h.ActionPathListUser)
@@ -498,86 +495,86 @@
     end
 end
-
-OutPut=browse_data(oldfile,'on','on'); % open the GUI browse_data to get select a campaign dir, experiment and device
-NbLines=numel(OutPut.Experiment)*numel(OutPut.DataSeries);
-icount=0;
-for iexp=1:numel(OutPut.Experiment)
-    for idevice=1:numel(OutPut.DataSeries)
-        icount=icount+1;
-        InputTable{icount,1}=fullfile(OutPut.Campaign,OutPut.Experiment{iexp});
-        InputTable{icount,2}=OutPut.DataSeries{idevice};
-        if isempty(InputTable{icount,3})
-            if icount>1
-            InputTable{icount,3}=InputTable{icount-1,3};
-            else
-                InputTable{icount,3}='';
-            end
-        end
-        if isempty(InputTable{icount,4})
-            if icount>1
-            InputTable{icount,4}=InputTable{icount-1,4};
-            else
-                InputTable{icount,4}='';
-            end
-        end
-                if isempty(InputTable{icount,5})
-            if icount>1
-            InputTable{icount,5}=InputTable{icount-1,5};
-            else
-                InputTable{icount,5}='';
-            end
-        end
-    end
-end
-if size(InputTable,1)>icount
-    InputTable(icount+1:size(InputTable,1),:)=[];
-end
+InputTable{1,1}='...';
 set(handles.InputTable,'Data',InputTable)
-REFRESH_Callback(hObject, eventdata, handles)
+browse_data(oldfile,'on','on'); % open the GUI browse_data to get select a campaign dir, experiment and device
+% NbLines=numel(OutPut.Experiment)*numel(OutPut.DataSeries);
+% icount=0;
+% for iexp=1:numel(OutPut.Experiment)
+%     for idevice=1:numel(OutPut.DataSeries)
+%         icount=icount+1;
+%         InputTable{icount,1}=fullfile(OutPut.Campaign,OutPut.Experiment{iexp});
+%         InputTable{icount,2}=OutPut.DataSeries{idevice};
+%         if isempty(InputTable{icount,3})
+%             if icount>1
+%             InputTable{icount,3}=InputTable{icount-1,3};
+%             else
+%                 InputTable{icount,3}='';
+%             end
+%         end
+%         if isempty(InputTable{icount,4})
+%             if icount>1
+%             InputTable{icount,4}=InputTable{icount-1,4};
+%             else
+%                 InputTable{icount,4}='';
+%             end
+%         end
+%                 if isempty(InputTable{icount,5})
+%             if icount>1
+%             InputTable{icount,5}=InputTable{icount-1,5};
+%             else
+%                 InputTable{icount,5}='';
+%             end
+%         end
+%     end
+% end
+% if size(InputTable,1)>icount
+%     InputTable(icount+1:size(InputTable,1),:)=[];
+% end
+%REFRESH_Callback(hObject, eventdata, handles)
 
 % --------------------------------------------------------------------
-function MenuCampaign_Callback(hObject, eventdata, handles)
-% -------------------------------------------------------------------- 
-
-OutPut=browse_data(get(hObject,'Label'),'on','on'); % open the GUI browse_data to get select a campaign dir, experiment and device
-if ~isfield(OutPut,'Campaign')
-    return
-end
-NbLines=numel(OutPut.Experiment)*numel(OutPut.DataSeries);
-icount=0;
-InputTable=get(handles.InputTable,'Data');
-for iexp=1:numel(OutPut.Experiment)
-    for idevice=1:numel(OutPut.DataSeries)
-        icount=icount+1;
-        InputTable{icount,1}=fullfile(OutPut.Campaign,OutPut.Experiment{iexp});
-        InputTable{icount,2}=OutPut.DataSeries{idevice};
-        if isempty(InputTable{icount,3})
-            if icount>1
-                InputTable{icount,3}=InputTable{icount-1,3};
-            else
-                InputTable{icount,3}='';
-            end
-        end
-        if isempty(InputTable{icount,4})
-            if icount>1
-                InputTable{icount,4}=InputTable{icount-1,4};
-            else
-                InputTable{icount,4}='';
-            end
-        end
-        if isempty(InputTable{icount,5})
-            if icount>1
-                InputTable{icount,5}=InputTable{icount-1,5};
-            else
-                InputTable{icount,5}='';
-            end
-        end
-    end
-end
-if size(InputTable,1)>icount
-    InputTable(icount+1:size(InputTable,1),:)=[];
-end
-set(handles.InputTable,'Data',InputTable)
-REFRESH_Callback(hObject, eventdata, handles)
+% function MenuCampaign_Callback(hObject, eventdata, handles)
+% % -------------------------------------------------------------------- 
+% 
+% OutPut=browse_data(get(hObject,'Label'),'on','on'); % open the GUI browse_data to get select a campaign dir, experiment and device
+% if ~isfield(OutPut,'Campaign')
+%     return
+% end
+% NbLines=numel(OutPut.Experiment)*numel(OutPut.DataSeries);
+% icount=0;
+% InputTable=get(handles.InputTable,'Data');
+% for iexp=1:numel(OutPut.Experiment)
+%     for idevice=1:numel(OutPut.DataSeries)
+%         icount=icount+1;
+%         InputTable{icount,1}=fullfile(OutPut.Campaign,OutPut.Experiment{iexp});
+%         InputTable{icount,2}=OutPut.DataSeries{idevice};
+%         if isempty(InputTable{icount,3})
+%             if icount>1
+%                 InputTable{icount,3}=InputTable{icount-1,3};
+%             else
+%                 InputTable{icount,3}='';
+%             end
+%         end
+%         if isempty(InputTable{icount,4})
+%             if icount>1
+%                 InputTable{icount,4}=InputTable{icount-1,4};
+%             else
+%                 InputTable{icount,4}='';
+%             end
+%         end
+%         if isempty(InputTable{icount,5})
+%             if icount>1
+%                 InputTable{icount,5}=InputTable{icount-1,5};
+%             else
+%                 InputTable{icount,5}='';
+%             end
+%         end
+%     end
+% end
+% if size(InputTable,1)>icount
+%     InputTable(icount+1:size(InputTable,1),:)=[];
+% end
+% set(handles.InputTable,'Data',InputTable)
+% REFRESH_Callback(hObject, eventdata, handles)
 
 
@@ -742,9 +739,9 @@
 %% enable other menus and uicontrols
 % set(handles.MenuOpenCampaign,'Enable','on')
-set(handles.MenuCampaign_1,'Enable','on')
-set(handles.MenuCampaign_2,'Enable','on')
-set(handles.MenuCampaign_3,'Enable','on')
-set(handles.MenuCampaign_4,'Enable','on')
-set(handles.MenuCampaign_5,'Enable','on')
+% set(handles.MenuCampaign_1,'Enable','on')
+% set(handles.MenuCampaign_2,'Enable','on')
+% set(handles.MenuCampaign_3,'Enable','on')
+% set(handles.MenuCampaign_4,'Enable','on')
+% set(handles.MenuCampaign_5,'Enable','on')
 set(handles.RUN, 'Enable','On')
 set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red 
@@ -1594,523 +1591,554 @@
 end
 
-%% create the output data directory if needed
-OutputDir='';
-if isfield(Param,'OutputSubDir')
-    SubDirOut=[get(handles.OutputSubDir,'String') Param.OutputDirExt];
-    SubDirOutNew=SubDirOut;
-    detect=exist(fullfile(Param.InputTable{1,1},SubDirOutNew),'dir'); % test if  the dir  already exist
-    check_create=1; % need to create the result directory by default
-    CheckOverwrite=1;
-    if isfield(Param,'CheckOverwrite')
-        CheckOverwrite=Param.CheckOverwrite;
-    end
-    while detect
-        if CheckOverwrite
-            comment=', possibly overwrite previous data';
+%% Look for prcessing on multiple experiments set by the GUI browse_data
+NbExp=1;
+ListExp=Param.InputTable(1,1);
+
+if get(handles.Replicate,'Value')
+    hh=findobj(allchild(0),'Tag','browse_data');
+    BrowseData=guidata(hh);
+    SourceDir=get(BrowseData.SourceDir,'String');
+    ListExp=get(BrowseData.ListExperiments,'String');
+    ListExp=ListExp(get(BrowseData.ListExperiments,'Value'));
+    NbExp=numel(ListExp) % number of experiments set possibly by the GUI browse_data, =1 otherwise
+    for ilist=1:NbExp
+        ListExp{ilist}=regexprep(ListExp{ilist},'+','');
+        ListExp{ilist}= [SourceDir ListExp{ilist}];
+    end
+end
+
+%%%%%%%%%%%%%%%%%%% LOOP ON EXPERIMENTS POSSIBLY SET BY THE GUI browse_data, NbExp=1 otherwise %%%%%%%%%
+for iexp=1:NbExp
+    Param.InputTable{1,1}=ListExp{iexp};
+    set(handles.InputTable,'Data',Param.InputTable)
+    [xx,ExpName]=fileparts(ListExp{iexp});
+    Param.IndexRange.first_i=str2num(get(handles.num_first_i,'String'));%reset the firrst_i and last_i for multiple experiments, modified by the splitting into NbProcess
+    Param.IndexRange.last_i=str2num(get(handles.num_last_i,'String'));
+    %% create the output data directory if needed
+    OutputDir='';
+    answer='';
+    if isfield(Param,'OutputSubDir')
+        SubDirOut=[get(handles.OutputSubDir,'String') Param.OutputDirExt];
+        SubDirOutNew=SubDirOut;
+        detect=exist(fullfile(Param.InputTable{1,1},SubDirOutNew),'dir'); % test if  the dir  already exist
+        check_create=1; % need to create the result directory by default
+        CheckOverwrite=1;
+        if isfield(Param,'CheckOverwrite')
+            CheckOverwrite=Param.CheckOverwrite;
+        end
+        while detect
+            if CheckOverwrite
+                comment=', possibly overwrite previous data';
+            else
+                comment=', will complement existing result files (no overwriting)';
+            end
+            answer=msgbox_uvmat('INPUT_Y-N-Cancel',['use existing ouput directory: ' fullfile(Param.InputTable{1,1},SubDirOutNew) comment]);
+            if strcmp(answer,'Cancel')
+                break
+            elseif strcmp(answer,'Yes')
+                detect=0;
+                check_create=0;
+            else
+                r=regexp(SubDirOutNew,'(?<root>.*\D)(?<num1>\d+)$','names'); % detect whether name ends by a number
+                if isempty(r)
+                    r(1).root=[SubDirOutNew '_'];
+                    r(1).num1='0';
+                end
+                SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)]; % increment the index by 1 or put 1
+                detect=exist(fullfile(Param.InputTable{1,1},SubDirOutNew),'dir'); % test if  the dir  already exists
+                check_create=1;
+            end
+        end
+        if strcmp(answer,'Cancel')
+            continue
+        end
+        Param.OutputDirExt=regexprep(SubDirOutNew,Param.OutputSubDir,'');
+        Param.OutputRootFile=Param.InputTable{1,3}; % the first sorted RootFile taken for output
+        set(handles.OutputDirExt,'String',Param.OutputDirExt)
+        OutputDir=fullfile(Param.InputTable{1,1},[Param.OutputSubDir Param.OutputDirExt]); % full name (with path) of output directory
+        if check_create    % create output directory if it does not exist
+            [tild,msg1]=mkdir(OutputDir);
+            if ~strcmp(msg1,'')
+                errormsg=['cannot create ' OutputDir ': ' msg1]; % error message for directory creation
+                return
+            end
+        end
+        
+    elseif isfield(Param,'ActionInput')&&isfield(Param.ActionInput,'LogPath')% custom definition of the output dir
+        OutputDir=Param.ActionInput.LogPath;
+    end
+    DirXml=fullfile(OutputDir,'0_XML');
+    if ~exist(DirXml,'dir')
+        [~,msg1]=mkdir(DirXml);
+        if ~strcmp(msg1,'')
+            errormsg=['cannot create ' DirXml ': ' msg1]; % error message for directory creation
+            return
+        end
+    end
+    OutputNomType=nomtype2pair(Param.InputTable{1,4}); % nomenclature for output files
+    
+    %% get the set of reference input field indices
+    first_i=1; % first i index to process
+    last_i=1; % last i index to process
+    incr_i=1; % increment step in i index
+    first_j=1; % first j index to process
+    last_j=1; % last j index to process
+    incr_j=1; % increment step in j index
+    if isfield(Param.IndexRange,'first_i')
+        first_i=Param.IndexRange.first_i;
+        incr_i=Param.IndexRange.incr_i;
+        last_i=Param.IndexRange.last_i;
+    end
+    if isfield(Param.IndexRange,'incr_j')
+        first_j=Param.IndexRange.first_j;
+        last_j=Param.IndexRange.last_j;
+        incr_j=Param.IndexRange.incr_j;
+    end
+    if last_i < first_i || last_j < first_j
+        errormsg= 'series/Run_Callback:last field index must be larger or equal to the first one';
+        return
+    end
+    %incr_i must be defined, =1 by default, if NbSlice is active
+    if isempty(incr_i)&& ~isempty(Param.IndexRange.NbSlice)
+        incr_i=1;
+        set(handles.num_incr_i,'String','1')
+    end
+    % case of no increment i defined: processing is done on the available files found in i1_series
+    if isempty(incr_i)
+        if isempty(incr_j)
+            [ref_j,ref_i]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
+            ref_j=ref_j(ref_j>=first_j & ref_j<=last_j);
+            ref_i=ref_i(ref_i>=first_i & ref_i<=last_i);
+            ref_j=ref_j-1;
+            ref_i=ref_i-1;
         else
-            comment=', will complement existing result files (no overwriting)';
-        end
-        answer=msgbox_uvmat('INPUT_Y-N-Cancel',['use existing ouput directory: ' fullfile(Param.InputTable{1,1},SubDirOutNew) comment]);
-        if strcmp(answer,'Cancel')
+            ref_j=first_j:incr_j:last_j;
+            [tild,ref_i]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
+            ref_i=ref_i-1;
+            ref_i=ref_i(ref_i>=first_i & ref_i<=last_i);
+        end
+        % increment i is defined: processing is done on first_i:incr_i:last_i;
+    else
+        ref_i=first_i:incr_i:last_i;
+        if isempty(incr_j)% automatic finding of the existing j indices
+            [ref_j,tild]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
+            ref_j=ref_j-1;
+            ref_j=ref_j(ref_j>=first_j & ref_j<=last_j);
+        else
+            ref_j=first_j:incr_j:last_j;
+        end
+    end
+    CPUTime=1; % job time estimated at 1 min per iteration (on index i and j) by default
+    if isfield(Param.Action, 'CPUTime') && ~isempty(Param.Action.CPUTime)
+        CPUTime=Param.Action.CPUTime; % Note: CpUTime for one iteration ref_i has to be multiplied by the number of j indices nbfield_j
+    end
+    nbfield_j=numel(ref_j); % number of j indices
+    BlockLength=numel(ref_i); % by default, job involves the full set of i field indices
+    NbProcess=1;
+    switch RunMode
+        case 'cluster'
+            JobNumberMax=SeriesData.SeriesParam.ClusterParam.JobNumberMax;
+            JobCPUTimeAdvised=SeriesData.SeriesParam.ClusterParam.JobCPUTimeAdvised;
+            if isempty(Param.IndexRange.NbSlice)% if NbSlice is not defined
+                BlockLength= ceil(JobCPUTimeAdvised/(CPUTime*nbfield_j)); % iterations are grouped in sets with length BlockLength  such that the typical CPU time of a job is JobCPUTimeAdvised.
+                BlockLength=max(BlockLength,ceil(numel(ref_i)*NbExp/JobNumberMax)); % possibly increase the BlockLength to have less than MaxJobNumber jobs
+                NbProcess=ceil(numel(ref_i)/BlockLength) ; % nbre of processes sent to oar
+            else
+                NbProcess=Param.IndexRange.NbSlice; % the parameter NbSlice sets the nbre of run processes
+            end
+            NbCore=min(NbCore,NbProcess); % reduces the number of cores if it exceeds the number of processes
+        otherwise
+            if ~isempty(Param.IndexRange.NbSlice)
+                NbProcess=Param.IndexRange.NbSlice; % the parameter NbSlice sets the nbre of run processes
+            end
+    end
+    
+    %% record nbre of output files and starting time for computation for status
+    StatusData=get(handles.status,'UserData');
+    if isfield(StatusData,'OutputFileMode')
+        switch StatusData.OutputFileMode
+            case 'NbInput'
+                StatusData.NbOutputFile=numel(ref_i)*nbfield_j;
+            case 'NbInput_i'
+                StatusData.NbOutputFile=numel(ref_i);
+            case 'NbSlice'
+                StatusData.NbOutputFile=str2num(get(handles.num_NbSlice,'String'));
+        end
+    end
+    StatusData.TimeStart=now;
+    set(handles.status,'UserData',StatusData)
+    
+    %% case of a function in Python
+    if strcmp(ActionExt, '.py (in dev.)')
+        fprintf([
+            '\n' ...
+            '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n' ...
+            'The option .py is used. It is still in development.\n' ...
+            'To try it, first install pyper and the most recent version of fluidimage\n' ...
+            '(see https://bitbucket.org/fluiddyn/fluidimage).\n' ...
+            'Warning: there is no direct correspondance between UVMAT and fluidimage parameters\n' ...
+            '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'])
+        RunMode = 'python';
+    end
+    
+    
+    %% direct processing on the current Matlab session or creation of command files
+    filexml=cell(1,NbProcess); % initialisation of the names of the files containing the processing parameters
+    extxml=cell(1,NbProcess); % initialisation of the set of labels used for the files documenting each process
+    for iprocess=1:NbProcess
+        extxml{iprocess}='.xml';
+    end
+    for iprocess=1:NbProcess
+        if ~strcmp(get(handles.RUN,'BusyAction'),'queue')% allow for STOP action
+            disp('program stopped by user')
             return
-        elseif strcmp(answer,'Yes')
-            detect=0;
-            check_create=0;
-        else
-            r=regexp(SubDirOutNew,'(?<root>.*\D)(?<num1>\d+)$','names'); % detect whether name ends by a number
-            if isempty(r)
-                r(1).root=[SubDirOutNew '_'];
-                r(1).num1='0';
-            end
-            SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)]; % increment the index by 1 or put 1
-            detect=exist(fullfile(Param.InputTable{1,1},SubDirOutNew),'dir'); % test if  the dir  already exists
-            check_create=1;
-        end
-    end
-    Param.OutputDirExt=regexprep(SubDirOutNew,Param.OutputSubDir,'');
-    Param.OutputRootFile=Param.InputTable{1,3}; % the first sorted RootFile taken for output
-    set(handles.OutputDirExt,'String',Param.OutputDirExt)
-    OutputDir=fullfile(Param.InputTable{1,1},[Param.OutputSubDir Param.OutputDirExt]); % full name (with path) of output directory
-    if check_create    % create output directory if it does not exist
-        [tild,msg1]=mkdir(OutputDir);
-        if ~strcmp(msg1,'')
-            errormsg=['cannot create ' OutputDir ': ' msg1]; % error message for directory creation
-            return
+        end
+        if isempty(Param.IndexRange.NbSlice)
+            Param.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i;
+            if Param.IndexRange.first_i>last_i
+                NbProcess=iprocess-1; % leave the loop, we are at the end of the calculation
+                break
+            end
+            Param.IndexRange.last_i=min(last_i,first_i+(iprocess)*BlockLength*incr_i-1);
+        else %multislices (then incr_i is not empty)
+            Param.IndexRange.first_i= first_i+iprocess-1;
+            Param.IndexRange.incr_i=incr_i*Param.IndexRange.NbSlice;
+        end
+        for ilist=1:size(Param.InputTable,1)
+            Param.InputTable{ilist,1}=regexprep(Param.InputTable{ilist,1},'\','/'); % correct path name for PCWIN system
+        end
+        
+        if isfield(Param,'OutputSubDir')
+            t=struct2xml(Param);
+            t=set(t,1,'name','Series');
+            extxml{iprocess}=fullfile_uvmat('','',Param.InputTable{1,3},'.xml',OutputNomType,...
+                Param.IndexRange.first_i,Param.IndexRange.last_i,first_j,last_j);
+            filexml{iprocess}=fullfile(OutputDir,'0_XML',extxml{iprocess});
+            try
+                save(t, filexml{iprocess}); % save the xml file containing the processing parameters
+            catch ME
+                if ~strcmp (RunMode,'local')
+                    errormsg=['error writting ' filexml{iprocess} ': ' ME.message];
+                    return
+                end
+            end
+        end
+        if strcmp (RunMode,'local')
+            switch ActionExt
+                case '.m'
+                    h_fun(Param); % direct launching
+                    
+                case '.sh'
+                    switch computer
+                        case {'PCWIN','PCWIN64'} %Windows system
+                            filexml=regexprep(filexml,'\\','\\\\'); % add '\' so that '\' are left as characters
+                            system([ActionFullName ' ' RunTime ' ' filexml{iprocess}]); % TODO: adapt to DOS system
+                        case {'GLNX86','GLNXA64','MACI64'}%Linux  system
+                            system([ActionFullName ' ' RunTime ' ' filexml{iprocess}]);
+                    end
+            end
         end
     end
     
-elseif isfield(Param,'ActionInput')&&isfield(Param.ActionInput,'LogPath')% custom definition of the output dir
-    OutputDir=Param.ActionInput.LogPath;   
-end
-DirXml=fullfile(OutputDir,'0_XML');
-if ~exist(DirXml,'dir')
-    [~,msg1]=mkdir(DirXml);
-    if ~strcmp(msg1,'')
-        errormsg=['cannot create ' DirXml ': ' msg1]; % error message for directory creation
-        return
-    end
-end
-OutputNomType=nomtype2pair(Param.InputTable{1,4}); % nomenclature for output files
-
-%% get the set of reference input field indices 
-first_i=1; % first i index to process
-last_i=1; % last i index to process
-incr_i=1; % increment step in i index
-first_j=1; % first j index to process
-last_j=1; % last j index to process
-incr_j=1; % increment step in j index
-if isfield(Param.IndexRange,'first_i')
-    first_i=Param.IndexRange.first_i;
-    incr_i=Param.IndexRange.incr_i;
-    last_i=Param.IndexRange.last_i;
-end
-if isfield(Param.IndexRange,'incr_j')
-    first_j=Param.IndexRange.first_j;
-    last_j=Param.IndexRange.last_j;
-    incr_j=Param.IndexRange.incr_j;
-end
-if last_i < first_i || last_j < first_j
-    errormsg= 'series/Run_Callback:last field index must be larger or equal to the first one';
-    return
-end
-%incr_i must be defined, =1 by default, if NbSlice is active
-if isempty(incr_i)&& ~isempty(Param.IndexRange.NbSlice)
-    incr_i=1;
-    set(handles.num_incr_i,'String','1')
-end
-% case of no increment i defined: processing is done on the available files found in i1_series
-if isempty(incr_i)
-    if isempty(incr_j)
-        [ref_j,ref_i]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
-        ref_j=ref_j(ref_j>=first_j & ref_j<=last_j);
-        ref_i=ref_i(ref_i>=first_i & ref_i<=last_i);
-        ref_j=ref_j-1;
-        ref_i=ref_i-1;
-    else
-        ref_j=first_j:incr_j:last_j;
-        [tild,ref_i]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
-        ref_i=ref_i-1;
-        ref_i=ref_i(ref_i>=first_i & ref_i<=last_i);
-    end
-    % increment i is defined: processing is done on first_i:incr_i:last_i;
-else
-    ref_i=first_i:incr_i:last_i;
-    if isempty(incr_j)% automatic finding of the existing j indices
-        [ref_j,tild]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
-        ref_j=ref_j-1;
-        ref_j=ref_j(ref_j>=first_j & ref_j<=last_j);
-    else
-        ref_j=first_j:incr_j:last_j;
-    end
-end
-CPUTime=1; % job time estimated at 1 min per iteration (on index i and j) by default
-if isfield(Param.Action, 'CPUTime') && ~isempty(Param.Action.CPUTime)
-    CPUTime=Param.Action.CPUTime; % Note: CpUTime for one iteration ref_i has to be multiplied by the number of j indices nbfield_j
-end
-nbfield_j=numel(ref_j); % number of j indices
-BlockLength=numel(ref_i); % by default, job involves the full set of i field indices
-NbProcess=1;
-switch RunMode
-    case 'cluster'
-        JobNumberMax=SeriesData.SeriesParam.ClusterParam.JobNumberMax;
-        JobCPUTimeAdvised=SeriesData.SeriesParam.ClusterParam.JobCPUTimeAdvised;
-        if isempty(Param.IndexRange.NbSlice)% if NbSlice is not defined
-            BlockLength= ceil(JobCPUTimeAdvised/(CPUTime*nbfield_j)); % iterations are grouped in sets with length BlockLength  such that the typical CPU time of a job is MinJobNumber.
-            BlockLength=max(BlockLength,ceil(numel(ref_i)/JobNumberMax)); % possibly increase the BlockLength to have less than MaxJobNumber jobs
-            NbProcess=ceil(numel(ref_i)/BlockLength) ; % nbre of processes sent to oar
-        else
-            NbProcess=Param.IndexRange.NbSlice; % the parameter NbSlice sets the nbre of run processes
-        end
-        NbCore=min(NbCore,NbProcess); % reduces the number of cores if it exceeds the number of processes
-    otherwise
-        if ~isempty(Param.IndexRange.NbSlice)
-            NbProcess=Param.IndexRange.NbSlice; % the parameter NbSlice sets the nbre of run processes
-        end
-end
-
-%% record nbre of output files and starting time for computation for status
-StatusData=get(handles.status,'UserData');
-if isfield(StatusData,'OutputFileMode')
-    switch StatusData.OutputFileMode
-        case 'NbInput'
-            StatusData.NbOutputFile=numel(ref_i)*nbfield_j;
-        case 'NbInput_i'
-            StatusData.NbOutputFile=numel(ref_i);
-        case 'NbSlice'
-            StatusData.NbOutputFile=str2num(get(handles.num_NbSlice,'String'));
-    end
-end
-StatusData.TimeStart=now;
-set(handles.status,'UserData',StatusData)
-
-%% case of a function in Python
-if strcmp(ActionExt, '.py (in dev.)')
-    fprintf([
-        '\n' ...
-        '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n' ...
-        'The option .py is used. It is still in development.\n' ...
-        'To try it, first install pyper and the most recent version of fluidimage\n' ...
-        '(see https://bitbucket.org/fluiddyn/fluidimage).\n' ...
-        'Warning: there is no direct correspondance between UVMAT and fluidimage parameters\n' ...
-        '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'])
-    RunMode = 'python';
-end
-
-
-%% direct processing on the current Matlab session or creation of command files
-filexml=cell(1,NbProcess); % initialisation of the names of the files containing the processing parameters
-extxml=cell(1,NbProcess); % initialisation of the set of labels used for the files documenting each process
-for iprocess=1:NbProcess
-    extxml{iprocess}='.xml';
-end
-for iprocess=1:NbProcess
-    if ~strcmp(get(handles.RUN,'BusyAction'),'queue')% allow for STOP action
-        disp('program stopped by user')
-        return
-    end
-    if isempty(Param.IndexRange.NbSlice)
-        Param.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i;
-        if Param.IndexRange.first_i>last_i
-            NbProcess=iprocess-1; % leave the loop, we are at the end of the calculation
-            break
-        end
-        Param.IndexRange.last_i=min(last_i,first_i+(iprocess)*BlockLength*incr_i-1);
-    else %multislices (then incr_i is not empty)
-        Param.IndexRange.first_i= first_i+iprocess-1;
-        Param.IndexRange.incr_i=incr_i*Param.IndexRange.NbSlice;
-    end
-    for ilist=1:size(Param.InputTable,1)
-        Param.InputTable{ilist,1}=regexprep(Param.InputTable{ilist,1},'\','/'); % correct path name for PCWIN system
+    if ~strcmp (RunMode,'local') && ~strcmp(RunMode,'python')
+        %% processing on a different session of the same computer (background) or cluster, create executable files
+        batch_file_list=cell(NbProcess,1); % initiate the list of executable files
+        DirExe=fullfile(OutputDir,'0_EXE'); % directory name for executable files
+        switch computer
+            case {'PCWIN','PCWIN64'} %Windows system
+                ExeExt='.bat';
+            case {'GLNX86','GLNXA64','MACI64'}%Linux  system
+                ExeExt='.sh';
+        end
+        %create subdirectory for executable files
+        if ~exist(DirExe,'dir')
+            [tild,msg1]=mkdir(DirExe);
+            if ~strcmp(msg1,'')
+                errormsg=['cannot create ' DirExe ': ' msg1]; % error message for directory creation
+                return
+            end
+        end
+        %create subdirectory for log files
+        DirLog=fullfile(OutputDir,'0_LOG');
+        if ~exist(DirLog,'dir')
+            [tild,msg1]=mkdir(DirLog);
+            if ~strcmp(msg1,'')
+                errormsg=['cannot create ' DirLog ': ' msg1]; % error message for directory creation
+                return
+            end
+        end
+        
+        %create the executable file
+        file_exe_global=fullfile_uvmat('','',Param.InputTable{1,3},ExeExt,OutputNomType,...
+            first_i,last_i,first_j,last_j);
+        file_exe_global=fullfile(OutputDir,'0_EXE',file_exe_global);
+        filelog_global=fullfile_uvmat('','',Param.InputTable{1,3},'.log',OutputNomType,...
+            first_i,last_i,first_j,last_j);
+        filelog_global=fullfile(OutputDir,'0_LOG',filelog_global);
+        
+        for iprocess=1:NbProcess
+            %create the executable file
+            batch_file_list{iprocess}=fullfile(OutputDir,'0_EXE',regexprep(extxml{iprocess},'.xml$',ExeExt));
+            
+            % set the log file name
+            filelog{iprocess}=fullfile(OutputDir,'0_LOG',regexprep(extxml{iprocess},'.xml$','.log'));
+        end
     end
     
-    if isfield(Param,'OutputSubDir')
-        t=struct2xml(Param);
-        t=set(t,1,'name','Series');
-        extxml{iprocess}=fullfile_uvmat('','',Param.InputTable{1,3},'.xml',OutputNomType,...
-            Param.IndexRange.first_i,Param.IndexRange.last_i,first_j,last_j);
-        filexml{iprocess}=fullfile(OutputDir,'0_XML',extxml{iprocess});
-        try
-            save(t, filexml{iprocess}); % save the xml file containing the processing parameters
-        catch ME
-            if ~strcmp (RunMode,'local')
-                errormsg=['error writting ' filexml{iprocess} ': ' ME.message];
+    %% launch the executable files for background or cluster processing
+    
+    switch RunMode
+        
+        case 'background'
+            [fid,message]=fopen(file_exe_global,'w');
+            if isequal(fid,-1)
+                errormsg=['creation of ' file_exe_global ':' message];
                 return
             end
-        end
-    end
-    if strcmp (RunMode,'local')
-        switch ActionExt
-            case '.m'
-                h_fun(Param); % direct launching
-                
-            case '.sh'
-                switch computer
-                    case {'PCWIN','PCWIN64'} %Windows system
-                        filexml=regexprep(filexml,'\\','\\\\'); % add '\' so that '\' are left as characters
-                        system([ActionFullName ' ' RunTime ' ' filexml{iprocess}]); % TODO: adapt to DOS system
-                    case {'GLNX86','GLNXA64','MACI64'}%Linux  system
-                        system([ActionFullName ' ' RunTime ' ' filexml{iprocess}]);
-                end
-        end
-    end
-end
-
-if ~strcmp (RunMode,'local') && ~strcmp(RunMode,'python')
-    %% processing on a different session of the same computer (background) or cluster, create executable files
-    batch_file_list=cell(NbProcess,1); % initiate the list of executable files
-    DirExe=fullfile(OutputDir,'0_EXE'); % directory name for executable files
-    switch computer
-        case {'PCWIN','PCWIN64'} %Windows system
-            ExeExt='.bat';
-        case {'GLNX86','GLNXA64','MACI64'}%Linux  system
-            ExeExt='.sh';
-    end
-    %create subdirectory for executable files
-    if ~exist(DirExe,'dir')
-        [tild,msg1]=mkdir(DirExe);
-        if ~strcmp(msg1,'')
-            errormsg=['cannot create ' DirExe ': ' msg1]; % error message for directory creation
-            return
-        end
-    end
-    %create subdirectory for log files
-    DirLog=fullfile(OutputDir,'0_LOG');
-    if ~exist(DirLog,'dir')
-        [tild,msg1]=mkdir(DirLog);
-        if ~strcmp(msg1,'')
-            errormsg=['cannot create ' DirLog ': ' msg1]; % error message for directory creation
-            return
-        end
-    end
-    
-    %create the executable file
-    file_exe_global=fullfile_uvmat('','',Param.InputTable{1,3},ExeExt,OutputNomType,...
-        first_i,last_i,first_j,last_j);
-    file_exe_global=fullfile(OutputDir,'0_EXE',file_exe_global);
-    filelog_global=fullfile_uvmat('','',Param.InputTable{1,3},'.log',OutputNomType,...
-        first_i,last_i,first_j,last_j);
-    filelog_global=fullfile(OutputDir,'0_LOG',filelog_global);
-
-    for iprocess=1:NbProcess    
-        %create the executable file       
-        batch_file_list{iprocess}=fullfile(OutputDir,'0_EXE',regexprep(extxml{iprocess},'.xml$',ExeExt));
-        
-        % set the log file name
-        filelog{iprocess}=fullfile(OutputDir,'0_LOG',regexprep(extxml{iprocess},'.xml$','.log'));      
-    end
-end
-
-%% launch the executable files for background or cluster processing
-
-switch RunMode
-    
-    case 'background'
-        [fid,message]=fopen(file_exe_global,'w');
-        if isequal(fid,-1)
-            errormsg=['creation of ' file_exe_global ':' message];
-            return
-        end
-        switch ActionExt
-            case '.m'% Matlab function
-                switch computer
-                    case {'GLNX86','GLNXA64','MACI64'}
-                        matlab_ver = ver('MATLAB');
-                        matlab_version = matlab_ver.Version;
-                        cmd=[...
-                            '#!/bin/bash\n'...
-                            'source /etc/profile\n'...
-                            'module load matlab/' matlab_version '\n'...% CHOICE OF MATLAB VERSION
-                            'time_start=$(date +%%s)\n'...
-                            'matlab -nodisplay -nosplash -nojvm -logfile ''' filelog_global ''' <<END_MATLAB\n'...
-                            'addpath(''' path_series ''');\n'...
-                            'addpath(''' Param.Action.ActionPath ''');\n'];
-                        for iprocess=1:NbProcess
-                            cmd=[cmd '' Param.Action.ActionName  '(''' filexml{iprocess} ''');\n'];
-                        end
-                        cmd=[cmd  'exit\n' 'END_MATLAB\n'...
-                            'time_end=$(date +%%s)\n'...
-                            'echo "global time = " $(($time_end - $time_start)) >> ''' filelog_global '''\n'];
-                        fprintf(fid,cmd); % fill the executable file with the  char string cmd
-                        fclose(fid); % close the executable filefilelog_global
-                        system(['chmod +x ' file_exe_global]); % set the file to executable
-                    case {'PCWIN','PCWIN64'}
-                        cmd=['matlab -automation -logfile ' regexprep(filelog{iprocess},'\\','\\\\')...
-                            ' -r "addpath(''' regexprep(path_series,'\\','\\\\') ''');'...
-                            'addpath(''' regexprep(Param.Action.ActionPath,'\\','\\\\') ''');'];
-                        for iprocess=1:NbProcess
-                            cmd=[cmd '' Param.Action.ActionName  '( ''' regexprep(filexml{iprocess},'\\','\\\\') ''');']
-                        end
-                        cmd=[cmd ';exit"'];
-                        fprintf(fid,cmd); % fill the executable file with the  char string cmd
-                        fclose(fid); % close the executable file
-                end
-                system([file_exe_global ' &'])% directly execute the command file
-            case '.sh' % compiled Matlab function
-                for iprocess=1:NbProcess
+            switch ActionExt
+                case '.m'% Matlab function
                     switch computer
                         case {'GLNX86','GLNXA64','MACI64'}
-                            [fid,message]=fopen(batch_file_list{iprocess},'w'); % create the executable file
-                            if isequal(fid,-1)
-                                errormsg=['creation of .bat file: ' message];
-                                return
+                            matlab_ver = ver('MATLAB');
+                            matlab_version = matlab_ver.Version;
+                            cmd=[...
+                                '#!/bin/bash\n'...
+                                'source /etc/profile\n'...
+                                'module load matlab/' matlab_version '\n'...% CHOICE OF MATLAB VERSION
+                                'time_start=$(date +%%s)\n'...
+                                'matlab -nodisplay -nosplash -nojvm -logfile ''' filelog_global ''' <<END_MATLAB\n'...
+                                'addpath(''' path_series ''');\n'...
+                                'addpath(''' Param.Action.ActionPath ''');\n'];
+                            for iprocess=1:NbProcess
+                                cmd=[cmd '' Param.Action.ActionName  '(''' filexml{iprocess} ''');\n'];
                             end
-                            cmd=['#!/bin/bash \n '...
-                                '#$ -cwd \n '...
-                                'hostname && date \n '...
-                                'umask 002 \n'...
-                                ActionFullName ' ' RunTime ' ' filexml{iprocess}]; % allow writting access to created files for user group
+                            cmd=[cmd  'exit\n' 'END_MATLAB\n'...
+                                'time_end=$(date +%%s)\n'...
+                                'echo "global time = " $(($time_end - $time_start)) >> ''' filelog_global '''\n'];
+                            fprintf(fid,cmd); % fill the executable file with the  char string cmd
+                            fclose(fid); % close the executable filefilelog_global
+                            system(['chmod +x ' file_exe_global]); % set the file to executable
+                        case {'PCWIN','PCWIN64'}
+                            cmd=['matlab -automation -logfile ' regexprep(filelog{iprocess},'\\','\\\\')...
+                                ' -r "addpath(''' regexprep(path_series,'\\','\\\\') ''');'...
+                                'addpath(''' regexprep(Param.Action.ActionPath,'\\','\\\\') ''');'];
+                            for iprocess=1:NbProcess
+                                cmd=[cmd '' Param.Action.ActionName  '( ''' regexprep(filexml{iprocess},'\\','\\\\') ''');']
+                            end
+                            cmd=[cmd ';exit"'];
                             fprintf(fid,cmd); % fill the executable file with the  char string cmd
                             fclose(fid); % close the executable file
-                            system(['chmod +x ' batch_file_list{iprocess}]); % set the file to executable
-                            system([batch_file_list{iprocess} ' &'])% directly execute the command file
-                        case {'PCWIN','PCWIN64'}
-                            msgbox_uvmat('ERROR','option for compiled Matlab functions not implemented for Windows system')
-                            return
                     end
+                    system([file_exe_global ' &'])% directly execute the command file
+                case '.sh' % compiled Matlab function
+                    for iprocess=1:NbProcess
+                        switch computer
+                            case {'GLNX86','GLNXA64','MACI64'}
+                                [fid,message]=fopen(batch_file_list{iprocess},'w'); % create the executable file
+                                if isequal(fid,-1)
+                                    errormsg=['creation of .bat file: ' message];
+                                    return
+                                end
+                                cmd=['#!/bin/bash \n '...
+                                    '#$ -cwd \n '...
+                                    'hostname && date \n '...
+                                    'umask 002 \n'...
+                                    ActionFullName ' ' RunTime ' ' filexml{iprocess}]; % allow writting access to created files for user group
+                                fprintf(fid,cmd); % fill the executable file with the  char string cmd
+                                fclose(fid); % close the executable file
+                                system(['chmod +x ' batch_file_list{iprocess}]); % set the file to executable
+                                system([batch_file_list{iprocess} ' &'])% directly execute the command file
+                            case {'PCWIN','PCWIN64'}
+                                msgbox_uvmat('ERROR','option for compiled Matlab functions not implemented for Windows system')
+                                return
+                        end
+                    end
+                    msgbox_uvmat('CONFIRMATION',[ActionFullName ' launched in background for ' ExpName ': press STATUS to see results'])
+            end
+            
+        case 'cluster' % option 'oar-parexec' used
+            %create subdirectory for oar commands
+            for iprocess=1:NbProcess
+                [fid,message]=fopen(batch_file_list{iprocess},'w'); % create the executable file
+                if isequal(fid,-1)
+                    errormsg=['creation of .bat file: ' message];
+                    return
                 end
-                msgbox_uvmat('CONFIRMATION',[ActionFullName ' launched in background: press STATUS to see results'])
-        end
-        
-    case 'cluster' % option 'oar-parexec' used
-        %create subdirectory for oar commands
-        for iprocess=1:NbProcess
-            [fid,message]=fopen(batch_file_list{iprocess},'w'); % create the executable file
-            if isequal(fid,-1)
-                errormsg=['creation of .bat file: ' message];
-                return
-            end
-            if  strcmp(ActionExt,'.sh')
-                cmd=['#!/bin/bash \n '...
-                    '#$ -cwd \n '...
-                    'hostname && date \n '...
-                    'umask 002 \n'...
-                    ActionFullName ' ' RunTime ' ' filexml{iprocess}]; % allow writting access to created files for user group
+                if  strcmp(ActionExt,'.sh')
+                    cmd=['#!/bin/bash \n '...
+                        '#$ -cwd \n '...
+                        'hostname && date \n '...
+                        'umask 002 \n'...
+                        ActionFullName ' ' RunTime ' ' filexml{iprocess}]; % allow writting access to created files for user group
+                else
+                    matlab_ver = ver('MATLAB');
+                    matlab_version = matlab_ver.Version;
+                    cmd=[...
+                        '#!/bin/bash\n'...
+                        'source /etc/profile\n'...
+                        'module load matlab/' matlab_version '\n'...% CHOICE OF MATLAB VERSION
+                        'matlab -nodisplay -nosplash -nojvm -singleCompThread -logfile ''' filelog{iprocess} ''' <<END_MATLAB\n'...
+                        'addpath(''' path_series ''');\n'...
+                        'addpath(''' Param.Action.ActionPath ''');\n'...
+                        '' Param.Action.ActionName  '(''' filexml{iprocess} ''');\n'...
+                        'exit\n'...
+                        'END_MATLAB\n'];
+                end
+                fprintf(fid,cmd); % fill the executable file with the  char string cmd
+                fclose(fid); % close the executable file
+                system(['chmod +x ' batch_file_list{iprocess}]); % set the file to executable
+            end
+            DIR_CLUSTER=fullfile(OutputDir,'0_CLUSTER');
+            if exist(DIR_CLUSTER,'dir')% delete the content of the dir 0_LOG to allow new input
+                curdir=pwd;
+                cd(DIR_CLUSTER)
+                delete('*')
+                cd(curdir)
             else
-                matlab_ver = ver('MATLAB');
-                matlab_version = matlab_ver.Version;
-                cmd=[...
-                    '#!/bin/bash\n'...
-                    'source /etc/profile\n'...
-                    'module load matlab/' matlab_version '\n'...% CHOICE OF MATLAB VERSION
-                    'matlab -nodisplay -nosplash -nojvm -singleCompThread -logfile ''' filelog{iprocess} ''' <<END_MATLAB\n'...
-                    'addpath(''' path_series ''');\n'...
-                    'addpath(''' Param.Action.ActionPath ''');\n'...
-                    '' Param.Action.ActionName  '(''' filexml{iprocess} ''');\n'...
-                    'exit\n'...
-                    'END_MATLAB\n'];
-            end
-            fprintf(fid,cmd); % fill the executable file with the  char string cmd
-            fclose(fid); % close the executable file
-            system(['chmod +x ' batch_file_list{iprocess}]); % set the file to executable
-        end
-        DIR_CLUSTER=fullfile(OutputDir,'0_CLUSTER');
-        if exist(DIR_CLUSTER,'dir')% delete the content of the dir 0_LOG to allow new input
-            curdir=pwd;
-            cd(DIR_CLUSTER)
-            delete('*')
-            cd(curdir)
-        else
-            [tild,msg1]=mkdir(DIR_CLUSTER);
-            if ~strcmp(msg1,'')
-                errormsg=['cannot create ' DIR_CLUSTER ': ' msg1]; % error message for directory creation
-                return
-            end
-        end
-        % create file containing the list of jobs
-        ListProcess=fullfile(DIR_CLUSTER,'job_list.txt'); % name of the file containing the list of executables
-        fid=fopen(ListProcess,'w'); % open it for writting
-        for iprocess=1:length(batch_file_list)
-            fprintf(fid,[batch_file_list{iprocess} '\n']); % write list of exe files
-        end
-        fclose(fid);
-        system(['chmod +x ' ListProcess]); % set the file to executable
- 
-        CPUTimeProcess=CPUTime*BlockLength*nbfield_j; % estimated CPU time for one individual process (in minutes)
-        LaunchCmdFcn=SeriesData.SeriesParam.ClusterParam.LaunchCmdFcn;
-        oar_command=feval(LaunchCmdFcn,ListProcess,ActionFullName,DirLog,NbProcess, NbCore,CPUTimeProcess)
-        [status,result]=system(oar_command)% execute system command and show the result (ID number of the launched job) on the Matlab command window
-        filename_oarcommand=fullfile(DIR_CLUSTER,'0_cluster_command'); % keep track of the command in file '0-OAR/0_cluster_command'
-        fid=fopen(filename_oarcommand,'w');
-        fprintf(fid,oar_command); % store the command
-        fprintf(fid,result); % store the result (job ID number)
-        fclose(fid);
-        msgbox_uvmat('CONFIRMATION',[ActionFullName ' launched as  ' num2str(NbProcess) ' processes in cluster: press STATUS to see results'])
-        
-%     case 'cluster_pbs' % for LMFA Kepler machine:  trqnsferred to fct 
-
-%         %create subdirectory for pbs command and log files
-%         DirPBS=fullfile(OutputDir,'0_PBS'); % todo : common name OAR/PBS
-%         if exist(DirPBS,'dir')% delete the content of the dir 0_LOG to allow new input
-%             curdir=pwd;
-%             cd(DirPBS)
-%             delete('*')
-%             cd(curdir)
-%         else
-%             [tild,msg1]=mkdir(DirPBS);
-%             if ~strcmp(msg1,'')
-%                 errormsg=['cannot create ' DirPBS ': ' msg1]; % error message for directory creation
-%                 return
-%             end
-%         end
-%         max_walltime=3600*20; % 20h max total calculation (cannot exceed 24 h)
-%         walltime_onejob=1800; % seconds, max estimated time for asingle file index value
-%         ListProcess=fullfile(DirPBS,'job_list.txt'); % create name of the global executable file
-%         fid=fopen(ListProcess,'w');
-%         for iprocess=1:length(batch_file_list)
-%             fprintf(fid,[batch_file_list{iprocess} '\n']); % list of exe files
-%         end
-%         fclose(fid);
-%         system(['chmod +x ' ListProcess]); % set the file to executable
-%         pbs_command=['qsub -n CIVX '...
-%             '-t idempotent --checkpoint ' num2str(walltime_onejob+60) ' '...
-%             '-l /core=' num2str(NbCore) ','...
-%             'walltime=' datestr(min(1.05*walltime_onejob/86400*max(NbProcess*BlockLength*nbfield_j,NbCore)/NbCore,max_walltime/86400),13) ' '...
-%             '-E ' regexprep(ListProcess,'\.txt\>','.stderr') ' '...
-%             '-O ' regexprep(ListProcess,'\.txt\>','.log') ' '...
-%             extra_qstat ' '...
-%             '"oar-parexec -s -f ' ListProcess ' '...
-%             '-l ' ListProcess '.log"'];
-%         filename_oarcommand=fullfile(DirPBS,'pbs_command');
-%         fid=fopen(filename_oarcommand,'w');
-%         fprintf(fid,pbs_command);
-%         fclose(fid);
-%         fprintf(pbs_command); % display in command line
-%         %system(pbs_command);
-%         msgbox_uvmat('CONFIRMATION',[ActionFullName ' command ready to be launched in cluster'])
-
-     case 'cluster_sge' % for PSMN % TODO: use the standard 'cluster' config with an external fct
-        % Au PSMN, on ne cr??e pas 1 job avec plusieurs c??urs, mais N jobs de 1 c??urs
-        % o?? N < 1000.
-        %create subdirectory for pbs command and log files
-
-        DirSGE=fullfile(OutputDir,'0_SGE');
-        if exist(DirSGE,'dir')% delete the content of the dir 0_LOG to allow new input
-            curdir=pwd;
-            cd(DirSGE)
-            delete('*')
-            cd(curdir)
-        else
-            [tild,msg1]=mkdir(DirSGE);
-            if ~strcmp(msg1,'')
-                errormsg=['cannot create ' DirSGE ': ' msg1]; % error message for directory creation
-                return
-            end
-        end
-        maxImgsPerJob = ceil(length(batch_file_list)/NbCore);
-        disp(['Max number of jobs: ' num2str(NbCore)])
-        disp(['Images per job: ' num2str(maxImgsPerJob)])
-        
-        iprocess = 1;
-        imgsInJob = [];
-        currJobIndex = 1;
-        done = 0;
-        while(~done)
-            if(iprocess <= length(batch_file_list))
-                imgsInJob = [imgsInJob, iprocess];
-            end
-            if((numel(imgsInJob) >= maxImgsPerJob) || (iprocess == length(batch_file_list)))
-                cmd=['#!/bin/sh \n'...
-                     '#$ -cwd \n'...
-                     'hostname && date\n']
-                for ii=1:numel(imgsInJob)
-                    cmd=[cmd ActionFullName ' /softs/matlab ' filexml{imgsInJob(ii)} '\n'];
+                [tild,msg1]=mkdir(DIR_CLUSTER);
+                if ~strcmp(msg1,'')
+                    errormsg=['cannot create ' DIR_CLUSTER ': ' msg1]; % error message for directory creation
+                    return
                 end
-                [fid, message] = fopen([DirSGE '/job' num2str(currJobIndex) '.sh'], 'w');
-                fprintf(fid, cmd);
-                fclose(fid);
-                system(['chmod +x ' DirSGE '/job' num2str(currJobIndex) '.sh'])
-                sge_command=['qsub -N civ_' num2str(currJobIndex) ' '...
-                    '-q ' qstat_Queue ' '...
-                    '-e ' fullfile([DirSGE '/job' num2str(currJobIndex) '.out']) ' '...
-                    '-o ' fullfile([DirSGE '/job' num2str(currJobIndex) '.out']) ' '...
-                    fullfile([DirSGE '/job' num2str(currJobIndex) '.sh'])];
-                fprintf(sge_command); % display in command line
-                [status, result] = system(sge_command);
-                fprintf(result);
-                currJobIndex = currJobIndex + 1;
-                imgsInJob = [];
-            end
-            if(iprocess == length(batch_file_list))
-                done = 1;
-            end
-            iprocess = iprocess + 1;
-        end
-        msgbox_uvmat('CONFIRMATION',[num2str(currJobIndex-1) ' jobs launched on queue ' qstat_Queue '.'])
-    case 'python'
-        command = ['LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | pyp "l = x.split('':''); l = [s for s in l if ''matlab'' not in s]; print('':''.join(l))") ' ...
-            'python -m fluidimage.run_from_xml ' filexml{iprocess}];
-        fprintf(['command:\n' command '\n\n'])
-        system(command, '-echo');
-end
-if exist(OutputDir,'dir')
-    [SUCCESS,MESSAGE,MESSAGEID] = fileattrib (OutputDir);
-    if MESSAGE.GroupWrite~=1
-    [success,msg] = fileattrib(OutputDir,'+w','g','s'); % allow writing access for the group of users, recursively in the folder
-    if success==0
-        msgbox_uvmat('WARNING',{['unable to set group write access to ' OutputDir ':']; msg}); % error message for directory creation
-    end
-    end
-end
-
+            end
+            % create file containing the list of jobs
+            ListProcess=fullfile(DIR_CLUSTER,'job_list.txt'); % name of the file containing the list of executables
+            fid=fopen(ListProcess,'w'); % open it for writting
+            for iprocess=1:length(batch_file_list)
+                fprintf(fid,[batch_file_list{iprocess} '\n']); % write list of exe files
+            end
+            fclose(fid);
+            system(['chmod +x ' ListProcess]); % set the file to executable
+            
+            CPUTimeProcess=CPUTime*BlockLength*nbfield_j; % estimated CPU time for one individual process (in minutes)
+            LaunchCmdFcn=SeriesData.SeriesParam.ClusterParam.LaunchCmdFcn;
+            oar_command=feval(LaunchCmdFcn,ListProcess,ActionFullName,DirLog,NbProcess, NbCore,CPUTimeProcess)
+            [status,result]=system(oar_command)% execute system command and show the result (ID number of the launched job) on the Matlab command window
+            filename_oarcommand=fullfile(DIR_CLUSTER,'0_cluster_command'); % keep track of the command in file '0-OAR/0_cluster_command'
+            fid=fopen(filename_oarcommand,'w');
+            fprintf(fid,oar_command); % store the command
+            fprintf(fid,result); % store the result (job ID number)
+            fclose(fid);
+            if status==0
+            msgbox_uvmat('CONFIRMATION',[ActionFullName ' launched for ' ExpName ' as ' num2str(NbProcess) ' processes in cluster: press STATUS to see results'])
+            else
+               msgbox_uvmat('ERROR',result) 
+            end
+            %     case 'cluster_pbs' % for LMFA Kepler machine:  trqnsferred to fct
+            
+            %         %create subdirectory for pbs command and log files
+            %         DirPBS=fullfile(OutputDir,'0_PBS'); % todo : common name OAR/PBS
+            %         if exist(DirPBS,'dir')% delete the content of the dir 0_LOG to allow new input
+            %             curdir=pwd;
+            %             cd(DirPBS)
+            %             delete('*')
+            %             cd(curdir)
+            %         else
+            %             [tild,msg1]=mkdir(DirPBS);
+            %             if ~strcmp(msg1,'')
+            %                 errormsg=['cannot create ' DirPBS ': ' msg1]; % error message for directory creation
+            %                 return
+            %             end
+            %         end
+            %         max_walltime=3600*20; % 20h max total calculation (cannot exceed 24 h)
+            %         walltime_onejob=1800; % seconds, max estimated time for asingle file index value
+            %         ListProcess=fullfile(DirPBS,'job_list.txt'); % create name of the global executable file
+            %         fid=fopen(ListProcess,'w');
+            %         for iprocess=1:length(batch_file_list)
+            %             fprintf(fid,[batch_file_list{iprocess} '\n']); % list of exe files
+            %         end
+            %         fclose(fid);
+            %         system(['chmod +x ' ListProcess]); % set the file to executable
+            %         pbs_command=['qsub -n CIVX '...
+            %             '-t idempotent --checkpoint ' num2str(walltime_onejob+60) ' '...
+            %             '-l /core=' num2str(NbCore) ','...
+            %             'walltime=' datestr(min(1.05*walltime_onejob/86400*max(NbProcess*BlockLength*nbfield_j,NbCore)/NbCore,max_walltime/86400),13) ' '...
+            %             '-E ' regexprep(ListProcess,'\.txt\>','.stderr') ' '...
+            %             '-O ' regexprep(ListProcess,'\.txt\>','.log') ' '...
+            %             extra_qstat ' '...
+            %             '"oar-parexec -s -f ' ListProcess ' '...
+            %             '-l ' ListProcess '.log"'];
+            %         filename_oarcommand=fullfile(DirPBS,'pbs_command');
+            %         fid=fopen(filename_oarcommand,'w');
+            %         fprintf(fid,pbs_command);
+            %         fclose(fid);
+            %         fprintf(pbs_command); % display in command line
+            %         %system(pbs_command);
+            %         msgbox_uvmat('CONFIRMATION',[ActionFullName ' command ready to be launched in cluster'])
+            
+        case 'cluster_sge' % for PSMN % TODO: use the standard 'cluster' config with an external fct
+            % Au PSMN, on ne cr??e pas 1 job avec plusieurs c??urs, mais N jobs de 1 c??urs
+            % o?? N < 1000.
+            %create subdirectory for pbs command and log files
+            
+            DirSGE=fullfile(OutputDir,'0_SGE');
+            if exist(DirSGE,'dir')% delete the content of the dir 0_LOG to allow new input
+                curdir=pwd;
+                cd(DirSGE)
+                delete('*')
+                cd(curdir)
+            else
+                [tild,msg1]=mkdir(DirSGE);
+                if ~strcmp(msg1,'')
+                    errormsg=['cannot create ' DirSGE ': ' msg1]; % error message for directory creation
+                    return
+                end
+            end
+            maxImgsPerJob = ceil(length(batch_file_list)/NbCore);
+            disp(['Max number of jobs: ' num2str(NbCore)])
+            disp(['Images per job: ' num2str(maxImgsPerJob)])
+            
+            iprocess = 1;
+            imgsInJob = [];
+            currJobIndex = 1;
+            done = 0;
+            while(~done)
+                if(iprocess <= length(batch_file_list))
+                    imgsInJob = [imgsInJob, iprocess];
+                end
+                if((numel(imgsInJob) >= maxImgsPerJob) || (iprocess == length(batch_file_list)))
+                    cmd=['#!/bin/sh \n'...
+                        '#$ -cwd \n'...
+                        'hostname && date\n']
+                    for ii=1:numel(imgsInJob)
+                        cmd=[cmd ActionFullName ' /softs/matlab ' filexml{imgsInJob(ii)} '\n'];
+                    end
+                    [fid, message] = fopen([DirSGE '/job' num2str(currJobIndex) '.sh'], 'w');
+                    fprintf(fid, cmd);
+                    fclose(fid);
+                    system(['chmod +x ' DirSGE '/job' num2str(currJobIndex) '.sh'])
+                    sge_command=['qsub -N civ_' num2str(currJobIndex) ' '...
+                        '-q ' qstat_Queue ' '...
+                        '-e ' fullfile([DirSGE '/job' num2str(currJobIndex) '.out']) ' '...
+                        '-o ' fullfile([DirSGE '/job' num2str(currJobIndex) '.out']) ' '...
+                        fullfile([DirSGE '/job' num2str(currJobIndex) '.sh'])];
+                    fprintf(sge_command); % display in command line
+                    [status, result] = system(sge_command);
+                    fprintf(result);
+                    currJobIndex = currJobIndex + 1;
+                    imgsInJob = [];
+                end
+                if(iprocess == length(batch_file_list))
+                    done = 1;
+                end
+                iprocess = iprocess + 1;
+            end
+            msgbox_uvmat('CONFIRMATION',[num2str(currJobIndex-1) ' jobs launched on queue ' qstat_Queue '.'])
+        case 'python'
+            command = ['LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | pyp "l = x.split('':''); l = [s for s in l if ''matlab'' not in s]; print('':''.join(l))") ' ...
+                'python -m fluidimage.run_from_xml ' filexml{iprocess}];
+            fprintf(['command:\n' command '\n\n'])
+            system(command, '-echo');
+    end
+    if exist(OutputDir,'dir')
+        [SUCCESS,MESSAGE,MESSAGEID] = fileattrib (OutputDir);
+        if MESSAGE.GroupWrite~=1
+            [success,msg] = fileattrib(OutputDir,'+w','g','s'); % allow writing access for the group of users, recursively in the folder
+            if success==0
+                msgbox_uvmat('WARNING',{['unable to set group write access to ' OutputDir ':']; msg}); % error message for directory creation
+            end
+        end
+    end
+end
 %------------------------------------------------------------------------
 function STOP_Callback(hObject, eventdata, handles)
@@ -3474,10 +3502,7 @@
 end
 
-%function num_NbProcess_Callback(hObject, eventdata, handles)
-
 
 function num_NbSlice_Callback(hObject, eventdata, handles)
 NbSlice=str2num(get(handles.num_NbSlice,'String'));
-%set(handles.num_NbProcess,'String',num2str(NbSlice))
 
 %------------------------------------------------------------------------
@@ -3520,6 +3545,6 @@
 
 % --- Executes on mouse motion over figure - except title and menu.
-function series_WindowButtonMotionFcn(hObject, eventdata, handles)
-set(hObject,'Pointer','arrow');
+% function series_WindowButtonMotionFcn(hObject, eventdata, handles)
+% set(hObject,'Pointer','arrow');
 
 
@@ -3736,2 +3761,13 @@
 
 
+% --- Executes on button press in Replicate.
+function Replicate_Callback(hObject, eventdata, handles)
+if get(handles.Replicate,'Value')
+InputTable=get(handles.InputTable,'Data');
+browse_data(fullfile(InputTable{1,1},InputTable{1,2}))
+else
+    hh=findobj(allchild(0),'Tag','browse_data');
+    if ~isempty(hh)
+        delete(hh)
+    end
+end
Index: /trunk/src/series/extract_rdvision.m
===================================================================
--- /trunk/src/series/extract_rdvision.m	(revision 1058)
+++ /trunk/src/series/extract_rdvision.m	(revision 1059)
@@ -186,16 +186,19 @@
 %      nbfield2=size(time,1);
 checkpreserve=0;% if =1, will npreserve the original images, else it erases them at the end
+
 for iview=1:size(Param.InputTable,1)
+    check_xml=0;
     for iview_xml=1:size(Param.InputTable,1)% look for the xml files in the different data directories
         filexml=[fullfile(RootPath,Param.InputTable{iview_xml,2},Param.InputTable{iview,3}) '.xml'];%new convention: xml at the level of the image folder
         if exist(filexml,'file')
+            check_xml=1;
             break
         end
     end
-    if ~exist(filexml,'file')
-        disp_uvmat('ERROR',[filexml ' missing'],checkrun)
-        return
-    end
- 
+    %     if ~exist(filexml,'file')
+    %         disp_uvmat('ERROR',[filexml ' missing'],checkrun)
+    %         return
+    %     end
+    
     newxml=fullfile(RootPath,Param.InputTable{iview,3});
     newxml=regexprep(newxml,'_Master_Dalsa_4M180$','');%suppress '_Master_Dalsa_4M180'
@@ -211,5 +214,7 @@
             [success,errormsg] = copyfile(filename_seq,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.seq']); %copy the seq file in the upper folder
             [success,errormsg] = copyfile(filename_sqb,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.sqb']); %copy the sqb file in the upper folder
+            if check_xml
             [success,errormsg] = copyfile(filexml,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.xml']); %copy the original xml file in the upper folder
+            end
         otherwise
             errormsg='input file extension must be .seq or .sqb';
Index: /trunk/src/set_object.m
===================================================================
--- /trunk/src/set_object.m	(revision 1058)
+++ /trunk/src/set_object.m	(revision 1059)
@@ -332,5 +332,5 @@
         set(handles.num_RangeY_2,'TooltipString',['num_RangeY_2: half width of the ' ObjectStyle])
     case {'plane','plane_z'}  
-%        set(handles.num_Angle_3,'Visible','on')
+        set(handles.num_Angle_3,'Visible','on')
         set(handles.num_RangeX_1,'Visible','on')
         set(handles.num_RangeX_2,'Visible','on')
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m	(revision 1058)
+++ /trunk/src/uvmat.m	(revision 1059)
@@ -1202,6 +1202,6 @@
 uicontrol('Style','pushbutton','Units','normalized', 'Position', [ii ii wwp hh],'BackgroundColor',[1 0 0],'String','APPLY','Callback',@(hObject,eventdata)set_slice_APPLY_Callback(hObject,eventdata),...
     'FontWeight','bold','FontUnits','points','FontSize',12,'TooltipString','''APPLY'': apply the output to the current field series in uvmat');
-uicontrol('Style','pushbutton','Units','normalized', 'Position', [2*ii+wwp ii wwp hh],'BackgroundColor',[1 0 0],'String','REPLICATE','Callback',@(hObject,eventdata)set_slice_REPLICATE_Callback(hObject,eventdata),...
-    'FontWeight','bold','FontUnits','points','FontSize',12,'TooltipString','''REPLICATE'': replicate the output for a series of experiments');
+uicontrol('Style','checkbox','Units','normalized', 'Position', [2*ii+wwp ii wwp hh],'BackgroundColor',[1 0 0],'String','Replicate','Callback',@(hObject,eventdata)set_slice_REPLICATE_Callback(hObject,eventdata),...
+    'FontWeight','bold','FontUnits','points','FontSize',12,'TooltipString','''Replicate'': select to replicate the output of APPLY to a series of experiments');
 uicontrol('Style','pushbutton','Units','normalized', 'Position', [3*ii+2*wwp ii wwp hh],'Callback',@(hObject,eventdata)set_slice_Cancel_Callback(hObject,eventdata),...
     'String','Cancel','FontWeight','bold','FontUnits','points','FontSize',12,'TooltipString','''Cancel'': quit GUI without action');
@@ -1272,4 +1272,9 @@
 end
 
+hreplicate=findobj(hObject,'Tag','Replicate');
+if get(hreplicate,'Value')
+    'TEST'
+else
+
 %% store the result in the xml file used for calibration
 errormsg=update_imadoc(GeometryCalib,XmlFile,'GeometryCalib');% introduce the calibration data in the xml file
@@ -1284,4 +1289,5 @@
 uvmat('InputFileREFRESH_Callback',huvmat,[],hhuvmat); %file input with xml reading  in uvmat, show the image in phys coordinates
 set(hObject,'BackgroundColor',[1 0 0]);% paint button back to red
+end
 
 delete(hset_slice)
@@ -1291,63 +1297,78 @@
 function set_slice_REPLICATE_Callback(hObject,eventdata)
 %------------------------------------------------------------------------
-set(hObject,'BackgroundColor',[1 1 0])
-drawnow
-
-%% read the GUI set_slice
-SliceData=read_GUI(get(hObject,'parent'));
-
-%% get info on the GUI uvmat
-huvmat=findobj(allchild(0),'Tag','uvmat');
-hhuvmat=guidata(huvmat);
-RootPath=read_file_boxes(hhuvmat);
-
-OutPutDir=uigetfile_uvmat('choose an image folder to document with slice position?',fileparts(RootPath),'uigetdir');
-OutPut=browse_data(OutPutDir,'off','on');
-nbcalib=0;
-for ilist=1:numel(OutPut.Experiment)
-    for idevice=1:numel(OutPut.DataSeries)
-        SubDirBase=regexprep(OutPut.DataSeries{idevice},'\..+$','');
-        XmlFile=fullfile(OutPut.Campaign,OutPut.Experiment{ilist},[SubDirBase '.xml']);
-
-        % read the current xml file
-        if  exist(XmlFile,'file')
-            [s,errormsg]=imadoc2struct(XmlFile,'GeometryCalib');
-            if ~isempty(errormsg)
-                msgbox_uvmat('ERROR',['error in reading ' XmlFile ': ' errormsg])
-                return
-            end
-            GeometryCalib=s.GeometryCalib;
-            GeometryCalib.NbSlice=SliceData.NbSlice;
-            GeometryCalib.CheckVolumeScan=SliceData.CheckVolumeScan;
-            Z_plane=linspace(SliceData.Z(1),SliceData.Z(2),SliceData.NbSlice);
-            GeometryCalib.SliceCoord=Z_plane'*[0 0 1];
-            GeometryCalib.SliceAngle=zeros(GeometryCalib.NbSlice,3);
-            Angle_1=linspace(SliceData.SliceAngle_1(1),SliceData.SliceAngle_1(2),SliceData.NbSlice);
-            Angle_2=linspace(SliceData.SliceAngle_2(1),SliceData.SliceAngle_2(2),SliceData.NbSlice);
-            GeometryCalib.SliceAngle(:,1)=Angle_1';%rotation around x axis (to generalise)
-            GeometryCalib.SliceAngle(:,2)=Angle_2';%rotation around y axis (to generalise)
-            GeometryCalib.SliceAngle(:,3)=0;
-            if SliceData.CheckRefraction
-                GeometryCalib.InterfaceCoord=[0 0 SliceData.H];
-                GeometryCalib.RefractionIndex=SliceData.RefractionIndex;
-            elseif isfield(GeometryCalib,'RefractionIndex')
-                GeometryCalib=rmfield(GeometryCalib,'RefractionIndex');
-                GeometryCalib=rmfield(GeometryCalib,'InterfaceCoord');
-            end
-
-            % update the current xml file
-            errormsg=update_imadoc(GeometryCalib,XmlFile,'GeometryCalib');% introduce the calibration data in the xml file
-            if ~strcmp(errormsg,'')
-                msgbox_uvmat('ERROR',errormsg);
-            else
-                display([XmlFile ' updated with slice positions'])
-                nbcalib=nbcalib+1;
-            end
-        end
-    end
-end
-set(hObject,'BackgroundColor',[1 0 0])
-msgbox_uvmat('CONFIMATION',[SubDirBase ' calibrated with slice positions for ' num2str(nbcalib) ' experiments']);
-
+if get(hObject,'Value') %open the GUI browse_data
+    % look for the GUI uvmat and check for an image as input
+    huvmat=findobj(allchild(0),'Name','uvmat');
+    hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
+    RootPath=get(hhuvmat.RootPath,'String');
+    SubDir=get(hhuvmat.SubDir,'String');
+    browse_data(fullfile(RootPath,SubDir))
+else
+    hbrowse=findobj(allchild(0),'Tag','browse_data');
+    if ~isempty(hbrowse)
+        delete(hbrowse)
+    end
+end
+
+% 
+% set(hObject,'BackgroundColor',[1 1 0])
+% drawnow
+% 
+% %% read the GUI set_slice
+% SliceData=read_GUI(get(hObject,'parent'));
+% 
+% %% get info on the GUI uvmat
+% huvmat=findobj(allchild(0),'Tag','uvmat');
+% hhuvmat=guidata(huvmat);
+% RootPath=read_file_boxes(hhuvmat);
+% 
+% OutPutDir=uigetfile_uvmat('choose an image folder to document with slice position?',fileparts(RootPath),'uigetdir');
+% OutPut=browse_data(OutPutDir,'off','on');
+% nbcalib=0;
+% for ilist=1:numel(OutPut.Experiment)
+%     for idevice=1:numel(OutPut.DataSeries)
+%         SubDirBase=regexprep(OutPut.DataSeries{idevice},'\..+$','');
+%         XmlFile=fullfile(OutPut.Campaign,OutPut.Experiment{ilist},[SubDirBase '.xml']);
+% 
+%         % read the current xml file
+%         if  exist(XmlFile,'file')
+%             [s,errormsg]=imadoc2struct(XmlFile,'GeometryCalib');
+%             if ~isempty(errormsg)
+%                 msgbox_uvmat('ERROR',['error in reading ' XmlFile ': ' errormsg])
+%                 return
+%             end
+%             GeometryCalib=s.GeometryCalib;
+%             GeometryCalib.NbSlice=SliceData.NbSlice;
+%             GeometryCalib.CheckVolumeScan=SliceData.CheckVolumeScan;
+%             Z_plane=linspace(SliceData.Z(1),SliceData.Z(2),SliceData.NbSlice);
+%             GeometryCalib.SliceCoord=Z_plane'*[0 0 1];
+%             GeometryCalib.SliceAngle=zeros(GeometryCalib.NbSlice,3);
+%             Angle_1=linspace(SliceData.SliceAngle_1(1),SliceData.SliceAngle_1(2),SliceData.NbSlice);
+%             Angle_2=linspace(SliceData.SliceAngle_2(1),SliceData.SliceAngle_2(2),SliceData.NbSlice);
+%             GeometryCalib.SliceAngle(:,1)=Angle_1';%rotation around x axis (to generalise)
+%             GeometryCalib.SliceAngle(:,2)=Angle_2';%rotation around y axis (to generalise)
+%             GeometryCalib.SliceAngle(:,3)=0;
+%             if SliceData.CheckRefraction
+%                 GeometryCalib.InterfaceCoord=[0 0 SliceData.H];
+%                 GeometryCalib.RefractionIndex=SliceData.RefractionIndex;
+%             elseif isfield(GeometryCalib,'RefractionIndex')
+%                 GeometryCalib=rmfield(GeometryCalib,'RefractionIndex');
+%                 GeometryCalib=rmfield(GeometryCalib,'InterfaceCoord');
+%             end
+% 
+%             % update the current xml file
+%             errormsg=update_imadoc(GeometryCalib,XmlFile,'GeometryCalib');% introduce the calibration data in the xml file
+%             if ~strcmp(errormsg,'')
+%                 msgbox_uvmat('ERROR',errormsg);
+%             else
+%                 display([XmlFile ' updated with slice positions'])
+%                 nbcalib=nbcalib+1;
+%             end
+%         end
+%     end
+% end
+% set(hObject,'BackgroundColor',[1 0 0])
+% msgbox_uvmat('CONFIMATION',[SubDirBase ' calibrated with slice positions for ' num2str(nbcalib) ' experiments']);
+% 
 
 %------------------------------------------------------------------------
