Index: trunk/src/series/civ2vel_3C.m
===================================================================
--- trunk/src/series/civ2vel_3C.m	(revision 924)
+++ trunk/src/series/civ2vel_3C.m	(revision 927)
@@ -34,5 +34,5 @@
 
 %=======================================================================
-% Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
+% Copyright 2008-2015, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
 %   http://www.legi.grenoble-inp.fr
 %   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
@@ -52,5 +52,5 @@
 
 function ParamOut=civ2vel_3C(Param)
-
+disp('test')
 %% set the input elements needed on the GUI series when the function is selected in the menu ActionName or InputTable refreshed
 if isstruct(Param) && isequal(Param.Action.RUN,0)
@@ -68,4 +68,5 @@
     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 input files
+    ParamOut.CheckOverwriteVisible='on'; % manage the overwrite of existing files (default=1)
     first_j=[];
     if size(Param.InputTable,1)<2
@@ -170,6 +171,37 @@
 warning off
 
+CheckOverwrite=1;%default
+if isfield(Param,'CheckOverwrite')
+    CheckOverwrite=Param.CheckOverwrite;
+end
 for index=1:NbField
+    
     update_waitbar(WaitbarHandle,index/NbField)
+    
+    
+    
+    
+      %% generating the name of the merged field
+    i1=i1_series{1}(index);
+    if ~isempty(i2_series{end})
+        i2=i2_series{end}(index);
+    else
+        i2=i1;
+    end
+    j1=1;
+    j2=1;
+    if ~isempty(j1_series{1})
+        j1=j1_series{1}(index);
+        if ~isempty(j2_series{end})
+            j2=j2_series{end}(index);
+        else
+            j2=j1;
+        end
+    end
+    OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},'.nc','_1-2',i1,i2,j1,j2);
+    
+    %%
+    
+   
     if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
         disp('program stopped by user')
@@ -177,4 +209,9 @@
     end
     
+     if (~CheckOverwrite && exist(OutputFile,'file'))  
+            disp('existing output file already exists, skip to next field')
+            continue% skip iteration if the mode overwrite is desactivated and the result file already exists
+     end   
+     
     %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
     Data=cell(1,NbView);%initiate the set Data
@@ -185,9 +222,17 @@
    clear ZItemp
    ZItemp=zeros(size(XI,1),size(XI,2),2);
+   
+   if index==1
+        first_img=i1_series{1,1}(1,1); %id of the first image of the series
+   end
+     
+     idtemp=0;
  for indextemp=index:index+1; 
+     idtemp=idtemp+1;
     if NbView==3 % if there is only 1 stereo folder, extract directly Xphys,Yphys and Zphys
-        
-        [Data{3},tild,errormsg] = nc2struct([Param.InputTable{3,1},'/',Param.InputTable{3,2},'/',Param.InputTable{3,3},'_',int2str(indextemp),'.nc']); 
-       
+      
+        
+        
+        [Data{3},tild,errormsg] = nc2struct([Param.InputTable{3,1},'/',Param.InputTable{3,2},'/',Param.InputTable{3,3},'_',int2str(first_img+indextemp-1),'.nc']); 
        
         if  exist('Data{3}.Civ3_FF','var') % FF is present, remove wrong vector
@@ -219,5 +264,8 @@
         end
         
-        [Data{3},tild,errormsg] = nc2struct([Param.InputTable{3,1},'/',Param.InputTable{3,2},'/',Param.InputTable{3,3},'_',int2str(indextemp),'.nc']); 
+   
+        
+        [Data{3},tild,errormsg] = nc2struct([Param.InputTable{3,1},'/',Param.InputTable{3,2},'/',Param.InputTable{3,3},'_',int2str(first_img+indextemp-1),'.nc']); 
+    
         if exist('Data{3}.Civ3_FF','var') % if FF is present, remove wrong vector
             temp=find(Data{3}.Civ3_FF==0);
@@ -241,5 +289,6 @@
         
         
-        [Data{4},tild,errormsg] = nc2struct([Param.InputTable{4,1},'/',Param.InputTable{4,2},'/',Param.InputTable{4,3},'_',int2str(indextemp),'.nc']); 
+
+         [Data{4},tild,errormsg] = nc2struct([Param.InputTable{4,1},'/',Param.InputTable{4,2},'/',Param.InputTable{4,3},'_',int2str(first_img+indextemp-1),'.nc']); 
         if exist('Data{4}.Civ3_FF','var') % if FF is present, remove wrong vector
             temp=find(Data{4}.Civ3_FF==0);
@@ -279,5 +328,5 @@
    
     
-       ZItemp(:,:,indextemp)=griddata(Xphys,Yphys,Zphys,XI,YI); %interpolation on the choosen gridd
+       ZItemp(:,:,idtemp)=griddata(Xphys,Yphys,Zphys,XI,YI); %interpolation on the choosen gridd
     
 end
@@ -320,5 +369,5 @@
     Va=griddata(X1,Y1,V1,Xa,Ya);
     
-    [Ua,Va,Xa,Ya]=Ud2U(XmlData{1}.GeometryCalib,Xa,Ya,Ua,Va); % convert Xd data to X 
+%     [Ua,Va,Xa,Ya]=Ud2U(XmlData{1}.GeometryCalib,Xa,Ya,Ua,Va); % convert Xd data to X 
     [A]=get_coeff(XmlData{1}.GeometryCalib,Xa,Ya,XI,YI,ZI); %get coef A~
     
@@ -332,5 +381,5 @@
     Vb=griddata(X2,Y2,V2,Xb,Yb);
 
-    [Ub,Vb,Xb,Yb]=Ud2U(XmlData{2}.GeometryCalib,Xb,Yb,Ub,Vb); % convert Xd data to X 
+%     [Ub,Vb,Xb,Yb]=Ud2U(XmlData{2}.GeometryCalib,Xb,Yb,Ub,Vb); % convert Xd data to X 
     [B]=get_coeff(XmlData{2}.GeometryCalib,Xb,Yb,XI,YI,ZI); %get coef B~
    
@@ -369,22 +418,5 @@
 
     
-    %% generating the name of the merged field
-    i1=i1_series{1}(index);
-    if ~isempty(i2_series{end})
-        i2=i2_series{end}(index);
-    else
-        i2=i1;
-    end
-    j1=1;
-    j2=1;
-    if ~isempty(j1_series{1})
-        j1=j1_series{1}(index);
-        if ~isempty(j2_series{end})
-            j2=j2_series{end}(index);
-        else
-            j2=j1;
-        end
-    end
-    OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},'.nc','_1-2',i1,i2,j1,j2);
+  
     
     %% recording the merged field
@@ -399,13 +431,13 @@
         MergeData.coord_x=xI;
         MergeData.coord_y=yI;
-        MergeData.Z=ZI;
     end
     MergeData.U=U/Dt;
     MergeData.V=V/Dt;
     MergeData.W=W/Dt;
-    
-    mfx=(XmlData{1}.GeometryCalib.fx_fy(1)+XmlData{2}.GeometryCalib.fx_fy(1))/2;
-    mfy=(XmlData{1}.GeometryCalib.fx_fy(2)+XmlData{2}.GeometryCalib.fx_fy(2))/2;
-    MergeData.Error=(sqrt(mfx^2+mfy^2)/4).*sqrt(sum(Error.*Error,3));
+    MergeData.Z=ZI;
+    
+%     mfx=(XmlData{1}.GeometryCalib.fx_fy(1)+XmlData{2}.GeometryCalib.fx_fy(1))/2;
+%     mfy=(XmlData{1}.GeometryCalib.fx_fy(2)+XmlData{2}.GeometryCalib.fx_fy(2))/2;
+    MergeData.Error=0.5*sqrt(sum(Error.^2,3));
     errormsg=struct2nc(OutputFile,MergeData);%save result file
     if isempty(errormsg)
@@ -496,5 +528,5 @@
 %% result
 Den=(Dxb-Dxa).*(Dxb-Dxa)+(Dyb-Dya).*(Dyb-Dya);
-error=((Dyb-Dya).*(-u)-(Dxb-Dxa).*(-v))./Den;
+error=abs(((Dyb-Dya).*(-u)-(Dxb-Dxa).*(-v)))./Den;
 % ex=-error.*(Dyb-Dya);
 % ey=-error.*(Dxb-Dxa);
Index: trunk/src/series/stereo_civ.m
===================================================================
--- trunk/src/series/stereo_civ.m	(revision 924)
+++ trunk/src/series/stereo_civ.m	(revision 927)
@@ -21,22 +21,20 @@
 %     .Patch2:
 % ncfile: name of a netcdf file to be created for the result (extension .nc)
-
-%=======================================================================
-% Copyright 2008-2016, 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.
-%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+%  Copyright 2011-2015, LEGI / CNRS UJF G-INP, Joel.Sommeria@legi.grenoble-inp.fr
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+%     This 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.
-%
+%     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.
-%=======================================================================
+%     GNU General Public License (open UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
 
 function [Data,errormsg,result_conv]= stereo_civ(Param)
@@ -67,4 +65,6 @@
     Data.OutputSubDirMode='auto'; %select the last subDir in the input table as root of the output subdir name (option 'all'/'first'/'last', 'all' by default)
     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)
+
     return
 end
@@ -168,5 +168,5 @@
 end
 if isempty(i1_series_Civ1)||(~isempty(PairCiv2) && isempty(i1_series_Civ2))
-    disp_uvmat('ERROR','no image pair fo civ in the input file index range',checkrun)
+    disp_uvmat('ERROR','no image pair for civ in the input file index range',checkrun)
     return
 end
@@ -265,4 +265,9 @@
 tic
 %%%%% MAIN LOOP %%%%%%
+CheckOverwrite=1;%default
+if isfield(Param,'CheckOverwrite')
+    CheckOverwrite=Param.CheckOverwrite;
+end
+
 for ifield=1:NbField
     update_waitbar(WaitbarHandle,ifield/NbField)
@@ -282,4 +287,11 @@
         ncfile2=fullfile_uvmat(RootPath_A,Civ1Dir,[RootFile_A,'_Light'],'.nc',NomTypeNc,i2_series_Civ1(ifield),[],...
             j1_series_Civ1(ifield),j2_series_Civ1(ifield));
+        
+     if (~CheckOverwrite && exist(ncfile,'file')) || (~CheckOverwrite && exist(ncfile2,'file')) 
+            disp('existing output file already exists, skip to next field')
+            result_conv=0;
+            continue% skip iteration if the mode overwrite is desactivated and the result file already exists
+     end   
+    
        
     %% Civ1
@@ -845,7 +857,10 @@
        
     end
-   end
-
-  disp(['ellapsed time for the loop ' num2str(toc) ' s'])
+end
+disp(['ellapsed time for the loop ' num2str(toc) ' s'])
+tic
+while toc < rand(1)*10
+    for i = 1:100000, sqrt(1237); end
+end
 
 
@@ -1099,5 +1114,5 @@
 [npy,npx]=size(result_conv);
 result_conv(result_conv<1)=1; %set to 1 correlation values smaller than 1 (to avoid divergence in the log)
-%the following 8 lines are copyright (c) 1998, Uri Shavit, Roi Gurka, Alex Liberzon, Technion ï¿œ Israel Institute of Technology
+%the following 8 lines are copyright (c) 1998, Uri Shavit, Roi Gurka, Alex Liberzon, Technion ??? Israel Institute of Technology
 %http://urapiv.wordpress.com
 peaky = y;
@@ -1136,9 +1151,9 @@
         for j=-1:1
             %following 15 lines based on
-            %H. Nobach ï¿œ M. Honkanen (2005)
+            %H. Nobach ??? M. Honkanen (2005)
             %Two-dimensional Gaussian regression for sub-pixel displacement
             %estimation in particle image velocimetry or particle position
             %estimation in particle tracking velocimetry
-            %Experiments in Fluids (2005) 38: 511ï¿œ515
+            %Experiments in Fluids (2005) 38: 511???515
             c10(j+2,i+2)=i*log(result_conv(y+j, x+i));
             c01(j+2,i+2)=j*log(result_conv(y+j, x+i));
