Changeset 674 for trunk/src/plot_field.m


Ignore:
Timestamp:
Aug 23, 2013, 2:56:17 PM (11 years ago)
Author:
sommeria
Message:

various bugs repaired, in particula timing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plot_field.m

    r652 r674  
    545545function [haxes,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellInfo,haxes,PlotParam,PosColorbar)
    546546%-------------------------------------------------------------------
    547 
     547PlotType='plane';
    548548grid(haxes, 'off')% remove grid (possibly remaining from other graphs)
     549
    549550%default plotting parameters
    550 PlotType='plane';%default
    551 % if ~exist('PlotParam','var')
    552 %     PlotParam=[];
    553 % end
    554 
    555551if ~isfield(PlotParam,'Scalar')
    556552    PlotParam.Scalar=[];
     
    559555    PlotParam.Vectors=[];
    560556end
    561 
    562557PlotParamOut=PlotParam;%default
    563 hfig=get(haxes,'parent');
     558errormsg='';%default
     559
     560hfig=get(haxes,'parent');%handle of the figure containing the plot axes
    564561hcol=findobj(hfig,'Tag','Colorbar'); %look for colorbar axes
    565562hima=findobj(haxes,'Tag','ima');% search existing image in the current axes
    566 errormsg='';%default
    567563test_ima=0; %default: test for image or map plot
    568564test_vec=0; %default: test for vector plots
     
    574570YName='';
    575571y_units='';
    576 for icell=1:numel(CellInfo) % length(CellVarIndex) =1 or 2 (from the calling function)
    577 %     VarRole=CellInfo{icell};
     572
     573% loop on the input field cells
     574for icell=1:numel(CellInfo)
    578575    if strcmp(CellInfo{icell}.CoordType,'tps') %do not plot directly tps data (used for projection only)
    579576        continue
     
    600597    ivar_F=[];
    601598    if isfield(CellInfo{icell},'VarIndex_warnflag')
    602     ivar_F=CellInfo{icell}.VarIndex_warnflag; %defines index (unique) for warning flag variable
    603     end
    604     ivar_FF=[];
    605     if isfield(CellInfo{icell},'VarIndex_errorflag')
    606     ivar_FF=CellInfo{icell}.VarIndex_errorflag; %defines index (unique) for error flag variable
    607     end
     599        ivar_F=CellInfo{icell}.VarIndex_warnflag; %defines index (unique) for warning flag variable
     600    end
     601    ivar_FF_vec=[];
    608602    if isfield(CellInfo{icell},'VarIndex_vector_x')&&isfield(CellInfo{icell},'VarIndex_vector_y') % vector components detected
    609         if test_vec
     603        if test_vec% a vector field has been already detected
    610604            errormsg='error in plot_field: attempt to plot two vector fields: to get the difference project on a plane with mode interp';
    611605            return
    612606        else
    613607            test_vec=1;
    614             vec_U=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_x});
     608            if isfield(CellInfo{icell},'VarIndex_errorflag')
     609                ivar_FF_vec=CellInfo{icell}.VarIndex_errorflag; %defines index (unique) for error flag variable
     610            end
     611            vec_U=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_x});
    615612            vec_V=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_y});
    616             if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates 
     613            if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates
    617614                XName=Data.ListVarName{CellInfo{icell}.CoordIndex(end)};
    618615                YName=Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
    619616                vec_X=reshape(Data.(XName),[],1); %transform vectors in column matlab vectors
    620617                vec_Y=reshape(Data.(YName),[],1);
    621             elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates 
     618            elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates
    622619                y=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)});
    623620                x=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end)});
     
    628625                    x=linspace(x(1),x(2),size(vec_U,2));
    629626                end
    630                 [vec_X,vec_Y]=meshgrid(x,y); 
     627                [vec_X,vec_Y]=meshgrid(x,y);
    631628            end
    632629            if isfield(PlotParam.Vectors,'ColorScalar') && ~isempty(PlotParam.Vectors.ColorScalar)
     
    637634                end
    638635            end
    639             if ~isempty(ivar_F)%~(isfield(PlotParam.Vectors,'HideWarning')&& isequal(PlotParam.Vectors.HideWarning,1)) 
    640                 if test_vec
     636            if ~isempty(ivar_F)%~(isfield(PlotParam.Vectors,'HideWarning')&& isequal(PlotParam.Vectors.HideWarning,1))
     637%                 if test_vec
    641638                    vec_F=Data.(Data.ListVarName{ivar_F}); % warning flags for  dubious vectors
    642                     if  ~(isfield(PlotParam.Vectors,'CheckHideWarning') && isequal(PlotParam.Vectors.CheckHideWarning,1)) 
     639                    if  ~(isfield(PlotParam.Vectors,'CheckHideWarning') && isequal(PlotParam.Vectors.CheckHideWarning,1))
    643640                        test_black=1;
    644641                    end
    645                 end
    646             end
    647             if ~isempty(ivar_FF) %&& ~test_false
    648                 if test_vec% TODO: deal with FF for structured coordinates
    649                     vec_FF=Data.(Data.ListVarName{ivar_FF}); % flags for false vectors
    650                 end
     642%                 end
     643            end
     644            if ~isempty(ivar_FF_vec) %&& ~test_false
     645%                 if test_vec% TODO: deal with FF for structured coordinates
     646                    vec_FF=Data.(Data.ListVarName{ivar_FF_vec}); % flags for false vectors
     647%                 end
    651648            end
    652649        end
    653650    elseif ~isempty(ivar_C) %scalar or image
    654651        if test_ima
    655              errormsg='attempt to plot two scalar fields or images';
     652            errormsg='attempt to plot two scalar fields or images';
    656653            return
    657654        end
    658655        A=squeeze(Data.(Data.ListVarName{ivar_C}));% scalar represented as color image
    659656        test_ima=1;
    660         if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates 
     657        if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates
    661658            A=reshape(A,1,[]);
    662659            XName=Data.ListVarName{ivar_X};
    663660            YName=Data.ListVarName{ivar_Y};
    664             eval(['AX=reshape(Data.' XName ',1,[]);']) 
     661            eval(['AX=reshape(Data.' XName ',1,[]);'])
    665662            eval(['AY=reshape(Data.' YName ',1,[]);'])
    666             [A,AX,AY]=proj_grid(AX',AY',A',[],[],'np>256');  % interpolate on a grid 
     663            [A,AX,AY]=proj_grid(AX',AY',A',[],[],'np>256');  % interpolate on a grid
    667664            if isfield(Data,'VarAttribute')
    668665                if numel(Data.VarAttribute)>=ivar_X && isfield(Data.VarAttribute{ivar_X},'units')
     
    672669                    y_units=[' (' Data.VarAttribute{ivar_Y}.units ')'];
    673670                end
    674             end       
    675         elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates 
     671            end
     672        elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates
    676673            YName=Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
    677             AY=Data.(YName); 
     674            AY=Data.(YName);
    678675            AX=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end)});
    679676            test_interp_X=0; %default, regularly meshed X coordinate
     
    686683                    y_units=Data.VarAttribute{CellInfo{icell}.CoordIndex(end-1)}.units;
    687684                end
    688             end 
     685            end
    689686            if numel(AY)>2
    690687                DAY=diff(AY);
     
    692689                DAY_max=max(DAY);
    693690                if sign(DAY_min)~=sign(DAY_max);% =1 for increasing values, 0 otherwise
    694                      errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarRole.coord(1)} ];
    695                       return
    696                 end 
     691                    errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarRole.coord(1)} ];
     692                    return
     693                end
    697694                test_interp_Y=(DAY_max-DAY_min)> 0.0001*abs(DAY_max);
    698695            end
     
    702699                DAX_max=max(DAX);
    703700                if sign(DAX_min)~=sign(DAX_max);% =1 for increasing values, 0 otherwise
    704                      errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarRole.coord(2)} ];
    705                       return
    706                 end 
     701                    errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarRole.coord(2)} ];
     702                    return
     703                end
    707704                test_interp_X=(DAX_max-DAX_min)> 0.0001*abs(DAX_max);
    708             end 
    709             if test_interp_Y         
     705            end
     706            if test_interp_Y
    710707                npxy(1)=max([256 floor((AY(end)-AY(1))/DAY_min) floor((AY(end)-AY(1))/DAY_max)]);
    711708                yI=linspace(AY(1),AY(end),npxy(1));
    712709                if ~test_interp_X
    713                     xI=linspace(AX(1),AX(end),size(A,2));%default 
     710                    xI=linspace(AX(1),AX(end),size(A,2));%default
    714711                    AX=xI;
    715712                end
    716713            end
    717             if test_interp_X 
     714            if test_interp_X
    718715                npxy(2)=max([256 floor((AX(end)-AX(1))/DAX_min) floor((AX(end)-AX(1))/DAX_max)]);
    719                 xI=linspace(AX(1),AX(end),npxy(2));   
     716                xI=linspace(AX(1),AX(end),npxy(2));
    720717                if ~test_interp_Y
    721                    yI=linspace(AY(1),AY(end),size(A,1));
    722                    AY=yI;
    723                 end
    724             end
    725             if test_interp_X || test_interp_Y               
     718                    yI=linspace(AY(1),AY(end),size(A,1));
     719                    AY=yI;
     720                end
     721            end
     722            if test_interp_X || test_interp_Y
    726723                [AX2D,AY2D]=meshgrid(AX,AY);
    727724                A=interp2(AX2D,AY2D,double(A),xI,yI');
    728725            end
    729             AX=[AX(1) AX(end)];% keep only the lower and upper bounds for image represnetation 
     726            AX=[AX(1) AX(end)];% keep only the lower and upper bounds for image represnetation
    730727            AY=[AY(1) AY(end)];
    731 %         else
    732 %             errormsg='error in plot_field: invalid coordinate definition ';
    733 %             return
    734728        end
    735729    end
     
    742736            y_units=Data.CoordUnit;
    743737        end
    744     end
    745        
    746 end
     738    end   
     739end
    747740
    748741%%   image or scalar plot %%%%%%%%%%%%%%%%%%%%%%%%%%
     
    10921085           vec_F=vec_F(ind_sel);
    10931086        end
    1094         if ~isempty(ivar_FF)
     1087        if ~isempty(ivar_FF_vec)
    10951088           vec_FF=vec_FF(ind_sel);
    10961089        end
     
    11061099       nbcolor=nbcolor+1;
    11071100       colorlist(nbcolor,:)=[0 0 0]; %add black to the list of colors
    1108        if ~isempty(ivar_FF)
    1109           %  ind_flag=find(vec_F~=1 & vec_F~=0 & vec_FF==0);  %flag warning but not false
     1101       if ~isempty(ivar_FF_vec)
    11101102            col_vec(vec_F~=1 & vec_F~=0 & vec_FF==0)=nbcolor;
    11111103       else
     
    11141106    end
    11151107    nbcolor=nbcolor+1;
    1116     if ~isempty(ivar_FF)
     1108    if ~isempty(ivar_FF_vec)
    11171109        if isfield(PlotParam.Vectors,'CheckHideFalse') && PlotParam.Vectors.CheckHideFalse==1
    11181110            colorlist(nbcolor,:)=[NaN NaN NaN];% no plot of false vectors
Note: See TracChangeset for help on using the changeset viewer.