FV3 Bundle
fft_mod.F90
Go to the documentation of this file.
1 ! (C) Copyright 2017-2018 UCAR
2 !
3 ! This software is licensed under the terms of the Apache Licence Version 2.0
4 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5 
6 !> Fortran module for Eigen FFTs
7 module fft_mod
8 
9 use, intrinsic :: iso_c_binding
10 use kinds
11 
12 implicit none
13 private
14 public :: fft_fwd, fft_inv
15 
16 !-------------------------------------------------------------------------------
17 interface
18 !-------------------------------------------------------------------------------
19 ! The lines below:
20 ! real(kind=c_double), intent(in) :: pgrid(:)
21 ! real(kind=c_double), intent(out) :: pfour(:)
22 ! would not work because then fortran passes an array descriptor
23 ! (somebody could pass a non-contiguous array using array syntax)
24 ! instead of the address of the first element of the array. YT
25 subroutine fft_fwd_c(kk, pgrid, pfour) bind(C,name='fft_fwd_f')
26  use, intrinsic :: iso_c_binding
27  implicit none
28  integer(c_int), intent(in) :: kk
29  real(c_double), intent(in) :: pgrid
30  real(c_double), intent(inout) :: pfour
31 end subroutine fft_fwd_c
32 !-------------------------------------------------------------------------------
33 subroutine fft_inv_c(kk, pfour, pgrid) bind(C,name='fft_inv_f')
34  use, intrinsic :: iso_c_binding
35  implicit none
36  integer(c_int), intent(in) :: kk
37  real(c_double), intent(in) :: pfour
38  real(c_double), intent(inout) :: pgrid
39 end subroutine fft_inv_c
40 !-------------------------------------------------------------------------------
41 end interface
42 !-------------------------------------------------------------------------------
43 
44 ! ------------------------------------------------------------------------------
45 contains
46 ! ------------------------------------------------------------------------------
47 
48 subroutine fft_fwd(kk, pg, pf)
49 implicit none
50 integer, intent(in) :: kk
51 real(kind_real), intent(in) :: pg(kk)
52 real(kind_real), intent(out) :: pf(kk+2)
53 real(c_double) :: zz(kk), ww(kk+2)
54 integer(c_int) :: nn
55 
56 nn=kk
57 zz(:) = pg(:)
58 call fft_fwd_c(nn, zz(1), ww(1))
59 pf(:) = ww(:)
60 
61 end subroutine fft_fwd
62 
63 ! ------------------------------------------------------------------------------
64 
65 subroutine fft_inv(kk, pf, pg)
66 implicit none
67 integer, intent(in) :: kk
68 real(kind_real), intent(in) :: pf(kk+2)
69 real(kind_real), intent(out) :: pg(kk)
70 real(c_double) :: zz(kk), ww(kk+2)
71 integer(c_int) :: nn
72 
73 nn=kk
74 ww(:) = pf(:)
75 call fft_inv_c(nn, ww(1), zz(1))
76 pg(:) = zz(:)
77 
78 end subroutine fft_inv
79 
80 ! ------------------------------------------------------------------------------
81 
82 end module fft_mod
subroutine, public fft_inv(kk, pf, pg)
Definition: fft_mod.F90:66
Fortran module for Eigen FFTs.
Definition: fft.F90:24
subroutine, public fft_fwd(kk, pg, pf)
Definition: fft_mod.F90:49