Index: trunk/src/plot_field.m
===================================================================
--- trunk/src/plot_field.m	(revision 88)
+++ trunk/src/plot_field.m	(revision 89)
@@ -31,15 +31,15 @@
 %    The only variable attribute used for plotting purpose is .Role which can take
 %    the values
-        %       Role = 'scalar':  (default) represents a scalar field
-        %            = 'coord_x', 'coord_y',  'coord_z': represents a separate set of
-        %                        unstructured coordinate x, y  or z
-        %            = 'vector': represents a vector field whose number of components
-        %                is given by the last dimension (called 'nb_dim')
-        %            = 'vector_x', 'vector_y', 'vector_z'  :represents the x, y or z  component of a vector  
-        %            = 'warnflag' : provides a warning flag about the quality of data in a 'Field', default=0, no warning
-        %            = 'errorflag': provides an error flag marking false data,
-        %                   default=0, no error. Different non zero values can represent different criteria of elimination.
-
-
+%       Role = 'scalar':  (default) represents a scalar field
+%            = 'coord_x', 'coord_y',  'coord_z': represents a separate set of
+%                        unstructured coordinate x, y  or z
+%            = 'vector': represents a vector field whose number of components
+%                is given by the last dimension (called 'nb_dim')
+%            = 'vector_x', 'vector_y', 'vector_z'  :represents the x, y or z  component of a vector  
+%            = 'warnflag' : provides a warning flag about the quality of data in a 'Field', default=0, no warning
+%            = 'errorflag': provides an error flag marking false data,
+%                   default=0, no error. Different non zero values can represent different criteria of elimination.
+%
+%
 %         additional elements characterizing the projection object (should not be necessary)--
 %            Data.Style : style of projection object
@@ -84,5 +84,5 @@
 % PosColorbar: if not empty, display a colorbar for B&W images
 %               imposed position of the colorbar (ex [0.821 0.471 0.019 0.445])
-%
+
 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
 %  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
@@ -141,12 +141,12 @@
 if testnewfig% create a new figure and axes if the plotting axes does not exist
     hfig=figure;
-    if isfield(Data,'IndexObj')&isfield(Data,'Style')&isfield(Data,'ProjMode')
+    if isfield(Data,'IndexObj') && isfield(Data,'Style') && isfield(Data,'ProjMode')
         figname=[num2str(Data.IndexObj) '-' Data.Style];
         set(hfig,'Name',figname)
     end
-    testhandle=0;
-    if isfield(PlotParam,'text_display_1')& ishandle(PlotParam.text_display_1)
+%     testhandle=0;
+    if isfield(PlotParam,'text_display_1') && ishandle(PlotParam.text_display_1)
         set(hfig,'UserData',PlotParam)
-        testhandle=1;
+%         testhandle=1;
     end
     set(hfig,'Units','normalized')
@@ -160,5 +160,5 @@
     hstack=findobj(allchild(0),'Type','figure');%current stack order of figures in matlab
 end
-if isfield(PlotParam,'text_display_1')& ishandle(PlotParam.text_display_1)
+if isfield(PlotParam,'text_display_1') && ishandle(PlotParam.text_display_1)
     PlotParam=read_plot_param(PlotParam);   
 end
@@ -171,5 +171,5 @@
 
 % check the cells of fields :
-testnbdim=1;
+% testnbdim=1;
 [CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Data);
 
@@ -180,5 +180,5 @@
 end
 if ~isfield(Data,'NbDim') %& ~isfield(Data,'Style')%determine the space dimensionb if not defined: choose the kind of plot 
-    [Data.NbDim,imax]=max(NbDim);
+    [Data.NbDim]=max(NbDim);
 end
 if isequal(Data.NbDim,0) 
@@ -207,6 +207,6 @@
     msgbox_uvmat('ERROR','volume plot not implemented yet')
     return
-else
-    testnbdim=0;
+% else
+%     testnbdim=0;
 end
 
@@ -239,5 +239,5 @@
 function hdisplay=plot_text(FieldData,hdisplay_in)
 %-------------------------------------------------------------------
-if exist('hdisplay_in','var') & ishandle(hdisplay_in) & isequal(get(hdisplay_in,'Type'),'uicontrol')
+if exist('hdisplay_in','var') && ishandle(hdisplay_in) && isequal(get(hdisplay_in,'Type'),'uicontrol')
     hdisplay=hdisplay_in;
 else
@@ -254,5 +254,5 @@
     sizss=size(ss);
     if isnumeric(ss)
-        if sizss(1)<=1 & length(ss)<5
+        if sizss(1)<=1 && length(ss)<5
             displ{icell}=num2str(ss);
         else
@@ -263,9 +263,9 @@
     elseif iscell(ss)
         sizcell=size(ss);
-        if sizcell(1)==1 & length(sizcell)==2 %line cell
+        if sizcell(1)==1 && length(sizcell)==2 %line cell
            ssline='{''';
            for icolumn=1:sizcell(2)
                if isnumeric(ss{icolumn})
-                   if size(ss{icolumn},1)<=1 & length(ss{icolumn})<5
+                   if size(ss{icolumn},1)<=1 && length(ss{icolumn})<5
                       sscolumn=num2str(ss{icolumn});%line vector
                    else
@@ -321,9 +321,9 @@
 plotstr='hhh=plot(';
 textmean={};
-abscissa_name='';
+% abscissa_name='';
 coord_x_index=[];
 test_newplot=1;
 hh=findobj(haxes,'tag','plot_line');
-num_curve=numel(hh);
+% num_curve=numel(hh);
 icurve=0;
 for icell=1:length(CellVarIndex)
@@ -351,5 +351,5 @@
     testcoordvar=0;
     charplot_0='''-''';%default
-    if isfield(data,'ObjectProjMode')& isequal(data.ObjectProjMode,'projection')
+    if isfield(data,'ObjectProjMode')&& isequal(data.ObjectProjMode,'projection')
         charplot_0='+';
     end
@@ -374,5 +374,5 @@
         VarAttribute=data.VarAttribute;
         for ivar=1:length(VarIndex) 
-             if length(VarAttribute)>=VarIndex(ivar) & isfield(VarAttribute{VarIndex(ivar)},'long_name')
+             if length(VarAttribute)>=VarIndex(ivar) && isfield(VarAttribute{VarIndex(ivar)},'long_name')
                  plotname{VarIndex(ivar)}=VarAttribute{VarIndex(ivar)}.long_name;
              else
@@ -461,5 +461,5 @@
         else
             legend_old=get(hlegend,'String');
-            if isequal(size(legend_old,1),size(legend_str,1))&~isequal(legend_old,legend_str)
+            if isequal(size(legend_old,1),size(legend_str,1))&&~isequal(legend_old,legend_str)
                 set(hlegend,'String',[legend_old legend_str]);
             end
@@ -537,5 +537,4 @@
 y_units='';
 for icell=1:length(CellVarIndex) % length(CellVarIndex) =1 or 2 (from the calling function)
-%     VarIndex=CellVarIndex{icell};
     VarType=VarTypeCell{icell};
     ivar_X=VarType.coord_x; % defines (unique) index for the variable representing unstructured x coordinate (default =[])
@@ -564,4 +563,6 @@
             eval(['vec_U=Data.' Data.ListVarName{ivar_U} ';']) 
             eval(['vec_V=Data.' Data.ListVarName{ivar_V} ';']) 
+            'TESTplot'
+            VarType.coord
             if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates or structured ones (then ivar_X and ivar_Y empty)     
                 eval(['vec_X=Data.' Data.ListVarName{ivar_X} ';']) 
@@ -614,8 +615,8 @@
             [A,AX,AY]=proj_grid(AX',AY',A',[],[],'np>256');  % interpolate on a grid  
             if isfield(Data,'VarAttribute')
-                if numel(Data.VarAttribute)>=ivar_X & isfield(Data.VarAttribute{ivar_X},'units')
+                if numel(Data.VarAttribute)>=ivar_X && isfield(Data.VarAttribute{ivar_X},'units')
                     x_units=['(' Data.VarAttribute{ivar_X}.units ')'];
                 end
-                if numel(Data.VarAttribute)>=ivar_Y & isfield(Data.VarAttribute{ivar_Y},'units')
+                if numel(Data.VarAttribute)>=ivar_Y && isfield(Data.VarAttribute{ivar_Y},'units')
                     y_units=['(' Data.VarAttribute{ivar_Y}.units ')'];
                 end
@@ -629,5 +630,5 @@
             test_interp_Y=0; %default, regularly meshed Y coordinate
             if isfield(Data,'VarAttribute')
-                if numel(Data.VarAttribute)>=VarType.coord(2) & isfield(Data.VarAttribute{VarType.coord(2)},'units')
+                if numel(Data.VarAttribute)>=VarType.coord(2) && isfield(Data.VarAttribute{VarType.coord(2)},'units')
                     x_units=['(' Data.VarAttribute{VarType.coord(2)}.units ')'];
                 end
@@ -714,4 +715,9 @@
     end
     %set the color map
+    if isfield(PlotParam.Scalar,'BW')
+        BW=PlotParam.Scalar.BW; %test for BW gray scale images
+    else
+        BW=(siz==2) && (isa(A,'uint8')|| isa(A,'uint16'));% non color images represented in gray scale by default
+    end
     if siz==2 %for black and white images
         if ~isfield(PlotParam.Scalar,'AutoScal')
@@ -729,5 +735,5 @@
             MinA=PlotParam.Scalar.MinA;  
         end; 
-        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
+        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
             MaxA=double(max(max(A)));
         else
@@ -756,11 +762,11 @@
             contmin=intercont*floor(min(min(B))/intercont);
             contmax=intercont*ceil(max(max(B))/intercont);
-            cont_pos_plus=[0:intercont:contmax];
-            cont_pos_min=[double(contmin):intercont:-intercont];
+            cont_pos_plus=0:intercont:contmax;
+            cont_pos_min=double(contmin):intercont:-intercont;
             cont_pos=[cont_pos_min cont_pos_plus];
             sizpx=(AX(end)-AX(1))/(np(2)-1);
             sizpy=(AY(1)-AY(end))/(np(1)-1);
             x_cont=[AX(1):sizpx:AX(end)]; % pixel x coordinates for image display 
-            y_cont=[AY(1):-sizpy:AY(end)]; % pixel x coordinates for image display
+            y_cont=AY(1):-sizpy:AY(end); % pixel x coordinates for image display
             txt=ver;%version of Matlab
             Release=txt(1).Release;
@@ -783,7 +789,7 @@
             colormap(map);
         end
-        if ~isequal(PlotParam.Scalar.Contours,1)       
+        if ~isequal(PlotParam.Scalar.Contours,1)  
             % rescale the grey levels with min and max, put a grey scale colorbar
-            if (isfield(PlotParam.Scalar,'BW')& (isequal(PlotParam.Scalar.BW,1))|isa(A,'uint8')| isa(A,'uint16'))%images
+            if BW
                 B=A;
                 vec=linspace(0,1,255);%define a linear greyscale colormap
@@ -797,5 +803,9 @@
     else %color images
         axes(haxes)
-        B=uint8(A); 
+        if BW
+            B=uint16(sum(A,3));
+        else
+            B=uint8(A);
+        end
         MinA=0;
         MaxA=255;
@@ -846,5 +856,5 @@
     test_ima=1;
     %display the colorbar code for B/W images if Poscolorbar not empty
-    if siz==2 & exist('PosColorbar','var')& ~isempty(PosColorbar)
+    if siz==2 && exist('PosColorbar','var')&& ~isempty(PosColorbar)
         if isempty(hcol)|~ishandle(hcol)
              hcol=colorbar;%create new colorbar
@@ -966,5 +976,5 @@
         dy_thresh=max(abs(diffy))/2; 
         ind_jump=find(abs(diffy) > dy_thresh); %indices with diff(vec_Y)> max/2, detect change of line
-        ind_sel=[1:ind_jump(1)];%select the first line
+        ind_sel=1:ind_jump(1);%select the first line
         for i=2:2:length(ind_jump)-1
             ind_sel=[ind_sel [ind_jump(i)+1:ind_jump(i+1)]];% select the odd lines
@@ -1191,5 +1201,5 @@
     siz=size(ind);
     if siz(2)<4%if there are less than 4 selected values (4 levels)
-        values=[-9:0.5*div:9];
+        values=-9:0.5*div:9;
         ind=find((ord*values-MaxA)<0 & (ord*values-MinA)>0);
     end
