-
Notifications
You must be signed in to change notification settings - Fork 1
/
runner.f90
737 lines (572 loc) · 21.3 KB
/
runner.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
program kd_tester
use kd_tree, only : kdnode
use kd_tree, only : kd_insert, kd_construct, kd_search, kd_remove
use kd_tree, only : kd_free
use kd_tree, only : kd_find_min
use getoptf
implicit none
integer :: argc
character (len=255) :: argv
character :: c
integer :: npoints
integer :: ndims
integer :: lrange
integer :: urange
integer :: ntests
integer :: npoints_l
integer :: npoints_u
integer :: ndims_l
integer :: ndims_u
namelist /testVars/ npoints, ndims, lrange, urange, ntests, npoints_l, npoints_u, ndims_l, ndims_u
open(42,file='namelist.input', status='old',form='formatted',action='read')
read(42, testVars)
close(42)
argc = command_argument_count()
call get_command(argv)
do while ( getopt(argc, argv, c, "12345d") )
select case (c)
case ('2')
write(0,*) "Launching test 2"
call test2(npoints, ndims, lrange, urange)
case ('3')
write(0,*) "Launching test 3"
call test3(npoints, ndims, lrange, urange)
case ('4')
write(0,*) "Launching test 4"
call test4(ntests, lrange, urange, npoints_l, npoints_u, ndims_l, ndims_u)
case ('5')
write(0,*) "Launching test 5"
call test5(ntests, npoints, ndims, lrange, urange)
case ('6')
write(0,*) "Launching test 6"
call test6(ntests, lrange, urange, npoints_l, npoints_u, ndims_l, ndims_u)
case ('m')
write(0,*) "Launching Minimum Test"
call test_min(ntests, lrange, urange, npoints_l, npoints_u, ndims_l, ndims_u)
case ('r')
write(0,*) "Launching remove Test"
call test_remove(ntests, lrange, urange, npoints_l, npoints_u, ndims_l, ndims_u)
case ('d')
write(0,*) "Launching remove Test"
call test_distance2(ntests, lrange, urange, npoints_l, npoints_u, ndims_l, ndims_u)
case ('i')
write(0,*) "Launching insert test"
call test_insert(ntests, lrange, urange, npoints_l, npoints_u, ndims_l, ndims_u)
endselect
enddo
contains
subroutine test_distance2(ntests, lrange, urange, npoints_l, npoints_u, ndims_l, ndims_u)
implicit none
integer, intent(in), value :: ntests
integer, intent(in), value :: lrange
integer, intent(in), value :: urange
integer, intent(in), value :: npoints_l
integer, intent(in), value :: npoints_u
integer, intent(in), value :: ndims_l
integer, intent(in), value :: ndims_u
type(kdnode), pointer :: tree => null()
real, dimension(:,:), pointer :: arry1, arry2
real, dimension(ndims) :: min_point
integer :: i, j, tests
real :: r_ndims, r_npoints
integer :: ndims, npoints
real :: min_d, dis, bf_min
real, dimension(:), allocatable :: minimum
real, dimension(:), allocatable :: result, actuall_min_point
do tests = 1, ntests, 1
call random_number(r_ndims)
call random_number(r_npoints)
ndims = int((r_ndims * (ndims_u + 1 - ndims_l)) + ndims_l)
npoints = int((r_npoints * (npoints_u + 1 - npoints_l)) + npoints_l)
write(0,*) ""
write(0,*) "Test number: ", tests
write(0,*) "ndims: ", ndims, " npoints: ", npoints
allocate(arry1(ndims, npoints))
allocate(arry2(ndims, npoints))
allocate(minimum(ndims))
allocate(result(ndims))
call random_number(arry1(:,:))
call random_number(arry2(:,:))
arry1 = (arry1(:,:) * (urange + 1 - lrange)) + lrange
arry2 = (arry2(:,:) * (urange + 1 - lrange)) + lrange
tree => kd_construct(arry1(:,:))
do i = 1, size(arry2, dim=2)
min_d = huge(min_d)
call kd_search(tree, arry2(:,i), result, min_d)
bf_min = huge(bf_min)
dis = huge(dis)
do j = 1, size(arry1, dim=2), 1
dis = sum((arry2(:,i) - arry1(:,j))**2)
if (dis < bf_min) then
bf_min = dis
actuall_min_point = arry1(:,j)
endif
end do
if (bf_min /= min_d) then
call print_tree(tree, 0, 0)
write(0,*) "We did not find the nearest neighbor :("
write(0,*) "Search Distance: ", min_d
write(0,*) "Actual Distance: ", bf_min
write(0,*) "We were searching for: "
write(0,*) arry2(:,i)
write(0,*) "KD Search found: "
write(0,*) result(:)
write(0,*) "BF actual nearest neighbor: "
write(0,*) actuall_min_point(:)
stop
endif
enddo
deallocate(arry1)
deallocate(arry2)
deallocate(minimum)
deallocate(result)
call kd_free(tree)
enddo
end subroutine test_distance2
subroutine test_insert(ntests, lrange, urange, npoints_l, npoints_u, ndims_l, ndims_u)
implicit none
integer, intent(in), value :: ntests
integer, intent(in), value :: lrange
integer, intent(in), value :: urange
integer, intent(in), value :: npoints_l
integer, intent(in), value :: npoints_u
integer, intent(in), value :: ndims_l
integer, intent(in), value :: ndims_u
type(kdnode), pointer :: tree => null()
real, dimension(:,:), pointer :: arry1, arry2
real, dimension(:), pointer :: result
integer :: i, j, tests
real :: r_ndims, r_npoints
integer :: ndims2, npoints2
real :: min_d, dis, bf_min
do tests = 1, ntests, 1
call random_number(r_ndims)
call random_number(r_npoints)
ndims = int((r_ndims * (ndims_u + 1 - ndims_l)) + ndims_l)
npoints = int((r_npoints * (npoints_u + 1 - npoints_l)) + npoints_l)
write(0,*) ""
write(0,*) "Test number: ", tests
write(0,*) "ndims: ", ndims, " npoints: ", npoints
allocate(arry1(ndims, npoints))
allocate(arry2(ndims, npoints))
allocate(result(ndims))
call random_number(arry1(:,:))
call random_number(arry2(:,:))
arry1 = (arry1(:,:) * (urange + 1 - lrange)) + lrange
arry2 = (arry2(:,:) * (urange + 1 - lrange)) + lrange
do i = 1, size(arry2, dim=2)
call kd_insert(tree, arry1(:, i))
min_d = huge(min_d)
call kd_search(tree, arry1(:,i), result, min_d)
if ( .NOT. all(arry1(:,i) == result(:))) then
write(0,*) "We could not find the node we just inserted.. :("
stop
endif
enddo
deallocate(arry1)
deallocate(arry2)
deallocate(result)
call kd_free(tree)
enddo
end subroutine test_insert
subroutine test2(npoints, ndims, lrange, urange)
implicit none
integer, intent(in), value :: npoints, ndims
integer, intent(in), value :: lrange, urange
type(kdnode), pointer :: rTree => null()
real, dimension(ndims, npoints) :: arry1, arry2
real, dimension(ndims) :: result
real :: min_d
integer :: i, r, k, n
min_d = huge(min_d)
write(0,*) "Real test: "
write(0,*) "Num Points: ", npoints
write(0,*) "Num Dims: ", ndims
call random_number(arry1)
call random_number(arry2)
arry1 = (arry1(:,:) * (urange + 1 - lrange)) + lrange
arry2 = (arry2(:,:) * (urange + 1 - lrange)) + lrange
rTree => kd_construct(arry1)
write(0,*) ""
if (associated(rTree)) then
write(0,*) "Real Tree Node: ", rTree % point
if (associated(rTree % left)) then
write(0,*) "Left tree was associated"
write(0,*) rTree % left % point
else
write(0,*) "Left tree was NOT associated"
endif
if (associated(rTree % right)) then
write(0,*) "Right tree was associated"
write(0,*) rTree % right % point
else
write(0,*) "Right tree was NOT associated"
endif
else
write(0,*) "rTree was not associated :'("
endif
write(0,*) ""
write(0,*) "Searching Test!"
write(0,*) ""
write(0,*) "Searching all points currently in the tree"
write(0,*) ""
do i = 1, size(arry1, dim=2)
min_d = huge(min_d)
call kd_search(rTree, arry1(:, i), result, min_d)
if (.NOT. (all(result(:) == arry1(:,i)) .AND. min_d == 0.0)) then
write(0,*) "That point wasn't in the tree, but its cloest point was: ", result, "and the dist: ", sqrt(min_d)
endif
enddo
write(0,*) ""
write(0,*) "Searching for randomly created points"
write(0,*) ""
do i = 1, size(arry2, dim=2)
min_d = huge(min_d)
call kd_search(rTree, arry2(:, i), result, min_d)
if (.NOT. (all(result(:) == arry2(:,i)) .AND. min_d == 0.0)) then
write(0,*) "That point wasn't in the tree, but its cloest point was: ", result, "and the dist: ", sqrt(min_d)
endif
enddo
call kd_free(rTree)
end subroutine test2
subroutine test3(npoints, ndims, lrange, urange)
use iso_c_binding, only : c_int
implicit none
interface
subroutine timer_start(timer_id) bind(C)
use iso_c_binding, only : c_int
integer (c_int), intent(in), value :: timer_id
end subroutine timer_start
subroutine timer_stop(timer_id, sec, nsec) bind(C)
use iso_c_binding, only : c_int
integer (c_int), intent(in), value :: timer_id
integer (c_int), intent(out) :: sec, nsec
end subroutine timer_stop
end interface
integer (c_int) :: timer_id, sec, nsec
integer, intent(in), value :: npoints, ndims
integer, intent(in), value :: lrange, urange
type(kdnode), pointer :: rTree => null()
real, dimension(ndims, npoints) :: arry1, arry2
real, dimension(ndims) :: result
real :: min_d
integer :: i, r, k, n
min_d = huge(min_d)
write(0,*) "Timing test. Size: ", npoints, " dims: ", ndims
call random_number(arry1)
call random_number(arry2)
arry1 = (arry1(:,:) * (urange + 1 - lrange)) + lrange
arry2 = (arry2(:,:) * (urange + 1 - lrange)) + lrange
write(0,*) "Constructing tree..."
call timer_start(0)
rTree => kd_construct(arry1)
call timer_stop(0, sec, nsec)
write(0,*) "Tree constructed... time: ", sec, nsec
write(0,*) "Searching for points that are within the tree..."
call timer_start(0)
do i = 1, size(arry1, dim=2)
call kd_search(rTree, arry1(:, i), result, min_d)
enddo
call timer_stop(0, sec, nsec)
write(0,*) "time: ", sec, nsec
write(0,*) "Searching for points that are NOT within the tree..."
call timer_start(0)
do i = 1, size(arry1, dim=2)
call kd_search(rTree, arry2(:, i), result, min_d)
enddo
call timer_stop(0, sec, nsec)
write(0,*) "time: ", sec, nsec
write(0,*) "Freeing rTree"
call timer_start(0)
call kd_free(rTree)
call timer_stop(0, sec, nsec)
write(0,*) "time: ", sec, nsec
write(0,*) "=============================================="
write(0,*) "Testing timing for inserting nodes"
call timer_start(0)
do i = 1, size(arry1, dim=2)
call kd_insert(rTree, arry1(:, i))
enddo
call timer_stop(0, sec, nsec)
write(0,*) "Tree insertion creation time: ", sec, nsec
write(0,*) "Searching for points that are within the INSERTED tree..."
call timer_start(0)
do i = 1, size(arry1, dim=2)
call kd_search(rTree, arry1(:, i), result, min_d)
enddo
call timer_stop(0, sec, nsec)
write(0,*) "time: ", sec, nsec
write(0,*) "Searching for points that are NOT within the INSERTED tree..."
call timer_start(0)
do i = 1, size(arry1, dim=2)
call kd_search(rTree, arry2(:, i), result, min_d)
enddo
call timer_stop(0, sec, nsec)
write(0,*) "time: ", sec, nsec
write(0,*) "Freeing rTree"
call timer_start(0)
call kd_free(rTree)
call timer_stop(0, sec, nsec)
write(0,*) "time: ", sec, nsec
end subroutine test3
function search_tree(tree, point)
implicit none
type(kdnode), pointer, intent(in) :: tree
real, dimension(:), intent(in) :: point
real, dimension(size(point, dim=1)) :: result
logical search_tree
real :: min_d
search_tree = .TRUE.
min_d = huge(min_d)
!write(0,*) "New Search", point
call kd_search(tree, point, result, min_d)
if (.NOT. (all(result(:) == point(:)) .AND. min_d == 0.0)) then
write(0,*) point(:), " was not in the tree, but its cloest point was: ", result, "and the dist: ", sqrt(min_d)
search_tree = .FALSE.
return
endif
end function search_tree
subroutine test4(ntests, lrange, urange, npoints_l, npoints_u, ndims_l, ndims_u)
implicit none
integer, intent(in), value :: ntests
integer, intent(in), value :: lrange
integer, intent(in), value :: urange
integer, intent(in), value :: npoints_l
integer, intent(in), value :: npoints_u
integer, intent(in), value :: ndims_l
integer, intent(in), value :: ndims_u
real, dimension(:,:), pointer :: arry1, arry2
type(kdnode), pointer :: tree => null()
real :: r_ndims, r_npoints
integer :: ndims, npoints
integer :: i, j
write(0,*) "Running Random tests"
write(0,*) " running ", ntests, " tests"
write(0,*) ""
do i = 1, ntests, 1
call random_number(r_ndims)
call random_number(r_npoints)
ndims = int((r_ndims * (ndims_u + 1 - ndims_l)) + ndims_l)
npoints = int((r_npoints * (npoints_u + 1 - npoints_l)) + npoints_l)
write(0,*) "Test number: ", i
write(0,*) "ndims: ", ndims, " npoints: ", npoints
allocate(arry1(ndims, npoints))
allocate(arry2(ndims, npoints))
call random_number(arry1(:,:))
call random_number(arry2(:,:))
arry1 = (arry1(:,:) * (urange + 1 - lrange)) + lrange
arry2 = (arry2(:,:) * (urange + 1 - lrange)) + lrange
tree => kd_construct(arry1)
!write(0,*) "Arry1: ", arry1
do j = 1, size(arry1, dim=2), 1
if( .NOT. search_tree(tree, arry1(:,j))) then
write(0,*) "This point was not found"
call print_tree(tree, 0, 0)
stop
endif
enddo
deallocate(arry1)
deallocate(arry2)
call kd_free(tree)
enddo
end subroutine test4
subroutine test5(ntests, npoints, ndims, lrange, urange)
implicit none
integer, intent(in), value :: ntests
integer, intent(in), value :: npoints
integer, intent(in), value :: ndims
integer, intent(in), value :: lrange
integer, intent(in), value :: urange
type(kdnode), pointer :: tree => null()
real, dimension(:,:), pointer :: arry1, arry2
integer :: i, j
real :: r_ndims, r_npoints
integer :: ndims2, npoints2
allocate(arry1(ndims, npoints))
allocate(arry2(ndims, npoints))
call random_number(arry1(:,:))
call random_number(arry2(:,:))
arry1(:,:) = (arry1(:,:) * (urange + 1 - lrange)) + lrange
arry2(:,:) = (arry2(:,:) * (urange + 1 - lrange)) + lrange
write(0,*) "Number of points: ", npoints, " Number of dims: ", ndims
do i = 1, size(arry1, dim=2), 1
call kd_insert(tree, arry1(:,i))
enddo
write(0,*) "All ", npoints, "were added into the tree!"
do i = 1, size(arry1, dim=2), 1
if( .NOT. search_tree(tree, arry1(:,i))) then
write(0,*) "This point was not found! But it should have been!!"
stop
endif
enddo
write(0,*) "All points that were inserted to make the tree were succesfully found within the tree!!"
call kd_free(tree)
end subroutine test5
subroutine test6(ntests, lrange, urange, npoints_l, npoints_u, ndims_l, ndims_u)
implicit none
integer, intent(in), value :: ntests
integer, intent(in), value :: lrange
integer, intent(in), value :: urange
integer, intent(in), value :: npoints_l
integer, intent(in), value :: npoints_u
integer, intent(in), value :: ndims_l
integer, intent(in), value :: ndims_u
real, dimension(:,:), pointer :: arry1, arry2
type(kdnode), pointer :: tree => null()
real :: r_ndims, r_npoints
integer :: ndims, npoints
integer :: i, j
write(0,*) "Running Random tests with insert"
write(0,*) " running ", ntests, " tests"
write(0,*) ""
do i = 1, ntests, 1
call random_number(r_ndims)
call random_number(r_npoints)
ndims = int((r_ndims * (ndims_u + 1 - ndims_l)) + ndims_l)
npoints = int((r_npoints * (npoints_u + 1 - npoints_l)) + npoints_l)
write(0,*) "Test number: ", i
write(0,*) "ndims: ", ndims, " npoints: ", npoints
allocate(arry1(ndims, npoints))
allocate(arry2(ndims, npoints))
call random_number(arry1(:,:))
call random_number(arry2(:,:))
arry1 = (arry1(:,:) * (urange + 1 - lrange)) + lrange
arry2 = (arry2(:,:) * (urange + 1 - lrange)) + lrange
do j = 1, npoints, 1
call kd_insert(tree, arry1(:, j))
enddo
!write(0,*) "Arry1: ", arry1
do j = 1, size(arry1, dim=2), 1
if( .NOT. search_tree(tree, arry1(:,j))) then
write(0,*) "This point was not found"
stop
endif
enddo
deallocate(arry1)
deallocate(arry2)
call kd_free(tree)
enddo
end subroutine test6
subroutine test_min(ntests, lrange, urange, npoints_l, npoints_u, ndims_l, ndims_u)
implicit none
integer, intent(in), value :: ntests
integer, intent(in), value :: lrange
integer, intent(in), value :: urange
integer, intent(in), value :: npoints_l
integer, intent(in), value :: npoints_u
integer, intent(in), value :: ndims_l
integer, intent(in), value :: ndims_u
type(kdnode), pointer :: tree => null()
real, dimension(:,:), pointer :: arry1, arry2
real, dimension(ndims) :: min_point
real, dimension(2,7) :: arry3
real :: r_ndims, r_npoints, r_test_dim
integer :: test_dim
real, dimension(:), pointer :: minimum
integer :: ndims2, npoints2
integer :: test, i, j
do test = 1, ntests
call random_number(r_ndims)
call random_number(r_npoints)
npoints = int((r_npoints * (npoints_u + 1 - npoints_l)) + npoints_l)
ndims = int((r_ndims * (ndims_u + 1 - ndims_l)) + ndims_l)
allocate(arry1(ndims, npoints))
allocate(arry2(ndims, npoints))
allocate(minimum(ndims))
call random_number(arry1(:,:))
call random_number(arry2(:,:))
arry1 = (arry1(:,:) * (urange + 1 - lrange)) + lrange
arry2 = (arry2(:,:) * (urange + 1 - lrange)) + lrange
write(0,*) "Test number: ", test
write(0,*) "ndims: ", ndims, " npoints: ", npoints
tree => kd_construct(arry1(:,:))
! Test each dimension
do test_dim = 1, ndims, 1
call kd_find_min(tree, minimum, test_dim)
if( .NOT. ( minimum(test_dim) == minval(arry1(test_dim,:)) )) then
write(0,*) "We found the wrong minimum in dimension: ", test_dim
write(0,*) "Min we found was: ", minimum
write(0,*) "Actual minimum was: ", minval(arry1(test_dim,:))
stop
endif
enddo
call kd_free(tree)
deallocate(arry1)
deallocate(arry2)
deallocate(minimum)
enddo
write(0,*) "All tests finished!"
end subroutine test_min
recursive subroutine print_tree(tree, left_or_right, level)
implicit none
type(kdnode), intent(inout), pointer :: tree
integer, value :: left_or_right
integer, value :: level
if ( .NOT. associated(tree)) then
write(0,*) " I AM AN UNASSOCIATED NODE"
return
endif
if (associated(tree) .AND. associated(tree % point)) then
if (left_or_right == -1) then
write(0,*) "Level: ", level, "Left: ", tree % point(:)
elseif (left_or_right == 0) then
write(0,*) "Level: ", level, "Root: ", tree % point(:)
elseif (left_or_right == 1) then
write(0,*) "Level: ", level, "Right: ", tree % point(:)
endif
endif
if ( associated(tree % left)) call print_tree(tree % left, -1, level + 1)
if ( associated(tree % right)) call print_tree(tree % right, 1, level + 1)
end subroutine print_tree
subroutine test_remove(ntests, lrange, urange, npoints_l, npoints_u, ndims_l, ndims_u)
implicit none
integer, intent(in), value :: ntests
integer, intent(in), value :: lrange
integer, intent(in), value :: urange
integer, intent(in), value :: npoints_l
integer, intent(in), value :: npoints_u
integer, intent(in), value :: ndims_l
integer, intent(in), value :: ndims_u
type(kdnode), pointer :: tree => null()
real, dimension(:,:), pointer :: arry1, arry2
real, dimension(ndims) :: min_point
real, dimension(3,10) :: arry3
integer :: i, j
real :: r_ndims, r_npoints
real, dimension(ndims) :: minimum
integer :: ndims2, npoints2
do j = 1, ntests, 1
call random_number(r_ndims)
call random_number(r_npoints)
ndims = int((r_ndims * (ndims_u + 1 - ndims_l)) + ndims_l)
npoints = int((r_npoints * (npoints_u + 1 - npoints_l)) + npoints_l)
write(0,*) "Test number: ", j
write(0,*) "ndims: ", ndims, " npoints: ", npoints
allocate(arry1(ndims, npoints))
allocate(arry2(ndims, npoints))
call random_number(arry1(:,:))
call random_number(arry2(:,:))
arry1 = (arry1(:,:) * (urange + 1 - lrange)) + lrange
arry2 = (arry2(:,:) * (urange + 1 - lrange)) + lrange
tree => kd_construct(arry1(:,:))
do i = 1, size(arry1, dim=2), 1
if(associated(tree)) then
if(.NOT. kd_remove(tree, arry1(:,i))) then
write(0,*) "We were not able to remove the point: ", arry1(:,i)
stop
endif
else
write(0,*) "The tree is no long associated"
endif
enddo
if ( associated(tree) ) then
write(0,*) "This tree was still associated :("
write(0,*) tree % point
stop
endif
deallocate(arry1)
deallocate(arry2)
call kd_free(tree)
enddo
end subroutine test_remove
end program kd_tester