# Basic use of FFTPACK

**URL:** <https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802>\
**Category:** Help\
**Created:** [February 16, 2022, 10:13am UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802 "2022-02-16T10:13:08Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![juannaviap](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@juannaviap](https://fortran-lang.discourse.group/u/juannaviap)\
**Post date:** [February 16, 2022, 10:13am UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/1 "2022-02-16T10:13:08Z")

</div>

Hi!

It’s my first time using [https://github.com/fortran-lang/fftpack](https://github.com/fortran-lang/fftpack) and I wonder if there is some documentation to get starter with.

I have found this [https://www.netlib.org/fftpack/doc](https://www.netlib.org/fftpack/doc) but I’m having problems:

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

Documentation with a few examples would be great.

Thanks!

---

<div class="post-metadata">

**Author:** ![interkosmos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/interkosmos/32/296_2.png) [@interkosmos](https://fortran-lang.discourse.group/u/interkosmos)\
**Post date:** [February 16, 2022, 10:24am UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/2 "2022-02-16T10:24:33Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![zoziha](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/zoziha/32/582_2.png) [@zoziha](https://fortran-lang.discourse.group/u/zoziha)\
**Post date:** [February 16, 2022, 1:44pm UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/3 "2022-02-16T13:44:55Z")

</div>

`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`.

```fortran
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](https://github.com/fortran-lang/fftpack/pull/25))

You can read first:

- [fftpack/fftpack.md at main · fortran-lang/fftpack (github.com)](https://github.com/fortran-lang/fftpack/blob/main/doc/specs/fftpack.md)

or

- [FFTPACK – Fortran-lang/fftpack](https://zoziha.github.io/fftpack/page/specs/fftpack.html)

---

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [May 7, 2022, 2:44pm UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/4 "2022-05-07T14:44:33Z")

</div>

But where is the module? It is not there.

---

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [May 7, 2022, 2:46pm UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/5 "2022-05-07T14:46:53Z")

</div>

[FFTPACK](https://www.netlib.org/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.

---

<div class="post-metadata">

**Author:** ![zoziha](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/zoziha/32/582_2.png) [@zoziha](https://fortran-lang.discourse.group/u/zoziha)\
**Post date:** [May 7, 2022, 4:05pm UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/6 "2022-05-07T16:05:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [May 7, 2022, 4:17pm UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/7 "2022-05-07T16:17:13Z")

</div>

I have downloaded it from the source https://github.com/fortran-lang/fftpack

After extracting it shows:

 ![fft](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/2/2392ea4dd093c5d1afb1bdcdb88483805bc44700.png)

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

 ![ft](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/e/e7967ca6d8db2e40d4f83410614aefdce7535b76.png)

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

---

<div class="post-metadata">

**Author:** ![zoziha](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/zoziha/32/582_2.png) [@zoziha](https://fortran-lang.discourse.group/u/zoziha)\
**Post date:** [May 7, 2022, 4:28pm UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/8 "2022-05-07T16:28:35Z")

</div>

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](https://github.com/fortran-lang/fftpack#build-with-make) introduction, use `make` to compile the link library and then use it.

---

<div class="post-metadata">

**Author:** ![Rob777](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@Rob777](https://fortran-lang.discourse.group/u/Rob777)\
**Post date:** [May 7, 2022, 6:01pm UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/9 "2022-05-07T18:01:22Z")

</div>

Have you compiled it?

---

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [May 8, 2022, 8:05am UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/10 "2022-05-08T08:05:23Z")

</div>

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

shahid@shahid-VirtualBox:~/Downloads/fftpack-main/src$

```

and I have no idea how to fix it.

---

<div class="post-metadata">

**Author:** ![zoziha](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/zoziha/32/582_2.png) [@zoziha](https://fortran-lang.discourse.group/u/zoziha)\
**Post date:** [May 8, 2022, 8:49am UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/11 "2022-05-08T08:49:22Z")

</div>

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.

```nohighlight
>> 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

```

---

<div class="post-metadata">

**Author:** ![mecej4](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/mecej4/32/855_2.png) [@mecej4](https://fortran-lang.discourse.group/u/mecej4)\
**Post date:** [May 8, 2022, 8:52am UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/12 "2022-05-08T08:52:47Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [May 8, 2022, 12:31pm UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/13 "2022-05-08T12:31:29Z")

</div>

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

 ![Screenshot from 2022-05-08 20-21-51](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/2/268a6638c882260e66ee4b16da54a158324f2247.png)  
 ![Screenshot from 2022-05-08 20-22-07](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/b/b70a75baf27e5bf72b73eb926377124742e67f6e.png)  
 ![Screenshot from 2022-05-08 20-22-15](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/c/cb372686d841e6687fe39352ce24657e3cc802d5.png)  
 ![Screenshot from 2022-05-08 20-22-20](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/0/0bbe726ad58d55132b2ac9f06f64e51e3f96c85d.png)

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

---

<div class="post-metadata">

**Author:** ![interkosmos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/interkosmos/32/296_2.png) [@interkosmos](https://fortran-lang.discourse.group/u/interkosmos)\
**Post date:** [May 8, 2022, 12:37pm UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/14 "2022-05-08T12:37:37Z")

</div>

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

```auto
$ gfortran bench1.f90 -o bench1

```

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

---

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [May 8, 2022, 12:59pm UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/15 "2022-05-08T12:59:59Z")

</div>

![Screenshot from 2022-05-08 20-56-04](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/2/274c7bad0c0b3067352d57b5509e9d4af65e3e81.png)

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

---

<div class="post-metadata">

**Author:** ![interkosmos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/interkosmos/32/296_2.png) [@interkosmos](https://fortran-lang.discourse.group/u/interkosmos)\
**Post date:** [May 8, 2022, 1:08pm UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/16 "2022-05-08T13:08:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zoziha](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/zoziha/32/582_2.png) [@zoziha](https://fortran-lang.discourse.group/u/zoziha)\
**Post date:** [May 8, 2022, 1:10pm UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/17 "2022-05-08T13:10:05Z")

</div>

You can try this:

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

```

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`).

---

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [May 8, 2022, 3:14pm UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/18 "2022-05-08T15:14:09Z")

</div>

I think it is working now

 ![Screenshot from 2022-05-08 23-07-36](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/e/e5a7c6a447854c67db255cc4277c37753f23f071.png)

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

---

<div class="post-metadata">

**Author:** ![jacobwilliams](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jacobwilliams/32/10_2.png) [@jacobwilliams](https://fortran-lang.discourse.group/u/jacobwilliams)\
**Post date:** [May 8, 2022, 4:12pm UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/19 "2022-05-08T16:12:14Z")

</div>

Why didn’t you just try to use FPM?

`fpm build` and 2 seconds later you have the library.

---

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [May 8, 2022, 4:22pm UTC](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802/20 "2022-05-08T16:22:40Z")

</div>

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

[Next page](https://fortran-lang.discourse.group/t/basic-use-of-fftpack/2802.md?page=2)
