Index: trunk/src/series/civ_series.m
===================================================================
--- trunk/src/series/civ_series.m	(revision 1143)
+++ trunk/src/series/civ_series.m	(revision 1144)
@@ -249,5 +249,4 @@
 Data.Program='civ_series';
 Data.CivStage=0;%default
-check_civx=0;%default
 
 %% get timing from the ImaDoc file or input video
@@ -332,5 +331,4 @@
             if strcmp(Param.ActionInput.ListCompareMode,'PIV')
                 ncfile_out=fullfile_uvmat(OutputPath,OutputDir,RootFile_A,'.nc',NomTypeNc,i1_civ2,i2_civ2,j1_civ2,j2_civ2);
-%                 ncfile_out=fullfile_uvmat(RootPath_A,OutputDir,RootFile_A,'.nc',NomTypeNc,i1_civ2,i2_civ2,j1_civ2,j2_civ2);
             else % displacement
                 ncfile_out=fullfile_uvmat(OutputPath,OutputDir,RootFile_A,'.nc',NomTypeNc,i2_civ2,[],j2_civ2);
@@ -448,5 +446,5 @@
         end
         % set the list of variables
-        Data.ListVarName={'Civ1_X','Civ1_Y','Civ1_U','Civ1_V','Civ1_F','Civ1_C'};%  cell array containing the names of the fields to record
+        Data.ListVarName={'Civ1_X','Civ1_Y','Civ1_U','Civ1_V','Civ1_C','Civ1_FF'};%  cell array containing the names of the fields to record
         Data.VarDimName={'nb_vec_1','nb_vec_1','nb_vec_1','nb_vec_1','nb_vec_1','nb_vec_1'};
         Data.VarAttribute{1}.Role='coord_x';
@@ -454,5 +452,6 @@
         Data.VarAttribute{3}.Role='vector_x';
         Data.VarAttribute{4}.Role='vector_y';
-        Data.VarAttribute{5}.Role='warnflag';
+        Data.VarAttribute{5}.Role='ancillary';
+        Data.VarAttribute{6}.Role='errorflag';
         % case of mask
         if par_civ1.CheckMask&&~isempty(par_civ1.Mask)
@@ -487,5 +486,5 @@
             Data.ListVarName=[Data.ListVarName 'Civ1_Z'];
             Data.Civ1_X=[];Data.Civ1_Y=[];Data.Civ1_Z=[];
-            Data.Civ1_U=[];Data.Civ1_V=[];Data.Civ1_C=[];Data.Civ1_F=[];
+            Data.Civ1_U=[];Data.Civ1_V=[];Data.Civ1_C=[];
             for ivol=1:NbSlice
                 % caluclate velocity data (y and v in indices, reverse to y component)
@@ -501,5 +500,5 @@
                 Data.Civ1_V=[Data.Civ1_V reshape(-vtable,[],1)];
                 Data.Civ1_C=[Data.Civ1_C reshape(ctable,[],1)];
-                Data.Civ1_F=[Data.Civ1_C reshape(F,[],1)];
+                Data.Civ1_FF=[Data.Civ1_FF reshape(F,[],1)];
             end
         else %usual PIV
@@ -516,5 +515,5 @@
             Data.Civ1_V=reshape(-vtable,[],1);
             Data.Civ1_C=reshape(ctable,[],1);
-            Data.Civ1_F=reshape(F,[],1);
+            Data.Civ1_FF=reshape(F,[],1);
             time_civ1=toc(tstart_civ1);
         end
@@ -557,9 +556,5 @@
         end
         Data.ListGlobalAttribute=[Data.ListGlobalAttribute Fix1_param];
-        Data.ListVarName=[Data.ListVarName {'Civ1_FF'}];
-        Data.VarDimName=[Data.VarDimName {'nb_vec_1'}];
-        nbvar=length(Data.ListVarName);
-        Data.VarAttribute{nbvar}.Role='errorflag';
-        Data.Civ1_FF=int8(detect_false(Param.ActionInput.Fix1,Data.Civ1_F,Data.Civ1_C,Data.Civ1_U,Data.Civ1_V));
+        Data.Civ1_FF=uint8(detect_false(Param.ActionInput.Fix1,Data.Civ1_C,Data.Civ1_U,Data.Civ1_V,Data.Civ1_FF));
         Data.CivStage=2;
     end
@@ -568,10 +563,5 @@
         disp('patch1 started')
          tstart_patch1=tic;
-        if check_civx
-            errormsg='Civ Matlab input needed for patch';
-            disp_uvmat('ERROR',errormsg,checkrun)
-            return
-        end
-        
+       
         % record the processing parameters of Patch1 as global attributes in the result nc file
         list_param=fieldnames(Param.ActionInput.Patch1)';
@@ -612,5 +602,5 @@
         Data.Civ1_U_smooth(ind_good)=Ures;% take the interpolated (smoothed) velocity values for good vectors, keep civ1 data for the other
         Data.Civ1_V_smooth(ind_good)=Vres;
-        Data.Civ1_FF(ind_good)=int8(FFres);
+        Data.Civ1_FF(ind_good)=uint8(FFres);
         time_patch1=toc(tstart_patch1);
         disp('patch1 performed')
@@ -802,5 +792,5 @@
         % define the Civ2 variable (if Civ2 data are not replaced from previous calculation)
         if isempty(find(strcmp('Civ2_X',Data.ListVarName),1))
-            Data.ListVarName=[Data.ListVarName {'Civ2_X','Civ2_Y','Civ2_U','Civ2_V','Civ2_F','Civ2_C'}];%  cell array containing the names of the fields to record
+            Data.ListVarName=[Data.ListVarName {'Civ2_X','Civ2_Y','Civ2_U','Civ2_V','Civ2_C','Civ2_FF'}];%  cell array containing the names of the fields to record
             Data.VarDimName=[Data.VarDimName {'nb_vec_2','nb_vec_2','nb_vec_2','nb_vec_2','nb_vec_2','nb_vec_2'}];
             Data.VarAttribute{nbvar+1}.Role='coord_x';
@@ -808,5 +798,6 @@
             Data.VarAttribute{nbvar+3}.Role='vector_x';
             Data.VarAttribute{nbvar+4}.Role='vector_y';
-            Data.VarAttribute{nbvar+5}.Role='warnflag';
+            Data.VarAttribute{nbvar+5}.Role='ancillary';
+            Data.VarAttribute{nbvar+6}.Role='errorflag';
         end
         Data.Civ2_X=reshape(xtable,[],1);
@@ -815,5 +806,5 @@
         Data.Civ2_V=reshape(-vtable,[],1);
         Data.Civ2_C=reshape(ctable,[],1);
-        Data.Civ2_F=reshape(F,[],1);
+        Data.Civ2_FF=reshape(F,[],1);
         disp('civ2 performed')
         time_civ2=toc(tstart_civ2);
@@ -847,21 +838,7 @@
             Data.(Fix2_param{ilist})=Param.ActionInput.Fix2.(list_param{ilist});
         end
-        Data.ListGlobalAttribute=[Data.ListGlobalAttribute Fix2_param];
-        if check_civx
-            if ~isfield(Data,'fix2')
-                Data.ListGlobalAttribute=[Data.ListGlobalAttribute 'fix2'];
-                Data.fix2=1;
-                Data.ListVarName=[Data.ListVarName {'vec2_FixFlag'}];
-                Data.VarDimName=[Data.VarDimName {'nb_vectors2'}];
-            end
-            Data.vec_FixFlag=detect_false(Param.Fix2,Data.vec2_F,Data.vec2_C,Data.vec2_U,Data.vec2_V);
-        else
-            Data.ListVarName=[Data.ListVarName {'Civ2_FF'}];
-            Data.VarDimName=[Data.VarDimName {'nb_vec_2'}];
-            nbvar=length(Data.ListVarName);
-            Data.VarAttribute{nbvar}.Role='errorflag';
-            Data.Civ2_FF=double(detect_false(Param.ActionInput.Fix2,Data.Civ2_F,Data.Civ2_C,Data.Civ2_U,Data.Civ2_V));
-            Data.CivStage=Data.CivStage+1;
-        end
+        Data.ListGlobalAttribute=[Data.ListGlobalAttribute Fix2_param];     
+        Data.Civ2_FF=double(detect_false(Param.ActionInput.Fix2,Data.Civ2_C,Data.Civ2_U,Data.Civ2_V,Data.Civ2_FF));
+        Data.CivStage=Data.CivStage+1;
     end
     
@@ -1082,6 +1059,6 @@
             if sizemask > 1/2% eliminate point if more than half of the correlation box is masked
                 F(ivec)=3; %
-                utable(ivec)=0;
-                vtable(ivec)=0;
+                utable(ivec)=NaN;
+                vtable(ivec)=NaN;
             else
                 image1_crop=image1_crop.*~mask1_crop;% put to zero the masked pixels (mask1_crop='true'=1)
@@ -1103,6 +1080,6 @@
             end
             if F(ivec)==3
-                utable(ivec)=0;
-                vtable(ivec)=0;
+                utable(ivec)=NaN;
+                vtable(ivec)=NaN;
             else
                 %mask
@@ -1197,5 +1174,5 @@
     peaky = peaky+ (f1-f2)/(2*f1-4*f0+2*f2);
 else
-    F=-2; % warning flag for vector truncated by the limited search box
+    F=1; % warning flag for vector truncated by the limited search box
 end
 peakx=x;
@@ -1206,5 +1183,5 @@
     peakx = peakx+ (f1-f2)/(2*f1-4*f0+2*f2);
 else
-    F=-2; % warning flag for vector truncated by the limited search box
+    F=1; % warning flag for vector truncated by the limited search box
 end
 vector=[peakx-floor(npx/2)-1 peaky-floor(npy/2)-1];
@@ -1215,5 +1192,5 @@
 %------------------------------------------------------------------------
 % vector=[0 0]; %default
-F=-2;
+F=1;
 peaky=y;
 peakx=x;
@@ -1258,5 +1235,5 @@
 [npy,npx]=size(result_conv);
 if x<4 || y<4 || npx-x<4 ||npy-y <4
-    F=-2;
+    F=1;
     vector=[x y];
 else
@@ -1292,13 +1269,13 @@
 
 
-function FF=detect_false(Param,F,C,U,V)
-FF=zeros(size(F));%default
-% FF=-2, for correlation max at edge
-% FF=-1, for too small correlation
-% FF=1, for velocity outside bounds
-% FF=2 for exclusion by difference with the smoothed field
-FF(F==-2)=-2;
+function FF=detect_false(Param,C,U,V,FFIn)
+FF=FFIn;%default, good vectors
+% FF=1, for correlation max at edge, not set in this function
+% FF=2, for too small correlation
+% FF=3, for velocity outside bounds
+% FF=4 for exclusion by difference with the smoothed field, not set in this function
+
 if isfield (Param,'MinCorr')
-     FF(C<Param.MinCorr)=-1;
+     FF(C<Param.MinCorr & FFIn==0)=2;
 end
 if (isfield(Param,'MinVel')&&~isempty(Param.MinVel))||(isfield (Param,'MaxVel')&&~isempty(Param.MaxVel))
@@ -1306,35 +1283,11 @@
     if isfield (Param,'MinVel')&&~isempty(Param.MinVel)
         U2Min=Param.MinVel*Param.MinVel;
-        FF(Umod<U2Min)=1;
+        FF(Umod<U2Min & FFIn==0)=3;
     end
     if isfield (Param,'MaxVel')&&~isempty(Param.MaxVel)
          U2Max=Param.MaxVel*Param.MaxVel;
-        FF(Umod>U2Max)=1;
-    end
-end
-
-
-%criterium on warn flags
-% FlagName={'CheckFmin2','CheckF2','CheckF3','CheckF4'};
-% FlagVal=[-2 2 3 4];
-% for iflag=1:numel(FlagName)
-%     if isfield(Param,FlagName{iflag}) && Param.(FlagName{iflag})
-%         FF=(FF==1| F==FlagVal(iflag));
-%     end
-% end
-% %criterium on correlation values
-% if isfield (Param,'MinCorr')
-%     FF=FF==1 | C<Param.MinCorr;
-% end
-% if (isfield(Param,'MinVel')&&~isempty(Param.MinVel))||(isfield (Param,'MaxVel')&&~isempty(Param.MaxVel))
-%     Umod= U.*U+V.*V;
-%     if isfield (Param,'MinVel')&&~isempty(Param.MinVel)
-%         FF=FF==1 | Umod<(Param.MinVel*Param.MinVel);
-%     end
-%     if isfield (Param,'MaxVel')&&~isempty(Param.MaxVel)
-%         FF=FF==1 | Umod>(Param.MaxVel*Param.MaxVel);
-%     end
-% end
-
+        FF(Umod>U2Max & FFIn==0)=3;
+    end
+end
 
 %------------------------------------------------------------------------
