473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Calling FFTW from C++? (x-posted)

Hi,

I am currently working on a program using FFTW-> http://www.fftw.org .
My basic C program to compute the 2D Fourier transform of a bunch of
data works fine when I compile it with gcc. However, I would like to
incorporate that code into a larger program that I wrote with C++.
Unfortunately, I cannot get my program to compile with g++.

I compile it as follows:

g++ ft2d.c -o ft2d -I/usr/local/include -L /usr/local/lib -lfftw3 -lm

The errors I get are:

ft2d.c: In function `int main()':
ft2d.c:13: invalid conversion from `void*' to `double (*)[2]'
ft2d.c:14: invalid conversion from `void*' to `double (*)[2]'

Here is my code:

#include <fftw3.h>
#include <math.h>

int main(void)
{
fftw_complex *in, *out;
fftw_plan p;
int nx = 5;
int ny = 5;
int i;

/* Allocate the input and output arrays, and create the plan */
in = fftw_malloc(sizeof(fftw_complex) * nx * ny);
out = fftw_malloc(sizeof(fftw_complex) * nx * ny);
p = fftw_plan_dft_2d(nx, ny, in, out, FFTW_FORWARD,
FFTW_ESTIMATE);

/* Now fill the input array with the input data */
/* We'll simply make a sine wave */
for (i = 0; i < (nx * ny); i++) {
in[i][0] = sin(i / 10.0 * M_PI); /* Real part */
in[i][1] = 0.0; /* Imaginary part */
}

/* Actually execute the plan on the input data */
fftw_execute(p);

/* Print out the results */
for (i = 0; i < (nx * ny); i++)
printf("Coefficient %d: %f%+f*i\n", i, out[i][0], out[i][1]);

/* Clean up after ourselves */
fftw_destroy_plan(p);
fftw_free(in); fftw_free(out);
return 0;
}

Eventually I will do something more complex than a sine wave, but you
get the idea.

If anyone knows what the problem is, I would greatly appreciate any
help. This is all that fftw.org has about calling it from C++:
http://fftw.org/faq/section2.html#cplusplus

Thanks in advance!!
--Erica
Jul 22 '05 #1
4 4327

"Erica" <er***@technodyke.com> wrote in message
news:34**************************@posting.google.c om...
Hi,

I am currently working on a program using FFTW-> http://www.fftw.org .
My basic C program to compute the 2D Fourier transform of a bunch of
data works fine when I compile it with gcc. However, I would like to
incorporate that code into a larger program that I wrote with C++.
Unfortunately, I cannot get my program to compile with g++.

I compile it as follows:

g++ ft2d.c -o ft2d -I/usr/local/include -L /usr/local/lib -lfftw3 -lm

The errors I get are:

ft2d.c: In function `int main()':
ft2d.c:13: invalid conversion from `void*' to `double (*)[2]'
ft2d.c:14: invalid conversion from `void*' to `double (*)[2]'
This is one of the differences between C++ and C. In C void* automatically
converts to any other pointer, in C++ you must cast.

Here is my code:

#include <fftw3.h>
#include <math.h>

int main(void)
{
fftw_complex *in, *out;
fftw_plan p;
int nx = 5;
int ny = 5;
int i;

/* Allocate the input and output arrays, and create the plan */
in = fftw_malloc(sizeof(fftw_complex) * nx * ny);
in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * nx * ny);
out = fftw_malloc(sizeof(fftw_complex) * nx * ny);


out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * nx * ny);

That should do it.

john
Jul 22 '05 #2

"Erica" <er***@technodyke.com> wrote in message
news:34**************************@posting.google.c om...
Hi,

I am currently working on a program using FFTW-> http://www.fftw.org .
My basic C program to compute the 2D Fourier transform of a bunch of
data works fine when I compile it with gcc. However, I would like to
incorporate that code into a larger program that I wrote with C++.
Unfortunately, I cannot get my program to compile with g++.

I compile it as follows:

g++ ft2d.c -o ft2d -I/usr/local/include -L /usr/local/lib -lfftw3 -lm

The errors I get are:

ft2d.c: In function `int main()':
ft2d.c:13: invalid conversion from `void*' to `double (*)[2]'
ft2d.c:14: invalid conversion from `void*' to `double (*)[2]'

You don't note in your code what lines 13 and 14 are, but if I'm counting
correctly, the errors are on the fftw_malloc lines, right? You probably
need to cast the results of those function calls to (fftw_complex *). It
appears that the fftw_malloc call returns a void*, and the compiler is
complaining about that type not matching your in and out variables' declared
type.

-Howard
Here is my code:

#include <fftw3.h>
#include <math.h>

int main(void)
{
fftw_complex *in, *out;
fftw_plan p;
int nx = 5;
int ny = 5;
int i;

/* Allocate the input and output arrays, and create the plan */
in = fftw_malloc(sizeof(fftw_complex) * nx * ny);
out = fftw_malloc(sizeof(fftw_complex) * nx * ny);


Jul 22 '05 #3
That did the trick...thanks!!

"Howard" <al*****@hotmail.com> wrote in message news:<DA*********************@bgtnsc04-news.ops.worldnet.att.net>...
"Erica" <er***@technodyke.com> wrote in message
news:34**************************@posting.google.c om...
Hi,

I am currently working on a program using FFTW-> http://www.fftw.org .
My basic C program to compute the 2D Fourier transform of a bunch of
data works fine when I compile it with gcc. However, I would like to
incorporate that code into a larger program that I wrote with C++.
Unfortunately, I cannot get my program to compile with g++.

I compile it as follows:

g++ ft2d.c -o ft2d -I/usr/local/include -L /usr/local/lib -lfftw3 -lm

The errors I get are:

ft2d.c: In function `int main()':
ft2d.c:13: invalid conversion from `void*' to `double (*)[2]'
ft2d.c:14: invalid conversion from `void*' to `double (*)[2]'


You don't note in your code what lines 13 and 14 are, but if I'm counting
correctly, the errors are on the fftw_malloc lines, right? You probably
need to cast the results of those function calls to (fftw_complex *). It
appears that the fftw_malloc call returns a void*, and the compiler is
complaining about that type not matching your in and out variables' declared
type.

-Howard
Here is my code:

#include <fftw3.h>
#include <math.h>

int main(void)
{
fftw_complex *in, *out;
fftw_plan p;
int nx = 5;
int ny = 5;
int i;

/* Allocate the input and output arrays, and create the plan */
in = fftw_malloc(sizeof(fftw_complex) * nx * ny);
out = fftw_malloc(sizeof(fftw_complex) * nx * ny);

Jul 22 '05 #4
er***@technodyke.com (Erica) wrote:

My basic C program to compute the 2D Fourier transform of a bunch of
data works fine when I compile it with gcc. However, I would like to
incorporate that code into a larger program that I wrote with C++.
Unfortunately, I cannot get my program to compile with g++.

I compile it as follows:

g++ ft2d.c -o ft2d -I/usr/local/include -L /usr/local/lib -lfftw3 -lm

The errors I get are:

ft2d.c: In function `int main()':
ft2d.c:13: invalid conversion from `void*' to `double (*)[2]'
ft2d.c:14: invalid conversion from `void*' to `double (*)[2]'


IMHO if you want to mix C and C++ in a project, you should
leave your C files as .C files, (and compile them with gcc not g++).
If you include the corresponding .H file from a C++ source file
do this:
extern "C" {
#include "ft2d.h"
};

Alternatively you could write a wrapper file that uses this,
that would avoid having to do this in every other unit that has
to include the C header.

There's a chapter in the c.l.c++ FAQ about mixing C and C++ in
projects, have a read of it and see if there is any more advice.
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Stanley | last post by:
Hi, I'm using FFTW library to do my FFT calculation. My sample size is so large to get the resolution I want ( >10^7 samples). It's time and memory consuming. Since I'm just interested in the...
1
by: JoePyeWuz | last post by:
Hi, I'm pretty new to using outside libraries...so I don't really understand how to install the FFTW(fast fourier transform made at MIT) library for use with my C++ programs. I have Windows XP and...
2
by: Marie | last post by:
Hi, I´m trying to perform Fourier Transforms on contiuously incoming images from a camera. I have sofar been using the Basic Interface for planning and execution for every image. Later I have...
3
by: Fabio Garufi | last post by:
Hi, all, I built the fftw-3.0.1-fma on a LynxOS 4.0 running on a board equipped with a PowerPC G4 7457. To compile it I had to slightly modify the configure script to use the -fvec instead of...
5
by: spasmous | last post by:
I'm looking into upgrading from version 2 to version 3 of the FFT code package FFTW (www.fftw.org). The two versions are incompatible - a lot of it has to do with changing from a complex struct...
2
by: John | last post by:
Hi, Has anyone create a DLL for FFTW that can be used from C#? I was able to compile all the .c files and produce .lib's, but I don't think the .libs I created can be used in C#. I tried to...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
0
by: Grace Allaboh | last post by:
Hi I've been searching for FFTW libraries that run on windows mobile 6. I really haven't had any success and i'm wondering if they even exist. I need to extract particular information eg heartbeat...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.