function sms_write_xys(filename,x,y,name)
% Writes an SMS XYS (XY Series) file (*.xys)
%
% Usage:
%   sms_write_xys(file,x,y,name)
%
% Input:
%   filename - XYS file name
%   x - x data in series
%   y - y data in series
%   name - Name of series
%
% written by Alex Sanchez, USACE-CHL

data = [x(:),y(:)];
n = length(x);
fid = fopen(filename,'w');
if nargin<4
    fprintf(fid,'XYS 1 %d "Curve"\n',n);
else
    fprintf(fid,'XYS 1 %d ',n);
    fprintf(fid,'"%s"\n',name);
end
fprintf(fid,'%f %f\n',data(1:n-1,:)');
fprintf(fid,'%f %f',data(n,:)');
fclose(fid);

return
end
