add_river_nodes_list.m 2.25 KB
Newer Older
1
function [Mobj] = add_river_nodes_list(Mobj,Nlist,RiverName)
Pierre Cazenave's avatar
Pierre Cazenave committed
2 3 4 5

% Add a set of river nodes comprising a single river to Mesh structure  
% Using a set of user-defined nodes
%
6
% [Mobj] = add_river_nodes(Mobj,Nlist,RiverName)
Pierre Cazenave's avatar
Pierre Cazenave committed
7 8 9 10 11 12 13 14 15 16 17 18
%
% DESCRIPTION:
%    Select using ginput the set of nodes comprising a river
%
% INPUT
%    Mobj = Matlab mesh object
%    RiverName = Name of the River
%
% OUTPUT:
%    Mobj = Matlab mesh object with an additional river nodelist
%
% EXAMPLE USAGE
19
%    Mobj = add_river_nodes(Mobj, [146, 3004], 'Potomac')
Pierre Cazenave's avatar
Pierre Cazenave committed
20 21 22
%
% Author(s):  
%    Geoff Cowles (University of Massachusetts Dartmouth)
23
%    Karen Amoudry (National Oceanography Centre, Liverpool)
Pierre Cazenave's avatar
Pierre Cazenave committed
24 25 26 27 28 29
%
% Note:
%    Uses ginput2 which allows zooming before selecting points and displays
%    clicked points realtime
%
% Revision history
30 31
%    2013-01-02 KJA bug fix: amended usage of 'unique' to prevent it from
%    sorting the values it returns.
Pierre Cazenave's avatar
Pierre Cazenave committed
32
%   
33 34
%==========================================================================
subname = 'add_river_nodes_list';
Pierre Cazenave's avatar
Pierre Cazenave committed
35
global ftbverbose
36 37 38 39
if ftbverbose
    fprintf('\n')
    fprintf(['begin : ' subname '\n'])
end
Pierre Cazenave's avatar
Pierre Cazenave committed
40

41
%--------------------------------------------------------------------------
Pierre Cazenave's avatar
Pierre Cazenave committed
42
% Get a unique list and make sure they are in the range of node numbers 
43
%--------------------------------------------------------------------------
44
Nlist = unique(Nlist,'stable');
Pierre Cazenave's avatar
Pierre Cazenave committed
45

46 47 48 49 50
if max(Nlist) > Mobj.nVerts
    fprintf('your river node number(s) exceed the total number of nodes in the domain\n');
    fprintf('stop screwing around\n');
    error('stopping...\n')
end
Pierre Cazenave's avatar
Pierre Cazenave committed
51

52
%--------------------------------------------------------------------------
Pierre Cazenave's avatar
Pierre Cazenave committed
53
% Plot the mesh 
54
%--------------------------------------------------------------------------
Pierre Cazenave's avatar
Pierre Cazenave committed
55

56 57 58
if strcmpi(Mobj.nativeCoords(1:3), 'car')
    x = Mobj.x;
    y = Mobj.y;
Pierre Cazenave's avatar
Pierre Cazenave committed
59
else
60 61 62
    x = Mobj.lon;
    y = Mobj.lat;
end
Pierre Cazenave's avatar
Pierre Cazenave committed
63 64

figure
65 66 67
patch('Vertices', [x,y], 'Faces', Mobj.tri,...
        'Cdata', Mobj.h, 'edgecolor', 'k', 'facecolor', 'interp');
hold on
Pierre Cazenave's avatar
Pierre Cazenave committed
68

69 70
plot(x(Nlist), y(Nlist), 'ro')
title('river nodes')
Pierre Cazenave's avatar
Pierre Cazenave committed
71 72 73 74 75

% add to mesh object
npts = numel(Nlist);
Mobj.nRivers = Mobj.nRivers + 1;
Mobj.nRivNodes(Mobj.nRivers) = npts;
76
Mobj.riv_nodes(Mobj.nRivers, 1:npts) = Nlist;
Pierre Cazenave's avatar
Pierre Cazenave committed
77 78 79
Mobj.riv_name{Mobj.nRivers} = RiverName;


80 81 82
if ftbverbose
    fprintf(['end   : ' subname '\n'])
end
Pierre Cazenave's avatar
Pierre Cazenave committed
83