write_FVCOM_stations.m 1.96 KB
Newer Older
1 2 3 4
function [Mobj]  = write_FVCOM_stations(Mobj,filename)

% Add a set of stations at which FVCOM will output time series. 
%
5
% function write_FVCOM_stations(Mobj,filename)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
%
% DESCRIPTION:
%    Given a mesh object with time series positions and names
%    (Mobj.Position and Mobj.Names from add_stations_list.m), write out to
%    ASCII file filename.
%
% INPUT
%    Mobj = Matlab mesh object
%    filename = FVCOM stations file name
%
% OUTPUT:
%    FVCOM stations file: filename
%
% EXAMPLE USAGE
%    write_FVCOM_stations(Mobj, 'tst_stations.dat')
%
% Author(s):  
%    Pierre Cazenave (Plymouth Marine Laboratory)
%
% Revision history
%    2012-11-30 First version.
%   
%==========================================================================
subname = 'write_FVCOM_stations';
global ftbverbose
if(ftbverbose)
  fprintf('\n'); fprintf(['begin : ' subname '\n']);
end

%--------------------------------------------------------------------------
% Parse input arguments
%--------------------------------------------------------------------------
if exist('Mobj', 'var') ~= 1 || exist('filename', 'var') ~= 1
39
	error('arguments to %s are incorrect', subname)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
end

%--------------------------------------------------------------------------
% Dump the file
%--------------------------------------------------------------------------
if strcmpi(Mobj.nativeCoords, 'cartesian')
	x = Mobj.Positions(:,3);
	y = Mobj.Positions(:,4);
elseif strcmpi(Mobj.nativeCoords, 'spherical')
	x = Mobj.Positions(:,1);
	y = Mobj.Positions(:,2);
else
    error('Unknown native coordinate system string: %s', Mobj.nativeCoords)
end

if(ftbverbose)
    fprintf('writing FVCOM gridfile %s\n',filename);
end

fid = fopen(filename,'w');
fprintf(fid, ' No           X        Y      Node (Cell)        Station Name\n');

for s=1:length(Mobj.stations)
    fprintf(fid, '%i %f %f %i %f %s\n', cell2mat(Mobj.stations{s}(1:5)), char(Mobj.stations{s}(6)));
end   

fclose(fid);

if(ftbverbose)
  fprintf(['end   : ' subname '\n'])
end