[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
|
---|
[521] | 25 | check_skipped=zeros(size(Operation));
|
---|
| 26 | Operator=cell(size(Operation));
|
---|
[517] | 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
|
---|
[521] | 30 | if ~isfield(Data,Operation{ilist})
|
---|
| 31 | check_skipped(ilist)=1;
|
---|
| 32 | 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
|
---|
| 35 | end
|
---|
| 36 | Operator{ilist}='';
|
---|
[517] | 37 | end
|
---|
| 38 | else
|
---|
[521] | 39 | if ~isfield(Data,r.UName)||~isfield(Data,r.VName)
|
---|
| 40 | check_skipped(ilist)=1;
|
---|
| 41 | else
|
---|
| 42 | UName{ilist}=r.UName;
|
---|
| 43 | VName{ilist}=r.VName;
|
---|
| 44 | if isempty(find(strcmp(r.UName,InputVarList)));
|
---|
| 45 | InputVarList=[InputVarList UName{ilist}]; %the variable is added to the list if it is not already in the list
|
---|
| 46 | end
|
---|
| 47 | if isempty(find(strcmp(r.VName,InputVarList)));
|
---|
| 48 | InputVarList=[InputVarList VName{ilist}]; %the variable is added to the list if it is not already in the list
|
---|
| 49 | end
|
---|
| 50 | Operator{ilist}=r.Operator;
|
---|
[517] | 51 | end
|
---|
[515] | 52 | end
|
---|
| 53 | end
|
---|
[517] | 54 | %create interpolator for linear interpolation
|
---|
| 55 | if exist('XI','var')
|
---|
| 56 | for ilist=1:numel(InputVarList)
|
---|
| 57 | F.(InputVarList{ilist})=TriScatteredInterp(Coord,Data.(InputVarList{ilist}),'linear');
|
---|
| 58 | end
|
---|
[515] | 59 | end
|
---|
[517] | 60 | for ilist=1:numel(Operation)
|
---|
[521] | 61 | if ~check_skipped(ilist)
|
---|
[533] | 62 | nbvar=numel(ListVarName);
|
---|
| 63 | switch Operator{ilist}
|
---|
| 64 | case 'vec'
|
---|
[517] | 65 | if exist('XI','var')
|
---|
[533] | 66 | VarVal{nbvar+1}=F.(UName{ilist})(XI,YI);
|
---|
| 67 | VarVal{nbvar+2}=F.(VName{ilist})(XI,YI);
|
---|
[517] | 68 | else
|
---|
[533] | 69 | VarVal{nbvar+1}=Data.(UName{ilist});
|
---|
| 70 | VarVal{nbvar+2}=Data.(VName{ilist});
|
---|
[517] | 71 | end
|
---|
[533] | 72 | ListVarName{nbvar+1}=UName{ilist};
|
---|
| 73 | ListVarName{nbvar+2}=VName{ilist};
|
---|
| 74 | VarAttribute{nbvar+1}.Role='vector_x';
|
---|
| 75 | VarAttribute{nbvar+2}.Role='vector_y';
|
---|
| 76 | case 'norm'
|
---|
| 77 | if exist('XI','var')
|
---|
| 78 | U2=F.(UName{ilist})(XI,YI).*F.(UName{ilist})(XI,YI);
|
---|
| 79 | V2=F.(VName{ilist})(XI,YI).*F.(VName{ilist})(XI,YI);
|
---|
| 80 | else
|
---|
| 81 | U2=Data.(UName{ilist}).*Data.(UName{ilist});
|
---|
| 82 | V2=Data.(VName{ilist}).*Data.(VName{ilist});
|
---|
| 83 | end
|
---|
| 84 | VarVal{nbvar+1}=sqrt(U2+V2);
|
---|
| 85 | ListVarName{nbvar+1}='norm';
|
---|
[517] | 86 | VarAttribute{nbvar+1}.Role='scalar';
|
---|
[533] | 87 | otherwise
|
---|
| 88 | if ~isempty(Operation{ilist})
|
---|
| 89 | if exist('XI','var')
|
---|
| 90 | VarVal{nbvar+1}=F.(Operation{ilist})(XI,YI);
|
---|
| 91 | else
|
---|
| 92 | VarVal{nbvar+1}= Data.(Operation{ilist});
|
---|
| 93 | end
|
---|
| 94 | ListVarName{nbvar+1}=Operation{ilist};
|
---|
| 95 | VarAttribute{nbvar+1}.Role='scalar';
|
---|
| 96 | end
|
---|
| 97 | end
|
---|
[515] | 98 | end
|
---|
| 99 | end
|
---|
[517] | 100 | % put an error flag to indicate NaN data
|
---|
| 101 | if exist('XI','var')
|
---|
[533] | 102 | nbvar=numel(ListVarName);
|
---|
| 103 | ListVarName{nbvar+1}='FF';
|
---|
| 104 | VarVal{nbvar+1}=isnan(VarVal{nbvar});
|
---|
| 105 | VarAttribute{nbvar+1}.Role='errorflag';
|
---|
[517] | 106 | end
|
---|
[515] | 107 |
|
---|
| 108 | % Attr_FF.Role='errorflag';
|
---|
| 109 | % VarAttribute=[VarAttribute {Attr_FF}];
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 |
|
---|