24 integer,
allocatable :: from_eff(:)
41 subroutine kdtree_create(kdtree,mpl,n,lon,lat,mask,sort,rearrange)
46 class(kdtree_type),
intent(inout) :: kdtree
47 type(mpl_type),
intent(in) :: mpl
48 integer,
intent(in) :: n
49 real(kind_real),
intent(in) :: lon(n)
50 real(kind_real),
intent(in) :: lat(n)
51 logical,
intent(in),
optional :: mask(n)
52 logical,
intent(in),
optional :: sort
53 logical,
intent(in),
optional :: rearrange
56 integer :: neff,i,ieff
57 real(kind_real),
allocatable :: input_data(:,:)
58 logical :: lmask(n),lsort,lrearrange
61 if (
present(mask))
then 68 if (
present(sort))
then 75 if (
present(rearrange))
then 76 lrearrange = rearrange
85 if (neff<1)
call mpl%abort(
'mask should have at least one valid point to create a kdtree')
88 allocate(input_data(3,neff))
89 allocate(kdtree%from_eff(neff))
98 call trans(1,lat(i),lon(i),input_data(1,ieff),input_data(2,ieff),input_data(3,ieff))
101 kdtree%from_eff(ieff) = i
106 kdtree%tp =>
kdtree2_create(input_data,sort=lsort,rearrange=lrearrange)
119 class(kdtree_type),
intent(inout) :: kdtree
121 if (
allocated(kdtree%from_eff))
then 123 deallocate(kdtree%from_eff)
140 class(kdtree_type),
intent(in) :: kdtree
141 real(kind_real),
intent(in) :: lon
142 real(kind_real),
intent(in) :: lat
143 integer,
intent(in) :: nn
144 integer,
intent(out) :: nn_index(nn)
145 real(kind_real),
intent(out) :: nn_dist(nn)
149 integer,
allocatable :: order(:)
150 real(kind_real) :: lontmp(1),lattmp(1)
151 real(kind_real) :: qv(3)
152 type(kdtree2_result) :: results(nn)
160 call trans(1,lattmp,lontmp,qv(1),qv(2),qv(3))
165 nn_index(i) = kdtree%from_eff(results(i)%idx)
166 nn_dist(i) = results(i)%sdis
175 if (abs(nn_dist(i)-nn_dist(j))<
rth*nn_dist(i)) nid = nid+1
181 call qsort(nid,nn_index(i:i+nid-1),order)
183 nn_dist(i+j-1) = nn_dist(i+order(j)-1)
203 class(kdtree_type),
intent(in) :: kdtree
204 real(kind_real),
intent(in) :: lon
205 real(kind_real),
intent(in) :: lat
206 real(kind_real),
intent(in) :: sr
207 integer,
intent(out) :: nn
210 real(kind_real) :: lontmp(1),lattmp(1)
211 real(kind_real) :: qv(3),brsq
218 call trans(1,lattmp,lontmp,qv(1),qv(2),qv(3))
221 brsq = (1.0-cos(sr))**2+sin(sr)**2
subroutine kdtree_dealloc(kdtree)
subroutine kdtree_create(kdtree, mpl, n, lon, lat, mask, sort, rearrange)
subroutine, public create(self, geom, vars)
Linked list implementation.
subroutine kdtree_count_nearest_neighbors(kdtree, lon, lat, sr, nn)
subroutine kdtree_find_nearest_neighbors(kdtree, lon, lat, nn, nn_index, nn_dist)
integer, parameter, public kind_real