Professional Documents
Culture Documents
! create tables
But when the fft is called later, the indx parameter might
different.
call fft1(f,kndx,isign=1)
module fft1
integer, save :: saved_indx
integer, dimension(:), allocatable, save :: mixup
complex, dimension(:), allocatable, save :: sct
contains
subroutine new_fft_table(indx)
! create fft tables
integer :: indx, isign, nx, nxh
saved_indx = indx
isign = 0
nx = 2**saved_indx; nxh = nx/2
allocate(mixup(nxh),sct(nxh))
call fft1r(f,t,isign,mixup,sct,indx,nx,nxh)
end subroutine new_fft_table
subroutine fft1(f,isign)
! perform fft
integer :: indx, isign, nx, nxh
real, dimension(:) :: f
complex, dimension(size(f)/2) :: t
nx = 2**saved_indx; nxh = nx/2
call fft1r(f,t,isign,mixup,sct,indx,nx,nxh)
end subroutine fft1
end module fft1
One can use these procedures as follows:
use fft1
call new_fft_table(indx)
call fft1(f,isign=1)
subroutine fft1cc(f)
complex, dimension(:) :: f
subroutine fft2rc(f)
real, dimension(:,:) :: f
and so on.
It is easy to overdo function overloading, however.
You should use it only when it is obvious what you intend
to happen. You should avoid using it if it obfuscates your
intention. For example, by overloading different
procedures with a generic name such as solve, you may
not remember later which solver you actually intended,
without carefully studying all the argument types in all
your modules. You still want a human being to be able to
read your code and easily determine what it is supposed
to be doing.
Function overloading is sometimes called static
polymorphism because the actual function being called is
determined (resolved) at compile time and not at run time.
! this is OK.