Home > fvcom_prepro > add_stations_list.m

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 with the following fields: - nativeCoords = native grid coordinate type. - x, y = grid node positions - xc, yc = grid element positions - h = water depth at the nodes - tri = grid triangulation table 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 (stations) containing: {id, x, y, nodelist, depth, 'station name', elem} where id is the station ID (from 1 number of valid stations, x and y are the coordinates of the station, nodelist is the indices of the model grid nodes, depth is the depth at the grid node, station name is a string of the name from the input file and eleme is the grid element ID closest to each station. 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. 2015-01-14 Add support for exporting the element ID closest to the station of interest (as well as the node ID which was already there). Fix some formatting issues. ==========================================================================

- find_nearest_pt Find nearest point in Mesh structure to (x,y)

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

Generated on Wed 20-Feb-2019 16:06:01 by