source: trunk/src/calc_tps.m @ 516

Last change on this file since 516 was 516, checked in by sommeria, 12 years ago

various bug corrections

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