function cmap = mk_cmap(ncmap, cmap_name, breakpoints)
%cmap =  mk_cmap(ncmap, cmap_name, breakpoints)
%
% ncmap is number of points to be interpolated onto
%
% homewbrewed cmap_name choices are:
% 'buoy'        %garish colors used on buoy
% 'pg3080'      %jet: bands switch at 30pg and 80pg
% 'g3080'       %gray: bands switch at 30pg and 80pg
% 'topo'        %nice blues and tans
% 'rg_vel'      %red/purple is positive, blue/green is negative; white at zero
% (otherwise, standard matlab palettes are available.
%          if just ncmap, uses pg3080)
%
% usage:
%  cmap =  mk_cmap(ncmap, cmap_name);
% 
% other names from matlab's list are:
%    hsv        - Hue-saturation-value color map.
%    hot        - Black-red-yellow-white color map.
%    gray       - Linear gray-scale color map.
%    bone       - Gray-scale with tinge of blue color map.
%    copper     - Linear copper-tone color map.
%    pink       - Pastel shades of pink color map.
%    white      - All white color map.
%    flag       - Alternating red, white, blue, and black color map.
%    lines      - Color map with the line colors.
%    colorcube  - Enhanced color-cube color map.
%    vga        - Windows colormap for 16 colors.
%    jet        - Variant of HSV.
%    prism      - Prism color map.
%    cool       - Shades of cyan and magenta color map.
%    autumn     - Shades of red and yellow color map.
%    spring     - Shades of magenta and yellow color map.
%    winter     - Shades of blue and green color map.
%    summer     - Shades of green and yellow color map.


% Jules 2000/11/27
% It's a hack - needs desperately to be cleaned up
% 2001/09/25 EF - slight cleanup and bugfix (in topo option).

program_name = 'mk_cmap';


if (nargin == 0)
   help(program_name)
   error('must choose number of points')
end

if (nargin == 1)
   cmap_name = 'pg3080';
end


if (nargin == 2)
   if (ischar(ncmap))
      help(program_name)
      error('first argument given was a string: maybe swap argument order?')
   end
end

index = (0:(ncmap-1))'/(ncmap-1);


switch cmap_name
 case 'buoy'      %------------------------------

  some = .2;
  rgb = [
     1 1 1;             %gray
     [1 1 1]*some;
     1 1 0;             %yellow
     [1 1 0]*some;
     1 0 1;             %magenta
     [1 0 1]*some;
     0 1 1;             %cyan
     [0 1 1]*some;
     1 0 0 ;            %red
     [1 0 0]*some;
     0 1 0;             %green
     [0 1 0]*some;
     0 0 1;             %blue
     [0 0 1]*some];

  %boundaries
  dlev = 2;
  lev = [0:dlev:12]';
  lev = [lev; lev(end)+dlev+lev];


  rrr = table1( [lev rgb(:,1)],[1:ncmap]*max(lev)/ncmap);
  ggg = table1( [lev rgb(:,2)],[1:ncmap]*max(lev)/ncmap);
  bbb = table1( [lev rgb(:,3)],[1:ncmap]*max(lev)/ncmap);
  cmap = [rrr ggg bbb];


 case 'pg3080'  %------------------------------
  breakpoints = [0.2 0.3 0.8 0.9];
  allindex= [0, breakpoints, 1]';
  r=table1([allindex [0 0 0 1 1 .6]'], index);
  g=table1([allindex [0 0 1 1 0 0]'], index);
  b=table1([allindex [.6 1 1 0 0 0]'], index);
  cmap = [r g b];


 case 'g3080'  %------------------------------

  hgray =  table1(...
     [[0 .01 .15 .28 .3 .31 .78 .82 1]' ...
      [0 .01 .35 .4 .52 .55 .6 .7 1]'],...
     index);
  cmap = [hgray hgray hgray];


 case 'rg_vel'  %-------------------------------
  
  breakpoints = [.15  .48 .52 .85 ];
  allindex= [0, breakpoints, 1]';
  r=table1([allindex [0 0 0 1 1 .6]'], index);
  g=table1([allindex [0 0 1 1 0 0]'], index);
  b=table1([allindex [.6 1 1 0 0 0]'], index);
  cmap = [r g b];
  
 case 'gautoedit'  %-------------------------------
  %             [0.2 0.4 0.6 0.8];
  breakpoints = [ .15 .35 .45 .60 .7 .82 ];

  allindex= [0, breakpoints, 1]';
  r=table1([allindex [   0   0   0 128 255 255 255 160]'/255],...
           index);
  g=table1([allindex [   0 128 255 255 255 255 128   0]'/255],...
           index);
  b=table1([allindex [ 160 255 255 255 128   0   0   0]'/255],...
           index);
  cmap = [r g b];

  
 case 'topo'    %------------------------------

  blued = [050 163 219];
  bluem = [111 215 255];
  blues = [205 242 255];
  tand = [251 235 231];
  tanm = [223 191 147];
  tans = [178 132 055];

  bluetanmap = [0     blued/255;
                1/5    bluem/255;
                2/5    blues/255;
                3/5    tand/255;
                4/5    tanm/255;
                5/5    tans/255];
  cmap = table1(bluetanmap, index);

 otherwise  %------------------------------
  cmap = feval(cmap_name, ncmap);
end

