Index: /trunk/src/get_file_series.m
===================================================================
--- /trunk/src/get_file_series.m	(revision 1096)
+++ /trunk/src/get_file_series.m	(revision 1097)
@@ -36,5 +36,5 @@
 InputTable=Param.InputTable;
 first_i=Param.IndexRange.first_i;
-incr_i=Param.IndexRange.incr_slice;
+incr_i=Param.IndexRange.incr_i;
 last_i=Param.IndexRange.last_i;
 first_j=[];last_j=[];incr_j=1;%default
Index: /trunk/src/mouse_motion.m
===================================================================
--- /trunk/src/mouse_motion.m	(revision 1096)
+++ /trunk/src/mouse_motion.m	(revision 1097)
@@ -279,4 +279,5 @@
                 Param.Action.RUN=1;
                 Param.ActionInput.ListCompareMode='PIV';
+                Param.ActionInput.PairIndices=read_GUI(hhciv.PairIndices);
                 par_civ.ImageA=Field.A;
                 par_civ.ImageB=Field.B;
Index: /trunk/src/plot_field.m
===================================================================
--- /trunk/src/plot_field.m	(revision 1096)
+++ /trunk/src/plot_field.m	(revision 1097)
@@ -127,5 +127,4 @@
         return
     end
-% end
 
 %% test axes and figure
@@ -266,5 +265,7 @@
     FigData=get(hfig,'UserData');
     if strcmp(get(hfig,'tag'),'view_field')||strcmp(get(hfig,'tag'),'uvmat')
+        if ~isempty(get(haxes,'tag'))
         FigData.(get(haxes,'tag'))=Data;
+        end
         set(hfig,'UserData',FigData)
     end
Index: /trunk/src/series.m
===================================================================
--- /trunk/src/series.m	(revision 1096)
+++ /trunk/src/series.m	(revision 1097)
@@ -168,22 +168,11 @@
 RunModeList={'local';'background'}; % default choice of extensions (Matlab fct .m or compiled version .sh)
 [s,w]=system(SeriesData.SeriesParam.ClusterParam.ExistenceTest); % look for cluster system presence
-% [s,w]=system('oarstat'); % look for cluster system 'oar'
 if isequal(s,0)
     RunModeList=[RunModeList;{'cluster'}];
     set(handles.MonitorCluster,'Visible','on'); % make visible button for access to Monika
     set(handles.num_CPUTime,'Visible','on'); % make visible button for CPU time estimate for one ref index
-    set(handles.num_CPUTime,'String','1')% defqult CPU time estimate 1 minute
+    set(handles.num_CPUTime,'String','')% default CPU time undefined
     set(handles.CPUTime_txt,'Visible','on'); % make visible button for CPU time title
 end
-% [s,w]=system('qstat -help'); % look for cluster system 'sge'
-% if isequal(s,0)
-%     if regexp(w,'^pbs')
-%         RunModeList=[RunModeList;{'cluster_pbs'}];
-%     elseif regexp(w,'^SGE')
-%         RunModeList=[RunModeList;{'cluster_sge'}];
-%     else
-%         RunModeList=[RunModeList;{'cluster_qstat_unknown'}];
-%     end
-% end
 set(handles.RunMode,'String',RunModeList)% display the menu of available run modes, local, background or cluster manager
 
@@ -208,10 +197,4 @@
         end
     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
     %get the menu of actions
     if isfield(h,'ActionListUser') && iscell(h.ActionListUser) && isfield(h,'ActionPathListUser') && iscell(h.ActionPathListUser)
@@ -287,7 +270,7 @@
 if isfield(Param,'InputFile')
     
-    %% fill the list of file series
+    %% fill the list of input file series
     InputTable=[{Param.InputFile.RootPath},{Param.InputFile.SubDir},{Param.InputFile.RootFile},{Param.InputFile.NomType},{Param.InputFile.FileExt}];
-    if isempty(find(cellfun('isempty',InputTable)==0)); % if there is no input file, do not introduce input info
+    if isempty(find(cellfun('isempty',InputTable)==0)) % if there is no input file, do not introduce input info
         set(handles.REFRESH,'BackgroundColor',[1 0 1])% set REFRESH button to magenta color to indicate that input refresh is needed
         return
@@ -299,4 +282,25 @@
     end
     set(handles.InputTable,'Data',InputTable)
+    
+    %% define the default path for the output files 
+    [InputPath,Device,DeviceExt]=fileparts(InputTable{1,1});
+    [InputPath,Experiment,ExperimentExt]=fileparts(InputPath);
+    set(handles.Device,'String',[Device DeviceExt])
+    set(handles.Experiment,'String',[Experiment ExperimentExt])
+    if ~isempty(regexp(InputTable{1,1},'(^http://)|(^https://)'))
+    set(handles.OutputPathBrowse,'Value',1)% an output folder needs to be specified for OpenDAP data
+    end
+
+    %update the output path if needed
+    if ~(isfield(SeriesData,'InputPath') && strcmp(SeriesData.InputPath,InputPath))
+    if get(handles.OutputPathBrowse,'Value')==1  % fix the output path in manual mode
+        OutputPathOld=get(handles.OutputPath,'String');
+        OutputPath=uigetdir(OutputPathOld,'pick a root folder for output data');
+        set(handles.OutputPath,'String',OutputPath)
+    else %reproduce the input path for output
+        set(handles.OutputPath,'String',InputPath)
+    end
+    end
+    
     %% determine the selected reference field indices for pair display
     
@@ -857,5 +861,4 @@
 [InputPath,Device,DeviceExt]=fileparts(InputTable{1,1});
 [InputPath,Experiment,ExperimentExt]=fileparts(InputPath);
-[~,InputPath,InputPathExt]=fileparts(InputPath);
 set(handles.Device,'String',[Device DeviceExt])
 set(handles.Experiment,'String',[Experiment ExperimentExt])
@@ -1843,8 +1846,8 @@
         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
+%     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
@@ -1852,4 +1855,11 @@
     switch RunMode
         case 'cluster'
+            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
+            else
+               answer=msgbox_uvmat('INPUT_TXT','estimate the CPU time(in minutes) for each value of index i:' ,''); 
+               CPUTime=str2num(answer);
+               set(handles.num_CPUTime,'String',answer)
+            end
             JobNumberMax=SeriesData.SeriesParam.ClusterParam.JobNumberMax;
             JobCPUTimeAdvised=SeriesData.SeriesParam.ClusterParam.JobCPUTimeAdvised;
@@ -2424,5 +2434,5 @@
 set(handles.ActionName,'BackgroundColor',[1 1 1])
 set(handles.ActionInput,'BackgroundColor',[1 0 1])% set ActionInput button to magenta color to indicate that input refr
-
+set(handles.num_CPUTime,'String','')
 
 % --- Executes on button press in ActionInput.
@@ -2637,5 +2647,5 @@
     end
     if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
-            set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
+            set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end
 end
 
Index: /trunk/src/series/aver_stat.m
===================================================================
--- /trunk/src/series/aver_stat.m	(revision 1096)
+++ /trunk/src/series/aver_stat.m	(revision 1097)
@@ -225,4 +225,6 @@
 
 %% settings for the output file
+OutputDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files
+OutputPath=fullfile(Param.OutputPath,num2str(Param.Experiment),num2str(Param.Device));
 NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file
 first_i=i1_series{1}(1);
@@ -467,5 +469,5 @@
     
     %% writing the result file
-    OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j_out,last_j_out);
+    OutputFile=fullfile_uvmat(OutputPath,OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j_out,last_j_out);
     if strcmp(FileExtOut,'.png') %case of images
         if isequal(FileInfo{1}.BitDepth,16)||(numel(FileInfo)==2 &&isequal(FileInfo{2}.BitDepth,16))
Index: /trunk/src/series/civ_input.m
===================================================================
--- /trunk/src/series/civ_input.m	(revision 1096)
+++ /trunk/src/series/civ_input.m	(revision 1097)
@@ -249,5 +249,4 @@
 set(handles.dt_unit,'String',['dt in m' TimeUnit]);%display dt in unit 10-3 of the time (e.g ms)
 set(handles.TimeUnit,'String',TimeUnit);
-%set(handles.CoordUnit,'String',CoordUnit)
 set(handles.SearchRange,'UserData', pxcm_search);
 
@@ -319,25 +318,16 @@
 %% set the menu and default choice of civ pairs
 if ~isfield(Param.IndexRange,'first_j')||isequal(MaxIndex_j,MinIndex_j)% no possibility of j pairs
-    set(handles.ListPairMode,'Value',1)
     PairMenu={'series(Di)'};
 elseif  MaxIndex_i==1 && MaxIndex_j>1% simple series in j
     PairMenu={'pair j1-j2';'series(Dj)'};
-    if  MaxIndex_j <= 10
-        set(handles.ListPairMode,'Value',1)% advice 'pair j1-j2' except in MaxIndex_j is large
-    end
 else
     PairMenu={'pair j1-j2';'series(Dj)';'series(Di)'};%multiple choice
-    if strcmp(NomTypeNc,'_1-2_1')
-        set(handles.ListPairMode,'Value',3)% advise 'series(Di)'
-    elseif  MaxIndex_j <= 10
-        set(handles.ListPairMode,'Value',1)% advice 'pair j1-j2' except in MaxIndex_j is large
-    end
 end
 set(handles.ListPairMode,'String',PairMenu)
 
 %% set default choice of pair mode
-PairIndex=1;
+PairIndex=[];
 if isfield(Param,'ActionInput') && isfield(Param.ActionInput,'PairIndices')
-    PairIndex=find(strcmp(Param.ActionInput.PairIndices.ListPairMode,PairMenu));
+    PairIndex=find(strcmp(Param.ActionInput.PairIndices.ListPairMode,PairMenu));%retrieve the previous option
 end
 if isempty(PairIndex)
@@ -353,4 +343,6 @@
         elseif  MaxIndex_j <= 10
             PairIndex=1;% advice 'pair j1-j2' except in MaxIndex_j is large
+        else
+            PairIndex=2;% advice 'Dj' 
         end
     end
@@ -1748,4 +1740,7 @@
      ImageData.ListVarName={'ny','nx','A'};
      ImageData.VarDimName= {'ny','nx',{'ny','nx'}};
+     ImageData.VarAttribute{1}.Role='coord_y';
+     ImageData.VarAttribute{2}.Role='coord_x';
+     ImageData.VarAttribute{3}.Role='scalar';
      ImageData.A=imread(Data.Civ1_ImageA); % read the first image
      if ndims(ImageData.A)==3 %case of color image
Index: /trunk/src/series/civ_series.m
===================================================================
--- /trunk/src/series/civ_series.m	(revision 1096)
+++ /trunk/src/series/civ_series.m	(revision 1097)
@@ -71,5 +71,5 @@
     Data.OutputFileMode='NbInput_i';% one output file expected per value of i index (used for waitbar)
     Data.CheckOverwriteVisible='on'; % manage the overwrite of existing files (default=1)
-    if isfield(Data.ActionInput,'PairIndices') && strcmp(Data.ActionInput.PairIndices.ListPairMode,'pair j1-j2')
+    if isfield(Data,'ActionInput') && isfield(Data.ActionInput,'PairIndices') && strcmp(Data.ActionInput.PairIndices.ListPairMode,'pair j1-j2')
         if isfield(Data.ActionInput.PairIndices,'ListPairCiv2')
             str_civ=Data.ActionInput.PairIndices.ListPairCiv2;
@@ -90,39 +90,39 @@
     end
     % estimated CPUTime
-    CPUtime_unit=0.01;%estimated time for a multiplication (in microsecond)
-    if isfield(Param.SeriesData,'FileInfo')&&isfield(Param.SeriesData.FileInfo{1},'Height')&&isfield(Param.SeriesData.FileInfo{1},'Width')
-        pixnbre=Param.SeriesData.FileInfo{1}.Height*Param.SeriesData.FileInfo{1}.Width; % total number of pxels for input images  
-        CPUtime=0;
-        if isfield(Data.ActionInput,'Civ1')
-            %BoxSize=Data.ActionInput.Civ1.CorrBoxSize(1)*Data.ActionInput.Civ1.CorrBoxSize(2);
-            tic
-            testboxa=rand(Data.ActionInput.Civ1.CorrBoxSize(1),Data.ActionInput.Civ1.CorrBoxSize(2));
-            testboxb=rand(Data.ActionInput.Civ1.SearchBoxSize(1),Data.ActionInput.Civ1.SearchBoxSize(2));
-            anss=conv2(testboxa,testboxb);
-            CPUtime_unit=toc;
-            nb_box=pixnbre/(Data.ActionInput.Civ1.Dx*Data.ActionInput.Civ1.Dy);    
-            %nbpos=Data.ActionInput.Civ1.SearchBoxSize-Data.ActionInput.Civ1.CorrBoxSize;
-            CPUtime=2*CPUtime_unit*nb_box%*BoxSize*nbpos(1)*nbpos(2);% adjustement factor 2 used
-        end
-        if isfield(Data.ActionInput,'Patch1')
-            CPUtime=2*CPUtime;
-        end
-        if isfield(Data.ActionInput,'Civ2')
-            tic
-            testboxa=rand(Data.ActionInput.Civ2.CorrBoxSize(1),Data.ActionInput.Civ2.CorrBoxSize(2));
-            testboxb=rand(Data.ActionInput.Civ2.SearchBoxSize(1),Data.ActionInput.Civ2.SearchBoxSize(2));
-            anss=conv2(testboxa,testboxb);
-            CPUtime_unit=toc;
-            nb_box=pixnbre/(Data.ActionInput.Civ2.Dx*Data.ActionInput.Civ2.Dy);
-            %BoxSize=Data.ActionInput.Civ2.CorrBoxSize(1)*Data.ActionInput.Civ2.CorrBoxSize(2);
-            %nbpos=Data.ActionInput.Civ2.SearchBoxSize-Data.ActionInput.Civ2.CorrBoxSize;
-            CPUtime=CPUtime+2*CPUtime_unit*nb_box;%*BoxSize*nbpos(1)*nbpos(2);
-        end
-        if isfield(Data.ActionInput,'Patch2')
-            CPUtime=(4/3)*CPUtime;
-        end
-        Data.CPUTime=ceil(CPUtime/6); % estimated CPU time per field pair in minute
-        Data.CPUTime=Data.CPUTime/10; % displqy CPU time with 1 digit beyond dot
-    end
+%     CPUtime_unit=0.01;%estimated time for a multiplication (in microsecond)
+%     if isfield(Param.SeriesData,'FileInfo')&&isfield(Param.SeriesData.FileInfo{1},'Height')&&isfield(Param.SeriesData.FileInfo{1},'Width')
+%         pixnbre=Param.SeriesData.FileInfo{1}.Height*Param.SeriesData.FileInfo{1}.Width; % total number of pxels for input images  
+%         CPUtime=0;
+%         if isfield(Data.ActionInput,'Civ1')
+%             %BoxSize=Data.ActionInput.Civ1.CorrBoxSize(1)*Data.ActionInput.Civ1.CorrBoxSize(2);
+%             tic
+%             testboxa=rand(Data.ActionInput.Civ1.CorrBoxSize(1),Data.ActionInput.Civ1.CorrBoxSize(2));
+%             testboxb=rand(Data.ActionInput.Civ1.SearchBoxSize(1),Data.ActionInput.Civ1.SearchBoxSize(2));
+%             anss=conv2(testboxa,testboxb);
+%             CPUtime_unit=toc;
+%             nb_box=pixnbre/(Data.ActionInput.Civ1.Dx*Data.ActionInput.Civ1.Dy);    
+%             %nbpos=Data.ActionInput.Civ1.SearchBoxSize-Data.ActionInput.Civ1.CorrBoxSize;
+%             CPUtime=2*CPUtime_unit*nb_box%*BoxSize*nbpos(1)*nbpos(2);% adjustement factor 2 used
+%         end
+%         if isfield(Data.ActionInput,'Patch1')
+%             CPUtime=2*CPUtime;
+%         end
+%         if isfield(Data.ActionInput,'Civ2')
+%             tic
+%             testboxa=rand(Data.ActionInput.Civ2.CorrBoxSize(1),Data.ActionInput.Civ2.CorrBoxSize(2));
+%             testboxb=rand(Data.ActionInput.Civ2.SearchBoxSize(1),Data.ActionInput.Civ2.SearchBoxSize(2));
+%             anss=conv2(testboxa,testboxb);
+%             CPUtime_unit=toc;
+%             nb_box=pixnbre/(Data.ActionInput.Civ2.Dx*Data.ActionInput.Civ2.Dy);
+%             %BoxSize=Data.ActionInput.Civ2.CorrBoxSize(1)*Data.ActionInput.Civ2.CorrBoxSize(2);
+%             %nbpos=Data.ActionInput.Civ2.SearchBoxSize-Data.ActionInput.Civ2.CorrBoxSize;
+%             CPUtime=CPUtime+2*CPUtime_unit*nb_box;%*BoxSize*nbpos(1)*nbpos(2);
+%         end
+%         if isfield(Data.ActionInput,'Patch2')
+%             CPUtime=(4/3)*CPUtime;
+%         end
+%         Data.CPUTime=ceil(CPUtime/6); % estimated CPU time per field pair in minute
+%         Data.CPUTime=Data.CPUTime/10; % displqy CPU time with 1 digit beyond dot
+%     end
     return
 end
@@ -474,4 +474,6 @@
             Data.ListGlobalAttribute=[ListGlobalAttribute Civ1_param];
             Data.CivStage=1;
+        else
+            i1=Param.ActionInput.PairIndices.ref_i; %case of TESTmode
         end
         % set the list of variables
Index: /trunk/src/series/merge_proj.m
===================================================================
--- /trunk/src/series/merge_proj.m	(revision 1096)
+++ /trunk/src/series/merge_proj.m	(revision 1097)
@@ -239,8 +239,4 @@
 %% MAIN LOOP ON FIELDS
 %%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
-% for i_slice=1:NbSlice
-%     index_slice=i_slice:NbSlice:NbField;% select file indices of the slice
-%     NbFiles=0;
-%     nbmissing=0;
 
     %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
Index: /trunk/src/series/sliding_average.m
===================================================================
--- /trunk/src/series/sliding_average.m	(revision 1096)
+++ /trunk/src/series/sliding_average.m	(revision 1097)
@@ -205,5 +205,5 @@
 end
 NbPeriod=2; %number of periods for the sliding average
-omega=2*pi/T;
+omega=2*2*pi/T;%harmonic
 Lscale=15;%diameter of the torus, length scale for normalisation
 Uscale=amplitude*omega;
Index: /trunk/src/series/sub_background_special.m
===================================================================
--- /trunk/src/series/sub_background_special.m	(revision 1097)
+++ /trunk/src/series/sub_background_special.m	(revision 1097)
@@ -0,0 +1,157 @@
+%'bed_scan': get the bed shape from laser ipact
+
+%------------------------------------------------------------------------
+% function GUI_input=bed_scan(Param)
+%
+%------------------------------------------------------------------------
+%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%OUTPUT
+% ParamOut: sets options in the GUI series.fig needed for the function
+%
+%INPUT:
+% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
+% In batch mode, Param is the name of the corresponding xml file containing the same information
+% when Param.Action.RUN=0 (as activated when the current Action is selected
+% in series), the function ouput paramOut set the activation of the needed GUI elements
+%
+% Param contains the elements:(use the menu bar command 'export/GUI config' in series to 
+% see the current structure Param)
+%    .InputTable: cell of input file names, (several lines for multiple input)
+%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
+%    .OutputSubDir: name of the subdirectory for data outputs
+%    .OutputDirExt: directory extension for data outputs
+%    .Action: .ActionName: name of the current activated function
+%             .ActionPath:   path of the current activated function
+%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
+%             .RUN =0 for GUI input, =1 for function activation
+%             .RunMode='local','background', 'cluster': type of function  use
+%             
+%    .IndexRange: set the file or frame indices on which the action must be performed
+%    .FieldTransform: .TransformName: name of the selected transform function
+%                     .TransformPath:   path  of the selected transform function
+%    .InputFields: sub structure describing the input fields withfields
+%              .FieldName: name(s) of the field
+%              .VelType: velocity type
+%              .FieldName_1: name of the second field in case of two input series
+%              .VelType_1: velocity type of the second field in case of two input series
+%              .Coord_y: name of y coordinate variable
+%              .Coord_x: name of x coordinate variable
+%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%=======================================================================
+% Copyright 2008-2021, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
+%   http://www.legi.grenoble-inp.fr
+%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
+%
+%     This file is part of the toolbox UVMAT.
+%
+%     UVMAT is free software; you can redistribute it and/or modify
+%     it under the terms of the GNU General Public License as published
+%     by the Free Software Foundation; either version 2 of the license,
+%     or (at your option) any later version.
+%
+%     UVMAT is distributed in the hope that it will be useful,
+%     but WITHOUT ANY WARRANTY; without even the implied warranty of
+%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%     GNU General Public License (see LICENSE.txt) for more details.
+%=======================================================================
+
+function ParamOut=sub_background_special (Param)
+
+%% set the input elements needed on the GUI series when the action is selected in the menu ActionName or InputTable refreshed
+if isstruct(Param) && isequal(Param.Action.RUN,0)
+    ParamOut.NbViewMax=1;% max nbre of input file series (default , no limitation)
+    ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
+    ParamOut.WholeIndexRange='on';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
+    ParamOut.NbSlice='off'; %nbre of slices ('off' by default)
+    ParamOut.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
+    ParamOut.FieldName='off';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+    ParamOut.FieldTransform = 'off';%can use a transform function
+    ParamOut.ProjObject='off';%can use projection object(option 'off'/'on',
+    ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
+    ParamOut.OutputDirExt='.sback';%set the output dir extension
+    ParamOut.OutputFileMode='NbInput';% ='=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
+    %check the type of the existence and type of the first input file:
+return
+end
+
+%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
+%% read input parameters from an xml file if input is a file name (batch mode)
+ParamOut=[];
+RUNHandle=[];
+WaitbarHandle=[];
+checkrun=1;
+if ischar(Param)% case of batch: Param is the name of the xml file containing the input parameters
+    Param=xml2struct(Param);% read Param as input file (batch case)
+    checkrun=0;
+else% interactive mode in Matlab
+    hseries=findobj(allchild(0),'Tag','series');
+    RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
+    WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
+end
+%% estimate the position of bottom and mask for each Z Index
+BottomIndex=[1900 1800 1700 1650 1650 1600 1600 1600 1600 1600 1600];
+MaxIndex=BottomIndex+100;
+MinIndex=BottomIndex-100;
+maskindex=[665 1080];% range of x index perturbed by shadows 
+NbSlice=11;
+Bfilter=ones(1,20)/20;
+%% root input file names and nomenclature type (cell arrays with one element)
+OutputDir=[Param.OutputSubDir Param.OutputDirExt];
+nbj=numel(Param.IndexRange.first_i:Param.IndexRange.last_i);
+for i_ind=Param.IndexRange.first_i:Param.IndexRange.last_i
+    ZIndex=mod(i_ind-1,NbSlice)+1; 
+    for j_ind=Param.IndexRange.first_j:Param.IndexRange.last_j
+        % read the current image
+        InputFile=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},Param.InputTable{1,5},Param.InputTable{1,4},i_ind,i_ind,j_ind);
+        A=imread(InputFile);
+        % get the bottom as the max of luminosity along vertical lines    
+        IndexMax=ones(1,size(A,2));%initiate the index position of the bottom
+        if j_ind==Param.IndexRange.first_j
+            indexMax_j=ones(nbj,size(A,2));%initiate the matrix of index position of the bottom
+        end
+        for icolumn=1:maskindex(1)
+            [M,IndexMax(icolumn)] = max(A(MinIndex(ZIndex)+1:MaxIndex(ZIndex),icolumn),[],1);
+        end
+        [M,IndexMax(maskindex(2))] = max(A(MinIndex(ZIndex)+1:MaxIndex(ZIndex),maskindex(2)),[],1);
+        for icolumn=maskindex(1)+1:maskindex(2)-1 % linear interpolation in the masked region
+            IndexMax(icolumn)= IndexMax(maskindex(1))*(maskindex(2)-icolumn)+IndexMax(maskindex(2))*(icolumn-maskindex(1));
+            IndexMax(icolumn)=IndexMax(icolumn)/(maskindex(2)-maskindex(1));
+        end
+        for icolumn=maskindex(2)+1:size(A,2)
+            [M,IndexMax(icolumn)] = max(A(MinIndex(ZIndex)+1:MaxIndex(ZIndex),icolumn),[],1);
+        end
+        IndexFilt=filter(Bfilter,1,IndexMax);% smoothed IndexMax
+        peakdetect=find(abs(IndexFilt-IndexMax)>5);% detect strong departures from the filtered values
+        IndexMax(peakdetect)=IndexFilt(peakdetect);%replace the peaks by the filtered values
+        IndexMax_j(j_ind,:)=round(filter(Bfilter,1,IndexMax));%filter again and take the closest integer
+        % get the background image as the min at each point in the j series 
+        if j_ind==Param.IndexRange.first_j
+            Amin=A;
+        else
+            Amin=min(Amin,A);
+        end
+    end
+    
+    for j_ind=Param.IndexRange.first_j:Param.IndexRange.last_j
+        InputFile=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},Param.InputTable{1,5},Param.InputTable{1,4},i_ind,i_ind,j_ind);
+        A=imread(InputFile);
+        A=A-Amin;
+        for icolumn=1:size(A,2)
+            A(MinIndex(ZIndex)+IndexMax_j(j_ind,icolumn):end,icolumn)=0;
+        end
+        OutputFile=fullfile_uvmat(Param.InputTable{1,1},OutputDir,Param.InputTable{1,3},Param.InputTable{1,5},Param.InputTable{1,4},i_ind,i_ind,j_ind);
+        imwrite(A,OutputFile)
+        disp([OutputFile ' written'])
+    end
+end
+
+
+
+
+
+
+ 
+
Index: /trunk/src/transform_field/ima_levels.m
===================================================================
--- /trunk/src/transform_field/ima_levels.m	(revision 1096)
+++ /trunk/src/transform_field/ima_levels.m	(revision 1097)
@@ -69,13 +69,17 @@
 fctblock= inline('mean(x(:))');
 B=imresize(Backg,size(A),'bilinear');% interpolate to the initial size image
-A=(A-B);%substract background
-AMean=blkproc(A,[nblock_y nblock_x],fctblock);% take the mean in  blocks
-fctblock= inline('var(x(:))');
-AVar=blkproc(A,[nblock_y nblock_x],fctblock);% take the mean in  blocks
-Avalue=AVar./AMean% typical value of particle luminosity
-Avalue=imresize(Avalue,size(A),'bilinear');% interpolate to the initial size image
-DataOut.A=uint16(1000*tanh(A./(2*Avalue)));
+DataOut.A=B;
+
+% A=(A-B);%substract background
+% AMean=blkproc(A,[nblock_y nblock_x],fctblock);% take the mean in  blocks
+% fctblock= inline('var(x(:))');
+% AVar=blkproc(A,[nblock_y nblock_x],fctblock);% take the mean in  blocks
+% Avalue=AVar./AMean;% typical value of particle luminosity
+% Avalue=imresize(Avalue,size(A),'bilinear');% interpolate to the initial size image
+% DataOut.A=uint16(1000*tanh(A./(2*Avalue)));
 %Bmin=blkproc(Aflagmin,[nblock_y nblock_x],sumblock);% find the number of minima in blocks
 %Backg=Backg./Bmin; % find the average of minima in blocks
 
 
+
+
