Index: /trunk/src/find_field_cells.m
===================================================================
--- /trunk/src/find_field_cells.m	(revision 1057)
+++ /trunk/src/find_field_cells.m	(revision 1058)
@@ -17,5 +17,6 @@
 %              _image   : B/W image, (behaves like scalar)
 %              _vector_x,_y,_z: indices of variables giving the vector components x, y, z
-%              _warnflag: index of warnflag    
+%              _warnflag: index of warnflag 
+%              _histo: index of variable used as histogram
 %       .DimIndex
 %      .ProjModeRequest= 'interp_lin', 'interp_tps' indicate whether lin interpolation  or derivatives (tps) is needed to calculate the requested field
@@ -118,7 +119,8 @@
 end
 ind_discrete=find(strcmp('discrete',Role));
-ind_coord_x=find(strcmp('coord_x',Role));
+ind_coord_x=[find(strcmp('coord_x',Role)) find(strcmp('histo',Role))];
 ind_coord_y=find(strcmp('coord_y',Role));
 ind_coord_z=find(strcmp('coord_z',Role));
+ind_histo=find(strcmp('histo',Role));
 ind_coord_tps=find(strcmp('coord_tps',Role));
 check_string=cellfun(@ischar,Data.VarDimName)==1;
@@ -477,5 +479,5 @@
         Cell1DPlot{icell}.YIndex_discrete=[];
         DimCell_x=Data.VarDimName{ind_coord_x(icell)};
-        for ivar=ind_coord_y 
+        for ivar=[ind_coord_y ind_histo]
             DimCell=Data.VarDimName{ivar};
             if  numel(DimCell_x)==1 && strcmp(DimCell_x{1},DimCell{1})
Index: /trunk/src/plot_field.m
===================================================================
--- /trunk/src/plot_field.m	(revision 1057)
+++ /trunk/src/plot_field.m	(revision 1058)
@@ -585,5 +585,5 @@
 TextDisplay=0;
 for icell=1:numel(CellInfo)
-    if isfield(CellInfo{icell},'VarIndex_histo')
+    if isfield(CellInfo{icell},'VarIndex_histo')% case of histogram plot
         TextDisplay=1;
         VarName=data.ListVarName{CellInfo{icell}.CoordIndex};
Index: /trunk/src/proj_field.m
===================================================================
--- /trunk/src/proj_field.m	(revision 1057)
+++ /trunk/src/proj_field.m	(revision 1058)
@@ -509,4 +509,5 @@
         if isfield(FieldData,'VarAttribute')&& numel(FieldData.VarAttribute)>=ivar
             VarAttribute_var=FieldData.VarAttribute{ivar};
+            VarAttribute_var.Role='coord_x';
         end
       %  VarAttribute_var.Role='coord_x';% the variable is now used as an absissa
Index: /trunk/src/read_field.m
===================================================================
--- /trunk/src/read_field.m	(revision 1057)
+++ /trunk/src/read_field.m	(revision 1058)
@@ -265,5 +265,5 @@
         A=imread(FileName);
     case 'rdvision'
-        [A,FileInfo,timestamps]=read_rdvision(FileName,num);
+        [A,FileInfo,timestamps,errormsg]=read_rdvision(FileName,num);
     case 'image_DaVis'
         Input=readimx(FileName);
Index: /trunk/src/read_rdvision.m
===================================================================
--- /trunk/src/read_rdvision.m	(revision 1057)
+++ /trunk/src/read_rdvision.m	(revision 1058)
@@ -125,8 +125,13 @@
       % binrepertoire='2017-01-19T22.12.182'% EXP14 %%%%%%%%%%%%%%%%%%%%%%%%%
         binfile=fullfile(RootPath,binrepertoire,sprintf('%s%.5d.bin',bin_file,data(ii).file_idx));
+        if ~exist(binfile,'file')
+            errormsg=[binfile ' does not exist'];
+            return
+        else
         fid=fopen(binfile,'rb');
         fseek(fid,data(ii).offset,-1);
         A(:,:,i)=reshape(fread(fid,w*h,classname),w,h)';
         fclose(fid);
+        end
     end
     
Index: /trunk/src/series/merge_proj.m
===================================================================
--- /trunk/src/series/merge_proj.m	(revision 1057)
+++ /trunk/src/series/merge_proj.m	(revision 1058)
@@ -533,9 +533,4 @@
                 end
         end
-%         if isempty(FFName)
-%             FFName='FF';
-%         end
-%         MergeData.(FFName)(NbAver~=0)=0;% flag to 1 undefined summed data
-%         MergeData.(FFName)(NbAver==0)=1;% flag to 1 undefined summed data
     end
 end
Index: /trunk/src/series/merge_proj_polar.m
===================================================================
--- /trunk/src/series/merge_proj_polar.m	(revision 1057)
+++ /trunk/src/series/merge_proj_polar.m	(revision 1058)
@@ -100,5 +100,6 @@
 HeadData.ListVarName= {'radius','azimuth'} ;
 HeadData.VarDimName={'radius','azimuth'};
-HeadData.VarAttribute={'coord_y','coord_x'} ;
+HeadData.VarAttribute{1}.Role='coord_y';
+HeadData.VarAttribute{2}.Role='coord_x';
 HeadData.radius=radius_shifted;
 HeadData.azimuth=azimuth_arclength;    
@@ -373,5 +374,7 @@
         ProjData{iview}.ListVarName= [ProjData{iview}.ListVarName ListVarName];
         ProjData{iview}.VarDimName={'radius','azimuth'};
-        ProjData{iview}.VarAttribute=[{'coord_x'} {'coord_y'} VarAttribute];
+%         ProjData{iview}.VarAttribute{1}.Role='coord_y';
+%         ProjData{iview}.VarAttribute{2}.Role='coord_x';
+        ProjData{iview}.VarAttribute=[ProjData{iview}.VarAttribute VarAttribute];
         for ivar=1:numel(ListVarName)
             ProjData{iview}.VarDimName{ivar+2}={'radius','azimuth'};
@@ -457,4 +460,75 @@
 disp([ num2str(ellapsed_time/(60*NbField),3) ' minutes per iteration'])
 
+% %'merge_field': concatene fields
+% %------------------------------------------------------------------------
+% function [MergeData,errormsg]=merge_field(Data)
+% %% default output
+% if isempty(Data)||~iscell(Data)
+%     MergeData=[];
+%     return
+% end
+% errormsg='';
+% MergeData=Data{1};% merged field= first field by default, reproduces the global attributes of the first field
+% NbView=length(Data);
+% if NbView==1% if there is only one field, just reproduce it in MergeData
+%     return
+% end
+% 
+% %% group the variables (fields of 'Data') in cells of variables with the same dimensions
+% [CellInfo,NbDim,errormsg]=find_field_cells(Data{1});
+% if ~isempty(errormsg)
+%     return
+% end
+% 
+% %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
+% for icell=1:length(CellInfo)
+%     if NbDim(icell)~=1 % skip field cells which are of dim 1
+%         switch CellInfo{icell}.CoordType
+%             case 'scattered'  %case of input fields with unstructured coordinates: just concatene data
+%                 for ivar=CellInfo{icell}.VarIndex %  indices of the selected variables in the list FieldData.ListVarName
+%                     VarName=Data{1}.ListVarName{ivar};
+%                     for iview=2:NbView
+%                         MergeData.(VarName)=[MergeData.(VarName); Data{iview}.(VarName)];
+%                     end
+%                 end
+%             case 'grid'        %case of fields defined on a structured  grid
+%                 FFName='';
+%                 if isfield(CellInfo{icell},'VarIndex_errorflag') && ~isempty(CellInfo{icell}.VarIndex_errorflag)
+%                     FFName=Data{1}.ListVarName{CellInfo{icell}.VarIndex_errorflag};% name of errorflag variable
+%                     MergeData.ListVarName(CellInfo{icell}.VarIndex_errorflag)=[];%remove error flag variable in MergeData (will use NaN instead)
+%                     MergeData.VarDimName(CellInfo{icell}.VarIndex_errorflag)=[];
+%                     MergeData.VarAttribute(CellInfo{icell}.VarIndex_errorflag)=[];
+%                 end
+%                 % select good data on each view
+%                 for ivar=CellInfo{icell}.VarIndex  %  indices of the selected variables in the list FieldData.ListVarName
+%                     VarName=Data{1}.ListVarName{ivar};
+%                     for iview=1:NbView
+%                         if isempty(FFName)
+%                             check_bad=isnan(Data{iview}.(VarName));%=0 for NaN data values, 1 else
+%                         else
+%                             check_bad=isnan(Data{iview}.(VarName)) | Data{iview}.(FFName)~=0;%=0 for NaN or error flagged data values, 1 else
+%                         end
+%                         Data{iview}.(VarName)(check_bad)=0; %set to zero NaN or data marked by error flag
+%                         if iview==1
+%                             %MergeData.(VarName)=Data{1}.(VarName);% initiate MergeData with the first field
+%                             MergeData.(VarName)(check_bad)=0; %set to zero NaN or data marked by error flag
+%                             NbAver=~check_bad;% initiate NbAver: the nbre of good data for each point
+%                         elseif size(Data{iview}.(VarName))~=size(MergeData.(VarName))
+%                             errormsg='sizes of the input matrices do not agree, need to interpolate on a common grid using a projection object';
+%                             return
+%                         else
+%                             MergeData.(VarName)=MergeData.(VarName) +double(Data{iview}.(VarName));%add data
+%                             NbAver=NbAver + ~check_bad;% add 1 for good data, 0 else
+%                         end
+%                     end
+%                     MergeData.(VarName)(NbAver~=0)=MergeData.(VarName)(NbAver~=0)./NbAver(NbAver~=0);% take average of defined data at each point
+%                     MergeData.(VarName)(NbAver==0)=NaN;% set to NaN the points with no good data
+%                 end
+%         end
+%    
+%     end
+% end
+
+
 %'merge_field': concatene fields
 %------------------------------------------------------------------------
@@ -469,5 +543,5 @@
 NbView=length(Data);
 if NbView==1% if there is only one field, just reproduce it in MergeData
-    return
+    return 
 end
 
@@ -514,5 +588,5 @@
                             errormsg='sizes of the input matrices do not agree, need to interpolate on a common grid using a projection object';
                             return
-                        else
+                        else                             
                             MergeData.(VarName)=MergeData.(VarName) +double(Data{iview}.(VarName));%add data
                             NbAver=NbAver + ~check_bad;% add 1 for good data, 0 else
@@ -523,12 +597,4 @@
                 end
         end
-        %         if isempty(FFName)
-        %             FFName='FF';
-        %         end
-        %         MergeData.(FFName)(NbAver~=0)=0;% flag to 1 undefined summed data
-        %         MergeData.(FFName)(NbAver==0)=1;% flag to 1 undefined summed data
-    end
-end
-
-
-    
+    end
+end    
Index: /trunk/src/series/sub_background.m
===================================================================
--- /trunk/src/series/sub_background.m	(revision 1057)
+++ /trunk/src/series/sub_background.m	(revision 1058)
@@ -140,6 +140,7 @@
     
     %% setting of  parameters specific to sub_background
-    nbaver_init=23; %default number of images used for the sliding background: to be adjusted later to include an integer number of bursts  
-    if nbfield_i~=1
+    CheckVolume='No';
+    nbaver_init=23; %default number of images used for the sliding background: to be adjusted later to include an integer number of bursts 
+     if nbfield_i~=1
         nbaver=floor(nbaver_init/nbfield_j); % number of bursts used for the sliding background,
         if isequal(mod(nbaver,2),0)% if nbaver is even
@@ -148,13 +149,32 @@
         nbaver_init=nbaver*nbfield_j;%propose by default an integer number of bursts
     end
-    
+    BrightnessRankThreshold=0.1;
+    CheckSubmedian='No';
+    SaturationCoeff=0;
+    if isfield(Param,'ActionInput')
+        if isfield(Param.ActionInput,'CheckVolume') && Param.ActionInput.CheckVolume
+            CheckVolume='Yes';
+        end
+        if isfield(Param.ActionInput,'SlidingSequenceLength')
+         nbaver_init=Param.ActionInput.SlidingSequenceLength;
+        end
+        if isfield(Param.ActionInput,'BrightnessRankThreshold')
+          BrightnessRankThreshold=Param.ActionInput.BrightnessRankThreshold;
+        end
+        if isfield(Param.ActionInput,'CheckSubmedian') && Param.ActionInput.CheckSubmedian
+        CheckSubmedian='Yes';
+        end
+        if isfield(Param.ActionInput,'SaturationCoeff') 
+            SaturationCoeff=Param.ActionInput.SaturationCoeff;
+        end
+    end   
     prompt = {'volume scan mode (Yes/No)';...
         'Number of images for the sliding background (MUST FIT IN COMPUTER MEMORY)';...
         'the luminosity rank chosen to define the background (0.1=for dense particle seeding, 0.5 (median) for sparse particles';...
         'set to 0 image levels below median(Yes/No)';...
-        'image rescaling coefficient(high values reduce the influence of bright particles), =0 for no rescaling' };
+        'image rescaling coefficient(=2 to reduce the influence of bright particles), =0 for no rescaling' };
     dlg_title = 'get (slice by slice) a sliding background and substract to each image';
     num_lines= 5;
-    def     = { 'No';num2str(nbaver_init);'0.1';'No';'2'};
+    def     = { CheckVolume;num2str(nbaver_init);num2str(BrightnessRankThreshold);CheckSubmedian;num2str(SaturationCoeff)};
     answer = inputdlg(prompt,dlg_title,num_lines,def);
     if isempty(answer)
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m	(revision 1057)
+++ /trunk/src/uvmat.m	(revision 1058)
@@ -2637,5 +2637,9 @@
     Mask.NbSlice_j=1;
     if isempty(j1_series)
+        if isempty(i1_series)
+            MaskNomType='*';
+        else
         Mask.NbSlice_i=i1_series(1,2,end);
+        end
     else
         Mask.NbSlice_j=j1_series(1,end,2);
@@ -2667,8 +2671,10 @@
     MaskIndex_i=str2num(get(handles.z_index,'String'));
 else
-    MaskIndex_i=mod(str2num(get(handles.i1,'String')),Mask.NbSlice_i);
-end
+    MaskIndex_i=mod(str2num(get(handles.i1,'String'))-1,Mask.NbSlice_i)+1;
+end
+MaskIndex_z=MaskIndex_i;%default
 if Mask.NbSlice_j>1
     MaskIndex_j=str2num(get(handles.j1,'String'));
+    MaskIndex_z=MaskIndex_j;
 else
     MaskIndex_j=1;
@@ -2702,5 +2708,5 @@
             return
         end
-        MaskField.ZIndex=MaskIndex_i;
+        MaskField.ZIndex=MaskIndex_z;
         %px to phys or other transform on field
          menu_transform=get(handles.TransformName,'String');
