Index: /trunk/src/civ.m
===================================================================
--- /trunk/src/civ.m	(revision 318)
+++ /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)
Index: /trunk/src/civ_matlab.m
===================================================================
--- /trunk/src/civ_matlab.m	(revision 318)
+++ /trunk/src/civ_matlab.m	(revision 319)
@@ -46,4 +46,9 @@
 check_patch1=0;%default
 
+if ischar(Param)
+    t=xmltree(Param);
+    Param=convert(t);
+end
+
 %% Civ1
 if isfield (Param,'Civ1')
@@ -62,12 +67,12 @@
     end
     Data.ListGlobalAttribute=[Data.ListGlobalAttribute Civ1_param];% {'Civ1_Time','Civ1_Dt'}];
-%     if exist('ncfile','var')% TEST for use interactively with mouse_motion (no file created)
-        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.VarDimName={'nbvec1','nbvec1','nbvec1','nbvec1','nbvec1','nbvec1'};
-        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';
+    %     if exist('ncfile','var')% TEST for use interactively with mouse_motion (no file created)
+    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.VarDimName={'nbvec1','nbvec1','nbvec1','nbvec1','nbvec1','nbvec1'};
+    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.Civ1_X=reshape(xtable,[],1);
     Data.Civ1_Y=reshape(Param.Civ1.ImageHeight-ytable+1,[],1);
@@ -77,22 +82,26 @@
     Data.Civ1_F=reshape(F,[],1);
     Data.CivStage=1;
-
+    
 else
-    Data=nc2struct(ncfile,'ListGlobalAttribute','absolut_time_T0') %look for the constant 'absolut_time_T0' to detect old civx data format 
+    if exist('ncfile','var')
+        CivFile=ncfile;
+    elseif isfield(Param.Patch1,'CivFile')
+        CivFile=Param.Patch1.CivFile;
+    end
+    Data=nc2struct(CivFile,'ListGlobalAttribute','absolut_time_T0') %look for the constant 'absolut_time_T0' to detect old civx data format
     if isfield(Data,'Txt')
-            errormsg=Data.Txt;
+        errormsg=Data.Txt;
         return
     end
     if ~isempty(Data.absolut_time_T0')%read civx file
         check_civx=1;% test for old civx data format
-        [Data,vardetect,ichoice]=nc2struct(ncfile);%read the variables in the netcdf file
+        [Data,vardetect,ichoice]=nc2struct(CivFile);%read the variables in the netcdf file
     else
         if isfield(Param,'Fix1')
-            Data=nc2struct(ncfile,ListVarCiv1);%read civ1 data in the existing netcdf file
+            Data=nc2struct(CivFile,ListVarCiv1);%read civ1 data in the existing netcdf file
         else
-            Data=nc2struct(ncfile,ListVarFix1);%read civ1 and fix1 data in the existing netcdf file
+            Data=nc2struct(CivFile,ListVarFix1);%read civ1 and fix1 data in the existing netcdf file
         end
     end
-
 end
 
@@ -296,5 +305,5 @@
 
 %% write result in a netcdf file if requested
-if exist('ncfile','var') && ~(isfield(Param,'CheckOuputFile')&&Param.CheckOuputFile)
+if exist('ncfile','var') 
     errormsg=struct2nc(ncfile,Data);
 end
@@ -420,8 +429,8 @@
     iref=par_civ.Grid(ivec,1);% xindex on the image A for the middle of the correlation box
     jref=par_civ.Grid(ivec,2);% yindex on the image B for the middle of the correlation box
-%     xtable(ivec)=iref;
-%     ytable(ivec)=jref;%default
+    %     xtable(ivec)=iref;
+    %     ytable(ivec)=jref;%default
     if ~(checkmask && par_civ.Mask(jref,iref)<=20) %velocity not set to zero by the black mask
-        if jref-iby2<1 || jref+iby2>par_civ.ImageHeight|| iref-ibx2<1 || iref+ibx2>par_civ.ImageWidth
+        if jref-iby2<1 || jref+iby2>par_civ.ImageHeight|| iref-ibx2<1 || iref+ibx2>par_civ.ImageWidth% we are outside the image
             F(ivec)=3;
         else
@@ -434,9 +443,10 @@
                 F(ivec)=3;
             end
+            %threshold on image maximum
+            if check_MaxIma && (image1_mean > par_civ.MaxIma || image2_mean > par_civ.MaxIma)
+                F(ivec)=3;
+            end
         end
-        %threshold on image maximum
-        if check_MaxIma && (image1_mean > par_civ.MaxIma || image2_mean > par_civ.MaxIma)
-            F(ivec)=3;
-        end
+        
         if F(ivec)~=3
             image1_crop=image1_crop-image1_mean;%substract the mean
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m	(revision 318)
+++ /trunk/src/uvmat.m	(revision 319)
@@ -1769,17 +1769,17 @@
 NomType=get(handles.FileIndex,'UserData');
 
-num1=stra2num(get(handles.i1,'String'));
-num2=stra2num(get(handles.i2,'String'));
-num_a=stra2num(get(handles.j1,'String'));
-num_b=stra2num(get(handles.j2,'String'));
+i1=stra2num(get(handles.i1,'String'));
+i2=stra2num(get(handles.i2,'String'));
+j1=stra2num(get(handles.j1,'String'));
+j2=stra2num(get(handles.j2,'String'));
 
 sub_value= get(handles.SubField,'Value');
 if sub_value % a second input file has been entered
     [FileName_1,RootPath_1,filebase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles);
-    [pp,ff,str1,str2,str_a,str_b]=name2display(FileIndices_1);
-    num1_1=stra2num(str1);%current set of indices for the second field (may be set different than the main indices)
-    num2_1=stra2num(str2);
-    num_a_1=stra2num(str_a);
-    num_b_1=stra2num(str_b);
+    [pp,ff,i1_1_str,i2_1_str,j1_1_str,j2_1_str]=name2display(FileIndices_1);
+    i1_1=stra2num(i1_1_str);%current set of indices for the second field (may be set different than the main indices)
+    i2_1=stra2num(i2_1_str);
+    j1_1=stra2num(j1_1_str);
+    j2_1=stra2num(j2_1_str);
     NomType_1=get(handles.FileIndex_1,'UserData');
 else
@@ -1790,44 +1790,56 @@
 %case of scanning along the first direction (rootfile numbers)
 if get(handles.scan_i,'Value')==1% case of scanning along index i   
-     num1=num1+increment;
-     num2=num2+increment;
-     [filename,num1,num_a,num2,num_b]=name_generator(filebase,num1,num_a,FileExt,NomType,comp_input,num2,num_b,subdir);
+     i1=i1+increment;
+     i2=i2+increment;
+     [filename,i1,j1,i2,j2]=name_generator(filebase,i1,j1,FileExt,NomType,comp_input,i2,j2,subdir);
      if sub_value% set the second field name and indices
-        num1_1=num1_1+increment;
-        num2_1=num2_1+increment;
-        filename_1=name_generator(filebase_1,num1_1,num_a_1,FileExt_1,NomType_1,1,num2_1,num_b_1,SubDir_1);
+        i1_1=i1_1+increment;
+        i2_1=i2_1+increment;
+        filename_1=name_generator(filebase_1,i1_1,j1_1,FileExt_1,NomType_1,1,i2_1,j2_1,SubDir_1);
      end   
 else % case of scanning along index j (burst numbers)
-    num_a=num_a+increment;
-    num_b=num_b+increment;
-    [filename,num1,num_a,num2,num_b]=name_generator(filebase,num1,num_a,FileExt,NomType,comp_input,num2,num_b,subdir);
+    j1=j1+increment;
+    j2=j2+increment;
+    [filename,i1,j1,i2,j2]=name_generator(filebase,i1,j1,FileExt,NomType,comp_input,i2,j2,subdir);
     if sub_value 
-        num_a_1=num_a_1+increment;
-        num_b_1=num_b_1+increment;
-        filename_1=name_generator(filebase_1,num1_1,num_a_1,FileExt_1,NomType_1,1,num2_1,num_b_1,SubDir_1);
+        j1_1=j1_1+increment;
+        j2_1=j2_1+increment;
+        filename_1=name_generator(filebase_1,i1_1,j1_1,FileExt_1,NomType_1,1,i2_1,j2_1,SubDir_1);
     end    
 end
 
 % refresh plots
-errormsg=refresh_field(handles,filename,filename_1,num1,num2,num_a,num_b);
+errormsg=refresh_field(handles,filename,filename_1,i1,i2,j1,j2);
 if isempty(errormsg)  %update the index counters
-    set(handles.i1,'String',num2stra(num1,NomType,1)); 
-    if isequal(num2,num1)
-         set(handles.i2,'String','');
+    if strcmp(NomType,'*')%case of movies
+        set(handles.i1,'String',num2str(i1))%update the index display
     else
-        set(handles.i2,'String',num2stra(num2,NomType,1));
-    end 
-    set(handles.j1,'String',num2stra(num_a,NomType,2));
-    if isequal(num_b,num_a)
-         set(handles.j2,'String','');
-    else
-        set(handles.j2,'String',num2stra(num_b,NomType,2));
-    end
-    [indices]=name_generator('',num1,num_a,'',NomType,1,num2,num_b,'');
-    set(handles.FileIndex,'String',indices);
-    if ~isempty(filename_1) 
-         indices_1=name_generator('',num1_1,num_a_1,'',NomType_1,1,num2_1,num_b_1,'');
-         set(handles.FileIndex_1,'String',indices_1);
-    end
+        [~,~,i1_str,i2_str,j1_str,j2_str]=name2display(filename);
+        set(handles.i1,'String',i1_str)
+        set(handles.j1,'String',j1_str)
+        if ~isequal(movie_status,1)
+            set(handles.i2,'String',i2_str)
+            set(handles.j2,'String',j2_str)
+        end
+        [indices]=name_generator('',i1,j1,'',NomType,1,i2,j2,'');
+        set(handles.FileIndex,'String',indices);
+        if ~isempty(filename_1)
+            indices_1=name_generator('',i1_1,j1_1,'',NomType_1,1,i2_1,j2_1,'');
+            set(handles.FileIndex_1,'String',indices_1);
+        end
+    end
+    %     set(handles.i1,'String',num2stra(i1,NomType,1));
+    %     if isequal(i2,i1)
+    %          set(handles.i2,'String','');
+    %     else
+    %         set(handles.i2,'String',num2stra(num2,NomType,1));
+    %     end
+    %     set(handles.j1,'String',num2stra(j1,NomType,2));
+    %     if isequal(j2,j1)
+    %          set(handles.j2,'String','');
+    %     else
+    %         set(handles.j2,'String',num2stra(j2,NomType,2));
+    %     end
+    
     if isequal(movie_status,1)
         set(handles.movie_pair,'Value',1)
