Changeset 179 for trunk/src/sub_field.m


Ignore:
Timestamp:
Jan 9, 2011, 12:56:28 PM (13 years ago)
Author:
sommeria
Message:

various bug repairs, in particular for 3D fields

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sub_field.m

    r165 r179  
    1 %'sub_field': combines two input fields
     1%'sub_field': combines two input fields
     2%
     3% the two fields are subtstracted when of the same nature (scalar or
     4% vector), if the coordinates do not coincide, the second field is
     5% interpolated on the cooridintes of the first one
     6%
     7% when scalar and vectors are combined, the fields are just merged in a single matlab structure for common visualisation
    28%-----------------------------------------------------------------------
    39% function SubData=sub_field(Field,Field_1)
     
    713%
    814% INPUT:
    9 % UvData: main structure UvData associated to the uvmat GUI as 'UserData'
    10 % Field: cell of Matlab structures representing the input fields
    11 %
    12 %    -- TODO: need to be rationalized --
     15% Field: matlab structure representing the first field
     16% Field_1:matlab structure representing the second field
    1317
    1418function [SubData,errormsg]=sub_field(Field,Field_1)
     
    7781    return
    7882end
    79 % VarIndex=CellVarIndex{iselect};
    80 % VarIndex_1=CellVarIndex_1{iselect_1};
    8183VarType=VarTypeCell{iselect};
    8284VarType_1=VarTypeCell_1{iselect_1};
     
    8587testU=~isempty(VarType.vector_x)&& ~isempty(VarType.vector_y);%vector field
    8688testU_1=~isempty(VarType_1.vector_x)&& ~isempty(VarType_1.vector_y);%vector field
    87 % testfalse=~isempty(VarType.errorflag);
    8889testfalse_1=~isempty(VarType_1.errorflag);
    8990ivar_C=[VarType.scalar VarType.image VarType.color VarType.ancillary]; %defines index (indices) for the scalar or ancillary fields
     
    101102if (testU && testU_1) || (~testU && ~testU_1)
    102103   %check coincidence in positions
    103    %unstructured coordinates
    104    if testX     
     104   %unstructured coordinates for the first field
     105   if testX 
     106       XName=Field.ListVarName{VarType.coord_x};
     107       YName=Field.ListVarName{VarType.coord_y};
     108       eval(['vec_X=Field.' XName ';'])
     109       eval(['vec_Y=Field.' YName ';'])
     110       nbpoints=numel(vec_X);
     111       vec_X=reshape(vec_X,nbpoints,1);
     112       vec_Y=reshape(vec_Y,nbpoints,1);
     113       if testX_1 %unstructured coordinates for the second field
     114            X_1_Name=Field_1.ListVarName{VarType_1.coord_x};
     115            Y_1_Name=Field_1.ListVarName{VarType_1.coord_y};
     116            eval(['vec_X_1=Field_1.' X_1_Name ';'])
     117            eval(['vec_Y_1=Field_1.' Y_1_Name ';'])
     118
     119       else   %structured coordinates for the second field
     120           y_1_Name=Field_1.ListVarName{VarType_1.coord(1)};
     121           x_1_Name=Field_1.ListVarName{VarType_1.coord(2)};
     122           eval(['y_1=Field_1.' y_1_Name ';'])
     123           eval(['x_1=Field_1.' x_1_Name ';'])
     124           if isequal(numel(x_1),2) 
     125               x_1=linspace(x_1(1),x_1(2),nbpoints_x_1);
     126           end
     127           if isequal(numel(y_1),2) 
     128               y_1=linspace(y_1(1),y_1(2),nbpoints_y_1);
     129           end
     130           [vec_X_1,vec_Y_1]=meshgrid(x_1,y_1);
     131       end
     132       vec_X_1=reshape(vec_X_1,[],1);
     133       vec_Y_1=reshape(vec_Y_1,[],1);
     134       if testfalse_1
     135           FFName_1=Field_1.ListVarName{VarType_1.errorflag};         
     136           eval(['vec_FF_1=Field_1.' FFName_1 ';'])
     137           vec_FF_1=reshape(vec_FF_1,[],1);
     138           indsel=find(~vec_FF_1);
     139           vec_X_1=vec_X_1(indsel);
     140           vec_Y_1=vec_Y_1(indsel);
     141       end
    105142       if testU % vector fields
    106143            U_1_Name=Field_1.ListVarName{VarType_1.vector_x};
     
    126163           end
    127164       end
    128        XName=Field.ListVarName{VarType.coord_x};
    129        YName=Field.ListVarName{VarType.coord_y};
    130        eval(['vec_X=Field.' XName ';'])
    131        eval(['vec_Y=Field.' YName ';'])
    132        nbpoints=numel(vec_X);
    133        vec_X=reshape(vec_X,nbpoints,1);
    134        vec_Y=reshape(vec_Y,nbpoints,1);
    135        if testX_1 %unstructured coordinates for the second field
    136             X_1_Name=Field_1.ListVarName{VarType_1.coord_x};
    137             Y_1_Name=Field_1.ListVarName{VarType_1.coord_y};
    138             eval(['vec_X_1=Field_1.' X_1_Name ';'])
    139             eval(['vec_Y_1=Field_1.' Y_1_Name ';'])
    140 
    141        else   %structured coordinates for the second field
    142            y_1_Name=Field_1.ListVarName{VarType_1.coord(1)};
    143            x_1_Name=Field_1.ListVarName{VarType_1.coord(2)};
    144            eval(['y_1=Field_1.' y_1_Name ';'])
    145            eval(['x_1=Field_1.' x_1_Name ';'])
    146            if isequal(numel(x_1),2) 
    147                x_1=linspace(x_1(1),x_1(2),nbpoints_x_1);
    148            end
    149            if isequal(numel(y_1),2) 
    150                y_1=linspace(y_1(1),y_1(2),nbpoints_y_1);
    151            end
    152            [vec_X_1,vec_Y_1]=meshgrid(x_1,y_1);
    153        end
    154        vec_X_1=reshape(vec_X_1,nbpoints_x_1*nbpoints_y_1,1);
    155        vec_Y_1=reshape(vec_Y_1,nbpoints_x_1*nbpoints_y_1,1);
    156        if testfalse_1
    157            FFName_1=Field_1.ListVarName{VarType_1.errorflag};         
    158            eval(['vec_FF_1=Field_1.' FFName_1 ';'])
    159            vec_FF_1=reshape(vec_FF_1,nbpoints_1,1);
    160            indsel=find(~vec_FF_1);
    161            vec_X_1=vec_X_1(indsel);
    162            vec_Y_1=vec_Y_1(indsel);
    163        end
     165
    164166       if ~isequal(vec_X_1,vec_X) && ~isequal(vec_Y_1,vec_Y) % if the unstructured positions are not the same
    165167           if testU
     
    228230if testU && ~testU_1
    229231    AName_1=Field_1.ListVarName{ivar_C_1};
    230     if isfield(Field_1,'VarAttribute') && numel(Field_1.VarAttribute)>=ivar_C_1
     232    if isfield(Field_1,'VarAttribute') & numel(Field_1.VarAttribute)>=ivar_C_1
    231233        AAttr=Field_1.VarAttribute{ivar_C_1} ;
    232234    else
     
    236238       XName_1=Field_1.ListVarName{VarType_1.coord_x};
    237239       YName_1=Field_1.ListVarName{VarType_1.coord_y};
    238        %SubData.ListVarName=[SubData.ListVarName {XName_1} {YName_1}];
    239240       DimCell=Field_1.VarDimName([VarType_1.coord_x VarType_1.coord_y ]);
    240241       if isfield(Field_1,'VarAttribute')
    241242           if numel(Field_1.VarAttribute)>=VarType_1.coord_x
    242                 XAttr=Field_1.VarAttribute{VarType_1.coord_x} ;
     243                XAttr=Field_1.VarAttribute{VarType_1.coord_x};
    243244           else
    244245                XAttr=[];
    245246           end
    246247           if numel(Field_1.VarAttribute)>=VarType_1.coord_y
    247                YAttr=Field_1.VarAttribute{VarType_1.coord_y} ;
     248               YAttr=Field_1.VarAttribute{VarType_1.coord_y};
    248249           else
    249250               YAttr=[];
     
    361362    eval(['SubData.' VName_1_1 '=Field_1.' VName_1 ';']) 
    362363end
    363 
    364364 
Note: See TracChangeset for help on using the changeset viewer.