Index: trunk/src/sub_field.m
===================================================================
--- trunk/src/sub_field.m	(revision 165)
+++ trunk/src/sub_field.m	(revision 179)
@@ -1,3 +1,9 @@
-%'sub_field': combines two input fields 
+%'sub_field': combines two input fields
+%
+% the two fields are subtstracted when of the same nature (scalar or
+% vector), if the coordinates do not coincide, the second field is
+% interpolated on the cooridintes of the first one
+%
+% when scalar and vectors are combined, the fields are just merged in a single matlab structure for common visualisation
 %-----------------------------------------------------------------------
 % function SubData=sub_field(Field,Field_1)
@@ -7,8 +13,6 @@
 %
 % INPUT: 
-% UvData: main structure UvData associated to the uvmat GUI as 'UserData'
-% Field: cell of Matlab structures representing the input fields
-% 
-%    -- TODO: need to be rationalized --
+% Field: matlab structure representing the first field
+% Field_1:matlab structure representing the second field
 
 function [SubData,errormsg]=sub_field(Field,Field_1)
@@ -77,6 +81,4 @@
     return
 end
-% VarIndex=CellVarIndex{iselect};
-% VarIndex_1=CellVarIndex_1{iselect_1};
 VarType=VarTypeCell{iselect};
 VarType_1=VarTypeCell_1{iselect_1};
@@ -85,5 +87,4 @@
 testU=~isempty(VarType.vector_x)&& ~isempty(VarType.vector_y);%vector field
 testU_1=~isempty(VarType_1.vector_x)&& ~isempty(VarType_1.vector_y);%vector field
-% testfalse=~isempty(VarType.errorflag);
 testfalse_1=~isempty(VarType_1.errorflag);
 ivar_C=[VarType.scalar VarType.image VarType.color VarType.ancillary]; %defines index (indices) for the scalar or ancillary fields
@@ -101,6 +102,42 @@
 if (testU && testU_1) || (~testU && ~testU_1)
    %check coincidence in positions
-   %unstructured coordinates
-   if testX      
+   %unstructured coordinates for the first field
+   if testX  
+       XName=Field.ListVarName{VarType.coord_x};
+       YName=Field.ListVarName{VarType.coord_y};
+       eval(['vec_X=Field.' XName ';']) 
+       eval(['vec_Y=Field.' YName ';'])
+       nbpoints=numel(vec_X);
+       vec_X=reshape(vec_X,nbpoints,1);
+       vec_Y=reshape(vec_Y,nbpoints,1);
+       if testX_1 %unstructured coordinates for the second field
+            X_1_Name=Field_1.ListVarName{VarType_1.coord_x};
+            Y_1_Name=Field_1.ListVarName{VarType_1.coord_y};
+            eval(['vec_X_1=Field_1.' X_1_Name ';']) 
+            eval(['vec_Y_1=Field_1.' Y_1_Name ';'])
+
+       else   %structured coordinates for the second field
+           y_1_Name=Field_1.ListVarName{VarType_1.coord(1)};
+           x_1_Name=Field_1.ListVarName{VarType_1.coord(2)};
+           eval(['y_1=Field_1.' y_1_Name ';']) 
+           eval(['x_1=Field_1.' x_1_Name ';'])
+           if isequal(numel(x_1),2)  
+               x_1=linspace(x_1(1),x_1(2),nbpoints_x_1);
+           end
+           if isequal(numel(y_1),2)  
+               y_1=linspace(y_1(1),y_1(2),nbpoints_y_1);
+           end
+           [vec_X_1,vec_Y_1]=meshgrid(x_1,y_1);
+       end
+       vec_X_1=reshape(vec_X_1,[],1);
+       vec_Y_1=reshape(vec_Y_1,[],1);
+       if testfalse_1
+           FFName_1=Field_1.ListVarName{VarType_1.errorflag};          
+           eval(['vec_FF_1=Field_1.' FFName_1 ';']) 
+           vec_FF_1=reshape(vec_FF_1,[],1);
+           indsel=find(~vec_FF_1);
+           vec_X_1=vec_X_1(indsel);
+           vec_Y_1=vec_Y_1(indsel);
+       end
        if testU % vector fields
             U_1_Name=Field_1.ListVarName{VarType_1.vector_x};
@@ -126,40 +163,5 @@
            end
        end
-       XName=Field.ListVarName{VarType.coord_x};
-       YName=Field.ListVarName{VarType.coord_y};
-       eval(['vec_X=Field.' XName ';']) 
-       eval(['vec_Y=Field.' YName ';'])
-       nbpoints=numel(vec_X);
-       vec_X=reshape(vec_X,nbpoints,1);
-       vec_Y=reshape(vec_Y,nbpoints,1);
-       if testX_1 %unstructured coordinates for the second field
-            X_1_Name=Field_1.ListVarName{VarType_1.coord_x};
-            Y_1_Name=Field_1.ListVarName{VarType_1.coord_y};
-            eval(['vec_X_1=Field_1.' X_1_Name ';']) 
-            eval(['vec_Y_1=Field_1.' Y_1_Name ';'])
-
-       else   %structured coordinates for the second field
-           y_1_Name=Field_1.ListVarName{VarType_1.coord(1)};
-           x_1_Name=Field_1.ListVarName{VarType_1.coord(2)};
-           eval(['y_1=Field_1.' y_1_Name ';']) 
-           eval(['x_1=Field_1.' x_1_Name ';'])
-           if isequal(numel(x_1),2)  
-               x_1=linspace(x_1(1),x_1(2),nbpoints_x_1);
-           end
-           if isequal(numel(y_1),2)  
-               y_1=linspace(y_1(1),y_1(2),nbpoints_y_1);
-           end
-           [vec_X_1,vec_Y_1]=meshgrid(x_1,y_1);
-       end
-       vec_X_1=reshape(vec_X_1,nbpoints_x_1*nbpoints_y_1,1);
-       vec_Y_1=reshape(vec_Y_1,nbpoints_x_1*nbpoints_y_1,1);
-       if testfalse_1
-           FFName_1=Field_1.ListVarName{VarType_1.errorflag};          
-           eval(['vec_FF_1=Field_1.' FFName_1 ';']) 
-           vec_FF_1=reshape(vec_FF_1,nbpoints_1,1);
-           indsel=find(~vec_FF_1);
-           vec_X_1=vec_X_1(indsel);
-           vec_Y_1=vec_Y_1(indsel);
-       end
+
        if ~isequal(vec_X_1,vec_X) && ~isequal(vec_Y_1,vec_Y) % if the unstructured positions are not the same
            if testU
@@ -228,5 +230,5 @@
 if testU && ~testU_1
     AName_1=Field_1.ListVarName{ivar_C_1};
-    if isfield(Field_1,'VarAttribute') && numel(Field_1.VarAttribute)>=ivar_C_1
+    if isfield(Field_1,'VarAttribute') & numel(Field_1.VarAttribute)>=ivar_C_1
         AAttr=Field_1.VarAttribute{ivar_C_1} ;
     else
@@ -236,14 +238,13 @@
        XName_1=Field_1.ListVarName{VarType_1.coord_x};
        YName_1=Field_1.ListVarName{VarType_1.coord_y};
-       %SubData.ListVarName=[SubData.ListVarName {XName_1} {YName_1}];
        DimCell=Field_1.VarDimName([VarType_1.coord_x VarType_1.coord_y ]);
        if isfield(Field_1,'VarAttribute') 
            if numel(Field_1.VarAttribute)>=VarType_1.coord_x
-                XAttr=Field_1.VarAttribute{VarType_1.coord_x} ;
+                XAttr=Field_1.VarAttribute{VarType_1.coord_x}; 
            else
                 XAttr=[];
            end
            if numel(Field_1.VarAttribute)>=VarType_1.coord_y
-               YAttr=Field_1.VarAttribute{VarType_1.coord_y} ;
+               YAttr=Field_1.VarAttribute{VarType_1.coord_y}; 
            else
                YAttr=[];
@@ -361,4 +362,3 @@
     eval(['SubData.' VName_1_1 '=Field_1.' VName_1 ';'])  
 end
-
   
