Ignore:
Timestamp:
Mar 20, 2020, 11:29:01 PM (5 years ago)
Author:
sommeria
Message:

various bug repair

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plot_field.m

    r1071 r1077  
    102102
    103103%% default input and output
    104 if ~exist('PlotParam','var'),PlotParam=[];end;
     104if ~exist('PlotParam','var'),PlotParam=[];end
    105105PlotType='text'; %default
    106106if ~isfield(PlotParam,'Axes')
     
    114114
    115115%% 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 fields
    122 %     index_3D=[];
    123 % else
    124116    [CellInfo,NbDimArray,errormsg]=find_field_cells(Data);
    125117    if ~isempty(errormsg)
     
    363355% --- plot 1D fields (usual x,y plots)
    364356%-------------------------------------------------------------------
    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
     374function PlotParamOut=plot_profile(Data,CellInfo,haxes,PlotParam,CheckHold)
    366375
    367376%% initialization
     
    376385legend_str={};
    377386
    378 %% suppress existing plot if empty data
    379 if isempty(data)
     387%% suppress existing plot if empty Data
     388if isempty(Data)
    380389    hplot=findobj(haxes,'tag','plot_line');
    381390    if ~isempty(hplot)
     
    407416MinY_cell=[];
    408417MaxY_cell=[];
    409 testplot=ones(size(data.ListVarName));%default test for plotted variables
     418testplot=ones(size(Data.ListVarName));%default test for plotted variables
    410419%loop on input  fields
    411420for icell=1:numel(CellInfo)
    412     VarIndex=[CellInfo{icell}.YIndex CellInfo{icell}.YIndex_discrete];%  indices of the selected variables in the list data.ListVarName
     421    VarIndex=[CellInfo{icell}.YIndex CellInfo{icell}.YIndex_discrete];%  indices of the selected variables in the list Data.ListVarName
    413422    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_x
     423    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
    416425    if isempty(find(strcmp(coord_x_name{icell},coord_x_name(1:end-1)), 1)) %xtitle not already selected
    417426        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 '), '];
    420429        else
    421430            xtitle=[xtitle ', '];
     
    432441            testplot(CellInfo{icell}.VarIndex_warnflag)=0;
    433442        end
    434         if isfield(data,'VarAttribute')
    435             VarAttribute=data.VarAttribute;
     443        if isfield(Data,'VarAttribute')
     444            VarAttribute=Data.VarAttribute;
    436445            for ivar=1:length(VarIndex)
    437446                if length(VarAttribute)>=VarIndex(ivar) && isfield(VarAttribute{VarIndex(ivar)},'long_name')
    438447                    plotname{VarIndex(ivar)}=VarAttribute{VarIndex(ivar)}.long_name;
    439448                else
    440                     plotname{VarIndex(ivar)}=data.ListVarName{VarIndex(ivar)};%name for display in plot A METTRE
     449                    plotname{VarIndex(ivar)}=Data.ListVarName{VarIndex(ivar)};%name for display in plot A METTRE
    441450                end
    442451            end
     
    453462        for ivar=1:length(VarIndex)
    454463            if testplot(VarIndex(ivar))
    455                 VarName=data.ListVarName{VarIndex(ivar)};
     464                VarName=Data.ListVarName{VarIndex(ivar)};
    456465                nbplot=nbplot+1;
    457466                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 '), '];
    460469                else
    461470                    ytitle=[ytitle ', '];
    462471                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);']);
    469478                if numel(coord_x{icell})==2
    470479                    coord_x{icell}=linspace(coord_x{icell}(1),coord_x{icell}(2),nbcomponent1);
     
    521530    end
    522531    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);
    525534       title_str=[title_str ext];
    526535    end
    527     if isfield(data,'Action')&&isfield(data.Action,'ActionName')
     536    if isfield(Data,'Action')&&isfield(Data.Action,'ActionName')
    528537        if ~isequal(title_str,'')
    529538            title_str=[title_str ', '];
    530539        end
    531         title_str=[title_str data.Action.ActionName];
     540        title_str=[title_str Data.Action.ActionName];
    532541    end
    533542    htitle=title(title_str);
     
    587596    if isfield(CellInfo{icell},'VarIndex_histo')% case of histogram plot
    588597        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});
    591600        x=coord_x{icell};
    592601        if isrow(x)
     
    610619    end
    611620end
    612 if TextDisplay;
     621if TextDisplay
    613622    disp(TableData);
    614623    PlotParamOut.TableDisplay=TableData;
Note: See TracChangeset for help on using the changeset viewer.