Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
fvcom-toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
FVCOM
fvcom-toolbox
Commits
66e3f6ee
Commit
66e3f6ee
authored
Jan 14, 2015
by
Pierre Cazenave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tidy up the code a bit and add extra information to the help.
parent
b1cfa623
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
17 deletions
+26
-17
fvcom_prepro/find_nearest_pt.m
fvcom_prepro/find_nearest_pt.m
+26
-17
No files found.
fvcom_prepro/find_nearest_pt.m
View file @
66e3f6ee
function
[
Point
,
Distance
]
=
find_nearest_pt
(
xloc
,
yloc
,
Mobj
)
% Find nearest point in Mesh structure to (x,y)
%
% function [Point,Distance] = find_nearest_pt(xloc,yloc,Mobj)
...
...
@@ -8,11 +7,14 @@ function [Point,Distance] = find_nearest_pt(xloc,yloc,Mobj)
% Find nearest point to (xloc,yloc) in the domain of Mobj
% using native coordinates of Mobj
%
% INPUT:
% INPUT:
% xloc = x location of point (in native Mobj coordinates)
% yloc = y location of point (in native Mobj coordinates)
% Mobj = Mesh object
%
% Mobj = Mesh object with the following fields:
% - nativeCoords = grid type (cartesian or spherical)
% - x, y and/or lon, lat = coordinates (dependent on
% nativeCoords).
%
% OUTPUT:
% Point = index of nearest vertex in the mesh
% Distance = Distance from x,y to Point in Mobj native coordinates
...
...
@@ -22,40 +24,47 @@ function [Point,Distance] = find_nearest_pt(xloc,yloc,Mobj)
%
% Author(s):
% Geoff Cowles (University of Massachusetts Dartmouth)
% Pierre Cazenave (Plymouth Marine Laboratory)
%
% Revision history
%
% 2015-01-14 Tidy up the code a bit and add extra information to the
% help.
%
%==============================================================================
global
ftbverbose
subname
=
'find_nearest_pt'
;
%fprintf('\n')
%fprintf(['begin : ' subname '\n'])
if
ftbverbose
fprintf
(
'\nbegin : %s\n'
,
subname
)
end
%------------------------------------------------------------------------------
% Parse input arguments
%------------------------------------------------------------------------------
if
(
exist
(
'xloc'
)
*
exist
(
'yloc'
)
*
exist
(
'Mobj'
)
==
0
)
error
(
'arguments to
find_nearest_pt are missing'
)
end
;
if
~
exist
(
'xloc'
,
'var'
)
||
~
exist
(
'yloc'
,
'var'
)
||
~
exist
(
'Mobj'
,
'var'
)
error
(
'arguments to
%s are missing'
,
subname
)
end
%------------------------------------------------------------------------------
% Set native coordinates
%------------------------------------------------------------------------------
if
(
lower
(
Mobj
.
nativeCoords
(
1
:
3
))
==
'car
'
)
if
strcmpi
(
Mobj
.
nativeCoords
,
'cartesian
'
)
x
=
Mobj
.
x
;
y
=
Mobj
.
y
;
else
else
if
strcmpi
(
Mobj
.
nativeCoords
,
'spherical'
)
x
=
Mobj
.
lon
;
y
=
Mobj
.
lat
;
end
;
else
error
(
'Unrecognised coordinate type.'
)
end
%------------------------------------------------------------------------------
% Find the nearest point
%------------------------------------------------------------------------------
radvec
=
sqrt
(
(
xloc
-
x
)
.^
2
+
(
yloc
-
y
)
.^
2
);
[
Distance
,
Point
]
=
min
(
radvec
);
[
Distance
,
Point
]
=
min
(
sqrt
((
xloc
-
x
)
.^
2
+
(
yloc
-
y
)
.^
2
));
%fprintf(['end : ' subname '\n'])
if
ftbverbose
fprintf
([
'end : '
subname
'\n'
])
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment