[515] | 1 |
|
---|
[517] | 2 | %'calc_field': defines fields (velocity, vort, div...) from civ data and calculate them
|
---|
[515] | 3 | %---------------------------------------------------------------------
|
---|
| 4 | % [DataOut,VarAttribute,errormsg]=calc_field_interp(Coord_tps,NbSites,SubRange,FieldVar,Operation,Coord_interp)
|
---|
| 5 | %
|
---|
| 6 | % OUTPUT:
|
---|
| 7 | % DataOut: structure representing the output fields
|
---|
| 8 | %
|
---|
| 9 | % 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
|
---|
| 16 |
|
---|
[517] | 17 | function [VarVal,ListVarName,VarAttribute,errormsg]=calc_field_interp(Coord,Data,Operation,XI,YI)
|
---|
[515] | 18 |
|
---|
| 19 | VarVal=[];
|
---|
| 20 | ListVarName={};
|
---|
| 21 | VarAttribute={};
|
---|
| 22 | errormsg='';
|
---|
[517] | 23 | InputVarList={};
|
---|
| 24 | if ischar(Operation),Operation={Operation};end
|
---|
| 25 | for ilist=1:numel(Operation)
|
---|
| 26 | r=regexp(Operation{ilist},'(?<Operator>(^vec|^norm))\((?<UName>.+),(?<VName>.+)\)$','names');
|
---|
| 27 | if isempty(r) % the operation is the variable
|
---|
| 28 | if isempty(find(strcmp(Operation{ilist},InputVarList)));
|
---|
| 29 | InputVarList=[InputVarList Operation{ilist}];
|
---|
| 30 | end
|
---|
| 31 | Operator{ilist}='';
|
---|
| 32 | else
|
---|
| 33 | UName{ilist}=r.UName;
|
---|
| 34 | VName{ilist}=r.VName;
|
---|
| 35 | if isempty(find(strcmp(r.UName,InputVarList)));
|
---|
| 36 | InputVarList=[InputVarList UName{ilist}];
|
---|
| 37 | end
|
---|
| 38 | if isempty(find(strcmp(r.VName,InputVarList)));
|
---|
| 39 | InputVarList=[InputVarList VName{ilist}];
|
---|
| 40 | end
|
---|
| 41 | Operator{ilist}=r.Operator;
|
---|
[515] | 42 | end
|
---|
| 43 | end
|
---|
[517] | 44 | %create interpolator for linear interpolation
|
---|
| 45 | if exist('XI','var')
|
---|
| 46 | for ilist=1:numel(InputVarList)
|
---|
| 47 | F.(InputVarList{ilist})=TriScatteredInterp(Coord,Data.(InputVarList{ilist}),'linear');
|
---|
| 48 | end
|
---|
[515] | 49 | end
|
---|
[517] | 50 | for ilist=1:numel(Operation)
|
---|
[515] | 51 | nbvar=numel(ListVarName);
|
---|
[517] | 52 | switch Operator{ilist}
|
---|
| 53 | case 'vec'
|
---|
| 54 | if exist('XI','var')
|
---|
| 55 | VarVal{nbvar+1}=F.(UName{ilist})(XI,YI);
|
---|
| 56 | VarVal{nbvar+2}=F.(VName{ilist})(XI,YI);
|
---|
| 57 | else
|
---|
| 58 | VarVal{nbvar+1}=Data.(UName{ilist});
|
---|
| 59 | VarVal{nbvar+2}=Data.(VName{ilist});
|
---|
| 60 | end
|
---|
| 61 | ListVarName{nbvar+1}=UName{ilist};
|
---|
| 62 | ListVarName{nbvar+2}=VName{ilist};
|
---|
[515] | 63 | VarAttribute{nbvar+1}.Role='vector_x';
|
---|
| 64 | VarAttribute{nbvar+2}.Role='vector_y';
|
---|
[517] | 65 | % case 'U'
|
---|
| 66 | % VarVal{nbvar+1}=F_u(XI,YI);
|
---|
| 67 | % ListVarName{nbvar+1}='U';
|
---|
| 68 | % VarAttribute{nbvar+1}.Role='scalar';
|
---|
| 69 | % case 'V'
|
---|
| 70 | % VarVal{nbvar+1}=F_v(XI,YI);
|
---|
| 71 | % ListVarName{nbvar+1}='V';
|
---|
| 72 | % VarAttribute{nbvar+1}.Role='scalar';
|
---|
| 73 | case 'norm'
|
---|
| 74 | if exist('XI','var')
|
---|
| 75 | U2=F.(UName{ilist})(XI,YI).*F.(UName{ilist})(XI,YI);
|
---|
| 76 | V2=F.(VName{ilist})(XI,YI).*F.(VName{ilist})(XI,YI);
|
---|
| 77 | else
|
---|
| 78 | U2=Data.(UName{ilist}).*Data.(UName{ilist});
|
---|
| 79 | V2=Data.(VName{ilist}).*Data.(VName{ilist});
|
---|
| 80 | end
|
---|
| 81 | VarVal{nbvar+1}=sqrt(U2+V2);
|
---|
| 82 | ListVarName{nbvar+1}='norm';
|
---|
[515] | 83 | VarAttribute{nbvar+1}.Role='scalar';
|
---|
[517] | 84 | otherwise
|
---|
| 85 | if ~isempty(Operation{ilist})
|
---|
| 86 | if exist('XI','var')
|
---|
| 87 | VarVal{nbvar+1}=F.(Operation{ilist})(XI,YI);
|
---|
| 88 | else
|
---|
| 89 | VarVal{nbvar+1}= Data.(Operation{ilist});
|
---|
| 90 | end
|
---|
| 91 | ListVarName{nbvar+1}=Operation{ilist};
|
---|
| 92 | VarAttribute{nbvar+1}.Role='scalar';
|
---|
| 93 | end
|
---|
[515] | 94 | end
|
---|
| 95 | end
|
---|
[517] | 96 | % put an error flag to indicate NaN data
|
---|
| 97 | if exist('XI','var')
|
---|
[515] | 98 | nbvar=numel(ListVarName);
|
---|
| 99 | ListVarName{nbvar+1}='FF';
|
---|
| 100 | VarVal{nbvar+1}=isnan(VarVal{nbvar});
|
---|
| 101 | VarAttribute{nbvar+1}.Role='errorflag';
|
---|
[517] | 102 | end
|
---|
[515] | 103 |
|
---|
| 104 | % Attr_FF.Role='errorflag';
|
---|
| 105 | % VarAttribute=[VarAttribute {Attr_FF}];
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 |
|
---|