  function [h]=sizesym(xc,yc,c,nsp,lab,colstr,colval,colrel);
%
% function [h]=sizesym(xc,yc,c,[nsp],[lab],[colstr],[colval],[colrel]);
%
% xc,yc = position
%     c = value 
%  nsp  = size reduction (to scale dot with: big nsp means smaller dot)
%         (this is typically the number of subplots)
%         (note: if nsp<0 then use log10 size)
%  lab  = labels to put on dots (if lab==1, no labels, if lab=0.5 then half)
%         (note: if lab<0 then use circles for dots)
%  colstr=string to represent color from "colval" vector
%         (but if colstr='z', then make
%             color a function of %between 0 & -100
%             representing green [0 1 0] to blue [0 0 1])
%  colval=vector to use as color
%  colrel=vector to stanadrdize color with
%
%
% makes symbol size dots at xc,yc according to "c"
% Jim Manning

% set default size
if nargin<4; nsp=1;end;

% calculate maximum value
maxc=maxnnan(abs(c));

%  note: default color of dots is always green
if nargin<6; colstr='g';end;

% Note: We want to normalize the dot size to less than 100
%       in the case of a full page plot. Otherwise we use 100/nsp
%       where "nsp" is the number of subplots.
%       We set zero value dot to be one tenth of max.
%       For example, we want zv=1 for maxc~10 and zv=10 for maxc~100.
%       (note: if nsp<0 then use log10 size)

% determine size of color string
[nrcs,nccs]=size(colstr);

if nsp<0;
  nsp=-1*nsp;
  dsp=10/nsp*ones(length(c),1);
  id=find(abs(c)>10);
  dsp(id)=log10(abs(c(id)))/max(log10(abs(c(id))))*100/nsp;
elseif nsp>0;
  dsp=10/nsp+abs(c)/maxc*100/nsp;
end;

% plot the symbol for each data point
for ii=1:length(c);

% change symbol type depending on positive or negative
  if c(ii)>=0;
    dsp(ii)=dsp(ii)/2;
    sym='x';
  elseif c(ii)<0;
    sym='.';
  end;
  if length(lab)==1;
    if lab<0;
      sym='*';
      dsp(ii)=dsp(ii)/4;
    end;
  end;

% plot the symbol finally
  if isnan(c(ii))~=1;
    h=plot(xc(ii),yc(ii),sym,'MarkerSize',dsp(ii));
  end;
  hold on;

  if colstr(1,:)=='z';
%    maxv=max(abs(colval));
%   set color depending on "colval" between green and blue
%   (Note: we added the factor of "1.1" to prevent values >1.0.)
%    set(h,'color',[0  1-(maxv-abs(colval(ii)))/range(colval) (maxv-abs(colval(ii)))/range(colval)]);
    set(h,'color',[0  1-colval(ii)/colrel(ii) colval(ii)/colrel(ii)]);
  else
    if nrcs==1;
      set(h,'color',colstr);
    else;
      set(h,'color',colstr(ii,:));
    end;
  end;
end;

% now post the actual values (or label)
% (note: if length(lab)==1, then post only that fraction of "c" values)
  for ik=1:length(c);
    if nargin<5;
      if c(ik)>1;
        h1=text(xc(ik),yc(ik),num2str(c(ik)));
      end;
    else;
      if length(lab)==1;
        if abs(c(ik))>(abs(lab)*maxnnan(abs(c)));
          if max(abs(c))>5;
            h1=text(xc(ik),yc(ik),num2str(round(abs(c(ik)))));
          else
%           post number with average number of sign digits
            stg=num2str(abs(c(ik)));
            id=find(stg=='.');
            if id~=[];
              ndg=floor(mean([length(stg(1:id-1)) length(stg(id+1:length(stg)))]));
              h1=text(xc(ik),yc(ik),stg(1:id+ndg));
            else;
               h1=text(xc(ik),yc(ik),stg);
            end;
          end;
        end;
      else;
        if lab(ik)~=0;
          h1=text(xc(ik),yc(ik),num2str(round(lab(ik))));
        end;
      end;
    end;

   
   
%   make sure we don't have black label on black dot
    if colstr(1)=='k';
      collab='w';
    else;
      collab='k';
   end;

   exh1=exist('h1');

   if exh1~=0;
     set(h1,'fontsize',14-2*nsp,'color',collab);
     set(h1,'verticalalignment','middle','horizontalalignment','center');

   end;  
 end;
  end;
  
