SPEED
GET_NEAREST_NODE_PGM.f90
Go to the documentation of this file.
1! Copyright (C) 2012 The SPEED FOUNDATION
2! Author: Ilario Mazzieri
3!
4! This file is part of SPEED.
5!
6! SPEED is free software; you can redistribute it and/or modify it
7! under the terms of the GNU Affero General Public License as
8! published by the Free Software Foundation, either version 3 of the
9! License, or (at your option) any later version.
10!
11! SPEED is distributed in the hope that it will be useful, but
12! WITHOUT ANY WARRANTY; without even the implied warranty of
13! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14! Affero General Public License for more details.
15!
16! You should have received a copy of the GNU Affero General Public License
17! along with SPEED. If not, see <http://www.gnu.org/licenses/>.
18
34
35 subroutine get_nearest_node_pgm(nloc,xs,ys,zs,xt,yt,zt,nt,dist_min,elevation)
36
37 implicit none
38
39 integer*4 :: i, nloc, nt
40
41 real*8 :: xt,yt,zt
42 real*8 :: elevation
43 real*8 :: dist,dist_min
44
45 real*8, dimension(nloc) :: xs, ys, zs
46
47 dist_min = 1.0d30
48 nt = 1
49
50 do i = 1,nloc
51
52 if (zs(i) .gt. elevation) then
53
54 dist = dsqrt((xs(i) - xt)*(xs(i) - xt) + (ys(i) - yt)*(ys(i) - yt) + (zs(i) - zt)*(zs(i) - zt))
55
56 if (dist .lt. dist_min) then
57 dist_min = dist; nt = i
58 endif
59
60 endif
61
62 enddo
63
64 return
65 end subroutine get_nearest_node_pgm
66
subroutine get_nearest_node_pgm(nloc, xs, ys, zs, xt, yt, zt, nt, dist_min
Computes the nearest node with respet to (xt,yt,zt) starting from a given elevation.