[8]  1  %'plot_field': plot any field with the structure defined in the uvmat package


 2  %


 3  %


 4  % This function is used by uvmat to plot fields. It automatically chooses the representation


 5  % appropriate to the input field structure:


 6  % 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).


 7  % The input field structure is first tested by check_field_structure.m,


 8  % then split into blocks of related variables by find_field_indices.m.


 9  % The dimensionality of each block is obtained by this fuction


 10  % considering the presence of variables with the attribute .Role='coord_x'


 11  % and/or coord_y and/or coord_z (case of unstructured coordinates), or


 12  % dimension variables (case of matrices).


 13  %


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


 15  %


 16  % OUPUT:


 17  % PlotType: type of plot: 'text','line'(curve plot),'plane':2D view,'volume'


 18  % PlotParamOut: structure, representing the updated plotting parameters, in case of automatic scaling


 19  % haxes: handle of the plotting axis, when a new figure is created.


 20  %


 21  %INPUT


 22  % Data: structure describing the field to plot


 23  % (optional) .ListGlobalAttribute: cell listing the names of the global attributes


 24  % .Att_1,Att_2... : values of the global attributes


 25  % (requested) .ListVarName: list of variable names to select (cell array of char strings {'VarName1', 'VarName2',...} )


 26  % (requested) .VarDimName: list of dimension names for each element of .ListVarName (cell array of string cells)


 27  % .VarAttribute: cell of attributes for each element of .ListVarName (cell array of structures of the form VarAtt.key=value)


 28  % (requested) .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName


 29  %


 30  % Variable attribute .Role :


 31  % The only variable attribute used for plotting purpose is .Role which can take


 32  % the values


 33  % Role = 'scalar': (default) represents a scalar field


 34  % = 'coord_x', 'coord_y', 'coord_z': represents a separate set of


 35  % unstructured coordinate x, y or z


 36  % = 'vector': represents a vector field whose number of components


 37  % is given by the last dimension (called 'nb_dim')


 38  % = 'vector_x', 'vector_y', 'vector_z' :represents the x, y or z component of a vector


 39  % = 'warnflag' : provides a warning flag about the quality of data in a 'Field', default=0, no warning


 40  % = 'errorflag': provides an error flag marking false data,


 41  % default=0, no error. Different non zero values can represent different criteria of elimination.


 42 


 43 


 44  % additional elements characterizing the projection object (should not be necessary)


 45  % Data.Style : style of projection object


 46  % Data.XObject,.YObject: set of coordinates defining the object position;


 47  % Data.ProjMode=type of projection ;


 48  % Data.ProjAngle=angle of projection;


 49  % Data.DX,.DY,.DZ=increments;


 50  % Data.MaxY,MinY: min and max Y


 51 


 52  % 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.


 53  %


 54  % PlotParam: parameters for plotting, as read on the uvmat interface (by function 'read_plot_param.m')


 55  % scalars


 56  % .Scalar.MaxA: upper bound (saturation color) for the scalar representation, max(field) by default


 57  % .Scalar.MinA: lower bound (saturation) for the scalar representation, min(field) by default


 58  % .Scalar.AutoScal: =1 (default) lower and upper bounds of the scalar representation set to the min and max of the field


 59  % =0 lower and upper bound imposed by .AMax and .MinA


 60  % .Scalar.BW= 1 black and white representation imposed, =0 by default.


 61  % .Scalar.Contours= 1: represent scalars by contour plots (Matlab function 'contour'); =0 by default


 62  % .IncrA : contour interval


 63  %  vectors


 64  % .Vectors.VecScale: scale for the vector representation


 65  % .Vectors.AutoVec: =0 (default) automatic length for vector representation, =1: length set by .VecScale


 66  % .Vectors.HideFalse= 0 (default) false vectors represented in magenta, =1: false vectors not represented;


 67  % .Vectors.HideWarning= 0 (default) vectors marked by warnflag~=0 marked in black, 1: no warning representation;


 68  % .Vectors.decimate4 = 0 (default) all vectors reprtesented, =1: half of the vectors represented along each coordinate


 69  %  vector color


 70  % .Vectors.ColorCode= 'black','white': imposed color (default ='blue')


 71  % 'rgb', : three colors red, blue, green depending


 72  % on thresholds .colcode1 and .colcode2 on the input scalar value (C)


 73  % 'brg': like rgb but reversed color order (blue, green, red)


 74  % '64 colors': continuous color from blue to red (multijet)


 75  % .Vectors.colcode1 : first threshold for rgb, first value for'continuous'


 76  % .Vectors.colcode2 : second threshold for rgb, last value (saturation) for 'continuous'


 77  % .Vectors.FixedCbounds; =0 (default): the bounds on C representation are min and max, =1: they are fixed by .Minc and .MaxC


 78  % .Vectors.MinC = imposed minimum of the scalar field used for vector color;


 79  % .Vectors.MaxC = imposed maximum of the scalar field used for vector color;


 80  %


 81  % KeepLim:=0 (default) adjust axes limit to the X,Y data, =1: preserves the previous axes limits


 82  % PosColorbar: if not empty, display a colorbar for B&W images


 83  % imposed position of the colorbar (ex [0.821 0.471 0.019 0.445])


 84  %


 85  %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA


 86  % Copyright Joel Sommeria, 2008, LEGI / CNRSUJFINPG, sommeria@coriolislegi.org.


 87  %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA


 88  % This file is part of the toolbox UVMAT.


 89  %


 90  % UVMAT is free software; you can redistribute it and/or modify


 91  % it under the terms of the GNU General Public License as published by


 92  % the Free Software Foundation; either version 2 of the License, or


 93  % (at your option) any later version.


 94  %


 95  % UVMAT is distributed in the hope that it will be useful,


 96  % but WITHOUT ANY WARRANTY; without even the implied warranty of


 97  % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the


 98  % GNU General Public License (file UVMAT/COPYING.txt) for more details.


 99  %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA


 100 


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


 102  %default output


 103  if ~exist('PlotParam','var'),PlotParam=[];end;


 104  if ~exist('KeepLim','var'),KeepLim=0;end;


 105  if ~exist('PosColorbar','var'),PosColorbar=[];end;


 106  PlotType='text'; %default


 107  PlotParamOut=PlotParam;%default


 108 


 109  % check input structure


 110  [Data,errormsg]=check_field_structure(Data);


 111 


 112  if ~isempty(errormsg)


 113  msgbox_uvmat('ERROR',['input of plot_field/check_field_structure: ' errormsg])


 114  display(['input of plot_field/check_field_structure:: ' errormsg])


 115  return


 116  end


 117 


 118  testnewfig=1;%test to create a new figure (default)


 119  testzoomaxes=0;%test for the existence of a zoom secondary figure attached to the plotting axes


 120  if exist('haxes','var')


 121  if ishandle(haxes)


 122  if isequal(get(haxes,'Type'),'axes')


 123  axes(haxes)


 124  testnewfig=0;


 125  AxeData=get(haxes,'UserData');


 126  if isfield(AxeData,'ZoomAxes')&& ishandle(AxeData.ZoomAxes)


 127  if isequal(get(AxeData.ZoomAxes,'Type'),'axes')


 128  testzoomaxes=1;


 129  zoomaxes=AxeData.ZoomAxes;


 130  end


 131  end


 132  end


 133  end


 134  end


 135  if testnewfig% create a new figure and axes if the plotting axes does not exist


 136  hfig=figure;


 137  if isfield(Data,'IndexObj')&isfield(Data,'Style')&isfield(Data,'ProjMode')


[46]  138  figname=[num2str(Data.IndexObj) '' Data.Style];


[8]  139  set(hfig,'Name',figname)


 140  end


 141  testhandle=0;


 142  if isfield(PlotParam,'text_display_1')& ishandle(PlotParam.text_display_1)


 143  set(hfig,'UserData',PlotParam)


 144  testhandle=1;


 145  end


 146  set(hfig,'Units','normalized')


 147  set(hfig,'WindowButtonDownFcn','mouse_down')


 148  %set(hfig,'WindowButtonMotionFcn',{'mouse_motion',PlotParam})%set mouse action function


 149  set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action function


 150  set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse action function


 151  haxes=axes;


 152  set(haxes,'position',[0.13,0.2,0.775,0.73])


 153  end


 154  if isfield(PlotParam,'text_display_1')& ishandle(PlotParam.text_display_1)


 155  PlotParam=read_plot_param(PlotParam);


 156  end


 157  if testnewfig


 158  PlotParam.NextPlot='add'; %parameter for plot_profile and plot_hist


 159  end


 160  if isfield(PlotParam,'Auto_xy') && isequal(PlotParam.Auto_xy,1)


 161  set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio


 162  end


 163 


 164  % check the cells of fields :


 165  testnbdim=1;


 166  [CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Data);


 167 


 168  if ~isempty(errormsg)


 169  msgbox_uvmat('ERROR',['input of plot_field/find_field_indices: ' errormsg])


 170  display(['input of plot_field: ' errormsg])


 171  return


 172  end


 173  if ~isfield(Data,'NbDim') %& ~isfield(Data,'Style')%determine the space dimensionb if not defined: choose the kind of plot


 174  [Data.NbDim,imax]=max(NbDim);


 175  end


 176  if isequal(Data.NbDim,0) % TODO: chech whether this function is still used, replace by plot_profile ?


 177  % if isfield(Data,'Style') & isequal(Data.Style,'points')


 178  AxeData=plot_text(Data,haxes);


 179  PlotType='text';


 180  % else


 181  % [AxeData,haxes]=plot_hist(Data,haxes,PlotParam);


 182  % end


 183  elseif isequal(Data.NbDim,1)


 184  [AxeData,haxes]=plot_profile(Data,CellVarIndex,VarType,haxes,PlotParam);%


 185  if testzoomaxes


 186  [AxeData,zoomaxes,PlotParamOut]=plot_profile(Data,CellVarIndex,VarType,zoomaxes,PlotParam);


 187  AxeData.ZoomAxes=zoomaxes;


 188  end


 189  PlotType='line';


 190  elseif isequal(Data.NbDim,2)


 191  ind_select=find(NbDim>=2);


 192  if numel(ind_select)>2


 193  msgbox_uvmat('ERROR',['more than two fields to map'])


 194  display(['more than two fields to map'])


 195  return


 196  end


 197  [AxeData,haxes,PlotParamOut,PlotType]=plot_plane(Data,CellVarIndex(ind_select),VarType(ind_select),haxes,PlotParam,KeepLim,PosColorbar);


 198  if testzoomaxes


 199  [AxeData,zoomaxes,PlotParamOut]=plot_plane(Data,CellVarIndex(ind_select),VarType(ind_select),zoomaxes,PlotParam,1,PosColorbar);


 200  AxeData.ZoomAxes=zoomaxes;


 201  end


 202  elseif isequal(Data.NbDim,3)


 203  msgbox_uvmat('ERROR','volume plot not implemented yet')


 204  return


 205  else


 206  testnbdim=0;


 207  end


 208 


 209  %display (or delete) error message


 210  htext=findobj(haxes,'Tag','hTxt');


 211  if isfield(Data,'Txt')


 212  if isempty(htext)


 213  Xlim=get(haxes,'XLim');


 214  Ylim=get(haxes,'YLim');


 215  htext=text(Xlim(1),(Ylim(1)+Ylim(2))/2,Data.Txt,'Tag','hTxt','Color','r');


 216  set(htext,'Interpreter','none')


 217  else


 218  set(htext,'String',Data.Txt)


 219  end


 220  elseif ~isempty(htext)


 221  delete(htext)


 222  end


 223 


 224  % set graph aspect ratio


 225 


 226 


 227  set(haxes,'UserData',AxeData)


 228  %set(haxes,'Tag','uvmat');


 229 


 230 


 231  % %


 232  % function [AxeData,haxes]=plot_hist(Data,haxes,PlotParam)% TODO: chech whether this function is still used, replace by plot_profile ?


 233  % %


 234  % AxeData=get(haxes,'UserData'); %defau


 235  % hfig=get(haxes,'parent');


 236  % if ~isfield(Data,'ListVarName')


 237  % return


 238  % end


 239  % 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];


 240  % set(haxes,'ColorOrder',ColorOrder)


 241  % if isfield(PlotParam,'NextPlot')


 242  % set(haxes,'NextPlot',PlotParam.NextPlot)


 243  % end


 244  % charplot='''''';


 245  % iplot=0;


 246  % legend_str={};


 247  % label_str='';


 248  % textmean={};


 249  % plotstr='plot(';


 250  % for ilist=1:length(Data.ListVarName)


 251  % VarName=Data.ListVarName{ilist};


 252  % eval(['[' VarName 'hist,' VarName 'val]=hist(double(Data.' VarName '),100);']);%coordinate variable set as c


 253  % plotstr=[plotstr VarName 'val,' VarName 'hist,' charplot ','];


 254  % eval(['nbcomponent2=size(Data.' VarName ',2);']);


 255  % eval(['nbcomponent1=size(Data.' VarName ',1);']);


 256  % eval(['varmean=mean(double(Data.' VarName '));']);%mean value


 257  % textmean=[textmean; {[VarName 'mean= ' num2str(varmean,4)]}];


 258  % if nbcomponent1==1 nbcomponent2==1


 259  % legend_str=[legend_str {VarName}]; %variable with one component


 260  % else


 261  % for ic=1:min(nbcomponent1,nbcomponent2)


 262  % legend_str=[legend_str [VarName '_' num2str(ic)]]; %variable with severals components


 263  % % labeled by their index (e.g. color component)


 264  % end


 265  % end


 266  % label_str=[label_str ' ' VarName];


 267  % end


 268  % if ~isequal(plotstr,'plot(')


 269  % plotstr(end)=')';


 270  % eval(plotstr)


 271  % hlegend=findobj(hfig,'Tag','legend');%find existing legend on the plot


 272  % if ~isempty(hlegend)


 273  % legend_old=get(hlegend,'String');


 274  % if isequal(size(legend_old,1),size(legend_str,1))


 275  % legend_str=[legend_old legend_str];


 276  % end


 277  % end


 278  % legend(legend_str)


 279  % xlabel(label_str)


 280  % ylabel('nb values')


 281  % grid on


 282  % title_str='';


 283  % if isfield(Data,'filename')


 284  % [Path, title_str, ext]=fileparts(Data.filename);


 285  % title_str=[title_str ext];


 286  % end


 287  % if isfield(Data,'Action')


 288  % if ~isequal(title_str,'')


 289  % title_str=[title_str ', '];


 290  % end


 291  % title_str=[title_str Data.Action];


 292  % end


 293  % htitle=title(title_str);


 294  % set(htitle,'Interpreter','none')% desable tex interpreter


 295  % hlist=findobj(gcf,'Style','listbox');


 296  % if isempty(hlist)


 297  % uicontrol('Style','popupmenu','Position',[20 20 200 20],'String',textmean);


 298  % else


 299  % set(hlist(1),'String',textmean)


 300  % end


 301  % end


 302  % AxeData=Data;


 303 


 304 


 305  %


 306  function [AxeData,haxes]=plot_profile(data,CellVarIndex,VarType,haxes,PlotParam)


 307  %


[61]  308  %axes(haxes)


[8]  309  hfig=get(haxes,'parent');


 310  AxeData=data;


 311  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];


 312  set(haxes,'ColorOrder',ColorOrder)


 313  if isfield(PlotParam,'NextPlot')


 314  set(haxes,'NextPlot',PlotParam.NextPlot)


 315  end


[61]  316  % adjust the size of the plot to include the whole field, except if KeepLim=1


 317  if isfield(PlotParam,'FixedLimits') && isequal(PlotParam.FixedLimits,1) %adjust the graph limits*


 318  set(haxes,'XLimMode', 'manual')


 319  set(haxes,'YLimMode', 'manual')


 320  else


 321  set(haxes,'XLimMode', 'auto')


 322  set(haxes,'YLimMode', 'auto')


 323  end


[8]  324  legend_str={};


 325 


 326  %initiates string of the plot command


 327  plotstr='plot(';


 328  textmean={};


 329  abscissa_name='';


 330  coord_x_index=[];


 331  for icell=1:length(CellVarIndex)


 332  testfalse=0;


 333  VarIndex=CellVarIndex{icell};% indices of the selected variables in the list data.ListVarName


 334  DimCell=data.VarDimName{VarIndex(1)};


 335  if ischar(DimCell)


 336  DimCell={DimCell};


 337  end


 338  XName=DimCell{1}; %first dimension considered as abscissa


 339  if ~isempty(VarType{icell}.coord_x)


 340  coord_x_index=VarType{icell}.coord_x;


 341  else


 342  coord_x_index_cell=VarType{icell}.coord(1);


 343  if isequal(coord_x_index_cell,0)


 344  continue % the cell has no abscissa, skip it


 345  end


 346  if ~isempty(coord_x_index)&&~isequal(coord_x_index_cell,coord_x_index)


 347  continue %all the selected variables must have the same first dimension


 348  else


 349  coord_x_index=coord_x_index_cell;


 350  end


 351  end


 352  testplot=ones(size(data.ListVarName));%default test for plotted variables


 353  testcoordvar=0;


 354  charplot_0='''''';%default


 355  if isfield(data,'ObjectProjMode')& isequal(data.ObjectProjMode,'projection')


 356  charplot_0='''+''';


 357  end


 358  xtitle='';


 359 


 360  xtitle=data.ListVarName{coord_x_index};


 361  eval(['coord_x{icell}=data.' data.ListVarName{coord_x_index} ';']);%coordinate variable set as coord_x


 362  if isfield(data,'VarAttribute')&& numel(data.VarAttribute)>=coord_x_index && isfield(data.VarAttribute{coord_x_index},'units')


 363  xtitle=[xtitle '(' data.VarAttribute{coord_x_index}.units ')'];


 364  end


 365  eval(['coord_x{icell}=data.' data.ListVarName{coord_x_index} ';']);%coordinate variable set as coord_x


 366  testcoordvar=1;


 367  testplot(coord_x_index)=0;


 368  if ~isempty(VarType{icell}.ancillary')


 369  testplot(VarType{icell}.ancillary)=0;


 370  end


 371  if ~isempty(VarType{icell}.warnflag')


 372  testplot(VarType{icell}.warnflag)=0;


 373  end


 374  if ~isempty(VarType{icell}.discrete')


 375  charplot_0='''+''';


 376  else


 377  charplot_0='''''';


 378  end


 379  if isfield(data,'VarAttribute')


 380  VarAttribute=data.VarAttribute;


 381  for ivar=1:length(VarIndex)


 382  if length(VarAttribute)>=VarIndex(ivar) & isfield(VarAttribute{VarIndex(ivar)},'long_name')


 383  plotname{VarIndex(ivar)}=VarAttribute{VarIndex(ivar)}.long_name;


 384  else


 385  plotname{VarIndex(ivar)}=data.ListVarName{VarIndex(ivar)};%name for display in plot A METTRE


 386  end


 387  end


 388  end


 389  for ivar=1:length(VarIndex)


 390  if testplot(VarIndex(ivar))


 391  VarName=data.ListVarName{VarIndex(ivar)};


 392  eval(['data.' VarName '=squeeze(data.' VarName ');'])


 393  if isequal(VarName,'A')


 394  charplot='''''';


 395  else


 396  charplot=charplot_0;


 397  end


 398  plotstr=[plotstr 'coord_x{' num2str(icell) '},data.' VarName ',' charplot ','];


 399  eval(['nbcomponent2=size(data.' VarName ',2);']);


 400  eval(['nbcomponent1=size(data.' VarName ',1);']);


 401  if numel(coord_x{icell})==2


 402  coord_x{icell}=linspace(coord_x{icell}(1),coord_x{icell}(2),nbcomponent1);


 403  end


 404  eval(['varmean=mean(double(data.' VarName '));']);%mean value


 405  textmean=[textmean; {[VarName 'mean= ' num2str(varmean,4)]}];


 406  if nbcomponent1==1 nbcomponent2==1


 407  legend_str=[legend_str {VarName}]; %variable with one component


 408  else %variable with severals components


 409  for ic=1:min(nbcomponent1,nbcomponent2)


 410  legend_str=[legend_str [VarName '_' num2str(ic)]]; %variable with severals components


 411  end % labeled by their index (e.g. color component)


 412  end


 413  end


 414  end


 415  end


 416  if ~isequal(plotstr,'plot(')


 417  plotstr(end)=')';


[61]  418  %execute plot (instruction plotstr)


[8]  419  eval(plotstr)


 420  %%%%%


 421  grid on


 422  hxlabel=xlabel(xtitle);


 423  set(hxlabel,'Interpreter','none')% desable tex interpreter


 424  if length(legend_str)>=1


 425  hylabel=ylabel(legend_str{end});


 426  set(hylabel,'Interpreter','none')% desable tex interpreter


 427  end


 428  if ~isempty(legend_str)


 429  hlegend=findobj(hfig,'Tag','legend');


 430  if isempty(hlegend)


 431  hlegend=legend(legend_str);


 432  txt=ver;


 433  Release=txt(1).Release;


 434  relnumb=str2num(Release(3:4));


 435  if relnumb >= 14


 436  set(hlegend,'Interpreter','none')% desable tex interpreter


 437  end


 438  else


 439  legend_old=get(hlegend,'String');


 440  if isequal(size(legend_old,1),size(legend_str,1))&~isequal(legend_old,legend_str)


 441  set(hlegend,'String',[legend_old legend_str]);


 442  end


 443  end


 444  end


 445  title_str='';


 446  if isfield(data,'filename')


 447  [Path, title_str, ext]=fileparts(data.filename);


 448  title_str=[title_str ext];


 449  end


 450  if isfield(data,'Action')


 451  if ~isequal(title_str,'')


 452  title_str=[title_str ', '];


 453  end


 454  title_str=[title_str data.Action];


 455  end


 456  htitle=title(title_str);


 457  txt=ver;


 458  Release=txt(1).Release;


 459  relnumb=str2num(Release(3:4));


 460  if relnumb >= 14


 461  set(htitle,'Interpreter','none')% desable tex interpreter


 462  end


 463  % A REPRENDRE Mean


 464  % hlist=findobj(gcf,'Style','listbox','Tag','liststat');


 465  % if isempty(hlist)


 466  % 'text'


 467  % textmean


 468  % set(gca,'position',[0.13,0.2,0.775,0.73])


 469  % uicontrol('Style','popupmenu','Position',[20 20 200 20],'String',textmean,'Tag','liststat');


 470  % else


 471  % set(hlist(1),'String',textmean)


 472  % end


 473  end


 474 


 475 


 476  %


 477  % plot_plane


 478  %


 479  function [AxeData,haxes,PlotParamOut,PlotType]=plot_plane(Data,CellVarIndex,VarTypeCell,haxes,PlotParam,KeepLim,PosColorbar)


 480 


 481  %default plotting parameters


 482  PlotType='plane';%default


 483  if ~exist('PlotParam','var')


 484  PlotParam=[];


 485  end


 486  if ~isfield(PlotParam,'Scalar')


 487  PlotParam.Scalar=[];


 488  end


 489  if ~isfield(PlotParam,'Vectors')


 490  PlotParam.Vectors=[];


 491  end


 492  PlotParamOut=PlotParam;%default


 493 


 494  %plotting axes


 495  hfig=get(haxes,'parent');


 496  hcol=findobj(hfig,'Tag','Colorbar'); %look for colorbar axes


 497  hima=findobj(haxes,'Tag','ima');% search existing image in the current axes


 498  AxeData=get(haxes,'UserData'); %default


 499  if ~isstruct(AxeData)% AxeData must be a structure


 500  AxeData=[];


 501  end


 502  AxeData.NbDim=2;


 503  if isfield(Data,'ObjectCoord')


 504  AxeData.ObjectCoord=Data.ObjectCoord;


 505  end


 506 


 507  test_ima=0; %default: test for image or map plot


 508  test_vec=0; %default: test for vector plots


 509  test_black=0;


 510  test_false=0;


 511  test_C=0;


 512  XName='';


 513  x_units='';


 514  YName='';


 515  y_units='';


 516  for icell=1:length(CellVarIndex) % length(CellVarIndex) =1 or 2 (from the calling function)


 517  % VarIndex=CellVarIndex{icell};


 518  VarType=VarTypeCell{icell};


 519  ivar_X=VarType.coord_x; % defines (unique) index for the variable representing unstructured x coordinate (default =[])


 520  ivar_Y=VarType.coord_y; % defines (unique)index for the variable representing unstructured y coordinate (default =[])


 521  ivar_U=VarType.vector_x; % defines (unique) index for the variable representing x vector component (default =[])


 522  ivar_V=VarType.vector_y; % defines (unique) index for the variable representing y vector component (default =[])


 523  ivar_C=[VarType.scalar VarType.image VarType.color VarType.ancillary]; %defines index (indices) for the scalar or ancillary fields


 524  if numel(ivar_C)>1


 525  msgbox_uvmat('ERROR','error in plot_field: too many scalar inputs')


 526  return


 527  end


 528  ivar_F=VarType.warnflag; %defines index (unique) for warning flag variable


 529  ivar_FF=VarType.errorflag; %defines index (unique) for error flag variable


 530  ind_coord=find(VarType.coord);


 531  if numel(ind_coord)==2


 532  VarType.coord=VarType.coord(ind_coord);


 533  end


 534  idim_Y=[];


 535  test_grid=0;


 536  if ~isempty(ivar_U) && ~isempty(ivar_V)% vector components detected


 537  if test_vec


 538  msgbox_uvmat('ERROR','error in plot_field: attempt to plot two vector fields')


 539  return


 540  else


 541  test_vec=1;


 542  eval(['vec_U=Data.' Data.ListVarName{ivar_U} ';'])


 543  eval(['vec_V=Data.' Data.ListVarName{ivar_V} ';'])


 544  if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates or structured ones (then ivar_X and ivar_Y empty)


 545  eval(['vec_X=Data.' Data.ListVarName{ivar_X} ';'])


 546  eval(['vec_Y=Data.' Data.ListVarName{ivar_Y} ';'])


 547  elseif numel(VarType.coord)==2 & VarType.coord~=[0 0];%coordinates defines by dimension variables


 548  eval(['y=Data.' Data.ListVarName{VarType.coord(1)} ';'])


 549  eval(['x=Data.' Data.ListVarName{VarType.coord(2)} ';'])


 550  if numel(y)==2 % y defined by first and last values on aregular mesh


 551  y=linspace(y(1),y(2),size(vec_U,1));


 552  end


 553  if numel(x)==2 % y defined by first and last values on aregular mesh


 554  x=linspace(x(1),x(2),size(vec_U,2));


 555  end


 556  [vec_X,vec_Y]=meshgrid(x,y);


 557  else


 558  msgbox_uvmat('ERROR','error in plot_field: invalid coordinate definition for vector field')


 559  return


 560  end


 561  if ~isempty(ivar_C)


 562  eval(['vec_C=Data.' Data.ListVarName{ivar_C} ';']) ;


 563  vec_C=reshape(vec_C,1,numel(vec_C));


 564  test_C=1;


 565  end


 566  if ~isempty(ivar_F)%~(isfield(PlotParam.Vectors,'HideWarning')&& isequal(PlotParam.Vectors.HideWarning,1))


 567  if test_vec


 568  eval(['vec_F=Data.' Data.ListVarName{ivar_F} ';']) % warning flags for dubious vectors


 569  if ~(isfield(PlotParam.Vectors,'HideWarning') && isequal(PlotParam.Vectors.HideWarning,1))


 570  test_black=1;


 571  end


 572  end


 573  end


 574  if ~isempty(ivar_FF) %&& ~test_false


 575  if test_vec% TODO: deal with FF for structured coordinates


 576  eval(['vec_FF=Data.' Data.ListVarName{ivar_FF} ';']) % flags for false vectors


 577  end


 578  end


 579  end


 580  elseif ~isempty(ivar_C) %scalar or image


 581  if test_ima


 582  msgbox_uvmat('ERROR','attempt to plot two scalar fields or images')


 583  return


 584  end


 585  eval(['A=squeeze(Data.' Data.ListVarName{ivar_C} ');']) ;% scalar represented as color image


 586  test_ima=1;


 587  if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates or structured ones (then ivar_X and ivar_Y empty)


 588  XName=Data.ListVarName{ivar_X};


 589  YName=Data.ListVarName{ivar_Y};


 590  eval(['AX=Data.' XName ';'])


 591  eval(['AY=Data.' YName ';'])


 592  [A,AX,AY]=proj_grid(AX',AY',A',[],[],'np>256'); % interpolate on a grid


 593  if isfield(Data,'VarAttribute')


 594  if numel(Data.VarAttribute)>=ivar_X & isfield(Data.VarAttribute{ivar_X},'units')


 595  x_units=['(' Data.VarAttribute{ivar_X}.units ')'];


 596  end


 597  if numel(Data.VarAttribute)>=ivar_Y & isfield(Data.VarAttribute{ivar_Y},'units')


 598  y_units=['(' Data.VarAttribute{ivar_Y}.units ')'];


 599  end


 600  end


 601  elseif numel(VarType.coord)==2 %structured coordinates


 602  XName=Data.ListVarName{VarType.coord(2)};


 603  YName=Data.ListVarName{VarType.coord(1)};


 604  eval(['AY=Data.' Data.ListVarName{VarType.coord(1)} ';'])


 605  eval(['AX=Data.' Data.ListVarName{VarType.coord(2)} ';'])


 606  test_interp_X=0; %default, regularly meshed X coordinate


 607  test_interp_Y=0; %default, regularly meshed Y coordinate


 608  if isfield(Data,'VarAttribute')


 609  if numel(Data.VarAttribute)>=VarType.coord(2) & isfield(Data.VarAttribute{VarType.coord(2)},'units')


 610  x_units=['(' Data.VarAttribute{VarType.coord(2)}.units ')'];


 611  end


 612  if numel(Data.VarAttribute)>=VarType.coord(1) & isfield(Data.VarAttribute{VarType.coord(1)},'units')


 613  y_units=['(' Data.VarAttribute{VarType.coord(1)}.units ')'];


 614  end


 615  end


 616  if numel(AY)>2


 617  DAY=diff(AY);


 618  DAY_min=min(DAY);


 619  DAY_max=max(DAY);


 620  if sign(DAY_min)~=sign(DAY_max);% =1 for increasing values, 0 otherwise


 621  errormsg=['errror in plot_field.m: non monotonic dimension variable # ' ListVarName{VarType.coord(1)} ];


 622  return


 623  end


 624  test_interp_Y=(DAY_maxDAY_min)> 0.0001*abs(DAY_max);


 625  end


 626  if numel(AX)>2


 627  DAX=diff(AX);


 628  DAX_min=min(DAX);


 629  DAX_max=max(DAX);


 630  if sign(DAX_min)~=sign(DAX_max);% =1 for increasing values, 0 otherwise


 631  errormsg=['errror in plot_field.m: non monotonic dimension variable # ' ListVarName{VarType.coord(2)} ];


 632  return


 633  end


 634  test_interp_X=(DAX_maxDAX_min)> 0.0001*abs(DAX_max);


 635  end


 636  if test_interp_Y


 637  npxy(1)=max([256 floor((AY(end)AY(1))/DAY_min) floor((AY(end)AY(1))/DAY_max)]);


 638  yI=linspace(AY(1),AY(end),npxy(1));


 639  if ~test_interp_X


 640  xI=linspace(AX(1),AX(end),size(A,2));%default


 641  AX=xI;


 642  end


 643  end


 644  if test_interp_X


 645  npxy(1)=max([256 floor((AX(end)AX(1))/DAX_min) floor((AX(end)AX(1))/DAX_max)]);


 646  xI=linspace(AX(1),AX(end),npxy(2));


 647  if ~test_interp_Y


 648  yI=linspace(AY(1),AY(end),size(A,1));


 649  AY=yI;


 650  end


 651  end


 652  if test_interp_X  test_interp_Y


 653  [AX2D,AY2D]=meshgrid(AX,AY);


 654  A=interp2(AX2D,AY2D,double(A),xI,yI');


 655  end


 656  AX=[AX(1) AX(end)];% keep only the lower and upper bounds for image represnetation


 657  AY=[AY(1) AY(end)];


 658  else


 659  msgbox_uvmat('ERROR','error in plot_field: invalid coordinate definition ')


 660  return


 661  end


 662  x_label=[Data.ListVarName{ivar_X} '(' x_units ')'];


 663  end


 664  % if isfield(Data,'VarAttribute')


 665  % VarAttribute=Data.VarAttribute;


 666  % end


 667  end


 668 


 669  %%%%%%%%%%%%%%%%%%%%% image or scalar plot %%%%%%%%%%%%%%%%%%%%%%%%%%


 670 


 671  if ~isfield(PlotParam.Scalar,'Contours')


 672  PlotParam.Scalar.Contours=0; %default


 673  end


 674  PlotParamOut=PlotParam; %default


 675  if test_ima


 676  % distinguish B/W and color images


 677  np=size(A);%size of image


 678  siz=size(np);


 679  %set the color map


 680  if siz(2)==2 %for black and white images


 681  if ~isfield(PlotParam.Scalar,'AutoScal')


 682  PlotParam.Scalar.AutoScal=0;%default


 683  end


 684  if ~isfield(PlotParam.Scalar,'MinA')


 685  PlotParam.Scalar.MinA=[];%default


 686  end


 687  if ~isfield(PlotParam.Scalar,'MaxA')


 688  PlotParam.Scalar.MaxA=[];%default


 689  end


 690  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


 691  MinA=double(min(min(A)));


 692  else


 693  MinA=PlotParam.Scalar.MinA;


 694  end;


 695  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


 696  MaxA=double(max(max(A)));


 697  else


 698  MaxA=PlotParam.Scalar.MaxA;


 699  end;


 700  PlotParamOut.Scalar.MinA=MinA;


 701  PlotParamOut.Scalar.MaxA=MaxA;


 702  axes(haxes)


 703  if isequal(PlotParam.Scalar.Contours,1)


 704  if ~isempty(hima) & ishandle(hima)


 705  delete(hima)


 706  end


 707  if ~isfield(PlotParam.Scalar,'IncrA')


 708  PlotParam.Scalar.IncrA=[];


 709  end


 710  if isempty(PlotParam.Scalar.IncrA)%  PlotParam.Scalar.AutoScal==0


 711  cont=colbartick(MinA,MaxA);


 712  intercont=cont(2)cont(1);%default


 713  PlotParamOut.Scalar.IncrA=intercont;


 714  else


 715  intercont=PlotParam.Scalar.IncrA;


 716  end


 717  B=A;


 718  abscontmin=intercont*floor(MinA/intercont);


 719  abscontmax=intercont*ceil(MaxA/intercont);


 720  contmin=intercont*floor(min(min(B))/intercont);


 721  contmax=intercont*ceil(max(max(B))/intercont);


 722  cont_pos_plus=[0:intercont:contmax];


 723  cont_pos_min=[double(contmin):intercont:intercont];


 724  cont_pos=[cont_pos_min cont_pos_plus];


 725  sizpx=(AX(end)AX(1))/(np(2)1);


 726  sizpy=(AY(1)AY(end))/(np(1)1);


 727  x_cont=[AX(1):sizpx:AX(end)]; % pixel x coordinates for image display


 728  y_cont=[AY(1):sizpy:AY(end)]; % pixel x coordinates for image display


 729  txt=ver;%version of Matlab


 730  Release=txt(1).Release;


 731  relnumb=str2num(Release(3:4));


 732  if relnumb >= 14


 733  vec=linspace(0,1,(abscontmaxabscontmin)/intercont);%define a greyscale colormap with steps intercont


 734  map=[vec' vec' vec'];


 735  colormap(map);


 736  [var,hcontour]=contour(x_cont,y_cont,B,cont_pos);


 737  set(hcontour,'Fill','on')


 738  set(hcontour,'LineStyle','none')


 739  hold on


 740  end


 741  [var_p,hcontour_p]=contour(x_cont,y_cont,B,cont_pos_plus,'k');


 742  hold on


 743  [var_m,hcontour_m]=contour(x_cont,y_cont,B,cont_pos_min,':');


 744  set(hcontour_m,'LineColor',[1 1 1])


 745  hold off


 746  caxis([abscontmin abscontmax])


 747  colormap(map);


 748  end


 749  if ~isequal(PlotParam.Scalar.Contours,1)


 750  % rescale the grey levels with min and max, put a grey scale colorbar


 751  if (isfield(PlotParam.Scalar,'BW')& (isequal(PlotParam.Scalar.BW,1))isa(A,'uint8') isa(A,'uint16'))%images


 752  B=A;


 753  vec=linspace(0,1,255);%define a linear greyscale colormap


 754  map=[vec' vec' vec'];


 755  colormap(map); %grey scale color map


 756  else


 757  B=A;


 758  colormap('default'); % standard faulse colors for div, vort , scalar fields


 759  end


 760  end


 761  elseif siz(2)==3 %color images


 762  axes(haxes)


 763  B=uint8(A);


 764  MinA=0;


 765  MaxA=255;


 766  end


 767  if ~isequal(PlotParam.Scalar.Contours,1)


 768  %interpolate to increase resolution


 769  test_interp=1;


 770  if max(np) <= 64


 771  npxy=8*np;% increase the resolution 8 times


 772  elseif max(np) <= 128


 773  npxy=4*np;% increase the resolution 4 times


 774  elseif max(np) <= 256


 775  npxy=2*np;% increase the resolution 2 times


 776  else


 777  npxy=np;


 778  test_interp=0; % no interpolation done


 779  end


[55]  780  if test_interp==1%if we interpolate


[8]  781  x=linspace(AX(1),AX(2),np(2));


 782  y=linspace(AY(1),AY(2),np(1));


 783  [X,Y]=meshgrid(x,y);


 784  xi=linspace(AX(1),AX(2),npxy(2));


 785  yi=linspace(AY(1),AY(2),npxy(1));


 786  B = interp2(X,Y,double(B),xi,yi');


 787  end


 788  if isempty(hima)


 789  tag=get(haxes,'Tag');


 790  hima=imagesc(AX,AY,B,[MinA MaxA]);


 791  set(hima,'Tag','ima','HitTest','off')


 792  set(haxes,'Tag',tag);%preserve the axes tag (removed by image fct !!!)


 793  else


 794  set(hima,'CData',B);


 795  if MinA<MaxA


 796  caxis([MinA MaxA])


 797  else


 798  caxis([MinA MinA+1])


 799  end


 800  set(hima,'XData',AX);


 801  set(hima,'YData',AY);


 802  end


 803  end


 804  if ~isstruct(AxeData)


 805  AxeData=[];


 806  end


 807  AxeData.A=A;


 808  AxeData.AX=[AX(1) AX(end)];


 809  AxeData.AY=[AY(1) AY(end)];


 810  test_ima=1;


 811  %display the colorbar code for B/W images if Poscolorbar not empty


 812  if siz(2)==2 & exist('PosColorbar','var')& ~isempty(PosColorbar)


 813  if isempty(hcol)~ishandle(hcol)


 814  hcol=colorbar;%create new colorbar


 815  end


 816  if length(PosColorbar)==4


 817  set(hcol,'Position',PosColorbar)


 818  end


 819  YTick=0;%default


 820  if MaxA>MinA


 821  if isequal(PlotParam.Scalar.Contours,1)


 822  colbarlim=get(hcol,'YLim');


 823  scale_bar=(colbarlim(2)colbarlim(1))/(abscontmaxabscontmin);


 824  YTick=cont_pos(2:end1);


 825  YTick_scaled=colbarlim(1)+scale_bar*(YTickabscontmin);


 826  set(hcol,'YTick',YTick_scaled);


 827  elseif (isfield(PlotParam.Scalar,'BW') & isequal(PlotParam.Scalar.BW,1))isa(A,'uint8') isa(A,'uint16')%images


 828  hi=get(hcol,'children');


 829  if iscell(hi)%multiple images in colorbar


 830  hi=hi{1};


 831  end


 832  set(hi,'YData',[MinA MaxA])


 833  set(hi,'CData',[1:256]')


 834  set(hcol,'YLim',[MinA MaxA])


 835  YTick=colbartick(MinA,MaxA);


 836  set(hcol,'YTick',YTick)


 837  else


 838  hi=get(hcol,'children');


 839  if iscell(hi)%multiple images in colorbar


 840  hi=hi{1};


 841  end


 842  set(hi,'YData',[MinA MaxA])


 843  set(hi,'CData',[1:64]')


 844  YTick=colbartick(MinA,MaxA);


 845  set(hcol,'YLim',[MinA MaxA])


 846  set(hcol,'YTick',YTick)


 847  end


 848  set(hcol,'Yticklabel',num2str(YTick'));


 849  end


 850  elseif ishandle(hcol)


 851  delete(hcol); %erase existing colorbar if not needed


 852  end


 853  else%no scalar plot


 854  if ~isempty(hima) && ishandle(hima)


 855  delete(hima)


 856  end


 857  if ~isempty(hcol)&& ishandle(hcol)


 858  delete(hcol)


 859  end


 860  AxeData.A=[];


 861  AxeData.AX=[];


 862  AxeData.AY=[];


 863  PlotParamOut=rmfield(PlotParamOut,'Scalar');


 864  end


 865 


 866  %%%%%%%%%%%%%%%%%%%%% vector plot %%%%%%%%%%%%%%%%%%%%%%%%%%


 867  if test_vec


 868  %vector scale representation


 869  if size(vec_U,1)==numel(vec_Y) && size(vec_U,2)==numel(vec_X); % x, y coordinate variables


 870  [vec_X,vec_Y]=meshgrid(vec_X,vec_Y);


 871  end


 872  vec_X=reshape(vec_X,1,numel(vec_X));%reshape in matlab vectors


 873  vec_Y=reshape(vec_Y,1,numel(vec_Y));


 874  vec_U=reshape(vec_U,1,numel(vec_U));


 875  vec_V=reshape(vec_V,1,numel(vec_V));


 876  MinMaxX=max(vec_X)min(vec_X);


 877  MinMaxY=max(vec_Y)min(vec_Y);


 878  AxeData.Mesh=sqrt((MinMaxX*MinMaxY)/length(vec_X));


 879  if ~isfield(PlotParam.Vectors,'AutoVec')  isequal(PlotParam.Vectors.AutoVec,0) ~isfield(PlotParam.Vectors,'VecScale')...


 880  isempty(PlotParam.Vectors.VecScale)~isa(PlotParam.Vectors.VecScale,'double') %automatic vector scale


 881  scale=[];


 882  if test_false %remove false vectors


 883  indsel=find(AxeData.FF==0);%indsel =indices of good vectors


 884  else


 885  indsel=[1:numel(vec_X)];%


 886  end


 887  if isempty(vec_U)


 888  scale=1;


 889  else


 890  if isempty(indsel)


 891  MaxU=max(abs(vec_U));


 892  MaxV=max(abs(vec_V));


 893  else


 894  MaxU=max(abs(vec_U(indsel)));


 895  MaxV=max(abs(vec_V(indsel)));


 896  end


 897  scale=MinMaxX/(max(MaxU,MaxV)*50);


 898  PlotParam.Vectors.VecScale=scale;%update the 'scale' display


 899  end


 900  else


 901  scale=PlotParam.Vectors.VecScale; %impose the length of vector representation


 902  end;


 903 


 904  %record vectors on the plotting axes


 905  if test_C==0


 906  vec_C=ones(1,numel(vec_X));


 907  end


 908  AxeData.X=vec_X';


 909  AxeData.Y=vec_Y';


 910  AxeData.U=vec_U';


 911  AxeData.V=vec_V';


 912  AxeData.C=vec_C';


 913  if isempty(ivar_F)


 914  AxeData.F=[];


 915  else


 916  AxeData.F=vec_F';


 917  end


 918  if isempty(ivar_FF)


 919  AxeData.FF=[];


 920  else


 921  AxeData.FF=vec_FF';


 922  end


 923  % if isfield(Data,'W')


 924  % AxeData.W=Data.W;


 925  % end


 926 


 927  %decimate by a factor 2 in vector mesh(4 in nbre of vectors)


 928  if isfield(PlotParam.Vectors,'decimate4')&isequal(PlotParam.Vectors.decimate4,1)


 929  diffy=diff(vec_Y); %difference dy=vec_Y(i+1)vec_Y(i)


 930  dy_thresh=max(abs(diffy))/2;


 931  ind_jump=find(abs(diffy) > dy_thresh); %indices with diff(vec_Y)> max/2, detect change of line


 932  ind_sel=[1:ind_jump(1)];%select the first line


 933  for i=2:2:length(ind_jump)1


 934  ind_sel=[ind_sel [ind_jump(i)+1:ind_jump(i+1)]];% select the odd lines


 935  end


 936  nb_sel=length(ind_sel);


 937  ind_sel=ind_sel([1:2:nb_sel]);% take half the points on a line


 938  vec_X=vec_X(ind_sel);


 939  vec_Y=vec_Y(ind_sel);


 940  vec_U=vec_U(ind_sel);


 941  vec_V=vec_V(ind_sel);


 942  vec_C=vec_C(ind_sel);


 943  if ~isempty(ivar_F)


 944  vec_F=vec_F(ind_sel);


 945  end


 946  if ~isempty(ivar_FF)


 947  vec_FF=vec_FF(ind_sel);


 948  end


 949  end


 950 


 951  %get main level color code


 952  [colorlist,col_vec,PlotParamOut.Vectors]=set_col_vec(PlotParam.Vectors,vec_C);


 953  % take flags into account: add flag colors to the list of colors


 954  sizlist=size(colorlist);


 955  nbcolor=sizlist(1);


 956  if test_black


 957  nbcolor=nbcolor+1;


 958  colorlist(nbcolor,:)=[0 0 0]; %add black to the list of colors


 959  if ~isempty(ivar_FF)


 960  ind_flag=find(vec_F~=1 & vec_FF==0); %flag warning but not false


 961  else


 962  ind_flag=find(vec_F~=1);


 963  end


 964  col_vec(ind_flag)=nbcolor;


 965  end


 966  nbcolor=nbcolor+1;


 967  if ~isempty(ivar_FF)


 968  ind_flag=find(vec_FF~=0);


 969  if isfield(PlotParam.Vectors,'HideFalse') && PlotParam.Vectors.HideFalse==1


 970  colorlist(nbcolor,:)=[NaN NaN NaN];% no plot of false vectors


 971  else


 972  colorlist(nbcolor,:)=[1 0 1];% magenta color


 973  end


 974  col_vec(ind_flag)=nbcolor;


 975  end


 976  %plot vectors:


 977  quiresetn(haxes,vec_X,vec_Y,vec_U,vec_V,scale,colorlist,col_vec);


 978  else


 979  hvec=findobj(haxes,'Tag','vel');


 980  if ~isempty(hvec)


 981  delete(hvec);


 982  end


 983  AxeData.X=[];


 984  AxeData.Y=[];


 985  AxeData.U=[];


 986  AxeData.V=[];


 987  AxeData.C=[];


 988  AxeData.W=[];


 989  AxeData.F=[];


 990  AxeData.FF=[];


 991  AxeData.Mesh=[];


 992  PlotParamOut=rmfield(PlotParamOut,'Vectors');


 993  end


 994  if isfield(Data,'Z')


 995  AxeData.Z=Data.Z;% A REVOIR


 996  end


 997  listfields={'AY','AX','A','X','Y','U','V','C','W','F','FF'};


 998  listdim={'AY','AX',{'AY','AX'},'nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors'};


 999  Role={'coord_y','coord_x','scalar','coord_x','coord_y','vector_x','vector_y','scalar','vector_z','warnflag','errorflag'};


 1000  ind_select=[];


 1001  nbvar=0;


 1002  AxeData.ListVarName={};


 1003  AxeData.VarDimName={};


 1004  AxeData.VarAttribute={};


 1005  for ilist=1:numel(listfields)


 1006  eval(['testvar=isfield(AxeData,listfields{ilist}) && ~isempty(AxeData.' listfields{ilist} ');'])


 1007  if testvar


 1008  nbvar=nbvar+1;


 1009  AxeData.ListVarName{nbvar}=listfields{ilist};


 1010  AxeData.VarDimName{nbvar}=listdim{ilist};


 1011  AxeData.VarAttribute{nbvar}.Role=Role{ilist};


 1012  end


 1013  end


 1014 


 1015  % adjust the size of the plot to include the whole field, except if KeepLim=1


 1016  if ~(exist('KeepLim','var') && isequal(KeepLim,1)) %adjust the graph limits*


 1017  test_lim=0;


 1018  if test_vec


[46]  1019  Xlim=[min(vec_X) max(vec_X)];


 1020  Ylim=[min(vec_Y) max(vec_Y)];


[8]  1021  test_lim=1;


 1022  if test_ima%both background image and vectors coexist, take the wider bound


 1023  Xlim(1)=min(AX(1),Xlim(1));


 1024  Xlim(2)=max(AX(end),Xlim(2));


 1025  Ylim(1)=min(AY(end),Ylim(1));


 1026  Ylim(2)=max(AY(1),Ylim(2));


 1027  end


 1028  elseif test_ima %only image plot


 1029  Xlim(1)=min(AX(1),AX(end));


 1030  Xlim(2)=max(AX(1),AX(end));


 1031  Ylim(1)=min(AY(1),AY(end));


 1032  Ylim(2)=max(AY(1),AY(end));


 1033  test_lim=1;


 1034  end


[46]  1035  if test_lim


 1036  if Xlim(2)>Xlim(1)


 1037  set(haxes,'XLim',Xlim);% set x limits of frame in axes coordinates


 1038  end


 1039  if Ylim(2)>Ylim(1)


 1040  set(haxes,'YLim',Ylim);% set y limits of frame in axes coordinate


 1041  end


[8]  1042  end


 1043  end


 1044  if ~(isfield(PlotParam,'Auto_xy') && isequal(PlotParam.Auto_xy,1))


 1045  set(haxes,'DataAspectRatio',[1 1 1])


 1046  end


 1047  set(haxes,'YDir','normal')


 1048  set(get(haxes,'XLabel'),'String',[XName x_units]);


 1049  set(get(haxes,'YLabel'),'String',[YName y_units]);


 1050  %


 1051  %function for plotting vectors


 1052  %


 1053  %INPUT:


 1054  % haxes: handles of the plotting axes


 1055  %x,y,u,v: vectors coordinates and vector components to plot, arrays withb the same dimension


 1056  % scale: scaling factor for vector length representation


 1057  %colorlist(icolor,:): list of vector colors, dim (nbcolor,3), depending on color #i


 1058  %col_vec: matlab vector setting the color number #i for each velocity vector


 1059  function quiresetn(haxes,x,y,u,v,scale,colorlist,col_vec)


 1060 


 1061  %define arrows


 1062  theta=0.5 ;%angle arrow


 1063  alpha=0.3 ;%length arrow


 1064  rot=alpha*[cos(theta) sin(theta); sin(theta) cos(theta)]';


 1065  %find the existing lines


 1066  %h=findobj(gca,'Type','Line');% search existing lines in the current axes


 1067  h=findobj(haxes,'Tag','vel');% search existing lines in the current axes


 1068  sizh=size(h);


 1069  set(h,'EraseMode','xor');


 1070  set(haxes,'NextPlot','replacechildren');


 1071  %htext=findobj('Tag','scalevec');


 1072 


 1073  %drawnow


 1074  %create lines (if no lines) or modify them


 1075  if ~isequal(size(col_vec),size(x))


 1076  col_vec=ones(size(x));% case of error in col_vec input


 1077  end


 1078  sizlist=size(colorlist);


 1079  ncolor=sizlist(1);


 1080 


 1081  for icolor=1:ncolor


 1082  %determine the line positions for each color icolor


 1083  ind=find(col_vec==icolor);


 1084  xc=x(ind);


 1085  yc=y(ind);


 1086  uc=u(ind)*scale;


 1087  vc=v(ind)*scale;


 1088  n=size(xc);


 1089  xN=NaN*ones(size(xc));


 1090  matx=[xc(:) xc(:)+uc(:) xN(:)]';


 1091  matx=reshape(matx,1,3*n(2));


 1092  maty=[yc(:) yc(:)+vc(:) xN(:)]';


 1093  maty=reshape(maty,1,3*n(2));


 1094 


 1095  %determine arrow heads


 1096  arrowplus=rot*[uc;vc];


 1097  arrowmoins=rot'*[uc;vc];


 1098  x1=xc+ucarrowplus(1,:);


 1099  x2=xc+uc;


 1100  x3=xc+ucarrowmoins(1,:);


 1101  y1=yc+vcarrowplus(2,:);


 1102  y2=yc+vc;


 1103  y3=yc+vcarrowmoins(2,:);


 1104  matxar=[x1(:) x2(:) x3(:) xN(:)]';


 1105  matxar=reshape(matxar,1,4*n(2));


 1106  matyar=[y1(:) y2(:) y3(:) xN(:)]';


 1107  matyar=reshape(matyar,1,4*n(2));


 1108  %draw the line or modify the existing ones


 1109  isn=isnan(colorlist(icolor,:));%test if color NaN


 1110  if 2*icolor > sizh(1) %if icolor exceeds the number of existing ones


 1111  axes(haxes)


 1112  if ~isn(1) %if the vectors are visible color not nan


 1113  if n(2)>0


 1114  hold on


 1115  line(matx,maty,'Color',colorlist(icolor,:),'Tag','vel');% plot new lines


 1116  line(matxar,matyar,'Color',colorlist(icolor,:),'Tag','vel');% plot arrows


 1117  end


 1118  end


 1119  else


 1120  if isn(1)


 1121  delete(h(2*icolor1))


 1122  delete(h(2*icolor))


 1123  else


 1124  set(h(2*icolor1),'Xdata',matx,'Ydata',maty);


 1125  set(h(2*icolor1),'Color',colorlist(icolor,:));


 1126  set(h(2*icolor1),'EraseMode','xor');


 1127  set(h(2*icolor),'Xdata',matxar,'Ydata',matyar);


 1128  set(h(2*icolor),'Color',colorlist(icolor,:));


 1129  set(h(2*icolor),'EraseMode','xor');


 1130  end


 1131  end


 1132  end


 1133  if sizh(1) > 2*ncolor


 1134  for icolor=ncolor+1 : sizh(1)/2%delete additional objects


 1135  delete(h(2*icolor1))


 1136  delete(h(2*icolor))


 1137  end


 1138  end


 1139 


 1140  %


 1141  %determine tick positions for colorbar


 1142  %


 1143  function YTick=colbartick(MinA,MaxA)


 1144  %determine tick positions with "simple" values between MinA and MaxA


 1145  YTick=0;%default


 1146  maxabs=max([abs(MinA) abs(MaxA)]);


 1147  if maxabs>0


 1148  ord=10^(floor(log10(maxabs)));%order of magnitude


 1149  div=1;


 1150  siz2=1;


 1151  while siz2<2


 1152  % values=[9:div:9];


 1153  values=10:div:10;


 1154  ind=find((ord*valuesMaxA)<0 & (ord*valuesMinA)>0);%indices of 'values' such that MinA<ord*values<MaxA


 1155  siz=size(ind);


 1156  if siz(2)<4%if there are less than 4 selected values (4 levels)


 1157  values=[9:0.5*div:9];


 1158  ind=find((ord*valuesMaxA)<0 & (ord*valuesMinA)>0);


 1159  end


 1160  siz2=size(ind,2);


 1161  % siz2=siz(2)


 1162  div=div/10;


 1163  end


 1164  YTick=ord*values(ind);


 1165  end 
