function [msg,x,y,z,xi,yi] = xyzchk(x,y,z,xi,yi)
%XYZCHK Check arguments to 3-D data routines.
%
%	[MSG,X,Y,Z] = XYZCHK(X,Y,Z)
%	  or
%	[MSG,X,Y,Z,XI,YI] = XYZCHK(X,Y,Z,XI,YI)

%	Copyright (c) 1984-93 by The MathWorks, Inc.

msg = [];


[m,n] = size(z);
if min(size(z))>1, % z is a matrix

  % Convert x,y to row and column matrices if necessary.
  if min(size(x))==1 & min(size(y))==1,
    [x,y] = meshgrid(x,y);
    if size(x,2)~=n | size(y,1)~=m,
      msg = 'The lengths of X and Y must match the size of Z.';
      return
    end
  elseif min(size(x))==1 | min(size(y))==1,
    msg = 'X and Y must both be vectors or both be matrices.';
    return
  else
    if any(size(x)~=size(z)) | any(size(y)~=size(z)),
      msg = 'Matrix X and Y must be the same size as Z.';
      return
    end
  end

else % z is a vector
  if min(size(x))~=1 | min(size(y))~=1,
    msg = 'X and Y must be vectors when Z is.';
    return
  elseif length(x)~=length(z) | length(y)~=length(z),
    msg = 'X and Y must be same length as Z.';
    return
  end
end

if nargin>3, % Check interpolation arguments
  % If x is a row and y is a column then build xi,yi matrices.
  if size(xi,1)==1 & size(yi,2)==1,
    [xi,yi] = meshgrid(xi,yi);
  elseif any(size(xi)~= size(yi)), % Also create matrix if sizes differ
    [xi,yi] = meshgrid(xi,yi);    
  end
end

