Changeset 1077 for trunk/src/plot_field.m
- Timestamp:
- Mar 20, 2020, 11:29:01 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plot_field.m
r1071 r1077 102 102 103 103 %% default input and output 104 if ~exist('PlotParam','var'),PlotParam=[];end ;104 if ~exist('PlotParam','var'),PlotParam=[];end 105 105 PlotType='text'; %default 106 106 if ~isfield(PlotParam,'Axes') … … 114 114 115 115 %% check input structure 116 % check the cells of fields :117 118 % if ~isfield(PlotParam,'FieldName')119 % index_0D=[];120 % index_1D=1;121 % index_2D=[];%find 2D fields122 % index_3D=[];123 % else124 116 [CellInfo,NbDimArray,errormsg]=find_field_cells(Data); 125 117 if ~isempty(errormsg) … … 363 355 % --- plot 1D fields (usual x,y plots) 364 356 %------------------------------------------------------------------- 365 function PlotParamOut=plot_profile(data,CellInfo,haxes,PlotParam,CheckHold) 357 %INPUT 358 % Data: structure describing the field to plot 359 % (optional) .ListGlobalAttribute: cell listing the names of the global attributes 360 % .Att_1,Att_2... : values of the global attributes 361 % (requested) .ListVarName: list of variable names to select (cell array of char strings {'VarName1', 'VarName2',...} ) 362 % (requested) .VarDimName: list of dimension names for each element of .ListVarName (cell array of string cells) 363 % .VarAttribute: cell of attributes for each element of .ListVarName (cell array of structures of the form VarAtt.key=value) 364 % (requested) .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName 365 % 366 % Variable attribute .Role : 367 % The only variable attribute used for plotting purpose is .Role which can take 368 % the values: 369 % Role = 'coord_x' or 'histo' to label the x coordinate 370 % ='coord_y' or 'discrete' to label the y coordinate, variables labelled as 'discrete' 371 % will be plotted as isolated points while variables labelled as 'coord_y' will be plotted as continuous lines 372 % other variables will not be taken into account for plot_profile 373 374 function PlotParamOut=plot_profile(Data,CellInfo,haxes,PlotParam,CheckHold) 366 375 367 376 %% initialization … … 376 385 legend_str={}; 377 386 378 %% suppress existing plot if empty data379 if isempty( data)387 %% suppress existing plot if empty Data 388 if isempty(Data) 380 389 hplot=findobj(haxes,'tag','plot_line'); 381 390 if ~isempty(hplot) … … 407 416 MinY_cell=[]; 408 417 MaxY_cell=[]; 409 testplot=ones(size( data.ListVarName));%default test for plotted variables418 testplot=ones(size(Data.ListVarName));%default test for plotted variables 410 419 %loop on input fields 411 420 for icell=1:numel(CellInfo) 412 VarIndex=[CellInfo{icell}.YIndex CellInfo{icell}.YIndex_discrete];% indices of the selected variables in the list data.ListVarName421 VarIndex=[CellInfo{icell}.YIndex CellInfo{icell}.YIndex_discrete];% indices of the selected variables in the list Data.ListVarName 413 422 coord_x_index=CellInfo{icell}.XIndex; 414 coord_x_name{icell}= data.ListVarName{coord_x_index};415 coord_x{icell}= data.(data.ListVarName{coord_x_index});%coordinate variable set as coord_x423 coord_x_name{icell}=Data.ListVarName{coord_x_index}; 424 coord_x{icell}=Data.(Data.ListVarName{coord_x_index});%coordinate variable set as coord_x 416 425 if isempty(find(strcmp(coord_x_name{icell},coord_x_name(1:end-1)), 1)) %xtitle not already selected 417 426 xtitle=[xtitle coord_x_name{icell}]; 418 if isfield( data,'VarAttribute')&& numel(data.VarAttribute)>=coord_x_index && isfield(data.VarAttribute{coord_x_index},'units')419 xtitle=[xtitle '(' data.VarAttribute{coord_x_index}.units '), '];427 if isfield(Data,'VarAttribute')&& numel(Data.VarAttribute)>=coord_x_index && isfield(Data.VarAttribute{coord_x_index},'units') 428 xtitle=[xtitle '(' Data.VarAttribute{coord_x_index}.units '), ']; 420 429 else 421 430 xtitle=[xtitle ', ']; … … 432 441 testplot(CellInfo{icell}.VarIndex_warnflag)=0; 433 442 end 434 if isfield( data,'VarAttribute')435 VarAttribute= data.VarAttribute;443 if isfield(Data,'VarAttribute') 444 VarAttribute=Data.VarAttribute; 436 445 for ivar=1:length(VarIndex) 437 446 if length(VarAttribute)>=VarIndex(ivar) && isfield(VarAttribute{VarIndex(ivar)},'long_name') 438 447 plotname{VarIndex(ivar)}=VarAttribute{VarIndex(ivar)}.long_name; 439 448 else 440 plotname{VarIndex(ivar)}= data.ListVarName{VarIndex(ivar)};%name for display in plot A METTRE449 plotname{VarIndex(ivar)}=Data.ListVarName{VarIndex(ivar)};%name for display in plot A METTRE 441 450 end 442 451 end … … 453 462 for ivar=1:length(VarIndex) 454 463 if testplot(VarIndex(ivar)) 455 VarName= data.ListVarName{VarIndex(ivar)};464 VarName=Data.ListVarName{VarIndex(ivar)}; 456 465 nbplot=nbplot+1; 457 466 ytitle=[ytitle VarName]; 458 if isfield( data,'VarAttribute')&& numel(data.VarAttribute)>=VarIndex(ivar) && isfield(data.VarAttribute{VarIndex(ivar)},'units')459 ytitle=[ytitle '(' data.VarAttribute{VarIndex(ivar)}.units '), '];467 if isfield(Data,'VarAttribute')&& numel(Data.VarAttribute)>=VarIndex(ivar) && isfield(Data.VarAttribute{VarIndex(ivar)},'units') 468 ytitle=[ytitle '(' Data.VarAttribute{VarIndex(ivar)}.units '), ']; 460 469 else 461 470 ytitle=[ytitle ', ']; 462 471 end 463 eval([' data.' VarName '=squeeze(data.' VarName ');'])464 MinY(ivar)=min(min( data.(VarName)));465 MaxY(ivar)=max(max( data.(VarName)));466 plotstr=[plotstr 'coord_x{' num2str(icell) '}, data.' VarName ',' charplot_0 ','];467 eval(['nbcomponent2=size( data.' VarName ',2);']);468 eval(['nbcomponent1=size( data.' VarName ',1);']);472 eval(['Data.' VarName '=squeeze(Data.' VarName ');']) 473 MinY(ivar)=min(min(Data.(VarName))); 474 MaxY(ivar)=max(max(Data.(VarName))); 475 plotstr=[plotstr 'coord_x{' num2str(icell) '},Data.' VarName ',' charplot_0 ',']; 476 eval(['nbcomponent2=size(Data.' VarName ',2);']); 477 eval(['nbcomponent1=size(Data.' VarName ',1);']); 469 478 if numel(coord_x{icell})==2 470 479 coord_x{icell}=linspace(coord_x{icell}(1),coord_x{icell}(2),nbcomponent1); … … 521 530 end 522 531 title_str=''; 523 if isfield( data,'filename')524 [Path, title_str, ext]=fileparts( data.filename);532 if isfield(Data,'filename') 533 [Path, title_str, ext]=fileparts(Data.filename); 525 534 title_str=[title_str ext]; 526 535 end 527 if isfield( data,'Action')&&isfield(data.Action,'ActionName')536 if isfield(Data,'Action')&&isfield(Data.Action,'ActionName') 528 537 if ~isequal(title_str,'') 529 538 title_str=[title_str ', ']; 530 539 end 531 title_str=[title_str data.Action.ActionName];540 title_str=[title_str Data.Action.ActionName]; 532 541 end 533 542 htitle=title(title_str); … … 587 596 if isfield(CellInfo{icell},'VarIndex_histo')% case of histogram plot 588 597 TextDisplay=1; 589 VarName= data.ListVarName{CellInfo{icell}.CoordIndex};590 pdf_val= data.(data.ListVarName{CellInfo{icell}.VarIndex_histo});598 VarName=Data.ListVarName{CellInfo{icell}.CoordIndex}; 599 pdf_val=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_histo}); 591 600 x=coord_x{icell}; 592 601 if isrow(x) … … 610 619 end 611 620 end 612 if TextDisplay ;621 if TextDisplay 613 622 disp(TableData); 614 623 PlotParamOut.TableDisplay=TableData;
Note: See TracChangeset
for help on using the changeset viewer.