Index: trunk/src/civ_matlab.m
===================================================================
--- trunk/src/civ_matlab.m	(revision 363)
+++ trunk/src/civ_matlab.m	(revision 364)
@@ -53,21 +53,40 @@
 if isfield (Param,'Civ1')
     check_civ1=1;% test for further use of civ1 results
+    % %% prepare images
+    par_civ1=Param.Civ1;
+    if isfield(par_civ1,'reverse_pair')
+        if par_civ1.reverse_pair
+            if ischar(par_civ1.ImageB)
+                temp=par_civ1.ImageA;
+                par_civ1.ImageA=imread(par_civ1.ImageB);
+            end
+            if ischar(temp)
+                par_civ1.ImageB=imread(temp);
+            end
+        end
+    else
+        if ischar(par_civ1.ImageA)
+            par_civ1.ImageA=imread(par_civ1.ImageA);
+        end
+        if ischar(par_civ1.ImageB)
+            par_civ1.ImageB=imread(par_civ1.ImageB);
+        end
+    end
+    
     % caluclate velocity data (y and v in indices, reverse to y component)
-    [xtable ytable utable vtable ctable F result_conv errormsg] = civ (Param.Civ1);
-
-   % to try the reverse_pair method, uncomment below
-%     [xtable1 ytable1 utable1 vtable1 ctable1 F1 result_conv1 errormsg1] = civ (Param.Civ1);
-%     Param.Civ1.reverse_pair=1;
-%     [xtable2 ytable2 utable2 vtable2 ctable2 F2 result_conv2 errormsg2] = civ (Param.Civ1);
-%     xtable=[xtable1; xtable2];
-%     ytable=[ytable1; ytable2];
-%     utable=[utable1; -utable2];
-%     vtable=[vtable1; -vtable2];
-%     ctable=[ctable1; ctable2];
-%     F=[F1; F2];
-%     result_conv=[result_conv1; result_conv2];
-%     errormsg=[errormsg1; errormsg2];
+    [xtable ytable utable vtable ctable F result_conv errormsg] = civ (par_civ1);
     
-    
+    % to try the reverse_pair method, uncomment below
+    %     [xtable1 ytable1 utable1 vtable1 ctable1 F1 result_conv1 errormsg1] = civ (Param.Civ1);
+    %     Param.Civ1.reverse_pair=1;
+    %     [xtable2 ytable2 utable2 vtable2 ctable2 F2 result_conv2 errormsg2] = civ (Param.Civ1);
+    %     xtable=[xtable1; xtable2];
+    %     ytable=[ytable1; ytable2];
+    %     utable=[utable1; -utable2];
+    %     vtable=[vtable1; -vtable2];
+    %     ctable=[ctable1; ctable2];
+    %     F=[F1; F2];
+    %     result_conv=[result_conv1; result_conv2];
+    %     errormsg=[errormsg1; errormsg2];
     if ~isempty(errormsg)
         return
@@ -80,5 +99,5 @@
     end
     Data.ListGlobalAttribute=[Data.ListGlobalAttribute Civ1_param];% {'Civ1_Time','Civ1_Dt'}];
-    Data.ListVarName={'Civ1_X','Civ1_Y','Civ1_U','Civ1_V','Civ1_C','Civ1_F'};%  cell array containing the names of the fields to record
+    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.VarDimName={'NbVec1','NbVec1','NbVec1','NbVec1','NbVec1','NbVec1'};
     Data.VarAttribute{1}.Role='coord_x';
@@ -93,6 +112,5 @@
     Data.Civ1_C=reshape(ctable,[],1);
     Data.Civ1_F=reshape(F,[],1);
-    Data.CivStage=1;
-    
+    Data.CivStage=1;  
 else
     if exist('ncfile','var')
@@ -111,9 +129,4 @@
     else
         Data=nc2struct(CivFile);%read civ1 and fix1 data in the existing netcdf file
-%         if isfield(Param,'Fix1')
-%             Data=nc2struct(CivFile,ListVarCiv1);%read civ1 data in the existing netcdf file
-%         else
-%             Data=nc2struct(CivFile,ListVarFix1);%read civ1 and fix1 data in the existing netcdf file
-%         end
     end
 end
@@ -181,12 +194,12 @@
     par_civ2=Param.Civ2;
     if ~isfield (Param,'Civ1') || ~strcmp(Param.Civ1.ImageA,par_civ2.ImageA)
-        par_civ2.ImageA=imread(par_civ2.ImageA);%read first image if not already done for civ1
+        par_civ2.ImageA=imread(Param.Civ2.ImageA);%read first image if not already done for civ1
     else
-        par_civ2.ImageA=Param.Civ1.ImageA;
+        par_civ2.ImageA=par_civ1.ImageA;
     end
     if ~isfield (Param,'Civ1') || ~strcmp(Param.Civ1.ImageB,par_civ2.ImageB)
-        par_civ2.ImageB=imread(par_civ2.ImageB);%read second image if not already done for civ1
+        par_civ2.ImageB=imread(Param.Civ2.ImageB);%read second image if not already done for civ1
          else
-        par_civ2.ImageB=Param.Civ1.ImageB;
+        par_civ2.ImageB=par_civ1.ImageB;
     end
     ibx2=ceil(par_civ2.Bx/2);
@@ -269,11 +282,12 @@
     Data.Civ2_Time=str2double(par_civ2.Time);
     Data.Civ2_Dt=str2double(par_civ2.Dt);
-    Data.ListVarName=[Data.ListVarName {'Civ2_X','Civ2_Y','Civ2_U','Civ2_V','Civ2_C','Civ2_F'}];%  cell array containing the names of the fields to record
+    nbvar=numel(Data.ListVarName);
+    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.VarDimName=[Data.VarDimName {'NbVec2','NbVec2','NbVec2','NbVec2','NbVec2','NbVec2'}];
-    Data.VarAttribute{1}.Role='coord_x';
-    Data.VarAttribute{2}.Role='coord_y';
-    Data.VarAttribute{3}.Role='vector_x';
-    Data.VarAttribute{4}.Role='vector_y';
-    Data.VarAttribute{5}.Role='warnflag';
+    Data.VarAttribute{nbvar+1}.Role='coord_x';
+    Data.VarAttribute{nbvar+2}.Role='coord_y';
+    Data.VarAttribute{nbvar+3}.Role='vector_x';
+    Data.VarAttribute{nbvar+4}.Role='vector_y';
+    Data.VarAttribute{nbvar+5}.Role='warnflag';
     Data.Civ2_X=reshape(xtable,[],1);
     Data.Civ2_Y=reshape(size(par_civ2.ImageA,1)-ytable+1,[],1);
@@ -290,5 +304,5 @@
     for ilist=1:length(ListFixParam)
         ParamName=ListFixParam{ilist};
-        ListName=['Fix1_' ParamName];
+        ListName=['Fix2_' ParamName];
         eval(['Data.ListGlobalAttribute=[Data.ListGlobalAttribute ''' ParamName '''];'])
         eval(['Data.' ListName '=Param.Fix2.' ParamName ';'])
@@ -308,5 +322,5 @@
         Data.VarAttribute{nbvar}.Role='errorflag';    
         Data.Civ2_FF=fix(Param.Fix2,Data.Civ2_F,Data.Civ2_C,Data.Civ2_U,Data.Civ2_V);
-        Data.CivStage=5;    
+        Data.CivStage=Data.CivStage+1;    
     end
     
@@ -316,7 +330,7 @@
 if isfield (Param,'Patch2')
     Data.ListGlobalAttribute=[Data.ListGlobalAttribute {'Patch2_Rho','Patch2_Threshold','Patch2_SubDomain'}];
-    Data.Patch2_Rho=str2double(Param.Patch2.Rho);
-    Data.Patch2_Threshold=str2double(Param.Patch2.Threshold);
-    Data.Patch2_SubDomain=str2double(Param.Patch2.SubDomain);
+    Data.Patch2_Rho=Param.Patch2.SmoothingParam;
+    Data.Patch2_Threshold=Param.Patch2.MaxDiff;
+    Data.Patch2_SubDomain=Param.Patch2.SubdomainSize;
     Data.ListVarName=[Data.ListVarName {'Civ2_U_Diff','Civ2_V_Diff','Civ2_X_SubRange','Civ2_Y_SubRange','Civ2_NbSites','Civ2_X_tps','Civ2_Y_tps','Civ2_U_tps','Civ2_V_tps'}];
     Data.VarDimName=[Data.VarDimName {'NbVec2','NbVec2',{'NbSubDomain2','Two'},{'NbSubDomain2','Two'},'NbSubDomain2',...
@@ -337,6 +351,6 @@
       Data.Civ2_V_Diff(ind_good)=Data.Civ2_V(ind_good)-Vres;
       Data.Civ2_FF(ind_good)=FFres;
-      Data.CivStage=6;                             
-end   
+      Data.CivStage=Data.CivStage+1;                             
+end  
 
 %% write result in a netcdf file if requested
@@ -379,5 +393,5 @@
 shifty=-par_civ.Shifty;% sign minus because image j index increases when y decreases
 if isfield(par_civ,'Grid')
-    if ischar(par_civ.Grid)
+    if ischar(par_civ.Grid)%read the drid file if the input is a file name
         par_civ.Grid=dlmread(par_civ.Grid);
         par_civ.Grid(1,:)=[];%the first line must be removed (heading in the grid file)
@@ -422,23 +436,23 @@
 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
+% %% 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
 
 [npy_ima npx_ima]=size(par_civ.ImageA);
@@ -660,8 +674,4 @@
     end
 end
-return
-
-
-FF=double(FF);
 
 
