I am trying to use the subroutine twofft which in turn uses subroutine four1 in the book(Numerical Recipes in Fortran) to compute the FFT of two double precision data arrays. If you carefully look at the twofft routine, the arrays fft1 and fft2 are declared as complex which are sent as arguments to four1 which declares the same two arrays as double precision( or real if you are using the real version).

Is this allowed? I am unable to obtain the correct FFT for my data. Any suggestion how to get around this problem? I just want to perform a quick FFT and a deconvolution and not have to go through the entire process of understanding the code.


1 Answer 1


No, it's illegal by the Fortran standard, but that said most compilers will let you get away with it (if the debugging options are not turned on and provided a correct interface is not in scope at the calling point) as long as you are passing Double Complex to double precision and the arrays of the later are twice the size of the former, and similarly complex to real - I say this because in your question you say

the arrays fft1 and fft2 are declared as complex which are sent as arguments to four1 which declares the same two arrays as double precision

which won't work - you have to pass DOUBLE complex to double precision.

That said I wouldn't touch the NR FFT routines with a barge pole. Instead I would install FFTW (http://www.fftw.org/) and use that. If you're using linux you can probably apt-get it or similar.

  • $\begingroup$ Thanks for the information and your suggestion. I was playing around with another set of routines namely, $\textit{fftpack5}$ and found that did the job of getting the FFT. I do have a new problem though, how does one multiply two complex numbers in fortran?Please know that I am quite new to fortran 77 standard. $\endgroup$
    – MSIngh
    Apr 17, 2016 at 2:08
  • 1
    $\begingroup$ You use the multiply sign! Complex is a basic type in Fortran. But scicomp isn't the best place for questions like this - instead ask them on stackoverflow and use the tag Fortran. Also do yourself a favour, don't learn Fortran 77, it's been obsolescent for over 1/4 of a century and NOBODY should be being taught it or teaching it today. Nowadays learn Fortran 2003, it's much cleaner and much safer. $\endgroup$
    – Ian Bush
    Apr 17, 2016 at 8:22
  • $\begingroup$ I can only upvote Ian Bush's comment as, one the one hand, I've heard the best (and the worst) about NR and yet still feel sceptical on it, and on the other hand, compilers are left with a possibility to compile Fortran 77 only for portability issues. Fortran 90/95/03 are more used and you should only learn 77 in case you have to deal with really old program (which can work well but may need updates from time to time). If you need good references, Michael Metcalf's books on the topic are wwwide spread and well written. $\endgroup$
    – G.Clavier
    Apr 18, 2016 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.