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
+
+
+
+
+
+
+ 
+
