Index: trunk/src/series/civ2vel_3C.m
===================================================================
--- trunk/src/series/civ2vel_3C.m	(revision 861)
+++ trunk/src/series/civ2vel_3C.m	(revision 862)
@@ -1,3 +1,3 @@
-%'civ2vel_3C': combine velocity fields from two camerasto get three velocity components
+%'civ2vel_3C': combine velocity fields from two cameras to get three velocity components
 %------------------------------------------------------------------------
 % function ParamOut=civ2vel_3C(Param)
@@ -116,5 +116,5 @@
      tsaiA=XmlData{1}.GeometryCalib;
  else
-     msgbox_uvmat('ERROR','no geometric calibration available for image A')
+     disp_uvmat('ERROR','no geometric calibration available for image A',checkrun)
      return
  end
@@ -122,11 +122,19 @@
      tsaiB=XmlData{2}.GeometryCalib;
  else
-     msgbox_uvmat('ERROR','no geometric calibration available for image B')
+     disp_uvmat('ERROR','no geometric calibration available for image B',checkrun)
      return
  end
 [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
 
-%% grid of physical positions
+%% grid of physical positions (given by projection plane)
+if ~Param.CheckObject
+         disp_uvmat('ERROR','a projection plane with interpolation is needed',checkrun)
+     return
+end
+ObjectData=Param.ProjObject;
+
 [x,y]=meshgrid(ObjectData.RangeX(1):ObjectData.DX:ObjectData.RangeX(2),ObjectData.RangeY(1):ObjectData.DY:ObjectData.RangeY(2));
+z=zeros(size(x));
+[Field,ParamOut,errormsg] = read_field(FileName,FileType,ParamIn,num)
 %camera coordinates:initialisation 2 cameras
 NbCamera=2;
@@ -178,11 +186,4 @@
         %% transform the input field (e.g; phys) if requested (no transform involving two input fields)
             %camera coordinates
-        xc=R(1)*Xphys+R(2)*Yphys+R(3)*Zphys+Calib.Tx_Ty_Tz(1);
-        yc=R(4)*Xphys+R(5)*Yphys+R(6)*Zphys+Calib.Tx_Ty_Tz(2);
-        zc=R(7)*Xphys+R(8)*Yphys+R(9)*Zphys+Calib.Tx_Ty_Tz(3);
-
-        %undistorted image coordinates
-        Xu=xc./zc;
-        Yu=yc./zc;
         Data{iview}=phys(Data{iview},XmlData{iview});
         
Index: trunk/src/series/civ_input.m
===================================================================
--- trunk/src/series/civ_input.m	(revision 861)
+++ trunk/src/series/civ_input.m	(revision 862)
@@ -397,5 +397,5 @@
 %% Civ2 parameters
 Param.Civ2.CorrBoxSize=[21 21];
-Param.Civ2.SearchBoxSize=[31 31];
+Param.Civ2.SearchBoxSize=[27 27];
 Param.Civ2.CorrSmooth=1;
 Param.Civ2.Dx=10;
@@ -539,5 +539,8 @@
     set(handles.ListPairCiv2,'Visible','off')
 end
-if max(checkbox(1:3))==0 && get(handles.CheckCiv2,'UserData')==6,% no operation asked before Civ2 and input file ready for civ3
+hseries=findobj(allchild(0),'Tag','series');% find the parent GUI 'series'
+hhseries=guidata(hseries); %handles of the elements in 'series'
+InputTable=get(hhseries.InputTable,'Data');
+if size(InputTable,1)>=1 && strcmp(InputTable{1,5},'.nc') && max(checkbox(1:3))==0 %&& get(handles.CheckCiv2,'UserData')==6,% no operation asked before Civ2 and input file ready for civ3
     set(handles.CheckCiv3,'Visible','on')
 else
@@ -573,5 +576,5 @@
     checkeven=(mod(ActionInput.Civ2.CorrBoxSize,2)==0);
     ActionInput.Civ2.CorrBoxSize(checkeven)=ActionInput.Civ2.CorrBoxSize(checkeven)+1;% set correlation box sizes to odd values
-    ActionInput.Civ2.SearchBoxSize=max(ActionInput.Civ2.SearchBoxSize,ActionInput.Civ2.CorrBoxSize+6);
+    ActionInput.Civ2.SearchBoxSize=max(ActionInput.Civ2.SearchBoxSize,ActionInput.Civ2.CorrBoxSize+4);
     checkeven=(mod(ActionInput.Civ2.SearchBoxSize,2)==0);
     ActionInput.Civ2.SearchBoxSize(checkeven)=ActionInput.Civ2.SearchBoxSize(checkeven)+1;% set search box sizes to odd values
@@ -1132,5 +1135,5 @@
 % --- Executes on button press in CheckDeformation.
 function CheckDeformation_Callback(hObject, eventdata, handles)
-set(handles.configSource,'String','NEW')
+set(handles.ConfigSource,'String','NEW')
 set(handles.OK,'BackgroundColor',[1 0 1])
 
@@ -1751,4 +1754,19 @@
      Param.Action.RUN=1;
      Param.ActionInput=read_GUI(handles.civ_input);
+     if isfield(Param.ActionInput,'Fix1')
+         Param.ActionInput=rmfield(Param.ActionInput,'Fix1');
+     end
+     if isfield(Param.ActionInput,'Patch1')
+         Param.ActionInput=rmfield(Param.ActionInput,'Patch1');
+     end
+     if isfield(Param.ActionInput,'Civ2')%remove options that may be selected beyond Patch1
+         Param.ActionInput=rmfield(Param.ActionInput,'Civ2');
+     end
+     if isfield(Param.ActionInput,'Fix2')
+         Param.ActionInput=rmfield(Param.ActionInput,'Fix2');
+     end
+     if isfield(Param.ActionInput,'Patch2')
+         Param.ActionInput=rmfield(Param.ActionInput,'Patch2');
+     end
      if isfield(Param,'OutputSubDir')
      Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
@@ -1819,4 +1837,13 @@
      Param.Action.RUN=1;
      Param.ActionInput=read_GUI(handles.civ_input);
+     if isfield(Param.ActionInput,'Civ2')%remove options that may be selected beyond Patch1
+         Param.ActionInput=rmfield(Param.ActionInput,'Civ2');
+     end
+     if isfield(Param.ActionInput,'Fix2')
+         Param.ActionInput=rmfield(Param.ActionInput,'Fix2');
+     end
+     if isfield(Param.ActionInput,'Patch2')
+         Param.ActionInput=rmfield(Param.ActionInput,'Patch2');
+     end
      if isfield(Param,'OutputSubDir')
      Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
@@ -1928,5 +1955,5 @@
     ViewData.PlotAxes.X=Data.Civ2_X';
     ViewData.PlotAxes.Y=Data.Civ2_Y';
-    ViewData.PlotAxes.ShiftX=Data.Civ2_U';% shift at each point (from patch1) estimated by running civ2 
+    ViewData.PlotAxes.ShiftX=Data.Civ2_U';% shift at each point (from patch1) estimated by the preliminary run of civ2 
     ViewData.PlotAxes.ShiftY=Data.Civ2_V';
     ViewData.PlotAxes.Civ1_SubRange=Data.Civ1_SubRange;
@@ -2279,8 +2306,2 @@
     drawnow
 end
-
-
-
-
-
-
Index: trunk/src/series/civ_series.m
===================================================================
--- trunk/src/series/civ_series.m	(revision 861)
+++ trunk/src/series/civ_series.m	(revision 862)
@@ -614,10 +614,4 @@
             end
         end
-        if par_civ2.CheckDeformation
-            DUDX=zeros(size(par_civ2.Grid,1),1);
-            DUDY=zeros(size(par_civ2.Grid,1),1);
-            DVDX=zeros(size(par_civ2.Grid,1),1);
-            DVDY=zeros(size(par_civ2.Grid,1),1);
-        end
         
         % get the guess from patch1 or patch2 (case 'CheckCiv3')
@@ -661,15 +655,21 @@
         Shifty=zeros(size(par_civ2.Grid,1),1);
         nbval=zeros(size(par_civ2.Grid,1),1);% nbre of interpolated values at each grid point (from the different patch subdomains)
+        if par_civ2.CheckDeformation
+            DUDX=zeros(size(par_civ2.Grid,1),1);
+            DUDY=zeros(size(par_civ2.Grid,1),1);
+            DVDX=zeros(size(par_civ2.Grid,1),1);
+            DVDY=zeros(size(par_civ2.Grid,1),1);
+        end
         NbSubDomain=size(SubRange,3);
         for isub=1:NbSubDomain% for each sub-domain of Patch1
             nbvec_sub=NbCentres(isub);% nbre of Civ vectors in the subdomain
             ind_sel=find(par_civ2.Grid(:,1)>=SubRange(1,1,isub) & par_civ2.Grid(:,1)<=SubRange(1,2,isub) &...
-                par_civ2.Grid(:,2)>=SubRange(2,1,isub) & par_civ2.Grid(:,2)<=SubRange(2,2,isub));
+                par_civ2.Grid(:,2)>=SubRange(2,1,isub) & par_civ2.Grid(:,2)<=SubRange(2,2,isub));% grid points in the subdomain
             if ~isempty(ind_sel)
-                epoints = par_civ2.Grid(ind_sel,:);% coordinates of interpolation sites
+                epoints = par_civ2.Grid(ind_sel,:);% coordinates of interpolation sites (measurement grids)
                 ctrs=Coord_tps(1:nbvec_sub,:,isub) ;%(=initial points) ctrs
                 nbval(ind_sel)=nbval(ind_sel)+1;% records the number of values for each interpolation point (in case of subdomain overlap)
-                EM = tps_eval(epoints,ctrs);
-                Shiftx(ind_sel)=Shiftx(ind_sel)+EM*U_tps(1:nbvec_sub+3,isub);
+                EM = tps_eval(epoints,ctrs);% thin plate spline (tps) coefficient
+                Shiftx(ind_sel)=Shiftx(ind_sel)+EM*U_tps(1:nbvec_sub+3,isub);%velocity shift estimated by tps from civ1
                 Shifty(ind_sel)=Shifty(ind_sel)+EM*V_tps(1:nbvec_sub+3,isub);
                 if par_civ2.CheckDeformation
@@ -691,8 +691,8 @@
             end
         end
-        ibx2=ceil(par_civ2.CorrBoxSize(1)/2);
-        iby2=ceil(par_civ2.CorrBoxSize(2)/2);
-        par_civ2.SearchBoxSize(1)=2*ibx2+9;% search ara +-4 pixels around the guess
-        par_civ2.SearchBoxSize(2)=2*iby2+9;
+%         ibx2=ceil(par_civ2.CorrBoxSize(1)/2);
+%         iby2=ceil(par_civ2.CorrBoxSize(2)/2);
+       % par_civ2.SearchBoxSize(1)=2*ibx2+9;% search ara +-4 pixels around the guess
+        %par_civ2.SearchBoxSize(2)=2*iby2+9;
         if CheckInputFile % else Dt given by par_civ2
             if strcmp(Param.ActionInput.ListCompareMode,'displacement')
@@ -704,5 +704,6 @@
         end
         par_civ2.SearchBoxShift=(Civ2_Dt/Civ1_Dt)*[Shiftx(nbval>=1)./nbval(nbval>=1) Shifty(nbval>=1)./nbval(nbval>=1)];
-        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];% grid taken at the extrapolated origin of the displacement vectors
+        % 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];
         if par_civ2.CheckDeformation
             par_civ2.DUDX=DUDX./nbval;
@@ -712,5 +713,5 @@
         end
         
-        % calculate velocity data (y and v in indices, reverse to y component)
+        % calculate velocity data (y and v in image indices, reverse to y component)
         [xtable, ytable, utable, vtable, ctable, F,result_conv,errormsg] = civ (par_civ2);
         
@@ -880,5 +881,5 @@
 %  .ImageWidth: nb of pixels of the image in x
 %  .Dx, Dy: mesh for the PIV calculation
-%  .Grid: grid giving the PIV calculation points (alternative to .Dx .Dy)
+%  .Grid: grid giving the PIV calculation points (alternative to .Dx .Dy): centres of the correlation boxes in Image A
 %  .Mask: name of a mask file or mask image matrix itself
 %  .MinIma: thresholds for image luminosity
@@ -893,18 +894,18 @@
 
 %% prepare measurement grid
-if isfield(par_civ,'Grid')% grid points set as input
-    if ischar(par_civ.Grid)%read the grid file if the input is a file name
+if isfield(par_civ,'Grid')% grid points set as input, central positions of the sub-images in image A
+    if ischar(par_civ.Grid)%read the grid file if the input is a file name (grid in x, y image coordinates)
         par_civ.Grid=dlmread(par_civ.Grid);
         par_civ.Grid(1,:)=[];%the first line must be removed (heading in the grid file)
     end
-    % else par_civ.Grid is already an array
-else% automatic grid
+    % else par_civ.Grid is already an array, no action here
+else% automatic grid in x, y image coordinates
     minix=floor(par_civ.Dx/2)-0.5;
     maxix=minix+par_civ.Dx*floor((par_civ.ImageWidth-1)/par_civ.Dx);
-    miniy=floor(par_civ.Dy/2)-0.5;
+    miniy=floor(par_civ.Dy/2)-0.5;% first automatic grid point at half the mesh Dy
     maxiy=minix+par_civ.Dy*floor((par_civ.ImageHeight-1)/par_civ.Dy);
     [GridX,GridY]=meshgrid(minix:par_civ.Dx:maxix,miniy:par_civ.Dy:maxiy);
     par_civ.Grid(:,1)=reshape(GridX,[],1);
-    par_civ.Grid(:,2)=reshape(GridY,[],1);
+    par_civ.Grid(:,2)=reshape(GridY,[],1);% increases with array index
 end
 nbvec=size(par_civ.Grid,1);
@@ -915,5 +916,5 @@
 isx2=ceil(par_civ.SearchBoxSize(1)/2);
 isy2=ceil(par_civ.SearchBoxSize(2)/2);
-shiftx=round(par_civ.SearchBoxShift(:,1));
+shiftx=round(par_civ.SearchBoxShift(:,1));%use the input shift estimate, rounded to the next integer value
 shifty=-round(par_civ.SearchBoxShift(:,2));% sign minus because image j index increases when y decreases
 if numel(shiftx)==1% case of a unique shift for the whole field( civ1)
@@ -922,9 +923,9 @@
 end
 
-%% Default output
-xtable=par_civ.Grid(:,1);
-ytable=par_civ.Grid(:,2);
-utable=zeros(nbvec,1);
-vtable=zeros(nbvec,1);
+%% Array initialisation and default output  if par_civ.CorrSmooth=0 (just the grid calculated, no civ computation)
+xtable=round(par_civ.Grid(:,1)+0.5)-0.5;
+ytable=round(par_civ.ImageHeight-par_civ.Grid(:,2)+0.5)-0.5;% y index corresponding to the position in image coordiantes
+utable=shiftx;%zeros(nbvec,1);
+vtable=shifty;%zeros(nbvec,1);
 ctable=zeros(nbvec,1);
 F=zeros(nbvec,1);
@@ -943,23 +944,4 @@
 check_MaxIma=isfield(par_civ,'MaxIma') && ~isempty(par_civ.MaxIma);
 
-% %% prepare images
-% if isfield(par_civ,'reverse_pair')
-%     if par_civ.reverse_pair
-%         if ischar(par_civ.ImageB)
-%             temp=par_civ.ImageA;
-%             par_civ.ImageA=imread(par_civ.ImageB);
-%         end
-%         if ischar(temp)
-%             par_civ.ImageB=imread(temp);
-%         end
-%     end
-% else
-%     if ischar(par_civ.ImageA)
-%         par_civ.ImageA=imread(par_civ.ImageA);
-%     end
-%     if ischar(par_civ.ImageB)
-%         par_civ.ImageB=imread(par_civ.ImageB);
-%     end
-% end
 par_civ.ImageA=sum(double(par_civ.ImageA),3);%sum over rgb component for color images
 par_civ.ImageB=sum(double(par_civ.ImageB),3);
@@ -1000,8 +982,9 @@
     mesh=0.25;%mesh in pixels for subpixel image interpolation (x 4 in each direction)
 end
-if par_civ.CorrSmooth~=0 % par_civ.CorrSmooth=0 implies no civ computation (just input image and grid points viven)
+
+if par_civ.CorrSmooth~=0 % par_civ.CorrSmooth=0 implies no civ computation (just input image and grid points given)
     for ivec=1:nbvec
         iref=round(par_civ.Grid(ivec,1)+0.5);% xindex on the image A for the middle of the correlation box
-        jref=round(par_civ.ImageHeight-par_civ.Grid(ivec,2)+0.5);% yindex on the image B for the middle of the correlation box
+        jref=round(par_civ.ImageHeight-par_civ.Grid(ivec,2)+0.5);%  j index  for the middle of the correlation box in the image A
         F(ivec)=0;
         subrange1_x=iref-ibx2:iref+ibx2;% x indices defining the first subimage
@@ -1076,5 +1059,4 @@
             else
                 F(ivec)=3;
-                [y,x]
             end
         end
@@ -1085,7 +1067,14 @@
 %------------------------------------------------------------------------
 % --- Find the maximum of the correlation function after interpolation
+% OUPUT:
+% vector = optimum displacement vector with subpixel correction
+% F =flag: =0 OK
+%           =-2 , warning: max too close to the edge of the search box (1 pixel margin)
+% INPUT:
+% x,y: position of the maximum correlation at integer values
+
 function [vector,F] = SUBPIXGAUSS (result_conv,x,y)
 %------------------------------------------------------------------------
-vector=[0 0]; %default
+% vector=[0 0]; %default
 F=0;
 [npy,npx]=size(result_conv);
@@ -1117,5 +1106,5 @@
 function [vector,F] = SUBPIX2DGAUSS (result_conv,x,y)
 %------------------------------------------------------------------------
-vector=[0 0]; %default
+% vector=[0 0]; %default
 F=-2;
 peaky=y;
Index: trunk/src/series/stereo_civ.m
===================================================================
--- trunk/src/series/stereo_civ.m	(revision 861)
+++ trunk/src/series/stereo_civ.m	(revision 862)
@@ -50,5 +50,6 @@
     path_series=fileparts(which('series'));
     addpath(fullfile(path_series,'series'))
-    Data=civ_input(Param);% introduce the civ parameters using the GUI civ_input
+   % Data=civ_input(Param);% introduce the civ parameters using the GUI civ_input
+   Data=stereo_input(Param)
     if isempty(Data)
         Data=Param;% if  civ_input has been cancelled, keep previous parameters
