SPEED
GET_NEAREST_NODE.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
19
33
34 subroutine get_nearest_node(n,xs,ys,zs,xt,yt,zt,nt,dist_min)
35
36 implicit none
37
38 integer*4 :: n,nt, i
39 integer*4, dimension(1) :: pos
40
41 !real*8 :: dx,dy,dz,d2,d2min
42 real*8 :: xt,yt,zt
43 real*8 :: dist_min
44
45 real*8, dimension(n) :: xs,ys,zs
46 real*8, dimension(n) :: dist_all
47
48 !d2min = 1.0d30
49
50 !do i = 1,n
51 ! dx = xs(i) - xt
52 ! dy = ys(i) - yt
53 ! dz = zs(i) - zt
54 ! d2 = dx*dx + dy*dy + dz*dz
55 ! if (d2.lt.d2min) then
56 ! d2min = d2
57 ! nt = i
58 !
59 ! endif
60 !enddo
61
62 dist_all = (xs-xt)*(xs-xt) + (ys-yt)*(ys-yt) + (zs-zt)*(zs-zt)
63 dist_min = minval(dist_all)
64 pos = minloc(dist_all); nt = pos(1)
65
66
67 return
68 end subroutine get_nearest_node
69
subroutine get_nearest_node(n, xs, ys, zs, xt, yt, zt, nt, dist_min)
Computes the nearest node with respet to (xt,yt,zt).