function dc=cntour(x,y,a,s,col)
% DUM=CNTOUR(X,Y,A,S,COL)
% make contour plot of A, as a function of X and Y
% negative contours have dashed lines,
% S   controls spacing
% COL color of lines
% this version differs from cntourx by allowing contours to be
% marked manualy
%
% D. Menemenlis 17 feb 94
% modified from /data17/diana/Barry/barry7/mscripts/cntourx.m

if exist('s')==0, s=1; end
if exist('col')==0, col='w'; end
dc=s;
%$$$ dc=s*(max(a(:))-min(a(:)))/5;
%$$$ amean=mean(a(:));
%$$$ dc=s*std(a(:));

% find a 1 digit number close to the desired contour interval
if dc~=0
%$$$   dc=str2num(sprintf('%.0e',dc/2))*2;
  mm=minmax(a);
  ac1=-dc/2:-dc:mm(1);
  if length(ac1)==1, ac1=[ac1 ac1]; end
  ac2=dc/2:dc:mm(2);
  if length(ac2)==1, ac2=[ac2 ac2]; end
  %$$$ ac1=amean-dc:-dc:mm(1);
  %$$$ ac2=amean:dc:mm(2);
else
  ac1=[];
  ac2=[0 0];
end

if ~isempty(ac1),
  c=contour(x,y,a,ac1,[col,'--']);
  if ~isempty(c),clabel2(c,'manual'),end
  hold on
end
if ~isempty(ac2),
  c=contour(x,y,a,ac2,col);
  if ~isempty(c),clabel2(c,'manual'),end
  hold off
end

xy=axis;
%$$$ text(xy(1)-.08*(xy(2)-x(1)),xy(3)-.08*(xy(4)-xy(3)),...
text(xy(1)-.08*(xy(2)-x(1)),xy(3)-.16*(xy(4)-xy(3)),...
    ['contour interval: ' num2str(dc)]);
