Ignore:
Timestamp:
Mar 20, 2026, 4:42:36 PM (22 hours ago)
Author:
sommeria
Message:

bug repaired for civ image rescale

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plot_field.m

    r1195 r1200  
    178178AxeData=get(haxes,'UserData');
    179179
    180 %% 2D plots
    181 if isempty(index_2D)
    182     plot_plane([],[],haxes,[]);%removes images or vector plots in the absence of 2D field plot
     180%% 2D plots
     181if isempty(index_2D) %removes images or vector plots in the absence of 2D field plot
     182    hima=findobj(haxes,'Tag','ima');% search existing image in the current axes
     183    if  ishandle(hima)
     184        delete(hima)
     185    end
     186    hvec=findobj(haxes,'Tag','vel');% search existing vectors in the current axes
     187    if ~isempty(hvec)
     188        delete(hvec);
     189    end
    183190else  %plot 2D field
    184 %     if ~exist('PosColorbar','var'),PosColorbar=[];end;
     191    %     if ~exist('PosColorbar','var'),PosColorbar=[];end;
    185192    [~,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellInfo(index_2D),haxes,PlotParamOut);
    186193    AxeData.NbDim=2;
    187     if testzoomaxes && isempty(errormsg)
    188         [zoomaxes,PlotParamOut,~,errormsg]=plot_plane(Data,CellInfo(index_2D),zoomaxes,PlotParamOut);
     194    if testzoomaxes && isempty(errormsg)% updater the plot on the attached axis
     195        PlotParamZoom=PlotParamOut;
     196        PlotParamZoom.Axes.CheckFixLimits=1;
     197        XLim=get(zoomaxes,'XLim');
     198        YLim=get(zoomaxes,'YLim');
     199        PlotParamZoom.Axes.MinX=XLim(1);
     200        PlotParamZoom.Axes.MaxX=XLim(2);
     201        PlotParamZoom.Axes.MinY=YLim(1);
     202        PlotParamZoom.Axes.MaxY=YLim(2);
     203        PlotParamZoom.Axes.CheckZoomFig=0;
     204        [zoomaxes,~,~,errormsg]=plot_plane(Data,CellInfo(index_2D),zoomaxes,PlotParamZoom);
    189205        AxeData.ZoomAxes=zoomaxes;
    190206    end
     
    275291% --- plot 0D fields: display data values without plot
    276292%------------------------------------------------------------------
    277 function errormsg=plot_text(FieldData,CellInfo,htext)
     293function errormsg=plot_text(FieldData,CellInfo,~)
    278294
    279295errormsg='';
    280 txt_cell={};
    281 Data={};
    282296VarIndex=[];
    283 for icell=1:length(CellInfo)
    284    
     297for icell=1:length(CellInfo)   
    285298    % select types of  variables to be projected
    286299    ListProj={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'};
     
    617630        end
    618631        Val=pdf2stat(x,pdf_val);
    619         Column=mat2cell(Val,ones(13,1),ones(1,size(Val,2)));
     632        Column=num2cell(Val,ones(13,1),ones(1,size(Val,2)));
    620633        if size(Val,2)==1%single component
    621634            TitleBar={VarName};
     
    665678test_ima=0; %default: test for image or map plot
    666679test_vec=0; %default: test for vector plots
    667 test_black=0;
    668680test_false=0;
    669681test_C=0;
     
    681693    ivar_Y=CellInfo{icell}.CoordIndex(end-1); % defines (unique)index for the variable representing unstructured y coordinate (default =[])
    682694    ivar_C=[];
    683     if isfield(CellInfo{icell},'VarIndex_scalar')
    684         ivar_C=[ivar_C CellInfo{icell}.VarIndex_scalar];
    685     end
    686     if isfield(CellInfo{icell},'VarIndex_image')
    687         ivar_C=[ivar_C CellInfo{icell}.VarIndex_image];
    688     end
    689     if isfield(CellInfo{icell},'VarIndex_color')
    690         ivar_C=[ivar_C CellInfo{icell}.VarIndex_color];
    691     end
    692     if isfield(CellInfo{icell},'VarIndex_ancillary')
    693         ivar_C=[ivar_C CellInfo{icell}.VarIndex_ancillary];
    694     end
    695     if numel(ivar_C)>1
    696         errormsg= 'error in plot_field: too many scalar inputs';
    697         return
    698     end
     695    ListFields=fields(CellInfo{icell});
     696    for ilist=1:numel(ListFields)
     697        if ismember(ListFields{ilist},{'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_ancillary'})
     698            ivar_C=CellInfo{icell}.(ListFields{ilist});
     699            break % do not allow more than one scalar
     700        end
     701    end
    699702    ivar_F=[];
    700703    if isfield(CellInfo{icell},'VarIndex_warnflag')
     
    734737            end
    735738            if isfield(PlotParam.Vectors,'ColorScalar') && ~isempty(PlotParam.Vectors.ColorScalar)
    736                 [VarVal,ListVarName,VarAttribute,errormsg]=calc_field_interp([],Data,PlotParam.Vectors.ColorScalar);
     739                [VarVal,~,~,errormsg]=calc_field_interp([],Data,PlotParam.Vectors.ColorScalar);
    737740                if ~isempty(VarVal)
    738741                    vec_C=reshape(VarVal{1},1,numel(VarVal{1}));
     
    745748                if ~isempty(ivar_F)%~(isfield(PlotParam.Vectors,'HideWarning')&& isequal(PlotParam.Vectors.HideWarning,1))
    746749                    vec_F=Data.(Data.ListVarName{ivar_F}); % warning flags for  dubious vectors
    747                     vec_FF(find(vec_F==-2))=1;%set alseFlag to 1(edge of the search box)
     750                    vec_FF(vec_F==-2)=1;%set FalseFlag to 1(edge of the search box)
    748751                end
    749752            end
     
    790793                DCoord_y_min=min(DCoord_y);
    791794                DCoord_y_max=max(DCoord_y);
    792                 if sign(DCoord_y_min)~=sign(DCoord_y_max);% =1 for increasing values, 0 otherwise
     795                if sign(DCoord_y_min)~=sign(DCoord_y_max)% =1 for increasing values, 0 otherwise
    793796                    errormsg=['errror in plot_field.m: non monotonic dimension variable ' YName ];
    794797                    return
     
    877880    if isfield(PlotParam.Scalar,'CheckBW') && ~isempty(PlotParam.Scalar.CheckBW)
    878881        ColorMap=PlotParam.Scalar.CheckBW;%PlotParam.Scalar.CheckBW is char string indicating the colormap type
    879     elseif ((siz==2) && (isa(A,'uint8')|| isa(A,'uint16')))% non color images represented in gray scale by default
     882    elseif siz==2 && (isa(A,'uint8')||isa(A,'uint16'))% non color images represented in gray scale by default
    880883        ColorMap='grayscale';
    881884    end
     
    962965        % fill the space between contours if opacity is undefined or =1
    963966        if isequal(Opacity,1)
    964             [var,hcontour]=contour(haxes,x_cont,y_cont,A,cont_pos);% determine all contours
     967            [~,hcontour]=contour(haxes,x_cont,y_cont,A,cont_pos);% determine all contours
    965968            set(hcontour,'Fill','on')% fill the space between contours
    966969            set(hcontour,'LineStyle','none')
    967970            hold on
    968971        end
    969         [var_p,hcontour_p]=contour(haxes,x_cont,y_cont,A,cont_pos_plus,'k-');% draw the contours for positive values as solid lines
     972        [~,~]=contour(haxes,x_cont,y_cont,A,cont_pos_plus,'k-');% draw the contours for positive values as solid lines
    970973        hold on
    971         [var_m,hcontour_m]=contour(haxes,x_cont,y_cont,A,cont_pos_min,'--');% draw the contours for negative values as dashed lines
     974        [~,hcontour_m]=contour(haxes,x_cont,y_cont,A,cont_pos_min,'--');% draw the contours for negative values as dashed lines
    972975        if isequal(Opacity,1)
    973976            set(hcontour_m,'LineColor',[1 1 1])% draw negative contours in white (better visibility in dark background)
     
    977980       
    978981        %determine the color scale and map
    979         caxis([abscontmin abscontmax])
     982        clim([abscontmin abscontmax])
    980983        if strcmp(ColorMap,'grayscale')
    981984            vec=linspace(0,1,(abscontmax-abscontmin)/interval);%define a greyscale colormap with steps interval
     
    10051008                    A=uint8(255*double(A)/double(MaxA));
    10061009                end
    1007 %             otherwise
    1008 %                 colormap(ColorMap);
     1010            otherwise
     1011                colormap(ColorMap);
    10091012        end
    10101013 
     
    10881091            end
    10891092            if length(PosColorbar)==4
    1090                 set(hcol,'Position',PosColorbar)
     1093                % set(hcol,'Units','pixel')
     1094                 set(hcol,'Position',PosColorbar)
    10911095            end
    10921096            %YTick=0;%default
     
    11261130    end
    11271131else%no scalar plot
    1128     if ~isempty(hima) && ishandle(hima)
     1132    if ishandle(hima)
    11291133        delete(hima)
    11301134    end
    1131     if ~isempty(PosColorbar) && ~isempty(hcol)&& ishandle(hcol)
     1135    if ~isempty(PosColorbar) && ~isempty(hcol) && ishandle(hcol)
    11321136        delete(hcol)
    11331137    end
     
    12171221    % take flags into account: add flag colors to the list of colors
    12181222    nbcolor=size(colorlist,1);
    1219 % % %     if test_black
    1220 % % %        nbcolor=nbcolor+1;
    1221 % % %        colorlist(nbcolor,:)=[0 0 0]; %add black to the list of colors
    1222 % % %        if ~isempty(ivar_FF_vec)
    1223 % % %             col_vec(vec_F~=1 & vec_F~=0 & vec_FF==0)=nbcolor;
    1224 % % %        else
    1225 % % %             col_vec(vec_F~=1 & vec_F~=0)=nbcolor;
    1226 % % %        end
    1227 % % %     end
    12281223    nbcolor=nbcolor+1;
    12291224    if ~isempty(ivar_FF_vec)
     
    13491344    arrowplus=rot*[uc;vc];
    13501345    arrowmoins=rot'*[uc;vc];
    1351     % x1=xc+uc/2-arrowplus(1,:);
    1352     % x2=xc+uc/2;
    1353     % x3=xc+uc/2-arrowmoins(1,:);
    1354     % y1=yc+vc/2-arrowplus(2,:);
    1355     % y2=yc+vc/2;
    1356     % y3=yc+vc/2-arrowmoins(2,:);
    13571346    x1=xc+uc-arrowplus(1,:);
    13581347    x2=xc+uc;
     
    13661355    matyar=reshape(matyar,1,4*n(2));
    13671356    %draw the line or modify the existing ones
    1368 %     tri=reshape(1:3*length(uc),3,[])';   
    13691357    isn=isnan(colorlist(icolor,:));%test if color NaN
    13701358    if 2*icolor > sizh(1) %if icolor exceeds the number of existing ones
     
    14321420diffy=diff(vec_Y); %difference dy=vec_Y(i+1)-vec_Y(i)
    14331421index=find(diffy);% find the indices of vec_Y after wich a change of horizontal line occurs(diffy non zero)
    1434 if isempty(index); msgbox_uvmat('ERROR','points aligned along abscissa in proj_grid.m'); return; end;%points aligned% A FAIRE: switch to line plot.
     1422if isempty(index); msgbox_uvmat('ERROR','points aligned along abscissa in proj_grid.m'); return; end%points aligned% A FAIRE: switch to line plot.
    14351423diff2=diff(diffy(index));% diff2 = fluctuations of the detected vertical grid mesh dy
    14361424if max(abs(diff2))>0.001*abs(diffy(index(1))) % if max(diff2) is larger than 1/1000 of the first mesh dy
     
    14891477    end
    14901478    if test_interp==1%if we interpolate
    1491         xi=[rangx(1):(rangx(2)-rangx(1))/(npxy(2)-1):rangx(2)];
    1492         yi=[rangy(1):(rangy(2)-rangy(1))/(npxy(1)-1):rangy(2)];
     1479        xi=rangx(1):(rangx(2)-rangx(1))/(npxy(2)-1):rangx(2);
     1480        yi=rangy(1):(rangy(2)-rangy(1))/(npxy(1)-1):rangy(2);
    14931481        [XI,YI]=meshgrid(xi,yi);
    14941482        A = interp2(X,Y,B,XI,YI);
Note: See TracChangeset for help on using the changeset viewer.