function k(blk,prf)

% This function is used to mark a profile with '+' for increased visibility.
% Usage:  k             - use mouse to click on profile to be marked
%         k(n)          - move marks <n> profiles from currently marked one
%         k(blk#,prf#)  - mark profile specified by <blk#>,<prf#>

%editglob
global IBLKPRF IKEY NPRFS CURRX NBINS PMIN PMAX DISP LASTPLOT

if nargin == 2
  newkey = find(IBLKPRF(:,1) == blk & IBLKPRF(:,2) == prf);
  if isempty(newkey)
    error(['Block ' int2str(blk) ', Profile ' int2str(prf) ' is not in current workspace.']);
  else
    IKEY = newkey;
  end
elseif nargin == 1
  if isempty(blk)
    IKEY = [];
  else
    np = blk;
    if isempty(IKEY)
      error('There is no key in current workspace.  Use k(blk#,prf#) or just k instead.');
    end
    newkey = IKEY + np;
    if newkey < 1 | newkey > NPRFS
      error('Key argument is beyond current range');
    else
      IKEY = newkey;
    end
  end
elseif nargin == 0
  if isempty(CURRX)
    error(' You must plot a variable first before using the k command without arguments')
  else
    disp(' Click on any bin in the profile to move key to ')
    [x y] = ginput(1);
    y = abs(y);
    yrange = [max(1,floor(y)):min(NBINS,ceil(y))];
    r = CURRX(yrange,PMIN:PMAX) + DISP(yrange,PMIN:PMAX);
    d = 1e38 * ones(size(r));
    imask = ~isnan(r);
    d(imask) = abs(r(imask) - x);
    [m IKEY] = min(min(d));
    IKEY = PMIN - 1 + IKEY;
  end
else
  disp(' Usage:  k(blk,prf) where blk,prf is the block # and profile # of desired key')
  disp('    or:  k(n)       where n is a signed # indicating direction & no. of profiles to move key to')
  disp('    or:  k          where you click on a bin in the profile to move the key to')
  return;
end

if ~isempty(IKEY)
  disp([int2str(IBLKPRF(IKEY,1)) ',' int2str(IBLKPRF(IKEY,2)) ' is new key']);
end
eval(LASTPLOT)
