function addcell (CMY, XY, varargin);

% Usage: addcell ([cyan, magenta, yellow], [x, y], height, width)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% addcell.m                              %
% written 2/24/00 by ben olding          %
% defines a cell on the testpage         %
% height & width are in inches           %
% x & y coordinates are in inches        %
% colors are from 0 to 1                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Requires: defbox.m, al.m

global PSText PSComment

ptsize = 10 / 72;

x=XY(1);
y=XY(2);
cyan=CMY(1);
magenta=CMY(2);
yellow=CMY(3);

% PS commands used -- 
% newpath  : starts a new path of lines
% moveto   : moves start to specificed coordinates
% inch     : user defined conversion from point to inch
% bxwidth  : user defined box width
% bxheight : user defined box height
% cyn,mag,yel,blk
%          : user defined colors
% bind def : defines (and evaluates) current definition

% Make the string to display
st1 = ['C=',num2str(cyan*10)];
st2 = ['M=',num2str(magenta*10)];
st3 = ['Y=',num2str(yellow*10)];

%%%%%%% Calculate amount of black
 black = 0;
 black = min([cyan magenta yellow]);
 if black == max ([cyan magenta yellow]),
   cyan    = 0;
   magenta = 0;
   yellow  = 0;
 else
   cyan    = (cyan - black)/(1-black);
   magenta = (magenta - black)/(1-black);
   yellow  = (yellow - black)/(1-black);
 end;

al ('newpath');
al ([num2str(x),' inch ',num2str(y),' inch moveto']);

% Parse variable input
v=length(varargin);
if v >= 1,
  al (['/bxheight ',num2str(varargin{1}),' def'],['% Define height']);
end;
if v >= 2,
  width = varargin{2};
  al (['/bxwidth ',num2str(width),' def'], ['% Define width']);
end

al ('0 0 0 1 setcmykcolor');
al (['(',st3,') show'],                 ['% Display Y data']);
al ([num2str(x),' inch ',num2str(y+ptsize),' inch moveto']);
al (['(',st2,') show'],                 ['% Display M data']);
al ([num2str(x),' inch ',num2str(y+2*ptsize),' inch moveto']);
al (['(',st1,') show'],                 ['% Display C data']);

al (['/cyn ',num2str(cyan),' def'],     ['% Define colors']);
al (['/mag ',num2str(magenta),' def']);
al (['/yel ',num2str(yellow),' def']);
al (['/blk ',num2str(black),' def']);

al ([num2str(x),' inch ',num2str(y+3*ptsize),' inch box']);
