1 | function DataOut=calc_tps(DataIn,checkall) |
---|
2 | DataOut=DataIn;%default |
---|
3 | SubDomain=1000; %default, estimated nbre of vectors in a subdomain used for tps |
---|
4 | if isfield(DataIn,'SubDomain') |
---|
5 | SubDomain=DataIn.SubDomain;% |
---|
6 | end |
---|
7 | %[CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_cells(DataIn); |
---|
8 | [CellInfo,NbDimArray,errormsg]=find_field_cells(DataIn); |
---|
9 | nbtps=0; |
---|
10 | for icell=1:numel(CellInfo); |
---|
11 | %VarType=VarTypeCell{icell}; |
---|
12 | if NbDimArray(icell)>=2 && strcmp(CellInfo{icell}.CoordType,'scattered')%'&& ~isempty(VarType.coord_x) |
---|
13 | nbtps=nbtps+1; |
---|
14 | X=DataIn.(DataIn.ListVarName{CellInfo{icell}.CoordIndex(end)}); |
---|
15 | Y=DataIn.(DataIn.ListVarName{CellInfo{icell}.CoordIndex(end-1)}); |
---|
16 | if isfield(CellInfo{icell},'VarIndex_vector_x')&&isfield(CellInfo{icell},'VarIndex_vector_y') |
---|
17 | Attr=DataIn.VarAttribute{CellInfo{icell}.VarIndex_vector_x}; |
---|
18 | if ~isfield(Attr,'VarIndex_tps')&& (checkall || (isfield(Attr,'FieldRequest')&&strcmp(Attr.FieldRequest,'interp_tps'))) |
---|
19 | U=DataIn.(DataIn.ListVarName{CellInfo{icell}.VarIndex_vector_x}); |
---|
20 | V=DataIn.(DataIn.ListVarName{CellInfo{icell}.VarIndex_vector_y}); |
---|
21 | else |
---|
22 | continue |
---|
23 | end |
---|
24 | end |
---|
25 | if isfield(CellInfo{icell},'VarIndex_errorflag') |
---|
26 | FF=DataIn.(DataIn.ListVarName{CellInfo{icell}.VarIndex_errorflag}); |
---|
27 | X=X(FF==0); |
---|
28 | Y=Y(FF==0); |
---|
29 | U=U(FF==0); |
---|
30 | V=V(FF==0); |
---|
31 | end |
---|
32 | if nbtps==1 |
---|
33 | ListNewVar={'SubRange','NbSites','Coord_tps','U_tps','V_tps'}; |
---|
34 | ListNewDim={'nb_tps','nb_subdomain'}; |
---|
35 | DataOut.VarDimName=[DataIn.VarDimName {{'nb_coord','nb_bounds','nb_subdomain'},{'nb_subdomain'},... |
---|
36 | {'nb_tps','nb_coord','nb_subdomain'},{'nb_tps','nb_subdomain'},{'nb_tps','nb_subdomain'}}]; |
---|
37 | else |
---|
38 | ListNewVar={['SubRange_' num2str(nbtps-1)],['NbSites_' num2str(nbtps-1)],['Coord_tps_' num2str(nbtps-1)],['U_tps_' num2str(nbtps-1)] ,['V_tps_' num2str(nbtps-1)]}; |
---|
39 | ListNewDim={['nb_tps_' num2str(nbtps-1)],['nb_subdomain_' num2str(nbtps-1)]}; |
---|
40 | DataOut.VarDimName=[DataIn.VarDimName {{'nb_coord','nb_bounds',ListNewDim{2}},ListNewDim(2),... |
---|
41 | {ListNewDim{1},'nb_coord',ListNewDim{2}},ListNewDim,ListNewDim}]; |
---|
42 | end |
---|
43 | DataOut.ListVarName=[DataIn.ListVarName ListNewVar]; |
---|
44 | |
---|
45 | [DataOut.(ListNewVar{1}),DataOut.(ListNewVar{2}),DataOut.(ListNewVar{3}),DataOut.(ListNewVar{4}),DataOut.(ListNewVar{5})] =... |
---|
46 | filter_tps([X Y],U,V,[],SubDomain,0); |
---|
47 | nbvar=numel(DataIn.ListVarName); |
---|
48 | |
---|
49 | DataOut.VarAttribute{nbvar+3}.Role='coord_tps'; |
---|
50 | DataOut.VarAttribute{nbvar+4}=DataIn.VarAttribute{CellInfo{icell}.VarIndex_vector_x};%reproduce attributes of velocity |
---|
51 | DataOut.VarAttribute{nbvar+4}.Role='vector_x_tps'; |
---|
52 | DataIn.VarAttribute{CellInfo{icell}.VarIndex_vector_x}.VarIndex_tps=nbvar+4;% indicte the correspondance with initial data |
---|
53 | DataOut.VarAttribute{nbvar+5}=DataIn.VarAttribute{CellInfo{icell}.VarIndex_vector_y};%reproduce attributes of velocity |
---|
54 | DataOut.VarAttribute{nbvar+5}.Role='vector_y_tps'; |
---|
55 | if isfield(DataOut,'ListDimName')%cleaning' |
---|
56 | DataOut=rmfield(DataOut,'ListDimName'); |
---|
57 | end |
---|
58 | if isfield(DataOut,'DimValue')%cleaning |
---|
59 | DataOut=rmfield(DataOut,'DimValue'); |
---|
60 | end |
---|
61 | end |
---|
62 | end |
---|