Index: /trunk/src/check_field_structure.m
===================================================================
--- /trunk/src/check_field_structure.m	(revision 158)
+++ /trunk/src/check_field_structure.m	(revision 159)
@@ -112,6 +112,4 @@
         else % DimName is detected in the current list of dimension names
             if ~isequal(Data.DimValue(iprev),sizvar(idim))
-                        RangeTest(iprev)
-            Data.DimValue(iprev)
                 if isequal(Data.DimValue(iprev),2)&& RangeTest(iprev)  % the dimension has been already detected as a range [min max]
                     Data.DimValue(iprev)=sizvar(idim); %update with actual value
Index: /trunk/src/civ.m
===================================================================
--- /trunk/src/civ.m	(revision 158)
+++ /trunk/src/civ.m	(revision 159)
@@ -1597,5 +1597,5 @@
 index_first=min(index);
 index_last=max(index);
-box_used=box_test([index_first : index_last]);
+box_used=box_test(index_first : index_last);
 [box_missing,ind_missing]=min(box_used);
 if isequal(box_missing,0)
@@ -1870,4 +1870,11 @@
         filename_cmx=filecell.nc.civ1{ifile,j};%output netcdf file
         filename_cmx(end-1:end+1)='cmx';%name of cmx file
+        if batch
+            [Rootbat,Filebat,extbat]=fileparts(filename_cmx);
+            filename_bat=fullfile(Rootbat,['job_' Filebat extbat]);
+         else
+            filename_bat=filename_cmx;
+        end
+        filename_bat(end-2:end)='bat';
         
         %CIV1
@@ -2211,12 +2218,9 @@
         end
         % create the .bat file:
-        if batch
-            [Rootbat,Filebat,extbat]=fileparts(filename_cmx);
-            filename_bat=fullfile(Rootbat,['job_' Filebat extbat]);
-         else
-            filename_bat=filename_cmx;
-        end
-        filename_bat(end-2:end)='bat';
-        fid=fopen(filename_bat,'w');
+        [fid,message]=fopen(filename_bat,'w');
+        if isequal(fid,-1)
+            msgbox_uvmat('ERROR', ['creation of .bat file: ' message])
+            return
+        end
         fprintf(fid,cmd);
         fclose(fid);
@@ -2246,5 +2250,5 @@
 
 if ~batch
-    [Rootbat,Filebat,extbat]=fileparts(filename_cmx);
+    [Rootbat,Filebat,extbat]=fileparts(filename_bat);
     filename_superbat=fullfile(Rootbat,['job_list.bat']);
     fid=fopen(filename_superbat,'w');
Index: /trunk/src/geometry_calib.m
===================================================================
--- /trunk/src/geometry_calib.m	(revision 158)
+++ /trunk/src/geometry_calib.m	(revision 159)
@@ -1099,4 +1099,5 @@
 function MenuDetectGrid_Callback(hObject, eventdata, handles)
 %------------------------------------------------------------------------
+%% initiate the grid
 CalibData=get(handles.geometry_calib,'UserData');%get information stored on the GUI geometry_calib
 grid_input=[];%default
@@ -1105,13 +1106,12 @@
 end
 [T,CalibData.grid,white_test]=create_grid(grid_input,'detect_grid');%display the GUI create_grid, read the set of phys coordinates T
-
 set(handles.geometry_calib,'UserData',CalibData)%store the phys grid parameters for later use
 
-%read the four last point coordinates in pixels
+%% read the four last point coordinates in pixels
 Coord_cell=get(handles.ListCoord,'String');%read list of coordinates on geometry_calib
 data=read_geometry_calib(Coord_cell);
 nbpoints=size(data.Coord,1); %nbre of calibration points
 if nbpoints~=4
-    msgbox_uvmat('ERROR','four points must be selected by the mouse, beginning by the new x axis, to delimitate the phs grid area')
+    msgbox_uvmat('ERROR','four points must have be selected by the mouse, beginning by the new x axis, to delimitate the phys grid area')
     return
 end
@@ -1130,14 +1130,13 @@
 end
 
-%read the current image, displayed in the GUI uvmat
+%% read the current image, displayed in the GUI uvmat
 huvmat=findobj(allchild(0),'Name','uvmat');
 UvData=get(huvmat,'UserData');
 A=UvData.Field.A;
 npxy=size(A);
-%linear transform on the current image
-X=[CalibData.grid.x_0 CalibData.grid.x_1 CalibData.grid.x_0 CalibData.grid.x_1]';%corner absissa in the phys coordinates
-Y=[CalibData.grid.y_0 CalibData.grid.y_0 CalibData.grid.y_1 CalibData.grid.y_1]';%corner ordinates in the phys coordinates
-
-%calculate transform matrices: 
+X=[CalibData.grid.x_0 CalibData.grid.x_1 CalibData.grid.x_0 CalibData.grid.x_1]';%corner absissa in the phys coordinates (cm)
+Y=[CalibData.grid.y_0 CalibData.grid.y_0 CalibData.grid.y_1 CalibData.grid.y_1]';%corner ordinates in the phys coordinates (cm)
+
+%calculate transform matrices for plane projection
 % reference: http://alumni.media.mit.edu/~cwren/interpolator/ by Christopher R. Wren
 B = [ X Y ones(size(X)) zeros(4,3)        -X.*corners_X -Y.*corners_X ...
@@ -1146,28 +1145,13 @@
 D = [ corners_X , corners_Y ];
 D = reshape (D', 8 , 1 );
-%l = inv(B' * B) * B' * D;
 l = (B' * B)\B' * D;
 Amat = reshape([l(1:6)' 0 0 1 ],3,3)';
 C = [l(7:8)' 1];
 
-%GeometryCalib.CalibrationType='tsai';
-%GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
-% GeometryCalib.f=1;
-% GeometryCalib.dpx=1;
-% GeometryCalib.dpy=1;
-% GeometryCalib.sx=1;
-% GeometryCalib.Cx=0;
-% GeometryCalib.Cy=0;
-% GeometryCalib.kappa1=0;
-% GeometryCalib.Tx=Amat(1,3);
-% GeometryCalib.Ty=Amat(2,3);
-% GeometryCalib.Tz=1;
-% GeometryCalib.R=[Amat(1,1),Amat(1,2),0;Amat(2,1),Amat(2,2),0;C(1),C(2),0];
-% 
-% [Amod,Rangx,Rangy]=phys_Ima(A-min(min(A)),GeometryCalib,0);
-
+% transform grid image into 'phys' coordinates 
 GeometryCalib.fx_fy=[1 1];
 GeometryCalib.Tx_Ty_Tz=[Amat(1,3) Amat(2,3) 1];
 GeometryCalib.R=[Amat(1,1),Amat(1,2),0;Amat(2,1),Amat(2,2),0;C(1),C(2),0];
+GeometryCalib.CoordUnit='cm';
 path_uvmat=which('uvmat');% check the path detected for source file uvmat
 path_UVMAT=fileparts(path_uvmat); %path to UVMAT
@@ -1188,21 +1172,8 @@
 Rangx=DataOut.AX;
 Rangy=DataOut.AY;
-% GeometryCalib.dpx=1;
-% GeometryCalib.dpy=1;
-% GeometryCalib.sx=1;
-% GeometryCalib.Cx=0;
-% GeometryCalib.Cy=0;
-% GeometryCalib.kappa1=0;
-% GeometryCalib.Tx=Amat(1,3);
-% GeometryCalib.Ty=Amat(2,3);
-% GeometryCalib.Tz=1;
-% GeometryCalib.R=[Amat(1,1),Amat(1,2),0;Amat(2,1),Amat(2,2),0;C(1),C(2),0];
-% 
-% [Amod,Rangx,Rangy]=phys_Ima(A-min(min(A)),GeometryCalib,0);
-
 if white_test
-    Amod=double(Amod);%will look for image maxima
+    Amod=double(Amod);%case of white grid markers: will look for image maxima
 else
-    Amod=-double(Amod);%will look for image minima
+    Amod=-double(Amod);%case of black grid markers: will look for image minima
 end
 % figure(12) %display corrected image
@@ -1210,4 +1181,5 @@
 % image(Rangx,Rangy,uint8(255*Amod/Amax))
 
+%% detection of local image extrema in each direction
 Dx=(Rangx(2)-Rangx(1))/(npxy(2)-1); %x mesh in real space
 Dy=(Rangy(2)-Rangy(1))/(npxy(1)-1); %y mesh in real space
@@ -1230,5 +1202,4 @@
     x_shift=0;
     y_shift=0;
-    %if ind_x_max+2<=2*ind_range_x+1 && ind_x_max-2>=1
     if ind_x_max+2<=numel(x_profile) && ind_x_max-2>=1
         Atop=x_profile(ind_x_max-2:ind_x_max+2);
Index: /trunk/src/proj_field.m
===================================================================
--- /trunk/src/proj_field.m	(revision 158)
+++ /trunk/src/proj_field.m	(revision 159)
@@ -1337,41 +1337,45 @@
         % case with no rotation and interpolation
         if isequal(ProjMode,'projection') && isequal(Phi,0) && isequal(Theta,0) && isequal(Psi,0)
-            if test_direct(1)
-                min_ind1=ceil((YMin-Coord{1}(1))/DYinit)+1;
-                max_ind1=floor((YMax-Coord{1}(1))/DYinit)+1;
-                Ybound(1)=Coord{1}(1)+DYinit*(min_ind1-1);
-                Ybound(2)=Coord{1}(1)+DYinit*(max_ind1-1);
+            if ~testXMin && ~testXMax && ~testYMin && ~testYMax
+                ProjData=FieldData; 
             else
-                min_ind1=ceil((Coord{1}(1)-YMax)/DYinit)+1;
-                max_ind1=floor((Coord{1}(1)-YMin)/DYinit)+1;
-                Ybound(2)=Coord{1}(1)-DYinit*(max_ind1-1);
-                Ybound(1)=Coord{1}(1)-DYinit*(min_ind1-1);
-            end              
-            if test_direct(2)==1
-                min_ind2=ceil((XMin-Coord{2}(1))/DXinit)+1;
-                max_ind2=floor((XMax-Coord{2}(1))/DXinit)+1;
-                Xbound(1)=Coord{2}(1)+DXinit*(min_ind2-1);
-                Xbound(2)=Coord{2}(1)+DXinit*(max_ind2-1);
-            else
-                min_ind2=ceil((Coord{2}(1)-XMax)/DXinit)+1;
-                max_ind2=floor((Coord{2}(1)-XMin)/DXinit)+1;
-                Xbound(2)=Coord{2}(1)+DXinit*(max_ind2-1);
-                Xbound(1)=Coord{2}(1)+DXinit*(min_ind2-1);
-            end 
-            min_ind1=max(min_ind1,1);% deals with margin (bound lower than the first index)
-            min_ind2=max(min_ind2,1);
-            max_ind1=min(max_ind1,DimValue(1));
-            max_ind2=min(max_ind2,DimValue(2));
-            for ivar=VarIndex
-                VarName=FieldData.ListVarName{ivar}; 
-                ProjData.ListVarName=[ProjData.ListVarName VarName];
-                ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
-                if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute)>=ivar
-                    ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar};
-                end
-                eval(['ProjData.' VarName '=FieldData.' VarName '(min_ind1:max_ind1,min_ind2:max_ind2) ;']);
-            end  
-            eval(['ProjData.' AYName '=FieldData.' AYName ';']) %record the new (projected ) y coordinates
-            eval(['ProjData.' AXName '=FieldData.' AXName ';']) %record the new (projected ) x coordinates
+                if test_direct(1)
+                    min_ind1=ceil((YMin-Coord{1}(1))/DYinit)+1;
+                    max_ind1=floor((YMax-Coord{1}(1))/DYinit)+1;
+                    Ybound(1)=Coord{1}(1)+DYinit*(min_ind1-1);
+                    Ybound(2)=Coord{1}(1)+DYinit*(max_ind1-1);
+                else
+                    min_ind1=ceil((Coord{1}(1)-YMax)/DYinit)+1;
+                    max_ind1=floor((Coord{1}(1)-YMin)/DYinit)+1;
+                    Ybound(2)=Coord{1}(1)-DYinit*(max_ind1-1);
+                    Ybound(1)=Coord{1}(1)-DYinit*(min_ind1-1);
+                end              
+                if test_direct(2)==1
+                    min_ind2=ceil((XMin-Coord{2}(1))/DXinit)+1;
+                    max_ind2=floor((XMax-Coord{2}(1))/DXinit)+1;
+                    Xbound(1)=Coord{2}(1)+DXinit*(min_ind2-1);
+                    Xbound(2)=Coord{2}(1)+DXinit*(max_ind2-1);
+                else
+                    min_ind2=ceil((Coord{2}(1)-XMax)/DXinit)+1;
+                    max_ind2=floor((Coord{2}(1)-XMin)/DXinit)+1;
+                    Xbound(2)=Coord{2}(1)+DXinit*(max_ind2-1);
+                    Xbound(1)=Coord{2}(1)+DXinit*(min_ind2-1);
+                end 
+                min_ind1=max(min_ind1,1);% deals with margin (bound lower than the first index)
+                min_ind2=max(min_ind2,1);
+                max_ind1=min(max_ind1,DimValue(1));
+                max_ind2=min(max_ind2,DimValue(2));
+                for ivar=VarIndex
+                    VarName=FieldData.ListVarName{ivar}; 
+                    ProjData.ListVarName=[ProjData.ListVarName VarName];
+                    ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
+                    if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute)>=ivar
+                        ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar};
+                    end
+                    eval(['ProjData.' VarName '=FieldData.' VarName '(min_ind1:max_ind1,min_ind2:max_ind2,:) ;']);
+                end  
+                eval(['ProjData.' AYName '=[Ybound(1) Ybound(2)];']) %record the new (projected ) y coordinates
+                eval(['ProjData.' AXName '=[Xbound(1) Xbound(2)];']) %record the new (projected ) x coordinates
+            end
         else       % case with rotation and/or interpolation
             if isempty(Coord_z) %2D case
Index: /trunk/src/read_civxdata.m
===================================================================
--- /trunk/src/read_civxdata.m	(revision 158)
+++ /trunk/src/read_civxdata.m	(revision 159)
@@ -1,4 +1,7 @@
 %'read_civxdata': reads civx data from netcdf files
 %------------------------------------------------------------------
+%
+% function [Field,VelTypeOut]=read_civxdata(filename,FieldNames,VelType)
+%
 % OUTPUT:
 % nb_coord,nb_dim,
Index: /trunk/src/set_object.m
===================================================================
--- /trunk/src/set_object.m	(revision 158)
+++ /trunk/src/set_object.m	(revision 159)
@@ -46,5 +46,5 @@
                    'gui_LayoutFcn',  [] , ...
                    'gui_Callback',   []);
-if nargin & isstr(varargin{1})
+if nargin & ischar(varargin{1})
     gui_State.gui_Callback = str2func(varargin{1});
 end
@@ -318,5 +318,5 @@
 end
 if isequal(style,'line')
-    if isequal(style_prev,'rectangle')|isequal(style_prev,'ellipse')
+    if strcmp(style_prev,'rectangle')||strcmp(style_prev,'ellipse')
         XMax=get(handles.XMax,'String');
         YMax=get(handles.YMax,'String');
@@ -328,5 +328,5 @@
     end
 elseif isequal(style,'polyline')
-elseif isequal(style,'rectangle')| isequal(style,'ellipse')
+elseif strcmp(style,'rectangle')|| strcmp(style,'ellipse')
      set(handles.XObject,'String',x_new)
      set(handles.YObject,'String',y_new)
@@ -387,5 +387,5 @@
     set(handles.YMax,'Visible','on')
 end
-if isequal(ObjectStyle,'rectangle')|isequal(ObjectStyle,'ellipse')
+if strcmp(ObjectStyle,'rectangle')||strcmp(ObjectStyle,'ellipse')
     set(handles.XMax,'Visible','on')
 else
@@ -731,5 +731,9 @@
 ListObject=get(hhuvmat.list_object_1,'String');%position in the objet list
 IndexObj_1=get(hhuvmat.list_object_1,'Value');
-IndexObj_2=get(hhuvmat.list_object_2,'Value');
+if isequal(get(hhuvmat.list_object_2,'Visible'),'on')
+    IndexObj_2=get(hhuvmat.list_object_2,'Value');
+else
+    IndexObj_2=[];
+end
 testnew=0;
 PlotHandles=get_plot_handles(hhuvmat);
@@ -741,6 +745,5 @@
     projview='uvmat';
      plotaxes=hhuvmat.axes3;%handle of axes3 in view_field
-elseif IndexObj_2<=numel(ListObject)&& strcmp(ListObject{IndexObj_2},ObjectName)% we are editing the object whose projection is viewed in view_field
-   
+elseif ~isempty(IndexObj_2) && IndexObj_2<=numel(ListObject)&& strcmp(ListObject{IndexObj_2},ObjectName)% we are editing the object whose projection is viewed in view_field  
     IndexObj=IndexObj_2;
 %     projview='view_field';
@@ -756,7 +759,7 @@
 end
 if strcmp(projview,'view_field')
-    hview_field=findobj(allchild(0),'tag','view_field')
+    hview_field=findobj(allchild(0),'tag','view_field');
     if isempty(hview_field)
-        hview_field=view_field
+        hview_field=view_field;
     end
     PlotHandles=guidata(hview_field);
@@ -792,20 +795,21 @@
 
 %% update the object plot and projection field
-if testnew
+if testnew 
     set(hhuvmat.list_object_2,'Value',IndexObj)
     ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;
     ObjectData.DisplayHandle_view_field=[];
-else % save the previous object graph handles
+elseif ~isfield(UvData.Object{IndexObj},'DisplayHandle_uvmat')% save the previous object graph handles
     ObjectData.DisplayHandle_uvmat=UvData.Object{IndexObj}.DisplayHandle_uvmat;
     ObjectData.DisplayHandle_view_field=UvData.Object{IndexObj}.DisplayHandle_view_field;
+else
+    ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;
+    ObjectData.DisplayHandle_view_field=[];
 end
 UvData.Object{IndexObj}=ObjectData;%update the current object properties
-IndexObj
-ObjectData
 UvData.Object=update_obj(UvData,IndexObj_1,IndexObj_2);
 
 %% plot the field projected on the object and store it the corresponding figue
 get(plotaxes,'tag')
-ProjData= proj_field(UvData.Field,ObjectData)%project the current interface field on ObjectData
+ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
 [PlotType,Object_out{IndexObj}.PlotParam,plotaxes]=plot_field(ProjData,plotaxes,PlotHandles);%update an existing field plot
 if strcmp(projview,'view_field')
@@ -880,5 +884,4 @@
     def={fullfile(dir_save,[Object.Style '.xml'])};
 end
-options.Resize='on';
 displ_txt='save object as an .xml file';%default display
 menu=get(handles.ProjMode,'String');
@@ -889,5 +892,4 @@
 end
 answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def);
-%answer=inputdlg('','save object in a new .xml file',1,def,'on');
 if ~isempty(answer)
     t=struct2xml(Object);
Index: /trunk/src/update_obj.m
===================================================================
--- /trunk/src/update_obj.m	(revision 158)
+++ /trunk/src/update_obj.m	(revision 159)
@@ -48,29 +48,15 @@
 
 %%  representation of the different objects in the plots uvmat and view_field
-%hfig=get(plotaxes,'parent');
-%tagfig=get(hfig,'tag');
-% if length(Object_set)<IndexObj
-    %Object_set{IndexObj}=ObjectData;
-% end
-% plot the updated object in uvmat
-%  hobject=[];
-% if isfield(Object_set{IndexObj},'DisplayHandle_uvmat') && ~isempty(Object_set{IndexObj}.DisplayHandle_uvmat) && ishandle(Object_set{IndexObj}.DisplayHandle_uvmat)
-%     hobject=Object_set{IndexObj}.DisplayHandle_uvmat;
-% % else
-% %     hobject=plotaxes;
-% end
-% Object_out{IndexObj}.DisplayHandle_uvmat=plot_object(Object_set{IndexObj},Object_set{1},hobject,'m');%update the object representation
 
-% if strcmp(tagfig,'uvmat')%plot uvmat
+%plot uvmat
     for iobj=1:length(Object_out) %change the view of all existing objects on the updated current object #IndexObj_1
          hobject=[];
         if isfield(Object_out{iobj},'DisplayHandle_uvmat') && ~isempty(Object_out{iobj}.DisplayHandle_uvmat) && ishandle(Object_out{iobj}.DisplayHandle_uvmat)
             hobject=Object_out{iobj}.DisplayHandle_uvmat;
-%         else 
-%             hobject=plotaxes;
         end
         Object_out{iobj}.DisplayHandle_uvmat=plot_object(Object_out{iobj},Object_out{IndexObj_1},hobject,'m');%update the object representation
     end
-% else%plot view_field
+% plot view_field
+if ~isempty(IndexObj_2)
     for iobj=1:length(Object_out) %change the view of all existing objects on the updated current object #IndexObj_2
         hobject=[];
@@ -82,4 +68,5 @@
         Object_out{iobj}.DisplayHandle_view_field=plot_object(Object_out{iobj},Object_out{IndexObj_2},hobject,'m');%update the object representation
     end
+end
 %  end
 
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m	(revision 158)
+++ /trunk/src/uvmat.m	(revision 159)
@@ -31,5 +31,5 @@
 %    'Strings' of all edit boxes and menus: get(handles.Tag,'String')
 %    'Values' of all menus and toggle buttons: get(handles.Tag,'Value')
-%     Matlab structure stored as 'UserData' of the figure uvmat.fig,(can be obtained by right mouse click on the interface).
+%     Matlab structure called UvData stored as 'UserData' of the figure uvmat.fig,(can be obtained by right mouse click on the interface).
 %          It contains the following fields:
 %     - Fixed specifiacation of plotting figures and axes (defined bu uvmat_OpeningFcn) 
@@ -47,6 +47,12 @@
 %           .FieldName_1:(char string) second field selected('image', 'velocity'...)
 %           .CName: (char string)name of the scalar used for vector colors
-%           .CoordType: (char string) coordinate transform: e.g. 'phys' or 'px'
-%           .MouseAction: store the current effect of mouse button (create or edit objects)
+%          .MovieObject: movie object representing an input movie
+%          .MovieObject_1: idem for a second input series (_1)
+%          .filename_1 : last second input file name (to deal with a constant second input without reading again the file)
+%          .VelType_1: last velocity type (civ1, civ2...) for the second input series
+%          .FieldName_1: last field name(velocity, vorticity...) for the second input series
+%          .NbDim: number of space dimensions of the input field
+%          .ZMin, .ZMax: range of the z coordinate
+%..... to complement
 %     - Information on  projection objects
 %           .Object: {[1x1 struct]}
@@ -79,7 +85,14 @@
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   DATA FLOW  (for run0_Callback) %%%%%%%%%%%%%%%%%%%%:
 %
+% fields are opened and visualised by the sub-function refresh_field.m
+% (called by uvmat_opening, RUN0, runp and runm)
+% The function first reads the name of the input file from the edit boxes  of the GUI
+% A second input file can be introduced for filed comparison
+% It then reads the input file(s) with the appropriate function, read for
+% images, read_civxdata.m for CIVx PIV data, nc2struct for other netcdf
+% files.
 %               Main input open   second input open(_1)        second image (pair animation) 
-% read_ncfield.m         |                 |                             
-% read image.m           |                 |                                                
+%            |                 |                             
+%            |                 |                                                
 %                     Field{1}         Field{2}               
 %                                                                         |
@@ -2058,14 +2071,5 @@
 end
 UvData=get(handles.uvmat,'UserData');
-%UvData =structure containing information stored outside the uicontrol of uvmat
-%      .NewSeries: =1 for a new series (new root fiel introduced), 0 else
-%      .MovieObject: movie object representing an input movie
-%      .MovieObject_1: idem for a second input series (_1)
-%      .filename_1 : last second input file name (to deal with a constant second input without reading again the file)
-%      .VelType_1: last velocity type (civ1, civ2...) for the second input series
-%      .FieldName_1: last field name(velocity, vorticity...) for the second input series
-%      .NbDim: number of space dimensions of the input field
-%      .ZMin, .ZMax: range of the z coordinate
-%..... to complement
+
 
 if ishandle(handles.UVMAT_title) %remove title panel on uvmat
@@ -2135,4 +2139,5 @@
     end
 end
+
 %% choose a second field if Subfield option is 'on'
 FieldName_1=[];
@@ -2493,123 +2498,135 @@
 [CellVarIndex,NbDim,VarType]=find_field_indices(UvData.Field);
 [NbDim,imax]=max(NbDim);
-if isempty(imax)
-%    DimVarIndex=0;    
-    coord_x=[];
-else
-%     VarIndex=CellVarIndex{imax};
-    coord_x=VarType{imax}.coord_x;
-end
-if isfield(UvData,'NbDim') && ~isempty(UvData.NbDim)
-    NbDim=UvData.NbDim;
-else  
-    UvData.NbDim=NbDim;
-end
-if ~isempty(CellVarIndex) && ~isempty(VarType{imax}.coord_x)  && ~isempty(VarType{imax}.coord_y)    %unstructured coordinate z
+% if isempty(imax)
+% %    DimVarIndex=0;    
+%     coord_x=[];
+% else
+% %     VarIndex=CellVarIndex{imax};
+%     coord_x=VarType{imax}.coord_x;
+% end
+% if isfield(UvData,'NbDim') && ~isempty(UvData.NbDim)
+%     NbDim=UvData.NbDim;
+% else  
+UvData.NbDim=NbDim;
+% end
+if ~isempty(VarType{imax}.coord_x)  && ~isempty(VarType{imax}.coord_y)    %unstructured coordinates
     XName=UvData.Field.ListVarName{VarType{imax}.coord_x};
     YName=UvData.Field.ListVarName{VarType{imax}.coord_y};
-    test_x=1;
-elseif isfield(UvData.Field,'X') && isfield(UvData.Field,'Y')
-    XName='X';
-    YName='Y';
-    test_x=1;
-end
-if test_x
-    eval(['UvData.XMax=max(UvData.Field.' XName ');'])
-    eval(['UvData.XMin=min(UvData.Field.' XName ');'])
-    eval(['UvData.YMax=max(UvData.Field.' YName ');'])
-    eval(['UvData.YMin=min(UvData.Field.' YName ');'])
-    eval(['nbvec=length(UvData.Field.' XName ');'])
-    if NbDim==3%
-        if ~isempty(CellVarIndex) && ~isempty(VarType{imax}.coord_z)%unstructured coordinate z
-            ZName=UvData.Field.ListVarName{VarType{imax}.coord_z};
-            eval(['UvData.ZMax=max(UvData.Field.' ZName ');'])
-            eval(['UvData.ZMin=min(UvData.Field.' ZName ');'])
-            test_z=1;   
-        elseif isfield(UvData,'Z')% usual civ data
-            UvData.ZMax=max(UvData.Z);
-            UvData.ZMin=min(UvData.Z);
-            test_z=1;
-        end
-    end
-    if isequal(UvData.ZMin,UvData.ZMax)%no z dependency
+    eval(['nbvec=length(UvData.Field.' XName ');'])%nbre of measurement points (e.g. vectors)
+    test_x=1;%test for unstructured coordinates
+elseif NbDim==2
+    YName=UvData.Field.ListVarName{VarType{imax}.coord(1)}; %structured coordinates
+    XName=UvData.Field.ListVarName{VarType{imax}.coord(2)};
+elseif NbDim==3
+    ZName=UvData.Field.ListVarName{VarType{imax}.coord(1)};%structured coordinates in 3D
+    YName=UvData.Field.ListVarName{VarType{imax}.coord(2)};
+    XName=UvData.Field.ListVarName{VarType{imax}.coord(3)};
+end
+
+eval(['XMax=max(UvData.Field.' XName ');'])
+eval(['XMin=min(UvData.Field.' XName ');'])
+eval(['YMax=max(UvData.Field.' YName ');'])
+eval(['YMin=min(UvData.Field.' YName ');'])
+eval(['nbvec=length(UvData.Field.' XName ');'])
+if NbDim==3%
+    if ~isempty(CellVarIndex) && ~isempty(VarType{imax}.coord_z)%unstructured coordinate z
+%         ZName=UvData.Field.ListVarName{VarType{imax}.coord_z};
+        eval(['ZMax=max(UvData.Field.' ZName ');'])
+        eval(['ZMin=min(UvData.Field.' ZName ');'])
+        test_z=1;   
+    elseif isfield(UvData,'Z')% usual civ data
+        ZMax=max(UvData.Z);
+        ZMin=min(UvData.Z);
+        test_z=1;
+    end
+    if isequal(ZMin,ZMax)%no z dependency
         NbDim=2;
         test_z=0;
-    end    
+    end
+end
+if test_x
     if test_z
-         Field.Mesh=((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)*(UvData.ZMax-UvData.ZMin))/nbvec;% volume per vector
-         Field.Mesh=(Field.Mesh)^(1/3);
+        UvData.Field.Mesh=((XMax-XMin)*(YMax-YMin)*(ZMax-ZMin))/nbvec;% volume per vector
+        UvData.Field.Mesh=(UvData.Field.Mesh)^(1/3);
     else
-        Field.Mesh=sqrt((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)/nbvec);%2D
-    end
-end
-
-%case of structured coordinates
-'TESTfield'
-UvData.Field
-if isfield(UvData.Field,'AX') && isfield(UvData.Field,'AY')&& isfield(UvData.Field,'A')
-    UvData.XMax=max(UvData.Field.AX);
-    UvData.XMin=min(UvData.Field.AX);
-    UvData.YMax=max(UvData.Field.AY);
-    UvData.YMin=min(UvData.Field.AY);
-    np_A=size(UvData.Field.A);
-    Field.Mesh=sqrt((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)/((np_A(1)-1) * (np_A(2)-1))) ; 
-end
-if  isempty(coord_x) && ~isempty(CellVarIndex)
+        UvData.Field.Mesh=sqrt((XMax-XMin)*(YMax-YMin)/nbvec);%2D
+    end
+else
     VarIndex=CellVarIndex{imax}; % list of variable indices
     DimIndex=UvData.Field.VarDimIndex{VarIndex(1)}; %list of dim indices for the variable
-    if NbDim==3
-        nbpoints=UvData.Field.DimValue(DimIndex(1));
-        if isfield(VarType{imax},'coord_3')&& ~isequal(VarType{imax}.coord_3,0) % z is a dimension variable
-            ZName=UvData.Field.ListVarName{VarType{imax}.coord_3};
-            eval(['UvData.ZMax=max(UvData.Field.' ZName ');'])
-            eval(['UvData.ZMin=min(UvData.Field.' ZName ');'])
-        else
-            testcoord_z=0;
-            if length(UvData.Field.VarAttribute)>=VarIndex(1)
-                if isfield(UvData.Field.VarAttribute{VarIndex(1)},'Coord_1')%regular grid 
-                    Coord_z=UvData.Field.VarAttribute{VarIndex(1)}.Coord_1;
-                    UvData.ZMax=max(Coord_z);
-                    UvData.ZMin=min(Coord_z);
-                    testcoord_z=1;
-                end
-            end
-            if ~testcoord_z
-                  UvData.ZMin=1;
-                  UvData.ZMax=UvData.Field.DimValue(DimIndex(1));
-            end
-        end
-        Field.Mesh=(UvData.ZMax-UvData.ZMin)/(nbpoints-1); 
-    elseif NbDim==2
-        nbpoints_y=UvData.Field.DimValue(DimIndex(1));       
-        Yvar=VarType{imax}.coord_y;
-        if Yvar~=0  % x is a dimension variable
-            YName=UvData.Field.ListVarName{Yvar};
-            eval(['UvData.YMax=max(UvData.Field.' YName ');'])
-            eval(['UvData.YMin=min(UvData.Field.' YName ');'])
-        else
-            testcoord_y=0;
-            if ~testcoord_y
-                  UvData.YMin=1;
-                  UvData.YMax=UvData.Field.DimValue(DimIndex(1));
-            end
-        end
-        DY=(UvData.YMax-UvData.YMin)/(nbpoints_y-1);
-        nbpoints_x=UvData.Field.DimValue(DimIndex(2));
-        Xvar=VarType{imax}.coord_x;
-        if Xvar~=0  % x is a dimension variable
-            XName=UvData.Field.ListVarName{Xvar};
-            eval(['UvData.XMax=max(UvData.Field.' XName ');'])
-            eval(['UvData.XMin=min(UvData.Field.' XName ');'])
-        else
-            testcoord_x=0;
-            if ~testcoord_x
-                  UvData.XMin=1;
-                  UvData.XMax=UvData.Field.DimValue(DimIndex(2));
-            end
-        end
-        DX=(UvData.XMax-UvData.XMin)/(nbpoints_x-1);
-        Field.Mesh= sqrt(DX*DY); 
-    end
-end
+    nbpoints_y=UvData.Field.DimValue(DimIndex(1));
+    nbpoints_x=UvData.Field.DimValue(DimIndex(2));
+    DX=(XMax-XMin)/nbpoints_x;
+    DY=(YMax-YMin)/nbpoints_y;
+    UvData.Field.Mesh=sqrt(DX*DY);
+end
+UvData.Field.XMax=XMax;
+UvData.Field.XMin=XMin;
+UvData.Field.YMax=XMax;
+UvData.Field.YMin=XMin;
+if test_z
+    UvData.Field.ZMax=ZMax;
+    UvData.Field.ZMin=ZMin;
+end
+
+%case of structured coordinates
+
+% if  isempty(coord_x) && ~isempty(CellVarIndex)
+%     VarIndex=CellVarIndex{imax}; % list of variable indices
+%     DimIndex=UvData.Field.VarDimIndex{VarIndex(1)}; %list of dim indices for the variable
+%     if NbDim==3
+%         nbpoints=UvData.Field.DimValue(DimIndex(1));
+%         if isfield(VarType{imax},'coord_3')&& ~isequal(VarType{imax}.coord_3,0) % z is a dimension variable
+%             ZName=UvData.Field.ListVarName{VarType{imax}.coord_3};
+%             eval(['UvData.ZMax=max(UvData.Field.' ZName ');'])
+%             eval(['UvData.ZMin=min(UvData.Field.' ZName ');'])
+%         else
+%             testcoord_z=0;
+%             if length(UvData.Field.VarAttribute)>=VarIndex(1)
+%                 if isfield(UvData.Field.VarAttribute{VarIndex(1)},'Coord_1')%regular grid 
+%                     Coord_z=UvData.Field.VarAttribute{VarIndex(1)}.Coord_1;
+%                     UvData.ZMax=max(Coord_z);
+%                     UvData.ZMin=min(Coord_z);
+%                     testcoord_z=1;
+%                 end
+%             end
+%             if ~testcoord_z
+%                   UvData.ZMin=1;
+%                   UvData.ZMax=UvData.Field.DimValue(DimIndex(1));
+%             end
+%         end
+%         Field.Mesh=(UvData.ZMax-UvData.ZMin)/(nbpoints-1); 
+%     elseif NbDim==2
+%         nbpoints_y=UvData.Field.DimValue(DimIndex(1));       
+%         Yvar=VarType{imax}.coord_y;
+%         if Yvar~=0  % x is a dimension variable
+%             YName=UvData.Field.ListVarName{Yvar};
+%             eval(['UvData.YMax=max(UvData.Field.' YName ');'])
+%             eval(['UvData.YMin=min(UvData.Field.' YName ');'])
+%         else
+%             testcoord_y=0;
+%             if ~testcoord_y
+%                   UvData.YMin=1;
+%                   UvData.YMax=UvData.Field.DimValue(DimIndex(1));
+%             end
+%         end
+%         DY=(UvData.YMax-UvData.YMin)/(nbpoints_y-1);
+%         nbpoints_x=UvData.Field.DimValue(DimIndex(2));
+%         Xvar=VarType{imax}.coord_x;
+%         if Xvar~=0  % x is a dimension variable
+%             XName=UvData.Field.ListVarName{Xvar};
+%             eval(['UvData.XMax=max(UvData.Field.' XName ');'])
+%             eval(['UvData.XMin=min(UvData.Field.' XName ');'])
+%         else
+%             testcoord_x=0;
+%             if ~testcoord_x
+%                   UvData.XMin=1;
+%                   UvData.XMax=UvData.Field.DimValue(DimIndex(2));
+%             end
+%         end
+%         DX=(UvData.XMax-UvData.XMin)/(nbpoints_x-1);
+%         Field.Mesh= sqrt(DX*DY); 
+%     end
+% end
 
 %create a default projection menuplane
@@ -2680,5 +2697,4 @@
 IndexObj_2=get(handles.list_object_2,'Value');%selected projection object for the second view
 if isequal(get(handles.list_object_2,'Visible'),'on') && IndexObj_2 <= numel(UvData.Object)&& ~isempty(UvData.Object{IndexObj_2})
-    UvData.Object{IndexObj_2}
     IndexObj(2)=IndexObj_2;
     view_field_handle=findobj(allchild(0),'tag','view_field');%handles of the view_field GUI
@@ -4419,5 +4435,5 @@
 list_str=get(handles.list_object_2,'String');
 IndexObj=get(handles.list_object_2,'Value');
-if strcmp(list_str{IndexObj},'...')
+if ischar(list_str) || strcmp(list_str{IndexObj},'...')
     hview_field=findobj(allchild(0),'Tag','view_field');
     if ~isempty(hview_field)
@@ -4655,5 +4671,4 @@
 % ------------------------------------------------------------------
 function MenuCalib_Callback(hObject, eventdata, handles)
-%geometry_calib; %display the GUI as a  waiting display
 
 UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface 
@@ -4662,8 +4677,4 @@
 set(handles.zoom,'Value',0)
 set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
-% set(handles.MenuMask,'enable','off')
-% set(handles.MenuGrid,'enable','off')
-% set(handles.MenuObject,'enable','off')
-% set(handles.MenuEdit,'enable','off')
 set(handles.list_object_1,'Value',1)      
 % initiate display of GUI geometry_calib
@@ -4682,12 +4693,8 @@
     pos_cal(2)=pos_uvmat(2)+UvData.CalOrigin(2)*pos_uvmat(4);
     pos_cal(3:4)=UvData.CalSize .* pos_uvmat(3:4);
-    %set(UvData.hset_object,'Position',pos_cal)
 end
 geometry_calib(FileName,pos_cal);% call the geometry_calib interface	
 set(handles.view_xml,'Backgroundcolor',[1 1 1])%indicate the end of reading of the current xml file by geometry_calib
 set(handles.MenuCalib,'checked','on')% indicate that MenuCalib is activated, test used by mouse action
-
-%UvData.MouseAction='calib';
-% set(handles.uvmat,'UserData',UvData);
 
 
@@ -4721,5 +4728,5 @@
                 flagobj=1;
                 testphys=0; %coordinates in pixels by default
-                if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys')
+                if isfield(ObjectData,'CoordUnit') && ~isequal(ObjectData.CoordUnit,'pixel')
                     if isfield(UvData,'XmlData')&& isfield(UvData.XmlData,'GeometryCalib')
                         Calib=UvData.XmlData.GeometryCalib;
