Changeset 530 for trunk/src/plot_field.m
- Timestamp:
- Aug 27, 2012, 4:38:41 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plot_field.m
r525 r530 110 110 index_1D=[]; 111 111 index_0D=[]; 112 errormsg=check_field_structure(Data);113 if ~isempty(errormsg)114 msgbox_uvmat('ERROR',['input of plot_field/check_field_structure: ' errormsg])115 display(['input of plot_field/check_field_structure: ' errormsg])116 return117 end112 % errormsg=check_field_structure(Data); 113 % if ~isempty(errormsg) 114 % msgbox_uvmat('ERROR',['input of plot_field/check_field_structure: ' errormsg]) 115 % display(['input of plot_field/check_field_structure: ' errormsg]) 116 % return 117 % end 118 118 % check the cells of fields : 119 [CellVarIndex,NbDim,VarType,errormsg]=find_field_cells(Data); 119 [CellInfo,NbDimArray,errormsg]=find_field_cells(Data); 120 %[CellVarIndex,NbDim,CoordType,VarRole,errormsg]=find_field_cells(Data); 120 121 if ~isempty(errormsg) 121 122 msgbox_uvmat('ERROR',['input of plot_field/find_field_cells: ' errormsg]); 122 123 return 123 124 end 124 index_2D=find(NbDim==2);%find 2D fields 125 index_3D=find(NbDim >2,1);125 126 index_3D=find(NbDimArray>2,1); 126 127 if ~isempty(index_3D) 127 if isfield(Data,'NbDim')&& isequal(Data.NbDim,2)128 index_2D=[index_2D index_3D];129 else128 % if isfield(Data,'NbDimArray')&& isequal(Data.NbDimArray,2) 129 % index_2D=[index_2D index_3D]; 130 % else 130 131 msgbox_uvmat('ERROR','volume plot not implemented yet'); 131 132 return 132 end 133 end 134 index_1D=find(NbDim==1&~cellfun(@isempty,VarType)); 135 index_0D=find(NbDim==0); 133 % end 134 end 135 index_2D=find(NbDimArray==2);%find 2D fields 136 index_1D=find(NbDimArray==1); 137 index_0D=find(NbDimArray==0); 136 138 %remove coordinates variables from 1D plot 137 139 % if ~isempty(index_2D) 138 140 % for ivar=1:length(index_1D) 139 % if isequal(CellVarIndex{index_1D(ivar)},Var Type{index_1D(ivar)}.coord)141 % if isequal(CellVarIndex{index_1D(ivar)},VarRole{index_1D(ivar)}.coord) 140 142 % index_1D(ivar)=0; 141 143 % end … … 192 194 %% 2D plots 193 195 if isempty(index_2D) 194 plot_plane([],[], [],haxes);%removes images or vector plots in the absence of 2D field plot196 plot_plane([],[],haxes);%removes images or vector plots in the absence of 2D field plot 195 197 else %plot 2D field 196 [tild,PlotParamOut,PlotType,errormsg]=plot_plane(Data,Cell VarIndex(index_2D),VarType(index_2D),haxes,PlotParam,PosColorbar);198 [tild,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellInfo(index_2D),haxes,PlotParam,PosColorbar); 197 199 AxeData.NbDim=2; 198 200 if testzoomaxes && isempty(errormsg) 199 [zoomaxes,PlotParamOut,tild,errormsg]=plot_plane(Data,Cell VarIndex(index_2D),VarType(index_2D),zoomaxes,PlotParam,PosColorbar);201 [zoomaxes,PlotParamOut,tild,errormsg]=plot_plane(Data,CellInfo(index_2D),zoomaxes,PlotParam,PosColorbar); 200 202 AxeData.ZoomAxes=zoomaxes; 201 203 end … … 205 207 if isempty(index_1D) 206 208 if ~isempty(haxes) 207 plot_profile([],[], [],haxes);%removes usual praphs y vs x in the absence of 1D field plot209 plot_profile([],[],haxes);%removes usual praphs y vs x in the absence of 1D field plot 208 210 end 209 211 else %plot 1D field (usual graph y vs x) 210 Coordinates=plot_profile(Data,Cell VarIndex(index_1D),VarType(index_1D),haxes,PlotParam.Coordinates);%212 Coordinates=plot_profile(Data,CellInfo(index_1D),haxes,PlotParam.Coordinates);% 211 213 if testzoomaxes 212 [zoomaxes,Coordinates]=plot_profile(Data,Cell VarIndex(index_1D),VarType(index_1D),zoomaxes,PlotParam.Coordinates);214 [zoomaxes,Coordinates]=plot_profile(Data,CellInfo(index_1D),zoomaxes,PlotParam.Coordinates); 213 215 AxeData.ZoomAxes=zoomaxes; 214 216 end … … 233 235 end 234 236 else 235 [errormsg]=plot_text(Data,Cell VarIndex(index_0D),VarType(index_0D),htext);237 [errormsg]=plot_text(Data,CellInfo(index_0D),htext); 236 238 end 237 239 end … … 262 264 263 265 %------------------------------------------------------------------- 264 function errormsg=plot_text(FieldData,Cell VarIndex,VarTypeCell,htext)266 function errormsg=plot_text(FieldData,CellInfo,htext) 265 267 %------------------------------------------------------------------- 266 268 errormsg=[]; 267 269 txt_cell={}; 268 270 Data={}; 269 for icell=1:length(Cell VarIndex)270 VarIndex=Cell VarIndex{icell};% indices of the selected variables in the list data.ListVarName271 for icell=1:length(CellInfo) 272 VarIndex=CellInfo{icell}.VarIndex;% indices of the selected variables in the list data.ListVarName 271 273 for ivar=1:length(VarIndex) 272 274 checkancillary=0; … … 303 305 304 306 %------------------------------------------------------------------- 305 function CoordinatesOut=plot_profile(data,Cell VarIndex,VarType,haxes,Coordinates)307 function CoordinatesOut=plot_profile(data,CellInfo,haxes,Coordinates) 306 308 %------------------------------------------------------------------- 307 309 … … 341 343 342 344 %loop on input fields 343 for icell=1:length(CellVarIndex) 344 if isempty(VarType{icell})% coordiante variable 345 continue 346 end 347 VarIndex=CellVarIndex{icell};% indices of the selected variables in the list data.ListVarName 348 if ~isempty(VarType{icell}.coord_x) 349 coord_x_index=VarType{icell}.coord_x; 350 else 351 coord_x_index_cell=VarType{icell}.coord(1); 352 if isequal(coord_x_index_cell,0) 353 continue % the cell has no abscissa, skip it 354 end 355 coord_x_index=coord_x_index_cell; 356 end 345 for icell=1:numel(CellInfo) 346 VarIndex=CellInfo{icell}.VarIndex;% indices of the selected variables in the list data.ListVarName 347 coord_x_index=CellInfo{icell}.CoordIndex; 357 348 testplot=ones(size(data.ListVarName));%default test for plotted variables 358 349 coord_x_name{icell}=data.ListVarName{coord_x_index}; … … 369 360 XMax(icell)=max(coord_x{icell}); 370 361 testplot(coord_x_index)=0; 371 if ~isempty(VarType{icell}.ancillary')372 testplot( VarType{icell}.ancillary)=0;373 end 374 if ~isempty(VarType{icell}.warnflag')375 testplot( VarType{icell}.warnflag)=0;362 if isfield(CellInfo{icell},'VarIndex_ancillary') 363 testplot(CellInfo{icell}.VarIndex_ancillary)=0; 364 end 365 if isfield(CellInfo{icell},'VarIndex_warnflag') 366 testplot(CellInfo{icell}.VarIndex_warnflag)=0; 376 367 end 377 368 if isfield(data,'VarAttribute') … … 385 376 end 386 377 end 387 if ~isempty(VarType{icell}.discrete')378 if isfield(CellInfo{icell},'VarIndex_discrete') 388 379 charplot_0='''+'''; 389 380 else … … 507 498 508 499 %------------------------------------------------------------------- 509 function [haxes,PlotParamOut,PlotType,errormsg]=plot_plane(Data,Cell VarIndex,VarTypeCell,haxes,PlotParam,PosColorbar)500 function [haxes,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellInfo,haxes,PlotParam,PosColorbar) 510 501 %------------------------------------------------------------------- 511 502 … … 538 529 YName=''; 539 530 y_units=''; 540 for icell=1: length(CellVarIndex) % length(CellVarIndex) =1 or 2 (from the calling function)541 VarType=VarTypeCell{icell};542 if ~isempty(VarType.coord_tps) %do not plot directly tps data (used for projection only)531 for icell=1:numel(CellInfo) % length(CellVarIndex) =1 or 2 (from the calling function) 532 % VarRole=CellInfo{icell}; 533 if strcmp(CellInfo{icell}.CoordType,'tps') %do not plot directly tps data (used for projection only) 543 534 continue 544 535 end 545 ivar_X=VarType.coord_x; % defines (unique) index for the variable representing unstructured x coordinate (default =[]) 546 ivar_Y=VarType.coord_y; % defines (unique)index for the variable representing unstructured y coordinate (default =[]) 547 ivar_U=VarType.vector_x; % defines (unique) index for the variable representing x vector component (default =[]) 548 ivar_V=VarType.vector_y; % defines (unique) index for the variable representing y vector component (default =[]) 549 ivar_C=[VarType.scalar VarType.image VarType.color VarType.ancillary]; %defines index (indices) for the scalar or ancillary fields 536 ivar_X=CellInfo{icell}.CoordIndex(end); % defines (unique) index for the variable representing unstructured x coordinate (default =[]) 537 ivar_Y=CellInfo{icell}.CoordIndex(end-1); % defines (unique)index for the variable representing unstructured y coordinate (default =[]) 538 ivar_C=[]; 539 if isfield(CellInfo{icell},'VarIndex_scalar') 540 ivar_C=[ivar_C CellInfo{icell}.VarIndex_scalar]; 541 end 542 if isfield(CellInfo{icell},'VarIndex_image') 543 ivar_C=[ivar_C CellInfo{icell}.VarIndex_image]; 544 end 545 if isfield(CellInfo{icell},'VarIndex_color') 546 ivar_C=[ivar_C CellInfo{icell}.VarIndex_color]; 547 end 548 if isfield(CellInfo{icell},'VarIndex_ancillary') 549 ivar_C=[ivar_C CellInfo{icell}.VarIndex_ancillary]; 550 end 550 551 if numel(ivar_C)>1 551 552 errormsg= 'error in plot_field: too many scalar inputs'; 552 553 return 553 554 end 554 ivar_F=VarType.warnflag; %defines index (unique) for warning flag variable 555 ivar_FF=VarType.errorflag; %defines index (unique) for error flag variable 556 ind_coord=find(VarType.coord); 557 if numel(ind_coord)==2 558 VarType.coord=VarType.coord(ind_coord); 559 end 560 if ~isempty(ivar_U) && ~isempty(ivar_V)% vector components detected 555 ivar_F=[]; 556 if isfield(CellInfo{icell},'VarIndex_warnflag') 557 ivar_F=CellInfo{icell}.VarIndex_warnflag; %defines index (unique) for warning flag variable 558 end 559 ivar_FF=[]; 560 if isfield(CellInfo{icell},'VarIndex_errorflag') 561 ivar_FF=CellInfo{icell}.VarIndex_errorflag; %defines index (unique) for error flag variable 562 end 563 if isfield(CellInfo{icell},'VarIndex_vector_x')&&isfield(CellInfo{icell},'VarIndex_vector_y') % vector components detected 561 564 if test_vec 562 565 errormsg='error in plot_field: attempt to plot two vector fields: to get the difference project on a plane with mode interp'; … … 564 567 else 565 568 test_vec=1; 566 vec_U=Data.(Data.ListVarName{ ivar_U});567 vec_V=Data.(Data.ListVarName{ ivar_V});568 if ~isempty(ivar_X) && ~isempty(ivar_Y)%2D field with unstructured coordinates569 XName=Data.ListVarName{ ivar_X};570 YName=Data.ListVarName{ ivar_Y};569 vec_U=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_x}); 570 vec_V=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_y}); 571 if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates 572 XName=Data.ListVarName{CellInfo{icell}.CoordIndex(end)}; 573 YName=Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 571 574 vec_X=reshape(Data.(XName),[],1); %transform vectors in column matlab vectors 572 575 vec_Y=reshape(Data.(YName),[],1); 573 elseif numel(VarType.coord)==2 && ~isequal(VarType.coord,[0 0]);%coordinates defines by dimension variables574 y=Data.(Data.ListVarName{ VarType.coord(1)});575 x=Data.(Data.ListVarName{ VarType.coord(2)});576 elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates 577 y=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)}); 578 x=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end)}); 576 579 if numel(y)==2 % y defined by first and last values on aregular mesh 577 580 y=linspace(y(1),y(2),size(vec_U,1)); … … 581 584 end 582 585 [vec_X,vec_Y]=meshgrid(x,y); 583 else584 errormsg='error in plot_field: invalid coordinate definition for vector field';585 return586 586 end 587 587 if isfield(PlotParam.Vectors,'ColorScalar') && ~isempty(PlotParam.Vectors.ColorScalar) 588 588 [VarVal,ListVarName,VarAttribute,errormsg]=calc_field_interp([],Data,PlotParam.Vectors.ColorScalar); 589 % if ~isempty(ivar_C) 590 %vec_C=Data.(Data.ListVarName{ivar_C}); 591 if ~isempty(VarVal) 592 vec_C=reshape(VarVal{1},1,numel(VarVal{1})); 593 test_C=1; 594 end 589 if ~isempty(VarVal) 590 vec_C=reshape(VarVal{1},1,numel(VarVal{1})); 591 test_C=1; 592 end 595 593 end 596 594 if ~isempty(ivar_F)%~(isfield(PlotParam.Vectors,'HideWarning')&& isequal(PlotParam.Vectors.HideWarning,1)) … … 613 611 return 614 612 end 615 eval(['A=squeeze(Data.' Data.ListVarName{ivar_C} ');']);% scalar represented as color image613 A=squeeze(Data.(Data.ListVarName{ivar_C}));% scalar represented as color image 616 614 test_ima=1; 617 if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates (then ivar_X and ivar_Y not empty)615 if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates 618 616 A=reshape(A,1,[]); 619 617 XName=Data.ListVarName{ivar_X}; … … 630 628 end 631 629 end 632 elseif numel(VarType.coord)==2 %structured coordinates 633 XName=Data.ListVarName{VarType.coord(2)}; 634 YName=Data.ListVarName{VarType.coord(1)}; 635 eval(['AY=Data.' Data.ListVarName{VarType.coord(1)} ';']) 636 eval(['AX=Data.' Data.ListVarName{VarType.coord(2)} ';']) 630 elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates 631 YName=Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 632 AY=Data.(YName); 633 AX=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end)}); 637 634 test_interp_X=0; %default, regularly meshed X coordinate 638 635 test_interp_Y=0; %default, regularly meshed Y coordinate 639 636 if isfield(Data,'VarAttribute') 640 if numel(Data.VarAttribute)>= VarType.coord(2) && isfield(Data.VarAttribute{VarType.coord(2)},'units')641 x_units=Data.VarAttribute{ VarType.coord(2)}.units;642 end 643 if numel(Data.VarAttribute)>= VarType.coord(1) && isfield(Data.VarAttribute{VarType.coord(1)},'units')644 y_units=Data.VarAttribute{ VarType.coord(1)}.units;637 if numel(Data.VarAttribute)>=CellInfo{icell}.CoordIndex(end) && isfield(Data.VarAttribute{CellInfo{icell}.CoordIndex(end)},'units') 638 x_units=Data.VarAttribute{CellInfo{icell}.CoordIndex(end)}.units; 639 end 640 if numel(Data.VarAttribute)>=CellInfo{icell}.CoordIndex(end-1) && isfield(Data.VarAttribute{CellInfo{icell}.CoordIndex(end-1)},'units') 641 y_units=Data.VarAttribute{CellInfo{icell}.CoordIndex(end-1)}.units; 645 642 end 646 643 end … … 650 647 DAY_max=max(DAY); 651 648 if sign(DAY_min)~=sign(DAY_max);% =1 for increasing values, 0 otherwise 652 errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{Var Type.coord(1)} ];649 errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarRole.coord(1)} ]; 653 650 return 654 651 end … … 660 657 DAX_max=max(DAX); 661 658 if sign(DAX_min)~=sign(DAX_max);% =1 for increasing values, 0 otherwise 662 errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{Var Type.coord(2)} ];659 errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarRole.coord(2)} ]; 663 660 return 664 661 end … … 687 684 AX=[AX(1) AX(end)];% keep only the lower and upper bounds for image represnetation 688 685 AY=[AY(1) AY(end)]; 689 else690 errormsg='error in plot_field: invalid coordinate definition ';691 return686 % else 687 % errormsg='error in plot_field: invalid coordinate definition '; 688 % return 692 689 end 693 690 end
Note: See TracChangeset
for help on using the changeset viewer.