Changeset 866 for trunk/src/proj_field.m
- Timestamp:
- Feb 8, 2015, 7:26:02 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/proj_field.m
r864 r866 120 120 end 121 121 122 % %% take the difference of projected input fields if relevant 123 % [CellInfo,NbDim,errormsg]=find_field_cells(ProjData); 124 % ind_remove=zeros(size(ProjData.ListVarName)); 125 % ivar=[]; 126 % ivar_1=[]; 127 % for icell=1:numel(CellInfo) 128 % if ~isempty(CellInfo{icell}) 129 % % if two scalar are in the same cell 130 % if isfield(CellInfo{icell},'VarIndex_scalar') && numel(CellInfo{icell}.VarIndex_scalar)==2 && ProjData.VarAttribute{CellInfo{icell}.VarIndex_scalar(2)}.CheckSub; 131 % ivar=[ivar CellInfo{icell}.VarIndex_scalar(1)]; 132 % ivar_1=[ivar_1 CellInfo{icell}.VarIndex_scalar(2)]; 133 % end 134 % % if two vector u components are in the same cell 135 % if isfield(CellInfo{icell},'VarIndex_vector_x') && numel(CellInfo{icell}.VarIndex_vector_x)==2 && ProjData.VarAttribute{CellInfo{icell}.VarIndex_vector_x(2)}.CheckSub; 136 % ivar=[ivar CellInfo{icell}.VarIndex_vector_x(1)]; 137 % ivar_1=[ivar_1 CellInfo{icell}.VarIndex_vector_x(2)]; 138 % end 139 % % if two vector v components are in the same cell 140 % if isfield(CellInfo{icell},'VarIndex_vector_y') && numel(CellInfo{icell}.VarIndex_vector_y)==2 && ProjData.VarAttribute{CellInfo{icell}.VarIndex_vector_y(2)}.CheckSub; 141 % ivar=[ivar CellInfo{icell}.VarIndex_vector_y(1)]; 142 % ivar_1=[ivar_1 CellInfo{icell}.VarIndex_vector_y(2)]; 143 % end 144 % end 145 % end 146 % % subtract fields if relevant 147 % for imod=1:numel(ivar) 148 % VarName=ProjData.ListVarName{ivar(imod)}; 149 % VarName_1=ProjData.ListVarName{ivar_1(imod)}; 150 % ProjData.(VarName)=double(ProjData.(VarName))-double(ProjData.(VarName_1)); 151 % ind_remove(ivar_1(imod))=1; 152 % end 153 % ProjData.ListVarName(find(ind_remove))=[]; 154 % ProjData.VarDimName(find(ind_remove))=[]; 155 % ProjData.VarAttribute(find(ind_remove))=[]; 156 122 157 %----------------------------------------------------------------- 123 158 %project on a set of points … … 387 422 XName=FieldData.ListVarName{ivar_X}; 388 423 YName=FieldData.ListVarName{ivar_Y}; 389 coord_x=FieldData.( XName);390 coord_y=FieldData.( YName);424 coord_x=FieldData.(FieldData.ListVarName{ivar_X}); 425 coord_y=FieldData.(FieldData.ListVarName{ivar_Y}); 391 426 % image or 2D matrix 392 427 case 'grid' %case of structured coordinates … … 584 619 costheta=cos(theta(isegment)); 585 620 sintheta=sin(theta(isegment)); 586 % XIsegment=LineCoord(isegment,1)+DX_edge*costheta:DX*costheta:LineCoord(isegment+1,1));587 % YIsegment=(LineCoord(isegment,2)+DX_edge*sintheta:DX*sintheta:LineCoord(isegment+1,2));621 % XIsegment=LineCoord(isegment,1)+DX_edge*costheta:DX*costheta:LineCoord(isegment+1,1)); 622 % YIsegment=(LineCoord(isegment,2)+DX_edge*sintheta:DX*sintheta:LineCoord(isegment+1,2)); 588 623 NbInterval=floor((dlength(isegment)-DX_edge)/DX); 589 624 LastX=DX_edge+DX*NbInterval; … … 618 653 ProjData.ListVarName={}; 619 654 ProjData.VarDimName={}; 655 check_abscissa=0; 620 656 for icell=1:length(CellInfo) 621 657 % list of variable types to be projected … … 631 667 %% identify vector components 632 668 testU=isfield(CellInfo{icell},'VarIndex_vector_x') &&isfield(CellInfo{icell},'VarIndex_vector_y') ;% test for vectors 633 % if testU634 % UName=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x};635 % VName=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y};636 % vector_x=FieldData.(UName);637 % vector_y=FieldData.(VName);638 % end669 % if testU 670 % UName=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x}; 671 % VName=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y}; 672 % vector_x=FieldData.(UName); 673 % vector_y=FieldData.(VName); 674 % end 639 675 %identify error flag 640 676 errorflag=0; %default, no error flag … … 654 690 %case of unstructured coordinates 655 691 case 'scattered' 656 XName= FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)}; 657 YName= FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 658 coord_x=FieldData.(XName); 659 coord_y=FieldData.(YName); 660 ProjData.ListVarName=[ProjData.ListVarName {XName}]; 661 ProjData.VarDimName=[ProjData.VarDimName {XName}]; 662 nbvar=numel(ProjData.ListVarName); 663 ProjData.VarAttribute{nbvar}.long_name='abscissa along line'; 692 % XName= FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)}; 693 % YName= FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 694 coord_x=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)}); 695 coord_y=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)}); 696 664 697 if isequal(ProjMode,'projection') 665 698 if width==0 … … 667 700 return 668 701 end 702 ProjData.ListVarName=[ProjData.ListVarName {FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)}}]; 703 ProjData.VarDimName=[ProjData.VarDimName {FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)}}]; 704 nbvar=numel(ProjData.ListVarName); 705 ProjData.VarAttribute{nbvar}.long_name='abscissa along line'; 669 706 % select the (non false) input data located in the band of projection 670 707 flagsel=(errorflag==0) & ((coord_y -yinf(1))*(xinf(2)-xinf(1))>(coord_x-xinf(1))*(yinf(2)-yinf(1))) ... … … 678 715 Xproj=(coord_x-ObjectData.Coord(1,1))*costheta + (coord_y-ObjectData.Coord(1,2))*sintheta; %projection on the line 679 716 [Xproj,indsort]=sort(Xproj);% sort points by increasing absissa along the projection line 680 ProjData.( XName)=Xproj;717 ProjData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)})=Xproj; 681 718 for ivar=1:numel(VarIndex) 682 719 ProjData.(VarName{ivar})=FieldData.(VarName{ivar})(flagsel);% restrict vrtibles to the projection band 683 720 ProjData.(VarName{ivar})=ProjData.(VarName{ivar})(indsort);% sort by absissa 684 721 ProjData.ListVarName=[ProjData.ListVarName VarName{ivar}]; 685 ProjData.VarDimName=[ProjData.VarDimName { XName}];722 ProjData.VarDimName=[ProjData.VarDimName {FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)}}]; 686 723 ProjData.VarAttribute{nbvar+ivar}=FieldData.VarAttribute{VarIndex(ivar)};%reproduce var attribute 687 724 if isfield(ProjData.VarAttribute{nbvar+ivar},'Role') … … 695 732 end 696 733 elseif isequal(ProjMode,'interp_lin') %filtering %linear interpolation: 734 if ~check_abscissa 735 XName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)}; 736 ProjData.ListVarName=[ProjData.ListVarName {XName}]; 737 ProjData.VarDimName=[ProjData.VarDimName {XName}]; 738 nbvar=numel(ProjData.ListVarName); 739 ProjData.VarAttribute{nbvar}.long_name='abscissa along line'; 740 check_abscissa=1; % define abcissa only once 741 end 697 742 if ~isequal(errorflag,0) 698 743 VarName_FF=FieldData.ListVarName{CellInfo{icell}.VarIndex_errorflag}; … … 704 749 FieldData.(VarName)=FieldData.(VarName)(indsel); 705 750 end 706 end 751 end 707 752 [ProjVar,ListFieldProj,VarAttribute,errormsg]=calc_field_interp([coord_x coord_y],FieldData,CellInfo{icell}.FieldName,XI,YI); 708 753 ProjData.X=Xproj; 754 nbvar=numel(ProjData.ListVarName); 709 755 ProjData.ListVarName=[ProjData.ListVarName ListFieldProj]; 710 756 ProjData.VarAttribute=[ProjData.VarAttribute VarAttribute]; … … 713 759 if isfield(VarAttribute{ivar},'Role') 714 760 if strcmp(VarAttribute{ivar}.Role,'vector_x'); 715 ivar_U=ivar ;761 ivar_U=ivar+nbvar; 716 762 elseif strcmp(VarAttribute{ivar}.Role,'vector_y'); 717 ivar_V=ivar ;763 ivar_V=ivar+nbvar; 718 764 end 719 765 end … … 741 787 if isfield(VarAttribute{ivar},'Role') 742 788 if strcmp(VarAttribute{ivar}.Role,'vector_x'); 743 ivar_U=ivar ;789 ivar_U=ivar+nbvar; 744 790 elseif strcmp(VarAttribute{ivar}.Role,'vector_y'); 745 ivar_V=ivar ;791 ivar_V=ivar+nbvar; 746 792 end 747 793 end … … 861 907 end 862 908 end 863 end 909 end 864 910 if ~isempty(ivar_U) && ~isempty(ivar_V) 865 vector_x =ProjData.(ProjData.ListVarName{nbvar+ivar_U}); 866 ProjData.(ProjData.ListVarName{nbvar+ivar_U}) =cos(theta)*vector_x+sin(theta)*ProjData.(ProjData.ListVarName{nbvar+ivar_V}); 867 ProjData.(ProjData.ListVarName{nbvar+ivar_V}) =-sin(theta)*vector_x+cos(theta)*ProjData.(ProjData.ListVarName{nbvar+ivar_V}); 868 end 869 911 vector_x =ProjData.(ProjData.ListVarName{ivar_U}); 912 ProjData.(ProjData.ListVarName{ivar_U}) =cos(theta)*vector_x+sin(theta)*ProjData.(ProjData.ListVarName{ivar_V}); 913 ProjData.(ProjData.ListVarName{ivar_V}) =-sin(theta)*vector_x+cos(theta)*ProjData.(ProjData.ListVarName{ivar_V}); 914 end 870 915 end 871 916 … … 1230 1275 1231 1276 if isfield(CellInfo{icell},'CheckSub') && CellInfo{icell}.CheckSub && ~isempty(vector_x_proj) 1232 ProjData.(ListVarName{vector_x_proj})=ProjData.(ListVarName{vector_x_proj})-VarVal{1}; 1233 ProjData.(ListVarName{vector_y_proj})=ProjData.(ListVarName{vector_y_proj})-VarVal{2}; 1277 ProjData.(FieldData.ListVarName{vector_x_proj})=ProjData.(FieldData.ListVarName{vector_x_proj})-VarVal{1}; 1278 ProjData.(FieldData.ListVarName{vector_y_proj})=ProjData.(FieldData.ListVarName{vector_y_proj})-VarVal{2}; 1279 ListVarName={};% no new variable 1280 VarAttribute={}; 1234 1281 else 1235 1282 VarDimName=cell(size(ListVarName)); … … 1243 1290 end 1244 1291 end 1292 vector_x_proj=CellInfo{icell}.VarIndex_vector_x; %preserve for next cell 1293 vector_y_proj=CellInfo{icell}.VarIndex_vector_y; %preserve for next cell 1245 1294 end 1246 1295 … … 1491 1540 ListVarName=[ListVarName VarName]; 1492 1541 VarAttribute{length(ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes 1493 eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz1542 ProjData.(VarName)=squeeze(FieldData.(VarName)(iz,:,:));% select the z index iz 1494 1543 %TODO : do a vertical average for a thick plane 1495 1544 if test_interp(2) || test_interp(3) 1496 eval(['ProjData.' VarName '=interp2(Coord{3},Coord{2},ProjData.' VarName ',Coord_x,Coord_y'');'])1545 ProjData.(VarName)=interp2(Coord{3},Coord{2},ProjData.(VarName),Coord_x,Coord_y); 1497 1546 end 1498 1547 end … … 1535 1584 if ~isempty(ivar_W) 1536 1585 WName=FieldData.ListVarName{ivar_W}; 1537 eval(['ProjData.' VName '=ProjData.' VName '+ ProjData.' WName '*sin(Theta);'])%1538 eval(['ProjData.' WName '=NormVec_X*ProjData.' UName '+ NormVec_Y*ProjData.' VName '+ NormVec_Z* ProjData.' WName ';']);1586 ProjData.(VName)=ProjData.(VName)+ ProjData.(WName)*sin(Theta);% 1587 ProjData.(WName)=NormVec_X*ProjData.(UName)+ NormVec_Y*ProjData.(VName)+ NormVec_Z* ProjData.(WName); 1539 1588 end 1540 1589 end
Note: See TracChangeset
for help on using the changeset viewer.