source: trunk/src/plot_field.m @ 5

Last change on this file since 5 was 2, checked in by gostiaux, 14 years ago
  • Initial import
  • Add .m files in src
  • Add .fig files in src
  • Add .xml config files
File size: 47.6 KB
Line 
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 / CNRS-UJF-INPG, sommeria@coriolis-legi.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
101function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,KeepLim,PosColorbar)
102%default output
103if ~exist('PlotParam','var'),PlotParam=[];end;
104if ~exist('KeepLim','var'),KeepLim=0;end;
105if ~exist('PosColorbar','var'),PosColorbar=[];end;
106PlotType='text'; %default
107PlotParamOut=PlotParam;%default
108
109% check input structure
110[Data,errormsg]=check_field_structure(Data);
111
112if ~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
116end
117
118testnewfig=1;%test to create a new figure (default)
119testzoomaxes=0;%test for the existence of a zoom secondary figure attached to the plotting axes
120if exist('haxes','var')
121    if ishandle(haxes)
122        if isequal(get(haxes,'Type'),'axes')
123%             hfig=get(haxes,'Parent');
124            axes(haxes)
125            testnewfig=0;
126            AxeData=get(haxes,'UserData');
127            if isfield(AxeData,'ZoomAxes')&& ishandle(AxeData.ZoomAxes)
128                if isequal(get(AxeData.ZoomAxes,'Type'),'axes')
129                    testzoomaxes=1;
130                    zoomaxes=AxeData.ZoomAxes;
131                end
132            end
133        end
134    end
135end
136if testnewfig% create a new figure and axes if the plotting axes does not exist
137    hfig=figure;
138    if isfield(Data,'IndexObj')&isfield(Data,'Style')&isfield(Data,'ProjMode')
139        figname=[num2str(Data.IndexObj) '-' set_title(Data.Style,Data.ProjMode)];
140        set(hfig,'Name',figname)
141    end
142    testhandle=0;
143    if isfield(PlotParam,'text_display_1')& ishandle(PlotParam.text_display_1)
144        set(hfig,'UserData',PlotParam)
145        testhandle=1;
146    end
147    set(hfig,'Units','normalized')
148    set(hfig,'WindowButtonDownFcn','mouse_down')
149    %set(hfig,'WindowButtonMotionFcn',{'mouse_motion',PlotParam})%set mouse action function
150    set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action function
151    set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse action function
152    haxes=axes;
153    set(haxes,'position',[0.13,0.2,0.775,0.73])
154end
155if isfield(PlotParam,'text_display_1')& ishandle(PlotParam.text_display_1)
156    PlotParam=read_plot_param(PlotParam);   
157end
158if testnewfig
159  PlotParam.NextPlot='add'; %parameter for plot_profile and plot_hist
160end
161if isfield(PlotParam,'Auto_xy') && isequal(PlotParam.Auto_xy,1)
162    set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio
163end
164
165% check the cells of fields :
166testnbdim=1;
167[CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Data);
168
169if ~isempty(errormsg)
170    msgbox_uvmat('ERROR',['input of plot_field/find_field_indices: ' errormsg])
171    display(['input of plot_field: ' errormsg])
172    return
173end
174if ~isfield(Data,'NbDim') %& ~isfield(Data,'Style')%determine the space dimensionb if not defined: choose the kind of plot
175    [Data.NbDim,imax]=max(NbDim);
176end
177if isequal(Data.NbDim,0) % TODO: chech whether this function is still used, replace by plot_profile ?
178%     if isfield(Data,'Style') & isequal(Data.Style,'points')
179        AxeData=plot_text(Data,haxes);
180        PlotType='text';
181%     else
182%         [AxeData,haxes]=plot_hist(Data,haxes,PlotParam);
183%     end
184elseif isequal(Data.NbDim,1)
185    [AxeData,haxes]=plot_profile(Data,CellVarIndex,VarType,haxes,PlotParam);%
186    if testzoomaxes
187        [AxeData,zoomaxes,PlotParamOut]=plot_profile(Data,CellVarIndex,VarType,zoomaxes,PlotParam);
188        AxeData.ZoomAxes=zoomaxes;
189    end
190    PlotType='line';
191elseif isequal(Data.NbDim,2)
192    ind_select=find(NbDim>=2);
193    if numel(ind_select)>2
194        msgbox_uvmat('ERROR',['more than two fields to map'])
195        display(['more than two fields to map'])
196        return
197    end
198    [AxeData,haxes,PlotParamOut,PlotType]=plot_plane(Data,CellVarIndex(ind_select),VarType(ind_select),haxes,PlotParam,KeepLim,PosColorbar);
199    if testzoomaxes
200        [AxeData,zoomaxes,PlotParamOut]=plot_plane(Data,CellVarIndex(ind_select),VarType(ind_select),zoomaxes,PlotParam,1,PosColorbar);
201        AxeData.ZoomAxes=zoomaxes;
202    end
203elseif isequal(Data.NbDim,3)
204    msgbox_uvmat('ERROR','volume plot not implemented yet')
205    return
206    %plot_volume(haxes,Data,PlotParam)% A FAIRE
207    %PlotType='volume';
208else
209    testnbdim=0;
210end
211
212%display (or delete) error message
213htext=findobj(haxes,'Tag','hTxt');
214if isfield(Data,'Txt')
215    if isempty(htext)
216        Xlim=get(haxes,'XLim');
217        Ylim=get(haxes,'YLim');
218        htext=text(Xlim(1),(Ylim(1)+Ylim(2))/2,Data.Txt,'Tag','hTxt','Color','r');
219        set(htext,'Interpreter','none')
220    else
221        set(htext,'String',Data.Txt)
222    end
223elseif ~isempty(htext)
224    delete(htext)
225end
226
227% set graph aspect ratio
228
229
230set(haxes,'UserData',AxeData)
231%set(haxes,'Tag','uvmat');
232
233 
234% %-------------------------------------------
235% function [AxeData,haxes]=plot_hist(Data,haxes,PlotParam)% TODO: chech whether this function is still used, replace by plot_profile ?
236% %------------------------------------------
237% AxeData=get(haxes,'UserData'); %defau
238% hfig=get(haxes,'parent');
239% if ~isfield(Data,'ListVarName')
240%     return
241% end
242% 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];
243% set(haxes,'ColorOrder',ColorOrder)
244% if isfield(PlotParam,'NextPlot')
245%     set(haxes,'NextPlot',PlotParam.NextPlot)
246% end
247% charplot='''-''';
248% iplot=0;
249% legend_str={};
250% label_str='';
251% textmean={};
252% plotstr='plot(';
253% for ilist=1:length(Data.ListVarName)
254%     VarName=Data.ListVarName{ilist};
255%     eval(['[' VarName 'hist,' VarName 'val]=hist(double(Data.' VarName '),100);']);%coordinate variable set as c
256%     plotstr=[plotstr VarName 'val,' VarName 'hist,' charplot ','];
257%     eval(['nbcomponent2=size(Data.' VarName ',2);']);
258%     eval(['nbcomponent1=size(Data.' VarName ',1);']);
259%     eval(['varmean=mean(double(Data.' VarName '));']);%mean value
260%     textmean=[textmean; {[VarName 'mean= ' num2str(varmean,4)]}];
261%     if nbcomponent1==1| nbcomponent2==1
262%         legend_str=[legend_str {VarName}]; %variable with one component
263%     else
264%         for ic=1:min(nbcomponent1,nbcomponent2)
265%             legend_str=[legend_str [VarName '_' num2str(ic)]]; %variable with severals  components
266%                                                                % labeled by their index (e.g. color component)
267%         end
268%     end
269%     label_str=[label_str ' ' VarName];
270% end
271% if ~isequal(plotstr,'plot(')
272%     plotstr(end)=')';
273%     eval(plotstr)
274%     hlegend=findobj(hfig,'Tag','legend');%find existing legend on the plot
275%     if ~isempty(hlegend)
276%         legend_old=get(hlegend,'String');
277%         if isequal(size(legend_old,1),size(legend_str,1))
278%              legend_str=[legend_old legend_str];
279%         end
280%     end
281%     legend(legend_str)
282%     xlabel(label_str)
283%     ylabel('nb values')
284%      grid on
285%     title_str='';
286%     if isfield(Data,'filename')
287%        [Path, title_str, ext]=fileparts(Data.filename);
288%        title_str=[title_str ext];
289%     end
290%     if isfield(Data,'Action')
291%         if ~isequal(title_str,'')
292%             title_str=[title_str ', '];
293%         end
294%         title_str=[title_str Data.Action];
295%     end
296%     htitle=title(title_str);
297%     set(htitle,'Interpreter','none')% desable tex interpreter
298%     hlist=findobj(gcf,'Style','listbox');
299%     if isempty(hlist)
300%             uicontrol('Style','popupmenu','Position',[20 20 200 20],'String',textmean);
301%     else
302%             set(hlist(1),'String',textmean)
303%     end
304% end
305% AxeData=Data;
306
307
308%----------------------------------------------------------
309function [AxeData,haxes]=plot_profile(data,CellVarIndex,VarType,haxes,PlotParam)
310%-----------------------------------------------------------
311axes(haxes)
312hfig=get(haxes,'parent');
313AxeData=data;
314ColorOrder=[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];
315set(haxes,'ColorOrder',ColorOrder)
316if isfield(PlotParam,'NextPlot')
317    set(haxes,'NextPlot',PlotParam.NextPlot)
318end
319legend_str={};
320
321%initiates string of the plot command
322plotstr='plot(';
323textmean={};
324abscissa_name='';
325coord_x_index=[];
326for icell=1:length(CellVarIndex)
327    testfalse=0;
328    VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list data.ListVarName
329    DimCell=data.VarDimName{VarIndex(1)};
330    if ischar(DimCell)
331        DimCell={DimCell};
332    end
333    XName=DimCell{1}; %first dimension considered as abscissa
334    if ~isempty(VarType{icell}.coord_x)
335        coord_x_index=VarType{icell}.coord_x;
336    else
337        coord_x_index_cell=VarType{icell}.coord(1);
338        if isequal(coord_x_index_cell,0)
339            continue  % the cell has no abscissa, skip it
340        end
341        if ~isempty(coord_x_index)&&~isequal(coord_x_index_cell,coord_x_index)
342            continue %all the selected variables must have the same first dimension
343        else
344            coord_x_index=coord_x_index_cell;
345        end
346    end
347    testplot=ones(size(data.ListVarName));%default test for plotted variables
348    testcoordvar=0;
349    charplot_0='''-''';%default
350    if isfield(data,'ObjectProjMode')& isequal(data.ObjectProjMode,'projection')
351        charplot_0='''+''';
352    end
353    xtitle=''; 
354   
355    xtitle=data.ListVarName{coord_x_index};
356    eval(['coord_x{icell}=data.' data.ListVarName{coord_x_index} ';']);%coordinate variable set as coord_x
357    if isfield(data,'VarAttribute')&& numel(data.VarAttribute)>=coord_x_index && isfield(data.VarAttribute{coord_x_index},'units')
358         xtitle=[xtitle '(' data.VarAttribute{coord_x_index}.units ')'];
359    end
360    eval(['coord_x{icell}=data.' data.ListVarName{coord_x_index} ';']);%coordinate variable set as coord_x
361    testcoordvar=1;
362    testplot(coord_x_index)=0;
363    if ~isempty(VarType{icell}.ancillary')
364            testplot(VarType{icell}.ancillary)=0;
365    end
366    if ~isempty(VarType{icell}.warnflag')
367            testplot(VarType{icell}.warnflag)=0;
368    end
369    if ~isempty(VarType{icell}.discrete')
370         charplot_0='''+''';
371    else
372          charplot_0='''-''';
373    end
374%     if testcoordvar==0
375%         coord_x{icell}=[1:data.DimValue(DimIndices(1))];%abscissa by default if no coordinate variable
376%        % charplot_0='''-''';
377%     end
378    if isfield(data,'VarAttribute')
379        VarAttribute=data.VarAttribute;
380        for ivar=1:length(VarIndex)
381             if length(VarAttribute)>=VarIndex(ivar) & isfield(VarAttribute{VarIndex(ivar)},'long_name')
382                 plotname{VarIndex(ivar)}=VarAttribute{VarIndex(ivar)}.long_name;
383             else
384                 plotname{VarIndex(ivar)}=data.ListVarName{VarIndex(ivar)};%name for display in plot A METTRE
385             end
386        end
387    end
388    for ivar=1:length(VarIndex)
389        if testplot(VarIndex(ivar))
390            VarName=data.ListVarName{VarIndex(ivar)};
391            eval(['data.' VarName '=squeeze(data.' VarName ');'])
392            if isequal(VarName,'A')
393                charplot='''-''';
394            else
395                charplot=charplot_0;
396            end
397            plotstr=[plotstr 'coord_x{' num2str(icell) '},data.' VarName ',' charplot ','];
398            eval(['nbcomponent2=size(data.' VarName ',2);']);
399            eval(['nbcomponent1=size(data.' VarName ',1);']);
400            if numel(coord_x{icell})==2
401                coord_x{icell}=linspace(coord_x{icell}(1),coord_x{icell}(2),nbcomponent1);
402            end
403            eval(['varmean=mean(double(data.' VarName '));']);%mean value
404            textmean=[textmean; {[VarName 'mean= ' num2str(varmean,4)]}];
405            if nbcomponent1==1| nbcomponent2==1
406                legend_str=[legend_str {VarName}]; %variable with one component
407            else  %variable with severals  components
408                for ic=1:min(nbcomponent1,nbcomponent2)
409                    legend_str=[legend_str [VarName '_' num2str(ic)]]; %variable with severals  components
410                end                                                   % labeled by their index (e.g. color component)
411            end
412        end
413    end
414end
415if ~isequal(plotstr,'plot(')
416    plotstr(end)=')';
417                %execute plot (instruction  plotstr)
418    eval(plotstr)
419                %%%%%
420    grid on
421    hxlabel=xlabel(xtitle);
422    set(hxlabel,'Interpreter','none')% desable tex interpreter
423    if length(legend_str)>=1
424        hylabel=ylabel(legend_str{end});
425        set(hylabel,'Interpreter','none')% desable tex interpreter
426    end
427    if ~isempty(legend_str)
428        hlegend=findobj(hfig,'Tag','legend');
429        if isempty(hlegend)
430            hlegend=legend(legend_str);
431            txt=ver;
432            Release=txt(1).Release;
433            relnumb=str2num(Release(3:4));
434            if relnumb >= 14
435                set(hlegend,'Interpreter','none')% desable tex interpreter
436            end
437        else
438            legend_old=get(hlegend,'String');
439            if isequal(size(legend_old,1),size(legend_str,1))&~isequal(legend_old,legend_str)
440                set(hlegend,'String',[legend_old legend_str]);
441            end
442        end
443    end
444    title_str='';
445    if isfield(data,'filename')
446       [Path, title_str, ext]=fileparts(data.filename);
447       title_str=[title_str ext];
448    end
449    if isfield(data,'Action')
450        if ~isequal(title_str,'')
451            title_str=[title_str ', '];
452        end
453        title_str=[title_str data.Action];
454    end
455    htitle=title(title_str);
456    txt=ver;
457    Release=txt(1).Release;
458    relnumb=str2num(Release(3:4));
459    if relnumb >= 14
460        set(htitle,'Interpreter','none')% desable tex interpreter
461    end
462    % A REPRENDRE Mean
463%         hlist=findobj(gcf,'Style','listbox','Tag','liststat');
464%         if isempty(hlist)
465%             'text'
466%             textmean
467%             set(gca,'position',[0.13,0.2,0.775,0.73])
468%             uicontrol('Style','popupmenu','Position',[20 20 200 20],'String',textmean,'Tag','liststat');
469%         else
470%             set(hlist(1),'String',textmean)
471%         end
472end
473
474
475%---------------------------------------
476% plot_plane
477%----------------------------------------
478function [AxeData,haxes,PlotParamOut,PlotType]=plot_plane(Data,CellVarIndex,VarTypeCell,haxes,PlotParam,KeepLim,PosColorbar)
479
480%default plotting parameters
481PlotType='plane';%default
482if ~exist('PlotParam','var')
483    PlotParam=[];
484end
485if ~isfield(PlotParam,'Scalar')
486    PlotParam.Scalar=[];
487end
488if ~isfield(PlotParam,'Vectors')
489    PlotParam.Vectors=[];
490end
491PlotParamOut=PlotParam;%default
492
493%plotting axes
494hfig=get(haxes,'parent');
495hcol=findobj(hfig,'Tag','Colorbar'); %look for colorbar axes
496hima=findobj(haxes,'Tag','ima');% search existing image in the current axes
497AxeData=get(haxes,'UserData'); %default
498if ~isstruct(AxeData)% AxeData must be a structure
499    AxeData=[];
500end
501AxeData.NbDim=2;
502if isfield(Data,'ObjectCoord')
503    AxeData.ObjectCoord=Data.ObjectCoord;
504end
505
506test_ima=0; %default: test for image or map plot
507test_vec=0; %default: test for vector plots
508test_black=0;
509test_false=0;
510test_C=0;
511XName='';
512x_units='';
513YName='';
514y_units='';
515for icell=1:length(CellVarIndex) % length(CellVarIndex) =1 or 2 (from the calling function)
516%     VarIndex=CellVarIndex{icell};
517    VarType=VarTypeCell{icell};
518    ivar_X=VarType.coord_x; % defines (unique) index for the variable representing unstructured x coordinate (default =[])
519    ivar_Y=VarType.coord_y; % defines (unique)index for the variable representing unstructured y coordinate (default =[])
520    ivar_U=VarType.vector_x; % defines (unique) index for the variable representing x vector component (default =[])
521    ivar_V=VarType.vector_y; % defines (unique) index for the variable representing y vector component (default =[])
522    ivar_C=[VarType.scalar VarType.image VarType.color VarType.ancillary]; %defines index (indices) for the scalar or ancillary fields
523    if numel(ivar_C)>1
524        msgbox_uvmat('ERROR','error in plot_field: too many scalar inputs')
525        return
526    end
527    ivar_F=VarType.warnflag; %defines index (unique) for warning flag variable
528    ivar_FF=VarType.errorflag; %defines index (unique) for error flag variable
529    ind_coord=find(VarType.coord);
530    if numel(ind_coord)==2
531        VarType.coord=VarType.coord(ind_coord);
532    end
533    idim_Y=[]; 
534    test_grid=0;
535    if ~isempty(ivar_U) && ~isempty(ivar_V)% vector components detected
536        if test_vec
537            msgbox_uvmat('ERROR','error in plot_field: attempt to plot two vector fields')
538            return
539        else
540            test_vec=1;
541            eval(['vec_U=Data.' Data.ListVarName{ivar_U} ';'])
542            eval(['vec_V=Data.' Data.ListVarName{ivar_V} ';'])
543            if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates or structured ones (then ivar_X and ivar_Y empty)     
544                eval(['vec_X=Data.' Data.ListVarName{ivar_X} ';'])
545                eval(['vec_Y=Data.' Data.ListVarName{ivar_Y} ';'])
546            elseif numel(VarType.coord)==2 & VarType.coord~=[0 0];%coordinates defines by dimension variables
547                eval(['y=Data.' Data.ListVarName{VarType.coord(1)} ';'])
548                eval(['x=Data.' Data.ListVarName{VarType.coord(2)} ';'])
549                if numel(y)==2 % y defined by first and last values on aregular mesh
550                    y=linspace(y(1),y(2),size(vec_U,1));
551                end
552                if numel(x)==2 % y defined by first and last values on aregular mesh
553                    x=linspace(x(1),x(2),size(vec_U,2));
554                end
555                [vec_X,vec_Y]=meshgrid(x,y); 
556            else
557                msgbox_uvmat('ERROR','error in plot_field: invalid coordinate definition for vector field')
558                return
559            end
560            if ~isempty(ivar_C)
561                 eval(['vec_C=Data.' Data.ListVarName{ivar_C} ';']) ;
562                 vec_C=reshape(vec_C,1,numel(vec_C));
563                 test_C=1;
564            end
565            if ~isempty(ivar_F)%~(isfield(PlotParam.Vectors,'HideWarning')&& isequal(PlotParam.Vectors.HideWarning,1))
566                if test_vec
567                    eval(['vec_F=Data.' Data.ListVarName{ivar_F} ';']) % warning flags for  dubious vectors
568                    if  ~(isfield(PlotParam.Vectors,'HideWarning') && isequal(PlotParam.Vectors.HideWarning,1))
569                        test_black=1;
570                    end
571                end
572            end
573            if ~isempty(ivar_FF) %&& ~test_false
574                if test_vec% TODO: deal with FF for structured coordinates
575                    eval(['vec_FF=Data.' Data.ListVarName{ivar_FF} ';']) % flags for false vectors
576                end
577            end
578        end
579    elseif ~isempty(ivar_C) %scalar or image
580        if test_ima
581             msgbox_uvmat('ERROR','attempt to plot two scalar fields or images')
582            return
583        end
584        eval(['A=squeeze(Data.' Data.ListVarName{ivar_C} ');']) ;% scalar represented as color image
585        test_ima=1;
586        if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates or structured ones (then ivar_X and ivar_Y empty)
587            XName=Data.ListVarName{ivar_X};
588            YName=Data.ListVarName{ivar_Y};
589            eval(['AX=Data.' XName ';'])
590            eval(['AY=Data.' YName ';'])
591            [A,AX,AY]=proj_grid(AX',AY',A',[],[],'np>256');  % interpolate on a grid 
592            if isfield(Data,'VarAttribute')
593                if numel(Data.VarAttribute)>=ivar_X & isfield(Data.VarAttribute{ivar_X},'units')
594                    x_units=['(' Data.VarAttribute{ivar_X}.units ')'];
595                end
596                if numel(Data.VarAttribute)>=ivar_Y & isfield(Data.VarAttribute{ivar_Y},'units')
597                    y_units=['(' Data.VarAttribute{ivar_Y}.units ')'];
598                end
599            end       
600        elseif numel(VarType.coord)==2 %structured coordinates
601            XName=Data.ListVarName{VarType.coord(2)};
602            YName=Data.ListVarName{VarType.coord(1)};
603            eval(['AY=Data.' Data.ListVarName{VarType.coord(1)} ';'])
604            eval(['AX=Data.' Data.ListVarName{VarType.coord(2)} ';'])
605            test_interp_X=0; %default, regularly meshed X coordinate
606            test_interp_Y=0; %default, regularly meshed Y coordinate
607            if isfield(Data,'VarAttribute')
608                if numel(Data.VarAttribute)>=VarType.coord(2) & isfield(Data.VarAttribute{VarType.coord(2)},'units')
609                    x_units=['(' Data.VarAttribute{VarType.coord(2)}.units ')'];
610                end
611                if numel(Data.VarAttribute)>=VarType.coord(1) & isfield(Data.VarAttribute{VarType.coord(1)},'units')
612                    y_units=['(' Data.VarAttribute{VarType.coord(1)}.units ')'];
613                end
614            end 
615            if numel(AY)>2
616                DAY=diff(AY);
617                DAY_min=min(DAY);
618                DAY_max=max(DAY);
619                if sign(DAY_min)~=sign(DAY_max);% =1 for increasing values, 0 otherwise
620                     errormsg=['errror in plot_field.m: non monotonic dimension variable # ' ListVarName{VarType.coord(1)} ];
621                      return
622                end
623                test_interp_Y=(DAY_max-DAY_min)> 0.0001*abs(DAY_max);
624            end
625            if numel(AX)>2
626                DAX=diff(AX);
627                DAX_min=min(DAX);
628                DAX_max=max(DAX);
629                if sign(DAX_min)~=sign(DAX_max);% =1 for increasing values, 0 otherwise
630                     errormsg=['errror in plot_field.m: non monotonic dimension variable # ' ListVarName{VarType.coord(2)} ];
631                      return
632                end
633                test_interp_X=(DAX_max-DAX_min)> 0.0001*abs(DAX_max);
634            end 
635            if test_interp_Y         
636                npxy(1)=max([256 floor((AY(end)-AY(1))/DAY_min) floor((AY(end)-AY(1))/DAY_max)]);
637                yI=linspace(AY(1),AY(end),npxy(1));
638                if ~test_interp_X
639                    xI=linspace(AX(1),AX(end),size(A,2));%default
640                    AX=xI;
641                end
642            end
643            if test_interp_X 
644                npxy(1)=max([256 floor((AX(end)-AX(1))/DAX_min) floor((AX(end)-AX(1))/DAX_max)]);
645                xI=linspace(AX(1),AX(end),npxy(2));   
646                if ~test_interp_Y
647                   yI=linspace(AY(1),AY(end),size(A,1));
648                   AY=yI;
649                end
650            end
651            if test_interp_X || test_interp_Y               
652                [AX2D,AY2D]=meshgrid(AX,AY);
653                A=interp2(AX2D,AY2D,double(A),xI,yI');
654            end
655            AX=[AX(1) AX(end)];% keep only the lower and upper bounds for image represnetation
656            AY=[AY(1) AY(end)];
657        else
658            msgbox_uvmat('ERROR','error in plot_field: invalid coordinate definition ')
659            return
660        end
661          x_label=[Data.ListVarName{ivar_X} '(' x_units ')'];
662    end       
663%     if isfield(Data,'VarAttribute')
664%         VarAttribute=Data.VarAttribute;
665%     end   
666end
667
668%%%%%%%%%%%%%%%%%%%%%   image or scalar plot %%%%%%%%%%%%%%%%%%%%%%%%%%
669
670if ~isfield(PlotParam.Scalar,'Contours')
671    PlotParam.Scalar.Contours=0; %default
672end
673PlotParamOut=PlotParam; %default
674if test_ima
675    % distinguish B/W and color images
676    np=size(A);%size of image
677    siz=size(np);
678    %set the color map
679    if siz(2)==2 %for black and white images
680        if ~isfield(PlotParam.Scalar,'AutoScal')
681            PlotParam.Scalar.AutoScal=0;%default
682        end
683        if ~isfield(PlotParam.Scalar,'MinA')
684            PlotParam.Scalar.MinA=[];%default
685        end
686        if ~isfield(PlotParam.Scalar,'MaxA')
687            PlotParam.Scalar.MaxA=[];%default
688        end
689        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
690            MinA=double(min(min(A)));
691        else
692            MinA=PlotParam.Scalar.MinA; 
693        end;
694        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
695            MaxA=double(max(max(A)));
696        else
697            MaxA=PlotParam.Scalar.MaxA; 
698        end;
699        PlotParamOut.Scalar.MinA=MinA;
700        PlotParamOut.Scalar.MaxA=MaxA;
701        axes(haxes)
702        if isequal(PlotParam.Scalar.Contours,1)
703            if ~isempty(hima) & ishandle(hima)
704                delete(hima)
705            end
706            if ~isfield(PlotParam.Scalar,'IncrA')
707                PlotParam.Scalar.IncrA=[];
708            end
709            if isempty(PlotParam.Scalar.IncrA)% | PlotParam.Scalar.AutoScal==0
710                cont=colbartick(MinA,MaxA);
711                intercont=cont(2)-cont(1);%default
712                PlotParamOut.Scalar.IncrA=intercont;
713            else
714               intercont=PlotParam.Scalar.IncrA;
715            end
716            B=A;           
717            abscontmin=intercont*floor(MinA/intercont);
718            abscontmax=intercont*ceil(MaxA/intercont);
719            contmin=intercont*floor(min(min(B))/intercont);
720            contmax=intercont*ceil(max(max(B))/intercont);
721            cont_pos_plus=[0:intercont:contmax];
722            cont_pos_min=[double(contmin):intercont:-intercont];
723            cont_pos=[cont_pos_min cont_pos_plus];
724            sizpx=(AX(end)-AX(1))/(np(2)-1);
725            sizpy=(AY(1)-AY(end))/(np(1)-1);
726            x_cont=[AX(1):sizpx:AX(end)]; % pixel x coordinates for image display
727            y_cont=[AY(1):-sizpy:AY(end)]; % pixel x coordinates for image display
728            txt=ver;%version of Matlab
729            Release=txt(1).Release;
730            relnumb=str2num(Release(3:4));
731            if relnumb >= 14
732                    vec=linspace(0,1,(abscontmax-abscontmin)/intercont);%define a greyscale colormap with steps intercont
733                map=[vec' vec' vec'];
734                colormap(map);
735                [var,hcontour]=contour(x_cont,y_cont,B,cont_pos);       
736                set(hcontour,'Fill','on')
737                set(hcontour,'LineStyle','none')
738                hold on
739            end
740            [var_p,hcontour_p]=contour(x_cont,y_cont,B,cont_pos_plus,'k-');
741            hold on
742            [var_m,hcontour_m]=contour(x_cont,y_cont,B,cont_pos_min,':');
743            set(hcontour_m,'LineColor',[1 1 1])
744            hold off
745            caxis([abscontmin abscontmax])
746            colormap(map);
747        end
748        if ~isequal(PlotParam.Scalar.Contours,1)       
749            % rescale the grey levels with min and max, put a grey scale colorbar
750            if (isfield(PlotParam.Scalar,'BW')& (isequal(PlotParam.Scalar.BW,1))|isa(A,'uint8')| isa(A,'uint16'))%images
751                B=A;
752                vec=linspace(0,1,255);%define a linear greyscale colormap
753                map=[vec' vec' vec'];
754                colormap(map);  %grey scale color map
755            else
756                B=A;
757                colormap('default'); % standard faulse colors for div, vort , scalar fields
758            end
759        end
760    elseif siz(2)==3 %color images
761        axes(haxes)
762        B=uint8(A);
763        MinA=0;
764        MaxA=255;
765    end
766    if ~isequal(PlotParam.Scalar.Contours,1)
767        %interpolate to increase resolution
768        test_interp=1;
769        if max(np) <= 64
770            npxy=8*np;% increase the resolution 8 times
771        elseif max(np) <= 128
772            npxy=4*np;% increase the resolution 4 times
773        elseif max(np) <= 256
774            npxy=2*np;% increase the resolution 2 times
775        else
776            npxy=np;
777            test_interp=0; % no interpolation done
778        end
779        if test_interp==1%if we interpolate             
780            x=linspace(AX(1),AX(2),np(2));
781            y=linspace(AY(1),AY(2),np(1));
782            [X,Y]=meshgrid(x,y);
783            xi=linspace(AX(1),AX(2),npxy(2));
784            yi=linspace(AY(1),AY(2),npxy(1));
785            B = interp2(X,Y,double(B),xi,yi');
786        end       
787        if isempty(hima)
788            tag=get(haxes,'Tag');
789            hima=imagesc(AX,AY,B,[MinA MaxA]);
790            set(hima,'Tag','ima','HitTest','off')
791            set(haxes,'Tag',tag);%preserve the axes tag (removed by image fct !!!)       
792        else
793            set(hima,'CData',B);
794            if MinA<MaxA
795                caxis([MinA MaxA])
796            else
797                caxis([MinA MinA+1])
798            end
799            set(hima,'XData',AX);
800            set(hima,'YData',AY);
801        end
802    end
803    if ~isstruct(AxeData)
804        AxeData=[];
805    end
806    AxeData.A=A;
807    AxeData.AX=[AX(1) AX(end)];
808    AxeData.AY=[AY(1) AY(end)];
809    test_ima=1;
810    %display the colorbar code for B/W images if Poscolorbar not empty
811    if siz(2)==2 & exist('PosColorbar','var')& ~isempty(PosColorbar)
812        if isempty(hcol)|~ishandle(hcol)
813             hcol=colorbar;%create new colorbar
814        end
815        if length(PosColorbar)==4
816                 set(hcol,'Position',PosColorbar)           
817        end
818        YTick=0;%default
819        if MaxA>MinA
820            if isequal(PlotParam.Scalar.Contours,1)
821                colbarlim=get(hcol,'YLim');
822                scale_bar=(colbarlim(2)-colbarlim(1))/(abscontmax-abscontmin);               
823                YTick=cont_pos(2:end-1);
824                YTick_scaled=colbarlim(1)+scale_bar*(YTick-abscontmin);
825                set(hcol,'YTick',YTick_scaled);
826            elseif (isfield(PlotParam.Scalar,'BW') & isequal(PlotParam.Scalar.BW,1))|isa(A,'uint8')| isa(A,'uint16')%images
827                hi=get(hcol,'children');
828                if iscell(hi)%multiple images in colorbar
829                    hi=hi{1};
830                end
831                set(hi,'YData',[MinA MaxA])
832                set(hi,'CData',[1:256]')
833                set(hcol,'YLim',[MinA MaxA])
834                YTick=colbartick(MinA,MaxA);
835                set(hcol,'YTick',YTick)               
836            else
837                hi=get(hcol,'children');
838                if iscell(hi)%multiple images in colorbar
839                    hi=hi{1};
840                end
841                set(hi,'YData',[MinA MaxA])
842                set(hi,'CData',[1:64]')
843                YTick=colbartick(MinA,MaxA);
844                set(hcol,'YLim',[MinA MaxA])
845                set(hcol,'YTick',YTick)
846            end
847            set(hcol,'Yticklabel',num2str(YTick'));
848        end
849    elseif ishandle(hcol)
850        delete(hcol); %erase existing colorbar if not needed
851    end
852else%no scalar plot
853    if ~isempty(hima) && ishandle(hima)
854        delete(hima)
855    end
856    if ~isempty(hcol)&& ishandle(hcol)
857       delete(hcol)
858    end
859    AxeData.A=[];
860    AxeData.AX=[];
861    AxeData.AY=[];
862    PlotParamOut=rmfield(PlotParamOut,'Scalar');
863end
864
865%%%%%%%%%%%%%%%%%%%%%   vector plot %%%%%%%%%%%%%%%%%%%%%%%%%%
866if test_vec
867   %vector scale representation
868    if size(vec_U,1)==numel(vec_Y) && size(vec_U,2)==numel(vec_X); % x, y  coordinate variables
869        [vec_X,vec_Y]=meshgrid(vec_X,vec_Y);
870    end   
871    vec_X=reshape(vec_X,1,numel(vec_X));%reshape in matlab vectors
872    vec_Y=reshape(vec_Y,1,numel(vec_Y));
873    vec_U=reshape(vec_U,1,numel(vec_U));
874    vec_V=reshape(vec_V,1,numel(vec_V));
875    MinMaxX=max(vec_X)-min(vec_X);
876    MinMaxY=max(vec_Y)-min(vec_Y);
877    AxeData.Mesh=sqrt((MinMaxX*MinMaxY)/length(vec_X));
878    if  ~isfield(PlotParam.Vectors,'AutoVec') || isequal(PlotParam.Vectors.AutoVec,0)|| ~isfield(PlotParam.Vectors,'VecScale')...
879               ||isempty(PlotParam.Vectors.VecScale)||~isa(PlotParam.Vectors.VecScale,'double') %automatic vector scale
880        scale=[];
881        if test_false %remove false vectors
882            indsel=find(AxeData.FF==0);%indsel =indices of good vectors
883        else     
884            indsel=[1:numel(vec_X)];%
885        end
886        if isempty(vec_U)
887            scale=1;
888        else
889            if isempty(indsel)
890                MaxU=max(abs(vec_U));
891                MaxV=max(abs(vec_V));
892            else
893                MaxU=max(abs(vec_U(indsel)));
894                MaxV=max(abs(vec_V(indsel)));
895            end
896            scale=MinMaxX/(max(MaxU,MaxV)*50);
897            PlotParam.Vectors.VecScale=scale;%update the 'scale' display
898        end
899    else
900        scale=PlotParam.Vectors.VecScale;  %impose the length of vector representation
901    end;
902   
903    %record vectors on the plotting axes
904    if test_C==0
905        vec_C=ones(1,numel(vec_X));
906    end
907    AxeData.X=vec_X';
908    AxeData.Y=vec_Y';
909    AxeData.U=vec_U';
910    AxeData.V=vec_V';
911    AxeData.C=vec_C';
912    if isempty(ivar_F)
913        AxeData.F=[];
914    else
915        AxeData.F=vec_F';
916    end
917    if isempty(ivar_FF)
918        AxeData.FF=[];
919    else
920        AxeData.FF=vec_FF';
921    end
922%     if isfield(Data,'W')
923%         AxeData.W=Data.W;
924%     end
925   
926    %decimate by a factor 2 in vector mesh(4 in nbre of vectors)
927    if isfield(PlotParam.Vectors,'decimate4')&isequal(PlotParam.Vectors.decimate4,1)
928        diffy=diff(vec_Y); %difference dy=vec_Y(i+1)-vec_Y(i)
929        dy_thresh=max(abs(diffy))/2;
930        ind_jump=find(abs(diffy) > dy_thresh); %indices with diff(vec_Y)> max/2, detect change of line
931        ind_sel=[1:ind_jump(1)];%select the first line
932        for i=2:2:length(ind_jump)-1
933            ind_sel=[ind_sel [ind_jump(i)+1:ind_jump(i+1)]];% select the odd lines
934        end
935        nb_sel=length(ind_sel);
936        ind_sel=ind_sel([1:2:nb_sel]);% take half the points on a line
937        vec_X=vec_X(ind_sel);
938        vec_Y=vec_Y(ind_sel);
939        vec_U=vec_U(ind_sel);
940        vec_V=vec_V(ind_sel);
941        vec_C=vec_C(ind_sel);
942        if ~isempty(ivar_F)
943           vec_F=vec_F(ind_sel);
944        end
945        if ~isempty(ivar_FF)
946           vec_FF=vec_FF(ind_sel);
947        end
948    end
949   
950    %get main level color code
951    [colorlist,col_vec,PlotParamOut.Vectors]=set_col_vec(PlotParam.Vectors,vec_C);
952    % take flags into account: add flag colors to the list of colors
953    sizlist=size(colorlist);
954    nbcolor=sizlist(1);
955    if test_black
956       nbcolor=nbcolor+1;
957       colorlist(nbcolor,:)=[0 0 0]; %add black to the list of colors
958       if ~isempty(ivar_FF)
959            ind_flag=find(vec_F~=1 & vec_FF==0);  %flag warning but not false
960       else
961            ind_flag=find(vec_F~=1);
962       end
963       col_vec(ind_flag)=nbcolor;   
964    end
965    nbcolor=nbcolor+1;
966    if ~isempty(ivar_FF)
967        ind_flag=find(vec_FF~=0);
968        if isfield(PlotParam.Vectors,'HideFalse') && PlotParam.Vectors.HideFalse==1
969            colorlist(nbcolor,:)=[NaN NaN NaN];% no plot of false vectors
970        else
971            colorlist(nbcolor,:)=[1 0 1];% magenta color
972        end
973        col_vec(ind_flag)=nbcolor;
974    end
975    %plot vectors:
976    quiresetn(haxes,vec_X,vec_Y,vec_U,vec_V,scale,colorlist,col_vec);   
977else
978    hvec=findobj(haxes,'Tag','vel');
979    if ~isempty(hvec)
980        delete(hvec);
981    end
982    AxeData.X=[];
983    AxeData.Y=[];
984    AxeData.U=[];
985    AxeData.V=[];
986    AxeData.C=[];
987    AxeData.W=[];
988    AxeData.F=[];
989     AxeData.FF=[];
990    AxeData.Mesh=[];
991    PlotParamOut=rmfield(PlotParamOut,'Vectors');
992end
993if isfield(Data,'Z')
994    AxeData.Z=Data.Z;% A REVOIR
995end
996listfields={'AY','AX','A','X','Y','U','V','C','W','F','FF'};
997listdim={'AY','AX',{'AY','AX'},'nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors'};
998Role={'coord_y','coord_x','scalar','coord_x','coord_y','vector_x','vector_y','scalar','vector_z','warnflag','errorflag'};
999ind_select=[];
1000nbvar=0;
1001AxeData.ListVarName={};
1002AxeData.VarDimName={};
1003AxeData.VarAttribute={};
1004for ilist=1:numel(listfields)
1005    eval(['testvar=isfield(AxeData,listfields{ilist}) && ~isempty(AxeData.' listfields{ilist} ');'])
1006    if testvar
1007        nbvar=nbvar+1;
1008        AxeData.ListVarName{nbvar}=listfields{ilist};
1009        AxeData.VarDimName{nbvar}=listdim{ilist};
1010        AxeData.VarAttribute{nbvar}.Role=Role{ilist};
1011    end
1012end
1013
1014% adjust the size of the plot to include the whole field, except if KeepLim=1
1015if ~(exist('KeepLim','var') && isequal(KeepLim,1))  %adjust the graph limits*
1016        test_lim=0;
1017        if test_vec
1018            Xlim=[min(vec_X) max(vec_X)];
1019            Ylim=[min(vec_Y) max(vec_Y)];
1020            test_lim=1;
1021            if test_ima%both background image and vectors coexist, take the wider bound
1022                Xlim(1)=min(AX(1),Xlim(1));
1023                Xlim(2)=max(AX(end),Xlim(2));
1024                Ylim(1)=min(AY(end),Ylim(1));
1025                Ylim(2)=max(AY(1),Ylim(2));
1026            end
1027        elseif test_ima %only image plot
1028            Xlim(1)=min(AX(1),AX(end));
1029            Xlim(2)=max(AX(1),AX(end));
1030            Ylim(1)=min(AY(1),AY(end));
1031            Ylim(2)=max(AY(1),AY(end));
1032            test_lim=1;
1033        end
1034        if test_lim
1035            set(haxes,'XLim',Xlim);% set x limits of frame in axes coordinates
1036            set(haxes,'YLim',Ylim);% set y limits of frame in axes coordinate
1037        end
1038end
1039if ~(isfield(PlotParam,'Auto_xy') && isequal(PlotParam.Auto_xy,1))
1040     set(haxes,'DataAspectRatio',[1 1 1])
1041end
1042set(haxes,'YDir','normal')
1043set(get(haxes,'XLabel'),'String',[XName x_units]);
1044set(get(haxes,'YLabel'),'String',[YName y_units]);
1045%---------------------------------------------
1046%function for plotting vectors
1047%------------------------------------------------
1048%INPUT:
1049% haxes: handles of the plotting axes
1050%x,y,u,v: vectors coordinates and vector components to plot, arrays withb the same dimension
1051% scale: scaling factor for vector length representation
1052%colorlist(icolor,:): list of vector colors, dim (nbcolor,3), depending on color #i
1053%col_vec: matlab vector setting the color number #i for each velocity vector
1054function quiresetn(haxes,x,y,u,v,scale,colorlist,col_vec)
1055
1056%define arrows
1057theta=0.5 ;%angle arrow
1058alpha=0.3 ;%length arrow
1059rot=alpha*[cos(theta) -sin(theta); sin(theta) cos(theta)]';
1060%find the existing lines
1061%h=findobj(gca,'Type','Line');% search existing lines in the current axes
1062h=findobj(haxes,'Tag','vel');% search existing lines in the current axes
1063sizh=size(h);
1064set(h,'EraseMode','xor');
1065set(haxes,'NextPlot','replacechildren');
1066%htext=findobj('Tag','scalevec');
1067     
1068%drawnow
1069%create lines (if no lines) or modify them
1070if ~isequal(size(col_vec),size(x))
1071    col_vec=ones(size(x));% case of error in col_vec input
1072end
1073sizlist=size(colorlist);
1074ncolor=sizlist(1);
1075
1076for icolor=1:ncolor
1077    %determine the line positions for each color icolor
1078    ind=find(col_vec==icolor);
1079    xc=x(ind);
1080    yc=y(ind);
1081    uc=u(ind)*scale;
1082    vc=v(ind)*scale;
1083    n=size(xc);
1084    xN=NaN*ones(size(xc));
1085    matx=[xc(:) xc(:)+uc(:) xN(:)]';
1086    matx=reshape(matx,1,3*n(2));
1087    maty=[yc(:) yc(:)+vc(:) xN(:)]';
1088    maty=reshape(maty,1,3*n(2));
1089   
1090    %determine arrow heads
1091    arrowplus=rot*[uc;vc];
1092    arrowmoins=rot'*[uc;vc];
1093    x1=xc+uc-arrowplus(1,:);
1094    x2=xc+uc;
1095    x3=xc+uc-arrowmoins(1,:);
1096    y1=yc+vc-arrowplus(2,:);
1097    y2=yc+vc;
1098    y3=yc+vc-arrowmoins(2,:);
1099    matxar=[x1(:) x2(:) x3(:) xN(:)]';
1100    matxar=reshape(matxar,1,4*n(2));
1101    matyar=[y1(:) y2(:) y3(:) xN(:)]';
1102    matyar=reshape(matyar,1,4*n(2));
1103    %draw the line or modify the existing ones
1104    isn=isnan(colorlist(icolor,:));%test if color NaN
1105    if 2*icolor > sizh(1) %if icolor exceeds the number of existing ones
1106        axes(haxes)
1107        if ~isn(1) %if the vectors are visible color not nan
1108            if n(2)>0
1109                hold on
1110                line(matx,maty,'Color',colorlist(icolor,:),'Tag','vel');% plot new lines
1111                line(matxar,matyar,'Color',colorlist(icolor,:),'Tag','vel');% plot arrows
1112            end
1113        end
1114    else
1115        if isn(1)
1116            delete(h(2*icolor-1))
1117            delete(h(2*icolor))
1118        else
1119            set(h(2*icolor-1),'Xdata',matx,'Ydata',maty);
1120            set(h(2*icolor-1),'Color',colorlist(icolor,:));
1121            set(h(2*icolor-1),'EraseMode','xor');
1122            set(h(2*icolor),'Xdata',matxar,'Ydata',matyar);
1123            set(h(2*icolor),'Color',colorlist(icolor,:));
1124            set(h(2*icolor),'EraseMode','xor');
1125        end
1126     end
1127end
1128if sizh(1) > 2*ncolor
1129    for icolor=ncolor+1 : sizh(1)/2%delete additional objects
1130        delete(h(2*icolor-1))
1131        delete(h(2*icolor))
1132    end
1133end
1134
1135%---------------------------------------
1136%determine tick positions for colorbar
1137%------------------------------------
1138function YTick=colbartick(MinA,MaxA)
1139%determine tick positions with "simple" values between MinA and MaxA
1140YTick=0;%default
1141maxabs=max([abs(MinA) abs(MaxA)]);
1142if maxabs>0
1143ord=10^(floor(log10(maxabs)));%order of magnitude
1144div=1;
1145siz2=1;
1146while siz2<2
1147%     values=[-9:div:9];
1148    values=-10:div:10;
1149    ind=find((ord*values-MaxA)<0 & (ord*values-MinA)>0);%indices of 'values' such that MinA<ord*values<MaxA
1150    siz=size(ind);
1151    if siz(2)<4%if there are less than 4 selected values (4 levels)
1152        values=[-9:0.5*div:9];
1153        ind=find((ord*values-MaxA)<0 & (ord*values-MinA)>0);
1154    end
1155    siz2=size(ind,2);
1156%     siz2=siz(2)
1157    div=div/10;
1158end
1159YTick=ord*values(ind);
1160end
Note: See TracBrowser for help on using the repository browser.