function col=cmap(type,n,m);
% CMAP     various (quantized) spectrum colormaps.
%          CMAP(TYPE) where TYPE=1-4 is a particular colormap.
%          CMAP(TYPE,N) gives the colormap N quantized levels
%          in a map of size 128.
%          CMAP(TYPE,N,M) gives an N-quantized M-map 
%
%          The quantization means that fairly nice contouring can
%          be done using the interpolated shading in pcolor. Typically
%          you would call:
%              >> shading('interp');
%              >> colormap(cmap(2,8));
%              >> pcolor(...);
%
%          to get an 8 level map. Boundaries are smoother the bigger you make
%          M.
%
%          See also SHADING, PCOLOR
%

% Rich Pawlowicz (WHOI) 12/feb/92
% Comments or questions call rich@boreas.whoi.edu

if (nargin==0), type=1; n=16; m=128; 
elseif (nargin==1), n=16; m=128; 
elseif (nargin==2), m=128; 
end;

ncol=m/n;

if (type==1),

  w=fix([0:m-1]'/ncol)*ncol/m*2*pi;
  we=w;
  we(w>3*pi/2)=3*pi/2*ones(sum(w>3*pi/2),1);

  col=128+round(128*[ sin(flipud(we)) -cos(w) sin((we)) ]);

elseif (type==2),

  w=fix([0:m-1]'/ncol)*ncol/m*pi;
  col=max(0,round(256*[ sin(w-pi/4) abs(sin(w+pi/2)) sin(w+pi/4) ]));

elseif (type==3),

  w=fix([0:m-1]'/ncol)*ncol/m*pi;
  col=max(0,round(256*[ sin(w-pi/4) (sin(w)) sin(w+pi/4) ]));

elseif (type==4),

  w=fix([0:m-1]'/ncol)*ncol/m*256;
  col=[w w w];

end;


