source: trunk/src/plot_field.m @ 1200

Last change on this file since 1200 was 1200, checked in by sommeria, 24 hours ago

bug repaired for civ image rescale

File size: 63.1 KB
RevLine 
[201]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:
[292]6%     2D vector fields are represented by arrows, 2D scalar fields by grey scale images or contour plots, 1D fields are represented by usual plot with (abscissa, ordinate).
[201]7%  The input field structure is first tested by check_field_structure.m,
[512]8%  then split into blocks of related variables  by find_field_cells.m.
[292]9%  The dimensionality of each block is obtained  by this function
[201]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%
[625]14% function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,PosColorbar)
[201]15%
[822]16% OUPUT:
[866]17% PlotType: type of plot: 'text','line'(curve plot),'plane':2D view,'volume', or errormsg
[201]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%
[822]21%INPUT
[201]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%   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.
44%
[294]45%   PlotParam: structure containing the parameters for plotting, as read on the uvmat or view_field GUI (by function 'read_GUI.m').
46%      Contains three substructures:
[748]47%     .Axes: coordinate parameters:
[294]48%           .CheckFixLimits:=0 (default) adjust axes limit to the X,Y data, =1: preserves the previous axes limits
[748]49%     .Axes.CheckFixAspectRatio: =0 (default):automatic adjustment of the graph, keep 1 to 1 aspect ratio for x and y scales.
50%     .Axes.AspectRatio: imposed aspect ratio y/x of axis unit plots
[201]51%            --scalars--
52%    .Scalar.MaxA: upper bound (saturation color) for the scalar representation, max(field) by default
53%    .Scalar.MinA: lower bound (saturation) for the scalar representation, min(field) by default
[292]54%    .Scalar.CheckFixScal: =0 (default) lower and upper bounds of the scalar representation set to the min and max of the field
[201]55%               =1 lower and upper bound imposed by .AMax and .MinA
[421]56%    .Scalar.CheckBW= 1: black and white representation imposed, =0 color imposed (color scale or rgb),
57%                   =[]: automatic (B/W for integer positive scalars, color  else)
[292]58%    .Scalar.CheckContours= 1: represent scalars by contour plots (Matlab function 'contour'); =0 by default
[201]59%    .IncrA : contour interval
60%            -- vectors--
61%    .Vectors.VecScale: scale for the vector representation
[292]62%    .Vectors.CheckFixVec: =0 (default) automatic length for vector representation, =1: length set by .VecScale
63%    .Vectors.CheckHideFalse= 0 (default) false vectors represented in magenta, =1: false vectors not represented;
64%    .Vectors.CheckHideWarning= 0 (default) vectors marked by warnflag~=0 marked in black, 1: no warning representation;
65%    .Vectors.CheckDecimate4 = 0 (default) all vectors reprtesented, =1: half of  the vectors represented along each coordinate
[201]66%         -- vector color--
67%    .Vectors.ColorCode= 'black','white': imposed color  (default ='blue')
68%                        'rgb', : three colors red, blue, green depending
69%                        on thresholds .colcode1 and .colcode2 on the input  scalar value (C)
70%                        'brg': like rgb but reversed color order (blue, green, red)
71%                        '64 colors': continuous color from blue to red (multijet)
72%    .Vectors.colcode1 : first threshold for rgb, first value for'continuous'
73%    .Vectors.colcode2 : second threshold for rgb, last value (saturation) for 'continuous'
[292]74%    .Vectors.CheckFixedCbounds;  =0 (default): the bounds on C representation are min and max, =1: they are fixed by .Minc and .MaxC
[201]75%    .Vectors.MinC = imposed minimum of the scalar field used for vector color;
76%    .Vectors.MaxC = imposed maximum of the scalar field used for vector color;
77%
[546]78% PosColorbar: % if absent, no action on colorbar
79%              % if empty, suppress any existing colorbar
80%              % if not empty, display a colorbar for B&W images at position PosColorbar
81%                expressed in figure relative unit (ex [0.821 0.471 0.019 0.445])
[201]82
[924]83%=======================================================================
[1126]84% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
[924]85%   http://www.legi.grenoble-inp.fr
[1127]86%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
[924]87%
[201]88%     This file is part of the toolbox UVMAT.
[924]89%
[201]90%     UVMAT is free software; you can redistribute it and/or modify
[924]91%     it under the terms of the GNU General Public License as published
92%     by the Free Software Foundation; either version 2 of the license,
93%     or (at your option) any later version.
94%
[201]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
[924]98%     GNU General Public License (see LICENSE.txt) for more details.
99%=======================================================================
[201]100
[781]101function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam)
[247]102
[388]103%% default input and output
[1077]104if ~exist('PlotParam','var'),PlotParam=[];end
[201]105PlotType='text'; %default
[749]106if ~isfield(PlotParam,'Axes')
[748]107    PlotParam.Axes=[];
[582]108    if isfield(Data,'CoordUnit')
[748]109        PlotParam.Axes.CheckFixAspectRatio=1;
110        PlotParam.Axes.AspectRatio=1; %set axes equal by default if CoordUnit is defined
[582]111    end
[292]112end
[569]113PlotParamOut=PlotParam;%default
[201]114
[388]115%% check input structure
[1098]116[CellInfo,NbDimArray,errormsg]=find_field_cells(Data);
117if ~isempty(errormsg)
118    msgbox_uvmat('ERROR',['input of plot_field/find_field_cells: ' errormsg]);
119    return
120end
121index_0D=find(NbDimArray==0);
122index_1D=find(NbDimArray==1);
123index_2D=find(NbDimArray==2);%find 2D fields
124index_3D=find(NbDimArray>2,1);
125if ~isempty(index_3D)
126    msgbox_uvmat('ERROR','volume plot not implemented yet');
127    return
128end
[294]129
[388]130%% test axes and figure
[429]131testnewfig=1;%test to create a new figure (default)
132testzoomaxes=0;%test for the existence of a zoom secondary figure attached to the plotting axes
133if exist('haxes','var')
134    if ishandle(haxes)
135        if isequal(get(haxes,'Type'),'axes')
136            testnewfig=0;
137            AxeData=get(haxes,'UserData');
138            if isfield(AxeData,'ZoomAxes')&& ishandle(AxeData.ZoomAxes)
139                if isequal(get(AxeData.ZoomAxes,'Type'),'axes')
140                    testzoomaxes=1;
141                    zoomaxes=AxeData.ZoomAxes;
[388]142                end
143            end
144        end
[201]145    end
[429]146end
147
148%% create a new figure and axes if the plotting axes does not exist
149if testnewfig
150    hfig=figure;
151    set(hfig,'Units','normalized')
152    haxes=axes;
153    set(haxes,'position',[0.13,0.2,0.775,0.73])
[569]154    PlotParamOut.NextPlot='add'; %parameter for plot_profile
[429]155else
156    hfig=get(haxes,'parent');
157    set(0,'CurrentFigure',hfig)% the parent of haxes becomes the current figure
158    set(hfig,'CurrentAxes',haxes)%  haxes becomes the current axes of the parent figure
159end
160
161%% set axes properties
[748]162if isfield(PlotParamOut.Axes,'CheckFixLimits') && isequal(PlotParamOut.Axes.CheckFixLimits,1)  %adjust the graph limits
[429]163    set(haxes,'XLimMode', 'manual')
164    set(haxes,'YLimMode', 'manual')
165else
166    set(haxes,'XLimMode', 'auto')
167    set(haxes,'YLimMode', 'auto')
168end
[760]169
170if isfield(PlotParamOut.Axes,'CheckFixAspectRatio') && isequal(PlotParamOut.Axes.CheckFixAspectRatio,1)&&isfield(PlotParamOut.Axes,'AspectRatio')
171    set(haxes,'DataAspectRatioMode','manual')
172    set(haxes,'DataAspectRatio',[PlotParamOut.Axes.AspectRatio 1 1])
173else
174    set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio
175end
176
[429]177errormsg='';
178AxeData=get(haxes,'UserData');
179
[1200]180%% 2D plots
181if isempty(index_2D) %removes images or vector plots in the absence of 2D field plot
182    hima=findobj(haxes,'Tag','ima');% search existing image in the current axes
183    if  ishandle(hima)
184        delete(hima)
185    end
186    hvec=findobj(haxes,'Tag','vel');% search existing vectors in the current axes
187    if ~isempty(hvec)
188        delete(hvec);
189    end
[429]190else  %plot 2D field
[1200]191    %     if ~exist('PosColorbar','var'),PosColorbar=[];end;
[1176]192    [~,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellInfo(index_2D),haxes,PlotParamOut);
[429]193    AxeData.NbDim=2;
[1200]194    if testzoomaxes && isempty(errormsg)% updater the plot on the attached axis
195        PlotParamZoom=PlotParamOut;
196        PlotParamZoom.Axes.CheckFixLimits=1;
197        XLim=get(zoomaxes,'XLim');
198        YLim=get(zoomaxes,'YLim');
199        PlotParamZoom.Axes.MinX=XLim(1);
200        PlotParamZoom.Axes.MaxX=XLim(2);
201        PlotParamZoom.Axes.MinY=YLim(1);
202        PlotParamZoom.Axes.MaxY=YLim(2);
203        PlotParamZoom.Axes.CheckZoomFig=0;
204        [zoomaxes,~,~,errormsg]=plot_plane(Data,CellInfo(index_2D),zoomaxes,PlotParamZoom);
[429]205        AxeData.ZoomAxes=zoomaxes;
[201]206    end
[429]207end
208
209%% 1D plot (usual graph y vs x)
[1031]210if isempty(index_1D)|| ~isempty(index_2D)
[429]211    if ~isempty(haxes)
[530]212        plot_profile([],[],haxes);%removes usual praphs y vs x in the absence of 1D field plot
[201]213    end
[429]214else %plot 1D field (usual graph y vs x)
[644]215    CheckHold=0;
216    if isfield(PlotParam,'CheckHold')
217        CheckHold= PlotParam.CheckHold;
218    end       
[874]219    PlotParamOut=plot_profile(Data,CellInfo(index_1D),haxes,PlotParamOut,CheckHold);%
[872]220    if isempty(index_2D)
221        if isfield(PlotParamOut,'Vectors')
222            PlotParamOut=rmfield(PlotParamOut,'Vectors');
223        end
224        if isfield(PlotParamOut,'Scalar')
225            PlotParamOut=rmfield(PlotParamOut,'Scalar');
226        end
[871]227    end
[429]228    if testzoomaxes
[748]229        [zoomaxes,PlotParamOut.Axes]=plot_profile(Data,CellInfo(index_1D),zoomaxes,PlotParamOut.Axes,CheckHold);
[429]230        AxeData.ZoomAxes=zoomaxes;
[201]231    end
[429]232    PlotType='line';
233end
234
[760]235%% aspect ratio
236AspectRatio=get(haxes,'DataAspectRatio');
237PlotParamOut.Axes.AspectRatio=AspectRatio(1)/AspectRatio(2);
238
[429]239%% text display
[873]240if ~(isfield(PlotParamOut,'Axes')&&isfield(PlotParamOut.Axes,'TextDisplay')&&(PlotParamOut.Axes.TextDisplay)) % if text is not already given as statistics
241    htext=findobj(hfig,'Tag','TableDisplay');
[874]242    if ~isempty(htext)%&&~isempty(hchecktable)
[873]243        if isempty(index_0D)
[434]244        else
[873]245            errormsg=plot_text(Data,CellInfo(index_0D),htext);
246            set(htext,'visible','on')
[434]247        end
[873]248        set(hfig,'Unit','pixels');
249        set(htext,'Unit','pixels')
250        PosFig=get(hfig,'Position');
251        % case of no plot with view_field: only text display
252        if strcmp(get(hfig,'Tag'),'view_field')
253            if isempty(index_1D) && isempty(index_2D)% case of no plot: only text display
254                set(haxes,'Visible','off')
255                PosTable=get(htext,'Position');
256                set(hfig,'Position',[PosFig(1) PosFig(2)  PosTable(3) PosTable(4)])
257            else
258                set(haxes,'Visible','on')
259                set(hfig,'Position',[PosFig(1) PosFig(2)  877 677])%default size for view_field
260            end
261        end
[294]262    end
[201]263end
[388]264%% display error message
[201]265if ~isempty(errormsg)
[866]266    PlotType=errormsg;
[201]267    msgbox_uvmat('ERROR', errormsg)
268end
269
270%% update the parameters stored in AxeData
[429]271if ishandle(haxes)&&( ~isempty(index_2D)|| ~isempty(index_1D))
[388]272    if isfield(PlotParamOut,'MinX')
[569]273        AxeData.RangeX=[PlotParamOut.MinX PlotParamOut.MaxX];
274        AxeData.RangeY=[PlotParamOut.MinY PlotParamOut.MaxY];
[388]275    end
276    set(haxes,'UserData',AxeData)
277end
[201]278
[206]279%% update the plotted field stored in parent figure
[429]280if ~isempty(index_2D)|| ~isempty(index_1D)
281    FigData=get(hfig,'UserData');
[511]282    if strcmp(get(hfig,'tag'),'view_field')||strcmp(get(hfig,'tag'),'uvmat')
[1097]283        if ~isempty(get(haxes,'tag'))
[511]284        FigData.(get(haxes,'tag'))=Data;
[1097]285        end
[429]286        set(hfig,'UserData',FigData)
287    end
[388]288end
[292]289
[201]290%-------------------------------------------------------------------
[690]291% --- plot 0D fields: display data values without plot
292%------------------------------------------------------------------
[1200]293function errormsg=plot_text(FieldData,CellInfo,~)
[690]294
[581]295errormsg='';
[690]296VarIndex=[];
[1200]297for icell=1:length(CellInfo)   
[535]298    % select types of  variables to be projected
299    ListProj={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'};
300    check_proj=false(size(FieldData.ListVarName));
301    for ilist=1:numel(ListProj)
302        if isfield(CellInfo{icell},ListProj{ilist})
303            check_proj(CellInfo{icell}.(ListProj{ilist}))=1;
304        end
305    end
[690]306    VarIndex=[VarIndex find(check_proj)];
307end
308
309% data need to be displayed in a table
[881]310% if strcmp(get(htext,'Type'),'uitable')% display data in a table
311%     VarNameCell=cell(1,numel(VarIndex));% prepare list of variable names to display (titles of columns)
312%     VarLength=zeros(1,numel(VarIndex));  % default number of values for each variable
313%     for ivar=1:numel(VarIndex)
314%         VarNameCell{ivar}=FieldData.ListVarName{VarIndex(ivar)};
315%         VarLength(ivar)=numel(FieldData.(VarNameCell{ivar}));
316%     end
317%     set(htext,'ColumnName',VarNameCell)
318%     Data=cell(max(VarLength),numel(VarIndex));% prepare the table of data display
319%     
320%     for ivar=1:numel(VarIndex)
321%         VarValue=FieldData.(VarNameCell{ivar});
322%         VarValue=reshape(VarValue,[],1);% reshape values array in a column
323%         Data(1:numel(VarValue),ivar)=num2cell(VarValue);
324%     end
325%     set(htext,'Data',Data)
326% end
[690]327%         if numel(VarValue)>1 && numel(VarValue)<10 % case of a variable with several values
328%             for ind=1:numel(VarValue)
329%                 VarNameCell{1,ind}=[VarName '_' num2str(ind)];% indicate each value by an index
330%             end
331%         else
332%             VarNameCell={VarName};
333%         end
334%         if numel(VarValue)<10
335%             if isempty(VarValue)
336%                 VarValueCell={'[]'};
337%             else
338%                 VarValueCell=num2cell(VarValue);
339%             end
340%             if isempty(Data)
341%                 Data =[VarNameCell VarValueCell];
342%             else
343%                 Data =[Data [VarNameCell VarValueCell]];
344%             end
345%         else
346%             if isempty(Data)
347%                 Data =[VarNameCell; num2cell(VarValue)];
348%             else
349%                 Data =[Data [VarNameCell; {['size ' num2str(size(VarValue))]}]];
350%             end
351%         end
352%         if size(VarValue,1)==1
353%             txt=[VarName '=' num2str(VarValue)];
354%             txt_cell=[txt_cell;{txt}];
355%         end
356%     end
357% end
358% if strcmp(get(htext,'Type'),'uitable')% display data in a table
359%
360
361%     set(htext,'Data',Data(2:end,:))
362% else  % display in a text edit box
363%     set(htext,'String',txt_cell)
364%     set(htext,'UserData',txt_cell)% for temporary storage when the edit box is used for mouse display
365% end
[201]366
[429]367
[201]368%-------------------------------------------------------------------
[690]369% --- plot 1D fields (usual x,y plots)
370%-------------------------------------------------------------------
[1077]371%INPUT
372%    Data:   structure describing the field to plot
373%         (optional) .ListGlobalAttribute: cell listing the names of the global attributes
374%                    .Att_1,Att_2... : values of the global attributes
375%         (requested)  .ListVarName: list of variable names to select (cell array of  char strings {'VarName1', 'VarName2',...} )
376%         (requested)  .VarDimName: list of dimension names for each element of .ListVarName (cell array of string cells)
377%                      .VarAttribute: cell of attributes for each element of .ListVarName (cell array of structures of the form VarAtt.key=value)
378%         (requested) .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
379
380%            Variable attribute .Role :
381%    The only variable attribute used for plotting purpose is .Role which can take
382%    the values:
383%       Role = 'coord_x' or 'histo' to label the x coordinate
384%            ='coord_y' or 'discrete' to label the y coordinate, variables labelled as 'discrete'
385%           will be plotted as isolated points while variables labelled as 'coord_y' will be plotted as continuous lines
386%    other variables will not be taken into account for plot_profile
[201]387
[1077]388function PlotParamOut=plot_profile(Data,CellInfo,haxes,PlotParam,CheckHold)
389
[644]390%% initialization
[874]391if ~(exist('PlotParam','var')&&~isempty(PlotParam.Axes))
[292]392    Coordinates=[];
[874]393    PlotParamOut.Axes=Coordinates;
394else
395    Coordinates=PlotParam.Axes;
396    PlotParamOut=PlotParam;
[201]397end
398hfig=get(haxes,'parent');
[644]399legend_str={};
400
[1077]401%% suppress existing plot if empty Data
402if isempty(Data)
[201]403    hplot=findobj(haxes,'tag','plot_line');
404    if ~isempty(hplot)
405        delete(hplot)
406    end
407    hlegend=findobj(hfig,'tag','legend');
408    if ~isempty(hlegend)
409        delete(hlegend)
410    end
411    return
412end
413
[644]414%% set the colors of the successive plots (designed to produce rgb for the three components of color images)
[651]415ColorOrder=[1 0 0;0 1 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];
416set(hfig,'DefaultAxesColorOrder',ColorOrder)
[644]417if CheckHold
[690]418    set(haxes,'NextPlot','add')
[644]419else
420    set(haxes,'NextPlot','replace')
[201]421end
422
423%% prepare the string for plot command
[1177]424plotstr='hhh=plot(';
[1176]425if isfield(PlotParam,'Type')
426    switch PlotParam.Type
427        case 'semilogx'
428            plotstr='hhh=semilogx(';
429        case 'semilogy'
430            plotstr='hhh=semilogy(';
431        case 'loglog'
432            plotstr='hhh=loglog(';
433    end
[1175]434end
[201]435xtitle='';
436ytitle='';
[644]437test_newplot=~CheckHold;
[569]438MinX=[];
439MaxX=[];
440MinY_cell=[];
441MaxY_cell=[];
[1077]442testplot=ones(size(Data.ListVarName));%default test for plotted variables
[201]443%loop on input  fields
[530]444for icell=1:numel(CellInfo)
[1077]445    VarIndex=[CellInfo{icell}.YIndex CellInfo{icell}.YIndex_discrete];%  indices of the selected variables in the list Data.ListVarName
[1045]446    coord_x_index=CellInfo{icell}.XIndex;
[1077]447    coord_x_name{icell}=Data.ListVarName{coord_x_index};
448    coord_x{icell}=Data.(Data.ListVarName{coord_x_index});%coordinate variable set as coord_x
[569]449    if isempty(find(strcmp(coord_x_name{icell},coord_x_name(1:end-1)), 1)) %xtitle not already selected
[426]450        xtitle=[xtitle coord_x_name{icell}];
[1077]451        if isfield(Data,'VarAttribute')&& numel(Data.VarAttribute)>=coord_x_index && isfield(Data.VarAttribute{coord_x_index},'units')
452            xtitle=[xtitle '(' Data.VarAttribute{coord_x_index}.units '), '];
[426]453        else
454            xtitle=[xtitle ', '];
455        end
[201]456    end
[729]457    if ~isempty(coord_x{icell})
458        MinX(icell)=min(coord_x{icell});
459        MaxX(icell)=max(coord_x{icell});
460        testplot(coord_x_index)=0;
461        if isfield(CellInfo{icell},'VarIndex_ancillary')
462            testplot(CellInfo{icell}.VarIndex_ancillary)=0;
463        end
464        if isfield(CellInfo{icell},'VarIndex_warnflag')
465            testplot(CellInfo{icell}.VarIndex_warnflag)=0;
466        end
[1077]467        if isfield(Data,'VarAttribute')
468            VarAttribute=Data.VarAttribute;
[729]469            for ivar=1:length(VarIndex)
470                if length(VarAttribute)>=VarIndex(ivar) && isfield(VarAttribute{VarIndex(ivar)},'long_name')
471                    plotname{VarIndex(ivar)}=VarAttribute{VarIndex(ivar)}.long_name;
472                else
[1077]473                    plotname{VarIndex(ivar)}=Data.ListVarName{VarIndex(ivar)};%name for display in plot A METTRE
[729]474                end
[201]475            end
476        end
[1048]477        if isfield(CellInfo{icell},'YIndex_discrete')&& ~isempty(CellInfo{icell}.YIndex_discrete)
[729]478            charplot_0='''+''';
479        else
480            charplot_0='''-''';
481        end
482        MinY=[];
483        MaxY=[];%default
484       
485        nbplot=0;
486        for ivar=1:length(VarIndex)
487            if testplot(VarIndex(ivar))
[1077]488                VarName=Data.ListVarName{VarIndex(ivar)};
[729]489                nbplot=nbplot+1;
490                ytitle=[ytitle VarName];
[1077]491                if isfield(Data,'VarAttribute')&& numel(Data.VarAttribute)>=VarIndex(ivar) && isfield(Data.VarAttribute{VarIndex(ivar)},'units')
492                    ytitle=[ytitle '(' Data.VarAttribute{VarIndex(ivar)}.units '), '];
[729]493                else
494                    ytitle=[ytitle ', '];
495                end
[1077]496                eval(['Data.' VarName '=squeeze(Data.' VarName ');'])
497                MinY(ivar)=min(min(Data.(VarName)));
498                MaxY(ivar)=max(max(Data.(VarName)));
499                plotstr=[plotstr 'coord_x{' num2str(icell) '},Data.' VarName ',' charplot_0 ','];
500                eval(['nbcomponent2=size(Data.' VarName ',2);']);
501                eval(['nbcomponent1=size(Data.' VarName ',1);']);
[729]502                if numel(coord_x{icell})==2
503                    coord_x{icell}=linspace(coord_x{icell}(1),coord_x{icell}(2),nbcomponent1);
504                end
505                if nbcomponent1==1|| nbcomponent2==1
506                    legend_str=[legend_str {VarName}]; %variable with one component
507                else  %variable with severals  components
508                    for ic=1:min(nbcomponent1,nbcomponent2)
509                        legend_str=[legend_str [VarName '_' num2str(ic)]]; %variable with severals  components
510                    end                                                   % labeled by their index (e.g. color component)
511                end
[201]512            end
513        end
[729]514        if ~isempty(MinY)
515            MinY_cell(icell)=min(MinY);
516            MaxY_cell(icell)=max(MaxY);
517        end
[201]518    end
519end
520
521%% activate the plot
[644]522if  ~isequal(plotstr,'hhh=plot(') 
[201]523    set(hfig,'CurrentAxes',haxes)
524    tag=get(haxes,'tag');   
525    %%%
526    plotstr=[plotstr '''tag'',''plot_line'');'];   
527    eval(plotstr)                  %execute plot (instruction  plotstr)
528    %%%
[651]529    set(haxes,'tag',tag)% restitute the axes tag (removed by the command plot)
530    set(haxes,'ColorOrder',ColorOrder)% restitute the plot color order (to get red green blue for histograms or cuts of color images)
[201]531    grid(haxes, 'on')
532    hxlabel=xlabel(xtitle(1:end-2));% xlabel (removes ', ' at the end)
533    set(hxlabel,'Interpreter','none')% desable tex interpreter
534    if length(legend_str)>=1
535        hylabel=ylabel(ytitle(1:end-2));% ylabel (removes ', ' at the end)
536        set(hylabel,'Interpreter','none')% desable tex interpreter
537    end
538    if ~isempty(legend_str)
539        hlegend=findobj(hfig,'Tag','legend');
540        if isempty(hlegend)
541            hlegend=legend(legend_str);
542            txt=ver('MATLAB');
543            Release=txt.Release;
544            relnumb=str2double(Release(3:4));% should be changed to Version for better compatibility
545            if relnumb >= 14
546                set(hlegend,'Interpreter','none')% desable tex interpreter
547            end
548        else
549            legend_old=get(hlegend,'String');
550            if isequal(size(legend_old,1),size(legend_str,1))&&~isequal(legend_old,legend_str)
551                set(hlegend,'String',[legend_old legend_str]);
552            end
553        end
554    end
555    title_str='';
[1077]556    if isfield(Data,'filename')
557       [Path, title_str, ext]=fileparts(Data.filename);
[201]558       title_str=[title_str ext];
559    end
[1077]560    if isfield(Data,'Action')&&isfield(Data.Action,'ActionName')
[201]561        if ~isequal(title_str,'')
562            title_str=[title_str ', '];
563        end
[1077]564        title_str=[title_str Data.Action.ActionName];
[201]565    end
566    htitle=title(title_str);
[428]567    set(htitle,'Interpreter','none')% desable tex interpreter
[201]568end
569
570%% determine axes bounds
[294]571fix_lim=isfield(Coordinates,'CheckFixLimits') && Coordinates.CheckFixLimits;
[569]572check_lim=isfield(Coordinates,'MinX')&&isfield(Coordinates,'MaxX')&&isfield(Coordinates,'MinY')&&isfield(Coordinates,'MaxY');
[201]573if fix_lim
[569]574    if ~check_lim
575        fix_lim=0; %free limits if limits are not set,
[221]576    end
[201]577end
[294]578if fix_lim
579    set(haxes,'XLim',[Coordinates.MinX Coordinates.MaxX])
580    set(haxes,'YLim',[Coordinates.MinY Coordinates.MaxY])
[569]581else
582    if ~isempty(MinX)
583        if check_lim
[874]584            Coordinates.MinX=min(min(MinX),Coordinates.MinX);
585            Coordinates.MaxX=max(max(MaxX),Coordinates.MaxX);
[569]586        else
[874]587            Coordinates.MinX=min(MinX);
588            Coordinates.MaxX=max(MaxX);
[569]589        end
590    end
591    if ~isempty(MinY_cell)
592        if check_lim
[874]593            Coordinates.MinY=min(min(MinY_cell),Coordinates.MinY);
594            Coordinates.MaxY=max(max(MaxY_cell),Coordinates.MaxY);
[569]595        else
[874]596            Coordinates.MinY=min(MinY_cell);
597            Coordinates.MaxY=max(MaxY_cell);
[569]598        end
599    end
[201]600end
601
[428]602%% determine plot aspect ratio
[789]603if isfield(Coordinates,'CheckFixAspectRatio') && isequal(Coordinates.CheckFixAspectRatio,1)&&isfield(Coordinates,'AspectRatio')
604    set(haxes,'DataAspectRatioMode','manual')
605    set(haxes,'DataAspectRatio',[Coordinates.AspectRatio 1 1])
606else
607    set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio
608    AspectRatio=get(haxes,'DataAspectRatio');
[874]609    Coordinates.AspectRatio=AspectRatio(1)/AspectRatio(2);
[789]610end
[874]611PlotParamOut.Axes= Coordinates;
[428]612
[871]613%% give statistics for pdf
[880]614%ind_var=find(testplot);
[881]615TableData={'Variable';'SampleNbr';'bin size';'Mean';'RMS';'Skewness';'Kurtosis';...
[873]616    'Min';'FirstCentile';'FirstDecile';'Median';'LastDecile';'LastCentile';'Max'};
[880]617
[874]618TextDisplay=0;
[873]619for icell=1:numel(CellInfo)
[1058]620    if isfield(CellInfo{icell},'VarIndex_histo')% case of histogram plot
[874]621        TextDisplay=1;
[1077]622        VarName=Data.ListVarName{CellInfo{icell}.CoordIndex};
623        pdf_val=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_histo});
[873]624        x=coord_x{icell};
[881]625        if isrow(x)
626            x=x';
627        end
628        if ~isequal(size(x,1),size(pdf_val,1))
629            pdf_val=pdf_val';
630        end
631        Val=pdf2stat(x,pdf_val);
[1200]632        Column=num2cell(Val,ones(13,1),ones(1,size(Val,2)));
[881]633        if size(Val,2)==1%single component
634            TitleBar={VarName};
635        else
636            TitleBar=cell(1,size(Val,2));
637            for icomp=1:size(Val,2)
638                TitleBar{icomp}=[VarName '_' num2str(icomp)];
639            end
640        end
641        Column=[TitleBar;Column];
[873]642        TableData=[TableData Column];
643    end
644end
[1077]645if TextDisplay
[873]646    disp(TableData);
[874]647    PlotParamOut.TableDisplay=TableData;
648else
649    if isfield(PlotParamOut,'TableDisplay')
650        PlotParamOut=rmfield(PlotParamOut,'TableDisplay');
651    end
[871]652end
653   
[201]654%-------------------------------------------------------------------
[781]655function [haxes,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellInfo,haxes,PlotParam)
[201]656%-------------------------------------------------------------------
[674]657PlotType='plane';
658grid(haxes, 'off')% remove grid (possibly remaining from other graphs)
[411]659
[201]660%default plotting parameters
661if ~isfield(PlotParam,'Scalar')
662    PlotParam.Scalar=[];
663end
664if ~isfield(PlotParam,'Vectors')
665    PlotParam.Vectors=[];
666end
[674]667PlotParamOut=PlotParam;%default
668errormsg='';%default
[201]669
[674]670hfig=get(haxes,'parent');%handle of the figure containing the plot axes
[781]671PosColorbar=[];
672FigData=get(hfig,'UserData');
673if isfield(FigData,'PosColorbar')
674    PosColorbar=FigData.PosColorbar;
675end
[201]676hcol=findobj(hfig,'Tag','Colorbar'); %look for colorbar axes
677hima=findobj(haxes,'Tag','ima');% search existing image in the current axes
678test_ima=0; %default: test for image or map plot
679test_vec=0; %default: test for vector plots
680test_false=0;
681test_C=0;
682XName='';
683x_units='';
684YName='';
685y_units='';
[674]686
687% loop on the input field cells
[1031]688for icell=1:numel(CellInfo)
[530]689    if strcmp(CellInfo{icell}.CoordType,'tps') %do not plot directly tps data (used for projection only)
[402]690        continue
691    end
[530]692    ivar_X=CellInfo{icell}.CoordIndex(end); % defines (unique) index for the variable representing unstructured x coordinate (default =[])
693    ivar_Y=CellInfo{icell}.CoordIndex(end-1); % defines (unique)index for the variable representing unstructured y coordinate (default =[])
694    ivar_C=[];
[1200]695    ListFields=fields(CellInfo{icell});
696    for ilist=1:numel(ListFields)
697        if ismember(ListFields{ilist},{'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_ancillary'})
698            ivar_C=CellInfo{icell}.(ListFields{ilist});
699            break % do not allow more than one scalar
700        end
701    end
[530]702    ivar_F=[];
703    if isfield(CellInfo{icell},'VarIndex_warnflag')
[674]704        ivar_F=CellInfo{icell}.VarIndex_warnflag; %defines index (unique) for warning flag variable
[201]705    end
[674]706    ivar_FF_vec=[];
[530]707    if isfield(CellInfo{icell},'VarIndex_vector_x')&&isfield(CellInfo{icell},'VarIndex_vector_y') % vector components detected
[674]708        if test_vec% a vector field has been already detected
[866]709            errormsg='error in plot_field: attempt to plot two vector fields: to get the difference project on a plane with ProjMode= interp_lin or interp_tps';
[201]710            return
711        else
[864]712            if numel(CellInfo{icell}.VarIndex_vector_x)>1
713                errormsg='error in plot_field: attempt to plot two vector fields';
[1031]714                return
[864]715            end
[201]716            test_vec=1;
[674]717            if isfield(CellInfo{icell},'VarIndex_errorflag')
718                ivar_FF_vec=CellInfo{icell}.VarIndex_errorflag; %defines index (unique) for error flag variable
719            end
720            vec_U=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_x});
[530]721            vec_V=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_y});
[1001]722            XName=Data.ListVarName{CellInfo{icell}.CoordIndex(end)};
723            YName=Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
[674]724            if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates
[517]725                vec_X=reshape(Data.(XName),[],1); %transform vectors in column matlab vectors
726                vec_Y=reshape(Data.(YName),[],1);
[674]727            elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates
[1001]728                y=Data.(YName);
729                x=Data.(XName);
[201]730                if numel(y)==2 % y defined by first and last values on aregular mesh
731                    y=linspace(y(1),y(2),size(vec_U,1));
732                end
733                if numel(x)==2 % y defined by first and last values on aregular mesh
734                    x=linspace(x(1),x(2),size(vec_U,2));
735                end
[674]736                [vec_X,vec_Y]=meshgrid(x,y);
[201]737            end
[517]738            if isfield(PlotParam.Vectors,'ColorScalar') && ~isempty(PlotParam.Vectors.ColorScalar)
[1200]739                [VarVal,~,~,errormsg]=calc_field_interp([],Data,PlotParam.Vectors.ColorScalar);
[530]740                if ~isempty(VarVal)
741                    vec_C=reshape(VarVal{1},1,numel(VarVal{1}));
742                    test_C=1;
743                end
[201]744            end
[1144]745
[674]746            if ~isempty(ivar_FF_vec) %&& ~test_false
[1031]747                vec_FF=Data.(Data.ListVarName{ivar_FF_vec}); % flags for false vectors
[1143]748                if ~isempty(ivar_F)%~(isfield(PlotParam.Vectors,'HideWarning')&& isequal(PlotParam.Vectors.HideWarning,1))
749                    vec_F=Data.(Data.ListVarName{ivar_F}); % warning flags for  dubious vectors
[1200]750                    vec_FF(vec_F==-2)=1;%set FalseFlag to 1(edge of the search box)
[1143]751                end
[201]752            end
753        end
754    elseif ~isempty(ivar_C) %scalar or image
755        if test_ima
[674]756            errormsg='attempt to plot two scalar fields or images';
[201]757            return
758        end
[530]759        A=squeeze(Data.(Data.ListVarName{ivar_C}));% scalar represented as color image
[201]760        test_ima=1;
[674]761        if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates
[227]762            A=reshape(A,1,[]);
[201]763            XName=Data.ListVarName{ivar_X};
764            YName=Data.ListVarName{ivar_Y};
[1001]765            Coord_x=reshape(Data.(XName),1,[]);
766            Coord_y=reshape(Data.(YName),1,[]);
[782]767            [A,Coord_x,Coord_y]=proj_grid(Coord_x',Coord_y',A',[],[],'np>256');  % interpolate on a grid
[201]768            if isfield(Data,'VarAttribute')
769                if numel(Data.VarAttribute)>=ivar_X && isfield(Data.VarAttribute{ivar_X},'units')
770                    x_units=[' (' Data.VarAttribute{ivar_X}.units ')'];
771                end
772                if numel(Data.VarAttribute)>=ivar_Y && isfield(Data.VarAttribute{ivar_Y},'units')
773                    y_units=[' (' Data.VarAttribute{ivar_Y}.units ')'];
774                end
[674]775            end
776        elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates
[530]777            YName=Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
[1001]778            XName=Data.ListVarName{CellInfo{icell}.CoordIndex(end)};
[782]779            Coord_y=Data.(YName);
[1001]780            Coord_x=Data.(XName);
[201]781            test_interp_X=0; %default, regularly meshed X coordinate
782            test_interp_Y=0; %default, regularly meshed Y coordinate
[1094]783%             if isfield(Data,'VarAttribute')
784%                 if numel(Data.VarAttribute)>=CellInfo{icell}.CoordIndex(end) && isfield(Data.VarAttribute{CellInfo{icell}.CoordIndex(end)},'units')
785%                     x_units=Data.VarAttribute{CellInfo{icell}.CoordIndex(end)}.units;
786%                 end
787%                 if numel(Data.VarAttribute)>=CellInfo{icell}.CoordIndex(end-1) && isfield(Data.VarAttribute{CellInfo{icell}.CoordIndex(end-1)},'units')
788%                     y_units=Data.VarAttribute{CellInfo{icell}.CoordIndex(end-1)}.units;
789%                 end
790%             end
[782]791            if numel(Coord_y)>2
792                DCoord_y=diff(Coord_y);
793                DCoord_y_min=min(DCoord_y);
794                DCoord_y_max=max(DCoord_y);
[1200]795                if sign(DCoord_y_min)~=sign(DCoord_y_max)% =1 for increasing values, 0 otherwise
[1001]796                    errormsg=['errror in plot_field.m: non monotonic dimension variable ' YName ];
[674]797                    return
798                end
[782]799                test_interp_Y=(DCoord_y_max-DCoord_y_min)> 0.0001*abs(DCoord_y_max);
[201]800            end
[782]801            if numel(Coord_x)>2
802                DCoord_x=diff(Coord_x);
803                DCoord_x_min=min(DCoord_x);
804                DCoord_x_max=max(DCoord_x);
[1094]805                if sign(DCoord_x_min)~=sign(DCoord_x_max)% =1 for increasing values, 0 otherwise
[674]806                    errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarRole.coord(2)} ];
807                    return
808                end
[782]809                test_interp_X=(DCoord_x_max-DCoord_x_min)> 0.0001*abs(DCoord_x_max);
[674]810            end
811            if test_interp_Y
[782]812                npxy(1)=max([256 floor((Coord_y(end)-Coord_y(1))/DCoord_y_min) floor((Coord_y(end)-Coord_y(1))/DCoord_y_max)]);
813                yI=linspace(Coord_y(1),Coord_y(end),npxy(1));
[201]814                if ~test_interp_X
[782]815                    xI=linspace(Coord_x(1),Coord_x(end),size(A,2));%default
816                    Coord_x=xI;
[201]817                end
818            end
[674]819            if test_interp_X
[782]820                npxy(2)=max([256 floor((Coord_x(end)-Coord_x(1))/DCoord_x_min) floor((Coord_x(end)-Coord_x(1))/DCoord_x_max)]);
821                xI=linspace(Coord_x(1),Coord_x(end),npxy(2));
[201]822                if ~test_interp_Y
[782]823                    yI=linspace(Coord_y(1),Coord_y(end),size(A,1));
824                    Coord_y=yI;
[201]825                end
826            end
[674]827            if test_interp_X || test_interp_Y
[782]828                [Coord_x2D,Coord_y2D]=meshgrid(Coord_x,Coord_y);
829                A=interp2(Coord_x2D,Coord_y2D,double(A),xI,yI');
[201]830            end
[782]831            Coord_x=[Coord_x(1) Coord_x(end)];% keep only the lower and upper bounds for image represnetation
832            Coord_y=[Coord_y(1) Coord_y(end)];
[201]833        end
834    end
835    %define coordinates as CoordUnits, if not defined as attribute for each variable
[1094]836%     if isfield(Data,'VarAttribute')&& numel(Data.VarAttribute)>=1 && isfield(Data.VarAttribute{1},'unit')
837%         y_units=Data.VarAttribute{1}.unit;
838%     end
[201]839    if isfield(Data,'CoordUnit')
840        if isempty(x_units)
841            x_units=Data.CoordUnit;
842        end
843        if isempty(y_units)
844            y_units=Data.CoordUnit;
845        end
[1094]846    elseif isfield(Data,'VarAttribute')
847        if numel(Data.VarAttribute)>=CellInfo{icell}.CoordIndex(end) && isfield(Data.VarAttribute{CellInfo{icell}.CoordIndex(end)},'units')
848            x_units=Data.VarAttribute{CellInfo{icell}.CoordIndex(end)}.units;
849        end
850        if numel(Data.VarAttribute)>=CellInfo{icell}.CoordIndex(end-1) && isfield(Data.VarAttribute{CellInfo{icell}.CoordIndex(end-1)},'units')
851            y_units=Data.VarAttribute{CellInfo{icell}.CoordIndex(end-1)}.units;
852        end
[1031]853    end
[674]854end
[1031]855
[688]856PlotParamOut=PlotParam; % output plot parameters equal to input by default
[201]857
858%%   image or scalar plot %%%%%%%%%%%%%%%%%%%%%%%%%%
859if test_ima
860    % distinguish B/W and color images
861    np=size(A);%size of image
862    siz=numel(np);
863    if siz>3
[428]864        errormsg=['unrecognized scalar type: ' num2str(siz) ' dimensions'];
865        return
[201]866    end
867    if siz==3
868        if np(3)==1
[1133]869            siz=2;%grey scale image
[201]870        elseif np(3)==3
871            siz=3;%color image
872        else
[206]873            errormsg=['unrecognized scalar type in plot_field: considered as 2D field with ' num2str(np(3)) ' color components'];
[201]874            return
875        end
876    end
877   
[822]878    %set for grey scale setting
[1133]879    ColorMap='default';%default colormap
[421]880    if isfield(PlotParam.Scalar,'CheckBW') && ~isempty(PlotParam.Scalar.CheckBW)
[1187]881        ColorMap=PlotParam.Scalar.CheckBW;%PlotParam.Scalar.CheckBW is char string indicating the colormap type
[1200]882    elseif siz==2 && (isa(A,'uint8')||isa(A,'uint16'))% non color images represented in gray scale by default
[1103]883        ColorMap='grayscale';
[428]884    end
[1103]885    PlotParamOut.Scalar.CheckBW=ColorMap;
[822]886    % determine the plot option 'image' or 'contours'
887    CheckContour=0; %default
[688]888    if isfield(PlotParam.Scalar,'ListContour')
889        CheckContour=strcmp(PlotParam.Scalar.ListContour,'contours');% =1 for contour plot option
[822]890    end
891   
892    %case of grey level images or contour plot
893    if ~isfield(PlotParam.Scalar,'CheckFixScalar')
894        PlotParam.Scalar.CheckFixScalar=0;% free scalar threshold value scale (from min to max) by default
895    end
896    if ~isfield(PlotParam.Scalar,'MinA')
897        PlotParam.Scalar.MinA=[];%no min scalar threshold value set
898    end
899    if ~isfield(PlotParam.Scalar,'MaxA')
900        PlotParam.Scalar.MaxA=[];%no max scalar threshold value set
901    end
902   
903    % determine the min scalar value
904    if PlotParam.Scalar.CheckFixScalar && ~isempty(PlotParam.Scalar.MinA) && isnumeric(PlotParam.Scalar.MinA)
905        MinA=double(PlotParam.Scalar.MinA); % min value set as input
[688]906    else
[822]907        MinA=double(min(min(min(A)))); % min value set as min of non NaN scalar values
[688]908    end
909   
[822]910    % error if the input scalar is NaN everywhere
911    if isnan(MinA)
912        errormsg='NaN input scalar or image in plot_field';
913        return
914    end
915   
916    % determine the max scalar value
917    CheckFixScalar=0;
918    if PlotParam.Scalar.CheckFixScalar && ~isempty(PlotParam.Scalar.MaxA) && isnumeric(PlotParam.Scalar.MaxA)
919        MaxA=double(PlotParam.Scalar.MaxA); % max value set as input
920        CheckFixScalar=1;
921    else
922        MaxA=double(max(max(max(A)))); % max value set as min of non NaN scalar values
923    end
924   
925    PlotParamOut.Scalar.MinA=MinA;
926    PlotParamOut.Scalar.MaxA=MaxA;
927    PlotParamOut.Scalar.Npx=size(A,2);
928    PlotParamOut.Scalar.Npy=size(A,1);
[1103]929   
[822]930    % case of contour plot
931    if CheckContour
932        if ~isempty(hima) && ishandle(hima)
933            delete(hima) % delete existing image
[201]934        end
[822]935       
936        % set the contour values
937        if ~isfield(PlotParam.Scalar,'IncrA')
938            PlotParam.Scalar.IncrA=[];% automatic contour interval
[201]939        end
[822]940        if ~isempty(PlotParam.Scalar.IncrA) && isnumeric(PlotParam.Scalar.IncrA)
941            interval=PlotParam.Scalar.IncrA;
942        else % automatic contour interval
943            cont=colbartick(MinA,MaxA);
944            interval=cont(2)-cont(1);%default
945            PlotParamOut.Scalar.IncrA=interval;% set the interval as output for display on the GUI
[201]946        end
[822]947        abscontmin=interval*floor(MinA/interval);
948        abscontmax=interval*ceil(MaxA/interval);
949        contmin=interval*floor(min(min(A))/interval);
950        contmax=interval*ceil(max(max(A))/interval);
951        cont_pos_plus=0:interval:contmax;% zero and positive contour values (plotted as solid lines)
952        cont_pos_min=double(contmin):interval:-interval;% negative contour values (plotted as dashed lines)
953        cont_pos=[cont_pos_min cont_pos_plus];% set of all contour values
[688]954       
[822]955        sizpx=(Coord_x(end)-Coord_x(1))/(np(2)-1);
956        sizpy=(Coord_y(1)-Coord_y(end))/(np(1)-1);
957        x_cont=Coord_x(1):sizpx:Coord_x(end); % pixel x coordinates for image display
958        y_cont=Coord_y(1):-sizpy:Coord_y(end); % pixel x coordinates for image display
[688]959       
[822]960        tag_axes=get(haxes,'Tag');% axes tag
961        Opacity=1;
962        if isfield(PlotParam.Scalar,'Opacity')&&~isempty(PlotParam.Scalar.Opacity)
963            Opacity=PlotParam.Scalar.Opacity;
[688]964        end
[822]965        % fill the space between contours if opacity is undefined or =1
966        if isequal(Opacity,1)
[1200]967            [~,hcontour]=contour(haxes,x_cont,y_cont,A,cont_pos);% determine all contours
[822]968            set(hcontour,'Fill','on')% fill the space between contours
969            set(hcontour,'LineStyle','none')
970            hold on
971        end
[1200]972        [~,~]=contour(haxes,x_cont,y_cont,A,cont_pos_plus,'k-');% draw the contours for positive values as solid lines
[822]973        hold on
[1200]974        [~,hcontour_m]=contour(haxes,x_cont,y_cont,A,cont_pos_min,'--');% draw the contours for negative values as dashed lines
[822]975        if isequal(Opacity,1)
976            set(hcontour_m,'LineColor',[1 1 1])% draw negative contours in white (better visibility in dark background)
977        end
978        set(haxes,'Tag',tag_axes);% restore axes tag (removed by the matlab fct contour !)
979        hold off
[688]980       
[822]981        %determine the color scale and map
[1200]982        clim([abscontmin abscontmax])
[1103]983        if strcmp(ColorMap,'grayscale')
[822]984            vec=linspace(0,1,(abscontmax-abscontmin)/interval);%define a greyscale colormap with steps interval
985            map=[vec' vec' vec'];
986            colormap(map);
[1103]987        elseif strcmp(ColorMap,'BuYlRd')
988            hh=load('BuYlRd.mat');
989            colormap(hh.BuYlRd);
[201]990        else
[1103]991            colormap(ColorMap);
[822]992        end
993    else %usual images (no contour)
[201]994        % set  colormap for  image display
[1131]995        switch ColorMap
996            case 'grayscale'
997                vec=linspace(0,1,255);%define a linear greyscale colormap
998                map=[vec' vec' vec'];
999                colormap(map);  %grey scale color map
1000                if siz==3% true color images visualized in BW
1001                    A=uint16(sum(A,3));%sum the three color components for color images displayed with BW option
1002                end
1003            case 'BuYlRd'
1004                hh=load('BuYlRd.mat');
1005                colormap(hh.BuYlRd);
1006            case 'truecolor'
1007                if siz==3 && CheckFixScalar % true color images rescaled by MaxA
1008                    A=uint8(255*double(A)/double(MaxA));
1009                end
[1200]1010            otherwise
1011                colormap(ColorMap);
[201]1012        end
[1131]1013 
[201]1014       
1015        % interpolate field to increase resolution of image display
[652]1016        test_interp=0;
[822]1017        if size(A,3)==1 % scalar or B/W image
[652]1018            test_interp=1;
1019            if max(np) <= 64
1020                npxy=8*np;% increase the resolution 8 times
1021            elseif max(np) <= 128
1022                npxy=4*np;% increase the resolution 4 times
1023            elseif max(np) <= 256
1024                npxy=2*np;% increase the resolution 2 times
1025            else
1026                npxy=np;
1027                test_interp=0; % no interpolation done
1028            end
[201]1029        end
[652]1030        if test_interp%if we interpolate
[782]1031            x=linspace(Coord_x(1),Coord_x(2),np(2));
1032            y=linspace(Coord_y(1),Coord_y(2),np(1));
[201]1033            [X,Y]=meshgrid(x,y);
[782]1034            xi=linspace(Coord_x(1),Coord_x(2),npxy(2));
1035            yi=linspace(Coord_y(1),Coord_y(2),npxy(1));
[688]1036            A = interp2(X,Y,double(A),xi,yi');
[428]1037        end
[848]1038        % create new image if no image handle is found
[428]1039        if isempty(hima)
[201]1040            tag=get(haxes,'Tag');
1041            if MinA<MaxA
[782]1042                hima=imagesc(Coord_x,Coord_y,A,[MinA MaxA]);
[201]1043            else % to deal with uniform field
[782]1044                hima=imagesc(Coord_x,Coord_y,A,[MaxA-1 MaxA]);
[201]1045            end
[428]1046            % the function imagesc reset the axes 'DataAspectRatioMode'='auto', change if .CheckFixAspectRatio is
[411]1047            % requested:
1048            set(hima,'Tag','ima')
1049            set(hima,'HitTest','off')
[428]1050            set(haxes,'Tag',tag);%preserve the axes tag (removed by image fct !!!)
[201]1051            uistack(hima, 'bottom')
[428]1052            % update an existing image
[201]1053        else
[688]1054            set(hima,'CData',A);
[201]1055            if MinA<MaxA
1056                set(haxes,'CLim',[MinA MaxA])
1057            else
[238]1058                set(haxes,'CLim',[MinA MaxA+1])
[201]1059            end
[782]1060            set(hima,'XData',Coord_x);
1061            set(hima,'YData',Coord_y);
[201]1062        end
[546]1063       
[405]1064        % set the transparency to 0.5 if vectors are also plotted
[428]1065        if isfield(PlotParam.Scalar,'Opacity')&& ~isempty(PlotParam.Scalar.Opacity)
1066            set(hima,'AlphaData',PlotParam.Scalar.Opacity)
[405]1067        else
[428]1068            if test_vec
1069                set(hima,'AlphaData',0.5)%set opacity to 0.5 by default in the presence of vectors
1070                PlotParamOut.Scalar.Opacity=0.5;
1071            else
1072                set(hima,'AlphaData',1)% full opacity (no transparency) by default
1073            end
[405]1074        end
[201]1075    end
[1090]1076    if isfield(PlotParam.Axes,'CheckFixAspectRatio') && isequal(PlotParam.Axes.CheckFixAspectRatio,1)
1077        set(haxes,'DataAspectRatioMode','manual')
1078        if isfield(PlotParam.Axes,'AspectRatio')
1079            set(haxes,'DataAspectRatio',[PlotParam.Axes.AspectRatio 1 1])
1080        else
1081            set(haxes,'DataAspectRatio',[1 1 1])
1082        end
1083    end
[201]1084    test_ima=1;
1085   
1086    %display the colorbar code for B/W images if Poscolorbar not empty
[546]1087    if ~isempty(PosColorbar)
[822]1088        if size(A,3)==1 && exist('PosColorbar','var')
[546]1089            if isempty(hcol)||~ishandle(hcol)
1090                hcol=colorbar;%create new colorbar
1091            end
1092            if length(PosColorbar)==4
[1200]1093                % set(hcol,'Units','pixel')
1094                 set(hcol,'Position',PosColorbar)
[546]1095            end
1096            %YTick=0;%default
1097            if MaxA>MinA
1098                if CheckContour
1099                    colbarlim=get(hcol,'YLim');
1100                    scale_bar=(colbarlim(2)-colbarlim(1))/(abscontmax-abscontmin);
1101                    YTick=cont_pos(2:end-1);
1102                    YTick_scaled=colbarlim(1)+scale_bar*(YTick-abscontmin);
1103                    set(hcol,'YTick',YTick_scaled);
1104                elseif (isfield(PlotParam.Scalar,'CheckBW') && isequal(PlotParam.Scalar.CheckBW,1))||isa(A,'uint8')|| isa(A,'uint16')%images
1105                    hi=get(hcol,'children');
1106                    if iscell(hi)%multiple images in colorbar
1107                        hi=hi{1};
1108                    end
1109                    set(hi,'YData',[MinA MaxA])
1110                    set(hi,'CData',(1:256)')
1111                    set(hcol,'YLim',[MinA MaxA])
1112                    YTick=colbartick(MinA,MaxA);
1113                    set(hcol,'YTick',YTick)
1114                else
1115                    hi=get(hcol,'children');
1116                    if iscell(hi)%multiple images in colorbar
1117                        hi=hi{1};
1118                    end
1119                    set(hi,'YData',[MinA MaxA])
1120                    set(hi,'CData',(1:64)')
1121                    YTick=colbartick(MinA,MaxA);
1122                    set(hcol,'YLim',[MinA MaxA])
1123                    set(hcol,'YTick',YTick)
[201]1124                end
[546]1125                set(hcol,'Yticklabel',num2str(YTick'));
[201]1126            end
[546]1127        elseif ishandle(hcol)
1128            delete(hcol); %erase existing colorbar if not needed
[201]1129        end
1130    end
1131else%no scalar plot
[1200]1132    if  ishandle(hima)
[201]1133        delete(hima)
1134    end
[1200]1135    if ~isempty(PosColorbar) && ~isempty(hcol) && ishandle(hcol)
[428]1136        delete(hcol)
[201]1137    end
1138    PlotParamOut=rmfield(PlotParamOut,'Scalar');
1139end
1140
1141%%   vector plot %%%%%%%%%%%%%%%%%%%%%%%%%%
1142if test_vec
1143   %vector scale representation
[1103]1144    if size(vec_U,1)==numel(vec_Y) && size(vec_U,2)==numel(vec_X) % x, y  coordinate variables
[201]1145        [vec_X,vec_Y]=meshgrid(vec_X,vec_Y);
1146    end   
1147    vec_X=reshape(vec_X,1,numel(vec_X));%reshape in matlab vectors
1148    vec_Y=reshape(vec_Y,1,numel(vec_Y));
1149    vec_U=reshape(vec_U,1,numel(vec_U));
1150    vec_V=reshape(vec_V,1,numel(vec_V));
1151     MinMaxX=max(vec_X)-min(vec_X);
[294]1152    if  isfield(PlotParam.Vectors,'CheckFixVectors') && isequal(PlotParam.Vectors.CheckFixVectors,1)&& isfield(PlotParam.Vectors,'VecScale')...
[210]1153               &&~isempty(PlotParam.Vectors.VecScale) && isa(PlotParam.Vectors.VecScale,'double') %fixed vector scale
1154        scale=PlotParam.Vectors.VecScale;  %impose the length of vector representation
1155    else
1156        if ~test_false %remove false vectors   
[201]1157            indsel=1:numel(vec_X);%
1158        end
1159        if isempty(vec_U)
1160            scale=1;
1161        else
1162            if isempty(indsel)
1163                MaxU=max(abs(vec_U));
1164                MaxV=max(abs(vec_V));
1165            else
1166                MaxU=max(abs(vec_U(indsel)));
1167                MaxV=max(abs(vec_V(indsel)));
1168            end
1169            scale=MinMaxX/(max(MaxU,MaxV)*50);
1170            PlotParam.Vectors.VecScale=scale;%update the 'scale' display
1171        end
[210]1172    end
[201]1173   
1174    %record vectors on the plotting axes
1175    if test_C==0
1176        vec_C=ones(1,numel(vec_X));
1177    end
1178   
1179    %decimate by a factor 2 in vector mesh(4 in nbre of vectors)
[581]1180    check_decimate=0;
[294]1181    if isfield(PlotParam.Vectors,'CheckDecimate4') && PlotParam.Vectors.CheckDecimate4
[581]1182        check_decimate=1;
[201]1183        diffy=diff(vec_Y); %difference dy=vec_Y(i+1)-vec_Y(i)
1184        dy_thresh=max(abs(diffy))/2;
1185        ind_jump=find(abs(diffy) > dy_thresh); %indices with diff(vec_Y)> max/2, detect change of line
1186        ind_sel=1:ind_jump(1);%select the first line
1187        for i=2:2:length(ind_jump)-1
1188            ind_sel=[ind_sel (ind_jump(i)+1:ind_jump(i+1))];% select the odd lines
1189        end
1190        nb_sel=length(ind_sel);
1191        ind_sel=ind_sel(1:2:nb_sel);% take half the points on a line
[581]1192    elseif isfield(PlotParam.Vectors,'CheckDecimate16') && PlotParam.Vectors.CheckDecimate16
1193        check_decimate=1;
1194        diffy=diff(vec_Y); %difference dy=vec_Y(i+1)-vec_Y(i)
1195        dy_thresh=max(abs(diffy))/2;
1196        ind_jump=find(abs(diffy) > dy_thresh); %indices with diff(vec_Y)> max/2, detect change of line
1197        ind_sel=1:ind_jump(1);%select the first line
1198        for i=2:4:length(ind_jump)-1
1199            ind_sel=[ind_sel (ind_jump(i)+1:ind_jump(i+1))];% select the odd lines
1200        end
1201        nb_sel=length(ind_sel);
1202        ind_sel=ind_sel(1:4:nb_sel);% take half the points on a line
1203    end
1204    if check_decimate
[201]1205        vec_X=vec_X(ind_sel);
1206        vec_Y=vec_Y(ind_sel);
1207        vec_U=vec_U(ind_sel);
1208        vec_V=vec_V(ind_sel);
1209        vec_C=vec_C(ind_sel);
[1143]1210%         if ~isempty(ivar_F)
1211%            vec_F=vec_F(ind_sel);
1212%         end
[674]1213        if ~isempty(ivar_FF_vec)
[201]1214           vec_FF=vec_FF(ind_sel);
1215        end
1216    end
1217   
1218    %get main level color code
1219    [colorlist,col_vec,PlotParamOut.Vectors]=set_col_vec(PlotParam.Vectors,vec_C);
1220   
1221    % take flags into account: add flag colors to the list of colors
[1103]1222    nbcolor=size(colorlist,1);
[201]1223    nbcolor=nbcolor+1;
[674]1224    if ~isempty(ivar_FF_vec)
[1143]1225        if isfield(PlotParam.Vectors,'CheckShowFalse') && PlotParam.Vectors.CheckShowFalse==1
[1152]1226            colorlist(nbcolor,:)=[1 0 1];% magenta color
1227            %colorlist(nbcolor,:)=[0 0 0];% blackcolor
[1143]1228            if strcmp(PlotParam.Vectors.FalseCriteria,'ALL')
1229                col_vec(vec_FF~=0)=nbcolor;
1230            else
1231                ind_dot=regexp(PlotParam.Vectors.FalseCriteria,':');
1232                FalseValue=str2num(PlotParam.Vectors.FalseCriteria(1:ind_dot-1));%get the selected flg number
1233                col_vec(vec_FF==FalseValue)=nbcolor;
1234                nbcolor=nbcolor+1;
1235                colorlist(nbcolor,:)=[NaN NaN NaN];%
1236                col_vec(vec_FF~=0 & vec_FF~=FalseValue)=nbcolor;
1237            end
1238        else
[201]1239            colorlist(nbcolor,:)=[NaN NaN NaN];% no plot of false vectors
[1143]1240            col_vec(vec_FF~=0)=nbcolor;
1241        end       
[201]1242    end
1243    %plot vectors:
1244    quiresetn(haxes,vec_X,vec_Y,vec_U,vec_V,scale,colorlist,col_vec);   
1245else
1246    hvec=findobj(haxes,'Tag','vel');
1247    if ~isempty(hvec)
1248        delete(hvec);
1249    end
1250    PlotParamOut=rmfield(PlotParamOut,'Vectors');
1251end
1252
1253%store the coordinate extrema occupied by the field
1254if ~isempty(Data)
[569]1255    MinX=[];
1256    MaxX=[];
1257    MinY=[];
1258    MaxY=[];
[748]1259    fix_lim=isfield(PlotParam.Axes,'CheckFixLimits') && PlotParam.Axes.CheckFixLimits;
[201]1260    if fix_lim
[748]1261        if isfield(PlotParam.Axes,'MinX')&&isfield(PlotParam.Axes,'MaxX')&&isfield(PlotParam.Axes,'MinY')&&isfield(PlotParam.Axes,'MaxY')
1262            MinX=PlotParam.Axes.MinX;
1263            MaxX=PlotParam.Axes.MaxX;
1264            MinY=PlotParam.Axes.MinY;
1265            MaxY=PlotParam.Axes.MaxY;
[569]1266        end  %else PlotParamOut.MinX =PlotParam.MinX...
[252]1267    else
1268        if test_ima %both background image and vectors coexist, take the wider bound
[782]1269            MinX=min(Coord_x);
1270            MaxX=max(Coord_x);
1271            MinY=min(Coord_y);
1272            MaxY=max(Coord_y);
[252]1273            if test_vec
[569]1274                MinX=min(MinX,min(vec_X));
1275                MaxX=max(MaxX,max(vec_X));
1276                MinY=min(MinY,min(vec_Y));
1277                MaxY=max(MaxY,max(vec_Y));
[252]1278            end
1279        elseif test_vec
[569]1280            MinX=min(vec_X);
1281            MaxX=max(vec_X);
1282            MinY=min(vec_Y);
1283            MaxY=max(vec_Y);
[201]1284        end
[252]1285    end
[748]1286    PlotParamOut.Axes.MinX=MinX;
1287    PlotParamOut.Axes.MaxX=MaxX;
1288    PlotParamOut.Axes.MinY=MinY;
1289    PlotParamOut.Axes.MaxY=MaxY;
[569]1290    if MaxX>MinX
1291        set(haxes,'XLim',[MinX MaxX]);% set x limits of frame in axes coordinates
[546]1292    end
[569]1293    if MaxY>MinY
1294        set(haxes,'YLim',[MinY MaxY]);% set x limits of frame in axes coordinates
[546]1295    end
[201]1296    set(haxes,'YDir','normal')
1297    set(get(haxes,'XLabel'),'String',[XName ' (' x_units ')']);
1298    set(get(haxes,'YLabel'),'String',[YName ' (' y_units ')']);
[748]1299    PlotParamOut.Axes.x_units=x_units;
1300    PlotParamOut.Axes.y_units=y_units;
[201]1301end
[760]1302
[201]1303%-------------------------------------------------------------------
1304% --- function for plotting vectors
1305%INPUT:
1306% haxes: handles of the plotting axes
1307% x,y,u,v: vectors coordinates and vector components to plot, arrays withb the same dimension
1308% scale: scaling factor for vector length representation
1309% colorlist(icolor,:): list of vector colors, dim (nbcolor,3), depending on color #i
1310% col_vec: matlab vector setting the color number #i for each velocity vector
1311function quiresetn(haxes,x,y,u,v,scale,colorlist,col_vec)
1312%-------------------------------------------------------------------
1313%define arrows
1314theta=0.5 ;%angle arrow
1315alpha=0.3 ;%length arrow
1316rot=alpha*[cos(theta) -sin(theta); sin(theta) cos(theta)]';
[1103]1317
[201]1318%find the existing lines
1319h=findobj(haxes,'Tag','vel');% search existing lines in the current axes
1320sizh=size(h);
1321set(haxes,'NextPlot','replacechildren');
1322
1323%create lines (if no lines) or modify them
1324if ~isequal(size(col_vec),size(x))
1325    col_vec=ones(size(x));% case of error in col_vec input
1326end
[1103]1327nbcolor=size(colorlist,1);
[201]1328
[1103]1329for icolor=1:nbcolor
[201]1330    %determine the line positions for each color icolor
1331    ind=find(col_vec==icolor);
1332    xc=x(ind);
1333    yc=y(ind);
1334    uc=u(ind)*scale;
1335    vc=v(ind)*scale;
1336    n=size(xc);
1337    xN=NaN*ones(size(xc));
[1158]1338    matx=[xc(:) xc(:)+uc(:) xN(:)]';
[201]1339    matx=reshape(matx,1,3*n(2));
[1158]1340    maty=[yc(:) yc(:)+vc(:) xN(:)]';
[201]1341    maty=reshape(maty,1,3*n(2));
1342   
1343    %determine arrow heads
1344    arrowplus=rot*[uc;vc];
1345    arrowmoins=rot'*[uc;vc];
[1158]1346    x1=xc+uc-arrowplus(1,:);
1347    x2=xc+uc;
1348    x3=xc+uc-arrowmoins(1,:);
1349    y1=yc+vc-arrowplus(2,:);
1350    y2=yc+vc;
1351    y3=yc+vc-arrowmoins(2,:);
[201]1352    matxar=[x1(:) x2(:) x3(:) xN(:)]';
1353    matxar=reshape(matxar,1,4*n(2));
1354    matyar=[y1(:) y2(:) y3(:) xN(:)]';
1355    matyar=reshape(matyar,1,4*n(2));
1356    %draw the line or modify the existing ones
1357    isn=isnan(colorlist(icolor,:));%test if color NaN
1358    if 2*icolor > sizh(1) %if icolor exceeds the number of existing ones
1359        if ~isn(1) %if the vectors are visible color not nan
1360            if n(2)>0
1361                hold on
1362                line(matx,maty,'Color',colorlist(icolor,:),'Tag','vel');% plot new lines
1363                line(matxar,matyar,'Color',colorlist(icolor,:),'Tag','vel');% plot arrows
1364            end
1365        end
1366    else
1367        if isn(1)
1368            delete(h(2*icolor-1))
1369            delete(h(2*icolor))
1370        else
1371            set(h(2*icolor-1),'Xdata',matx,'Ydata',maty);
1372            set(h(2*icolor-1),'Color',colorlist(icolor,:));
[932]1373%            set(h(2*icolor-1),'EraseMode','xor');
[201]1374            set(h(2*icolor),'Xdata',matxar,'Ydata',matyar);
1375            set(h(2*icolor),'Color',colorlist(icolor,:));
[932]1376            %set(h(2*icolor),'EraseMode','xor');
[201]1377        end
1378    end
1379end
[1103]1380if sizh(1) > 2*nbcolor
1381    for icolor=nbcolor+1 : sizh(1)/2 %delete additional objects
[201]1382        delete(h(2*icolor-1))
1383        delete(h(2*icolor))
1384    end
1385end
1386
1387%-------------------------------------------------------------------
1388% ---- determine tick positions for colorbar
1389function YTick=colbartick(MinA,MaxA)
1390%-------------------------------------------------------------------
1391%determine tick positions with "simple" values between MinA and MaxA
1392YTick=0;%default
1393maxabs=max([abs(MinA) abs(MaxA)]);
1394if maxabs>0
1395ord=10^(floor(log10(maxabs)));%order of magnitude
1396div=1;
1397siz2=1;
1398while siz2<2
1399    values=-10:div:10;
1400    ind=find((ord*values-MaxA)<0 & (ord*values-MinA)>0);%indices of 'values' such that MinA<ord*values<MaxA
1401    siz=size(ind);
1402    if siz(2)<4%if there are less than 4 selected values (4 levels)
1403        values=-9:0.5*div:9;
1404        ind=find((ord*values-MaxA)<0 & (ord*values-MinA)>0);
1405    end
1406    siz2=size(ind,2);
1407    div=div/10;
1408end
1409YTick=ord*values(ind);
1410end
1411
[356]1412% -------------------------------------------------------------------------
[389]1413% --- 'proj_grid': project  fields with unstructured coordinantes on a regular grid
[356]1414function [A,rangx,rangy]=proj_grid(vec_X,vec_Y,vec_A,rgx_in,rgy_in,npxy_in)
[389]1415% -------------------------------------------------------------------------
[356]1416if length(vec_Y)<2
1417    msgbox_uvmat('ERROR','less than 2 points in proj_grid.m');
1418    return;
1419end
1420diffy=diff(vec_Y); %difference dy=vec_Y(i+1)-vec_Y(i)
1421index=find(diffy);% find the indices of vec_Y after wich a change of horizontal line occurs(diffy non zero)
[1200]1422if isempty(index); msgbox_uvmat('ERROR','points aligned along abscissa in proj_grid.m'); return; end%points aligned% A FAIRE: switch to line plot.
[356]1423diff2=diff(diffy(index));% diff2 = fluctuations of the detected vertical grid mesh dy
1424if max(abs(diff2))>0.001*abs(diffy(index(1))) % if max(diff2) is larger than 1/1000 of the first mesh dy
1425    % the data are not regularly spaced and must be interpolated  on a regular grid
1426    if exist('rgx_in','var') & ~isempty (rgx_in) & isnumeric(rgx_in) & length(rgx_in)==2%  positions imposed from input
1427        rangx=rgx_in; % first and last positions
1428        rangy=rgy_in;
1429        dxy(1)=1/(npxy_in(1)-1);%grid mesh in y
1430        dxy(2)=1/(npxy_in(2)-1);%grid mesh in x
1431        dxy(1)=(rangy(2)-rangy(1))/(npxy_in(1)-1);%grid mesh in y
1432        dxy(2)=(rangx(2)-rangx(1))/(npxy_in(2)-1);%grid mesh in x
1433    else % interpolation grid automatically determined
1434        rangx(1)=min(vec_X);
1435        rangx(2)=max(vec_X);
1436        rangy(2)=min(vec_Y);
1437        rangy(1)=max(vec_Y);
1438        dxymod=sqrt((rangx(2)-rangx(1))*(rangy(1)-rangy(2))/length(vec_X));
1439        dxy=[-dxymod/4 dxymod/4];% increase the resolution 4 times
1440    end
[869]1441    xi=rangx(1):dxy(2):rangx(2);
1442    yi=rangy(1):dxy(1):rangy(2);
1443    A=griddata(vec_X,vec_Y,vec_A,xi,yi');
[1095]1444    A=reshape(A,length(yi),length(xi));
[356]1445else
1446    x=vec_X(1:index(1));% the set of abscissa (obtained on the first line)
1447    indexend=index(end);% last vector index of line change
1448    ymax=vec_Y(indexend+1);% y coordinate AFTER line change
1449    ymin=vec_Y(index(1));
1450    y=vec_Y(index);
1451    y(length(y)+1)=ymax;
1452    nx=length(x);   %number of grid points in x
1453    ny=length(y);   % number of grid points in y
1454    B=(reshape(vec_A,nx,ny))'; %vec_A reshaped as a rectangular matrix
1455    [X,Y]=meshgrid(x,y);% positions X and Y also reshaped as matrix
1456
1457    %linear interpolation to improve the image resolution and/or adjust
1458    %to prescribed positions
1459    test_interp=1;
1460    if exist('rgx_in','var') & ~isempty (rgx_in) & isnumeric(rgx_in) & length(rgx_in)==2%  positions imposed from input
1461        rangx=rgx_in; % first and last positions
1462        rangy=rgy_in;
1463        npxy=npxy_in;
1464    else       
1465        rangx=[vec_X(1) vec_X(nx)];% first and last position found for x
1466          rangy=[max(ymax,ymin) min(ymax,ymin)];
1467        if max(nx,ny) <= 64 & isequal(npxy_in,'np>256')
1468            npxy=[8*ny 8*nx];% increase the resolution 8 times
1469        elseif max(nx,ny) <= 128 & isequal(npxy_in,'np>256')
1470            npxy=[4*ny 4*nx];% increase the resolution 4 times
1471        elseif max(nx,ny) <= 256 & isequal(npxy_in,'np>256')
1472            npxy=[2*ny 2*nx];% increase the resolution 2 times
1473        else
1474            npxy=[ny nx];
1475            test_interp=0; % no interpolation done
1476        end
1477    end
1478    if test_interp==1%if we interpolate
[1200]1479        xi=rangx(1):(rangx(2)-rangx(1))/(npxy(2)-1):rangx(2);
1480        yi=rangy(1):(rangy(2)-rangy(1))/(npxy(1)-1):rangy(2);
[356]1481        [XI,YI]=meshgrid(xi,yi);
1482        A = interp2(X,Y,B,XI,YI);
1483    else %no interpolation for a resolution higher than 256
1484        A=B;
1485    end
[801]1486end
Note: See TracBrowser for help on using the repository browser.