add_river_nodes_list.m 2.5 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
%    2013-01-02 KJA bug fix: amended usage of 'unique' to prevent it from
31 32
%    sorting the values it returns. Amended by Pierre to support pre-2012
%    versions of MATLAB whilst giving the same result.
Pierre Cazenave's avatar
Pierre Cazenave committed
33
%   
34 35
%==========================================================================
subname = 'add_river_nodes_list';
Pierre Cazenave's avatar
Pierre Cazenave committed
36
global ftbverbose
37 38 39 40
if ftbverbose
    fprintf('\n')
    fprintf(['begin : ' subname '\n'])
end
Pierre Cazenave's avatar
Pierre Cazenave committed
41

42
%--------------------------------------------------------------------------
Pierre Cazenave's avatar
Pierre Cazenave committed
43
% Get a unique list and make sure they are in the range of node numbers 
44
%--------------------------------------------------------------------------
45 46 47 48
% Make this works in versions of MATLAB older than 2012a (newer versions
% can just use unique(A, 'stable'), but checking versions is a pain).
[~, Nidx] = unique(Nlist);
Nlist = Nlist(sort(Nidx));
Pierre Cazenave's avatar
Pierre Cazenave committed
49

50 51 52 53 54
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
55

56
%--------------------------------------------------------------------------
Pierre Cazenave's avatar
Pierre Cazenave committed
57
% Plot the mesh 
58
%--------------------------------------------------------------------------
Pierre Cazenave's avatar
Pierre Cazenave committed
59

60 61 62
if strcmpi(Mobj.nativeCoords(1:3), 'car')
    x = Mobj.x;
    y = Mobj.y;
Pierre Cazenave's avatar
Pierre Cazenave committed
63
else
64 65 66
    x = Mobj.lon;
    y = Mobj.lat;
end
Pierre Cazenave's avatar
Pierre Cazenave committed
67 68

figure
69 70 71
patch('Vertices', [x,y], 'Faces', Mobj.tri,...
        'Cdata', Mobj.h, 'edgecolor', 'k', 'facecolor', 'interp');
hold on
Pierre Cazenave's avatar
Pierre Cazenave committed
72

73 74
plot(x(Nlist), y(Nlist), 'ro')
title('river nodes')
Pierre Cazenave's avatar
Pierre Cazenave committed
75 76 77 78 79

% add to mesh object
npts = numel(Nlist);
Mobj.nRivers = Mobj.nRivers + 1;
Mobj.nRivNodes(Mobj.nRivers) = npts;
80
Mobj.riv_nodes(Mobj.nRivers, 1:npts) = Nlist;
Pierre Cazenave's avatar
Pierre Cazenave committed
81 82 83
Mobj.riv_name{Mobj.nRivers} = RiverName;


84 85 86
if ftbverbose
    fprintf(['end   : ' subname '\n'])
end
Pierre Cazenave's avatar
Pierre Cazenave committed
87