function J=matsmap(nbase)
%function J=matsmap(nbase)
% ssec color table
%
% Nicked from Mats
%
if nargin < 1
   nbase = size(get(gcf,'colormap'),1);
end


%rgb=[ ...
%   0   0 255 ...
%   0   0 255 ...
% 128 228 255 ...
% 128 228 25 ...
%   0  51 102 ...
% 255 255 255 ...
% 102  153  204 ...
% 102  153  204 ...
%   0  102  0 ...
%   0  102  0 ...
% 153  204  0 ...
% 153  204  0 ...
% 246  219  45 ...
% 246  219  45 ...
% 255  102  0 ...
% 255  102  0 ...
% 255  255  255 ...
% 255  255  255  ];
 %128 228 255 ...
 %128 228 25 ...

   %0   0 255 ...
rgb=[ ...
 235 255 255 ...
 235 255 255 ...
   0 200 255 ...
   0 200 255 ...
   0  51 102 ...
   0  51 102 ...
 102  153  204 ...
 102  153  204 ...
   0  102  0 ...
   0  102  0 ...
 153  204  0 ...
 153  204  0 ...
 246  219  45 ...
 246  219  45 ...
 255  102  0 ...
 255  102  0 ...
 255  255  255 ...
 255  255  255  
];

rgb=reshape(rgb,3,prod(size(rgb))/3);
rgb=rgb/256.;
ncol=size(rgb,2);

ncol2=ncol/2;



J=[];
for i=1:nbase
   rind=1+(ncol2-1)*(i-1)/((nbase-1));
   l0=max(1,min(floor(rind),ncol2));
   l1=min(l0+1,ncol2);
   w0=min(1,max(l1-rind,0));
   w1=1.-w0;

   n0=2*(l0);
   n1=min(2*(l0)+1,ncol);
%disp([ num2str(rind,'%6.2f') ' ' num2str(l0,'%4.4d')  ' ' num2str(l1,'%4.4d') ' '  ...
%       num2str(w0,'%6.2f') ' ' num2str(w1,'%6.2f')  ' ' num2str(n0,'%4.4d')  ' ' num2str(n1,'%4.4d')   ])

   r=w0*rgb(1,n0)+w1*rgb(1,n1);
   g=w0*rgb(2,n0)+w1*rgb(2,n1);
   b=w0*rgb(3,n0)+w1*rgb(3,n1);
   J=[J ; r g b];
end

