Ignore:
Timestamp:
Mar 6, 2013, 9:20:51 PM (8 years ago)
Author:
sommeria
Message:

bugs corrected for reading vort div

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/calc_field_interp.m

    r575 r579  
    22% for projection with linear interpolation
    33%---------------------------------------------------------------------
    4 % [DataOut,VarAttribute,errormsg]=calc_field_interp(Coord_tps,NbSites,SubRange,FieldVar,Operation,Coord_interp)
     4% [VarVal,ListVarName,VarAttribute,errormsg]=calc_field_interp(Coord,Data,FieldName,XI,YI)
    55%
    66% OUTPUT:
    77% VarVal: array giving the values of the calculated field
     8% ListVarName: corresponding list of variable names
     9% VarAttribute: corresponding list of variable attributes, each term #ilist is of the form VarAttribute{ilist}.tag=value
    810%
    911% INPUT:
    10 % Coord_tps:
    11 % NbSites
    12 % SubRange
    13 % FieldVar
    14 % Operation: cell array representing the list of operations (eg div, rot..)
    15 % Coord_interp: coordiantes of sites on which the fields need to be calculated
     12% Coord(nbpoints,2): matrix of x,y coordinates of theinput data points
     13% Data: inputfield structure
     14% FieldName: string representing the field to calculate, or cell array of fields (as displayed in uvmat/FieldName)
     15% XI, YI: set of x and y coordiantes where the fields need to be linearly interpolated
    1616
    17 function [VarVal,ListVarName,VarAttribute,errormsg]=calc_field_interp(Coord,Data,Operation,XI,YI)
     17function [VarVal,ListVarName,VarAttribute,errormsg]=calc_field_interp(Coord,Data,FieldName,XI,YI)
    1818
    19 VarVal=[];
     19VarVal={};
    2020ListVarName={};
    2121VarAttribute={};
    2222errormsg='';
    2323InputVarList={};
    24 if ischar(Operation),Operation={Operation};end
    25 check_skipped=zeros(size(Operation));
    26 Operator=cell(size(Operation));
    27 for ilist=1:numel(Operation)
    28     r=regexp(Operation{ilist},'(?<Operator>(^vec|^norm))\((?<UName>.+),(?<VName>.+)\)$','names');
    29     if isempty(r) % the operation is the variable
    30         if ~isfield(Data,Operation{ilist})
    31             check_skipped(ilist)=1;
     24if ischar(FieldName),FieldName={FieldName};end
     25check_skipped=zeros(size(FieldName));% default, =1 to mark the variables which can be calculated
     26Operator=cell(size(FieldName));
     27for ilist=1:numel(FieldName)
     28    Operator{ilist}='';%default empty operator (vec, norm,...)
     29    r=regexp(FieldName{ilist},'(?<Operator>(^vec|^norm|^curl|^div|^strain))\((?<UName>.+),(?<VName>.+)\)$','names');% analyse the field name
     30    if isempty(r) % the field name is a variable itself
     31        if ~isfield(Data,FieldName{ilist})
     32            check_skipped(ilist)=1; %variable not found
    3233        else
    33             if isempty(find(strcmp(Operation{ilist},InputVarList)));
    34                 InputVarList=[InputVarList Operation{ilist}];% the variable is added to the list if it is not already in the list
     34            if isempty(find(strcmp(FieldName{ilist},InputVarList), 1));
     35                InputVarList=[InputVarList FieldName{ilist}];% the variable is added to the list of input variables if it is not already in the list
    3536            end
    36             Operator{ilist}='';
    3737        end
    3838    else
    39         if ~isfield(Data,r.UName)||~isfield(Data,r.VName)
     39        if ~isfield(Data,r.UName)||~isfield(Data,r.VName)%needed input variable not found
    4040            check_skipped(ilist)=1;
     41        elseif strcmp(r.Operator,'curl')||strcmp(r.Operator,'div')||strcmp(r.Operator,'strain')
     42            Operator{ilist}=r.Operator;
     43            switch r.Operator
     44                case 'curl'% case of CivX data format
     45                    UName{ilist}='vort';
     46                    Data.vort=Data.DjUi(:,1,2)-Data.DjUi(:,2,1);
     47                case 'div'
     48                    UName{ilist}='div';
     49                    Data.div=Data.DjUi(:,1,1)+Data.DjUi(:,2,2);
     50                case 'strain'
     51                    UName{ilist}='strain';
     52                    Data.strain=Data.DjUi(:,1,2)+Data.DjUi(:,2,1);
     53            end
     54            InputVarList=[InputVarList UName{ilist}]; %the variable is added to the list if it is not already in the list
    4155        else
    4256            UName{ilist}=r.UName;
     
    4559                InputVarList=[InputVarList UName{ilist}]; %the variable is added to the list if it is not already in the list
    4660            end
    47             if isempty(find(strcmp(r.VName,InputVarList)));
     61            if isempty(find(strcmp(r.VName,InputVarList), 1));
    4862                InputVarList=[InputVarList VName{ilist}]; %the variable is added to the list if it is not already in the list
    4963            end
     
    5872    end
    5973end
    60 for ilist=1:numel(Operation)
     74for ilist=1:numel(FieldName)
    6175    if ~check_skipped(ilist)
    6276        nbvar=numel(ListVarName);
     
    8599                ListVarName{nbvar+1}='norm';
    86100                VarAttribute{nbvar+1}.Role='scalar';
     101            case {'curl','div','strain'}
     102                if exist('XI','var')
     103                    VarVal{nbvar+1}=F.(UName{ilist})(XI,YI);
     104                else
     105                    VarVal{nbvar+1}=Data.(UName{ilist});
     106                end
     107                ListVarName{nbvar+1}=UName{ilist};
     108                VarAttribute{nbvar+1}.Role='scalar';
    87109            otherwise
    88                 if ~isempty(Operation{ilist})
     110                if ~isempty(FieldName{ilist})
    89111                    if exist('XI','var')
    90                         VarVal{nbvar+1}=F.(Operation{ilist})(XI,YI);
     112                        VarVal{nbvar+1}=F.(FieldName{ilist})(XI,YI);
    91113                    else
    92                         VarVal{nbvar+1}= Data.(Operation{ilist});
     114                        VarVal{nbvar+1}= Data.(FieldName{ilist});
    93115                    end
    94                     ListVarName{nbvar+1}=Operation{ilist};
     116                    ListVarName{nbvar+1}=FieldName{ilist};
    95117                    VarAttribute{nbvar+1}.Role='scalar';
    96118                end
     
    99121end
    100122% put an error flag to indicate NaN data
    101 if exist('XI','var')
     123if exist('XI','var')&&~isempty(VarVal)
    102124    nbvar=numel(ListVarName);
    103125    ListVarName{nbvar+1}='FF';
Note: See TracChangeset for help on using the changeset viewer.