Re: FFTW Fortran Real2Complex R2C output array structure? fftw_plan_dft_r2c_3d?



On Jun 13, 5:40 am, "Steven G. Johnson" <stev...@xxxxxxxxxxxx> wrote:
On Jun 12, 1:16 pm, "Robert S." <r...@xxxxxxxxxxxxxxx> wrote:

I'm using the FFTW package and am using the fortan wrappers
to compute a 3D transform. This I seem to do successfully, however
I can not seem to disentangle the raw output.>From studying the figure on page 8 of the fftw 3.1.2 manual

[...]

(I don't shuffle the 3rd dimension since this runs from 1---ngrid3/2+1
and already
contains just the +ve frequncies.)

Remember that a Fortran array corresponds to a C array with *reversed*
dimensions (column-major vs. row-major format). So, in the C FFTW
interface, for an r2c (real-input) transform the last dimension is cut
in ~half, but in the Fortran interface the *first* dimension is cut in
~half.

This is discussed in the FFTW manual. See the third bullet point of:
http://www.fftw.org/doc/Fortran_002dinterface-routines.html
and the last example of:
http://www.fftw.org/doc/Fortran-Examples.html

Regards,
Steven G. Johnson


Dear Steven,
Many thanks! The routine works pefectly.
Best,
Robert

AND just for completeness:
The working frequency shuffle routine, based on Stephen's comments, is
presented below.
This places the zero frequency value at the position array(1, ng2/2 ,
ng3/2 )

-----------------------------------------------------------------------------------------------

subroutine FFTWshuffle_R2C_3D(array)

integer :: ng1,ng2,ng3
integer :: j,k,jj,kk

complex(DPC), dimension(:,:,:) :: array
complex(DPC), allocatable, dimension(:,:,:) :: image

ng1 = size(array,dim=1)
ng2 = size(array,dim=2)
ng3 = size(array,dim=3)

allocate (image(ng1,ng2,ng3))

do k=1,ng3
do j=1,ng2

jj = j + ng2/2 + 1
kk = k + ng3/2 + 1

if (jj.gt.ng2) jj=jj-ng2
if (kk.gt.ng3) kk=kk-ng3

image(:,j,k)=array(:,jj,kk)

enddo
enddo

array=image

deallocate (image)

end subroutine FFTWshuffle_R2C_3D

-------------------------------------------------------------------



.



Relevant Pages

  • Re: another FFTW problem
    ... dimension out ... Because what is being transformed is necessarily discrete in time, the result of the transform is necessarily periodic and discrete in frequency. ...
    (comp.dsp)
  • Re: FFTW Fortran Real2Complex R2C output array structure? fftw_plan_dft_r2c_3d?
    ... So, in the C FFTW ... for an r2c transform the last dimension is cut ...
    (comp.dsp)
  • FFTW: successive real2complex 1-D FFTs fail
    ... I've been experimenting lately with the great FFTW library in C, ... Perform 1-D FFTs on every row of the same image array ... I first create the plans, then I load the image into fftw_in, and then I ... The strange thing is that the second transform produces wrong results. ...
    (comp.dsp)
  • Re: Neutrino Mass and Supernovae
    ... all transform diffeerntly, even though each has dimension M. ... > exchanges momentum when the floton is decaccelerated by some ... both the time and the spatial derivatives are zero. ...
    (sci.physics)
  • fftw - loosing accuracy in cosine transform
    ... Sorry if this is a wrong place for posting fftw related question. ... transform as opposed to the fouerier transform? ... in cosine transform it is O. ... sample array contains input to the FFTW program ...
    (comp.lang.fortran)