Home > fvcom_prepro > add_stations_list.m

add_stations_list

PURPOSE ^

Add a set of stations at which FVCOM will output time series.

SYNOPSIS ^

function [Mobj] = add_stations_list(Mobj,Positions,Names,Dist)

DESCRIPTION ^

 Add a set of stations at which FVCOM will output time series.

 [Mobj] = add_stations_list(Mobj,Positions,Names,Dist)

 DESCRIPTION:
    Supply a list of positions (in the same coordinate system as the
    native coordinates of the grid) and a cell array of names. Nearest
    grid node to those supplied will be used in the output file.

 INPUT
    Mobj = Matlab mesh object
    Positions = 2xn array of the XY positions of the stations
    Names = Cell array of the names of the stations defined in Positions
    Dist = Maximum distance from a station for a node to be included

    Optionally supply positions as a 4xn array with spherical x and y and
    cartesian x and y in columns 1, 2, 3 and 4, respectively. The
    values in Mobj.nativecoords will be used for the distance check, so
    ensure Dist is in those units.

 OUTPUT:
    Mobj = Matlab mesh object with an additional cell array containing id,
    x, y, nodelist, depth and station name.

 EXAMPLE USAGE
    Mobj = add_stations_list(Mobj, [-5.54, 50.103; -3.0865, 58.441], ...
    {'Newlyn', 'Wick'}, 0.25)

 Author(s):
    Pierre Cazenave (Plymouth Marine Laboratory)


 Revision history
    2012-11-30 First version.

==========================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Mobj]  = add_stations_list(Mobj,Positions,Names,Dist)
0002 
0003 % Add a set of stations at which FVCOM will output time series.
0004 %
0005 % [Mobj] = add_stations_list(Mobj,Positions,Names,Dist)
0006 %
0007 % DESCRIPTION:
0008 %    Supply a list of positions (in the same coordinate system as the
0009 %    native coordinates of the grid) and a cell array of names. Nearest
0010 %    grid node to those supplied will be used in the output file.
0011 %
0012 % INPUT
0013 %    Mobj = Matlab mesh object
0014 %    Positions = 2xn array of the XY positions of the stations
0015 %    Names = Cell array of the names of the stations defined in Positions
0016 %    Dist = Maximum distance from a station for a node to be included
0017 %
0018 %    Optionally supply positions as a 4xn array with spherical x and y and
0019 %    cartesian x and y in columns 1, 2, 3 and 4, respectively. The
0020 %    values in Mobj.nativecoords will be used for the distance check, so
0021 %    ensure Dist is in those units.
0022 %
0023 % OUTPUT:
0024 %    Mobj = Matlab mesh object with an additional cell array containing id,
0025 %    x, y, nodelist, depth and station name.
0026 %
0027 % EXAMPLE USAGE
0028 %    Mobj = add_stations_list(Mobj, [-5.54, 50.103; -3.0865, 58.441], ...
0029 %    {'Newlyn', 'Wick'}, 0.25)
0030 %
0031 % Author(s):
0032 %    Pierre Cazenave (Plymouth Marine Laboratory)
0033 %
0034 %
0035 % Revision history
0036 %    2012-11-30 First version.
0037 %
0038 %==========================================================================
0039 subname = 'add_stations_list';
0040 global ftbverbose
0041 if(ftbverbose)
0042   fprintf('\n')
0043   fprintf(['begin : ' subname '\n'])
0044 end;
0045 
0046 %--------------------------------------------------------------------------
0047 % Check the inputs
0048 %--------------------------------------------------------------------------
0049 nPos = size(Positions, 1);
0050 nNames = size(Names, 1);
0051 if nPos ~= nNames
0052     error('The number of the supplied station positions and names do not match (%i and %i respectively)', nPos, nNames)
0053 end
0054 
0055 %--------------------------------------------------------------------------
0056 % For each site in the supplied positions, find the nearest node ID
0057 %--------------------------------------------------------------------------
0058 
0059 % Check for whether the input has both spherical and cartesian.
0060 if size(Positions, 2) > 2
0061     % Now check for which is the native coordinate system, and output the
0062     % station positions in that coordinate system.
0063     if strcmpi(Mobj.nativeCoords, 'cartesian')
0064         cols = [3, 4];
0065     elseif strcmpi(Mobj.nativeCoords, 'spherical')
0066         cols = [1, 2];
0067     else
0068         error('Unknown native coordinate system string: %s', Mobj.nativeCoords)
0069     end
0070 else
0071     % We have to assume the positions are in the grid's native coordinate
0072     % system.
0073     cols = [1, 2];
0074 end
0075 
0076 inc = 1;
0077 % out = cell(nPos, 1);
0078 
0079 for s=1:nPos
0080     [node, dist] = find_nearest_pt(Positions(s, cols(1)), Positions(s, cols(2)), Mobj);
0081 
0082     if dist >= Dist
0083         % Skip out for this station
0084         if(ftbverbose)
0085             fprintf('Skipping station %s (%g, %g). Nodal distance from station position = %f\n', Names{s}, Positions(s, 1), Positions(s, 2), dist)
0086         end
0087         continue
0088     end
0089     out{inc} = {inc, Positions(s, cols(1)), Positions(s, cols(2)), node, Mobj.h(node), Names{s}};
0090     inc = inc + 1;
0091 end
0092 
0093 if ~isempty(out)
0094     Mobj.stations = out;
0095 else
0096     Mobj.stations = [];
0097     if ftbverbose
0098         fprintf('No stations found within the model domain.\n')
0099     end
0100 end

Generated on Tue 04-Jun-2013 12:12:57 by m2html © 2005