


Export a set of points to a CST file which can be imported into SMS.
write_SMS_cst(file, x, y)
DESCRIPTION:
Create an ASCII file in the CST format recognised by SMS from the
coordinates specified in (x, y). If x and y are cell arrays, the
coordinates in each cell array are treated as different arcs in the CST
file (e.g. if you have multiple open boundaries you would like in a
single CST file).
INPUT:
file - file name to save to.
x, y - coordinate pairs for the open boundary.
OUTPUT:
file - ASCII file in SMS CST format.
EXAMPLE USAGE:
write_SMS_cst('/tmp/test.cst', x, y)
Author(s):
Pierre Cazenave (Plymouth Marine Laboratory)
Revision history:
2013-03-11 First version.
==========================================================================

0001 function write_SMS_cst(file, x, y) 0002 % Export a set of points to a CST file which can be imported into SMS. 0003 % 0004 % write_SMS_cst(file, x, y) 0005 % 0006 % DESCRIPTION: 0007 % Create an ASCII file in the CST format recognised by SMS from the 0008 % coordinates specified in (x, y). If x and y are cell arrays, the 0009 % coordinates in each cell array are treated as different arcs in the CST 0010 % file (e.g. if you have multiple open boundaries you would like in a 0011 % single CST file). 0012 % 0013 % INPUT: 0014 % file - file name to save to. 0015 % x, y - coordinate pairs for the open boundary. 0016 % 0017 % OUTPUT: 0018 % file - ASCII file in SMS CST format. 0019 % 0020 % EXAMPLE USAGE: 0021 % write_SMS_cst('/tmp/test.cst', x, y) 0022 % 0023 % Author(s): 0024 % Pierre Cazenave (Plymouth Marine Laboratory) 0025 % 0026 % Revision history: 0027 % 2013-03-11 First version. 0028 % 0029 %========================================================================== 0030 0031 subname = 'write_SMS_cst'; 0032 0033 global ftbverbose 0034 if ftbverbose 0035 fprintf('\n'); fprintf(['begin : ' subname '\n']); 0036 end 0037 0038 f = fopen(file, 'w'); 0039 if f < 0 0040 error('Unable to open output file (check permissions?)') 0041 end 0042 0043 if iscell(x) && iscell(y) 0044 nb = length(x); 0045 else 0046 nb = 1; 0047 end 0048 0049 % Header 0050 fprintf(f, 'COAST\n'); 0051 fprintf(f, '%i\n', nb); 0052 0053 for bb = 1:nb % each boundary 0054 if iscell(x) && iscell(y) 0055 np = length(x{bb}); 0056 xx = x{bb}; 0057 yy = y{bb}; 0058 else 0059 np = length(x); 0060 xx = x; 0061 yy = y; 0062 end 0063 0064 % The current arc's header 0065 fprintf(f, '%i\t0.0\n', np); 0066 0067 % All the positions 0068 for i=1:length(xx); 0069 fprintf(f, '\t%.6f\t%.6f\t0.0\n', xx(i), yy(i)); 0070 end 0071 0072 end 0073 0074 fclose(f); 0075 0076 if ftbverbose 0077 fprintf('end : %s \n', subname) 0078 end