Changeset 579 for trunk/src/calc_field_interp.m
 Timestamp:
 Mar 6, 2013, 9:20:51 PM (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/calc_field_interp.m
r575 r579 2 2 % for projection with linear interpolation 3 3 % 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) 5 5 % 6 6 % OUTPUT: 7 7 % 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 8 10 % 9 11 % 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 16 16 17 function [VarVal,ListVarName,VarAttribute,errormsg]=calc_field_interp(Coord,Data, Operation,XI,YI)17 function [VarVal,ListVarName,VarAttribute,errormsg]=calc_field_interp(Coord,Data,FieldName,XI,YI) 18 18 19 VarVal= [];19 VarVal={}; 20 20 ListVarName={}; 21 21 VarAttribute={}; 22 22 errormsg=''; 23 23 InputVarList={}; 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; 24 if ischar(FieldName),FieldName={FieldName};end 25 check_skipped=zeros(size(FieldName));% default, =1 to mark the variables which can be calculated 26 Operator=cell(size(FieldName)); 27 for 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 32 33 else 33 if isempty(find(strcmp( Operation{ilist},InputVarList)));34 InputVarList=[InputVarList Operation{ilist}];% the variable is added to the listif it is not already in the list34 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 35 36 end 36 Operator{ilist}='';37 37 end 38 38 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 40 40 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 41 55 else 42 56 UName{ilist}=r.UName; … … 45 59 InputVarList=[InputVarList UName{ilist}]; %the variable is added to the list if it is not already in the list 46 60 end 47 if isempty(find(strcmp(r.VName,InputVarList) ));61 if isempty(find(strcmp(r.VName,InputVarList), 1)); 48 62 InputVarList=[InputVarList VName{ilist}]; %the variable is added to the list if it is not already in the list 49 63 end … … 58 72 end 59 73 end 60 for ilist=1:numel( Operation)74 for ilist=1:numel(FieldName) 61 75 if ~check_skipped(ilist) 62 76 nbvar=numel(ListVarName); … … 85 99 ListVarName{nbvar+1}='norm'; 86 100 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'; 87 109 otherwise 88 if ~isempty( Operation{ilist})110 if ~isempty(FieldName{ilist}) 89 111 if exist('XI','var') 90 VarVal{nbvar+1}=F.( Operation{ilist})(XI,YI);112 VarVal{nbvar+1}=F.(FieldName{ilist})(XI,YI); 91 113 else 92 VarVal{nbvar+1}= Data.( Operation{ilist});114 VarVal{nbvar+1}= Data.(FieldName{ilist}); 93 115 end 94 ListVarName{nbvar+1}= Operation{ilist};116 ListVarName{nbvar+1}=FieldName{ilist}; 95 117 VarAttribute{nbvar+1}.Role='scalar'; 96 118 end … … 99 121 end 100 122 % put an error flag to indicate NaN data 101 if exist('XI','var') 123 if exist('XI','var')&&~isempty(VarVal) 102 124 nbvar=numel(ListVarName); 103 125 ListVarName{nbvar+1}='FF';
Note: See TracChangeset
for help on using the changeset viewer.