-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_interface.F90
More file actions
67 lines (45 loc) · 1.91 KB
/
test_interface.F90
File metadata and controls
67 lines (45 loc) · 1.91 KB
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
! Some interface code to test the gaussian_filter from python. The
! gaussian_filter module can't be called directly from Python because it has
! assumed shape arrays. Also f2py needs kind=8 to use double reals.
module test_interface
use gaussian_filter, only: gaussian_kernel, convolve, tile_and_reflect, assert
implicit none
private
public run_gaussian_filter, run_tile_and_reflect
contains
subroutine run_gaussian_filter(sigma, truncate, kx, ky, kernel, &
nx, ny, input, output, mask, has_mask)
real(kind=8), intent(in) :: sigma, truncate
! Indices and output for kernel
integer, intent(in) :: kx, ky
real(kind=8), intent(out), dimension(kx, ky) :: kernel
! Indices and data input/output
integer, intent(in) :: nx, ny
real(kind=8), intent(in), dimension(nx, ny) :: input
real(kind=8), intent(out), dimension(nx, ny) :: output
real(kind=8), intent(in), dimension(nx, ny) :: mask
! Since f2py does not support optional arguments.
logical, intent(in) :: has_mask
! Get the kernel first.
real, allocatable, dimension(:,:) :: k
call gaussian_kernel(sigma, k, truncate)
call assert(all(shape(k) - shape(kernel) == 0), &
'Kernel shapes do not match')
kernel(:, :) = k(:, :)
if (has_mask) then
call convolve(input, kernel, output, mask)
else
call convolve(input, kernel, output)
endif
end subroutine run_gaussian_filter
subroutine run_tile_and_reflect(input, x, y, output)
integer, intent(in) :: x, y
real(kind=8), intent(in), dimension(x, y) :: input
real(kind=8), intent(out), dimension(3*x, 3*y) :: output
real(kind=8), allocatable, dimension(:, :) :: tmp
call tile_and_reflect(input, tmp)
call assert(all(shape(tmp) - shape(output) == 0), &
'Output shapes do not match')
output(:,:) = tmp(:,:)
end subroutine run_tile_and_reflect
end module test_interface