source: trunk/src/calc_tps.m @ 575

Last change on this file since 575 was 546, checked in by sommeria, 9 years ago

bugs corrected for tps projection on a grid + pb of colorbar display solved

File size: 3.6 KB
Line 
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
12function DataOut=calc_tps(DataIn,checkall)     
13DataOut=DataIn;%default
14SubDomain=1000; %default, estimated nbre of vectors in a subdomain used for tps
15if isfield(DataIn,'SubDomain')
16    SubDomain=DataIn.SubDomain;%
17end
18[CellInfo,NbDimArray,errormsg]=find_field_cells(DataIn);
19nbtps=0;
20for icell=1:numel(CellInfo);
21    if NbDimArray(icell)>=2 && strcmp(CellInfo{icell}.CoordType,'scattered')%'&& ~isempty(VarType.coord_x)
22        nbtps=nbtps+1;
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};
27            if ~isfield(Attr,'VarIndex_tps')&& (checkall || (isfield(Attr,'FieldRequest')&&strcmp(Attr.FieldRequest,'interp_tps')))               
28                U=DataIn.(DataIn.ListVarName{CellInfo{icell}.VarIndex_vector_x});
29                V=DataIn.(DataIn.ListVarName{CellInfo{icell}.VarIndex_vector_y});
30            else
31                continue
32            end
33        end
34        if isfield(CellInfo{icell},'VarIndex_errorflag')
35            FF=DataIn.(DataIn.ListVarName{CellInfo{icell}.VarIndex_errorflag});
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';
59        DataOut.VarAttribute{nbvar+4}=DataIn.VarAttribute{CellInfo{icell}.VarIndex_vector_x};%reproduce attributes of velocity
60         DataOut.VarAttribute{nbvar+4}.Role='vector_x_tps';
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
63         DataOut.VarAttribute{nbvar+5}.Role='vector_y_tps';
64        if isfield(DataOut,'ListDimName')%cleaning'
65            DataOut=rmfield(DataOut,'ListDimName');
66        end
67        if isfield(DataOut,'DimValue')%cleaning
68            DataOut=rmfield(DataOut,'DimValue');
69        end
70    end
71end
Note: See TracBrowser for help on using the repository browser.