


Add a set of river nodes comprising a single river to Mesh structure
Using a set of user-defined nodes
[Mobj] = add_river_nodes(Mobj,Nlist,RiverName)
DESCRIPTION:
Select using ginput the set of nodes comprising a river
INPUT
Mobj = Matlab mesh object
RiverName = Name of the River
plotFig = [optional] show a figure of the mesh (1 = yes)
OUTPUT:
Mobj = Matlab mesh object with an additional river nodelist
EXAMPLE USAGE
Mobj = add_river_nodes(Mobj, [146, 3004], 'Potomac')
Author(s):
Geoff Cowles (University of Massachusetts Dartmouth)
Karen Amoudry (National Oceanography Centre, Liverpool)
Note:
Uses ginput2 which allows zooming before selecting points and displays
clicked points realtime
Revision history
2013-01-02 KJA bug fix: amended usage of 'unique' to prevent it from
sorting the values it returns. Amended by Pierre to support pre-2012
versions of MATLAB whilst giving the same result.
2013-10-22 KJA: added capability to turn off figures (copied from
Pierre's adaptation to add_obc_nodes_list.m)
2014-05-20 Set boolean flag to true to indicate rivers.
==========================================================================

0001 function [Mobj] = add_river_nodes_list(Mobj,Nlist,RiverName,plotFig) 0002 0003 % Add a set of river nodes comprising a single river to Mesh structure 0004 % Using a set of user-defined nodes 0005 % 0006 % [Mobj] = add_river_nodes(Mobj,Nlist,RiverName) 0007 % 0008 % DESCRIPTION: 0009 % Select using ginput the set of nodes comprising a river 0010 % 0011 % INPUT 0012 % Mobj = Matlab mesh object 0013 % RiverName = Name of the River 0014 % plotFig = [optional] show a figure of the mesh (1 = yes) 0015 % 0016 % OUTPUT: 0017 % Mobj = Matlab mesh object with an additional river nodelist 0018 % 0019 % EXAMPLE USAGE 0020 % Mobj = add_river_nodes(Mobj, [146, 3004], 'Potomac') 0021 % 0022 % Author(s): 0023 % Geoff Cowles (University of Massachusetts Dartmouth) 0024 % Karen Amoudry (National Oceanography Centre, Liverpool) 0025 % 0026 % Note: 0027 % Uses ginput2 which allows zooming before selecting points and displays 0028 % clicked points realtime 0029 % 0030 % Revision history 0031 % 2013-01-02 KJA bug fix: amended usage of 'unique' to prevent it from 0032 % sorting the values it returns. Amended by Pierre to support pre-2012 0033 % versions of MATLAB whilst giving the same result. 0034 % 2013-10-22 KJA: added capability to turn off figures (copied from 0035 % Pierre's adaptation to add_obc_nodes_list.m) 0036 % 2014-05-20 Set boolean flag to true to indicate rivers. 0037 % 0038 %========================================================================== 0039 subname = 'add_river_nodes_list'; 0040 global ftbverbose 0041 if ftbverbose 0042 fprintf('\n') 0043 fprintf(['begin : ' subname '\n']) 0044 end 0045 0046 % Do we want a figure showing how we're getting along? 0047 if nargin == 3 0048 plotFig = 0; 0049 end 0050 0051 %-------------------------------------------------------------------------- 0052 % Get a unique list and make sure they are in the range of node numbers 0053 %-------------------------------------------------------------------------- 0054 % Make this works in versions of MATLAB older than 2012a (newer versions 0055 % can just use unique(A, 'stable'), but checking versions is a pain). 0056 [~, Nidx] = unique(Nlist); 0057 Nlist = Nlist(sort(Nidx)); 0058 0059 if max(Nlist) > Mobj.nVerts 0060 fprintf('your river node number(s) exceed the total number of nodes in the domain\n'); 0061 fprintf('stop screwing around\n'); 0062 error('stopping...\n') 0063 end 0064 0065 %-------------------------------------------------------------------------- 0066 % Plot the mesh 0067 %-------------------------------------------------------------------------- 0068 if plotFig == 1 0069 if strcmpi(Mobj.nativeCoords(1:3), 'car') 0070 x = Mobj.x; 0071 y = Mobj.y; 0072 else 0073 x = Mobj.lon; 0074 y = Mobj.lat; 0075 end 0076 0077 figure 0078 patch('Vertices', [x,y], 'Faces', Mobj.tri,... 0079 'Cdata', Mobj.h, 'edgecolor', 'k', 'facecolor', 'interp'); 0080 hold on 0081 0082 plot(x(Nlist), y(Nlist), 'ro') 0083 title('river nodes') 0084 end 0085 0086 % add to mesh object 0087 npts = numel(Nlist); 0088 Mobj.nRivers = Mobj.nRivers + 1; 0089 Mobj.nRivNodes(Mobj.nRivers) = npts; 0090 Mobj.riv_nodes(Mobj.nRivers, 1:npts) = Nlist; 0091 Mobj.riv_name{Mobj.nRivers} = RiverName; 0092 0093 Mobj.have_rivers = true; 0094 0095 if ftbverbose 0096 fprintf(['end : ' subname '\n']) 0097 end 0098