Changeset 388 for trunk/src/plot_field.m


Ignore:
Timestamp:
Apr 6, 2012, 4:37:12 PM (12 years ago)
Author:
sommeria
Message:

several bugs corrected
file indexing, color images...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plot_field.m

    r379 r388  
    9494
    9595function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,PosColorbar)
    96 % use htext: handles of the text edit box (uicontrol)
    97 % introduce PlotParam.Hold: 'on' or 'off' (for curves)
    98 %default output
    99 
     96
     97%% default input and output
    10098if ~exist('PlotParam','var'),PlotParam=[];end;
    10199if ~exist('PosColorbar','var'),PosColorbar=[];end;
     
    107105end
    108106
    109 %% test axes and figure
    110 testnewfig=1;%test to create a new figure (default)
    111 testzoomaxes=0;%test for the existence of a zoom secondary figure attached to the plotting axes
    112 if exist('haxes','var')
    113     if ishandle(haxes)
    114         if isequal(get(haxes,'Type'),'axes')
    115             testnewfig=0;
    116             AxeData=get(haxes,'UserData');
    117             if isfield(AxeData,'ZoomAxes')&& ishandle(AxeData.ZoomAxes)
    118                 if isequal(get(AxeData.ZoomAxes,'Type'),'axes')
    119                     testzoomaxes=1;
    120                     zoomaxes=AxeData.ZoomAxes;
    121                 end
    122             end
    123         end
    124     end
    125 end
    126 
    127 % create a new figure and axes if the plotting axes does not exist
    128 if testnewfig
    129     hfig=figure;
    130     set(hfig,'Units','normalized')
    131     haxes=axes;
    132     set(haxes,'position',[0.13,0.2,0.775,0.73])
    133      PlotParam.NextPlot='add'; %parameter for plot_profile and plot_his
    134 else
    135     hfig=get(haxes,'parent');
    136     set(0,'CurrentFigure',hfig)% the parent of haxes becomes the current figure
    137     set(hfig,'CurrentAxes',haxes)%  haxes becomes the current axes of the parent figure
    138 end
    139 
    140107%% check input structure
    141 if ~isempty(Data)
    142     [Data,errormsg]=check_field_structure(Data);
    143     if ~isempty(errormsg)
    144         msgbox_uvmat('ERROR',['input of plot_field/check_field_structure: ' errormsg])
    145         display(['input of plot_field/check_field_structure:: ' errormsg])
    146         return
    147     end
    148 
    149     %% check the cells of fields :
    150     [CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Data);
    151     if ~isempty(errormsg)
    152         msgbox_uvmat('ERROR',['input of plot_field/find_field_indices: ' errormsg]);
    153         return
    154     end
    155     index_2D=find(NbDim==2,2);%find 2D fields (at most 2)
    156     index_3D=find(NbDim>2,1);
    157     if ~isempty(index_3D)
    158         if isfield(Data,'NbDim')&& isequal(Data.NbDim,2)
    159             index_2D=[index_2D index_3D];
    160         else
     108index_2D=[];
     109index_1D=[];
     110index_0D=[];
     111[Data,errormsg]=check_field_structure(Data);
     112if ~isempty(errormsg)
     113    msgbox_uvmat('ERROR',['input of plot_field/check_field_structure: ' errormsg])
     114    display(['input of plot_field/check_field_structure: ' errormsg])
     115    return
     116end
     117% check the cells of fields :
     118[CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Data);
     119if ~isempty(errormsg)
     120    msgbox_uvmat('ERROR',['input of plot_field/find_field_indices: ' errormsg]);
     121    return
     122end
     123index_2D=find(NbDim==2,2);%find 2D fields (at most 2)
     124index_3D=find(NbDim>2,1);
     125if ~isempty(index_3D)
     126    if isfield(Data,'NbDim')&& isequal(Data.NbDim,2)
     127        index_2D=[index_2D index_3D];
     128    else
    161129        msgbox_uvmat('ERROR','volume plot not implemented yet');
    162130        return
    163         end
    164     end
    165    
    166     index_1D=find(NbDim==1);
    167     index_0D=find(NbDim==0);
     131    end
     132end
     133index_1D=find(NbDim==1);
     134index_0D=find(NbDim==0);
     135%remove coordinates variables from 1D plot
     136if ~isempty(index_2D)
     137    for ivar=1:length(index_1D)
     138        if isequal(CellVarIndex{index_1D(ivar)},VarType{index_1D(ivar)}.coord)
     139            index_1D(ivar)=0;
     140        end
     141    end
     142    index_1D=index_1D(index_1D>0);
     143end
     144
     145%% pure text display
     146if isempty(index_2D) && isempty(index_1D)% no plot
     147    hfig=findobj(allchild(0),'Tag','fig_text_display');
     148    if isempty(hfig)
     149        hfig=figure('name','text_display','Tag','fig_text_display');
     150    end
     151    htext=findobj(hfig,'Tag','text_display');
     152    if isempty(htext)
     153        htext=uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.09 0.9 0.71],'Tag','text_display');
     154    end
     155    if isempty(index_0D)
     156        set(htext,'String',{''})
     157    else
     158        [errormsg]=plot_text(Data,CellVarIndex(index_0D),htext);
     159    end
     160    haxes=[];
     161end
     162
     163%% test axes and figure
     164if ~isempty(index_2D)|| ~isempty(index_1D)%  plot
     165    testnewfig=1;%test to create a new figure (default)
     166    testzoomaxes=0;%test for the existence of a zoom secondary figure attached to the plotting axes
     167    if exist('haxes','var')
     168        if ishandle(haxes)
     169            if isequal(get(haxes,'Type'),'axes')
     170                testnewfig=0;
     171                AxeData=get(haxes,'UserData');
     172                if isfield(AxeData,'ZoomAxes')&& ishandle(AxeData.ZoomAxes)
     173                    if isequal(get(AxeData.ZoomAxes,'Type'),'axes')
     174                        testzoomaxes=1;
     175                        zoomaxes=AxeData.ZoomAxes;
     176                    end
     177                end
     178            end
     179        end
     180    end
     181    % create a new figure and axes if the plotting axes does not exist
     182    if testnewfig
     183        hfig=figure;
     184        set(hfig,'Units','normalized')
     185        haxes=axes;
     186        set(haxes,'position',[0.13,0.2,0.775,0.73])
     187        PlotParam.NextPlot='add'; %parameter for plot_profile and plot_his
     188    else
     189        hfig=get(haxes,'parent');
     190        set(0,'CurrentFigure',hfig)% the parent of haxes becomes the current figure
     191        set(hfig,'CurrentAxes',haxes)%  haxes becomes the current axes of the parent figure
     192    end
    168193   
    169194    %% set axes properties
    170     if isfield(Coordinates,'CheckFixLimits') && isequal(Coordinates.CheckFixLimits,1)  %adjust the graph limits*
     195    if isfield(Coordinates,'CheckFixLimits') && isequal(Coordinates.CheckFixLimits,1)  %adjust the graph limits
    171196        set(haxes,'XLimMode', 'manual')
    172197        set(haxes,'YLimMode', 'manual')
     
    184209        set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio
    185210    end
    186 else
    187     index_2D=[];
    188     index_1D=[];
    189     index_0D=[];
    190 end
    191 
    192 %% plot if the input field is valid
    193 PlotType='text';
    194 errormsg=[];
    195 AxeData=get(haxes,'UserData');
    196 if isempty(index_2D)
    197     plot_plane([],[],[],haxes);%removes images or vector plots if any
    198 else
    199     [xx,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellVarIndex(index_2D),VarType(index_2D),haxes,PlotParam,PosColorbar);
    200     AxeData.NbDim=2;
    201     if testzoomaxes && isempty(errormsg)
    202         [zoomaxes,PlotParamOut,xx,errormsg]=plot_plane(Data,CellVarIndex(index_2D),VarType(index_2D),zoomaxes,PlotParam,PosColorbar);
    203         AxeData.ZoomAxes=zoomaxes;
    204     end
    205     %remove coordinates variables from 1D plot
    206     for ivar=1:length(index_1D)
    207         if isequal(CellVarIndex{index_1D(ivar)},VarType{index_1D(ivar)}.coord)
    208             index_1D(ivar)=0;
    209         end
    210     end
    211     index_1D=find(index_1D);
    212 end
    213 
    214 if isempty(index_1D)
    215     plot_profile([],[],[],haxes);%
    216 else
    217     Coordinates=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),haxes,Coordinates);%
    218     if testzoomaxes
    219         [zoomaxes,Coordinates]=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),zoomaxes,PlotParam.Coordinates);
    220         AxeData.ZoomAxes=zoomaxes;
    221     end
    222     if ~isempty(Coordinates)
    223         PlotParamOut.Coordinates=Coordinates;
    224     end
    225     PlotType='line';
    226 end
    227 htext=findobj(hfig,'Tag','text_display');
    228 if ~isempty(htext)
    229     if isempty(index_0D)
    230         set(htext,'String',{''})
    231     else
    232         [errormsg]=plot_text(Data,CellVarIndex(index_0D),htext);
    233     end
    234 end
    235 
     211    errormsg='';
     212   
     213    %% plot if the input field is valid
     214    AxeData=get(haxes,'UserData');
     215    if isempty(index_2D)
     216        plot_plane([],[],[],haxes);%removes images or vector plots if any
     217    else
     218        [tild,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellVarIndex(index_2D),VarType(index_2D),haxes,PlotParam,PosColorbar);
     219        AxeData.NbDim=2;
     220        if testzoomaxes && isempty(errormsg)
     221            [zoomaxes,PlotParamOut,tild,errormsg]=plot_plane(Data,CellVarIndex(index_2D),VarType(index_2D),zoomaxes,PlotParam,PosColorbar);
     222            AxeData.ZoomAxes=zoomaxes;
     223        end
     224    end
     225    if isempty(index_1D)
     226        if ~isempty(haxes)
     227            plot_profile([],[],[],haxes);%
     228        end
     229    else
     230        Coordinates=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),haxes,Coordinates);%
     231        if testzoomaxes
     232            [zoomaxes,Coordinates]=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),zoomaxes,PlotParam.Coordinates);
     233            AxeData.ZoomAxes=zoomaxes;
     234        end
     235        if ~isempty(Coordinates)
     236            PlotParamOut.Coordinates=Coordinates;
     237        end
     238        PlotType='line';
     239    end
     240    % text display
     241    htext=findobj(hfig,'Tag','text_display');
     242    if ~isempty(htext)
     243        if isempty(index_0D)
     244            set(htext,'String',{''})
     245        else
     246            [errormsg]=plot_text(Data,CellVarIndex(index_0D),htext);
     247        end
     248    end
     249end
     250
     251%% display error message
    236252if ~isempty(errormsg)
    237253    msgbox_uvmat('ERROR', errormsg)
    238254end
    239 if isfield(PlotParamOut,'MinX')
    240     AxeData.RangeX=[PlotParamOut.MinX PlotParamOut.MaxX];%'[PlotParamOut.MinX PlotParamOut.MaxX];
    241     AxeData.RangeY=[PlotParamOut.MinY PlotParamOut.MaxY];%[PlotParamOut.MinY PlotParamOut.MaxY]
    242 end
    243255
    244256%% update the parameters stored in AxeData
    245 set(haxes,'UserData',AxeData)
     257if ishandle(haxes)
     258    if isfield(PlotParamOut,'MinX')
     259        AxeData.RangeX=[PlotParamOut.MinX PlotParamOut.MaxX];%'[PlotParamOut.MinX PlotParamOut.MaxX];
     260        AxeData.RangeY=[PlotParamOut.MinY PlotParamOut.MaxY];%[PlotParamOut.MinY PlotParamOut.MaxY]
     261    end
     262    set(haxes,'UserData',AxeData)
     263end
    246264
    247265%% update the plotted field stored in parent figure
     266
    248267FigData=get(hfig,'UserData');
    249 tagaxes=get(haxes,'tag');
     268if strcmp(get(hfig,'tag'),'view_field')
     269    set(hfig,'UserData',[]); % refresh user data in view_field (set by civ/TestCiv )
     270end
     271tagaxes=get(haxes,'tag');% tag of the current plot axis
    250272if isfield(FigData,tagaxes)
    251     eval(['FigData.' tagaxes '=Data;'])
     273    FigData.(tagaxes)=Data;
    252274    set(hfig,'UserData',FigData)
    253275end
Note: See TracChangeset for help on using the changeset viewer.