Index: trunk/src/series/civ_input.m
===================================================================
--- trunk/src/series/civ_input.m	(revision 872)
+++ trunk/src/series/civ_input.m	(revision 873)
@@ -373,4 +373,5 @@
 
 %% Civ1 parameters
+Param.CheckCiv1=1;
 Param.Civ1.CorrBoxSize=[25 25];
 Param.Civ1.SearchBoxSize=[55 55];
@@ -381,8 +382,10 @@
 Param.Civ1.CheckGrid=0;
 Param.Civ1.CheckMask=0;
+Param.Civ1.Mask='';
 Param.Civ1.CheckThreshold=0;
 Param.Civ1.TestCiv1=0;
 
 %% Fix1 parameters
+Param.CheckFix1=1;
 Param.Fix1.CheckFmin2=1;
 Param.Fix1.CheckF3=1;
@@ -390,4 +393,5 @@
 
 %% Patch1 parameters
+Param.CheckPatch1=1;
 Param.Patch1.FieldSmooth=10;
 Param.Patch1.MaxDiff=1.5000;
@@ -396,4 +400,5 @@
 
 %% Civ2 parameters
+Param.CheckCiv2=1;
 Param.Civ2.CorrBoxSize=[21 21];
 Param.Civ2.SearchBoxSize=[27 27];
@@ -403,8 +408,10 @@
 Param.Civ2.CheckGrid=0;
 Param.Civ2.CheckMask=0;
+Param.Civ2.Mask='';
 Param.Civ2.CheckThreshold=0;
 Param.Civ2.TestCiv2=0;
 
 %% Fix2 parameters
+Param.CheckFix2=1;
 Param.Fix2.CheckFmin2=1;
 Param.Fix2.CheckF4=1;
@@ -413,4 +420,5 @@
 
 %% Patch2 parameters
+Param.CheckPatch2=1;
 Param.Patch2.FieldSmooth=2;
 Param.Patch2.MaxDiff=1.5000;
@@ -419,4 +427,5 @@
 
 fill_GUI(Param,handles.civ_input)% fill the elements of the GUI series with the input parameters
+update_CivOptions(handles,0)
 
 % -----------------------------------------------------------------------
@@ -1129,5 +1138,5 @@
 % --- Executes on selection in menu CorrSmooth.
 function num_CorrSmooth_Callback(hObject, eventdata, handles)
-set(handles.configSource,'String','NEW')
+set(handles.ConfigSource,'String','NEW')
 set(handles.OK,'BackgroundColor',[1 0 1])
 %------------------------------------------------------------------------
@@ -1473,5 +1482,5 @@
 end
 set(hObject,'BackgroundColor',[1 0 1])
-set(handles.configSource,'String','NEW')
+set(handles.ConfigSource,'String','NEW')
 set(handles.OK,'BackgroundColor',[1 0 1])
 %------------------------------------------------------------------------
@@ -1518,6 +1527,6 @@
     set(handle_txtbox,'Visible','off')
 end
-set(handles.configSource,'String','NEW')
-set(handles.configSource,'BackgroundColor',[1 0 1])
+set(handles.ConfigSource,'String','NEW')
+set(handles.ConfigSource,'BackgroundColor',[1 0 1])
 
 % %------------------------------------------------------------------------
@@ -1735,5 +1744,5 @@
     set(obj,'Visible','off')
 end
-set(handles.configSource,'String','NEW')
+set(handles.ConfigSource,'String','NEW')
 set(handles.OK,'BackgroundColor',[1 0 1])
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -1748,6 +1757,10 @@
 if get(handles.TestCiv1,'Value')
     set(handles.TestCiv1,'BackgroundColor',[1 1 0])% paint TestCiv1 button to yellow to confirm civ launch  
-    %Param.Action.RUN=1;
-    
+    set(handles.CheckFix1,'value',0)% desactivate next step
+    set(handles.CheckPatch1,'value',0)% desactivate next step
+    set(handles.CheckCiv2,'value',0)% desactivate next step
+    set(handles.CheckFix2,'value',0)% desactivate next step
+    set(handles.CheckPatch2,'value',0)% desactivate next step
+    update_CivOptions(handles,0)
       hseries=findobj(allchild(0),'Tag','series');
      Param=read_GUI(hseries);
@@ -1887,8 +1900,7 @@
     end
     figure(1)
-    hold on
-    semilogx(SmoothingParam,DiffVel,'b',SmoothingParam,NbExclude,'r')
+    semilogx(SmoothingParam,DiffVel,'b',SmoothingParam,NbExclude,'r',SmoothingParam,0.2*ones(size(SmoothingParam)),'m')
     grid on
-    legend('rms velocity diff. Patch1-Civ1 (pixels)','proportion of excluded vectors (between 0 to 1)')
+    legend('rms velocity diff. Patch1-Civ1 (pixels)','proportion of excluded vectors (between 0 to 1)','recommended diff Patch1-Civ1')
     xlabel('smoothing parameter')
     ylabel('smoothing effect')
@@ -1912,4 +1924,7 @@
 if get(handles.TestCiv2,'Value')
     set(handles.TestCiv2,'BackgroundColor',[1 1 0])% paint TestCiv1 button to yellow to confirm civ launch
+    set(handles.CheckFix2,'value',0)% desactivate next step
+    set(handles.CheckPatch2,'value',0)% desactivate next step
+    update_CivOptions(handles,0)
       hseries=findobj(allchild(0),'Tag','series');
      Param=read_GUI(hseries);
@@ -2065,8 +2080,7 @@
     end
     figure(1)
-    hold on
-    semilogx(SmoothingParam,DiffVel,'b',SmoothingParam,NbExclude,'r')
+    semilogx(SmoothingParam,DiffVel,'b',SmoothingParam,NbExclude,'r',SmoothingParam,0.1*ones(size(SmoothingParam)),'m')
     grid on
-    legend('rms velocity diff. Patch2-Civ2 (pixels)','proportion of excluded vectors (between 0 to 1)')
+    legend('rms velocity diff. Patch2-Civ2 (pixels)','proportion of excluded vectors (between 0 to 1)','recommended value diff. Patch2-Civ2')
     xlabel('smoothing parameter')
     ylabel('smoothing effect')
Index: trunk/src/series/civ_series.m
===================================================================
--- trunk/src/series/civ_series.m	(revision 872)
+++ trunk/src/series/civ_series.m	(revision 873)
@@ -705,5 +705,5 @@
         par_civ2.SearchBoxShift=(Civ2_Dt/Civ1_Dt)*[Shiftx(nbval>=1)./nbval(nbval>=1) Shifty(nbval>=1)./nbval(nbval>=1)];
         % shift the grid points by half the expected shift to provide the correlation box position in image A
-        par_civ2.Grid=[par_civ2.Grid(nbval>=1,1)-par_civ2.SearchBoxShift(nbval>=1,1)/2 par_civ2.Grid(nbval>=1,2)-par_civ2.SearchBoxShift(nbval>=1,2)/2];
+        par_civ2.Grid=[par_civ2.Grid(nbval>=1,1)-par_civ2.SearchBoxShift(:,1)/2 par_civ2.Grid(nbval>=1,2)-par_civ2.SearchBoxShift(:,2)/2];
         if par_civ2.CheckDeformation
             par_civ2.DUDX=DUDX./nbval;
@@ -732,6 +732,4 @@
              end
         end
-        %         Data.Civ2_Time=1;
-        %         Data.Civ2_Dt=1;
         for ilist=1:length(list_param)
             Data.(Civ2_param{4+ilist})=Param.ActionInput.Civ2.(list_param{ilist});
@@ -961,5 +959,6 @@
 checkmask=0;
 MinA=min(min(par_civ.ImageA));
-MinB=min(min(par_civ.ImageB));
+%MinB=min(min(par_civ.ImageB));
+check_undefined=false(size(par_civ.ImageA));
 if isfield(par_civ,'Mask') && ~isempty(par_civ.Mask)
     checkmask=1;
@@ -968,8 +967,7 @@
         return
     end
-    %  check_noflux=(par_civ.Mask<100) ;%TODO: to implement
     check_undefined=(par_civ.Mask<200 & par_civ.Mask>=20 );
-    par_civ.ImageA(check_undefined)=MinA;% put image A to zero (i.e. the min image value) in the undefined  area
-    par_civ.ImageB(check_undefined)=MinB;% put image B to zero (i.e. the min image value) in the undefined  area
+    par_civ.ImageA(check_undefined)=0;% put image A to zero (i.e. the min image value) in the undefined  area
+    par_civ.ImageB(check_undefined)=0;% put image B to zero (i.e. the min image value) in the undefined  area
 end
 
@@ -994,4 +992,6 @@
         image1_crop=MinA*ones(numel(subrange1_y),numel(subrange1_x));% default value=min of image A
         image2_crop=MinA*ones(numel(subrange2_y),numel(subrange2_x));% default value=min of image A
+        mask1_crop=ones(numel(subrange1_y),numel(subrange1_x));% default value=1 for mask
+        mask2_crop=ones(numel(subrange2_y),numel(subrange2_x));% default value=min for mask
         check1_x=subrange1_x>=1 & subrange1_x<=par_civ.ImageWidth;% check which points in the subimage 1 are contained in the initial image 1
         check1_y=subrange1_y>=1 & subrange1_y<=par_civ.ImageHeight;
@@ -1000,18 +1000,24 @@
         image1_crop(check1_y,check1_x)=par_civ.ImageA(subrange1_y(check1_y),subrange1_x(check1_x));%extract a subimage (correlation box) from image A
         image2_crop(check2_y,check2_x)=par_civ.ImageB(subrange2_y(check2_y),subrange2_x(check2_x));%extract a larger subimage (search box) from image B
-        image1_mean=mean(mean(image1_crop));
-        image2_mean=mean(mean(image2_crop));
-        %threshold on image minimum
-        if check_MinIma && (image1_mean < par_civ.MinIma || image2_mean < par_civ.MinIma)
-            F(ivec)=3;
-        end
-        %threshold on image maximum
-        if check_MaxIma && (image1_mean > par_civ.MaxIma || image2_mean > par_civ.MaxIma)
-            F(ivec)=3;
-        end
-        
+        mask1_crop(check1_y,check1_x)=check_undefined(subrange1_y(check1_y),subrange1_x(check1_x));%extract a mask subimage (correlation box) from image A
+        mask2_crop(check2_y,check2_x)=check_undefined(subrange2_y(check2_y),subrange2_x(check2_x));%extract a mask subimage (search box) from image B
+        sizemask=sum(sum(mask1_crop))/(numel(subrange1_y)*numel(subrange1_x));%size of the masked part relative to the correlation sub-image
+        if sizemask > 1/2% eliminate point if more than half of the correlation box is masked
+            F(ivec)=3; %
+        else
+            image1_mean=mean(mean(image1_crop))/(1-sizemask);
+            image2_mean=mean(mean(image2_crop))/(1-sizemask);
+            %threshold on image minimum
+            if check_MinIma && (image1_mean < par_civ.MinIma || image2_mean < par_civ.MinIma)
+                F(ivec)=3;
+            end
+            %threshold on image maximum
+            if check_MaxIma && (image1_mean > par_civ.MaxIma || image2_mean > par_civ.MaxIma)
+                F(ivec)=3;
+            end
+        end
         if F(ivec)~=3
-            image1_crop=image1_crop-image1_mean;%substract the mean
-            image2_crop=image2_crop-image2_mean;
+            image1_crop=(image1_crop-image1_mean).*~mask1_crop;%substract the mean, put to zero the masked parts
+            image2_crop=(image2_crop-image2_mean).*~mask2_crop;
             if CheckDeformation
                 xi=(1:mesh:size(image1_crop,2));
