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