Index: trunk/src/uvmat.m
===================================================================
--- trunk/src/uvmat.m	(revision 403)
+++ trunk/src/uvmat.m	(revision 404)
@@ -1989,19 +1989,16 @@
 if ~isempty(filename)
     ObjectName=filename;
-    FieldName=[];%default
-    VelType=[];%default
-   % FileExt=get(handles.FileExt,'String');
-    FileType=UvData.FileType{1};
-    switch FileType
-        %     if strcmp(Ext,'.nc')||strcmp(Ext,'.cdf')
+    FieldName='';%default
+    VelType='';%default
+%     FileType=UvData.FileType{1};
+    switch UvData.FileType{1}
         case {'civx','civdata','netcdf'};
             list_fields=get(handles.Fields,'String');% list menu fields
-            index_fields=get(handles.Fields,'Value');% selected string index
-            FieldName= list_fields{index_fields}; % selected field
+  %          index_fields=get(handles.Fields,'Value');% selected string index
+            FieldName= list_fields{get(handles.Fields,'Value')}; % selected field
             if ~strcmp(FieldName,'get_field...')
                 if get(handles.FixVelType,'Value')
                     VelTypeList=get(handles.VelType,'String');
                     VelType=VelTypeList{get(handles.VelType,'Value')};
-%                     VelType=setfield(handles);% read the velocity type.
                 end
             end
@@ -2029,5 +2026,5 @@
     ParamIn.VelType=VelType;
     ParamIn.GUIName='get_field';
-    [Field{1},ParamOut,errormsg] = read_field(ObjectName,FileType,ParamIn,num_i1);
+    [Field{1},ParamOut,errormsg] = read_field(ObjectName,UvData.FileType{1},ParamIn,num_i1);
     if ~isempty(errormsg)
         errormsg=['error in reading ' filename ': ' errormsg];
@@ -2056,7 +2053,6 @@
     end
     Name=filename_1;
-    FileType_1=UvData.FileType{2};
-    switch FileType_1
-        %     if strcmp(Ext,'.nc')||strcmp(Ext,'.cdf')
+%     FileType_1=UvData.FileType{2};
+    switch UvData.FileType{2}
         case {'civx','civdata','netcdf'};
             list_fields=get(handles.Fields_1,'String');% list menu fields
@@ -2066,5 +2062,4 @@
                     VelTypeList=get(handles.VelType_1,'String');
                     VelType_1=VelTypeList{get(handles.VelType_1,'Value')};% read the velocity type.
-%                     VelType_1=setfield(handles);% read the velocity type.
                 end
             end
@@ -2102,5 +2097,5 @@
         ParamIn.VelType=VelType_1;
         ParamIn.GUIName='get_field_1';
-        [Field{2},ParamOut_1,errormsg] = read_field(Name,FileType_1,ParamIn,num_i1);
+        [Field{2},ParamOut_1,errormsg] = read_field(Name,UvData.FileType{2},ParamIn,num_i1);
         if ~isempty(errormsg)
             errormsg=['error in reading ' FieldName_1 ' in ' filename_1 ': ' errormsg];
@@ -2124,10 +2119,10 @@
 test_veltype=0;
 % if ~isequal(FileType,'netcdf')|| isequal(FieldName,'get_field...')
-if (strcmp(FileType,'civx')||strcmp(FileType,'civdata'))&& ~strcmp(FieldName,'get_field...')
+if (strcmp(UvData.FileType{1},'civx')||strcmp(UvData.FileType{1},'civdata'))&& ~strcmp(FieldName,'get_field...')
     test_veltype=1;
     set(handles.VelType,'Visible','on')
     set(handles.VelType_1,'Visible','on')
     set(handles.FixVelType,'Visible','on')
-    menu=set_veltype_display(ParamOut.CivStage,FileType);
+    menu=set_veltype_display(ParamOut.CivStage,UvData.FileType{1});
     index_menu=strcmp(ParamOut.VelType,menu);%look for VelType in  the menu
     index_val=find(index_menu,1);
@@ -2154,5 +2149,5 @@
     set(handles.Fields_1,'String',[{''};ParamOut.FieldList]); %update the field menu
 else
-    if (~strcmp(FileType_1,'netcdf')&&~strcmp(FileType_1,'civdata')&&~strcmp(FileType_1,'civx'))|| isequal(FieldName_1,'get_field...')
+    if (~strcmp(UvData.FileType{2},'netcdf')&&~strcmp(UvData.FileType{2},'civdata')&&~strcmp(UvData.FileType{2},'civx'))|| isequal(FieldName_1,'get_field...')
         set(handles.VelType_1,'Visible','off')
     else 
@@ -2228,5 +2223,5 @@
     end
     %% update tps in phys coordinates if needed
-    if (strcmp(VelType,'filter1')||strcmp(VelType,'filter2'))&& strcmp(FileType,'civdata')&&isfield(Field{1},'U')&& isfield(Field{1},'V')
+    if (strcmp(VelType,'filter1')||strcmp(VelType,'filter2'))&& strcmp(UvData.FileType{1},'civdata')&&isfield(Field{1},'U')&& isfield(Field{1},'V')
         Field{1}.X=Field{1}.X(Field{1}.FF==0);
         Field{1}.Y=Field{1}.Y(Field{1}.FF==0);
@@ -2235,7 +2230,7 @@
         [Field{1}.SubRange,Field{1}.NbSites,Field{1}.Coord_tps,Field{1}.U_tps,Field{1}.V_tps]=filter_tps([Field{1}.X Field{1}.Y],Field{1}.U,Field{1}.V,[],Field{1}.Patch1_SubDomain,0);
     end
-    if numel(Field)==2 && ~test_keepdata_1 && isequal(FileType_1(1:3),'civ') && ~isequal(ParamOut_1.FieldName,'get_field...')%&&~isempty(FieldName_1)
+    if numel(Field)==2 && ~test_keepdata_1 && isequal(UvData.FileType{2}(1:3),'civ') && ~isequal(ParamOut_1.FieldName,'get_field...')%&&~isempty(FieldName_1)
         %update tps in phys coordinates if needed
-        if (strcmp(VelType_1,'filter1')||strcmp(VelType_1,'filter2'))&& strcmp(FileType_1,'civdata')&&isfield(Field{2},'U')&& isfield(Field{2},'V')
+        if (strcmp(VelType_1,'filter1')||strcmp(VelType_1,'filter2'))&& strcmp(UvData.FileType{2},'civdata')&&isfield(Field{2},'U')&& isfield(Field{2},'V')
             Field{2}.X=Field{2}.X(Field{2}.FF==0);
             Field{2}.Y=Field{1}.Y(Field{2}.FF==0);
@@ -2256,5 +2251,7 @@
 
 %% combine the two input fields (e.g. substract velocity fields)
+Field{1}.FieldList=[{ParamOut.FieldName} {ParamOut.ColorVar}];
 if numel(Field)==2
+    Field{2}.FieldList=[{ParamOut_1.FieldName} {ParamOut_1.ColorVar}];
    [UvData.Field,errormsg]=sub_field(Field{1},Field{2});  
 else
@@ -2265,10 +2262,11 @@
     return
 end
-UvData.Field.FieldList={FieldName}; % TODO: to generalise, used for proj_field with tps interpolation
+%UvData.Field.FieldList={FieldName}; % TODO: to generalise, used for proj_field with tps interpolation
+
 
 %% get bounds and mesh (needed for mouse action and to open set_object)
 test_x=0;
 test_z=0;% test for unstructured z coordinate
-[UvData.Field,errormsg]=check_field_structure(UvData.Field);
+[errormsg,ListDimName,DimValue,VarDimIndex]=check_field_structure(UvData.Field);
 if ~isempty(errormsg)
     errormsg=['error in uvmat/refresh_field/check_field_structure: ' errormsg];
@@ -2336,13 +2334,13 @@
     else
         VarIndex=CellVarIndex{imax}; % list of variable indices
-        DimIndex=UvData.Field.VarDimIndex{VarIndex(1)}; %list of dim indices for the variable
-        nbpoints_x=UvData.Field.DimValue(DimIndex(NbDim));
+        DimIndex=VarDimIndex{VarIndex(1)}; %list of dim indices for the variable
+        nbpoints_x=DimValue(DimIndex(NbDim));
         DX=(XMax-XMin)/(nbpoints_x-1);
         if NbDim >1
-            nbpoints_y=UvData.Field.DimValue(DimIndex(NbDim-1));
+            nbpoints_y=DimValue(DimIndex(NbDim-1));
             DY=(YMax-YMin)/(nbpoints_y-1);
         end
         if NbDim==3
-            nbpoints_z=UvData.Field.DimValue(DimIndex(1));
+            nbpoints_z=DimValue(DimIndex(1));
             DZ=(ZMax-ZMin)/(nbpoints_z-1);
             UvData.Field.Mesh=(DX*DY*DZ)^(1/3);
@@ -2352,4 +2350,13 @@
             UvData.Field.Mesh=DX;%sqrt(DX*DY);
         end
+    end
+    % adjust the mesh to a value 1, 2 , 5 *10^n
+    ord=10^(floor(log10(UvData.Field.Mesh)));%order of magnitude
+    if UvData.Field.Mesh/ord>=5
+        UvData.Field.Mesh=5*ord;
+    elseif UvData.Field.Mesh/ord>=2
+        UvData.Field.Mesh=2*ord;
+    else
+        UvData.Field.Mesh=ord;
     end
 end
@@ -2362,12 +2369,5 @@
     ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
     if ~isempty(hset_object) %if set_object is detected
-%         hhset_object=guidata(hset_object);
-% %         ZBounds_old(1)=get(hhset_object.z_slider,'Min');
-% %         ZBounds_old(2)=get(hhset_object.z_slider,'Max');
-% %         if isequal(ZBounds_old,ZBounds)
-%             test_set_object=0;% do not refresh the GUI set_object
-%         else
-            delete(hset_object);% delete the GUI set_object if it does not fit 
-%         end
+          delete(hset_object);% delete the GUI set_object if it does not fit 
     end
     if test_set_object% reinitiate the GUI set_object
@@ -2380,8 +2380,5 @@
         UvData.Object{1}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
         UvData.Object{1}.Angle=[0 0 0];
-%         UvData.Object{1}.Theta=0;
-%         UvData.Object{1}.Psi=0;
         UvData.Object{1}.HandlesDisplay=plot(0,0,'Tag','proj_object');% A REVOIR
-%         PlotHandles=get_plot_handles(handles);
         UvData.Object{1}.Name='1-PLANE';
         UvData.Object{1}.enable_plot=1;
@@ -2460,5 +2457,5 @@
      PlotParam{1}.Vectors.ListColorCode= {'rgb'};
 end
-keeplim(1)=get(handles.CheckFixLimits,'Value');% test for fixed graph limits
+%keeplim(1)=get(handles.CheckFixLimits,'Value');% test for fixed graph limits
 PosColorbar{1}=UvData.OpenParam.PosColorbar;%prescribe the colorbar position on the uvmat interface
 
@@ -2471,5 +2468,5 @@
         %PlotParam{2}=read_plot_param(plot_handles{2});%read plotting parameters on the viewinterface
         PlotParam{2}=read_GUI(handles.uvmat);%read plotting parameters on the uvmat interface
-        keeplim(2)=get(plot_handles{2}.CheckFixLimits,'Value');
+       % keeplim(2)=get(plot_handles{2}.CheckFixLimits,'Value');
         PosColorbar{2}='*'; %TODO: deal with colorbar position on view_field
     end
@@ -2479,22 +2476,9 @@
 for imap=1:numel(IndexObj)
     iobj=IndexObj(imap);
-%     if iobj==1 && ~isfield(UvData.Object{iobj},'Type')% case with no projection (only for the first empty object)
-%         ord=10^(floor(log10(UvData.Field.Mesh)));%order of magnitude
-%         if UvData.Field.Mesh/ord>=5
-%             mesh=5*ord;
-%         elseif UvData.Field.Mesh/ord>=2
-%             mesh=2*ord;
-%         else
-%             mesh=ord;
-%         end
-%         coord_x=UvData.Field.XMin:mesh:UvData.Field.XMax;
-%         coord_y=UvData.Field.YMin:mesh:UvData.Field.YMax;
-%         [XI,YI]=meshgrid(coord_x,coord_y);
-%         XI=reshape(XI,[],1);
-%         YI=reshape(YI,[],1);
-%         [ObjectData,errormsg]=calc_field({FieldName},UvData.Field,[XI YI]);
-%     else
+     if iobj==1 && ~isfield(UvData.Object{iobj},'Type')% case with no projection (only for the first empty object)
+         [ObjectData,errormsg]=calc_field(UvData.Field.FieldList,UvData.Field);
+     else
         [ObjectData,errormsg]=proj_field(UvData.Field,UvData.Object{iobj});% project field on the object
-%     end
+     end
     if ~isempty(errormsg)
         return
@@ -2539,16 +2523,17 @@
             end
             ObjectData.ListVarName(ind_off)=[];
-            ObjectData.VarDimIndex(ind_off)=[];
+            VarDimIndex(ind_off)=[];
             ind_off=[];
-            for ilist=1:length(ObjectData.ListDimName)
-                if isequal(ObjectData.ListDimName{ilist},'MaskX') || isequal(ObjectData.ListDimName{ilist},'MaskY')
+            for ilist=1:length(ListDimName)
+                if isequal(ListDimName{ilist},'MaskX') || isequal(ListDimName{ilist},'MaskY')
                     ind_off=[ind_off ilist];
                 end
             end
-            ObjectData.ListDimName(ind_off)=[];
-            ObjectData.DimValue(ind_off)=[];
+            ListDimName(ind_off)=[];
+            DimValue(ind_off)=[];
         end
     end
     if ~isempty(ObjectData)
+        
         PlotType='none'; %default
         if imap==2 && isempty(view_field_handle)
@@ -3237,9 +3222,9 @@
         data.CoordType=UvData.CoordType;
     end
-    if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
-        data.RangeY=UvData.Mesh;
-        data.RangeX=UvData.Mesh;
-        data.DX=UvData.Mesh;
-        data.DY=UvData.Mesh;
+    if isfield(UvData.Field,'Mesh')&~isempty(UvData.Field.Mesh)
+        data.RangeX=[UvData.Field.XMin UvData.Field.XMax];
+        data.RangeY=[UvData.Field.YMin UvData.Field.YMax];
+        data.DX=UvData.Field.Mesh;
+        data.DY=UvData.Field.Mesh;
     elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
         np=size(UvData.Field.A);
@@ -4328,24 +4313,16 @@
 if isfield(UvData,'Field')
     Field=UvData.Field;
-    if isfield(Field,'Mesh')&&~isempty(Field.Mesh)
-        ord=10^(floor(log10(Field.Mesh)));%order of magnitude
-        if Field.Mesh/ord>=5
-            mesh=5*ord;
-        elseif Field.Mesh/ord>=2
-            mesh=2*ord;
-        else
-            mesh=ord;
-        end
-        data.RangeX=mesh;
-        data.RangeY=mesh;
-        data.DX=mesh;
-        data.DY=mesh;
-    elseif isfield(Field,'AX')&& isfield(Field,'AY')&& isfield(Field,'A')%only image
-        np=size(Field.A);
-        meshx=(Field.AX(end)-Field.AX(1))/np(2);
-        meshy=abs(Field.AY(end)-Field.AY(1))/np(1);
-        data.RangeY=max(meshx,meshy);
-        data.RangeX=max(meshx,meshy);
-        data.DX=max(meshx,meshy);
+    if isfield(UvData.Field,'Mesh')&&~isempty(UvData.Field.Mesh)
+        data.RangeX=[UvData.Field.XMin UvData.Field.XMax];
+        data.RangeY=[UvData.Field.YMin UvData.Field.YMax];
+        data.DX=UvData.Field.Mesh;
+        data.DY=UvData.Field.Mesh;
+%     elseif isfield(Field,'AX')&& isfield(Field,'AY')&& isfield(Field,'A')%only image
+%         np=size(Field.A);
+%         meshx=(Field.AX(end)-Field.AX(1))/np(2);
+%         meshy=abs(Field.AY(end)-Field.AY(1))/np(1);
+%         data.RangeY=max(meshx,meshy);
+%         data.RangeX=max(meshx,meshy);
+%         data.DX=max(meshx,meshy);
     end
     if isfield(Field,'NbDim')&& isequal(Field.NbDim,3)
@@ -4360,5 +4337,5 @@
 end
 hset_object=findobj(allchild(0),'tag','set_object');
-IndexObj=get(handles.ListObject,'Value')
+IndexObj=get(handles.ListObject,'Value');
 if ~isempty(hset_object)
     delete(hset_object)% delete existing version of set_object
