Changeset 89 for trunk/src/plot_field.m


Ignore:
Timestamp:
May 20, 2010, 1:48:25 AM (14 years ago)
Author:
sommeria
Message:

many bug corrections and cleaning. Activation of the BW option in uvmat. Improvement of the interaction of get_field with uvmat.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plot_field.m

    r88 r89  
    3131%    The only variable attribute used for plotting purpose is .Role which can take
    3232%    the values
    33         %       Role = 'scalar':  (default) represents a scalar field
    34         %            = 'coord_x', 'coord_y',  'coord_z': represents a separate set of
    35         %                        unstructured coordinate x, y  or z
    36         %            = 'vector': represents a vector field whose number of components
    37         %                is given by the last dimension (called 'nb_dim')
    38         %            = 'vector_x', 'vector_y', 'vector_z'  :represents the x, y or z  component of a vector 
    39         %            = 'warnflag' : provides a warning flag about the quality of data in a 'Field', default=0, no warning
    40         %            = 'errorflag': provides an error flag marking false data,
    41         %                   default=0, no error. Different non zero values can represent different criteria of elimination.
    42 
    43 
     33%       Role = 'scalar':  (default) represents a scalar field
     34%            = 'coord_x', 'coord_y',  'coord_z': represents a separate set of
     35%                        unstructured coordinate x, y  or z
     36%            = 'vector': represents a vector field whose number of components
     37%                is given by the last dimension (called 'nb_dim')
     38%            = 'vector_x', 'vector_y', 'vector_z'  :represents the x, y or z  component of a vector 
     39%            = 'warnflag' : provides a warning flag about the quality of data in a 'Field', default=0, no warning
     40%            = 'errorflag': provides an error flag marking false data,
     41%                   default=0, no error. Different non zero values can represent different criteria of elimination.
     42%
     43%
    4444%         additional elements characterizing the projection object (should not be necessary)--
    4545%            Data.Style : style of projection object
     
    8484% PosColorbar: if not empty, display a colorbar for B&W images
    8585%               imposed position of the colorbar (ex [0.821 0.471 0.019 0.445])
    86 %
     86
    8787%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    8888%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
     
    141141if testnewfig% create a new figure and axes if the plotting axes does not exist
    142142    hfig=figure;
    143     if isfield(Data,'IndexObj')&isfield(Data,'Style')&isfield(Data,'ProjMode')
     143    if isfield(Data,'IndexObj') && isfield(Data,'Style') && isfield(Data,'ProjMode')
    144144        figname=[num2str(Data.IndexObj) '-' Data.Style];
    145145        set(hfig,'Name',figname)
    146146    end
    147     testhandle=0;
    148     if isfield(PlotParam,'text_display_1')& ishandle(PlotParam.text_display_1)
     147%     testhandle=0;
     148    if isfield(PlotParam,'text_display_1') && ishandle(PlotParam.text_display_1)
    149149        set(hfig,'UserData',PlotParam)
    150         testhandle=1;
     150%         testhandle=1;
    151151    end
    152152    set(hfig,'Units','normalized')
     
    160160    hstack=findobj(allchild(0),'Type','figure');%current stack order of figures in matlab
    161161end
    162 if isfield(PlotParam,'text_display_1')& ishandle(PlotParam.text_display_1)
     162if isfield(PlotParam,'text_display_1') && ishandle(PlotParam.text_display_1)
    163163    PlotParam=read_plot_param(PlotParam);   
    164164end
     
    171171
    172172% check the cells of fields :
    173 testnbdim=1;
     173% testnbdim=1;
    174174[CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Data);
    175175
     
    180180end
    181181if ~isfield(Data,'NbDim') %& ~isfield(Data,'Style')%determine the space dimensionb if not defined: choose the kind of plot
    182     [Data.NbDim,imax]=max(NbDim);
     182    [Data.NbDim]=max(NbDim);
    183183end
    184184if isequal(Data.NbDim,0)
     
    207207    msgbox_uvmat('ERROR','volume plot not implemented yet')
    208208    return
    209 else
    210     testnbdim=0;
     209% else
     210%     testnbdim=0;
    211211end
    212212
     
    239239function hdisplay=plot_text(FieldData,hdisplay_in)
    240240%-------------------------------------------------------------------
    241 if exist('hdisplay_in','var') & ishandle(hdisplay_in) & isequal(get(hdisplay_in,'Type'),'uicontrol')
     241if exist('hdisplay_in','var') && ishandle(hdisplay_in) && isequal(get(hdisplay_in,'Type'),'uicontrol')
    242242    hdisplay=hdisplay_in;
    243243else
     
    254254    sizss=size(ss);
    255255    if isnumeric(ss)
    256         if sizss(1)<=1 & length(ss)<5
     256        if sizss(1)<=1 && length(ss)<5
    257257            displ{icell}=num2str(ss);
    258258        else
     
    263263    elseif iscell(ss)
    264264        sizcell=size(ss);
    265         if sizcell(1)==1 & length(sizcell)==2 %line cell
     265        if sizcell(1)==1 && length(sizcell)==2 %line cell
    266266           ssline='{''';
    267267           for icolumn=1:sizcell(2)
    268268               if isnumeric(ss{icolumn})
    269                    if size(ss{icolumn},1)<=1 & length(ss{icolumn})<5
     269                   if size(ss{icolumn},1)<=1 && length(ss{icolumn})<5
    270270                      sscolumn=num2str(ss{icolumn});%line vector
    271271                   else
     
    321321plotstr='hhh=plot(';
    322322textmean={};
    323 abscissa_name='';
     323% abscissa_name='';
    324324coord_x_index=[];
    325325test_newplot=1;
    326326hh=findobj(haxes,'tag','plot_line');
    327 num_curve=numel(hh);
     327% num_curve=numel(hh);
    328328icurve=0;
    329329for icell=1:length(CellVarIndex)
     
    351351    testcoordvar=0;
    352352    charplot_0='''-''';%default
    353     if isfield(data,'ObjectProjMode')& isequal(data.ObjectProjMode,'projection')
     353    if isfield(data,'ObjectProjMode')&& isequal(data.ObjectProjMode,'projection')
    354354        charplot_0='+';
    355355    end
     
    374374        VarAttribute=data.VarAttribute;
    375375        for ivar=1:length(VarIndex)
    376              if length(VarAttribute)>=VarIndex(ivar) & isfield(VarAttribute{VarIndex(ivar)},'long_name')
     376             if length(VarAttribute)>=VarIndex(ivar) && isfield(VarAttribute{VarIndex(ivar)},'long_name')
    377377                 plotname{VarIndex(ivar)}=VarAttribute{VarIndex(ivar)}.long_name;
    378378             else
     
    461461        else
    462462            legend_old=get(hlegend,'String');
    463             if isequal(size(legend_old,1),size(legend_str,1))&~isequal(legend_old,legend_str)
     463            if isequal(size(legend_old,1),size(legend_str,1))&&~isequal(legend_old,legend_str)
    464464                set(hlegend,'String',[legend_old legend_str]);
    465465            end
     
    537537y_units='';
    538538for icell=1:length(CellVarIndex) % length(CellVarIndex) =1 or 2 (from the calling function)
    539 %     VarIndex=CellVarIndex{icell};
    540539    VarType=VarTypeCell{icell};
    541540    ivar_X=VarType.coord_x; % defines (unique) index for the variable representing unstructured x coordinate (default =[])
     
    564563            eval(['vec_U=Data.' Data.ListVarName{ivar_U} ';'])
    565564            eval(['vec_V=Data.' Data.ListVarName{ivar_V} ';'])
     565            'TESTplot'
     566            VarType.coord
    566567            if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates or structured ones (then ivar_X and ivar_Y empty)     
    567568                eval(['vec_X=Data.' Data.ListVarName{ivar_X} ';'])
     
    614615            [A,AX,AY]=proj_grid(AX',AY',A',[],[],'np>256');  % interpolate on a grid 
    615616            if isfield(Data,'VarAttribute')
    616                 if numel(Data.VarAttribute)>=ivar_X & isfield(Data.VarAttribute{ivar_X},'units')
     617                if numel(Data.VarAttribute)>=ivar_X && isfield(Data.VarAttribute{ivar_X},'units')
    617618                    x_units=['(' Data.VarAttribute{ivar_X}.units ')'];
    618619                end
    619                 if numel(Data.VarAttribute)>=ivar_Y & isfield(Data.VarAttribute{ivar_Y},'units')
     620                if numel(Data.VarAttribute)>=ivar_Y && isfield(Data.VarAttribute{ivar_Y},'units')
    620621                    y_units=['(' Data.VarAttribute{ivar_Y}.units ')'];
    621622                end
     
    629630            test_interp_Y=0; %default, regularly meshed Y coordinate
    630631            if isfield(Data,'VarAttribute')
    631                 if numel(Data.VarAttribute)>=VarType.coord(2) & isfield(Data.VarAttribute{VarType.coord(2)},'units')
     632                if numel(Data.VarAttribute)>=VarType.coord(2) && isfield(Data.VarAttribute{VarType.coord(2)},'units')
    632633                    x_units=['(' Data.VarAttribute{VarType.coord(2)}.units ')'];
    633634                end
     
    714715    end
    715716    %set the color map
     717    if isfield(PlotParam.Scalar,'BW')
     718        BW=PlotParam.Scalar.BW; %test for BW gray scale images
     719    else
     720        BW=(siz==2) && (isa(A,'uint8')|| isa(A,'uint16'));% non color images represented in gray scale by default
     721    end
    716722    if siz==2 %for black and white images
    717723        if ~isfield(PlotParam.Scalar,'AutoScal')
     
    729735            MinA=PlotParam.Scalar.MinA; 
    730736        end;
    731         if isequal(PlotParam.Scalar.AutoScal,0)|isempty(PlotParam.Scalar.MaxA)|~isa(PlotParam.Scalar.MaxA,'double') %correct if there is no numerical data in edit box
     737        if isequal(PlotParam.Scalar.AutoScal,0)||isempty(PlotParam.Scalar.MaxA)||~isa(PlotParam.Scalar.MaxA,'double') %correct if there is no numerical data in edit box
    732738            MaxA=double(max(max(A)));
    733739        else
     
    756762            contmin=intercont*floor(min(min(B))/intercont);
    757763            contmax=intercont*ceil(max(max(B))/intercont);
    758             cont_pos_plus=[0:intercont:contmax];
    759             cont_pos_min=[double(contmin):intercont:-intercont];
     764            cont_pos_plus=0:intercont:contmax;
     765            cont_pos_min=double(contmin):intercont:-intercont;
    760766            cont_pos=[cont_pos_min cont_pos_plus];
    761767            sizpx=(AX(end)-AX(1))/(np(2)-1);
    762768            sizpy=(AY(1)-AY(end))/(np(1)-1);
    763769            x_cont=[AX(1):sizpx:AX(end)]; % pixel x coordinates for image display
    764             y_cont=[AY(1):-sizpy:AY(end)]; % pixel x coordinates for image display
     770            y_cont=AY(1):-sizpy:AY(end); % pixel x coordinates for image display
    765771            txt=ver;%version of Matlab
    766772            Release=txt(1).Release;
     
    783789            colormap(map);
    784790        end
    785         if ~isequal(PlotParam.Scalar.Contours,1)       
     791        if ~isequal(PlotParam.Scalar.Contours,1) 
    786792            % rescale the grey levels with min and max, put a grey scale colorbar
    787             if (isfield(PlotParam.Scalar,'BW')& (isequal(PlotParam.Scalar.BW,1))|isa(A,'uint8')| isa(A,'uint16'))%images
     793            if BW
    788794                B=A;
    789795                vec=linspace(0,1,255);%define a linear greyscale colormap
     
    797803    else %color images
    798804        axes(haxes)
    799         B=uint8(A);
     805        if BW
     806            B=uint16(sum(A,3));
     807        else
     808            B=uint8(A);
     809        end
    800810        MinA=0;
    801811        MaxA=255;
     
    846856    test_ima=1;
    847857    %display the colorbar code for B/W images if Poscolorbar not empty
    848     if siz==2 & exist('PosColorbar','var')& ~isempty(PosColorbar)
     858    if siz==2 && exist('PosColorbar','var')&& ~isempty(PosColorbar)
    849859        if isempty(hcol)|~ishandle(hcol)
    850860             hcol=colorbar;%create new colorbar
     
    966976        dy_thresh=max(abs(diffy))/2;
    967977        ind_jump=find(abs(diffy) > dy_thresh); %indices with diff(vec_Y)> max/2, detect change of line
    968         ind_sel=[1:ind_jump(1)];%select the first line
     978        ind_sel=1:ind_jump(1);%select the first line
    969979        for i=2:2:length(ind_jump)-1
    970980            ind_sel=[ind_sel [ind_jump(i)+1:ind_jump(i+1)]];% select the odd lines
     
    11911201    siz=size(ind);
    11921202    if siz(2)<4%if there are less than 4 selected values (4 levels)
    1193         values=[-9:0.5*div:9];
     1203        values=-9:0.5*div:9;
    11941204        ind=find((ord*values-MaxA)<0 & (ord*values-MinA)>0);
    11951205    end
Note: See TracChangeset for help on using the changeset viewer.