Copyright (C) 2000-2012 |
GNU Info (fftw.info)Fortran ExamplesFortran Examples ================ In C you might have something like the following to transform a one-dimensional complex array: fftw_complex in[N], *out[N]; fftw_plan plan; plan = fftw_create_plan(N,FFTW_FORWARD,FFTW_ESTIMATE); fftw_one(plan,in,out); fftw_destroy_plan(plan); In Fortran, you use the following to accomplish the same thing: double complex in, out dimension in(N), out(N) integer plan call fftw_f77_create_plan(plan,N,FFTW_FORWARD,FFTW_ESTIMATE) call fftw_f77_one(plan,in,out) call fftw_f77_destroy_plan(plan) Notice how all routines are called as Fortran subroutines, and the plan is returned via the first argument to `fftw_f77_create_plan'. *Important:* these examples assume that `integer' is the same size as a pointer, and may need modification on a 64-bit machine. Note: Wrapper Routines, above. To do the same thing, but using 8 threads in parallel (Note: Multi-threaded FFTW.), you would simply replace the call to `fftw_f77_one' with: call fftw_f77_threads_one(8,plan,in,out) To transform a three-dimensional array in-place with C, you might do: fftw_complex arr[L][M][N]; fftwnd_plan plan; int n[3] = {L,M,N}; plan = fftwnd_create_plan(3,n,FFTW_FORWARD, FFTW_ESTIMATE | FFTW_IN_PLACE); fftwnd_one(plan, arr, 0); fftwnd_destroy_plan(plan); In Fortran, you would use this instead: double complex arr dimension arr(L,M,N) integer n dimension n(3) integer plan n(1) = L n(2) = M n(3) = N call fftwnd_f77_create_plan(plan,3,n,FFTW_FORWARD, + FFTW_ESTIMATE + FFTW_IN_PLACE) call fftwnd_f77_one(plan, arr, 0) call fftwnd_f77_destroy_plan(plan) Instead of calling `fftwnd_f77_create_plan(plan,3,n,...)', we could also have called `fftw3d_f77_create_plan(plan,L,M,N,...)'. Note that we pass the array dimensions in the "natural" order; also note that the last argument to `fftwnd_f77' is ignored since the transform is `FFTW_IN_PLACE'. To transform a one-dimensional real array in Fortran, you might do: double precision in, out dimension in(N), out(N) integer plan call rfftw_f77_create_plan(plan,N,FFTW_REAL_TO_COMPLEX, + FFTW_ESTIMATE) call rfftw_f77_one(plan,in,out) call rfftw_f77_destroy_plan(plan) To transform a two-dimensional real array, out of place, you might use the following: double precision in double complex out dimension in(M,N), out(M/2 + 1, N) integer plan call rfftw2d_f77_create_plan(plan,M,N,FFTW_REAL_TO_COMPLEX, + FFTW_ESTIMATE) call rfftwnd_f77_one_real_to_complex(plan, in, out) call rfftwnd_f77_destroy_plan(plan) Important: Notice that it is the *first* dimension of the complex output array that is cut in half in Fortran, rather than the last dimension as in C. This is a consequence of the wrapper routines reversing the order of the array dimensions passed to FFTW so that the Fortran program can use its ordinary column-major order. automatically generated by info2www version 1.2.2.9 |