Index: /trunk/src/civ.m
===================================================================
--- /trunk/src/civ.m	(revision 262)
+++ /trunk/src/civ.m	(revision 263)
@@ -1508,6 +1508,7 @@
     return
 end
-[filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc]=...
-    set_civ_filenames(handles,ref_i,ref_j,box_test);
+[filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,xx,yy,compare]=...
+    set_civ_filenames(handles,ref_i,ref_j,box_test)
+
 set(handles.civ,'UserData',filecell);%store for futur use of status callback
 if isempty(filecell)% (error message displayed in fct set_civ_filenames)
@@ -1602,5 +1603,5 @@
         if isfield(sparam,'Civ1Bin')
             Civ1Bin=sparam.Civ1Bin;
-            if ~exist(Civ1Bin,'file')||isempty(which(Civ1Bin))% if path defined as relative to uvmat
+            if ~exist(Civ1Bin,'file')&&~isempty(which(Civ1Bin))% if path defined as relative to uvmat
                 sparam.Civ1Bin=fullfile(path_UVMAT,Civ1Bin);
                 if ~exist(sparam.Civ1Bin,'file')
@@ -1612,5 +1613,5 @@
         if isfield(sparam,'Civ2Bin')
             Civ2Bin=sparam.Civ2Bin;
-            if ~exist(Civ2Bin,'file')||isempty(which(Civ2Bin))% if path defined as relative to uvmat
+            if ~exist(Civ2Bin,'file')&&~isempty(which(Civ2Bin))% if path defined as relative to uvmat
                 sparam.Civ2Bin=fullfile(path_UVMAT,Civ2Bin);
                 if ~exist(sparam.Civ2Bin,'file')
@@ -1621,10 +1622,10 @@
         end
         if  isfield(sparam,'PatchBin')
-            if ~exist(sparam.PatchBin,'file')||isempty(which(sparam.PatchBin))% if path defined as relative to uvmat
+            if ~exist(sparam.PatchBin,'file')&&~isempty(which(sparam.PatchBin))% if path defined as relative to uvmat
                 sparam.PatchBin=fullfile(path_UVMAT,sparam.PatchBin);
             end
         end
         if isfield(sparam,'FixBin')
-            if ~exist(sparam.FixBin,'file')||isempty(which(sparam.FixBin))% if path defined as relative to uvmat
+            if ~exist(sparam.FixBin,'file')&&~isempty(which(sparam.FixBin))% if path defined as relative to uvmat
                 sparam.FixBin=fullfile(path_UVMAT,sparam.FixBin);
             end
@@ -1758,5 +1759,5 @@
                 CivAllxml=set(CivAllxml,1,'name','CivDoc');
         end
-        [Rootbat,Filebat]=fileparts(filecell.nc.civ1{ifile,j});%output netcdf file (without extention)
+        [Rootbat,Filebat]=fileparts(filecell.nc.civ1{ifile,j});%output netcdf file (without extension)
         flname=fullfile(Rootbat,Filebat);
         if batch
@@ -2164,7 +2165,15 @@
                 end
                 if box_test(3)==1
-                    Param.Patch1.Rho=rho_patch1;
-                    Param.Patch1.Threshold=thresh_patch1;
-                    Param.Patch1.SubDomain=subdomain_patch1;
+                    if strcmp(compare,'stereo PIV')
+                        filebase_A=filecell.filebase;
+                        [pp,ff]=fileparts(filebase_A);
+                        filebase_B=fullfile(pp,get(handles.RootName_1,'String'));
+                        RUN_STLIN(filecell.ncA.civ1{ifile,j},filecell.nc.civ1{ifile,j},'civ1',filecell.st{ifile,j},...
+                            str2num(nx_patch1),str2num(ny_patch1),str2num(thresh_patch1),[filebase_A '.xml'],[filebase_B '.xml'])
+                    else
+                        Param.Patch1.Rho=rho_patch1;
+                        Param.Patch1.Threshold=thresh_patch1;
+                        Param.Patch1.SubDomain=subdomain_patch1;
+                    end
                 end
                 if box_test(4)==1
@@ -2193,9 +2202,20 @@
                     Param.Fix2=fix2;
                 end
-                [Data,erromsg]=civ_uvmat(Param,filecell.nc.civ1{ifile,j});
-                if isempty(errormsg)
-                    display([filecell.nc.civ1{ifile,j} ' written'])
-                else
-                    msgbox_uvmat('ERROR',errormsg)
+                if box_test(6)==1
+                    if strcmp(compare,'stereo PIV')
+                        filebase_A=filecell.filebase;
+                        [pp,ff]=fileparts(filebase_A);
+                        filebase_B=fullfile(pp,get(handles.RootName_1,'String'));
+                        RUN_STLIN(filecell.ncA.civ2{ifile,j},filecell.nc.civ2{ifile,j},'civ2',filecell.st{ifile,j},...
+                            str2num(nx_patch2),str2num(ny_patch2),str2num(thresh_patch2),[filebase_A '.xml'],[filebase_B '.xml'])
+                    end
+                end
+                if ~strcmp(compare,'stereo PIV')
+                    [Data,erromsg]=civ_uvmat(Param,filecell.nc.civ1{ifile,j});
+                    if isempty(errormsg)
+                        display([filecell.nc.civ1{ifile,j} ' written'])
+                    else
+                        msgbox_uvmat('ERROR',errormsg)
+                    end
                 end
         end
@@ -2273,5 +2293,5 @@
 %------------------------------------------------------------------------
 % --- determine the list of filenames and indices needed for launch_job
-function [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2]=...
+function [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2,compare]=...
     set_civ_filenames(handles,ref_i,ref_j,box_test)
 %------------------------------------------------------------------------
@@ -2503,6 +2523,6 @@
         %create the new subdir_civ1
         if ~exist(fullfile(Path_ima,subdir_civ1_new),'dir')
-            cd(Path_ima);          
-            [xx,msg1]=mkdir(subdir_civ1_new);
+%             cd(Path_ima);          
+            [xx,msg1]=mkdir(fullfile(Path_ima,subdir_civ1_new));
 
             if ~strcmp(msg1,'')
@@ -2518,5 +2538,5 @@
                 end
             end
-            cd(currentdir);
+%             cd(currentdir);
         end
         if strcmp(compare,'stereo PIV')&&(strcmp(mode,'pair j1-j2')||strcmp(mode,'series(Dj)')||strcmp(mode,'series(Di)'))%check second nc series
@@ -2544,11 +2564,11 @@
             end
             %create the new subdir_civ1
-            if exist(fullfile(Path_ima,subdir_civ1_new),'dir')
-                   cd(Path_ima);          
-                [xx,msg1]=mkdir(subdir_civ1_new);
-                            cd(currentdir);
+            if ~exist(fullfile(Path_ima,subdir_civ1_new),'dir')
+%                    cd(Path_ima);          
+                [xx,msg1]=mkdir(fullfile(Path_ima,subdir_civ1_new));
+%                             cd(currentdir);
                 if ~strcmp(msg1,'')
                     msgbox_uvmat('ERROR',['cannot create ' subdir_civ1_new ': ' msg1])
-                    cd(currentdir)
+%                     cd(currentdir)
                     filecell={};
                     return
@@ -2557,5 +2577,5 @@
                     if ~strcmp(msg2,'')
                         msgbox_uvmat('ERROR',['pb of permission for ' subdir_civ1_new ': ' msg2])%error message for directory creation
-                        cd(currentdir)
+%                         cd(currentdir)
                         filecell={};
                         return
@@ -4463,5 +4483,5 @@
 %------------------------------------------------------------------------
 test=get(handles.compare,'Value');
-if test==2 || test==3
+if test==2 || test==3 % case 'dispalcemen' or 'stereo PIV'
     filebase=get(handles.RootName,'String');
     browse=get(handles.browse_root,'Userdata');
@@ -4475,6 +4495,8 @@
     if test==2
         set(handles.mode,'Visible','off')
+        set(handles.CivMode,'Value',1) % mode 'civX' selected by default
     else
         set(handles.mode,'Visible','on')
+        set(handles.CivMode,'Value',3) % mode 'Matlab' selected for stereo 
     end
     
@@ -4496,17 +4518,17 @@
     sizf=size(fileinput);
     if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
-    [path,name,ext]=fileparts(fileinput);
+    [path,name,ext]=fileparts(fileinput)
     [path1]=fileparts(filebase);
-%     if isunix
-%         ['readlink ' path]
-%         [status,path]=system(['readlink ' path])
-%         [status,path1]=system(['readlink ' path1])% look for the true path in case of symbolic paths
-%     end
+    if isunix
+        [status,path]=system(['readlink ' path])
+        [status,path1]=system(['readlink ' path1])% look for the true path in case of symbolic paths
+    end
     if ~strcmp(path1,path)
-        msgbox_uvmat('ERROR','The two  input image series must be in the same directory')
+        msgbox_uvmat('ERROR','The second image series must be in the same directory as the first one')
         return
-    end
-    set(handles.RootName_1,'String',name);
+     end
+%     set(handles.RootName_1,'String',name);
     [RootPath,RootFile,field_count,str2,str_a,str_b,xx,nom_type,subdir]=name2display(name);
+    set(handles.RootName_1,'String',RootFile);
     browse=get(handles.browse_root,'UserData');
     browse.nom_type_ima_1=nom_type;
@@ -4515,20 +4537,20 @@
     %check image extension
     if ~strcmp(ext,get(handles.ImaExt,'String'))
-        msgbox_uvmat('ERROR','The two  input image series must have the same extension name')
+        msgbox_uvmat('ERROR','The second image series must have the same extension name as the first one')
         return
     end
     
     %% check coincidence of image sizes
-    ref_i=get(handles.ref_i,'string');
-    ref_j=get(handles.ref_j,'string');
-    [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc]=set_civ_filenames(handles,ref_i,ref_j,[1 0 0 0 0 0]);
-    A=imread(filecell.ima1.civ1{1});
-    A_1=imread(fileinput);
-    npxy=size(A);
-    npxy_1=size(A_1);
-    if ~isequal(size(A),size(A_1))
-        msgbox_uvmat('ERROR','The two input image series do not have the same size')
-        return
-    end
+%     ref_i=get(handles.ref_i,'string');
+%     ref_j=get(handles.ref_j,'string');
+%     [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc]=set_civ_filenames(handles,ref_i,ref_j,[1 0 0 0 0 0]);
+%     A=imread(filecell.ima1.civ1{1});
+%     A_1=imread(fileinput);
+%     npxy=size(A);
+%     npxy_1=size(A_1);
+%     if ~isequal(size(A),size(A_1))
+%         msgbox_uvmat('ERROR','The two input image series do not have the same size')
+%         return
+%     end
 else
     set(handles.mode,'Visible','on')
@@ -4541,14 +4563,15 @@
     set(handles.test_stereo1,'Value',0)
     set(handles.test_stereo2,'Value',0)
+    set(handles.CivMode,'Value',1) % mode 'civX' selected by default
 end
 if test==3 && get(handles.PATCH1,'Value')
-    set(handles.stereo1,'Visible','on')
-else
-    set(handles.stereo1,'Visible','off')
+    set(handles.test_stereo1,'Visible','on')
+else
+    set(handles.test_stereo1,'Visible','off')
 end
 if test==3 && get(handles.PATCH2,'Value')
-    set(handles.stereo2,'Visible','on')
-else
-    set(handles.stereo2,'Visible','off')
+    set(handles.test_stereo2,'Visible','on')
+else
+    set(handles.test_stereo2,'Visible','off')
 end
 mode_Callback(hObject, eventdata, handles)
