Changeset 530 for trunk/src/plot_field.m


Ignore:
Timestamp:
Aug 27, 2012, 4:38:41 PM (9 years ago)
Author:
sommeria
Message:

new conventions for find_field_cells .

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plot_field.m

    r525 r530  
    110110index_1D=[];
    111111index_0D=[];
    112 errormsg=check_field_structure(Data);
    113 if ~isempty(errormsg)
    114     msgbox_uvmat('ERROR',['input of plot_field/check_field_structure: ' errormsg])
    115     display(['input of plot_field/check_field_structure: ' errormsg])
    116     return
    117 end
     112% errormsg=check_field_structure(Data);
     113% if ~isempty(errormsg)
     114%     msgbox_uvmat('ERROR',['input of plot_field/check_field_structure: ' errormsg])
     115%     display(['input of plot_field/check_field_structure: ' errormsg])
     116%     return
     117% end
    118118% check the cells of fields :
    119 [CellVarIndex,NbDim,VarType,errormsg]=find_field_cells(Data);
     119[CellInfo,NbDimArray,errormsg]=find_field_cells(Data);
     120%[CellVarIndex,NbDim,CoordType,VarRole,errormsg]=find_field_cells(Data);
    120121if ~isempty(errormsg)
    121122    msgbox_uvmat('ERROR',['input of plot_field/find_field_cells: ' errormsg]);
    122123    return
    123124end
    124 index_2D=find(NbDim==2);%find 2D fields
    125 index_3D=find(NbDim>2,1);
     125
     126index_3D=find(NbDimArray>2,1);
    126127if ~isempty(index_3D)
    127     if isfield(Data,'NbDim')&& isequal(Data.NbDim,2)
    128         index_2D=[index_2D index_3D];
    129     else
     128%     if isfield(Data,'NbDimArray')&& isequal(Data.NbDimArray,2)
     129%         index_2D=[index_2D index_3D];
     130%     else
    130131        msgbox_uvmat('ERROR','volume plot not implemented yet');
    131132        return
    132     end
    133 end
    134 index_1D=find(NbDim==1&~cellfun(@isempty,VarType));
    135 index_0D=find(NbDim==0);
     133%     end
     134end
     135index_2D=find(NbDimArray==2);%find 2D fields
     136index_1D=find(NbDimArray==1);
     137index_0D=find(NbDimArray==0);
    136138%remove coordinates variables from 1D plot
    137139% if ~isempty(index_2D)
    138140%     for ivar=1:length(index_1D)
    139 %         if isequal(CellVarIndex{index_1D(ivar)},VarType{index_1D(ivar)}.coord)
     141%         if isequal(CellVarIndex{index_1D(ivar)},VarRole{index_1D(ivar)}.coord)
    140142%             index_1D(ivar)=0;
    141143%         end
     
    192194%% 2D plots
    193195if isempty(index_2D)
    194     plot_plane([],[],[],haxes);%removes images or vector plots in the absence of 2D field plot
     196    plot_plane([],[],haxes);%removes images or vector plots in the absence of 2D field plot
    195197else  %plot 2D field
    196     [tild,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellVarIndex(index_2D),VarType(index_2D),haxes,PlotParam,PosColorbar);
     198    [tild,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellInfo(index_2D),haxes,PlotParam,PosColorbar);
    197199    AxeData.NbDim=2;
    198200    if testzoomaxes && isempty(errormsg)
    199         [zoomaxes,PlotParamOut,tild,errormsg]=plot_plane(Data,CellVarIndex(index_2D),VarType(index_2D),zoomaxes,PlotParam,PosColorbar);
     201        [zoomaxes,PlotParamOut,tild,errormsg]=plot_plane(Data,CellInfo(index_2D),zoomaxes,PlotParam,PosColorbar);
    200202        AxeData.ZoomAxes=zoomaxes;
    201203    end
     
    205207if isempty(index_1D)
    206208    if ~isempty(haxes)
    207         plot_profile([],[],[],haxes);%removes usual praphs y vs x in the absence of 1D field plot
     209        plot_profile([],[],haxes);%removes usual praphs y vs x in the absence of 1D field plot
    208210    end
    209211else %plot 1D field (usual graph y vs x)
    210     Coordinates=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),haxes,PlotParam.Coordinates);%
     212    Coordinates=plot_profile(Data,CellInfo(index_1D),haxes,PlotParam.Coordinates);%
    211213    if testzoomaxes
    212         [zoomaxes,Coordinates]=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),zoomaxes,PlotParam.Coordinates);
     214        [zoomaxes,Coordinates]=plot_profile(Data,CellInfo(index_1D),zoomaxes,PlotParam.Coordinates);
    213215        AxeData.ZoomAxes=zoomaxes;
    214216    end
     
    233235        end
    234236    else
    235         [errormsg]=plot_text(Data,CellVarIndex(index_0D),VarType(index_0D),htext);
     237        [errormsg]=plot_text(Data,CellInfo(index_0D),htext);
    236238    end
    237239end
     
    262264
    263265%-------------------------------------------------------------------
    264 function errormsg=plot_text(FieldData,CellVarIndex,VarTypeCell,htext)
     266function errormsg=plot_text(FieldData,CellInfo,htext)
    265267%-------------------------------------------------------------------
    266268errormsg=[];
    267269txt_cell={};
    268270Data={};
    269 for icell=1:length(CellVarIndex)
    270     VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list data.ListVarName
     271for icell=1:length(CellInfo)
     272    VarIndex=CellInfo{icell}.VarIndex;%  indices of the selected variables in the list data.ListVarName
    271273    for ivar=1:length(VarIndex)
    272274        checkancillary=0;
     
    303305
    304306%-------------------------------------------------------------------
    305 function CoordinatesOut=plot_profile(data,CellVarIndex,VarType,haxes,Coordinates)
     307function CoordinatesOut=plot_profile(data,CellInfo,haxes,Coordinates)
    306308%-------------------------------------------------------------------
    307309
     
    341343
    342344%loop on input  fields
    343 for icell=1:length(CellVarIndex)
    344     if isempty(VarType{icell})% coordiante variable
    345         continue
    346     end
    347     VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list data.ListVarName
    348     if ~isempty(VarType{icell}.coord_x)
    349         coord_x_index=VarType{icell}.coord_x;
    350     else
    351         coord_x_index_cell=VarType{icell}.coord(1);
    352         if isequal(coord_x_index_cell,0)
    353              continue  % the cell has no abscissa, skip it
    354         end
    355         coord_x_index=coord_x_index_cell;
    356     end
     345for icell=1:numel(CellInfo)
     346    VarIndex=CellInfo{icell}.VarIndex;%  indices of the selected variables in the list data.ListVarName
     347    coord_x_index=CellInfo{icell}.CoordIndex;
    357348    testplot=ones(size(data.ListVarName));%default test for plotted variables
    358349    coord_x_name{icell}=data.ListVarName{coord_x_index};
     
    369360    XMax(icell)=max(coord_x{icell});
    370361    testplot(coord_x_index)=0;
    371     if ~isempty(VarType{icell}.ancillary')
    372         testplot(VarType{icell}.ancillary)=0;
    373     end
    374     if ~isempty(VarType{icell}.warnflag')
    375         testplot(VarType{icell}.warnflag)=0;
     362    if isfield(CellInfo{icell},'VarIndex_ancillary')
     363        testplot(CellInfo{icell}.VarIndex_ancillary)=0;
     364    end
     365    if isfield(CellInfo{icell},'VarIndex_warnflag')
     366        testplot(CellInfo{icell}.VarIndex_warnflag)=0;
    376367    end
    377368    if isfield(data,'VarAttribute')
     
    385376        end
    386377    end
    387     if ~isempty(VarType{icell}.discrete')
     378    if isfield(CellInfo{icell},'VarIndex_discrete')
    388379        charplot_0='''+''';
    389380    else
     
    507498
    508499%-------------------------------------------------------------------
    509 function [haxes,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellVarIndex,VarTypeCell,haxes,PlotParam,PosColorbar)
     500function [haxes,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellInfo,haxes,PlotParam,PosColorbar)
    510501%-------------------------------------------------------------------
    511502
     
    538529YName='';
    539530y_units='';
    540 for icell=1:length(CellVarIndex) % length(CellVarIndex) =1 or 2 (from the calling function)
    541     VarType=VarTypeCell{icell};
    542     if ~isempty(VarType.coord_tps) %do not plot directly tps data (used for projection only)
     531for icell=1:numel(CellInfo) % length(CellVarIndex) =1 or 2 (from the calling function)
     532%     VarRole=CellInfo{icell};
     533    if strcmp(CellInfo{icell}.CoordType,'tps') %do not plot directly tps data (used for projection only)
    543534        continue
    544535    end
    545     ivar_X=VarType.coord_x; % defines (unique) index for the variable representing unstructured x coordinate (default =[])
    546     ivar_Y=VarType.coord_y; % defines (unique)index for the variable representing unstructured y coordinate (default =[])
    547     ivar_U=VarType.vector_x; % defines (unique) index for the variable representing x vector component (default =[])
    548     ivar_V=VarType.vector_y; % defines (unique) index for the variable representing y vector component (default =[])
    549     ivar_C=[VarType.scalar VarType.image VarType.color VarType.ancillary]; %defines index (indices) for the scalar or ancillary fields
     536    ivar_X=CellInfo{icell}.CoordIndex(end); % defines (unique) index for the variable representing unstructured x coordinate (default =[])
     537    ivar_Y=CellInfo{icell}.CoordIndex(end-1); % defines (unique)index for the variable representing unstructured y coordinate (default =[])
     538    ivar_C=[];
     539    if isfield(CellInfo{icell},'VarIndex_scalar')
     540        ivar_C=[ivar_C CellInfo{icell}.VarIndex_scalar];
     541    end
     542    if isfield(CellInfo{icell},'VarIndex_image')
     543        ivar_C=[ivar_C CellInfo{icell}.VarIndex_image];
     544    end
     545    if isfield(CellInfo{icell},'VarIndex_color')
     546        ivar_C=[ivar_C CellInfo{icell}.VarIndex_color];
     547    end
     548    if isfield(CellInfo{icell},'VarIndex_ancillary')
     549        ivar_C=[ivar_C CellInfo{icell}.VarIndex_ancillary];
     550    end
    550551    if numel(ivar_C)>1
    551552        errormsg= 'error in plot_field: too many scalar inputs';
    552553        return
    553554    end
    554     ivar_F=VarType.warnflag; %defines index (unique) for warning flag variable
    555     ivar_FF=VarType.errorflag; %defines index (unique) for error flag variable
    556     ind_coord=find(VarType.coord);
    557     if numel(ind_coord)==2
    558         VarType.coord=VarType.coord(ind_coord);
    559     end
    560     if ~isempty(ivar_U) && ~isempty(ivar_V)% vector components detected
     555    ivar_F=[];
     556    if isfield(CellInfo{icell},'VarIndex_warnflag')
     557    ivar_F=CellInfo{icell}.VarIndex_warnflag; %defines index (unique) for warning flag variable
     558    end
     559    ivar_FF=[];
     560    if isfield(CellInfo{icell},'VarIndex_errorflag')
     561    ivar_FF=CellInfo{icell}.VarIndex_errorflag; %defines index (unique) for error flag variable
     562    end
     563    if isfield(CellInfo{icell},'VarIndex_vector_x')&&isfield(CellInfo{icell},'VarIndex_vector_y') % vector components detected
    561564        if test_vec
    562565            errormsg='error in plot_field: attempt to plot two vector fields: to get the difference project on a plane with mode interp';
     
    564567        else
    565568            test_vec=1;
    566             vec_U=Data.(Data.ListVarName{ivar_U});
    567             vec_V=Data.(Data.ListVarName{ivar_V});
    568             if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field with unstructured coordinates
    569                 XName=Data.ListVarName{ivar_X};
    570                 YName=Data.ListVarName{ivar_Y};
     569            vec_U=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_x});
     570            vec_V=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_y});
     571            if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates
     572                XName=Data.ListVarName{CellInfo{icell}.CoordIndex(end)};
     573                YName=Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
    571574                vec_X=reshape(Data.(XName),[],1); %transform vectors in column matlab vectors
    572575                vec_Y=reshape(Data.(YName),[],1);
    573             elseif numel(VarType.coord)==2 && ~isequal(VarType.coord,[0 0]);%coordinates defines by dimension variables
    574                 y=Data.(Data.ListVarName{VarType.coord(1)});
    575                 x=Data.(Data.ListVarName{VarType.coord(2)});
     576            elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates
     577                y=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)});
     578                x=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end)});
    576579                if numel(y)==2 % y defined by first and last values on aregular mesh
    577580                    y=linspace(y(1),y(2),size(vec_U,1));
     
    581584                end
    582585                [vec_X,vec_Y]=meshgrid(x,y); 
    583             else
    584                 errormsg='error in plot_field: invalid coordinate definition for vector field';
    585                 return
    586586            end
    587587            if isfield(PlotParam.Vectors,'ColorScalar') && ~isempty(PlotParam.Vectors.ColorScalar)
    588588                [VarVal,ListVarName,VarAttribute,errormsg]=calc_field_interp([],Data,PlotParam.Vectors.ColorScalar);
    589 %             if ~isempty(ivar_C)
    590                  %vec_C=Data.(Data.ListVarName{ivar_C});
    591                  if ~isempty(VarVal)
    592                  vec_C=reshape(VarVal{1},1,numel(VarVal{1}));
    593                  test_C=1;
    594                  end
     589                if ~isempty(VarVal)
     590                    vec_C=reshape(VarVal{1},1,numel(VarVal{1}));
     591                    test_C=1;
     592                end
    595593            end
    596594            if ~isempty(ivar_F)%~(isfield(PlotParam.Vectors,'HideWarning')&& isequal(PlotParam.Vectors.HideWarning,1))
     
    613611            return
    614612        end
    615         eval(['A=squeeze(Data.' Data.ListVarName{ivar_C} ');']) ;% scalar represented as color image
     613        A=squeeze(Data.(Data.ListVarName{ivar_C}));% scalar represented as color image
    616614        test_ima=1;
    617         if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates  (then ivar_X and ivar_Y not empty)
     615        if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates
    618616            A=reshape(A,1,[]);
    619617            XName=Data.ListVarName{ivar_X};
     
    630628                end
    631629            end       
    632         elseif numel(VarType.coord)==2 %structured coordinates
    633             XName=Data.ListVarName{VarType.coord(2)};
    634             YName=Data.ListVarName{VarType.coord(1)};
    635             eval(['AY=Data.' Data.ListVarName{VarType.coord(1)} ';'])
    636             eval(['AX=Data.' Data.ListVarName{VarType.coord(2)} ';'])
     630        elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates
     631            YName=Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
     632            AY=Data.(YName);
     633            AX=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end)});
    637634            test_interp_X=0; %default, regularly meshed X coordinate
    638635            test_interp_Y=0; %default, regularly meshed Y coordinate
    639636            if isfield(Data,'VarAttribute')
    640                 if numel(Data.VarAttribute)>=VarType.coord(2) && isfield(Data.VarAttribute{VarType.coord(2)},'units')
    641                     x_units=Data.VarAttribute{VarType.coord(2)}.units;
    642                 end
    643                 if numel(Data.VarAttribute)>=VarType.coord(1) && isfield(Data.VarAttribute{VarType.coord(1)},'units')
    644                     y_units=Data.VarAttribute{VarType.coord(1)}.units;
     637                if numel(Data.VarAttribute)>=CellInfo{icell}.CoordIndex(end) && isfield(Data.VarAttribute{CellInfo{icell}.CoordIndex(end)},'units')
     638                    x_units=Data.VarAttribute{CellInfo{icell}.CoordIndex(end)}.units;
     639                end
     640                if numel(Data.VarAttribute)>=CellInfo{icell}.CoordIndex(end-1) && isfield(Data.VarAttribute{CellInfo{icell}.CoordIndex(end-1)},'units')
     641                    y_units=Data.VarAttribute{CellInfo{icell}.CoordIndex(end-1)}.units;
    645642                end
    646643            end 
     
    650647                DAY_max=max(DAY);
    651648                if sign(DAY_min)~=sign(DAY_max);% =1 for increasing values, 0 otherwise
    652                      errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarType.coord(1)} ];
     649                     errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarRole.coord(1)} ];
    653650                      return
    654651                end
     
    660657                DAX_max=max(DAX);
    661658                if sign(DAX_min)~=sign(DAX_max);% =1 for increasing values, 0 otherwise
    662                      errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarType.coord(2)} ];
     659                     errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarRole.coord(2)} ];
    663660                      return
    664661                end
     
    687684            AX=[AX(1) AX(end)];% keep only the lower and upper bounds for image represnetation
    688685            AY=[AY(1) AY(end)];
    689         else
    690             errormsg='error in plot_field: invalid coordinate definition ';
    691             return
     686%         else
     687%             errormsg='error in plot_field: invalid coordinate definition ';
     688%             return
    692689        end
    693690    end
Note: See TracChangeset for help on using the changeset viewer.