Index: trunk/src/civ.m
===================================================================
--- trunk/src/civ.m	(revision 317)
+++ trunk/src/civ.m	(revision 319)
@@ -196,5 +196,5 @@
     browse=[];%initialisation
 else
-    browse=get(handlesRootName,'UserData');
+    browse=get(handles.RootName,'UserData');
 end
 browse.num_i1=num_i1;
@@ -289,5 +289,5 @@
 set(handles.num_Rho,'Value',1)
 set(handles.num_Rho,'String',{'1';'2'})
-set(handles.BATCH,'Enable','off')
+% set(handles.BATCH,'Enable','off')
 
 % -----------------------------------------------------------------------
@@ -345,4 +345,5 @@
 num_ref_i=i1;%efaulmt ref index
 num_ref_j=j1;
+browse=get(handles.RootName,'UserData');
 browse.incr_pair=[0 0];%default
 
@@ -1180,4 +1181,8 @@
                     cmd=[cmd...
                         cmd_civ1(filecell.nc.civ1{ifile,j},Param) '\n'];
+                    if ~isempty(errormsg)
+                        msgbox_uvmat('ERROR',errormsg)
+                        return
+                    end
                 case 'CivAll'
                     CivAllCmd=[CivAllCmd ' civ1 '];
@@ -1428,10 +1433,17 @@
                 drawnow
                 if ~strcmp(compare,'stereo PIV')
-                    [Data,erromsg]=civ_matlab(Param,filecell.nc.civ1{ifile,j});
-                    if isempty(errormsg)
-                        display([filecell.nc.civ1{ifile,j} ' written'])
+                    filename_xml=[OutputFile '.civ.xml'];
+                    t=struct2xml(Param);
+                    save(t,filename_xml)
+                    if batch   
+                        batch_file_list{length(batch_file_list)+1}=filename_xml;
                     else
-                        msgbox_uvmat('ERROR',errormsg)
-                    end                 
+                        [Data,erromsg]=civ_matlab(Param,filecell.nc.civ1{ifile,j});
+                        if isempty(errormsg)
+                            display([filecell.nc.civ1{ifile,j} ' written'])
+                        else
+                            msgbox_uvmat('ERROR',errormsg)
+                        end
+                    end
                 end
         end
@@ -2471,9 +2483,9 @@
 %------------------------------------------------------------------------
 test=get(handles.ListCompareMode,'Value');
-if test==2 || test==3 % case 'dispalcemen' or 'stereo PIV'
+if test==2 || test==3 % case 'displacement' or 'stereo PIV'
     filebase=get(handles.RootName,'String');
-    browse=get(handlesRootName,'Userdata');
+    browse=get(handles.RootName,'Userdata');
     browse.nom_type_ima1=browse.nom_type_ima;
-    set(handlesRootName,'UserData',browse);
+    set(handles.RootName,'UserData',browse);
     set(handles.sub_txt,'Visible','on')
     set(handles.RootName_1,'Visible','On');%mkes the second file input window visible
@@ -2519,7 +2531,7 @@
     [RootPath,RootFile,field_count,str2,str_a,str_b,xx,nom_type,subdir]=name2display(name);
     set(handles.RootName_1,'String',RootFile);
-    browse=get(handlesRootName,'UserData');
+    browse=get(handles.RootName,'UserData');
     browse.nom_type_ima_1=nom_type;
-    set(handlesRootName,'UserData',browse)
+    set(handles.RootName,'UserData',browse)
     
     %check image extension
@@ -2549,12 +2561,12 @@
     set(handles.ListPairMode,'Value',1)
     set(handles.ListPairMode,'String',mode_store)
-    set(handles.test_stereo1,'Value',0)
+%     set(handles.test_stereo1,'Value',0)
     set(handles.CheckStereo,'Value',0)
     set(handles.ListPairMode,'Value',1) % mode 'civX' selected by default
 end
 if test==3 && get(handles.CheckPatch1,'Value')
-    set(handles.test_stereo1,'Visible','on')
-else
-    set(handles.test_stereo1,'Visible','off')
+    set(handles.CheckStereo,'Visible','on')
+else
+    set(handles.CheckStereo,'Visible','off')
 end
 if test==3 && get(handles.CheckPatch2,'Value')
@@ -2563,5 +2575,5 @@
     set(handles.CheckStereo,'Visible','off')
 end
-mode_Callback(hObject, eventdata, handles)
+ListPairMode_Callback(hObject, eventdata, handles)
 
 
@@ -2701,5 +2713,5 @@
     displ_num(3,1)=0;
     displ_num(4,1)=0;
-    if nbfield > 1
+    if nbfield > 1 || nbfield==0
         set(handles.itext,'Visible','On')
         set(handles.first_i,'Visible','On')
@@ -3656,5 +3668,5 @@
 
 %% if hObject is on the checkciv1 frame, duplicate action for checkciv2 frame
-PanelName=get(hparent,'tag')
+PanelName=get(hparent,'tag');
 if strcmp(PanelName,'Civ1')
     hchildren=get(handles.Civ2,'children');
@@ -4038,4 +4050,6 @@
 %pixels per cm and matrix of the image times, read from the .civ file by uvmat
 %changes : filename_cmx -> filename ( no extension )
+cmd='';
+errormsg=''; %default
 filename=regexprep(filename,'.nc',''); %file name for the result 
 if isequal(Param.Civ1.Dt,'0')
@@ -4045,4 +4059,8 @@
 Param.Civ1.ImageB=regexprep(Param.Civ1.ImageB,'.png','');
 fid=fopen([filename '.civ1.cmx'],'w');
+if isequal(fid,-1)
+    display(['cmd file ' filename ' cannot be created'])
+    return
+end
 fprintf(fid,['##############   CMX file' '\n' ]);
 fprintf(fid,   ['FirstImage ' regexprep(Param.Civ1.ImageA,'\\','\\\\') '\n' ]);% for windows compatibility
@@ -4358,13 +4376,23 @@
     Data.ListVarName={'ny','nx','A'};
     Data.VarDimName= {'ny','nx',{'ny','nx'}};
-
-    Param=read_GUI(handles.civ)
-    Param.CheckOutputFile=0;
-    [Data,errormsg]=civ_matlab(Param,filecell.nc.civ1{1})% get the grid of x, y positions set for PIV 
-    if ~isempty(errormsg)
-        msgbox_uvmat('ERROR',Data.Txt)
-        return
-    end
-    set(handles.TestCiv1,'BackgroundColor',[1 0 0])
+    
+    param_patch1=read_GUI(handles.Patch1);
+    param_patch1.CivFile=filecell.nc.civ1{1};
+    Param.Patch1=param_patch1;
+    for irho=1:7
+        [Data,errormsg]=civ_matlab(Param);% get the grid of x, y positions set for PIV
+        if ~isempty(errormsg)
+            msgbox_uvmat('ERROR',Data.Txt)
+            return
+        end
+        SmoothingParam(irho)=Param.Patch1.SmoothingParam;
+        Data.Civ1_U_Diff=Data.Civ1_U_Diff(Data.Civ1_FF==0);
+        Data.Civ1_V_Diff=Data.Civ1_V_Diff(Data.Civ1_FF==0);
+        DiffVel(irho)=sqrt(mean(Data.Civ1_U_Diff.*Data.Civ1_U_Diff+Data.Civ1_V_Diff.*Data.Civ1_V_Diff))
+        Param.Patch1.SmoothingParam=2*Param.Patch1.SmoothingParam;
+    end
+    figure
+    plot(SmoothingParam,DiffVel)
+    set(handles.TestPatch1,'BackgroundColor',[1 0 0])
 else
     corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
@@ -4372,5 +4400,5 @@
         delete(corrfig)
     end
-    hview_field=findobj(allchild(0),'tag','view_field');% look for view_field    
+    hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
     if ~isempty(hview_field)
         delete(hview_field)
