function write_xys(filename,x,y,name)
% Writes an SMS XYS (XY Series) file (*.xys)
%
%   write_xys(file,x,y,name)
%
% 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