0

I would like to ask for your help to compile a .f90 program that uses fftw3 (I am just learning Fortran and I got the code from someone else).

When I compile it, I get this error:

>> gfortran test1.f90 

    plo  = fftw_plan_dft_1d(NT, IN, OUT, fftw_forward, FFTW_ESTIMATE)
           1
Error: Function 'fftw_plan_dft_1d' at (1) has no IMPLICIT type

    iplo = fftw_plan_dft_1d(NT, OUT, IN, fftw_forward, FFTW_ESTIMATE)
           1
Error: Function 'fftw_plan_dft_1d' at (1) has no IMPLICIT type

I followed what is recommended in this link:

Function has no implicit type

but I keep getting the error.

This is the code I am trying to compile:

!******************************

module FFTW3

    use, intrinsic :: iso_c_binding
    include "fftw3.f"

end module


module gst_module

use FFTW3

use omp_lib

implicit none

contains

subroutine transf(NT, x, IN)

    implicit none

    type(C_PTR) :: plo, iplo

    integer (kind=4) i, j, NT !  , FFTW_ESTIMATE
    real    (kind=8) x(NT), h(NT)
    complex (kind=8) y(NT), IN(NT), OUT(NT)


    do i=1,NT
        IN(i) = dcmplx(x(i),0.0d0)
    end do


    plo  = fftw_plan_dft_1d(NT, IN, OUT, fftw_forward, FFTW_ESTIMATE)
    iplo = fftw_plan_dft_1d(NT, OUT, IN, fftw_forward, FFTW_ESTIMATE)


    call fftw_execute_dft(plo, IN, OUT)

! To make it shorter here I removed some lines of code that create the h vector

    do i=1,NT
        OUT(i) = OUT(i) * real(h(i),8)
    end do

    call fftw_execute_dft(iplo, OUT, IN)

! Here other lines of code using the results ..

    call fftw_destroy_plan(plo)
    call fftw_destroy_plan(iplo)

end subroutine transf

end module gst_module

!***************************

I tried to compile in Linux using this version:

>> gfortran --version

GNU Fortran (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.

And also in CYGWIN using:

>> gfortran --version

GNU Fortran (GCC) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

and in both cases I get the same error messages.

I have to say that the guy who shared the code does not get any error messages. He uses:

>> gfortran --version:

GNU Fortran (Homebrew GCC 11.2.0_3) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.

I will appreciate your help A LOT.

Hugo
  • 1
  • 1
  • Welcome, please use the editing.features of the question editor to mark the code in your question appropriately. I did it for you. Also pay attention to the description of the tags you use and always use tag [tag:fortran] for Fortran questions. Be aware that the code is Fortran 2003 or later, not Fortran 90. – Vladimir F Героям слава Feb 17 '22 at 07:49
  • I only have 11.1.0, but that gives the same error as you - and the error is correct as there is no declaration in the include file for the function return values – Ian Bush Feb 17 '22 at 07:54
  • Note also, or tell the person who is supplying you this code, that `dcmplx` is not standard Fortran (use `cmplx` and provide an appropriate kind), and `real( 8 )` and similar are not portable, may not compile, and may not do what you expect - see https://stackoverflow.com/questions/838310/fortran-90-kind-parameter . Also gfortran 4.8.5 is truly ancient, I would very strongly recommend upgrading. – Ian Bush Feb 17 '22 at 07:59
  • Thanks @Ian for your comments. I will do that. – Hugo Feb 19 '22 at 04:17
  • Thanks @VladimirF for editing my message and clarifications. – Hugo Feb 19 '22 at 04:19

1 Answers1

1

You are using the modern Fortran 2003-based interface to FFTW. For that, the right include file to use is fftw3.f03. The fftw3.f include file also exists, but it defines the legacy interface and contains completely different functions.

See the instructions in the manual https://fftw.org/doc/Defining-an-FFTW-module.html

The example there is:

  module FFTW3
    use, intrinsic :: iso_c_binding
    include 'fftw3.f03'
  end module
  • The question remains, why did it work for the other guy. I can only speculate that he did something to those include files on his computer. But normally, those include files are not compatible and the old interface contains completely different functions. – Vladimir F Героям слава Feb 17 '22 at 08:51
  • I changed to fftw3.f03 and got messages like this: (.text+0x5a9): undefined reference to `fftw_plan_dft_1d'. I asked to the guy the exact compilation flags and finally works. This is what he gave me: >> gfortran -Ofast -ftree-vectorize -c test1.f90 Thanks to everyone! – Hugo Feb 19 '22 at 04:42
  • @Hugo Undefined difference is alinker error. It apoears in a later step and means that you must link the library (`-lfftw3`). See https://stackoverflow.com/questions/66855252/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – Vladimir F Героям слава Feb 19 '22 at 07:32