Home > . > plot_field.m

# plot_field

## PURPOSE

'plot_field': plot any field with the structure defined in the uvmat package

## SYNOPSIS

function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,KeepLim,PosColorbar)

## DESCRIPTION

    'plot_field': plot any field with the structure defined in the uvmat package
    ------------------------------------------------------------------------

      This function is used by uvmat to plot fields. It automatically chooses the representation
     appropriate to the input field structure:
         2D vector fields are represented by arrows, 2D scalar fiedlds by grey scale images or contour plots, 1D fields are represented by usual plot with (abscissa, ordinate).
      The input field structure is first tested by check_field_structure.m,
      then split into blocks of related variables  by find_field_indices.m.
      The dimensionality of each block is obtained  by this fuction
      considering the presence of variables with the attribute .Role='coord_x'
      and/or coord_y and/or coord_z (case of unstructured coordinates), or
      dimension variables (case of matrices).

     function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,KeepLim,PosColorbar)

     OUPUT:
     PlotType: type of plot: 'text','line'(curve plot),'plane':2D view,'volume'
     PlotParamOut: structure, representing the updated  plotting parameters, in case of automatic scaling
     haxes: handle of the plotting axis, when a new figure is created.

    INPUT
        Data:   structure describing the field to plot
             (optional) .ListGlobalAttribute: cell listing the names of the global attributes
                        .Att_1,Att_2... : values of the global attributes
             (requested)  .ListVarName: list of variable names to select (cell array of  char strings {'VarName1', 'VarName2',...} )
             (requested)  .VarDimName: list of dimension names for each element of .ListVarName (cell array of string cells)
                          .VarAttribute: cell of attributes for each element of .ListVarName (cell array of structures of the form VarAtt.key=value)
             (requested) .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName

                Variable attribute .Role :
        The only variable attribute used for plotting purpose is .Role which can take
        the values
           Role = 'scalar':  (default) represents a scalar field
                = 'coord_x', 'coord_y',  'coord_z': represents a separate set of
                            unstructured coordinate x, y  or z
                = 'vector': represents a vector field whose number of components
                    is given by the last dimension (called 'nb_dim')
                = 'vector_x', 'vector_y', 'vector_z'  :represents the x, y or z  component of a vector
                = 'warnflag' : provides a warning flag about the quality of data in a 'Field', default=0, no warning
                = 'errorflag': provides an error flag marking false data,
                       default=0, no error. Different non zero values can represent different criteria of elimination.

## CROSS-REFERENCE INFORMATION

This function calls:

- check_field_structure 'check_field_structure': check the representation of fields by a Matlab structure
- find_field_indices 'find_file_indices': group the variables of a nc-formated Matlab structure into 'fields' with common dimensions
- msgbox_uvmat 'msgbox_uvmat': associated with GUI msgbox_uvmat.fig to display message boxes, for error, warning or input calls
- plot_text 'plot_text': function for displaying the content of a Matlab structure in a figure
- proj_grid 'proj_grid': project fields with unstructured coordinantes on a regular grid
- read_plot_param 'read_plot_param': read plotting parameters from the interface uvmat
- set_col_vec 'set_col_vec': sets the color code for vectors depending on a scalar vec_C and parameters given by the struct colcode
- set_title 'set_title': defines the 'TITLE' of a projection object
- warndlg_uvmat 'warndlg_uvmat': display warning message (error, warning, confirmation) in a given figure

This function is called by:

- geometry_calib 'geometry_calib': performs geometric calibration from a set of reference points
- get_field 'get_field': display variables and attributes from a Netcdf file, and plot selected fields
- mouse_down 'mouse_down': function activated when the mouse button is pressed on a figure (callback for 'WindowButtonDownFcn'
- probe_calib 'probe_calib': performs geometric calibration from a set of reference points
- series 'series': master function associated to the GUI series.m for analysis field series
- update_obj 'update_obj': update the object graph representation and its projection field, record it in the uvmat interface
- uvmat 'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization

## SUBFUNCTIONS

- function [AxeData,haxes]=plot_hist(Data,haxes,PlotParam)
- function [AxeData,haxes]=plot_profile(data,CellVarIndex,VarType,haxes,PlotParam)
- function [AxeData,haxes,PlotParamOut,PlotType]=plot_plane(Data,CellVarIndex,VarTypeCell,haxes,PlotParam,KeepLim,PosColorbar)
- function quiresetn(haxes,x,y,u,v,scale,colorlist,col_vec)
- function YTick=colbartick(MinA,MaxA)

## SOURCE CODE

    0001 %'plot_field': plot any field with the structure defined in the uvmat package
    0002 %------------------------------------------------------------------------
    0003 %
    0004 %  This function is used by uvmat to plot fields. It automatically chooses the representation
    0005 % appropriate to the input field structure:
    0006 %     2D vector fields are represented by arrows, 2D scalar fiedlds by grey scale images or contour plots, 1D fields are represented by usual plot with (abscissa, ordinate).
    0007 %  The input field structure is first tested by check_field_structure.m,
    0008 %  then split into blocks of related variables  by find_field_indices.m.
    0009 %  The dimensionality of each block is obtained  by this fuction
    0010 %  considering the presence of variables with the attribute .Role='coord_x'
    0011 %  and/or coord_y and/or coord_z (case of unstructured coordinates), or
    0012 %  dimension variables (case of matrices).
    0013 %
    0014 % function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,KeepLim,PosColorbar)
    0015 %
    0016 % OUPUT:
    0017 % PlotType: type of plot: 'text','line'(curve plot),'plane':2D view,'volume'
    0018 % PlotParamOut: structure, representing the updated  plotting parameters, in case of automatic scaling
    0019 % haxes: handle of the plotting axis, when a new figure is created.
    0020 %
    0021 %INPUT
    0022 %    Data:   structure describing the field to plot
    0023 %         (optional) .ListGlobalAttribute: cell listing the names of the global attributes
    0024 %                    .Att_1,Att_2... : values of the global attributes
    0025 %         (requested)  .ListVarName: list of variable names to select (cell array of  char strings {'VarName1', 'VarName2',...} )
    0026 %         (requested)  .VarDimName: list of dimension names for each element of .ListVarName (cell array of string cells)
    0027 %                      .VarAttribute: cell of attributes for each element of .ListVarName (cell array of structures of the form VarAtt.key=value)
    0028 %         (requested) .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
    0029 %
    0030 %            Variable attribute .Role :
    0031 %    The only variable attribute used for plotting purpose is .Role which can take
    0032 %    the values
    0033         %       Role = 'scalar':  (default) represents a scalar field
    0034         %            = 'coord_x', 'coord_y',  'coord_z': represents a separate set of
    0035         %                        unstructured coordinate x, y  or z
    0036         %            = 'vector': represents a vector field whose number of components
    0037         %                is given by the last dimension (called 'nb_dim')
    0038         %            = 'vector_x', 'vector_y', 'vector_z'  :represents the x, y or z  component of a vector
    0039         %            = 'warnflag' : provides a warning flag about the quality of data in a 'Field', default=0, no warning
    0040         %            = 'errorflag': provides an error flag marking false data,
    0041         %                   default=0, no error. Different non zero values can represent different criteria of elimination.
    0042
    0043
    0044 %         additional elements characterizing the projection object (should not be necessary)--
    0045 %            Data.Style : style of projection object
    0046 %            Data.XObject,.YObject: set of coordinates defining the object position;
    0047 %            Data.ProjMode=type of projection ;
    0048 %            Data.ProjAngle=angle of projection;
    0049 %            Data.DX,.DY,.DZ=increments;
    0050 %            Data.MaxY,MinY: min and max Y
    0051
    0052 %   haxes: handle of the plotting axes to update with the new plot. If this input is absent or not a valid axes handle, a new figure is created.
    0053 %
    0054 %   PlotParam: parameters for plotting, as read on the uvmat interface (by function 'read_plot_param.m')
    0055 %            --scalars--
    0056 %    .Scalar.MaxA: upper bound (saturation color) for the scalar representation, max(field) by default
    0057 %    .Scalar.MinA: lower bound (saturation) for the scalar representation, min(field) by default
    0058 %    .Scalar.AutoScal: =1 (default) lower and upper bounds of the scalar representation set to the min and max of the field
    0059 %               =0 lower and upper bound imposed by .AMax and .MinA
    0060 %    .Scalar.BW= 1 black and white representation imposed, =0 by default.
    0061 %    .Scalar.Contours= 1: represent scalars by contour plots (Matlab function 'contour'); =0 by default
    0062 %    .IncrA : contour interval
    0063 %            -- vectors--
    0064 %    .Vectors.VecScale: scale for the vector representation
    0065 %    .Vectors.AutoVec: =0 (default) automatic length for vector representation, =1: length set by .VecScale
    0066 %    .Vectors.HideFalse= 0 (default) false vectors represented in magenta, =1: false vectors not represented;
    0067 %    .Vectors.HideWarning= 0 (default) vectors marked by warnflag~=0 marked in black, 1: no warning representation;
    0068 %    .Vectors.decimate4 = 0 (default) all vectors reprtesented, =1: half of  the vectors represented along each coordinate
    0069 %         -- vector color--
    0070 %    .Vectors.ColorCode= 'black','white': imposed color  (default ='blue')
    0071 %                        'rgb', : three colors red, blue, green depending
    0072 %                        on thresholds .colcode1 and .colcode2 on the input  scalar value (C)
    0073 %                        'brg': like rgb but reversed color order (blue, green, red)
    0074 %                        '64 colors': continuous color from blue to red (multijet)
    0075 %    .Vectors.colcode1 : first threshold for rgb, first value for'continuous'
    0076 %    .Vectors.colcode2 : second threshold for rgb, last value (saturation) for 'continuous'
    0077 %    .Vectors.FixedCbounds;  =0 (default): the bounds on C representation are min and max, =1: they are fixed by .Minc and .MaxC
    0078 %    .Vectors.MinC = imposed minimum of the scalar field used for vector color;
    0079 %    .Vectors.MaxC = imposed maximum of the scalar field used for vector color;
    0080 %
    0081 % KeepLim:=0 (default) adjust axes limit to the X,Y data, =1: preserves the previous axes limits
    0082 % PosColorbar: if not empty, display a colorbar for B&W images
    0083 %               imposed position of the colorbar (ex [0.821 0.471 0.019 0.445])
    0084 %
    0085 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0086 %  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
    0087 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0088 %     This file is part of the toolbox UVMAT.
    0089 %
    0090 %     UVMAT is free software; you can redistribute it and/or modify
    0091 %     it under the terms of the GNU General Public License as published by
    0092 %     the Free Software Foundation; either version 2 of the License, or
    0093 %     (at your option) any later version.
    0094 %
    0095 %     UVMAT is distributed in the hope that it will be useful,
    0096 %     but WITHOUT ANY WARRANTY; without even the implied warranty of
    0097 %     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0098 %     GNU General Public License (file UVMAT/COPYING.txt) for more details.
    0099 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0100
    0101 function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,KeepLim,PosColorbar)
    0102 %default output
    0103 if ~exist('PlotParam','var'),PlotParam=[];end;
    0104 if ~exist('KeepLim','var'),KeepLim=0;end;
    0105 if ~exist('PosColorbar','var'),PosColorbar=[];end;
    0106 PlotType='text'; %default
    0107 PlotParamOut=PlotParam;%default
    0108
    0109 % check input structure
    0110 [Data,errormsg]=check_field_structure(Data);
    0111
    0112 if ~isempty(errormsg)
    0113     msgbox_uvmat('ERROR',['input of plot_field/check_field_structure: ' errormsg])
    0114     display(['input of plot_field/check_field_structure:: ' errormsg])
    0115     return
    0116 end
    0117
    0118 testnewfig=1;%test to create a new figure (default)
    0119 testzoomaxes=0;%test for the existence of a zoom secondary figure attached to the plotting axes
    0120 if exist('haxes','var')
    0121     if ishandle(haxes)
    0122         if isequal(get(haxes,'Type'),'axes')
    0123 %             hfig=get(haxes,'Parent');
    0124             axes(haxes)
    0125             testnewfig=0;
    0126             AxeData=get(haxes,'UserData');
    0127             if isfield(AxeData,'ZoomAxes')&& ishandle(AxeData.ZoomAxes)
    0128                 if isequal(get(AxeData.ZoomAxes,'Type'),'axes')
    0129                     testzoomaxes=1;
    0130                     zoomaxes=AxeData.ZoomAxes;
    0131                 end
    0132             end
    0133         end
    0134     end
    0135 end
    0136 if testnewfig% create a new figure and axes if the plotting axes does not exist
    0137     hfig=figure;
    0138     if isfield(Data,'IndexObj')&isfield(Data,'Style')&isfield(Data,'ProjMode')
    0139         figname=[num2str(Data.IndexObj) '-' set_title(Data.Style,Data.ProjMode)];
    0140         set(hfig,'Name',figname)
    0141     end
    0142     testhandle=0;
    0143     if isfield(PlotParam,'text_display_1')& ishandle(PlotParam.text_display_1)
    0144         set(hfig,'UserData',PlotParam)
    0145         testhandle=1;
    0146     end
    0147     set(hfig,'Units','normalized')
    0148     set(hfig,'WindowButtonDownFcn','mouse_down')
    0149     %set(hfig,'WindowButtonMotionFcn',{'mouse_motion',PlotParam})%set mouse action function
    0150     set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action function
    0151     set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse action function
    0152     haxes=axes;
    0153     set(haxes,'position',[0.13,0.2,0.775,0.73])
    0154 end
    0155 if isfield(PlotParam,'text_display_1')& ishandle(PlotParam.text_display_1)
    0156     PlotParam=read_plot_param(PlotParam);
    0157 end
    0158 if testnewfig
    0159   PlotParam.NextPlot='add'; %parameter for plot_profile and plot_hist
    0160 end
    0161 if isfield(PlotParam,'Auto_xy') && isequal(PlotParam.Auto_xy,1)
    0162     set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio
    0163 end
    0164
    0165 % check the cells of fields :
    0166 testnbdim=1;
    0167 [CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Data);
    0168
    0169 if ~isempty(errormsg)
    0170     msgbox_uvmat('ERROR',['input of plot_field/find_field_indices: ' errormsg])
    0171     display(['input of plot_field: ' errormsg])
    0172     return
    0173 end
    0174 if ~isfield(Data,'NbDim') %& ~isfield(Data,'Style')%determine the space dimensionb if not defined: choose the kind of plot
    0175     [Data.NbDim,imax]=max(NbDim);
    0176 end
    0177 if isequal(Data.NbDim,0) % TODO: chech whether this function is still used, replace by plot_profile ?
    0178     if isfield(Data,'Style') & isequal(Data.Style,'points')
    0179         AxeData=plot_text(Data,haxes);
    0180         PlotType='text';
    0181     else
    0182         [AxeData,haxes]=plot_hist(Data,haxes,PlotParam);
    0183     end
    0184 elseif isequal(Data.NbDim,1)
    0185     [AxeData,haxes]=plot_profile(Data,CellVarIndex,VarType,haxes,PlotParam);%
    0186     if testzoomaxes
    0187         [AxeData,zoomaxes,PlotParamOut]=plot_profile(Data,CellVarIndex,VarType,zoomaxes,PlotParam);
    0188         AxeData.ZoomAxes=zoomaxes;
    0189     end
    0190     PlotType='line';
    0191 elseif isequal(Data.NbDim,2)
    0192     ind_select=find(NbDim>=2);
    0193     if numel(ind_select)>2
    0194         msgbox_uvmat('ERROR',['more than two fields to map'])
    0195         display(['more than two fields to map'])
    0196         return
    0197     end
    0198     [AxeData,haxes,PlotParamOut,PlotType]=plot_plane(Data,CellVarIndex(ind_select),VarType(ind_select),haxes,PlotParam,KeepLim,PosColorbar);
    0199     if testzoomaxes
    0200         [AxeData,zoomaxes,PlotParamOut]=plot_plane(Data,CellVarIndex(ind_select),VarType(ind_select),zoomaxes,PlotParam,1,PosColorbar);
    0201         AxeData.ZoomAxes=zoomaxes;
    0202     end
    0203 elseif isequal(Data.NbDim,3)
    0204     msgbox_uvmat('ERROR','volume plot not implemented yet')
    0205     return
    0206     %plot_volume(haxes,Data,PlotParam)% A FAIRE
    0207     %PlotType='volume';
    0208 else
    0209     testnbdim=0;
    0210 end
    0211
    0212 %display (or delete) error message
    0213 htext=findobj(haxes,'Tag','hTxt');
    0214 if isfield(Data,'Txt')
    0215     if isempty(htext)
    0216         Xlim=get(haxes,'XLim');
    0217         Ylim=get(haxes,'YLim');
    0218         htext=text(Xlim(1),(Ylim(1)+Ylim(2))/2,Data.Txt,'Tag','hTxt','Color','r');
    0219         set(htext,'Interpreter','none')
    0220     else
    0221         set(htext,'String',Data.Txt)
    0222     end
    0223 elseif ~isempty(htext)
    0224     delete(htext)
    0225 end
    0226
    0227 % set graph aspect ratio
    0228
    0229
    0230 set(haxes,'UserData',AxeData)
    0231 %set(haxes,'Tag','uvmat');
    0232
    0233
    0234 %-------------------------------------------
    0235 function [AxeData,haxes]=plot_hist(Data,haxes,PlotParam)% TODO: chech whether this function is still used, replace by plot_profile ?
    0236 %------------------------------------------
    0237 AxeData=get(haxes,'UserData'); %defau
    0238 hfig=get(haxes,'parent');
    0239 if ~isfield(Data,'ListVarName')
    0240     return
    0241 end
    0242 ColorOrder=[1 0 0;0 0.5 0;0 0 1;0 0.75 0.75;0.75 0 0.75;0.75 0.75 0;0.25 0.25 0.25];
    0243 set(haxes,'ColorOrder',ColorOrder)
    0244 if isfield(PlotParam,'NextPlot')
    0245     set(haxes,'NextPlot',PlotParam.NextPlot)
    0246 end
    0247 charplot='''-''';
    0248 iplot=0;
    0249 legend_str={};
    0250 label_str='';
    0251 textmean={};
    0252 plotstr='plot(';
    0253 for ilist=1:length(Data.ListVarName)
    0254     VarName=Data.ListVarName{ilist};
    0255     eval(['[' VarName 'hist,' VarName 'val]=hist(double(Data.' VarName '),100);']);%coordinate variable set as c
    0256     plotstr=[plotstr VarName 'val,' VarName 'hist,' charplot ','];
    0257     eval(['nbcomponent2=size(Data.' VarName ',2);']);
    0258     eval(['nbcomponent1=size(Data.' VarName ',1);']);
    0259     eval(['varmean=mean(double(Data.' VarName '));']);%mean value
    0260     textmean=[textmean; {[VarName 'mean= ' num2str(varmean,4)]}];
    0261     if nbcomponent1==1| nbcomponent2==1
    0262         legend_str=[legend_str {VarName}]; %variable with one component
    0263     else
    0264         for ic=1:min(nbcomponent1,nbcomponent2)
    0265             legend_str=[legend_str [VarName '_' num2str(ic)]]; %variable with severals  components
    0266                                                                % labeled by their index (e.g. color component)
    0267         end
    0268     end
    0269     label_str=[label_str ' ' VarName];
    0270 end
    0271 if ~isequal(plotstr,'plot(')
    0272     plotstr(end)=')';
    0273     eval(plotstr)
    0274     hlegend=findobj(hfig,'Tag','legend');%find existing legend on the plot
    0275     if ~isempty(hlegend)
    0276         legend_old=get(hlegend,'String');
    0277         if isequal(size(legend_old,1),size(legend_str,1))
    0278              legend_str=[legend_old legend_str];
    0279         end
    0280     end
    0281     legend(legend_str)
    0282     xlabel(label_str)
    0283     ylabel('nb values')
    0284      grid on
    0285     title_str='';
    0286     if isfield(Data,'filename')
    0287        [Path, title_str, ext]=fileparts(Data.filename);
    0288        title_str=[title_str ext];
    0289     end
    0290     if isfield(Data,'Action')
    0291         if ~isequal(title_str,'')
    0292             title_str=[title_str ', '];
    0293         end
    0294         title_str=[title_str Data.Action];
    0295     end
    0296     htitle=title(title_str);
    0297     set(htitle,'Interpreter','none')% desable tex interpreter
    0298     hlist=findobj(gcf,'Style','listbox');
    0299     if isempty(hlist)
    0300             uicontrol('Style','popupmenu','Position',[20 20 200 20],'String',textmean);
    0301     else
    0302             set(hlist(1),'String',textmean)
    0303     end
    0304 end
    0305 AxeData=Data;
    0306
    0307
    0308 %----------------------------------------------------------
    0309 function [AxeData,haxes]=plot_profile(data,CellVarIndex,VarType,haxes,PlotParam)
    0310 %-----------------------------------------------------------
    0311 axes(haxes)
    0312 hfig=get(haxes,'parent');
    0313 AxeData=data;
    0314 ColorOrder=[1 0 0;0 0.5 0;0 0 1;0 0.75 0.75;0.75 0 0.75;0.75 0.75 0;0.25 0.25 0.25];
    0315 set(haxes,'ColorOrder',ColorOrder)
    0316 if isfield(PlotParam,'NextPlot')
    0317     set(haxes,'NextPlot',PlotParam.NextPlot)
    0318 end
    0319 legend_str={};
    0320
    0321 %initiates string of the plot command
    0322 plotstr='plot(';
    0323 textmean={};
    0324 abscissa_name='';
    0325 coord_x_index=[];
    0326 for icell=1:length(CellVarIndex)
    0327     testfalse=0;
    0328     VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list data.ListVarName
    0329     DimCell=data.VarDimName{VarIndex(1)};
    0330     if ischar(DimCell)
    0331         DimCell={DimCell};
    0332     end
    0333     XName=DimCell{1}; %first dimension considered as abscissa
    0334     coord_x_index_cell=VarType{icell}.coord(1);
    0335     if isequal(coord_x_index_cell,0)
    0336         continue  % the cell has no abscissa, skip it
    0337     end
    0338     if ~isempty(coord_x_index)&&~isequal(coord_x_index_cell,coord_x_index)
    0339         continue %all the selected variables must have the same first dimension
    0340     else
    0341         coord_x_index=coord_x_index_cell;
    0342     end
    0343     testplot=ones(size(data.ListVarName));%default test for plotted variables
    0344     testcoordvar=0;
    0345     charplot_0='''-''';%default
    0346     if isfield(data,'ObjectProjMode')& isequal(data.ObjectProjMode,'projection')
    0347         charplot_0='''+''';
    0348     end
    0349     xtitle='';
    0350
    0351     xtitle=data.ListVarName{coord_x_index};
    0352     eval(['coord_x{icell}=data.' data.ListVarName{coord_x_index} ';']);%coordinate variable set as coord_x
    0353     if isfield(data,'VarAttribute')&& numel(data.VarAttribute)>=coord_x_index && isfield(data.VarAttribute{coord_x_index},'units')
    0354          xtitle=[xtitle '(' data.VarAttribute{coord_x_index}.units ')'];
    0355     end
    0356     eval(['coord_x{icell}=data.' data.ListVarName{coord_x_index} ';']);%coordinate variable set as coord_x
    0357     testcoordvar=1;
    0358     testplot(coord_x_index)=0;
    0359     if ~isempty(VarType{icell}.ancillary')
    0360             testplot(VarType{icell}.ancillary)=0;
    0361     end
    0362     if ~isempty(VarType{icell}.warnflag')
    0363             testplot(VarType{icell}.warnflag)=0;
    0364     end
    0365     if ~isempty(VarType{icell}.discrete')
    0366          charplot_0='''+''';
    0367     else
    0368           charplot_0='''-''';
    0369     end
    0370     if testcoordvar==0
    0371         coord_x{icell}=[1:data.DimValue(DimIndices(1))];%abscissa by default if no coordinate variable
    0372        % charplot_0='''-''';
    0373     end
    0374     if isfield(data,'VarAttribute')
    0375         VarAttribute=data.VarAttribute;
    0376         for ivar=1:length(VarIndex)
    0377              if length(VarAttribute)>=VarIndex(ivar) & isfield(VarAttribute{VarIndex(ivar)},'long_name')
    0378                  plotname{VarIndex(ivar)}=VarAttribute{VarIndex(ivar)}.long_name;
    0379              else
    0380                  plotname{VarIndex(ivar)}=data.ListVarName{VarIndex(ivar)};%name for display in plot A METTRE
    0381              end
    0382         end
    0383     end
    0384     for ivar=1:length(VarIndex)
    0385         if testplot(VarIndex(ivar))
    0386             VarName=data.ListVarName{VarIndex(ivar)};
    0387             eval(['data.' VarName '=squeeze(data.' VarName ');'])
    0388             if isequal(VarName,'A')
    0389                 charplot='''-''';
    0390             else
    0391                 charplot=charplot_0;
    0392             end
    0393             plotstr=[plotstr 'coord_x{' num2str(icell) '},data.' VarName ',' charplot ','];
    0394             eval(['nbcomponent2=size(data.' VarName ',2);']);
    0395             eval(['nbcomponent1=size(data.' VarName ',1);']);
    0396             eval(['varmean=mean(double(data.' VarName '));']);%mean value
    0397             textmean=[textmean; {[VarName 'mean= ' num2str(varmean,4)]}];
    0398             if nbcomponent1==1| nbcomponent2==1
    0399                 legend_str=[legend_str {VarName}]; %variable with one component
    0400             else  %variable with severals  components
    0401                 for ic=1:min(nbcomponent1,nbcomponent2)
    0402                     legend_str=[legend_str [VarName '_' num2str(ic)]]; %variable with severals  components
    0403                 end                                                   % labeled by their index (e.g. color component)
    0404             end
    0405         end
    0406     end
    0407 end
    0408 if ~isequal(plotstr,'plot(')
    0409     plotstr(end)=')';
    0410                 %execute plot (instruction  plotstr)
    0411     eval(plotstr)
    0412                 %%%%%
    0413     grid on
    0414     hxlabel=xlabel(xtitle);
    0415     set(hxlabel,'Interpreter','none')% desable tex interpreter
    0416     if length(legend_str)>=1
    0417         hylabel=ylabel(legend_str{end});
    0418         set(hylabel,'Interpreter','none')% desable tex interpreter
    0419     end
    0420     if ~isempty(legend_str)
    0421         hlegend=findobj(hfig,'Tag','legend');
    0422         if isempty(hlegend)
    0423             hlegend=legend(legend_str);
    0424             txt=ver;
    0425             Release=txt(1).Release;
    0426             relnumb=str2num(Release(3:4));
    0427             if relnumb >= 14
    0428                 set(hlegend,'Interpreter','none')% desable tex interpreter
    0429             end
    0430         else
    0431             legend_old=get(hlegend,'String');
    0432             if isequal(size(legend_old,1),size(legend_str,1))&~isequal(legend_old,legend_str)
    0433                 set(hlegend,'String',[legend_old legend_str]);
    0434             end
    0435         end
    0436     end
    0437     title_str='';
    0438     if isfield(data,'filename')
    0439        [Path, title_str, ext]=fileparts(data.filename);
    0440        title_str=[title_str ext];
    0441     end
    0442     if isfield(data,'Action')
    0443         if ~isequal(title_str,'')
    0444             title_str=[title_str ', '];
    0445         end
    0446         title_str=[title_str data.Action];
    0447     end
    0448     htitle=title(title_str);
    0449     txt=ver;
    0450     Release=txt(1).Release;
    0451     relnumb=str2num(Release(3:4));
    0452     if relnumb >= 14
    0453         set(htitle,'Interpreter','none')% desable tex interpreter
    0454     end
    0455     % A REPRENDRE Mean
    0456 %         hlist=findobj(gcf,'Style','listbox','Tag','liststat');
    0457 %         if isempty(hlist)
    0458 %             'text'
    0459 %             textmean
    0460 %             set(gca,'position',[0.13,0.2,0.775,0.73])
    0461 %             uicontrol('Style','popupmenu','Position',[20 20 200 20],'String',textmean,'Tag','liststat');
    0462 %         else
    0463 %             set(hlist(1),'String',textmean)
    0464 %         end
    0465 end
    0466
    0467
    0468 %---------------------------------------
    0469 % plot_plane
    0470 %----------------------------------------
    0471 function [AxeData,haxes,PlotParamOut,PlotType]=plot_plane(Data,CellVarIndex,VarTypeCell,haxes,PlotParam,KeepLim,PosColorbar)
    0472
    0473 %default plotting parameters
    0474 PlotType='plane';%default
    0475 if ~exist('PlotParam','var')
    0476     PlotParam=[];
    0477 end
    0478 if ~isfield(PlotParam,'Scalar')
    0479     PlotParam.Scalar=[];
    0480 end
    0481 if ~isfield(PlotParam,'Vectors')
    0482     PlotParam.Vectors=[];
    0483 end
    0484 PlotParamOut=PlotParam;%default
    0485
    0486 %plotting axes
    0487 hfig=get(haxes,'parent');
    0488 hcol=findobj(hfig,'Tag','Colorbar'); %look for colorbar axes
    0489 hima=findobj(haxes,'Tag','ima');% search existing image in the current axes
    0490 AxeData=get(haxes,'UserData'); %default
    0491 if ~isstruct(AxeData)% AxeData must be a structure
    0492     AxeData=[];
    0493 end
    0494 AxeData.NbDim=2;
    0495 if isfield(Data,'ObjectCoord')
    0496     AxeData.ObjectCoord=Data.ObjectCoord;
    0497 end
    0498
    0499 test_ima=0; %default: test for image or map plot
    0500 test_vec=0; %default: test for vector plots
    0501 test_black=0;
    0502 test_false=0;
    0503 test_C=0;
    0504 for icell=1:length(CellVarIndex) % length(CellVarIndex) =1 or 2 (from the calling function)
    0505 %     VarIndex=CellVarIndex{icell};
    0506     VarType=VarTypeCell{icell};
    0507     ivar_X=VarType.coord_x; % defines (unique) index for the variable representing unstructured x coordinate (default =[])
    0508     ivar_Y=VarType.coord_y; % defines (unique)index for the variable representing unstructured y coordinate (default =[])
    0509     ivar_U=VarType.vector_x; % defines (unique) index for the variable representing x vector component (default =[])
    0510     ivar_V=VarType.vector_y; % defines (unique) index for the variable representing y vector component (default =[])
    0511     ivar_C=[VarType.scalar VarType.image VarType.color VarType.ancillary]; %defines index (indices) for the scalar or ancillary fields
    0512     if numel(ivar_C)>1
    0513         msgbox_uvmat('ERROR','too many scalar inputs in plot_field.m')
    0514         return
    0515     end
    0516     ivar_F=VarType.warnflag; %defines index (unique) for warning flag variable
    0517     ivar_FF=VarType.errorflag; %defines index (unique) for error flag variable
    0518     idim_Y=[];
    0519     test_grid=0;
    0520     if ~isempty(ivar_U) && ~isempty(ivar_V)% vector components detected
    0521         if test_vec
    0522             msgbox_uvmat('ERROR','attempt to plot two vector fields')
    0523             return
    0524         else
    0525             test_vec=1;
    0526             eval(['vec_U=Data.' Data.ListVarName{ivar_U} ';'])
    0527             eval(['vec_V=Data.' Data.ListVarName{ivar_V} ';'])
    0528             if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates or structured ones (then ivar_X and ivar_Y empty)
    0529                 eval(['vec_X=Data.' Data.ListVarName{ivar_X} ';'])
    0530                 eval(['vec_Y=Data.' Data.ListVarName{ivar_Y} ';'])
    0531             elseif numel(VarType.coord)==2 & VarType.coord~=[0 0];%coordinates defines by dimension variables
    0532                 eval(['y=Data.' Data.ListVarName{VarType.coord(1)} ';'])
    0533                 eval(['x=Data.' Data.ListVarName{VarType.coord(2)} ';'])
    0534                 if numel(y)==2 % y defined by first and last values on aregular mesh
    0535                     y=linspace(y(1),y(2),size(vec_U,1));
    0536                 end
    0537                 if numel(x)==2 % y defined by first and last values on aregular mesh
    0538                     x=linspace(x(1),x(2),size(vec_U,2));
    0539                 end
    0540                 [vec_X,vec_Y]=meshgrid(x,y);
    0541             else
    0542                 msgbox_uvmat('ERROR','error in plot_field: bad coordinate definition for vector field')
    0543                 return
    0544             end
    0545             if ~isempty(ivar_C)
    0546                  eval(['vec_C=Data.' Data.ListVarName{ivar_C} ';']) ;
    0547                  vec_C=reshape(vec_C,1,numel(vec_C));
    0548                  test_C=1;
    0549             end
    0550             if ~(isfield(PlotParam.Vectors,'HideWarning')&& isequal(PlotParam.Vectors.HideWarning,1))&&~isempty(ivar_F) &&~test_black
    0551                 if numel(ivar_F)>1
    0552                     warndlg_uvmat('multiple warning flags in plot_field.m, make a selection','ERROR')
    0553                     return
    0554                 elseif test_vec
    0555                     eval(['AxeData.F=Data.' Data.ListVarName{ivar_F} ';']) % flags for false vectors
    0556                     test_black=1;
    0557                 end
    0558             end
    0559             if ~isempty(ivar_FF) && ~test_false
    0560                if numel(ivar_FF)>1
    0561                     warndlg_uvmat('multiple error flags in plot_field.m, make a selection','ERROR')
    0562                     return
    0563                else %A VOIR CAS IMAGES
    0564                     eval(['AxeData.FF=Data.' Data.ListVarName{ivar_FF} ';']) % flags for false vectors
    0565                     test_false=1;
    0566                end
    0567             end
    0568         end
    0569     elseif ~isempty(ivar_C) %scalar or image
    0570         if test_ima
    0571              msgbox_uvmat('ERROR','attempt to plot two scalar fields or images')
    0572             return
    0573         end
    0574         eval(['A=Data.' Data.ListVarName{ivar_C} ';']) ;% scalar represented as color image
    0575         test_ima=1;
    0576         if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates or structured ones (then ivar_X and ivar_Y empty)
    0577             eval(['AX=Data.' Data.ListVarName{ivar_X} ';'])
    0578             eval(['AY=Data.' Data.ListVarName{ivar_Y} ';'])
    0579             [A,AX,AY]=proj_grid(AX',AY',A',[],[],'np>256');  % interpolate on a grid
    0580         elseif numel(VarType.coord)>=2 & VarType.coord(1:2)~=[0 0];%structured coordinates
    0581             eval(['AY=Data.' Data.ListVarName{VarType.coord(1)} ';'])
    0582             eval(['AX=Data.' Data.ListVarName{VarType.coord(2)} ';'])
    0583             test_interp_X=0; %default, regularly meshed X coordinate
    0584             test_interp_Y=0; %default, regularly meshed Y coordinate
    0585             if numel(AY)>2
    0586                 DAY=diff(AY);
    0587                 DAY_min=min(DAY);
    0588                 DAY_max=max(DAY);
    0589                 if sign(DAY_min)~=sign(DAY_max);% =1 for increasing values, 0 otherwise
    0590                      errormsg=['errror in plot_field.m: non monotonic dimension variable # ' ListVarName{VarType.coord(1)} ];
    0591                       return
    0592                 end
    0593                 test_interp_Y=(DAY_max-DAY_min)> 0.0001*abs(DAY_max);
    0594             end
    0595             if numel(AX)>2
    0596                 DAX=diff(AX);
    0597                 DAX_min=min(DAX);
    0598                 DAX_max=max(DAX);
    0599                 if sign(DAX_min)~=sign(DAX_max);% =1 for increasing values, 0 otherwise
    0600                      errormsg=['errror in plot_field.m: non monotonic dimension variable # ' ListVarName{VarType.coord(2)} ];
    0601                       return
    0602                 end
    0603                 test_interp_X=(DAX_max-DAX_min)> 0.0001*abs(DAX_max);
    0604             end
    0605             if test_interp_Y
    0606                 npxy(1)=max([256 floor((AY(end)-AY(1))/DAY_min) floor((AY(end)-AY(1))/DAY_max)]);
    0607                 yI=linspace(AY(1),AY(end),npxy(1));
    0608                 if ~test_interp_X
    0609                     xI=linspace(AX(1),AX(2),size(A,2));%default
    0610                     AX=xI;
    0611                 end
    0612             end
    0613             if test_interp_X
    0614                 npxy(1)=max([256 floor((AX(end)-AX(1))/DAX_min) floor((AX(end)-AX(1))/DAX_max)]);
    0615                 xI=linspace(AX(1),AX(end),npxy(2));
    0616                 if ~test_interp_Y
    0617                    yI=linspace(AY(1),AY(end),size(A,1));
    0618                    AY=yI;
    0619                 end
    0620             end
    0621             if test_interp_X || test_interp_Y
    0622                 [AX2D,AY2D]=meshgrid(AX,AY);
    0623                 A=interp2(AX2D,AY2D,double(A),xI,yI');
    0624             end
    0625             AX=[AX(1) AX(end)];% keep only the lower and upper bounds for image represnetation
    0626             AY=[AY(1) AY(end)];
    0627         else
    0628             msgbox_uvmat('ERROR','bad coordinate definition for vector field')
    0629             return
    0630         end
    0631     end
    0632     if isfield(Data,'VarAttribute')
    0633         VarAttribute=Data.VarAttribute;
    0634     end
    0635 end
    0636
    0637 %%%%%%%%%%%%%%%%%%%%%   image or scalar plot %%%%%%%%%%%%%%%%%%%%%%%%%%
    0638
    0639 if ~isfield(PlotParam.Scalar,'Contours')
    0640     PlotParam.Scalar.Contours=0; %default
    0641 end
    0642 PlotParamOut=PlotParam; %default
    0643 if test_ima
    0644     % distinguish B/W and color images
    0645     np=size(A);%size of image
    0646     siz=size(np);
    0647     %set the color map
    0648     if siz(2)==2 %for black and white images
    0649         if ~isfield(PlotParam.Scalar,'AutoScal')
    0650             PlotParam.Scalar.AutoScal=0;%default
    0651         end
    0652         if ~isfield(PlotParam.Scalar,'MinA')
    0653             PlotParam.Scalar.MinA=[];%default
    0654         end
    0655         if ~isfield(PlotParam.Scalar,'MaxA')
    0656             PlotParam.Scalar.MaxA=[];%default
    0657         end
    0658         if isequal(PlotParam.Scalar.AutoScal,0)|isempty(PlotParam.Scalar.MinA)|~isa(PlotParam.Scalar.MinA,'double')  %correct if there is no numerical data in edit box
    0659             MinA=double(min(min(A)));
    0660         else
    0661             MinA=PlotParam.Scalar.MinA;
    0662         end;
    0663         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
    0664             MaxA=double(max(max(A)));
    0665         else
    0666             MaxA=PlotParam.Scalar.MaxA;
    0667         end;
    0668         PlotParamOut.Scalar.MinA=MinA;
    0669         PlotParamOut.Scalar.MaxA=MaxA;
    0670         axes(haxes)
    0671         if isequal(PlotParam.Scalar.Contours,1)
    0672             if ~isempty(hima) & ishandle(hima)
    0673                 delete(hima)
    0674             end
    0675             if ~isfield(PlotParam.Scalar,'IncrA')
    0676                 PlotParam.Scalar.IncrA=[];
    0677             end
    0678             if isempty(PlotParam.Scalar.IncrA)% | PlotParam.Scalar.AutoScal==0
    0679                 cont=colbartick(MinA,MaxA);
    0680                 intercont=cont(2)-cont(1);%default
    0681                 PlotParamOut.Scalar.IncrA=intercont;
    0682             else
    0683                intercont=PlotParam.Scalar.IncrA;
    0684             end
    0685             B=A;
    0686             abscontmin=intercont*floor(MinA/intercont);
    0687             abscontmax=intercont*ceil(MaxA/intercont);
    0688             contmin=intercont*floor(min(min(B))/intercont);
    0689             contmax=intercont*ceil(max(max(B))/intercont);
    0690             cont_pos_plus=[0:intercont:contmax];
    0691             cont_pos_min=[double(contmin):intercont:-intercont];
    0692             cont_pos=[cont_pos_min cont_pos_plus];
    0693             sizpx=(AX(end)-AX(1))/(np(2)-1);
    0694             sizpy=(AY(1)-AY(end))/(np(1)-1);
    0695             x_cont=[AX(1):sizpx:AX(end)]; % pixel x coordinates for image display
    0696             y_cont=[AY(1):-sizpy:AY(end)]; % pixel x coordinates for image display
    0697             txt=ver;%version of Matlab
    0698             Release=txt(1).Release;
    0699             relnumb=str2num(Release(3:4));
    0700             if relnumb >= 14
    0701                     vec=linspace(0,1,(abscontmax-abscontmin)/intercont);%define a greyscale colormap with steps intercont
    0702                 map=[vec' vec' vec'];
    0703                 colormap(map);
    0704                 [var,hcontour]=contour(x_cont,y_cont,B,cont_pos);
    0705                 set(hcontour,'Fill','on')
    0706                 set(hcontour,'LineStyle','none')
    0707                 hold on
    0708             end
    0709             [var_p,hcontour_p]=contour(x_cont,y_cont,B,cont_pos_plus,'k-');
    0710             hold on
    0711             [var_m,hcontour_m]=contour(x_cont,y_cont,B,cont_pos_min,':');
    0712             set(hcontour_m,'LineColor',[1 1 1])
    0713             hold off
    0714             caxis([abscontmin abscontmax])
    0715             colormap(map);
    0716         end
    0717         if ~isequal(PlotParam.Scalar.Contours,1)
    0718             % rescale the grey levels with min and max, put a grey scale colorbar
    0719             if (isfield(PlotParam.Scalar,'BW')& (isequal(PlotParam.Scalar.BW,1))|isa(A,'uint8')| isa(A,'uint16'))%images
    0720                 B=A;
    0721                 vec=linspace(0,1,255);%define a linear greyscale colormap
    0722                 map=[vec' vec' vec'];
    0723                 colormap(map);  %grey scale color map
    0724             else
    0725                 B=A;
    0726                 colormap('default'); % standard faulse colors for div, vort , scalar fields
    0727             end
    0728         end
    0729     elseif siz(2)==3 %color images
    0730         axes(haxes)
    0731         B=uint8(A);
    0732         MinA=0;
    0733         MaxA=255;
    0734     end
    0735     if ~isequal(PlotParam.Scalar.Contours,1)
    0736         %interpolate to increase resolution
    0737         test_interp=1;
    0738         if max(np) <= 64
    0739             npxy=8*np;% increase the resolution 8 times
    0740         elseif max(np) <= 128
    0741             npxy=4*np;% increase the resolution 4 times
    0742         elseif max(np) <= 256
    0743             npxy=2*np;% increase the resolution 2 times
    0744         else
    0745             npxy=np;
    0746             test_interp=0; % no interpolation done
    0747         end
    0748         if test_interp==1%if we interpolate
    0749             x=[AX(1):(AX(2)-AX(1))/(np(2)-1):AX(2)];
    0750             y=[AY(1):(AY(2)-AY(1))/(np(1)-1):AY(2)];
    0751             [X,Y]=meshgrid(x,y);
    0752 %             xi=[AX(1):(AX(2)-AX(1))/(npxy(2)-1):AX(2)];
    0753 %             yi=[AY(1):(AY(2)-AY(1))/(npxy(1)-1):AY(2)];
    0754
    0755             xi=linspace(AX(1),AX(2),npxy(2));
    0756             yi=linspace(AY(1),AY(2),npxy(1));
    0757             B = interp2(X,Y,double(B),xi,yi');
    0758         end
    0759         if isempty(hima)
    0760             tag=get(haxes,'Tag');
    0761             hima=imagesc(AX,AY,B,[MinA MaxA]);
    0762             set(hima,'Tag','ima','HitTest','off')
    0763             set(haxes,'Tag',tag);%preserve the axes tag (removed by image fct !!!)
    0764             %axis(haxes,'image'); % preserve the image aspect ratio     %TESTMOD
    0765         else
    0766             set(hima,'CData',B);
    0767             if MinA<MaxA
    0768                 caxis([MinA MaxA])
    0769             else
    0770                 caxis([MinA MinA+1])
    0771             end
    0772             set(hima,'XData',AX);
    0773             set(hima,'YData',AY);
    0774         end
    0775     end
    0776     if ~isstruct(AxeData)
    0777         AxeData=[];
    0778     end
    0779     AxeData.A=A;
    0780     AxeData.AX=[AX(1) AX(end)];
    0781     AxeData.AY=[AY(1) AY(end)];
    0782     test_ima=1;
    0783     %display the colorbar code for B/W images if Poscolorbar not empty
    0784     if siz(2)==2 & exist('PosColorbar','var')& ~isempty(PosColorbar)
    0785         if isempty(hcol)|~ishandle(hcol)
    0786              hcol=colorbar;%create new colorbar
    0787         end
    0788         if length(PosColorbar)==4
    0789                  set(hcol,'Position',PosColorbar)
    0790         end
    0791         YTick=0;%default
    0792         if MaxA>MinA
    0793             if isequal(PlotParam.Scalar.Contours,1)
    0794                 colbarlim=get(hcol,'YLim');
    0795                 scale_bar=(colbarlim(2)-colbarlim(1))/(abscontmax-abscontmin);
    0796                 YTick=cont_pos(2:end-1);
    0797                 YTick_scaled=colbarlim(1)+scale_bar*(YTick-abscontmin);
    0798                 set(hcol,'YTick',YTick_scaled);
    0799             elseif (isfield(PlotParam.Scalar,'BW') & isequal(PlotParam.Scalar.BW,1))|isa(A,'uint8')| isa(A,'uint16')%images
    0800                 hi=get(hcol,'children');
    0801                 if iscell(hi)%multiple images in colorbar
    0802                     hi=hi{1};
    0803                 end
    0804                 set(hi,'YData',[MinA MaxA])
    0805                 set(hi,'CData',[1:256]')
    0806                 set(hcol,'YLim',[MinA MaxA])
    0807                 YTick=colbartick(MinA,MaxA);
    0808                 set(hcol,'YTick',YTick)
    0809             else
    0810                 hi=get(hcol,'children');
    0811                 if iscell(hi)%multiple images in colorbar
    0812                     hi=hi{1};
    0813                 end
    0814                 set(hi,'YData',[MinA MaxA])
    0815                 set(hi,'CData',[1:64]')
    0816                 YTick=colbartick(MinA,MaxA);
    0817                 set(hcol,'YLim',[MinA MaxA])
    0818                 set(hcol,'YTick',YTick)
    0819             end
    0820             set(hcol,'Yticklabel',num2str(YTick'));
    0821         end
    0822     elseif ishandle(hcol)
    0823         delete(hcol); %erase existing colorbar if not needed
    0824     end
    0825 else%no scalar plot
    0826     if ~isempty(hima) && ishandle(hima)
    0827         delete(hima)
    0828     end
    0829     if ~isempty(hcol)&& ishandle(hcol)
    0830        delete(hcol)
    0831     end
    0832     AxeData.A=[];
    0833     AxeData.AX=[];
    0834     AxeData.AY=[];
    0835     PlotParamOut=rmfield(PlotParamOut,'Scalar');
    0836 end
    0837
    0838 %%%%%%%%%%%%%%%%%%%%%   vector plot %%%%%%%%%%%%%%%%%%%%%%%%%%
    0839 if test_vec
    0840    %vector scale representation
    0841     if size(vec_U,1)==numel(vec_Y) && size(vec_U,2)==numel(vec_X); % x, y  coordinate variables
    0842         [vec_X,vec_Y]=meshgrid(vec_X,vec_Y);
    0843     end
    0844     vec_X=reshape(vec_X,1,numel(vec_X));%reshape in matlab vectors
    0845     vec_Y=reshape(vec_Y,1,numel(vec_Y));
    0846     vec_U=reshape(vec_U,1,numel(vec_U));
    0847     vec_V=reshape(vec_V,1,numel(vec_V));
    0848     MinMaxX=max(vec_X)-min(vec_X);
    0849     MinMaxY=max(vec_Y)-min(vec_Y);
    0850     AxeData.Mesh=sqrt((MinMaxX*MinMaxY)/length(vec_X));
    0851     if  ~isfield(PlotParam.Vectors,'AutoVec') || isequal(PlotParam.Vectors.AutoVec,0)|| ~isfield(PlotParam.Vectors,'VecScale')...
    0852                ||isempty(PlotParam.Vectors.VecScale)||~isa(PlotParam.Vectors.VecScale,'double') %automatic vector scale
    0853         scale=[];
    0854         if test_false %remove false vectors
    0855             indsel=find(AxeData.FF==0);%indsel =indices of good vectors
    0856         else
    0857             indsel=[1:numel(vec_X)];%
    0858         end
    0859         if isempty(vec_U)
    0860             scale=1;
    0861         else
    0862             if isempty(indsel)
    0863                 MaxU=max(abs(vec_U));
    0864                 MaxV=max(abs(vec_V));
    0865             else
    0866                 MaxU=max(abs(vec_U(indsel)));
    0867                 MaxV=max(abs(vec_V(indsel)));
    0868             end
    0869             scale=MinMaxX/(max(MaxU,MaxV)*50);
    0870             PlotParam.Vectors.VecScale=scale;%update the 'scale' display
    0871         end
    0872     else
    0873         scale=PlotParam.Vectors.VecScale;  %impose the length of vector representation
    0874     end;
    0875
    0876     %record vectors on the plotting axes
    0877     if test_C==0
    0878         vec_C=ones(1,numel(vec_X));
    0879     end
    0880     AxeData.X=vec_X';
    0881     AxeData.Y=vec_Y';
    0882     AxeData.U=vec_U';
    0883     AxeData.V=vec_V';
    0884     AxeData.C=vec_C';
    0885     if isfield(Data,'W')
    0886         AxeData.W=Data.W;
    0887     end
    0888
    0889     %decimate by a factor 2 in vector mesh(4 in nbre of vectors)
    0890     if isfield(PlotParam.Vectors,'decimate4')&isequal(PlotParam.Vectors.decimate4,1)
    0891         diffy=diff(vec_Y); %difference dy=vec_Y(i+1)-vec_Y(i)
    0892         dy_thresh=max(abs(diffy))/2;
    0893         ind_jump=find(abs(diffy) > dy_thresh); %indices with diff(vec_Y)> max/2, detect change of line
    0894         ind_sel=[1:ind_jump(1)];%select the first line
    0895         for i=2:2:length(ind_jump)-1
    0896             ind_sel=[ind_sel [ind_jump(i)+1:ind_jump(i+1)]];% select the odd lines
    0897         end
    0898         nb_sel=length(ind_sel);
    0899         ind_sel=ind_sel([1:2:nb_sel]);% take half the points on a line
    0900         vec_X=vec_X(ind_sel);
    0901         vec_Y=vec_Y(ind_sel);
    0902         vec_U=vec_U(ind_sel);
    0903         vec_V=vec_V(ind_sel);
    0904         vec_C=vec_C(ind_sel);
    0905         if isfield(Data,'F')&& isequal(size(Data.F),size(vec_X))sdfsdf
    0906             Data.F=Data.F(ind_sel);
    0907         end
    0908         if isfield(Data,'FF')&& isequal(size(Data.FF),size(vec_X))
    0909             Data.FF=Data.FF(ind_sel);
    0910         end
    0911     end
    0912
    0913     %get main level color code
    0914     [colorlist,col_vec,PlotParamOut.Vectors]=set_col_vec(PlotParam.Vectors,vec_C);
    0915     % take flags into account: add flag colors to the list of colors
    0916     sizlist=size(colorlist);
    0917     nbcolor=sizlist(1);
    0918     if test_black && isfield (Data,'F')
    0919        nbcolor=nbcolor+1;
    0920        colorlist(nbcolor,:)=[0 0 0]; %add black to the list of colors
    0921        if isfield(Data,'FF')
    0922             ind_flag=find(Data.F~=1 & Data.FF==0);  %flag warning but not faulse
    0923        else
    0924             ind_flag=find(Data.F~=1);
    0925        end
    0926        col_vec(ind_flag)=nbcolor;
    0927     end
    0928     nbcolor=nbcolor+1;
    0929     if test_false && isfield (Data,'FF')
    0930         ind_flag=find(Data.FF~=0);
    0931         if isfield(PlotParam.Vectors,'HideFalse') & PlotParam.Vectors.HideFalse==1
    0932             colorlist(nbcolor,:)=[NaN NaN NaN];% no plot of false vectors
    0933         else
    0934             colorlist(nbcolor,:)=[1 0 1];% magenta color
    0935         end
    0936         col_vec(ind_flag)=nbcolor;
    0937     end
    0938     %plot vectors:
    0939     quiresetn(haxes,vec_X,vec_Y,vec_U,vec_V,scale,colorlist,col_vec);
    0940 else
    0941     hvec=findobj(haxes,'Tag','vel');
    0942     if ~isempty(hvec)
    0943         delete(hvec);
    0944     end
    0945     AxeData.X=[];
    0946     AxeData.Y=[];
    0947     AxeData.U=[];
    0948     AxeData.V=[];
    0949     AxeData.C=[];
    0950     AxeData.W=[];
    0951     AxeData.Mesh=[];
    0952     PlotParamOut=rmfield(PlotParamOut,'Vectors');
    0953 end
    0954 if isfield(Data,'Z')
    0955     AxeData.Z=Data.Z;% A REVOIR
    0956 end
    0957 listfields={'AY','AX','A','X','Y','U','V','C','W','F','FF'};
    0958 listdim={'AY','AX',{'AY','AX'},'nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors'};
    0959 Role={'coord_y','coord_x','scalar','coord_x','coord_y','vector_x','vector_y','scalar','vector_z','warnflag','falseflag'};
    0960 ind_select=[];
    0961 nbvar=0;
    0962
    0963 for ilist=1:numel(listfields)
    0964     eval(['testvar=isfield(AxeData,listfields{ilist}) && ~isempty(AxeData.' listfields{ilist} ');'])
    0965     if testvar
    0966         nbvar=nbvar+1;
    0967         AxeData.ListVarName{nbvar}=listfields{ilist};
    0968         AxeData.VarDimName{nbvar}=listdim{ilist};
    0969         AxeData.VarAttribute{nbvar}.Role=Role{ilist};
    0970     end
    0971 end
    0972
    0973 % adjust the size of the plot to include the whole field, except if KeepLim=1
    0974 if ~(exist('KeepLim','var') && isequal(KeepLim,1))  %adjust the graph limits*
    0975         test_lim=0;
    0976         if test_vec
    0977             Xlim=[min(vec_X) max(vec_X)];
    0978             Ylim=[min(vec_Y) max(vec_Y)];
    0979             test_lim=1;
    0980             if test_ima%both background image and vectors coexist, take the wider bound
    0981                 Xlim(1)=min(AX(1),Xlim(1));
    0982                 Xlim(2)=max(AX(end),Xlim(2));
    0983                 Ylim(1)=min(AY(end),Ylim(1));
    0984                 Ylim(2)=max(AY(1),Ylim(2));
    0985             end
    0986         elseif test_ima %only image plot
    0987             Xlim(1)=min(AX(1),AX(end));
    0988             Xlim(2)=max(AX(1),AX(end));
    0989             Ylim(1)=min(AY(1),AY(end));
    0990             Ylim(2)=max(AY(1),AY(end));
    0991             test_lim=1;
    0992         end
    0993         if test_lim
    0994             set(haxes,'XLim',Xlim);% set x limits of frame in axes coordinates
    0995             set(haxes,'YLim',Ylim);% set y limits of frame in axes coordinate
    0996         end
    0997 end
    0998 if ~(isfield(PlotParam,'Auto_xy') && isequal(PlotParam.Auto_xy,1))
    0999      set(haxes,'DataAspectRatio',[1 1 1])
    1000 end
    1001 set(haxes,'YDir','normal')
    1002
    1003 %---------------------------------------------
    1004 %function for plotting vectors
    1005 %------------------------------------------------
    1006 %INPUT:
    1007 % haxes: handles of the plotting axes
    1008 %x,y,u,v: vectors coordinates and vector components to plot, arrays withb the same dimension
    1009 % scale: scaling factor for vector length representation
    1010 %colorlist(icolor,:): list of vector colors, dim (nbcolor,3), depending on color #i
    1011 %col_vec: matlab vector setting the color number #i for each velocity vector
    1012 function quiresetn(haxes,x,y,u,v,scale,colorlist,col_vec)
    1013
    1014 %define arrows
    1015 theta=0.5 ;%angle arrow
    1016 alpha=0.3 ;%length arrow
    1017 rot=alpha*[cos(theta) -sin(theta); sin(theta) cos(theta)]';
    1018 %find the existing lines
    1019 %h=findobj(gca,'Type','Line');% search existing lines in the current axes
    1020 h=findobj(haxes,'Tag','vel');% search existing lines in the current axes
    1021 sizh=size(h);
    1022 set(h,'EraseMode','xor');
    1023 set(haxes,'NextPlot','replacechildren');
    1024 %htext=findobj('Tag','scalevec');
    1025
    1026 %drawnow
    1027 %create lines (if no lines) or modify them
    1028 if ~isequal(size(col_vec),size(x))
    1029     col_vec=ones(size(x));% case of error in col_vec input
    1030 end
    1031 sizlist=size(colorlist);
    1032 ncolor=sizlist(1);
    1033
    1034 for icolor=1:ncolor
    1035     %determine the line positions for each color icolor
    1036     ind=find(col_vec==icolor);
    1037     xc=x(ind);
    1038     yc=y(ind);
    1039     uc=u(ind)*scale;
    1040     vc=v(ind)*scale;
    1041     n=size(xc);
    1042     xN=NaN*ones(size(xc));
    1043     matx=[xc(:) xc(:)+uc(:) xN(:)]';
    1044     matx=reshape(matx,1,3*n(2));
    1045     maty=[yc(:) yc(:)+vc(:) xN(:)]';
    1046     maty=reshape(maty,1,3*n(2));
    1047
    1048     %determine arrow heads
    1049     arrowplus=rot*[uc;vc];
    1050     arrowmoins=rot'*[uc;vc];
    1051     x1=xc+uc-arrowplus(1,:);
    1052     x2=xc+uc;
    1053     x3=xc+uc-arrowmoins(1,:);
    1054     y1=yc+vc-arrowplus(2,:);
    1055     y2=yc+vc;
    1056     y3=yc+vc-arrowmoins(2,:);
    1057     matxar=[x1(:) x2(:) x3(:) xN(:)]';
    1058     matxar=reshape(matxar,1,4*n(2));
    1059     matyar=[y1(:) y2(:) y3(:) xN(:)]';
    1060     matyar=reshape(matyar,1,4*n(2));
    1061     %draw the line or modify the existing ones
    1062     isn=isnan(colorlist(icolor,:));%test if color NaN
    1063     if 2*icolor > sizh(1) %if icolor exceeds the number of existing ones
    1064         axes(haxes)
    1065         if ~isn(1) %if the vectors are visible color not nan
    1066             if n(2)>0
    1067                 hold on
    1068                 line(matx,maty,'Color',colorlist(icolor,:),'Tag','vel');% plot new lines
    1069                 line(matxar,matyar,'Color',colorlist(icolor,:),'Tag','vel');% plot arrows
    1070             end
    1071         end
    1072     else
    1073         if isn(1)
    1074             delete(h(2*icolor-1))
    1075             delete(h(2*icolor))
    1076         else
    1077             set(h(2*icolor-1),'Xdata',matx,'Ydata',maty);
    1078             set(h(2*icolor-1),'Color',colorlist(icolor,:));
    1079             set(h(2*icolor-1),'EraseMode','xor');
    1080             set(h(2*icolor),'Xdata',matxar,'Ydata',matyar);
    1081             set(h(2*icolor),'Color',colorlist(icolor,:));
    1082             set(h(2*icolor),'EraseMode','xor');
    1083         end
    1084      end
    1085 end
    1086 if sizh(1) > 2*ncolor
    1087     for icolor=ncolor+1 : sizh(1)/2%delete additional objects
    1088         delete(h(2*icolor-1))
    1089         delete(h(2*icolor))
    1090     end
    1091 end
    1092
    1093 %---------------------------------------
    1094 %determine tick positions for colorbar
    1095 %------------------------------------
    1096 function YTick=colbartick(MinA,MaxA)
    1097 %determine tick positions with "simple" values between MinA and MaxA
    1098 YTick=0;%default
    1099 maxabs=max([abs(MinA) abs(MaxA)]);
    1100 if maxabs>0
    1101 ord=10^(floor(log10(maxabs)));%order of magnitude
    1102 div=1;
    1103 siz2=1;
    1104 while siz2<2
    1105 %     values=[-9:div:9];
    1106     values=-10:div:10;
    1107     ind=find((ord*values-MaxA)<0 & (ord*values-MinA)>0);%indices of 'values' such that MinA<ord*values<MaxA
    1108     siz=size(ind);
    1109     if siz(2)<4%if there are less than 4 selected values (4 levels)
    1110         values=[-9:0.5*div:9];
    1111         ind=find((ord*values-MaxA)<0 & (ord*values-MinA)>0);
    1112     end
    1113     siz2=size(ind,2);
    1114 %     siz2=siz(2)
    1115     div=div/10;
    1116 end
    1117 YTick=ord*values(ind);
    1118 end