Changeset 674 for trunk/src/plot_field.m
- Timestamp:
- Aug 23, 2013, 2:56:17 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plot_field.m
r652 r674 545 545 function [haxes,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellInfo,haxes,PlotParam,PosColorbar) 546 546 %------------------------------------------------------------------- 547 547 PlotType='plane'; 548 548 grid(haxes, 'off')% remove grid (possibly remaining from other graphs) 549 549 550 %default plotting parameters 550 PlotType='plane';%default551 % if ~exist('PlotParam','var')552 % PlotParam=[];553 % end554 555 551 if ~isfield(PlotParam,'Scalar') 556 552 PlotParam.Scalar=[]; … … 559 555 PlotParam.Vectors=[]; 560 556 end 561 562 557 PlotParamOut=PlotParam;%default 563 hfig=get(haxes,'parent'); 558 errormsg='';%default 559 560 hfig=get(haxes,'parent');%handle of the figure containing the plot axes 564 561 hcol=findobj(hfig,'Tag','Colorbar'); %look for colorbar axes 565 562 hima=findobj(haxes,'Tag','ima');% search existing image in the current axes 566 errormsg='';%default567 563 test_ima=0; %default: test for image or map plot 568 564 test_vec=0; %default: test for vector plots … … 574 570 YName=''; 575 571 y_units=''; 576 for icell=1:numel(CellInfo) % length(CellVarIndex) =1 or 2 (from the calling function) 577 % VarRole=CellInfo{icell}; 572 573 % loop on the input field cells 574 for icell=1:numel(CellInfo) 578 575 if strcmp(CellInfo{icell}.CoordType,'tps') %do not plot directly tps data (used for projection only) 579 576 continue … … 600 597 ivar_F=[]; 601 598 if isfield(CellInfo{icell},'VarIndex_warnflag') 602 ivar_F=CellInfo{icell}.VarIndex_warnflag; %defines index (unique) for warning flag variable 603 end 604 ivar_FF=[]; 605 if isfield(CellInfo{icell},'VarIndex_errorflag') 606 ivar_FF=CellInfo{icell}.VarIndex_errorflag; %defines index (unique) for error flag variable 607 end 599 ivar_F=CellInfo{icell}.VarIndex_warnflag; %defines index (unique) for warning flag variable 600 end 601 ivar_FF_vec=[]; 608 602 if isfield(CellInfo{icell},'VarIndex_vector_x')&&isfield(CellInfo{icell},'VarIndex_vector_y') % vector components detected 609 if test_vec 603 if test_vec% a vector field has been already detected 610 604 errormsg='error in plot_field: attempt to plot two vector fields: to get the difference project on a plane with mode interp'; 611 605 return 612 606 else 613 607 test_vec=1; 614 vec_U=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_x}); 608 if isfield(CellInfo{icell},'VarIndex_errorflag') 609 ivar_FF_vec=CellInfo{icell}.VarIndex_errorflag; %defines index (unique) for error flag variable 610 end 611 vec_U=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_x}); 615 612 vec_V=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_y}); 616 if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates 613 if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates 617 614 XName=Data.ListVarName{CellInfo{icell}.CoordIndex(end)}; 618 615 YName=Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 619 616 vec_X=reshape(Data.(XName),[],1); %transform vectors in column matlab vectors 620 617 vec_Y=reshape(Data.(YName),[],1); 621 elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates 618 elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates 622 619 y=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)}); 623 620 x=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end)}); … … 628 625 x=linspace(x(1),x(2),size(vec_U,2)); 629 626 end 630 [vec_X,vec_Y]=meshgrid(x,y); 627 [vec_X,vec_Y]=meshgrid(x,y); 631 628 end 632 629 if isfield(PlotParam.Vectors,'ColorScalar') && ~isempty(PlotParam.Vectors.ColorScalar) … … 637 634 end 638 635 end 639 if ~isempty(ivar_F)%~(isfield(PlotParam.Vectors,'HideWarning')&& isequal(PlotParam.Vectors.HideWarning,1)) 640 if test_vec 636 if ~isempty(ivar_F)%~(isfield(PlotParam.Vectors,'HideWarning')&& isequal(PlotParam.Vectors.HideWarning,1)) 637 % if test_vec 641 638 vec_F=Data.(Data.ListVarName{ivar_F}); % warning flags for dubious vectors 642 if ~(isfield(PlotParam.Vectors,'CheckHideWarning') && isequal(PlotParam.Vectors.CheckHideWarning,1)) 639 if ~(isfield(PlotParam.Vectors,'CheckHideWarning') && isequal(PlotParam.Vectors.CheckHideWarning,1)) 643 640 test_black=1; 644 641 end 645 end646 end 647 if ~isempty(ivar_FF ) %&& ~test_false648 if test_vec% TODO: deal with FF for structured coordinates649 vec_FF=Data.(Data.ListVarName{ivar_FF }); % flags for false vectors650 end642 % end 643 end 644 if ~isempty(ivar_FF_vec) %&& ~test_false 645 % if test_vec% TODO: deal with FF for structured coordinates 646 vec_FF=Data.(Data.ListVarName{ivar_FF_vec}); % flags for false vectors 647 % end 651 648 end 652 649 end 653 650 elseif ~isempty(ivar_C) %scalar or image 654 651 if test_ima 655 652 errormsg='attempt to plot two scalar fields or images'; 656 653 return 657 654 end 658 655 A=squeeze(Data.(Data.ListVarName{ivar_C}));% scalar represented as color image 659 656 test_ima=1; 660 if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates 657 if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates 661 658 A=reshape(A,1,[]); 662 659 XName=Data.ListVarName{ivar_X}; 663 660 YName=Data.ListVarName{ivar_Y}; 664 eval(['AX=reshape(Data.' XName ',1,[]);']) 661 eval(['AX=reshape(Data.' XName ',1,[]);']) 665 662 eval(['AY=reshape(Data.' YName ',1,[]);']) 666 [A,AX,AY]=proj_grid(AX',AY',A',[],[],'np>256'); % interpolate on a grid 663 [A,AX,AY]=proj_grid(AX',AY',A',[],[],'np>256'); % interpolate on a grid 667 664 if isfield(Data,'VarAttribute') 668 665 if numel(Data.VarAttribute)>=ivar_X && isfield(Data.VarAttribute{ivar_X},'units') … … 672 669 y_units=[' (' Data.VarAttribute{ivar_Y}.units ')']; 673 670 end 674 end 675 elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates 671 end 672 elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates 676 673 YName=Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 677 AY=Data.(YName); 674 AY=Data.(YName); 678 675 AX=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end)}); 679 676 test_interp_X=0; %default, regularly meshed X coordinate … … 686 683 y_units=Data.VarAttribute{CellInfo{icell}.CoordIndex(end-1)}.units; 687 684 end 688 end 685 end 689 686 if numel(AY)>2 690 687 DAY=diff(AY); … … 692 689 DAY_max=max(DAY); 693 690 if sign(DAY_min)~=sign(DAY_max);% =1 for increasing values, 0 otherwise 694 695 696 end 691 errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarRole.coord(1)} ]; 692 return 693 end 697 694 test_interp_Y=(DAY_max-DAY_min)> 0.0001*abs(DAY_max); 698 695 end … … 702 699 DAX_max=max(DAX); 703 700 if sign(DAX_min)~=sign(DAX_max);% =1 for increasing values, 0 otherwise 704 705 706 end 701 errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarRole.coord(2)} ]; 702 return 703 end 707 704 test_interp_X=(DAX_max-DAX_min)> 0.0001*abs(DAX_max); 708 end 709 if test_interp_Y 705 end 706 if test_interp_Y 710 707 npxy(1)=max([256 floor((AY(end)-AY(1))/DAY_min) floor((AY(end)-AY(1))/DAY_max)]); 711 708 yI=linspace(AY(1),AY(end),npxy(1)); 712 709 if ~test_interp_X 713 xI=linspace(AX(1),AX(end),size(A,2));%default 710 xI=linspace(AX(1),AX(end),size(A,2));%default 714 711 AX=xI; 715 712 end 716 713 end 717 if test_interp_X 714 if test_interp_X 718 715 npxy(2)=max([256 floor((AX(end)-AX(1))/DAX_min) floor((AX(end)-AX(1))/DAX_max)]); 719 xI=linspace(AX(1),AX(end),npxy(2)); 716 xI=linspace(AX(1),AX(end),npxy(2)); 720 717 if ~test_interp_Y 721 yI=linspace(AY(1),AY(end),size(A,1));722 AY=yI;723 end 724 end 725 if test_interp_X || test_interp_Y 718 yI=linspace(AY(1),AY(end),size(A,1)); 719 AY=yI; 720 end 721 end 722 if test_interp_X || test_interp_Y 726 723 [AX2D,AY2D]=meshgrid(AX,AY); 727 724 A=interp2(AX2D,AY2D,double(A),xI,yI'); 728 725 end 729 AX=[AX(1) AX(end)];% keep only the lower and upper bounds for image represnetation 726 AX=[AX(1) AX(end)];% keep only the lower and upper bounds for image represnetation 730 727 AY=[AY(1) AY(end)]; 731 % else732 % errormsg='error in plot_field: invalid coordinate definition ';733 % return734 728 end 735 729 end … … 742 736 y_units=Data.CoordUnit; 743 737 end 744 end 745 746 end 738 end 739 end 747 740 748 741 %% image or scalar plot %%%%%%%%%%%%%%%%%%%%%%%%%% … … 1092 1085 vec_F=vec_F(ind_sel); 1093 1086 end 1094 if ~isempty(ivar_FF )1087 if ~isempty(ivar_FF_vec) 1095 1088 vec_FF=vec_FF(ind_sel); 1096 1089 end … … 1106 1099 nbcolor=nbcolor+1; 1107 1100 colorlist(nbcolor,:)=[0 0 0]; %add black to the list of colors 1108 if ~isempty(ivar_FF) 1109 % ind_flag=find(vec_F~=1 & vec_F~=0 & vec_FF==0); %flag warning but not false 1101 if ~isempty(ivar_FF_vec) 1110 1102 col_vec(vec_F~=1 & vec_F~=0 & vec_FF==0)=nbcolor; 1111 1103 else … … 1114 1106 end 1115 1107 nbcolor=nbcolor+1; 1116 if ~isempty(ivar_FF )1108 if ~isempty(ivar_FF_vec) 1117 1109 if isfield(PlotParam.Vectors,'CheckHideFalse') && PlotParam.Vectors.CheckHideFalse==1 1118 1110 colorlist(nbcolor,:)=[NaN NaN NaN];% no plot of false vectors
Note: See TracChangeset
for help on using the changeset viewer.