Index: trunk/src/civ.m
===================================================================
--- trunk/src/civ.m	(revision 386)
+++ trunk/src/civ.m	(revision 387)
@@ -1095,5 +1095,5 @@
         Param.xml=s.RunParam;
     else
-        msgbox_uvmat('ERROR','no run civ binaries defined in PARAM.xml')
+        errormsg='no run civ binaries defined in PARAM.xml';
         return
     end
@@ -1110,5 +1110,5 @@
     [s,w]=system(test_command);
     if ~isequal(s,0)
-        msgbox_uvmat('ERROR',[batch_mode ' batch system not available'])
+        errormsg=[batch_mode ' batch system not available'];
         return
     end
@@ -1137,5 +1137,5 @@
                 Param.xml.(bin_name{1})=fullname;
             else
-                msgbox_uvmat('ERROR',['Binary ' Param.xml.(bin_name{1}) ' defined in PARAM.xml does not exist'])
+                errormsg=['Binary ' Param.xml.(bin_name{1}) ' defined in PARAM.xml does not exist'];
                 return
             end
@@ -1239,8 +1239,10 @@
 %                         Param.Civ1.Grid=[filecell.filebase '_' name_generator(Param.Civ1.Grid,i1_grid,1,'.grid','_i')];
                         if ~exist(Param.Civ1.GridName,'file')
-                            msgbox_uvmat('ERROR','grid file absent for civ1')
+                            errormsg='grid file absent for civ1';
+                            return
                         end
                     elseif ~exist(Param.Civ1.Grid,'file')
-                        msgbox_uvmat('ERROR','grid file absent for civ1')
+                        errormsg='grid file absent for civ1';
+                        return
                     end
                 end
@@ -1250,8 +1252,7 @@
             switch CivMode
                 case 'CivX'
-                    cmd=[cmd...
-                        cmd_civ1(filecell.nc.civ1{ifile,j},Param) '\n'];
+                    [cmd_civ,errormsg]=cmd_civ1(filecell.nc.civ1{ifile,j},Param);
+                    cmd=[cmd cmd_civ '\n'];
                     if ~isempty(errormsg)
-                        msgbox_uvmat('ERROR',errormsg)
                         return
                     end
@@ -1318,10 +1319,12 @@
 %                                 patch1.gridPatch=[filecell.filebase '_' name_generator(gridname,i1_grid,1,'.grid','_i')];
                                 if ~exist(patch1.gridPatch,'file')
-                                    msgbox_uvmat('ERROR','grid file absent for patch1')
+                                    errormsg='grid file absent for patch1';
+                                    return
                                 end
                             elseif exist(gridname,'file')
                                 patch1.gridPatch=gridname;
                             else
-                                msgbox_uvmat('ERROR','grid file absent for patch1')
+                                errormsg='grid file absent for patch1';
+                                return
                             end
                         end
@@ -1456,10 +1459,12 @@
 %                                 patch2.gridPatch=[filecell.filebase '_' name_generator(gridname,i1_grid,1,'.grid','_i')];
                                 if ~exist(patch2.gridPatch,'file')
-                                    msgbox_uvmat('ERROR','grid file absent for patch2')
+                                    errormsg='grid file absent for patch2';
+                                    return
                                 end
                             elseif exist(gridname,'file')
                                 patch2.gridPatch=gridname;
                             else
-                                msgbox_uvmat('ERROR','grid file absent for patch2')
+                                errormsg='grid file absent for patch2';
+                                return
                             end
                         end
@@ -1495,5 +1500,5 @@
                 [fid,message]=fopen(filename_bat,'w');
                 if isequal(fid,-1)
-                    msgbox_uvmat('ERROR', ['creation of .bat file: ' message])
+                    errormsg=['creation of .bat file: ' message];
                     return
                 end
@@ -1516,5 +1521,5 @@
                         [fid,message]=fopen(filename_bat,'w');
                         if isequal(fid,-1)
-                            msgbox_uvmat('ERROR', ['creation of .bat file: ' message])
+                            errormsg= ['creation of .bat file: ' message];
                             return
                         end
@@ -1537,6 +1542,6 @@
                         if isempty(errormsg)
                             display([filecell.nc.civ1{ifile,j} ' written'])
-                        else
-                            msgbox_uvmat('ERROR',errormsg)
+%                         else
+%                             msgbox_uvmat('ERROR',errormsg)
                         end
                     end
@@ -3031,5 +3036,5 @@
 else %case civ2 alone
     if ~get(handles.CheckCiv2,'Value') && ~get(handles.CheckCiv1,'Value') && ~get(handles.CheckFix1,'Value') && ~get(handles.CheckPatch1,'Value')
-        if ~exist(fullfile(filepath,subdir_civ2,ext_dir),'dir')
+        if ~exist(fullfile(RootPath,subdir_civ2,ext_dir),'dir')
             errordlg(['no civ2 file available: subdirectory ' subdir_civ2 ' does not exist'])
             set(handles.ListPairCiv2,'Value',1);
@@ -3637,6 +3642,7 @@
     end 
 end
-%------------------------------------------------------------------------
-% --- Executes on button press in CheckMask.
+
+%------------------------------------------------------------------------
+% --- Executes on button press in CheckMask: common to all panels (civ1, Civ2..)
 function CheckMask_Callback(hObject, eventdata, handles)
 %------------------------------------------------------------------------
@@ -3645,7 +3651,5 @@
 parent_tag=get(hparent,'Tag');
 hchildren=get(hparent,'children');
-handle_txtbox=findobj(hchildren,'tag','txt_Mask');
-% handle_dx=findobj(hchildren,'tag','num_Dx');
-% handle_dy=findobj(hchildren,'tag','num_Dy');
+handle_txtbox=findobj(hchildren,'tag','Mask');% look for the mask name box in the same panel
 testmask=0;
 if value
@@ -3673,7 +3677,6 @@
 end
 if testmask
-%     stage=4;%default
     if strcmp(parent_tag,'Civ1')
-            set(handles.Mask,'Visible','on')
+        set(handles.Mask,'Visible','on')
         set(handles.Mask,'String',filemask)
     set(handles.CheckMask,'Value',1)
@@ -3907,4 +3910,7 @@
     Data.VarDimName= {'ny','nx',{'ny','nx'}};
     Data.A=imread(filecell.ima1.civ1{1});
+    if ndims(Data.A)==3 %case of color image
+        Data.VarDimName= {'ny','nx',{'ny','nx','rgb'}};
+    end
     Data.ny=[size(Data.A,1) 1];
     Data.nx=[1 size(Data.A,2)];
@@ -3915,5 +3921,5 @@
     Param.Civ1=par_civ1;
     Grid=civ_matlab(Param);% get the grid of x, y positions set for PIV 
-    hview_field=view_field(Data);
+    hview_field=view_field(Data); %view the image in the GUI view_field
     set(0,'CurrentFigure',hview_field)
     hhview_field=guihandles(hview_field);
@@ -3960,10 +3966,9 @@
 
 %------------------------------------------------------------------------
-function cmd=cmd_civ1(filename,Param)
+function [cmd,errormsg]=cmd_civ1(filename,Param)
 %------------------------------------------------------------------------
 %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)
@@ -3972,7 +3977,7 @@
 Param.Civ1.ImageA=regexprep(Param.Civ1.ImageA,'.png','');
 Param.Civ1.ImageB=regexprep(Param.Civ1.ImageB,'.png','');
-fid=fopen([filename '.civ1.cmx'],'w');
+[fid,errormsg]=fopen([filename '.civ1.cmx'],'w');
 if isequal(fid,-1)
-    display(['cmd file ' filename ' cannot be created'])
+    errormsg=['cmd file ' filename ' cannot be created: ' errormsg];
     return
 end
@@ -4054,7 +4059,4 @@
 filename=regexprep(filename,'.nc','');
 MaskName_string='';%default
-% if Param.(fixname).CheckMask
-%     MaskName_string=[' -maskName "' Param.(fixname).Mask '"'];
-% end
 MaxVel_string='';%default
 if ~isempty(Param.(fixname).MaxVel)
@@ -4095,8 +4097,9 @@
 %------------------------------------------------------------------------
 % --- CheckCiv2  CheckCiv2  CheckCiv2 CheckCiv2
-function cmd=cmd_civ2(filename,Param)
+function [cmd,errormsg]=cmd_civ2(filename,Param)
 %------------------------------------------------------------------------
 %pixels per cm and matrix of the image times, read from the .civ file by uvmat
 % global civ2Bin sge%name of the executable for checkciv1 calculation
+ cmd='';
 filename=regexprep(filename,'.nc','');
 if isequal(Param.Civ2.Dt,'0')
@@ -4107,6 +4110,4 @@
 [fid,errormsg]=fopen([filename '.civ2.cmx'],'w');
 if isequal(fid,-1)
-    msgbox_uvmat('ERROR',errormsg)
-    cmd='';
     return
 end
