%PILATUS - creates the pilatus colormap usually used when displaying pixel
%          detector data.
%
%   cmap = PILATUS returns the pilatus colormap with the same length as the
%          current figure's colormap. If no figure exists, MATLAB creates
%          one.
%          (cmap is a m-by-3 array)
%
%   cmap = PILATUS(m) returns the pilatus colormap with length m
%          (cmap is a m-by-3 array)
%
%   For example, to reset the colormap of the current figure:
%          colormap(pilatus)
%
%
%   See also the built-in colormaps:
%       hsv, gray, hot, bone, copper, pink, flag, cool,
%   or the functions
%       colormap, rgbplot.

%%
%==========================================================================
% Further info for function PILATUS
% ---------------------------------
%
% CVS-Info:
% ---------
% $Date: 2006/10/18 12:50:31 $
% $Author: schlepuetz $
% $Revision: 1.1 $
% $Source: /import/cvs/X/PILATUS/App/lib/X_PILATUS_Matlab/pilatus.m,v $
% $Tag: $
%
% Author(s):            C. M. Schlepuetz (CS)
% Co-autor(s):          S. A. Pauli (SP)
% Address:              Surface Diffraction Station
%                       Materials Science Beamline X04SA
%                       Swiss Light Source (SLS)
%                       Paul Scherrer Institut
%                       CH - 5232 Villigen PSI
% Created:              2006/06/30
%
% Change Log:
% -----------
% 2006/06/30 (CS):
% - created first version of this file.
%

%%
%==========================================================================
%  Main function - PILATUS
%                  =======

function J = pilatus(m)
if nargin < 1
   m = size(get(gcf,'colormap'),1);
end

cmap = [       0         0         0
               0         0    1.0000
               0    1.0000    1.0000
               0    1.0000         0
          1.0000    1.0000         0
          1.0000         0         0
          1.0000    1.0000    1.0000 ];

J = zeros(m,3);

i = 1;
first = 1;
last = ceil(i*m/(length(cmap)-1));
J(first:last,:) = [linspace(cmap(i,1),cmap(i+1,1),last-first+1)',...
                   linspace(cmap(i,2),cmap(i+1,2),last-first+1)',...
                   linspace(cmap(i,3),cmap(i+1,3),last-first+1)'];
               
for i=2:length(cmap)-2
    first = ceil((i-1)*(m/(length(cmap)-1)));
    last = ceil(i*m/(length(cmap)-1));
    J(first:last,:) = [linspace(cmap(i,1),cmap(i+1,1),last-first+1)',...
                       linspace(cmap(i,2),cmap(i+1,2),last-first+1)',...
                       linspace(cmap(i,3),cmap(i+1,3),last-first+1)'];
end
      
i = length(cmap)-1;
first = ceil((i-1)*(m/(length(cmap)-1)));
last = m;
J(first:last,:) = [linspace(cmap(i,1),cmap(i+1,1),last-first+1)',...
                   linspace(cmap(i,2),cmap(i+1,2),last-first+1)',...
                   linspace(cmap(i,3),cmap(i+1,3),last-first+1)'];
               
%==========================================================================
%
%---------------------------------------------------%
% emacs setup:  force text mode to get no help with %
%               indentation and force use of spaces %
%               when tabbing.                       %
% Local Variables:                                  %
% mode:text                                         %
% indent-tabs-mode:nil                              %
% End:                                              %
%---------------------------------------------------%
%
% $Log: pilatus.m,v $
% Revision 1.1  2006/10/18 12:50:31  schlepuetz
% first version of this file
%
%
%============================= End of $RCSfile: pilatus.m,v $ ===