Index: /trunk/src/civ.m
===================================================================
--- /trunk/src/civ.m	(revision 247)
+++ /trunk/src/civ.m	(revision 248)
@@ -2152,4 +2152,7 @@
                 Param.Patch1.SubDomain=subdomain_patch1;
             end
+            if box_test(4)==1
+                Param.Civ2=par_civ2;
+            end
             [Data,erromsg]=civ_uvmat(Param,filecell.nc.civ1{ifile,j});
             if isempty(errormsg)
@@ -2705,6 +2708,10 @@
                 if ~testdiff % civ2 or patch2 are written in the same file as civ1
                     if box_test(4)==0 ; %check the existence of civ2 if it is not calculated
-                        Data=nc2struct(filename,'ListGlobalAttribute','civ2');
-                        if isempty(Data.civ2)||isequal(Data.civ2,0)
+                        Data=nc2struct(filename,'ListGlobalAttribute','CivStage','civ2');
+                        if ~isempty(Data.CivStage) && Data.CivStage<4 %test for civ files
+                            msgbox_uvmat('ERROR',['no civ2 data in ' filename])
+                            filecell=[];
+                            return
+                        elseif isempty(Data.civ2)||isequal(Data.civ2,0)
                             msgbox_uvmat('ERROR',['no civ2 data in ' filename])
                             filecell=[];
@@ -2712,6 +2719,12 @@
                         end
                     elseif box_test(3)==0; %check the existence of patch if it is not calculated
-                        Data=nc2struct(filename,'ListGlobalAttribute','patch');
-                        if isempty(Data.patch)||isequal(Data.patch,0)
+                        Data=nc2struct(filename,'ListGlobalAttribute','CivStage','patch')
+                        if ~isempty(Data.CivStage)
+                            if Data.CivStage<3 %test for civ files
+                                msgbox_uvmat('ERROR',['no patch data in ' filename])
+                                filecell=[];
+                                return
+                            end
+                        elseif isempty(Data.patch)||isequal(Data.patch,0)
                             msgbox_uvmat('ERROR',['no patch data in ' filename])
                             filecell=[];
@@ -2801,6 +2814,10 @@
                     return
                 else
-                    Data=nc2struct(filename,'ListGlobalAttribute','civ2');
-                    if isempty(Data.civ2)||isequal(Data.civ2,0)
+                    Data=nc2struct(filename,'ListGlobalAttribute','CivStage','civ2');
+                    if ~isempty(Data.CivStage) && Data.CivStage<4 %test for civ files
+                            msgbox_uvmat('ERROR',['no civ2 data in ' filename])
+                            filecell=[];
+                            return
+                    elseif isempty(Data.civ2)||isequal(Data.civ2,0)
                         msgbox_uvmat('ERROR',['no civ2 data in ' filename])
                         filecell=[];
@@ -4677,5 +4694,5 @@
     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,file_ref_fix1,file_ref_fix2]=...
-        set_civ_filenames(handles,ref_i,ref_j,[1 0 0 0 0 0]);
+        set_civ_filenames(handles,ref_i,ref_j,[1 0 0 0 0 0])
     Data.ListVarName={'ny','nx','A'};
     Data.VarDimName={'ny','nx',{'ny','nx'}};
Index: /trunk/src/civ_uvmat.m
===================================================================
--- /trunk/src/civ_uvmat.m	(revision 247)
+++ /trunk/src/civ_uvmat.m	(revision 248)
@@ -8,9 +8,10 @@
 ListVarCiv1={'Civ1_X','Civ1_Y','Civ1_U','Civ1_V','Civ1_C','Civ1_F'};
 ListVarFix1={'Civ1_X','Civ1_Y','Civ1_U','Civ1_V','Civ1_C','Civ1_F','Civ1_FF'};
+mask='';
+maskname='';%default
 
 %% Civ1
 if isfield (Param,'Civ1')
     par_civ1=Param.Civ1;
-    str2num(par_civ1.rho)
     image1=imread(par_civ1.filename_ima_a);
     image2=imread(par_civ1.filename_ima_b);
@@ -30,7 +31,10 @@
     PointCoord(:,1)=reshape(GridX,[],1);
     PointCoord(:,2)=reshape(GridY,[],1);
-    
+    if ~isempty(par_civ1.maskname)
+        maskname=par_civ1.maskname;
+        mask=imread(maskname);
+    end
     % 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,str2num(par_civ1.rho), []);
+    [xtable ytable utable vtable ctable F] = pivlab (image1,image2,ibx2,iby2,isx2,isy2,shiftx,-shifty,PointCoord,str2num(par_civ1.rho), mask);
     list_param=(fieldnames(par_civ1))';
     list_remove={'pxcmx','pxcmy','npx','npy','gridflag','maskflag','term_a','term_b','T0'};
@@ -148,4 +152,68 @@
       Data.CivStage=3;                             
 end   
+
+%% Civ2
+if isfield (Param,'Civ2')
+    par_civ2=Param.Civ2
+    image1=imread(par_civ2.filename_ima_a);
+    image2=imread(par_civ2.filename_ima_b);
+    stepx=str2num(par_civ2.dx);
+    stepy=str2num(par_civ2.dy);
+    ibx2=ceil(str2num(par_civ2.ibx)/2);
+    iby2=ceil(str2num(par_civ2.iby)/2);
+    isx2=4;
+    isy2=4;
+%     shiftx=str2num(par_civ1.shiftx);
+%     shifty=str2num(par_civ1.shifty);
+% TO GET shift from par_civ2.filename_nc1
+    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);
+    if ~isempty(par_civ2.maskname)&& ~strcmp(maskname,par_civ2.maskname)% mask exist, not already read in civ1
+        mask=imread(par_civ2.maskname);
+    end
+    % 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,str2num(par_civ1.rho),mask);
+    list_param=(fieldnames(par_civ1))';
+    list_remove={'pxcmx','pxcmy','npx','npy','gridflag','maskflag','term_a','term_b','T0'};
+    index=zeros(size(list_param));
+    for ilist=1:length(list_remove)
+        index=strcmp(list_remove{ilist},list_param);
+        if ~isempty(find(index,1))
+            list_param(index)=[];
+        end
+    end
+    for ilist=1:length(list_param)
+        Civ1_param{ilist}=['Civ1_' list_param{ilist}];
+        eval(['Data.Civ1_' list_param{ilist} '=Param.Civ1.' list_param{ilist} ';'])
+    end
+    if isfield(Data,'Civ1_gridname') && strcmp(Data.Civ1_gridname(1:6),'noFile')
+        Data.Civ1_gridname='';
+    end
+    if isfield(Data,'Civ1_maskname') && strcmp(Data.Civ1_maskname(1:6),'noFile')
+        Data.Civ1_maskname='';
+    end
+    Data.ListGlobalAttribute=[Data.ListGlobalAttribute Civ1_param {'Civ1_Time','Civ1_Dt'}];
+    Data.Civ1_Time=str2double(par_civ1.T0);
+    Data.Civ1_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={'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(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);
+    Data.CivStage=Data.CivStage+1;
+end
 %% write result
 % 'TESTcalc'
Index: /trunk/src/editxml.m
===================================================================
--- /trunk/src/editxml.m	(revision 247)
+++ /trunk/src/editxml.m	(revision 248)
@@ -330,7 +330,7 @@
     head_name=get(t,1,'name');
     %Path to shemas:
-%     path_uvmat=which('editxml');% check the path detected for source file uvmat
-%     path_UVMAT=fileparts(path_uvmat); %path to UVMAT
-%     xmlparam=fullfile(path_UVMAT,'PARAM.xml');
+    path_uvmat=which('editxml');% check the path detected for source file uvmat
+    path_UVMAT=fileparts(path_uvmat); %path to UVMAT
+    %     xmlparam=fullfile(path_UVMAT,'PARAM.xml');
     xmlparam='PARAM.xml'; %will find PARAM.xml whose path is set in priority
     if exist(xmlparam,'file')
@@ -338,23 +338,23 @@
         sparam=convert(tparam);
         if isfield(sparam,'SchemaPath')
-            schemafile=[fullfile(sparam.SchemaPath,head_name) '.xsd'];
-        end 
-        if ~exist(schemafile,'file')
-            schemafile=fullfile(path_UVMAT,schemafile);%look for relative path definition
-        end
-        if exist(schemafile,'file')
-            xs=xmltree(schemafile);
-        else
-            msgbox_uvmat('ERROR',['The xml schema for ' CurrentFile ' is unknown, check the schema path set in the file PARAM.xml'])
-            [FileName, PathName]=uigetfile( ...
-           {'*.xsd', '(*.xsd)';
-            '*.xsd',  '.xsd files '; ...
-            '*.*',  'All Files (*.*)'}, ...
-            'Pick a .xsd schema' ,schemafile); %file browser
-            if ischar(PathName) && ischar(FileName) && exist(fullfile(PathName,FileName),'file')
-                DataIn.Schema=fullfile(PathName,FileName);
-                xs=xmltree(DataIn.Schema);%open the associated schema file
+            schemafile=[fullfile(sparam.SchemaPath,head_name) '.xsd'];           
+            if ~exist(schemafile,'file')
+                schemafile=fullfile(path_UVMAT,schemafile);%look for relative path definition
+            end
+            if exist(schemafile,'file')
+                xs=xmltree(schemafile);
             else
-                xs=[];
+                msgbox_uvmat('ERROR',['The needed xml schema  ' sparam.SchemaPath ' is not found, check the file PARAM.xml'])
+                [FileName, PathName]=uigetfile( ...
+                    {'*.xsd', '(*.xsd)';
+                    '*.xsd',  '.xsd files '; ...
+                    '*.*',  'All Files (*.*)'}, ...
+                    'Pick a .xsd schema' ,schemafile); %file browser
+                if ischar(PathName) && ischar(FileName) && exist(fullfile(PathName,FileName),'file')
+                    DataIn.Schema=fullfile(PathName,FileName);
+                    xs=xmltree(DataIn.Schema);%open the associated schema file
+                else
+                    xs=[];
+                end
             end
         end
Index: /trunk/src/mouse_motion.m
===================================================================
--- /trunk/src/mouse_motion.m	(revision 247)
+++ /trunk/src/mouse_motion.m	(revision 248)
@@ -224,5 +224,4 @@
                        xround=Field.X(ind_pt);
                        yround=Field.Y(ind_pt);
-%                         if isfield(Field,'A')
 %                             dx=str2double(par.dx);
 %                             dy=str2double(par.dy);
@@ -253,5 +252,5 @@
                             set(hhhh,'Position',[xround-isx2+shiftx yround-isy2+shifty 2*isx2 2*isy2])
                         end
-                        [xtable ytable utable vtable ctable typevector result_conv] = pivlab (Field.A,Field.B,ibx2,iby2,isx2,isy2,shiftx,shifty,[xround yround], 1, []);
+                        [xtable ytable utable vtable ctable typevector result_conv] = pivlab (Field.A,Field.B,ibx2,iby2,isx2,isy2,shiftx,shifty,[xround size(Field.A,1)-yround+1], 1, []);
 %                         Asub=Field.A(yround-iby2:yround+iby2,xround-ibx2:xround+ibx2);%first sub-image
 %                         Asub=reshape(Asub,[],1);%first sub-image reshaped as matlab vector
Index: /trunk/src/pivlab.m
===================================================================
--- /trunk/src/pivlab.m	(revision 247)
+++ /trunk/src/pivlab.m	(revision 248)
@@ -42,4 +42,6 @@
 %% mask
 testmask=0;
+image1=double(image1);
+image2=double(image2);
 if exist('mask','var') && ~isempty(mask)
    testmask=1;
@@ -54,11 +56,9 @@
     %  100>=mask> 20: velocity not calculated, impermeable (no flux through mask boundaries)
     %  20>=mask: velocity=0
-    test_noflux=(mask<=100) ;
-    test_undefined=(mask<=200 & mask>100 );
-    image1(test_undefined)=min(min(image1))*ones(size(image1));% put image to zero in the undefined  area
-    image2(test_undefined)=min(min(image1))*ones(size(image1));% put image to zero in the undefined  area
+    test_noflux=(mask<100) ;
+    test_undefined=(mask<200 & mask>=100 );
+    image1(test_undefined)=min(min(image1));% put image to zero in the undefined  area
+    image2(test_undefined)=min(min(image2));% put image to zero in the undefined  area
 end
-image1=double(image1);
-image2=double(image2);
 
 %% calculate correlations: MAINLOOP
Index: /trunk/src/proj_field.m
===================================================================
--- /trunk/src/proj_field.m	(revision 247)
+++ /trunk/src/proj_field.m	(revision 248)
@@ -1772,5 +1772,5 @@
             testbound=1;
         end
-        if testYMin
+        if testYMax
             testin=testin & (coord_Y <= YMax);
             testbound=1;
Index: /trunk/src/series.m
===================================================================
--- /trunk/src/series.m	(revision 247)
+++ /trunk/src/series.m	(revision 248)
@@ -2167,7 +2167,10 @@
 
 %check the current path to the selected function
+if ~isempty(list_transform{ind_coord})
 func=functions(list_transform{ind_coord});
 set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
-
+else
+   set(handles.path_transform,'String',''); %show the path to the senlected function 
+end
 %------------------------------------------------------------------------
 % --- generates a series of file names with reference numbers between range1 and
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m	(revision 247)
+++ /trunk/src/uvmat.m	(revision 248)
@@ -1494,8 +1494,9 @@
             maskname=maskfiles(ilist).name;% take the first mask file in the list
             [rr,ff,x1,x2,xa,xb,xext,Mask_NomType{ilist}]=name2display(maskname);
-            if ~strcmp(Mask_NomType{ilist},Mask_NomType{1})
-                msgbox_uvmat('ERROR',['inconsistent mask types ' Mask_NomType{1} Mask_NomType{ilist } ' coexist in the current image directory'])
-                return
-            end
+% 
+%             if ~strcmp(Mask_NomType{ilist},Mask_NomType{1})
+%                 msgbox_uvmat('ERROR',['inconsistent mask types ' Mask_NomType{1} ' and ' Mask_NomType{ilist } ' coexist in the current image directory'])
+%                 return
+%             end
             [Path2,Name,ext]=fileparts(maskname);
             Namedouble=double(Name);
@@ -1521,5 +1522,5 @@
             Mask.NbSlice=nbslice;
             num_i1=mod(num_i1-1,nbslice)+1;
-            Mask.NomType=Mask_NomType{1};
+            Mask.NomType=regexprep(Mask_NomType{1},'0','');%remove '0' in nom type for masks
             [maskname,mdetect]=name_generator(Mask.Base,num_i1,num_j1,'.png',Mask.NomType);%
             mdetect=exist(maskname,'file');
@@ -2147,5 +2148,4 @@
     ParamIn.GUIName='get_field';
     [Field{1},ParamOut,errormsg] = read_field(ObjectName,FileType,ParamIn,num_i1);
-    Field{1}
     if ~isempty(errormsg)
         errormsg=['error in reading ' filename ': ' errormsg];
@@ -2594,5 +2594,5 @@
 
 %% Plot the projections on the selected  projection objects
-'PLOT'
+
 % main projection object (uvmat display)
 list_object=get(handles.list_object_1,'String');
