Index: /trunk/src/civ.m
===================================================================
--- /trunk/src/civ.m	(revision 237)
+++ /trunk/src/civ.m	(revision 238)
@@ -66,5 +66,5 @@
 filebase=''; % root file name ('filebase'.civ)
 ext=[];
-testall=0;
+set(handles.CivAll,'String',{'CivX';'CivAll';'CivUvmat'})
 %default input parameters:
 num_i1=1; % set of field i numbers
@@ -106,5 +106,4 @@
 end
 set(handles.RootName,'String',filebase);
-set(handles.ImaDoc,'UserData',testall);
 set(handles.ImaDoc,'String',ext)
 
@@ -113,8 +112,5 @@
 path_UVMAT=fileparts(path_uvmat); %path to UVMAT
 errormsg=[];%default error message
-% xmlfile=fullfile(path_UVMAT,'PARAM.xml');
-% if ~exist(xmlfile,'file')
 xmlfile='PARAM.xml';
-% end
 if exist(xmlfile,'file')
     try
@@ -269,12 +265,7 @@
     oldfile=filebase;
 end
-% testall=get(handles.ImaDoc,'UserData');
 ind_opening=1;%default
 browse.incr_pair=[0 0]; %default
-% if testall
-%     menu={'*.*', 'All Files (*.*)'; '*.xml; *.avi;*.AVI;*.nc','(*.xml,*.avi,*.nc)'; ...
-%         '*.xml', '.xml files';'*.avi;*.AVI', '.avi files';'*.nc','.nc files'};
-% else % menu selecting only .civ or .avi files
- menu={'*.xml;*.civ;*.png;*.jpg;*.tif;*.avi;*.AVI;*.nc;', ' (*.xml,*.civ,*.png,*.jpg ,.tif, *.avi,*.nc)';
+menu={'*.xml;*.civ;*.png;*.jpg;*.tif;*.avi;*.AVI;*.nc;', ' (*.xml,*.civ,*.png,*.jpg ,.tif, *.avi,*.nc)';
        '*.xml',  '.xml files '; ...
         '*.civ',  '.civ files '; ...
@@ -285,8 +276,4 @@
         '*.nc','.netcdf files'; ...
         '*.*',  'All Files (*.*)'};
-   % menu={'*.xml;*.avi;*.AVI;*.nc','(*.xml,*.avi,*.nc)'; ...
-     %   '*.xml', '.xml files';'*.avi;*.AVI', '.avi files';'*.nc', '.nc files';...
-    %    '*.*', 'All Files (*.*)'};
-% end
 [FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file',oldfile);
 fileinput=[PathName FileName];%complete file name
@@ -442,6 +429,4 @@
 end
 set(handles.browse_root,'UserData',browse);% store information from browser
-% testall=isequal(menu(filtindex,1),{'*.*'});
-% set(handles.ImaDoc,'UserData',testall);
 
 RootName_Callback(hObject, eventdata, handles);
@@ -1583,6 +1568,13 @@
     end
 end
-civAll=isequal(get(handles.CivAll,'Value'),2); % Boolean for new civ programs
-if civAll && isfield(sparam,'CivBin')
+
+%% choose the civ program
+ProgList=get(handles.CivAll,'String');
+index=get(handles.CivAll,'Value');
+CivX=isequal(ProgList{index},'CivX');
+CivAll=isequal(ProgList{index},'CivAll');
+CivUvmat=isequal(ProgList{index},'CivUvmat');
+%CivAll=isequal(get(handles.CivAll,'Value'),2); % Boolean for new civ programs
+if CivAll && isfield(sparam,'CivBin')
     CivBin=sparam.CivBin;
     if ~exist(CivBin,'file') || ~isempty(which(CivBin))% if path defined as relative to uvmat 
@@ -1739,8 +1731,8 @@
             cmd=[cmd 'umask 002 \n'];%allow writting access to created files for user group
         end
-        if civAll
-            civAllxml=xmltree;% xml contents,  all parameters
-            civAllCmd='';
-            civAllxml=set(civAllxml,1,'name','CivDoc');
+        if CivAll
+            CivAllxml=xmltree;% xml contents,  all parameters
+            CivAllCmd='';
+            CivAllxml=set(CivAllxml,1,'name','CivDoc');
         end
         [Rootbat,Filebat]=fileparts(filecell.nc.civ1{ifile,j});%output netcdf file (without extention)
@@ -1808,5 +1800,5 @@
             %
             i_cmd=i_cmd+1;
-            if isequal(civAll,0)
+            if isequal(CivAll,0)
                 civ1_exe=CIV1_CMD(fullfile(Rootbat,Filebat),'',par_civ1,handles,sparam);%create the parameter file .civ1.cmx and set the execution string civ1_exe
 %                 if(isunix)
@@ -1818,13 +1810,13 @@
                 cmd=[cmd civ1_exe '\n'];
             else
-                civAllCmd=[civAllCmd ' civ1 '];
+                CivAllCmd=[CivAllCmd ' civ1 '];
                 str=CIV1_CMD_Unified(fullfile(Rootbat,Filebat),'',par_civ1);
                 fieldnames=fields(str);
-                [civAllxml,uid_civ1]=add(civAllxml,1,'element','civ1');
+                [CivAllxml,uid_civ1]=add(CivAllxml,1,'element','civ1');
                 for ilist=1:length(fieldnames)
                     val=eval(['str.' fieldnames{ilist}]);
                     if ischar(val)
-                        [civAllxml,uid_t]=add(civAllxml,uid_civ1,'element',fieldnames{ilist});
-                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
+                        [CivAllxml,uid_t]=add(CivAllxml,uid_civ1,'element',fieldnames{ilist});
+                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
                     end
                 end
@@ -1844,5 +1836,5 @@
                 maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
             end
-            if isequal(civAll,0)
+            if CivX
                 if isunix %unix system
                 cmd_FIX=[sparam.FixBin ' -f ' filecell.nc.civ1{ifile,j} ' -fi1 ' num2str(flagindex1(1)) ...
@@ -1856,5 +1848,5 @@
                 end
                 cmd=[cmd cmd_FIX '\n'];
-            else
+            elseif CivAll
                 fix1.inputFileName=filecell.nc.civ1{ifile,j} ;
                 fix1.fi1=num2str(flagindex1(1));
@@ -1864,13 +1856,13 @@
                 fix1.threshV=num2str(thresh_vel1);
                 fieldnames=fields(fix1);
-                [civAllxml,uid_fix1]=add(civAllxml,1,'element','fix1');
+                [CivAllxml,uid_fix1]=add(CivAllxml,1,'element','fix1');
                 for ilist=1:length(fieldnames)
                     val=eval(['fix1.' fieldnames{ilist}]);
                     if ischar(val)
-                        [civAllxml,uid_t]=add(civAllxml,uid_fix1,'element',fieldnames{ilist});
-                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
+                        [CivAllxml,uid_t]=add(CivAllxml,uid_fix1,'element',fieldnames{ilist});
+                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
                     end
                 end
-                civAllCmd=[civAllCmd ' fix1 '];
+                CivAllCmd=[CivAllCmd ' fix1 '];
             end
         end
@@ -1878,5 +1870,5 @@
         %PATCH1
         if box_test(3)==1
-            if isequal(civAll,0)
+            if isequal(CivAll,0)
                 cmd_PATCH=PATCH_CMD(filecell.nc.civ1{ifile,j},nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,test_interp,sparam.PatchBin);
                 cmd=[cmd cmd_PATCH '\n'];
@@ -1912,13 +1904,13 @@
                 patch1.convectFlow='n';
                 fieldnames=fields(patch1);
-                [civAllxml,uid_patch1]=add(civAllxml,1,'element','patch1');
+                [CivAllxml,uid_patch1]=add(CivAllxml,1,'element','patch1');
                 for ilist=1:length(fieldnames)
                     val=eval(['patch1.' fieldnames{ilist}]);
                     if ischar(val)
-                        [civAllxml,uid_t]=add(civAllxml,uid_patch1,'element',fieldnames{ilist});
-                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
+                        [CivAllxml,uid_t]=add(CivAllxml,uid_patch1,'element',fieldnames{ilist});
+                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
                     end
                 end
-                civAllCmd=[civAllCmd ' patch1 '];
+                CivAllCmd=[CivAllCmd ' patch1 '];
             end
         end
@@ -1987,5 +1979,5 @@
             flname=fullfile(Rootbat,Filebat);
             
-            if isequal(civAll,0)
+            if isequal(CivAll,0)
                 cmd_CIV2=CIV2_CMD(flname,[],par_civ2,sparam);%creates the cmx file [fullfile(Rootbat,Filebat) '.civ2.cmx]
 %                 if(isunix)
@@ -1996,13 +1988,13 @@
 %                 end
             else
-                civAllCmd=[civAllCmd ' civ2 '];
+                CivAllCmd=[CivAllCmd ' civ2 '];
                 str=CIV2_CMD_Unified(flname,'',par_civ2);
                 fieldnames=fields(str);
-                [civAllxml,uid_civ2]=add(civAllxml,1,'element','civ2');
+                [CivAllxml,uid_civ2]=add(CivAllxml,1,'element','civ2');
                 for ilist=1:length(fieldnames)
                     val=eval(['str.' fieldnames{ilist}]);
                     if ischar(val)
-                        [civAllxml,uid_t]=add(civAllxml,uid_civ2,'element',fieldnames{ilist});
-                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
+                        [CivAllxml,uid_t]=add(CivAllxml,uid_civ2,'element',fieldnames{ilist});
+                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
                     end
                 end
@@ -2022,5 +2014,5 @@
                 maskname =name_generator(maskbase,num1_mask,1,'.png','_i');
             end
-            if isequal(civAll,0)
+            if isequal(CivAll,0)
                 if isunix
                 cmd_FIX=[sparam.FixBin ' -f ' filecell.nc.civ2{ifile,j} ' -fi1 ' num2str(flagindex2(1)) ...
@@ -2042,13 +2034,13 @@
                 fix2.threshV=num2str(thresh_vel2);
                 fieldnames=fields(fix2);
-                [civAllxml,uid_fix2]=add(civAllxml,1,'element','fix2');
+                [CivAllxml,uid_fix2]=add(CivAllxml,1,'element','fix2');
                 for ilist=1:length(fieldnames)
                     val=eval(['fix2.' fieldnames{ilist}]);
                     if ischar(val)
-                        [civAllxml,uid_t]=add(civAllxml,uid_fix2,'element',fieldnames{ilist});
-                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
+                        [CivAllxml,uid_t]=add(CivAllxml,uid_fix2,'element',fieldnames{ilist});
+                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
                     end
                 end
-                civAllCmd=[civAllCmd ' fix2 '];
+                CivAllCmd=[CivAllCmd ' fix2 '];
             end
         end
@@ -2056,5 +2048,5 @@
         %PATCH2
         if box_test(6)==1
-            if isequal(civAll,0)
+            if isequal(CivAll,0)
                 cmd_PATCH=PATCH_CMD(filecell.nc.civ2{ifile,j},nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,thresh_patch2,test_interp,sparam.PatchBin);
                 cmd=[cmd cmd_PATCH '\n'];
@@ -2090,18 +2082,18 @@
                 patch2.convectFlow='n';
                 fieldnames=fields(patch2);
-                [civAllxml,uid_patch2]=add(civAllxml,1,'element','patch2');
+                [CivAllxml,uid_patch2]=add(CivAllxml,1,'element','patch2');
                 for ilist=1:length(fieldnames)
                     val=eval(['patch2.' fieldnames{ilist}]);
                     if ischar(val)
-                        [civAllxml,uid_t]=add(civAllxml,uid_patch2,'element',fieldnames{ilist});
-                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
+                        [CivAllxml,uid_t]=add(CivAllxml,uid_patch2,'element',fieldnames{ilist});
+                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
                     end
                 end
-                civAllCmd=[civAllCmd ' patch2 '];
-            end
-        end
-        if isequal(civAll,1)
-            save(civAllxml,[flname '.xml']);
-            cmd=[cmd sparam.CivBin ' -f ' flname '.xml '  civAllCmd ' >' flname '.log' '\n'];
+                CivAllCmd=[CivAllCmd ' patch2 '];
+            end
+        end
+        if CivAll
+            save(CivAllxml,[flname '.xml']);
+            cmd=[cmd sparam.CivBin ' -f ' flname '.xml '  CivAllCmd ' >' flname '.log' '\n'];
         end
         % create the .bat file:
@@ -2120,5 +2112,5 @@
                     eval(  ['!qsub -p ' pvalue ' -q civ.q -e ' flname '.errors -o ' flname '.log' ' ' filename_bat]);
             end
-        elseif ~isequal(get(handles.CivAll,'Value'),3)
+        elseif ~CivUvmat
             %% to lauch the jobs locally :
             if(isunix)
@@ -2130,44 +2122,29 @@
             disp(cmd_str);
         else       %run PIVlab if selected
-            Data=civ_uvmat(par_civ1);
-%             image1=imread(par_civ1.filename_ima_a);
-%             image2=imread(par_civ1.filename_ima_b);     
-%             stepx=str2num(par_civ1.dx);
-%             stepy=str2num(par_civ1.dy);
-%             ibx2=ceil(str2num(par_civ1.ibx)/2);
-%             iby2=ceil(str2num(par_civ1.iby)/2);
-%             isx2=ceil(str2num(par_civ1.isx)/2);
-%             isy2=ceil(str2num(par_civ1.isy)/2);
-%             shiftx=str2num(par_civ1.shiftx);
-%             shifty=str2num(par_civ1.shifty);
-% %             ibx=2*ibx2-1;%ibx and iby odd, reduced by 1 if even
-% %             iby=2*iby2-1;
-%             miniy=max(1+isy2-shifty,1+iby2);
-%             minix=max(1+isx2-shiftx,1+ibx2);
-%             maxiy=min(size(image1,1)-isy2-shifty,size(image1,1)-iby2); 
-%             maxix=min(size(image1,2)-isx2-shiftx,size(image1,2)-ibx2); 
-%             [GridX,GridY]=meshgrid(minix:stepx:maxix,miniy:stepy:maxiy);
-%             PointCoord(:,1)=reshape(GridX,[],1);
-%             PointCoord(:,2)=reshape(GridY,[],1);
-%             % caluclate velocity data (y and v in indices, reverse to y component)
-%             [xtable ytable utable vtable ctable typevector] = pivlab (image1,image2,ibx2,iby2,isx2,isy2,shiftx,shifty,PointCoord, 1, []); 
-%                Data.ListGlobalAttribute={'title','Time','Dt'};
-%                Data.title='PIVlab';
-%                Data.Time=str2double(par_civ1.T0);
-%                Data.Dt=str2double(par_civ1.Dt);
-%                Data.ListVarName={'X','Y','U','V','C','FF'};%  cell array containing the names of the fields to record
-%                Data.VarDimName={'nbvec','nbvec','nbvec','nbvec','nbvec','nbvec'};
-%                 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='errorflag';
-%             Data.X=reshape(xtable,[],1);
-%             Data.Y=reshape(size(image1,1)-ytable+1,[],1);
-%             Data.U=reshape(utable,[],1);
-%             Data.V=reshape(-vtable,[],1);
-%             Data.C=reshape(ctable,[],1);
-%             Data.FF=reshape(~typevector,[],1);
-            errormsg=struct2nc(filecell.nc.civ1{ifile,j},Data);
+            if box_test(1)==1
+                Param.Civ1=par_civ1;
+            end
+            if box_test(2)==1
+                fix1.WarnFlags=[];
+                if get(handles.vec_Fmin2,'Value')
+                    fix1.WarnFlags=[fix1.WarnFlags -2];
+                end
+                if get(handles.vec_F3,'Value')
+                    fix1.WarnFlags=[fix1.WarnFlags 3];
+                end
+                fix1.LowerBoundCorr=thresh_vecC1;
+                if get(handles.inf_sup1,'Value')
+                    fix1.UppperBoundVel=thresh_vel1;
+                else
+                     fix1.LowerBoundVel=thresh_vel1;
+                end
+                Param.Fix1=fix1;
+            end
+            if box_test(3)==1
+                Param.Patch1.Rho=rho_patch1;
+                Param.Patch1.Threshold=thresh_patch1;
+                Param.Patch1.SubDomain=subdomain_patch1;
+            end
+            [Data,erromsg]=civ_uvmat(Param,filecell.nc.civ1{ifile,j});
             if isempty(errormsg)
                 display([filecell.nc.civ1{ifile,j} ' written'])
@@ -2179,5 +2156,5 @@
 end
 
-if ~batch && ~isequal(get(handles.CivAll,'Value'),3)
+if ~batch && ~CivUvmat
     [Rootbat,Filebat,extbat]=fileparts(filename_bat);
     filename_superbat=fullfile(Rootbat,'job_list.bat');
@@ -4006,4 +3983,8 @@
 end
 par.rho=get(handles.rho,'String');
+if isequal(get(handles.rho,'Style'),'popupmenu')
+    index=get(handles.rho,'Value');
+    par.rho=par.rho{index};
+end
 par.dx=get(handles.dx_civ1,'String');
 par.dy=get(handles.dy_civ1,'String');
@@ -4301,50 +4282,50 @@
 end
 
-%------------------------------------------------------------------------
-% --- civ using pivlab
-function Data=civ_uvmat(par_civ1)
-%------------------------------------------------------------------------
-image1=imread(par_civ1.filename_ima_a);
-image2=imread(par_civ1.filename_ima_b);
-stepx=str2num(par_civ1.dx);
-stepy=str2num(par_civ1.dy);
-ibx2=ceil(str2num(par_civ1.ibx)/2);
-iby2=ceil(str2num(par_civ1.iby)/2);
-isx2=ceil(str2num(par_civ1.isx)/2);
-isy2=ceil(str2num(par_civ1.isy)/2);
-shiftx=str2num(par_civ1.shiftx);
-shifty=str2num(par_civ1.shifty);
-miniy=max(1+isy2-shifty,1+iby2);
-minix=max(1+isx2-shiftx,1+ibx2);
-maxiy=min(size(image1,1)-isy2-shifty,size(image1,1)-iby2);
-maxix=min(size(image1,2)-isx2-shiftx,size(image1,2)-ibx2);
-[GridX,GridY]=meshgrid(minix:stepx:maxix,miniy:stepy:maxiy);
-PointCoord(:,1)=reshape(GridX,[],1);
-PointCoord(:,2)=reshape(GridY,[],1);
-% caluclate velocity data (y and v in indices, reverse to y component)
-[xtable ytable utable vtable ctable F] = pivlab (image1,image2,ibx2,iby2,isx2,isy2,shiftx,shifty,PointCoord, 1, []);
-Data.ListGlobalAttribute=[{'Conventions','Program','CivStage'} {'Time','Dt'}];
-Data.Conventions='uvmat/civdata';
-Data.Program='civ_uvmat';
-Data.CivStage=1;
-% list_param=fieldnames(Param.Civ1);
-% for ilist=1:length(list_param)
-%     eval(['Data.Civ1_' list_param{ilist} '=Param.Civ1.' list_param{ilist} ';'])
-% end
-Data.Time=str2double(par_civ1.T0);
-Data.Dt=str2double(par_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.VarDimName={'nbvec','nbvec','nbvec','nbvec','nbvec','nbvec'};
-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(size(image1,1)-ytable+1,[],1);
-Data.Civ1_U=reshape(utable,[],1);
-Data.Civ1_V=reshape(-vtable,[],1);
-Data.Civ1_C=reshape(ctable,[],1);
-Data.Civ1_F=reshape(F,[],1);
+% %------------------------------------------------------------------------
+% % --- civ using pivlab
+% function Data=civ_uvmat(par_civ1)
+% %------------------------------------------------------------------------
+% image1=imread(par_civ1.filename_ima_a);
+% image2=imread(par_civ1.filename_ima_b);
+% stepx=str2num(par_civ1.dx);
+% stepy=str2num(par_civ1.dy);
+% ibx2=ceil(str2num(par_civ1.ibx)/2);
+% iby2=ceil(str2num(par_civ1.iby)/2);
+% isx2=ceil(str2num(par_civ1.isx)/2);
+% isy2=ceil(str2num(par_civ1.isy)/2);
+% shiftx=str2num(par_civ1.shiftx);
+% shifty=str2num(par_civ1.shifty);
+% miniy=max(1+isy2-shifty,1+iby2);
+% minix=max(1+isx2-shiftx,1+ibx2);
+% maxiy=min(size(image1,1)-isy2-shifty,size(image1,1)-iby2);
+% maxix=min(size(image1,2)-isx2-shiftx,size(image1,2)-ibx2);
+% [GridX,GridY]=meshgrid(minix:stepx:maxix,miniy:stepy:maxiy);
+% PointCoord(:,1)=reshape(GridX,[],1);
+% PointCoord(:,2)=reshape(GridY,[],1);
+% % caluclate velocity data (y and v in indices, reverse to y component)
+% [xtable ytable utable vtable ctable F] = pivlab (image1,image2,ibx2,iby2,isx2,isy2,shiftx,shifty,PointCoord, 1, []);
+% Data.ListGlobalAttribute=[{'Conventions','Program','CivStage'} {'Time','Dt'}];
+% Data.Conventions='uvmat/civdata';
+% Data.Program='civ_uvmat';
+% Data.CivStage=1;
+% % list_param=fieldnames(Param.Civ1);
+% % for ilist=1:length(list_param)
+% %     eval(['Data.Civ1_' list_param{ilist} '=Param.Civ1.' list_param{ilist} ';'])
+% % end
+% Data.Time=str2double(par_civ1.T0);
+% Data.Dt=str2double(par_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.VarDimName={'nbvec','nbvec','nbvec','nbvec','nbvec','nbvec'};
+% 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(size(image1,1)-ytable+1,[],1);
+% Data.Civ1_U=reshape(utable,[],1);
+% Data.Civ1_V=reshape(-vtable,[],1);
+% Data.Civ1_C=reshape(ctable,[],1);
+% Data.Civ1_F=reshape(F,[],1);
 
 %------------------------------------------------------------------------
@@ -4918,12 +4899,28 @@
 % --- Executes on button press in CivAll.
 function CivAll_Callback(hObject, eventdata, handles)
-if get(handles.CivAll,'Value')==2
-    if get(handles.PATCH1,'Value')
-        set(handles.thresh_patch1,'Visible','on')
-        set(handles.thresh_text1,'Visible','on')
-    end
-else
-    set(handles.thresh_patch1,'Visible','off')
-    set(handles.thresh_text1,'Visible','off')
-end
-
+Listprog=get(handles.CivAll,'String');
+index=get(handles.CivAll,'Value');
+prog=Listprog{index};
+switch prog
+    case 'CivX'
+        set(handles.thresh_patch1,'Visible','off')
+        set(handles.thresh_text1,'Visible','off')
+        set(handles.rho,'Style','edit')
+        set(handles.rho,'String','1')
+    case 'CivAll'
+        if get(handles.PATCH1,'Value')
+            set(handles.thresh_patch1,'Visible','on')
+            set(handles.thresh_text1,'Visible','on')
+        end
+        set(handles.rho,'Style','edit')
+        set(handles.rho,'String','1')
+    case 'CivUvmat'
+        if get(handles.PATCH1,'Value')
+            set(handles.thresh_patch1,'Visible','on')
+            set(handles.thresh_text1,'Visible','on')
+        end
+        set(handles.rho,'Style','popupmenu')
+        set(handles.rho,'Value',1)
+        set(handles.rho,'String',{'1';'2'})
+end
+
Index: /trunk/src/geometry_calib.m
===================================================================
--- /trunk/src/geometry_calib.m	(revision 237)
+++ /trunk/src/geometry_calib.m	(revision 238)
@@ -458,14 +458,20 @@
 norm=abs(det(R));
 GeometryCalib.CalibrationType='linear';
+if (a_X1(2)/a_Y1(3))>0
+    epsilon=1;
 GeometryCalib.fx_fy(1)=sqrt((a_X1(2)/a_Y1(3))*norm);
+else
+    GeometryCalib.fx_fy(1)=-sqrt((-a_X1(2)/a_Y1(3))*norm);
+      epsilon=-1;
+end
 GeometryCalib.fx_fy(2)=(a_Y1(3)/a_X1(2))*GeometryCalib.fx_fy(1);
 GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
 %GeometryCalib.Tx_Ty_Tz=[a_X1(1) a_Y1(1) 1]; 
 GeometryCalib.Tx_Ty_Tz=[a_X1(1)/GeometryCalib.fx_fy(1) a_Y1(1)/GeometryCalib.fx_fy(2) 1];
-R(1,:)=R(1,:)/GeometryCalib.fx_fy(1);
+R(1,:)=epsilon*R(1,:)/GeometryCalib.fx_fy(1);
 R(2,:)=R(2,:)/GeometryCalib.fx_fy(2);
 R=[R;[0 0]];
-GeometryCalib.R=[R [0;0;1]];
-GeometryCalib.omc=(180/pi)*[acos(GeometryCalib.R(1,1)) 0 0];
+GeometryCalib.R=[R [0;0;-1]];
+GeometryCalib.omc=(180/pi)*[acos(GeometryCalib.R(1,1)) 0 0]
 %------------------------------------------------------------------------
 % determine the tsai parameters for a view normal to the grid plane
Index: /trunk/src/mouse_down.m
===================================================================
--- /trunk/src/mouse_down.m	(revision 237)
+++ /trunk/src/mouse_down.m	(revision 238)
@@ -109,4 +109,8 @@
                 haxes=[];%mouse out of axes
             end
+            break
+        elseif isequal(htype,'uicontrol') && isequal(get(hchild(ichild),'Visible'),'on')
+            msgbox(get(hchild(ichild),'String'),get(hchild(ichild),'Tag'))
+            break
         end
     end
Index: /trunk/src/pivlab.m
===================================================================
--- /trunk/src/pivlab.m	(revision 237)
+++ /trunk/src/pivlab.m	(revision 238)
@@ -90,17 +90,17 @@
         result_conv=(result_conv/corrmax)*255; %normalize, peak=always 255
         %Find the correlation max, at 255
-        [y,x] = find(result_conv==255);
-        if ~isnan(y) & ~isnan(x)
+        [y,x] = find(result_conv==255,1);
+        if ~isnan(y) && ~isnan(x)
             try
                 if subpixfinder==1
-                    [vector] = SUBPIXGAUSS (result_conv,x,y);
+                    [vector,F(ivec)] = SUBPIXGAUSS (result_conv,x,y);
                 elseif subpixfinder==2
-                    [vector] = SUBPIX2DGAUSS (result_conv,x,y);
+                    [vector,F(ivec)] = SUBPIX2DGAUSS (result_conv,x,y);
                 end
                 sum_square=sum(sum(image1_crop.*image1_crop));
                 ctable(ivec)=corrmax/sum_square;% correlation value
-                if vector(1)>shiftx+isx2-ibx2+subpixfinder || vector(2)>shifty+isy2-iby2+subpixfinder
-                    F(ivec)=-2;%vector reaches the border of the search zone
-                end
+%                 if vector(1)>shiftx+isx2-ibx2+subpixfinder || vector(2)>shifty+isy2-iby2+subpixfinder
+%                     F(ivec)=-2;%vector reaches the border of the search zone
+%                 end
             catch ME
                 vector=[0 0]; %if something goes wrong with cross correlation.....
@@ -125,37 +125,43 @@
 
 
-function [vector] = SUBPIXGAUSS (result_conv,x,y)
+function [vector,F] = SUBPIXGAUSS (result_conv,x,y)
+vector=[0 0]; %default
+F=0;
+[npy,npx]=size(result_conv);
 
-if size(x,1)>1 %if there are more than 1 peaks just take the first
-    x=x(1:1);
-end
-if size(y,1)>1 %if there are more than 1 peaks just take the first
-    y=y(1:1);
-end
-if (x <= (size(result_conv,1)-1)) && (y <= (size(result_conv,1)-1)) && (x >= 1) && (y >= 1)
+% if (x <= (size(result_conv,1)-1)) && (y <= (size(result_conv,1)-1)) && (x >= 1) && (y >= 1)
     %the following 8 lines are copyright (c) 1998, Uri Shavit, Roi Gurka, Alex Liberzon, Technion  Israel Institute of Technology
     %http://urapiv.wordpress.com
-    f0 = log(result_conv(y,x));
-    f1 = log(result_conv(y-1,x));
-    f2 = log(result_conv(y+1,x));
-    peaky = y+ (f1-f2)/(2*f1-4*f0+2*f2);
-    f0 = log(result_conv(y,x));
-    f1 = log(result_conv(y,x-1));
-    f2 = log(result_conv(y,x+1));
-    peakx = x+ (f1-f2)/(2*f1-4*f0+2*f2);
-    [npy,npx]=size(result_conv);
+    peaky = y;
+    if y <= npy-1 && y >= 1
+        f0 = log(result_conv(y,x));
+        f1 = log(result_conv(y-1,x));
+        f2 = log(result_conv(y+1,x));
+        peaky = peaky+ (f1-f2)/(2*f1-4*f0+2*f2);
+    else
+        F=-2; % warning flag for vector truncated by the limited search box
+    end
+    peakx=x;
+    if x <= npx-1 && x >= 1
+        f0 = log(result_conv(y,x));
+        f1 = log(result_conv(y,x-1));
+        f2 = log(result_conv(y,x+1));
+        peakx = peakx+ (f1-f2)/(2*f1-4*f0+2*f2);
+    else
+        F=-2; % warning flag for vector truncated by the limited search box
+    end
     vector=[peakx-floor(npx/2)-1 peaky-floor(npy/2)-1];
-else
-    vector=[NaN NaN];
-end
+% else
+%     vector=[NaN NaN];
+% end
 
-function [vector] = SUBPIX2DGAUSS (result_conv,x,y)
-if size(x,1)>1 %if there are more than 1 peaks just take the first
-    x=x(1:1);
-end
-if size(y,1)>1 %if there are more than 1 peaks just take the first
-    y=y(1:1);
-end
-if (x <= (size(result_conv,1)-1)) && (y <= (size(result_conv,1)-1)) && (x >= 1) && (y >= 1)
+function [vector,F] = SUBPIX2DGAUSS (result_conv,x,y)
+vector=[0 0]; %default
+F=-2;
+peaky=y;
+peakx=x;
+[npy,npx]=size(result_conv);
+if (x <= npx-1) && (y <= npy-1) && (x >= 1) && (y >= 1)
+    F=0;
     for i=-1:1
         for j=-1:1
@@ -181,13 +187,10 @@
     deltax=(c11*c01-2*c10*c02)/(4*c20*c02-c11^2);
     deltay=(c11*c10-2*c01*c20)/(4*c20*c02-c11^2);
-    peakx=x+deltax;
-    peaky=y+deltay;
-    
-    [npy,npx]=size(result_conv);
-    vector=[peakx-floor(npx/2)-1 peaky-floor(npy/2)-1];
-%     SubpixelX=peakx-(ibx/2)-SubPixOffset;
-%     SubpixelY=peaky-(iby/2)-SubPixOffset;
-%     vector=[SubpixelX, SubpixelY];
-else
-    vector=[NaN NaN];
+    if abs(deltax)<1
+        peakx=x+deltax;
+    end
+    if abs(deltay)<1
+        peaky=y+deltay;
+    end
 end
+vector=[peakx-floor(npx/2)-1 peaky-floor(npy/2)-1];
Index: /trunk/src/plot_field.m
===================================================================
--- /trunk/src/plot_field.m	(revision 237)
+++ /trunk/src/plot_field.m	(revision 238)
@@ -900,8 +900,6 @@
             if MinA<MaxA
                 set(haxes,'CLim',[MinA MaxA])
-                %caxis([MinA MaxA])
             else
-                set(haxes,'CLim',[MinA MaxA])
-                %caxis([MaxA-1 MaxA])
+                set(haxes,'CLim',[MinA MaxA+1])
             end
             set(hima,'XData',AX);
@@ -909,7 +907,4 @@
         end
     end
-%     if ~isstruct(AxeData)
-%         AxeData=[];
-%     end
     test_ima=1;
     
Index: /trunk/src/series.m
===================================================================
--- /trunk/src/series.m	(revision 237)
+++ /trunk/src/series.m	(revision 238)
@@ -122,14 +122,8 @@
     FieldCell{1}=param.list_fields{param.index_fields};
 end
-if isfield(param,'civ1')&& islogical(param.civ1) && isfield(param,'civ2')&& islogical(param.civ2)&...
-        isfield(param,'interp1')&& islogical(param.interp1)&&isfield(param,'interp2')&& islogical(param.interp2)&...
-        isfield(param,'filter1')&& islogical(param.filter1)&&isfield(param,'filter2')&& islogical(param.filter2)
-    set(handles.civ1,'Value',param.civ1);
-    set(handles.civ2,'Value',param.civ1);
-    set(handles.interp1,'Value',param.interp1);
-    set(handles.interp2,'Value',param.interp2);
-    set(handles.filter1,'Value',param.filter1);
-    set(handles.filter2,'Value',param.filter2);
-end
+% if isfield(param,'velTypeMenu')&&isfield(param,'velTypeIndex')
+%     set(handles.VelTypeMenu,'Value',param.VelTypeIndex)
+%     set(handles.VelTypeMenu,'String',param.VelTypeMenu)
+% end  
 set(hObject,'WindowButtonUpFcn',{@mouse_up_gui,handles}) 
 NomType_Callback(hObject, eventdata, handles)
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m	(revision 237)
+++ /trunk/src/uvmat.m	(revision 238)
@@ -2427,5 +2427,7 @@
    UvData.Field=Field{1};
 end
-
+UvData.Field
+max(max(UvData.Field.A))
+min(min(UvData.Field.A))
 %% get bounds and mesh (needed for mouse action and to open set_object)
 test_x=0;
@@ -3927,5 +3929,5 @@
 set(handles.list_object_1,'Value',1)
 set(handles.list_object_1,'String',{''})
-set(handles.list_object_2,'Value',2)
+set(handles.list_object_2,'Value',1)
 set(handles.list_object_2,'String',{''})
 list_object_2_Callback(hObject, eventdata, handles)
@@ -4306,6 +4308,6 @@
 function list_object_2_Callback(hObject, eventdata, handles)
 %------------------------------------------------------------------------
-list_str=get(handles.list_object_2,'String');
-IndexObj=get(handles.list_object_2,'Value');
+list_str=get(handles.list_object_2,'String')
+IndexObj=get(handles.list_object_2,'Value')
 if ischar(list_str) || isempty(list_str{IndexObj})% || strcmp(list_str{IndexObj},'...')
     hview_field=findobj(allchild(0),'Tag','view_field');
@@ -4738,10 +4740,14 @@
     param.index_fields_1=param.index_fields_1-1;
 end
-param.civ1=get(handles.VelType,'Value');
-param.civ2=get(handles.civ2,'Value');
-param.interp1=get(handles.interp1,'Value');
-param.interp2=get(handles.interp2,'Value');
-param.filter1=get(handles.filter1,'Value');
-param.filter2=get(handles.filter2,'Value');
+% if isequal(get(handles.VelType,'Visible'),'on')
+%     param.VelTypeMenu=get(handles.VelType,'String');
+%     param.VelTypeIndex=get(handles.VelType,'Value');
+% end
+% param.civ1=get(handles.VelType,'Value');
+% param.civ2=get(handles.civ2,'Value');
+% param.interp1=get(handles.interp1,'Value');
+% param.interp2=get(handles.interp2,'Value');
+% param.filter1=get(handles.filter1,'Value');
+% param.filter2=get(handles.filter2,'Value');
 param.menu_coord_str=get(handles.transform_fct,'String');
 param.menu_coord_val=get(handles.transform_fct,'Value');
