Commit 73161b90 authored by Pierre Cazenave's avatar Pierre Cazenave
Browse files

Add fixes to stop return of sorted arrays when using unique

parent a5d941ec
...@@ -24,10 +24,13 @@ function [Mobj] = add_obc_nodes_list(Mobj,Nlist,ObcName,ObcType,plotFig) ...@@ -24,10 +24,13 @@ function [Mobj] = add_obc_nodes_list(Mobj,Nlist,ObcName,ObcType,plotFig)
% Author(s): % Author(s):
% Geoff Cowles (University of Massachusetts Dartmouth) % Geoff Cowles (University of Massachusetts Dartmouth)
% Pierre Cazenave (Plymouth Marine Laboratory) % Pierre Cazenave (Plymouth Marine Laboratory)
% Karen Amoudry (National Oceanography Centre, Liverpool)
% %
% %
% Revision history: % Revision history:
% 2012-11-26 Add ability to turn off the figures. % 2012-11-26 Add ability to turn off the figures.
% 2013-01-02 KJA bug fix: amended usage of 'unique' in line 50 to
% prevent it from sorting the values it returns.
% %
%========================================================================== %==========================================================================
subname = 'add_obc_nodes'; subname = 'add_obc_nodes';
...@@ -45,7 +48,7 @@ end ...@@ -45,7 +48,7 @@ end
%-------------------------------------------------------------------------- %--------------------------------------------------------------------------
% Get a unique list and make sure they are in the range of node numbers % Get a unique list and make sure they are in the range of node numbers
%-------------------------------------------------------------------------- %--------------------------------------------------------------------------
Nlist = unique(Nlist); Nlist = unique(Nlist,'stable');
if(max(Nlist) > Mobj.nVerts); if(max(Nlist) > Mobj.nVerts);
fprintf('your open boundary node number exceed the total number of nodes in the domain\n'); fprintf('your open boundary node number exceed the total number of nodes in the domain\n');
......
...@@ -20,12 +20,15 @@ function [Mobj] = add_river_nodes_list(Mobj,Nlist,RiverName) ...@@ -20,12 +20,15 @@ function [Mobj] = add_river_nodes_list(Mobj,Nlist,RiverName)
% %
% Author(s): % Author(s):
% Geoff Cowles (University of Massachusetts Dartmouth) % Geoff Cowles (University of Massachusetts Dartmouth)
% Karen Amoudry (National Oceanography Centre, Liverpool)
% %
% Note: % Note:
% Uses ginput2 which allows zooming before selecting points and displays % Uses ginput2 which allows zooming before selecting points and displays
% clicked points realtime % clicked points realtime
% %
% Revision history % Revision history
% 2013-01-02 KJA bug fix: amended usage of 'unique' to prevent it from
% sorting the values it returns.
% %
%========================================================================== %==========================================================================
subname = 'add_river_nodes_list'; subname = 'add_river_nodes_list';
...@@ -38,7 +41,7 @@ end ...@@ -38,7 +41,7 @@ end
%-------------------------------------------------------------------------- %--------------------------------------------------------------------------
% Get a unique list and make sure they are in the range of node numbers % Get a unique list and make sure they are in the range of node numbers
%-------------------------------------------------------------------------- %--------------------------------------------------------------------------
Nlist = unique(Nlist); Nlist = unique(Nlist,'stable');
if max(Nlist) > Mobj.nVerts if max(Nlist) > Mobj.nVerts
fprintf('your river node number(s) exceed the total number of nodes in the domain\n'); fprintf('your river node number(s) exceed the total number of nodes in the domain\n');
......
...@@ -22,7 +22,11 @@ function [spongeRadius] = calc_sponge_radius(Mobj,Nlist) ...@@ -22,7 +22,11 @@ function [spongeRadius] = calc_sponge_radius(Mobj,Nlist)
% spongeRadius = calc_sponge_radius(Mobj,Nlist) % spongeRadius = calc_sponge_radius(Mobj,Nlist)
% %
% Author(s) % Author(s)
% Karen Thurston (National Oceanography Centre, Liverpool) % Karen Amoudry (National Oceanography Centre, Liverpool)
%
% Revision history:
% 2013-01-02 KJA bug fix: amended usage of 'unique' to prevent it from
% sorting the values it returns.
% %
%========================================================================== %==========================================================================
subname = 'calc_sponge_radius'; subname = 'calc_sponge_radius';
...@@ -35,7 +39,7 @@ end ...@@ -35,7 +39,7 @@ end
%-------------------------------------------------------------------------- %--------------------------------------------------------------------------
% Get a unique list and make sure they are in the range of node numbers % Get a unique list and make sure they are in the range of node numbers
%-------------------------------------------------------------------------- %--------------------------------------------------------------------------
Nlist = unique(Nlist); Nlist = unique(Nlist,'stable');
spongeRadius = 100000+zeros(size(Nlist)); spongeRadius = 100000+zeros(size(Nlist));
...@@ -43,7 +47,7 @@ spongeRadius = 100000+zeros(size(Nlist)); ...@@ -43,7 +47,7 @@ spongeRadius = 100000+zeros(size(Nlist));
for i =1:length(Nlist) for i =1:length(Nlist)
% Find the neighbouring nodes % Find the neighbouring nodes
[r,c]=find(Mobj.tri==Nlist(i)); [r,c]=find(Mobj.tri==Nlist(i));
neighbours = unique(Mobj.tri(r,:)); neighbours = unique(Mobj.tri(r,:),'stable');
% Remove the node of interest from the neighbours list % Remove the node of interest from the neighbours list
n = find(neighbours~=Nlist(i)); n = find(neighbours~=Nlist(i));
......
...@@ -44,6 +44,7 @@ function Mobj = get_FVCOM_rivers(Mobj, dist_thresh) ...@@ -44,6 +44,7 @@ function Mobj = get_FVCOM_rivers(Mobj, dist_thresh)
% %
% Author(s): % Author(s):
% Pierre Cazenave (Plymouth Marine Laboratory) % Pierre Cazenave (Plymouth Marine Laboratory)
% Karen Amoudry (National Oceanography Centre, Liverpool)
% %
% Revision history: % Revision history:
% 2013-03-27 - First version. % 2013-03-27 - First version.
...@@ -59,6 +60,8 @@ function Mobj = get_FVCOM_rivers(Mobj, dist_thresh) ...@@ -59,6 +60,8 @@ function Mobj = get_FVCOM_rivers(Mobj, dist_thresh)
% searches for another node in the element which is part of at least two % searches for another node in the element which is part of at least two
% elements, thereby avoiding the "element filling" issue. Also updated % elements, thereby avoiding the "element filling" issue. Also updated
% the help to list all the required fields in the Mobj. % the help to list all the required fields in the Mobj.
% 2013-01-02 KJA bug fix: amended usage of 'unique' to prevent it from
% sorting the values it returns.
% %
%========================================================================== %==========================================================================
...@@ -87,7 +90,7 @@ polcoms_flow = Mobj.rivers.discharge; ...@@ -87,7 +90,7 @@ polcoms_flow = Mobj.rivers.discharge;
% For duplicates, we need, therefore, to work out a way to handle them % For duplicates, we need, therefore, to work out a way to handle them
% elegantly. We will assume that rivers with the same name are close to one % elegantly. We will assume that rivers with the same name are close to one
% another. As such, we'll sum their discharges. % another. As such, we'll sum their discharges.
[~, di] = unique(fvcom_name, 'first'); [~, di] = unique(fvcom_name, 'first','stable');
fv_dupes = 1:length(fvcom_name); fv_dupes = 1:length(fvcom_name);
fv_dupes(di) = []; % index of duplicates (does this work with more than two?) fv_dupes(di) = []; % index of duplicates (does this work with more than two?)
...@@ -229,7 +232,7 @@ end ...@@ -229,7 +232,7 @@ end
% Now we've got a list and some of the nodes will be duplicates. Sum the % Now we've got a list and some of the nodes will be duplicates. Sum the
% discharge values assigned to those nodes. % discharge values assigned to those nodes.
fv_uniq_obc = unique(fv_obc); fv_uniq_obc = unique(fv_obc,'stable');
fv_uniq_flow = nan(pc_nt, length(fv_uniq_obc)); fv_uniq_flow = nan(pc_nt, length(fv_uniq_obc));
fv_uniq_names = cell(length(fv_uniq_obc), 1); fv_uniq_names = cell(length(fv_uniq_obc), 1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment