Basic use of FFTPACK


It’s my first time using and I wonder if there is some documentation to get starter with.

I have found this but I’m having problems:

Function ‘rffti’ at (1) has no IMPLICIT type

Documentation with a few examples would be great.



You are using the modernised version of FFTPACK. You first have to import the required Fortran modules:

use :: fftpack, only: rffti, rfftf
use :: fftpack_kind, only: rk

rffti should be a routine in single-precision fftpack(netlib/fftpack), Fortran-lang/fftpack uses netlib/dfftpack. The default is double precision, which corresponds to dffti.

use fftpack, only: dffti, dfftf, dfftb
use fftpack_kind, only: rk

Sorry, the documentation of fftpack has not been perfected in the first time, and now there is a preliminary FORD document in PR. (see Add FORD gh-pages PR #25 · fortran-lang/fftpack)

You can read first:


1 Like

But where is the module? It is not there.

FFTPACK I did not find it in this link. Where to look for it? A bit of description would be very helpful. Thanks in advance.

Are you looking for the fftpack module? The netlib version of fftpack is f77 style, it has no module, the fftpack under the fortran-lang namespace uses f90 style and has modules.

I have downloaded it from the source

After extracting it shows:

If I run it (using Simply Fortran IDE on Windows OS) it shows an error (red line):

So I need help to understand the reason for it. Did I miss something during the download?

This does not seem to be related to the fftpack code. It is most likely related to the programming environment or IDE you are using. You can compile fftpack following the README introduction, use make to compile the link library and then use it.

1 Like

Have you compiled it?

The documentation shows two ways

  1. fpm
  2. make

and I am not familiar with both.
So now I am doing with a virtual machine (ubuntu 20.04) in the following way (after putting bench1.f90 in src):

shahid@shahid-VirtualBox:~$ cd Downloads/fftpack-main/src
shahid@shahid-VirtualBox:~/Downloads/fftpack-main/src$ gfortran -c rk.f90
shahid@shahid-VirtualBox:~/Downloads/fftpack-main/src$ gfortran -c fftpack.f90
shahid@shahid-VirtualBox:~/Downloads/fftpack-main/src$ gfortran -c bench1.f90
shahid@shahid-VirtualBox:~/Downloads/fftpack-main/src$ gfortran bench1.o fftpack.o rk.o

/usr/bin/ld: bench1.o: in function `MAIN__':

bench1.f90:(.text+0x709): undefined reference to `zffti_'
/usr/bin/ld: bench1.f90:(.text+0x7c0): undefined reference to `zfftf_'
/usr/bin/ld: bench1.f90:(.text+0x877): undefined reference to `zfftb_'
collect2: error: ld returned 1 exit status


and I have no idea how to fix it.

Just compiling rk.f90 and fftpack.f90 is not enough, the source code is interdependent, it will be easiest to use the provided compilation methods like make, otherwise you will have to put all the source files from the src folder into your IDE for compilation.

>> make
gfortran -O2 -c rk.f90
gfortran -O2 -c zfftb.f90
gfortran -O2 -c cfftb1.f90
gfortran -O2 -c zfftf.f90
gfortran -O2 -c cfftf1.f90
gfortran -O2 -c zffti.f90
gfortran -O2 -c cffti1.f90
gfortran -O2 -c dcosqb.f90
gfortran -O2 -c cosqb1.f90
gfortran -O2 -c dcosqf.f90
gfortran -O2 -c cosqf1.f90
gfortran -O2 -c dcosqi.f90
gfortran -O2 -c dcost.f90
gfortran -O2 -c dcosti.f90
gfortran -O2 -c ezfft1.f90
gfortran -O2 -c dzfftb.f90
gfortran -O2 -c dzfftf.f90
gfortran -O2 -c dzffti.f90
gfortran -O2 -c passb.f90
gfortran -O2 -c passb2.f90
gfortran -O2 -c passb3.f90
gfortran -O2 -c passb4.f90
gfortran -O2 -c passb5.f90
gfortran -O2 -c passf.f90
gfortran -O2 -c passf2.f90
gfortran -O2 -c passf3.f90
gfortran -O2 -c passf4.f90
gfortran -O2 -c passf5.f90
gfortran -O2 -c radb2.f90
gfortran -O2 -c radb3.f90
gfortran -O2 -c radb4.f90
gfortran -O2 -c radb5.f90
gfortran -O2 -c radbg.f90
gfortran -O2 -c radf2.f90
gfortran -O2 -c radf3.f90
gfortran -O2 -c radf4.f90
gfortran -O2 -c radf5.f90
gfortran -O2 -c radfg.f90
gfortran -O2 -c dfftb.f90
gfortran -O2 -c rfftb1.f90
gfortran -O2 -c dfftf.f90
gfortran -O2 -c rfftf1.f90
gfortran -O2 -c dffti.f90
gfortran -O2 -c rffti1.f90
gfortran -O2 -c dsinqb.f90
gfortran -O2 -c dsinqf.f90
gfortran -O2 -c dsinqi.f90
gfortran -O2 -c dsint.f90
gfortran -O2 -c sint1.f90
gfortran -O2 -c dsinti.f90
gfortran -O2 -c fftpack.f90
gfortran -O2 -c fftpack_fft.f90
gfortran -O2 -c fftpack_ifft.f90
gfortran -O2 -c fftpack_rfft.f90
gfortran -O2 -c fftpack_irfft.f90
gfortran -O2 -c fftpack_fftshift.f90
gfortran -O2 -c fftpack_ifftshift.f90
gfortran -O2 -c fftpack_qct.f90
gfortran -O2 -c fftpack_iqct.f90
gfortran -O2 -c fftpack_dct.f90
ar -rcs libdfftpack.a zfftb.o cfftb1.o zfftf.o cfftf1.o zffti.o cffti1.o dcosqb.o cosqb1.o dcosqf.o cosqf1.o dcosqi.o dcost.o dcosti.o ezfft1.o dzfftb.o dzfftf.o dzffti.o passb.o passb2.o passb3.o passb4.o passb5.o passf.o passf2.o passf3.o passf4.o 
passf5.o radb2.o radb3.o radb4.o radb5.o radbg.o radf2.o radf3.o radf4.o radf5.o radfg.o dfftb.o rfftb1.o dfftf.o rfftf1.o dffti.o rffti1.o dsinqb.o dsinqf.o dsinqi.o dsint.o sint1.o dsinti.o fftpack.o fftpack_fft.o fftpack_ifft.o fftpack_rfft.o fftpack_irfft.o fftpack_fftshift.o fftpack_ifftshift.o fftpack_qct.o fftpack_iqct.o fftpack_dct.o rk.o
1 Like

Many packages such as FFTPACK consist of scores of source files, with many interdependencies. Because of these interdependencies, they have to be compiled in a proper sequence. Before you can compile any source file that has a USE <some_module> in it, you have to compile the source file that contains MODULE <some_module>. Before you can build an executable that depends on routines in the FFTpack library, you have to build the library.

The Linux/Unix Make utility program is able to do all this on the basis of the makefile(s) provided by the package creators.

The simplest way to build and run the test is as follows.

  • In your Virtualbox VM, in a shell window, change to the fftpack-main directory.

  • Enter the command make

If you wish to build from an IDE such as SimplyFortran’s, you have to look up its documentation, or wait for another user of the IDE to help you (I am not such a user).

1 Like

Thanks for the clear explanation. I really appreciate it.
Following the suggestions, I performed it and I get this error now

There is a problem with linking now? What path should I put in the code to run it? Or the make file does it?

You did not link your program bench1 against FFTPACK, when running

$ gfortran bench1.f90 -o bench1

Link against libdfftpack.a (statically) or -ldfftpack (shared).

I do not understand it. Does not look like it was linked properly. Or there is something else I just do not see?

Either copy libdfftpack.a to your project directory or add the relative/absolute path, maybe ../libdfftpack.a?

1 Like

You can try this:

gfortran bench1.f90 -L../src -ldfftpack -I../src -o bench1  # Link the fftpack library

This is actually the link library usage of most compiled languages, how to use the link library: declare the link library location (-L../src), link library name (-ldfftpack), header file path (-I../src).

1 Like

I think it is working now

One question: This package is just for rank 1? I read it from the that x: Shall be a real and rank-1 array (e.g in line 508).

Why didn’t you just try to use FPM?

fpm build and 2 seconds later you have the library.

1 Like

Yeah. I feel it is time to learn FPM. So far I have not used it.